WorldObject* LootObject::GetWorldObject(Player* bot) { Refresh(bot, guid); PlayerbotAI* ai = bot->GetPlayerbotAI(); Creature *creature = ai->GetCreature(guid); if (creature && creature->getDeathState() == CORPSE) return creature; GameObject* go = ai->GetGameObject(guid); if (go && go->isSpawned()) return go; return NULL; }
void LootObject::Refresh(Player* bot, ObjectGuid guid) { skillId = SKILL_NONE; reqSkillValue = 0; reqItem = NULL; this->guid = ObjectGuid(); PlayerbotAI* ai = bot->GetPlayerbotAI(); Creature *creature = ai->GetCreature(guid); if (creature && creature->getDeathState() == CORPSE) { if (creature->HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE)) this->guid = guid; if (creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE)) { skillId = creature->GetCreatureTemplate()->GetRequiredLootSkill(); uint32 targetLevel = creature->getLevel(); reqSkillValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel - 10) * 10 : targetLevel * 5; if (bot->HasSkill(skillId) && bot->GetSkillValue(skillId) >= reqSkillValue) this->guid = guid; } return; } GameObject* go = ai->GetGameObject(guid); if (go && go->isSpawned()) { uint32 lockId = go->GetGOInfo()->GetLockId(); LockEntry const *lockInfo = sLockStore.LookupEntry(lockId); if (!lockInfo) return; // TODO: remove? /*for(uint32 i = 0; i < 6; ++i) { if (go->GetGOInfo()->questItems[i]) { this->guid = guid; return; } }*/ for (int i = 0; i < 8; ++i) { switch (lockInfo->Type[i]) { case LOCK_KEY_ITEM: if (lockInfo->Index[i] > 0) { reqItem = lockInfo->Index[i]; this->guid = guid; } break; case LOCK_KEY_SKILL: if (SkillByLockType(LockType(lockInfo->Index[i])) > 0) { skillId = SkillByLockType(LockType(lockInfo->Index[i])); reqSkillValue = lockInfo->Skill[i]; this->guid = guid; } break; default: break; } } } }