bool Totem::Create(uint32 guidlow, CreatureCreatePos& cPos, CreatureInfo const* cinfo, Unit* owner) { SetMap(cPos.GetMap()); Team team = owner->GetTypeId() == TYPEID_PLAYER ? ((Player*)owner)->GetTeam() : TEAM_NONE; if (!CreateFromProto(guidlow, cinfo, team)) return false; // special model selection case for totems if (owner->GetTypeId() == TYPEID_PLAYER) { if (uint32 modelid_race = sObjectMgr.GetModelForRace(GetNativeDisplayId(), owner->getRaceMask())) SetDisplayId(modelid_race); } cPos.SelectFinalPoint(this); // totem must be at same Z in case swimming caster and etc. if (fabs(cPos.m_pos.z - owner->GetPositionZ()) > 5.0f) cPos.m_pos.z = owner->GetPositionZ(); if (!cPos.Relocate(this)) return false; // Notify the map's instance data. // Only works if you create the object in it, not if it is moves to that map. // Normally non-players do not teleport to other maps. if (InstanceData* iData = GetMap()->GetInstanceData()) iData->OnCreatureCreate(this); LoadCreatureAddon(false); return true; }
void Pet::SavePetToDB(PetSaveMode mode) { if (!GetEntry()) return; // save only fully controlled creature if (!isControlled()) return; // not save not player pets if (!IS_PLAYER_GUID(GetOwnerGUID())) return; Player* owner = (Player*)GetOwner(); if (!owner) return; // not save pet as current if another pet temporary unsummoned if (mode == PET_SAVE_AS_CURRENT && owner->GetTemporaryUnsummonedPetNumber() && owner->GetTemporaryUnsummonedPetNumber() != m_charmInfo->GetPetNumber()) { // pet will lost anyway at restore temporary unsummoned if (getPetType() == HUNTER_PET) return; // for warlock case mode = PET_SAVE_NOT_IN_SLOT; } uint32 curhealth = GetHealth(); uint32 curmana = GetPower(POWER_MANA); SQLTransaction trans = CharacterDatabase.BeginTransaction(); // save auras before possibly removing them _SaveAuras(trans); // stable and not in slot saves if (mode > PET_SAVE_AS_CURRENT) RemoveAllAuras(); _SaveSpells(trans); _SaveSpellCooldowns(trans); CharacterDatabase.CommitTransaction(trans); // current/stable/not_in_slot if (mode >= PET_SAVE_AS_CURRENT) { uint32 ownerLowGUID = GUID_LOPART(GetOwnerGUID()); std::string name = m_name; CharacterDatabase.EscapeString(name); trans = CharacterDatabase.BeginTransaction(); // remove current data trans->PAppend("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", ownerLowGUID, m_charmInfo->GetPetNumber()); // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) if (mode <= PET_SAVE_LAST_STABLE_SLOT) trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND slot = '%u'", PET_SAVE_NOT_IN_SLOT, ownerLowGUID, uint32(mode)); // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT if (getPetType() == HUNTER_PET && (mode == PET_SAVE_AS_CURRENT || mode > PET_SAVE_LAST_STABLE_SLOT)) trans->PAppend("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '%u' OR slot > '%u')", ownerLowGUID, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT); // save pet std::ostringstream ss; ss << "INSERT INTO character_pet (id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType) " << "VALUES (" << m_charmInfo->GetPetNumber() << ',' << GetEntry() << ',' << ownerLowGUID << ',' << GetNativeDisplayId() << ',' << uint32(getLevel()) << ',' << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ',' << uint32(GetReactState()) << ',' << uint32(mode) << ", '" << name.c_str() << "', " << uint32(HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ? 0 : 1) << ',' << curhealth << ',' << curmana << ',' << GetPower(POWER_HAPPINESS) << ", '"; for (uint32 i = ACTION_BAR_INDEX_START; i < ACTION_BAR_INDEX_END; ++i) { ss << uint32(m_charmInfo->GetActionBarEntry(i)->GetType()) << ' ' << uint32(m_charmInfo->GetActionBarEntry(i)->GetAction()) << ' '; }; ss << "', " << time(NULL) << ',' << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ',' << uint32(getPetType()) << ')'; trans->Append(ss.str().c_str()); CharacterDatabase.CommitTransaction(trans); } // delete else { RemoveAllAuras(); DeleteFromDB(m_charmInfo->GetPetNumber()); } }