From cafd0eaba140714dd2f22248fb4aa7fc90b45024 Mon Sep 17 00:00:00 2001 From: KayenEQ Date: Wed, 4 Feb 2015 22:46:02 -0500 Subject: [PATCH] Added perl function function: CanClassEquipItem(item_id) Returns a bool if can equip or not. --- zone/mob.cpp | 23 +++++++++++++++++++++++ zone/mob.h | 1 + zone/perl_mob.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/zone/mob.cpp b/zone/mob.cpp index 68ed1e35d..5af690a64 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -5363,3 +5363,26 @@ int32 Mob::GetSpellStat(uint32 spell_id, const char *identifier, uint8 slot) return stat; } +bool Mob::CanClassEquipItem(uint32 item_id) +{ + const Item_Struct* itm = nullptr; + itm = database.GetItem(item_id); + + if (!itm) + return false; + + if(itm->Classes == 65535 ) + return true; + + if (GetClass() > 16) + return false; + + int bitmask = 1; + bitmask = bitmask << (GetClass() - 1); + + if(!(itm->Classes & bitmask)) + return false; + else + return true; +} + diff --git a/zone/mob.h b/zone/mob.h index c37eae706..330e8160e 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -315,6 +315,7 @@ public: virtual int32 GetHerosForgeModel(uint8 material_slot) const; virtual uint32 GetEquipmentColor(uint8 material_slot) const; virtual uint32 IsEliteMaterialItem(uint8 material_slot) const; + bool CanClassEquipItem(uint32 item_id); bool AffectedBySpellExcludingSlot(int slot, int effect); virtual bool Death(Mob* killerMob, int32 damage, uint16 spell_id, SkillUseTypes attack_skill) = 0; virtual void Damage(Mob* from, int32 damage, uint16 spell_id, SkillUseTypes attack_skill, diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index f72e98e43..a28d51376 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -8367,6 +8367,33 @@ XS(XS_Mob_ProcessSpecialAbilities) XSRETURN_EMPTY; } +XS(XS_Mob_CanClassEquipItem); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Mob_CanClassEquipItem) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Mob::CanClassEquipItem(THIS, item_id)"); + { + Mob * THIS; + bool RETVAL; + uint32 item_id = (uint32)SvUV(ST(1)); + + if (sv_derived_from(ST(0), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Mob *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Mob"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + RETVAL = THIS->CanClassEquipItem(item_id); + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + } + XSRETURN(1); +} + #ifdef __cplusplus extern "C" #endif @@ -8675,6 +8702,7 @@ XS(boot_Mob) newXSproto(strcpy(buf, "SetSpecialAbilityParam"), XS_Mob_SetSpecialAbilityParam, file, "$$$$"); newXSproto(strcpy(buf, "ClearSpecialAbilities"), XS_Mob_ClearSpecialAbilities, file, "$"); newXSproto(strcpy(buf, "ProcessSpecialAbilities"), XS_Mob_ProcessSpecialAbilities, file, "$$"); + newXSproto(strcpy(buf, "CanClassEquipItem"), XS_Mob_CanClassEquipItem, file, "$$"); XSRETURN_YES; }