Enhance some methods for checking weapons to allow for Titan's Grip.
Johnny C. Lam [05-22-14 - 12:37]
Enhance some methods for checking weapons to allow for Titan's Grip.
Titan's Grip allows for a 2H weapon to be equipped in the off-hand. Add
extra parameters to HasOneHandedWeapon() and HasTwoHandedWeapon() to allow
checking in a specific weapon slot, and to HasMainHandWeapon() and
HasOffHandWeapon() to allow checking explicitly for either a 1H or 2H
weapon.
Give HasWeapon() condition an extra paramter "type=value" where value is
"1h" or "2h" to allow checking explicitly for a 1H or 2H weapon in the
given hand.
git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1490 d5049fe3-3747-40f7-a4b5-f36d6801af5f
diff --git a/OvaleEquipement.lua b/OvaleEquipement.lua
index a4296c1..761b891 100644
--- a/OvaleEquipement.lua
+++ b/OvaleEquipement.lua
@@ -73,7 +73,6 @@ local OVALE_SLOTNAME = {
LegsSlot = true,
MainHandSlot = true,
NeckSlot = true,
- RangedSlot = true,
SecondaryHandSlot = true,
ShirtSlot = true,
ShoulderSlot = true,
@@ -83,6 +82,11 @@ local OVALE_SLOTNAME = {
WaistSlot = true,
WristSlot = true,
}
+do
+ for slotName in pairs(OVALE_SLOTNAME) do
+ OVALE_SLOTNAME[slotName] = API_GetInventorySlotInfo(slotName)
+ end
+end
-- slots that can contain pieces from armor sets
local OVALE_ARMORSET_SLOT_IDS = { INVSLOT_CHEST, INVSLOT_HAND, INVSLOT_HEAD, INVSLOT_LEGS, INVSLOT_SHOULDER }
-- database of armor set items: OVALE_ARMORSET[itemId] = armorSetName
@@ -457,27 +461,28 @@ do
end
function OvaleEquipement:GetEquippedItem(slotId)
- if type(slotId) ~= "number" then
- if not OVALE_SLOTNAME[slotId] then return nil end
- slotId = API_GetInventorySlotInfo(slotId)
- if not slotId then return nil end
+ if slotId and type(slotId) ~= "number" then
+ slotId = OVALE_SLOTNAME[slotId]
end
- return self.equippedItems[slotId]
+ if slotId then
+ return self.equippedItems[slotId]
+ end
+ return nil
end
function OvaleEquipement:GetEquippedItemLevel(slotId)
- if type(slotId) ~= "number" then
- if not OVALE_SLOTNAME[slotId] then return nil end
- slotId = API_GetInventorySlotInfo(slotId)
- if not slotId then return nil end
+ if slotId and type(slotId) ~= "number" then
+ slotId = OVALE_SLOTNAME[slotId]
end
- return self.equippedItemLevels[slotId]
+ if slotId then
+ return self.equippedItemLevels[slotId]
+ end
+ return nil
end
function OvaleEquipement:HasEquippedItem(itemId, slotId)
if slotId and type(slotId) ~= "number" then
- if not OVALE_SLOTNAME[slotId] then return nil end
- slotId = API_GetInventorySlotInfo(slotId)
+ slotId = OVALE_SLOTNAME[slotId]
end
if slotId then
if self.equippedItems[slotId] == itemId then
@@ -493,15 +498,38 @@ function OvaleEquipement:HasEquippedItem(itemId, slotId)
return nil
end
-function OvaleEquipement:HasMainHandWeapon()
- return self.mainHandItemType == "INVTYPE_WEAPON"
- or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
- or self.mainHandItemType == "INVTYPE_2HWEAPON"
+function OvaleEquipement:HasMainHandWeapon(handedness)
+ if handedness then
+ if handedness == 1 then
+ return self.mainHandItemType == "INVTYPE_WEAPON"
+ or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
+ elseif handedness == 2 then
+ return self.mainHandItemType == "INVTYPE_2HWEAPON"
+ end
+ else
+ return self.mainHandItemType == "INVTYPE_WEAPON"
+ or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
+ or self.mainHandItemType == "INVTYPE_2HWEAPON"
+ end
+ return false
end
-function OvaleEquipement:HasOffHandWeapon()
- return self.offHandItemType == "INVTYPE_WEAPON"
- or self.offHandItemType == "INVTYPE_WEAPONOFFHAND"
+function OvaleEquipement:HasOffHandWeapon(handedness)
+ if handedness then
+ if handedness == 1 then
+ return self.offHandItemType == "INVTYPE_WEAPON"
+ or self.offHandItemType == "INVTYPE_WEAPONOFFHAND"
+ or self.offHandItemType == "INVTYPE_WEAPONMAINHAND"
+ elseif handedness == 2 then
+ return self.offHandItemType == "INVTYPE_2HWEAPON"
+ end
+ else
+ return self.offHandItemType == "INVTYPE_WEAPON"
+ or self.offHandItemType == "INVTYPE_WEAPONOFFHAND"
+ or self.offHandItemType == "INVTYPE_WEAPONMAINHAND"
+ or self.offHandItemType == "INVTYPE_2HWEAPON"
+ end
+ return false
end
function OvaleEquipement:HasShield()
@@ -513,13 +541,37 @@ function OvaleEquipement:HasTrinket(itemId)
or self:HasEquippedItem(itemId, INVSLOT_TRINKET2)
end
-function OvaleEquipement:HasTwoHandedWeapon()
- return self.mainHandItemType == "INVTYPE_2HWEAPON"
+function OvaleEquipement:HasTwoHandedWeapon(slotId)
+ if slotId and type(slotId) ~= "number" then
+ slotId = OVALE_SLOTNAME[slotId]
+ end
+ if slotId then
+ if slotId == INVSLOT_MAINHAND then
+ return self.mainHandItemType == "INVTYPE_2HWEAPON"
+ elseif slotId == INVSLOT_OFFHAND then
+ return self.offHandItemType == "INVTYPE_2HWEAPON"
+ end
+ else
+ return self.mainHandItemType == "INVTYPE_2HWEAPON" or self.offHandItemType == "INVTYPE_2HWEAPON"
+ end
+ return false
end
-function OvaleEquipement:HasOneHandedWeapon()
- return self.mainHandItemType == "INVTYPE_WEAPON"
- or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
+function OvaleEquipement:HasOneHandedWeapon(slotId)
+ if slotId and type(slotId) ~= "number" then
+ slotId = OVALE_SLOTNAME[slotId]
+ end
+ if slotId then
+ if slotId == INVSLOT_MAINHAND then
+ return self.mainHandItemType == "INVTYPE_WEAPON" or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
+ elseif slotId == INVSLOT_OFFHAND then
+ return self.offHandItemType == "INVTYPE_WEAPON" or self.offHandItemType == "INVTYPE_WEAPONMAINHAND"
+ end
+ else
+ return self.mainHandItemType == "INVTYPE_WEAPON" or self.mainHandItemType == "INVTYPE_WEAPONMAINHAND"
+ or self.offHandItemType == "INVTYPE_WEAPON" or self.offHandItemType == "INVTYPE_WEAPONMAINHAND"
+ end
+ return false
end
function OvaleEquipement:UpdateArmorSetCount()
diff --git a/conditions/HasWeapon.lua b/conditions/HasWeapon.lua
index 5227dcf..c2d59c7 100644
--- a/conditions/HasWeapon.lua
+++ b/conditions/HasWeapon.lua
@@ -23,17 +23,26 @@ do
-- @param yesno Optional. If yes, then return true if the weapon is equipped. If no, then return true if it isn't equipped.
-- Default is yes.
-- Valid values: yes, no.
+ -- @param type Optional. If set via type=value, then specify whether the weapon must be one-handed or two-handed.
+ -- Default is unset.
+ -- Valid values: 1h, 2h
-- @return A boolean value.
-- @usage
-- if HasWeapon(offhand) and BuffStacks(killing_machine) Spell(frost_strike)
local function HasWeapon(condition)
local hand, yesno = condition[1], condition[2]
+ local weaponType = condition.type
local boolean = false
+ if weaponType == "1h" then
+ weaponType = 1
+ elseif weaponType == "2h" then
+ weaponType = 2
+ end
if hand == "offhand" or hand == "off" then
- boolean = OvaleEquipement:HasOffHandWeapon()
+ boolean = OvaleEquipement:HasOffHandWeapon(weaponType)
elseif hand == "mainhand" or hand == "main" then
- boolean = OvaleEquipement:HasMainHandWeapon()
+ boolean = OvaleEquipement:HasMainHandWeapon(weaponType)
end
return TestBoolean(boolean, yesno)
end