Skip to content

Commit

Permalink
Add more core lib functions for ItemType
Browse files Browse the repository at this point in the history
  • Loading branch information
Codinablack committed Feb 16, 2025
1 parent 0aa8f11 commit 99a0363
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions data/lib/core/itemtype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,104 @@ end

function ItemType:isKey()
return self:getType() == ITEM_TYPE_KEY
end

function ItemType:isHelmet()
return self:usesSlot(CONST_SLOT_HEAD)
end

function ItemType:isArmor()
return self:usesSlot(CONST_SLOT_ARMOR)
end

function ItemType:isLegs()
return self:usesSlot(CONST_SLOT_LEGS)
end

function ItemType:isBoots()
return self:usesSlot(CONST_SLOT_FEET)
end

function ItemType:isWeapon()
local notWeapons = {WEAPON_NONE, WEAPON_SHIELD, WEAPON_AMMO}
return not table.contains(notWeapons, self:getWeaponType())
end

function ItemType:isTwoHanded()
return bit.band(self:getSlotPosition(), SLOTP_TWO_HAND) ~= 0
end

function ItemType:isBow()
local ammoType = self:getAmmoType()
return self:getWeaponType() == WEAPON_DISTANCE and (ammoType == AMMO_ARROW or ammoType == AMMO_BOLT)
end

function ItemType:isMissile()
local ammoType = self:getAmmoType()
return self:getWeaponType() == WEAPON_DISTANCE and ammoType ~= AMMO_ARROW and ammoType ~= AMMO_BOLT
end

function ItemType:isQuiver()
return self:getWeaponType() == WEAPON_QUIVER
end

function ItemType:isWand()
return self:getWeaponType() == WEAPON_WAND
end

function ItemType:isShield()
return self:getWeaponType() == WEAPON_SHIELD
end

function ItemType:isBackpack()
return self:usesSlot(CONST_SLOT_BACKPACK)
end

function ItemType:isNecklace()
return self:usesSlot(CONST_SLOT_NECKLACE)
end

function ItemType:isRing()
return self:usesSlot(CONST_SLOT_RING)
end

function ItemType:isAmmo()
return self:getWeaponType() == WEAPON_AMMO
end

function ItemType:isTrinket()
return self:usesSlot(CONST_SLOT_AMMO) and self:getWeaponType() == WEAPON_NONE
end

function ItemType:isBed()
return self:getType() == ITEM_TYPE_BED
end

function ItemType:isSplash()
return self:getGroup() == ITEM_GROUP_SPLASH
end

function ItemType:getWeaponString()
local weaponType = self:getWeaponType()
local weaponString = "unknown"

if weaponType == WEAPON_CLUB then
weaponString = "blunt instrument"
elseif weaponType == WEAPON_SWORD then
weaponString = "stabbing weapon"
elseif weaponType == WEAPON_AXE then
weaponString = "cutting weapon"
elseif weaponType == WEAPON_DISTANCE then
weaponString = self:isBow() and "firearm" or "missile"
elseif weaponType == WEAPON_WAND then
weaponString = "wand/rod"
elseif weaponType == WEAPON_QUIVER then
weaponString = "quiver"
end

if self:isTwoHanded() then
weaponString = string.format("%s, two-handed", weaponString)
end

return weaponString
end

0 comments on commit 99a0363

Please sign in to comment.