From dcd1a0755316b34ab8a9394adb6c816892ad1c46 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sun, 5 Jul 2015 03:11:25 -0400 Subject: [PATCH] Fix issue with two hander for NPCs dual wielding Cleaned up some other 2hander logic as well --- zone/attack.cpp | 29 ++++------------------------- zone/bonuses.cpp | 6 +++++- zone/loottables.cpp | 4 +++- zone/mob.cpp | 1 + zone/mob.h | 3 +++ 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/zone/attack.cpp b/zone/attack.cpp index f953ce3db..3714bb8e2 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -4921,7 +4921,6 @@ void Client::SetAttackTimer() attack_timer.SetAtTrigger(4000, true); Timer *TimerToUse = nullptr; - const Item_Struct *PrimaryWeapon = nullptr; for (int i = MainRange; i <= MainSecondary; i++) { //pick a timer @@ -4943,19 +4942,8 @@ void Client::SetAttackTimer() //special offhand stuff if (i == MainSecondary) { - //if we have a 2H weapon in our main hand, no dual - if (PrimaryWeapon != nullptr) { - if (PrimaryWeapon->ItemClass == ItemClassCommon - && (PrimaryWeapon->ItemType == ItemType2HSlash - || PrimaryWeapon->ItemType == ItemType2HBlunt - || PrimaryWeapon->ItemType == ItemType2HPiercing)) { - attack_dw_timer.Disable(); - continue; - } - } - //if we cant dual wield, skip it - if (!CanThisClassDualWield()) { + if (!CanThisClassDualWield() || HasTwoHanderEquipped()) { attack_dw_timer.Disable(); continue; } @@ -5004,9 +4992,6 @@ void Client::SetAttackTimer() if (quiver_haste > 0) speed *= quiver_haste; TimerToUse->SetAtTrigger(std::max(RuleI(Combat, MinHastedDelay), speed), true, true); - - if (i == MainPrimary) - PrimaryWeapon = ItemToUse; } } @@ -5044,7 +5029,7 @@ void NPC::SetAttackTimer() //special offhand stuff if (i == MainSecondary) { - if(!CanThisClassDualWield()) { + if(!CanThisClassDualWield() || HasTwoHanderEquipped()) { attack_dw_timer.Disable(); continue; } @@ -5085,14 +5070,8 @@ void Client::DoAttackRounds(Mob *target, int hand, bool IsFromSpell) } auto extraattackchance = aabonuses.ExtraAttackChance + spellbonuses.ExtraAttackChance + itembonuses.ExtraAttackChance; - if (extraattackchance) { - auto wpn = GetInv().GetItem(MainPrimary); - if (wpn && (wpn->GetItem()->ItemType == ItemType2HBlunt || - wpn->GetItem()->ItemType == ItemType2HSlash || - wpn->GetItem()->ItemType == ItemType2HPiercing)) - if (zone->random.Roll(extraattackchance)) - Attack(target, hand, false, false, IsFromSpell); - } + if (extraattackchance && HasTwoHanderEquipped() && zone->random.Roll(extraattackchance)) + Attack(target, hand, false, false, IsFromSpell); } } diff --git a/zone/bonuses.cpp b/zone/bonuses.cpp index 1e719dceb..155dfc4ae 100644 --- a/zone/bonuses.cpp +++ b/zone/bonuses.cpp @@ -141,6 +141,7 @@ void Client::CalcItemBonuses(StatBonuses* newbon) { ClearItemFactionBonuses(); SetShieldEquiped(false); SetTwoHandBluntEquiped(false); + SetTwoHanderEquipped(false); unsigned int i; //should not include 21 (SLOT_AMMO) @@ -154,8 +155,11 @@ void Client::CalcItemBonuses(StatBonuses* newbon) { const Item_Struct *item = inst->GetItem(); if (i == MainSecondary && (item && item->ItemType == ItemTypeShield)) SetShieldEquiped(true); - else if (i == MainPrimary && (item && item->ItemType == ItemType2HBlunt)) + else if (i == MainPrimary && (item && item->ItemType == ItemType2HBlunt)) { SetTwoHandBluntEquiped(true); + SetTwoHanderEquipped(true); + } else if (i == MainPrimary && (item && (item->ItemType == ItemType2HSlash || item->ItemType == ItemType2HPiercing))) + SetTwoHanderEquipped(true); } //Power Source Slot diff --git a/zone/loottables.cpp b/zone/loottables.cpp index e3014b12e..12766b57f 100644 --- a/zone/loottables.cpp +++ b/zone/loottables.cpp @@ -334,9 +334,11 @@ void NPC::AddLootDrop(const Item_Struct *item2, ItemList* itemlist, int16 charge eslot = MaterialPrimary; if (item2->Damage > 0) SendAddPlayerState(PlayerState::PrimaryWeaponEquipped); + if (item2->ItemType == ItemType2HBlunt || item2->ItemType == ItemType2HSlash || item2->ItemType == ItemType2HPiercing) + SetTwoHanderEquipped(true); } else if (foundslot == MainSecondary - && (GetOwner() != nullptr || (GetLevel() >= 13 && zone->random.Roll(NPC_DW_CHANCE)) || (item2->Damage==0)) && + && (GetOwner() != nullptr || (CanThisClassDualWield() && zone->random.Roll(NPC_DW_CHANCE)) || (item2->Damage==0)) && (item2->ItemType == ItemType1HSlash || item2->ItemType == ItemType1HBlunt || item2->ItemType == ItemTypeShield || item2->ItemType == ItemType1HPiercing)) { diff --git a/zone/mob.cpp b/zone/mob.cpp index ad0a60899..ce0a97db9 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -211,6 +211,7 @@ Mob::Mob(const char* in_name, trackable = true; has_shieldequiped = false; has_twohandbluntequiped = false; + has_twohanderequipped = false; has_numhits = false; has_MGB = false; has_ProjectIllusion = false; diff --git a/zone/mob.h b/zone/mob.h index 02d6d3e55..0094b0fbc 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -336,6 +336,8 @@ public: inline void SetShieldEquiped(bool val) { has_shieldequiped = val; } bool HasTwoHandBluntEquiped() const { return has_twohandbluntequiped; } inline void SetTwoHandBluntEquiped(bool val) { has_twohandbluntequiped = val; } + bool HasTwoHanderEquipped() { return has_twohanderequipped; } + void SetTwoHanderEquipped(bool val) { has_twohanderequipped = val; } virtual uint16 GetSkill(SkillUseTypes skill_num) const { return 0; } virtual uint32 GetEquipment(uint8 material_slot) const { return(0); } virtual int32 GetEquipmentMaterial(uint8 material_slot) const; @@ -1221,6 +1223,7 @@ protected: bool offhand; bool has_shieldequiped; bool has_twohandbluntequiped; + bool has_twohanderequipped; bool has_numhits; bool has_MGB; bool has_ProjectIllusion;