Pull Mob mainhand/offhand attack rounds into their own functions

This commit is contained in:
Michael Cook (mackal) 2015-07-05 01:15:46 -04:00
parent 578bbf657a
commit 7c89ab3fec
3 changed files with 62 additions and 54 deletions

View File

@ -5103,3 +5103,61 @@ bool Client::CheckDualWield()
return zone->random.Int(1, 375) <= chance;
}
void Mob::DoMainHandAttackRounds(Mob *target, ExtraAttackOptions *opts)
{
if (IsNPC()) {
int16 n_atk = CastToNPC()->GetNumberOfAttacks();
if (n_atk <= 1) {
Attack(target, MainPrimary, false, false, false, opts);
} else {
for (int i = 0; i < n_atk; ++i) {
Attack(target, MainPrimary, false, false, false, opts);
}
}
} else {
Attack(target, MainPrimary, false, false, false, opts);
}
if (target) {
// we use this random value in three comparisons with different
// thresholds, and if its truely random, then this should work
// out reasonably and will save us compute resources.
int32 RandRoll = zone->random.Int(0, 99);
if ((CanThisClassDoubleAttack() || GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD))
// check double attack, this is NOT the same rules that clients use...
&&
RandRoll < (GetLevel() + NPCDualAttackModifier)) {
Attack(target, MainPrimary, false, false, false, opts);
// lets see if we can do a triple attack with the main hand
// pets are excluded from triple and quads...
if ((GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD)) && !IsPet() &&
RandRoll < (GetLevel() + NPCTripleAttackModifier)) {
Attack(target, MainPrimary, false, false, false, opts);
// now lets check the quad attack
if (GetSpecialAbility(SPECATK_QUAD) &&
RandRoll < (GetLevel() + NPCQuadAttackModifier)) {
Attack(target, MainPrimary, false, false, false, opts);
}
}
}
}
}
void Mob::DoOffHandAttackRounds(Mob *target, ExtraAttackOptions *opts)
{
if (!target)
return;
// Mobs will only dual wield w/ the flag or have a secondary weapon
if (GetSpecialAbility(SPECATK_INNATE_DW) || GetEquipment(MaterialSecondary) != 0) {
if (CheckDualWield()) {
Attack(target, MainSecondary, false, false, false, opts);
if (CanThisClassDoubleAttack()) {
// This isn't correct yet
if (zone->random.Roll(GetLevel() + 20)) {
Attack(target, MainSecondary, false, false, false, opts);
}
}
}
}
}

View File

@ -167,6 +167,8 @@ public:
void CommonBreakInvisible();
bool HasDied();
virtual bool CheckDualWield();
void DoMainHandAttackRounds(Mob *target, ExtraAttackOptions *opts = nullptr);
void DoOffHandAttackRounds(Mob *target, ExtraAttackOptions *opts = nullptr);
//Appearance
void SendLevelAppearance();

View File

@ -1101,42 +1101,7 @@ void Mob::AI_Process() {
//try main hand first
if(attack_timer.Check()) {
if(IsNPC()) {
int16 n_atk = CastToNPC()->GetNumberOfAttacks();
if(n_atk <= 1) {
Attack(target, MainPrimary);
} else {
for(int i = 0; i < n_atk; ++i) {
Attack(target, MainPrimary);
}
}
} else {
Attack(target, MainPrimary);
}
if (target) {
//we use this random value in three comparisons with different
//thresholds, and if its truely random, then this should work
//out reasonably and will save us compute resources.
int32 RandRoll = zone->random.Int(0, 99);
if ((CanThisClassDoubleAttack() || GetSpecialAbility(SPECATK_TRIPLE)
|| GetSpecialAbility(SPECATK_QUAD))
//check double attack, this is NOT the same rules that clients use...
&& RandRoll < (GetLevel() + NPCDualAttackModifier)) {
Attack(target, MainPrimary);
// lets see if we can do a triple attack with the main hand
//pets are excluded from triple and quads...
if ((GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD))
&& !IsPet() && RandRoll < (GetLevel() + NPCTripleAttackModifier)) {
Attack(target, MainPrimary);
// now lets check the quad attack
if (GetSpecialAbility(SPECATK_QUAD)
&& RandRoll < (GetLevel() + NPCQuadAttackModifier)) {
Attack(target, MainPrimary);
}
}
}
}
DoMainHandAttackRounds(target);
if (GetSpecialAbility(SPECATK_FLURRY)) {
int flurry_chance = GetSpecialAbilityParam(SPECATK_FLURRY, 0);
@ -1271,24 +1236,7 @@ void Mob::AI_Process() {
//now off hand
if (attack_dw_timer.Check() && CanThisClassDualWield())
{
int myclass = GetClass();
//can only dual wield without a weapon if your a monk
if(GetSpecialAbility(SPECATK_INNATE_DW) || (GetEquipment(MaterialSecondary) != 0 && GetLevel() > 29) || myclass == MONK || myclass == MONKGM) {
float DualWieldProbability = (GetSkill(SkillDualWield) + GetLevel()) / 400.0f;
if(zone->random.Roll(DualWieldProbability))
{
Attack(target, MainSecondary);
if (CanThisClassDoubleAttack())
{
if (zone->random.Roll(GetLevel() + 20))
{
Attack(target, MainSecondary);
}
}
}
}
}
DoOffHandAttackRounds(target);
//now special attacks (kick, etc)
if(IsNPC())