void GameObject::Update(uint32 p_time) { if(m_event_Instanceid != m_instanceId) { event_Relocate(); return; } if(!IsInWorld()) return; if(m_deleted) return; if(spell && (GetUInt32Value(GAMEOBJECT_STATE) == 1)) { if(checkrate > 1) { if(counter++%checkrate) return; } ObjectSet::iterator itr = GetInRangeSetBegin(); ObjectSet::iterator it2 = itr; ObjectSet::iterator iend = GetInRangeSetEnd(); Unit * pUnit; float dist; this->AquireInrangeLock(); //make sure to release lock before exit function ! for(; it2 != iend;) { itr = it2; ++it2; dist = GetDistanceSq((*itr)); if( (*itr) != m_summoner && (*itr)->IsUnit() && dist <= range) { pUnit = static_cast<Unit*>(*itr); if(m_summonedGo) { if(!m_summoner) { ExpireAndDelete(); return; } if(!isAttackable(m_summoner,pUnit))continue; } Spell * sp=SpellPool.PooledNew(); sp->Init((Object*)this,spell,true,NULL); SpellCastTargets tgt((*itr)->GetGUID()); tgt.m_destX = GetPositionX(); tgt.m_destY = GetPositionY(); tgt.m_destZ = GetPositionZ(); sp->prepare(&tgt); // proc on trap trigger if( pInfo->Type == GAMEOBJECT_TYPE_TRAP ) { if( m_summoner != NULL ) m_summoner->HandleProc( PROC_ON_TRAP_TRIGGER, pUnit, spell ); } if(m_summonedGo) { ExpireAndDelete(); this->ReleaseInrangeLock(); return; } if(spell->EffectImplicitTargetA[0] == 16 || spell->EffectImplicitTargetB[0] == 16) { this->ReleaseInrangeLock(); return; // on area dont continue. } } } this->ReleaseInrangeLock(); } }
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) { // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HIGHGUID_ITEM); bool delete_result = false; if(!result) { result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid); delete_result = true; } if (!result) { sLog.outError("Item (GUID: %u owner: %u) not found in table `item_instance`, can't load. ",guid,GUID_LOPART(owner_guid)); return false; } Field *fields = result->Fetch(); if(!LoadValues(fields[0].GetString())) { sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.",guid); if (delete_result) delete result; return false; } bool need_save = false; // need explicit save data at load fixes // overwrite possible wrong/corrupted guid uint64 new_item_guid = MAKE_NEW_GUID(guid,0, HIGHGUID_ITEM); if(GetUInt64Value(OBJECT_FIELD_GUID) != new_item_guid) { SetUInt64Value(OBJECT_FIELD_GUID, MAKE_NEW_GUID(guid,0, HIGHGUID_ITEM)); need_save = true; } if (delete_result) delete result; ItemPrototype const* proto = GetProto(); if(!proto) return false; // update max durability (and durability) if need if(proto->MaxDurability!= GetUInt32Value(ITEM_FIELD_MAXDURABILITY)) { SetUInt32Value(ITEM_FIELD_MAXDURABILITY,proto->MaxDurability); if(GetUInt32Value(ITEM_FIELD_DURABILITY) > proto->MaxDurability) SetUInt32Value(ITEM_FIELD_DURABILITY,proto->MaxDurability); need_save = true; } // recalculate suffix factor if(GetItemRandomPropertyId() < 0) { if(UpdateItemSuffixFactor()) need_save = true; } // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS,ITEM_FLAGS_BINDED, false); need_save = true; } // update duration if need, and remove if not need if ((proto->Duration == 0) != (GetUInt32Value(ITEM_FIELD_DURATION) == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration); need_save = true; } // set correct owner if (owner_guid != 0 && GetOwnerGUID() != owner_guid) { SetOwnerGUID(owner_guid); need_save = true; } if (need_save) // normal item changed state set not work at loading { std::ostringstream ss; ss << "UPDATE item_instance SET data = '"; for(uint16 i = 0; i < m_valuesCount; ++i ) ss << GetUInt32Value(i) << " "; ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID()) << "' WHERE guid = '" << guid << "'"; CharacterDatabase.Execute( ss.str().c_str() ); } //Set extended cost for refundable item if(HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE)) { QueryResult *result_ext = CharacterDatabase.PQuery("SELECT ExtendedCost, price FROM item_instance WHERE guid = '%u'", guid); if(result_ext) { m_ExtendedCostId = result_ext->Fetch()[0].GetUInt32(); m_price = result_ext->Fetch()[1].GetUInt32(); delete result_ext; } } return true; }
bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry) { // 0 1 2 3 4 5 6 7 8 9 10 //result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text FROM item_instance WHERE guid = '%u'", guid); // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HighGuid::Item); // Set entry, MUST be before proto check SetEntry(entry); SetObjectScale(1.0f); ItemTemplate const* proto = GetTemplate(); if (!proto) return false; // set owner (not if item is only loaded for gbank/auction/mail if (owner_guid) SetOwnerGUID(owner_guid); bool need_save = false; // need explicit save data at load fixes SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HighGuid::Player, fields[0].GetUInt32())); SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid(HighGuid::Player, fields[1].GetUInt32())); SetCount(fields[2].GetUInt32()); uint32 duration = fields[3].GetUInt32(); SetUInt32Value(ITEM_FIELD_DURATION, duration); // update duration if need, and remove if not need if ((proto->Duration == 0) != (duration == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration); need_save = true; } Tokenizer tokens(fields[4].GetString(), ' ', MAX_ITEM_PROTO_SPELLS); if (tokens.size() == MAX_ITEM_PROTO_SPELLS) for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i, atoi(tokens[i])); SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32()); // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND, false); need_save = true; } std::string enchants = fields[6].GetString(); _LoadIntoDataField(enchants.c_str(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET); SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt16()); // recalculate suffix factor if (GetItemRandomPropertyId() < 0) UpdateItemSuffixFactor(); uint32 durability = fields[8].GetUInt16(); SetUInt32Value(ITEM_FIELD_DURABILITY, durability); // update max durability (and durability) if need SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); if (durability > proto->MaxDurability) { SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability); need_save = true; } SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32()); SetText(fields[10].GetString()); if (need_save) // normal item changed state set not work at loading { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_INSTANCE_ON_LOAD); stmt->setUInt32(0, GetUInt32Value(ITEM_FIELD_DURATION)); stmt->setUInt32(1, GetUInt32Value(ITEM_FIELD_FLAGS)); stmt->setUInt32(2, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(3, guid); CharacterDatabase.Execute(stmt); } return true; }
void Item::SaveToDB() { uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: { static SqlStatementID delItem ; static SqlStatementID insItem ; SqlStatement stmt = CharacterDatabase.CreateStatement(delItem, "DELETE FROM item_instance WHERE guid = ?"); stmt.PExecute(guid); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; stmt = CharacterDatabase.CreateStatement(insItem, "INSERT INTO item_instance (guid,owner_guid,data) VALUES (?, ?, ?)"); stmt.PExecute(guid, GetOwnerGuid().GetCounter(), ss.str().c_str()); } break; case ITEM_CHANGED: { static SqlStatementID updInstance ; static SqlStatementID updGifts ; SqlStatement stmt = CharacterDatabase.CreateStatement(updInstance, "UPDATE item_instance SET data = ?, owner_guid = ? WHERE guid = ?"); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; stmt.PExecute(ss.str().c_str(), GetOwnerGuid().GetCounter(), guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { stmt = CharacterDatabase.CreateStatement(updGifts, "UPDATE character_gifts SET guid = ? WHERE item_guid = ?"); stmt.PExecute(GetOwnerGuid().GetCounter(), GetGUIDLow()); } } break; case ITEM_REMOVED: { static SqlStatementID delItemText; static SqlStatementID delInst ; static SqlStatementID delGifts ; static SqlStatementID delLoot ; if (uint32 item_text_id = GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID)) { SqlStatement stmt = CharacterDatabase.CreateStatement(delItemText, "DELETE FROM item_text WHERE id = ?"); stmt.PExecute(item_text_id); } SqlStatement stmt = CharacterDatabase.CreateStatement(delInst, "DELETE FROM item_instance WHERE guid = ?"); stmt.PExecute(guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { stmt = CharacterDatabase.CreateStatement(delGifts, "DELETE FROM character_gifts WHERE item_guid = ?"); stmt.PExecute(GetGUIDLow()); } if (HasSavedLoot()) { stmt = CharacterDatabase.CreateStatement(delLoot, "DELETE FROM item_loot WHERE guid = ?"); stmt.PExecute(GetGUIDLow()); } delete this; return; } case ITEM_UNCHANGED: return; } if (m_lootState == ITEM_LOOT_CHANGED || m_lootState == ITEM_LOOT_REMOVED) { static SqlStatementID delLoot ; SqlStatement stmt = CharacterDatabase.CreateStatement(delLoot, "DELETE FROM item_loot WHERE guid = ?"); stmt.PExecute(GetGUIDLow()); } if (loot && (m_lootState == ITEM_LOOT_NEW || m_lootState == ITEM_LOOT_CHANGED)) { if (Player* owner = GetOwner()) { static SqlStatementID saveGold ; static SqlStatementID saveLoot ; // save money as 0 itemid data if (loot->GetGoldAmount()) { SqlStatement stmt = CharacterDatabase.CreateStatement(saveGold, "INSERT INTO item_loot (guid,owner_guid,itemid,amount,property) VALUES (?, ?, 0, ?, 0)"); stmt.PExecute(GetGUIDLow(), owner->GetGUIDLow(), loot->GetGoldAmount()); } SqlStatement stmt = CharacterDatabase.CreateStatement(saveLoot, "INSERT INTO item_loot (guid,owner_guid,itemid,amount,property) VALUES (?, ?, ?, ?, ?)"); // save items and quest items (at load its all will added as normal, but this not important for item loot case) LootItemList lootList; loot->GetLootItemsListFor(owner, lootList); for (LootItemList::const_iterator lootItr = lootList.begin(); lootItr != lootList.end(); ++lootItr) { LootItem* lootItem = *lootItr; stmt.addUInt32(GetGUIDLow()); stmt.addUInt32(owner->GetGUIDLow()); stmt.addUInt32(lootItem->itemId); stmt.addUInt8(lootItem->count); stmt.addInt32(lootItem->randomPropertyId); stmt.Execute(); } } } if (m_lootState != ITEM_LOOT_NONE && m_lootState != ITEM_LOOT_TEMPORARY) SetLootState(ITEM_LOOT_UNCHANGED); SetState(ITEM_UNCHANGED); }
void Item::SaveToDB(SQLTransaction& trans) { uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: case ITEM_CHANGED: { uint8 index = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_ADD_ITEM_INSTANCE : CHAR_UPDATE_ITEM_INSTANCE); stmt->setUInt32( index, GetEntry()); stmt->setUInt32(++index, GUID_LOPART(GetOwnerGUID())); stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR))); stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR))); stmt->setUInt32(++index, GetCount()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION)); std::ostringstream ssSpells; for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) ssSpells << GetSpellCharges(i) << " "; stmt->setString(++index, ssSpells.str()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS)); std::ostringstream ssEnchants; for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i) { ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << " "; ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << " "; ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << " "; } stmt->setString(++index, ssEnchants.str()); stmt->setInt32 (++index, GetItemRandomPropertyId()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME)); stmt->setString(++index, m_text); stmt->setUInt32(++index, guid); trans->Append(stmt); if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GIFT_OWNER); stmt->setUInt32(0, GUID_LOPART(GetOwnerGUID())); stmt->setUInt32(1, guid); trans->Append(stmt); } break; } case ITEM_REMOVED: { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE); stmt->setUInt32(0, guid); trans->Append(stmt); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); stmt->setUInt32(0, guid); trans->Append(stmt); } delete this; return; } case ITEM_UNCHANGED: break; } SetState(ITEM_UNCHANGED); }
void Creature::generateLoot() { memset(item_list, 0, 8*128); itemcount = 0; int LootValue = 0, MaxLootValue = 0; int itemsToGet = 0; int creature_level = getLevel(); if(creature_level < 10) { itemsToGet = rand()%2; } else if(creature_level < 25) { itemsToGet = rand()%3; } else if(creature_level < 40) { itemsToGet = rand()%4; } else if(creature_level < 60) { itemsToGet = rand()%5; } else if(creature_level < 80) { itemsToGet = rand()%6; } else { itemsToGet = rand()%7; } m_lootMoney = (uint32)(creature_level * (rand()%5 + 1)*sWorld.getRate(RATE_DROP)); if( itemsToGet == 0 ) return; MaxLootValue = (int)(((creature_level * (rand()%40+50))/5)*sWorld.getRate(RATE_DROP)+rand()%5+5); const LootMgr::LootList &loot_list(LootManager.getCreaturesLootList(GetUInt32Value(OBJECT_FIELD_ENTRY))); bool not_done = (loot_list.size() && itemsToGet); std::vector<short> indexes(loot_list.size()); std::generate(indexes.begin(), indexes.end(), SequenceGen()); sLog.outDebug("Number of items to get %d", itemsToGet); while (not_done) { int idx = rand()%indexes.size(); const LootItem &item(loot_list[indexes[idx]]); indexes.erase(indexes.begin()+idx); ItemPrototype *pCurItem = objmgr.GetItemPrototype(item.itemid); if( pCurItem != NULL && item.chance >= (rand()%100) ) { if( !(LootValue > MaxLootValue) ) { LootValue += pCurItem->BuyPrice; addItem(item.itemid, 1); --itemsToGet; } } not_done = (itemsToGet && indexes.size() && !(LootValue > MaxLootValue)); } }
void Item::SaveToDB() { uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: { static SqlStatementID delItem ; static SqlStatementID insItem ; SqlStatement stmt = CharacterDatabase.CreateStatement(delItem, "DELETE FROM item_instance WHERE guid = ?"); stmt.PExecute(guid); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; stmt = CharacterDatabase.CreateStatement(insItem, "INSERT INTO item_instance (guid,owner_guid,data) VALUES (?, ?, ?)"); stmt.PExecute(guid, GetOwnerGuid().GetCounter(), ss.str().c_str()); } break; case ITEM_CHANGED: { static SqlStatementID updInstance ; static SqlStatementID updGifts ; SqlStatement stmt = CharacterDatabase.CreateStatement(updInstance, "UPDATE item_instance SET data = ?, owner_guid = ? WHERE guid = ?"); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; stmt.PExecute(ss.str().c_str(), GetOwnerGuid().GetCounter(), guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { stmt = CharacterDatabase.CreateStatement(updGifts, "UPDATE character_gifts SET guid = ? WHERE item_guid = ?"); stmt.PExecute(GetOwnerGuid().GetCounter(), GetGUIDLow()); } } break; case ITEM_REMOVED: { static SqlStatementID delItemText; static SqlStatementID delInst ; static SqlStatementID delGifts ; static SqlStatementID delLoot ; if (uint32 item_text_id = GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID)) { SqlStatement stmt = CharacterDatabase.CreateStatement(delItemText, "DELETE FROM item_text WHERE id = ?"); stmt.PExecute(item_text_id); } SqlStatement stmt = CharacterDatabase.CreateStatement(delInst, "DELETE FROM item_instance WHERE guid = ?"); stmt.PExecute(guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { stmt = CharacterDatabase.CreateStatement(delGifts, "DELETE FROM character_gifts WHERE item_guid = ?"); stmt.PExecute(GetGUIDLow()); } if (HasSavedLoot()) { stmt = CharacterDatabase.CreateStatement(delLoot, "DELETE FROM item_loot WHERE guid = ?"); stmt.PExecute(GetGUIDLow()); } delete this; return; } case ITEM_UNCHANGED: return; } if (m_lootState == ITEM_LOOT_CHANGED || m_lootState == ITEM_LOOT_REMOVED) { static SqlStatementID delLoot ; SqlStatement stmt = CharacterDatabase.CreateStatement(delLoot, "DELETE FROM item_loot WHERE guid = ?"); stmt.PExecute(GetGUIDLow()); } if (m_lootState == ITEM_LOOT_NEW || m_lootState == ITEM_LOOT_CHANGED) { if (Player* owner = GetOwner()) { static SqlStatementID saveGold ; static SqlStatementID saveLoot ; // save money as 0 itemid data if (loot.gold) { SqlStatement stmt = CharacterDatabase.CreateStatement(saveGold, "INSERT INTO item_loot (guid,owner_guid,itemid,amount,property) VALUES (?, ?, 0, ?, 0)"); stmt.PExecute(GetGUIDLow(), owner->GetGUIDLow(), loot.gold); } SqlStatement stmt = CharacterDatabase.CreateStatement(saveLoot, "INSERT INTO item_loot (guid,owner_guid,itemid,amount,property) VALUES (?, ?, ?, ?, ?)"); // save items and quest items (at load its all will added as normal, but this not important for item loot case) for (size_t i = 0; i < loot.GetMaxSlotInLootFor(owner); ++i) { QuestItem* qitem = NULL; LootItem* item = loot.LootItemInSlot(i, owner, &qitem); if (!item) continue; // questitems use the blocked field for other purposes if (!qitem && item->is_blocked) continue; stmt.addUInt32(GetGUIDLow()); stmt.addUInt32(owner->GetGUIDLow()); stmt.addUInt32(item->itemid); stmt.addUInt8(item->count); stmt.addInt32(item->randomPropertyId); stmt.Execute(); } } } if (m_lootState != ITEM_LOOT_NONE && m_lootState != ITEM_LOOT_TEMPORARY) SetLootState(ITEM_LOOT_UNCHANGED); SetState(ITEM_UNCHANGED); }
void AreaTrigger::Update(uint32 p_time) { if (GetDuration() > int32(p_time)) _duration -= p_time; else Remove(); // expired WorldObject::Update(p_time); SpellInfo const* m_spellInfo = sSpellMgr->GetSpellInfo(GetUInt32Value(AREATRIGGER_SPELLID)); if (!m_spellInfo) return; if (!GetCaster()) { Remove(); return; } Unit* caster = GetCaster(); float radius = 0.0f; // Custom MoP Script switch (m_spellInfo->Id) { case 102793:// Ursol's Vortex { std::list<Unit*> targetList; radius = 8.0f; SurgeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) for (auto itr : targetList) if (!itr->HasAura(127797)) caster->CastSpell(itr, 127797, true); break; } case 115460:// Healing Sphere { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { caster->CastSpell(itr, 115464, true); // Healing Sphere heal SetDuration(0); return; } } break; } case 115817:// Cancel Barrier { std::list<Unit*> targetList; radius = 6.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) for (auto itr : targetList) itr->CastSpell(itr, 115856, true); break; } case 116011:// Rune of Power { std::list<Unit*> targetList; bool affected = false; radius = 2.25f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { if (itr->GetGUID() == caster->GetGUID()) { caster->CastSpell(itr, 116014, true); // Rune of Power affected = true; if (caster->ToPlayer()) caster->ToPlayer()->UpdateManaRegen(); return; } } } if (!affected) caster->RemoveAura(116014); break; } case 116235:// Amethyst Pool { std::list<Unit*> targetList; radius = 10.0f; SurgeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { // Amethyst Pool - Periodic Damage if (itr->GetDistance(this) > 3.5f) itr->RemoveAura(130774); else if (!itr->HasAura(130774)) caster->CastSpell(itr, 130774, true); } } break; } case 116546:// Draw Power { std::list<Unit*> targetList; radius = 30.0f; SurgeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); for (auto itr : targetList) { if (itr->IsInAxe(caster, this, 2.0f)) { if (!itr->HasAura(116663)) caster->AddAura(116663, itr); } else itr->RemoveAurasDueToSpell(116663); } break; } case 117032:// Healing Sphere (Afterlife) { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { if (itr->GetGUID() == caster->GetGUID()) { caster->CastSpell(itr, 125355, true); // Heal for 15% of life SetDuration(0); return; } } } break; } case 119031:// Gift of the Serpent (Mastery) { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { caster->CastSpell(itr, 124041, true); // Gift of the Serpent heal SetDuration(0); return; } } break; } case 121286:// Chi Sphere (Afterlife) { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { if (itr->GetGUID() == caster->GetGUID()) { caster->CastSpell(itr, 121283, true); // Restore 1 Chi SetDuration(0); return; } } } break; } case 121536:// Angelic Feather { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { caster->CastSpell(itr, 121557, true); // Angelic Feather increase speed SetDuration(0); return; } } break; } case 122035:// Path of Blossom { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::NearestAttackableUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::NearestAttackableUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); if (!targetList.empty()) { for (auto itr : targetList) { caster->CastSpell(itr, 122036, true); // Path of Blossom damage SetDuration(0); return; } } break; } case 124503:// Gift of the Ox case 124506:// Gift of the Ox² { std::list<Unit*> targetList; radius = 1.0f; SurgeCore::AnyFriendlyUnitInObjectRangeCheck u_check(this, caster, radius); SurgeCore::UnitListSearcher<SurgeCore::AnyFriendlyUnitInObjectRangeCheck> searcher(this, targetList, u_check); VisitNearbyObject(radius, searcher); for (auto itr : targetList) { if (itr->GetGUID() != caster->GetGUID()) continue; caster->CastSpell(itr, 124507, true); // Gift of the Ox - Heal SetDuration(0); return; } break; } default: break; } }
void Item::SaveToDB() { uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: { std::string text = m_text; CharacterDatabase.escape_string(text); CharacterDatabase.PExecute( "DELETE FROM item_instance WHERE guid = '%u'", guid ); std::ostringstream ss; ss << "INSERT INTO item_instance (guid,owner_guid,data,text) VALUES (" << guid << "," << GetOwnerGuid().GetCounter() << ",'"; for(uint16 i = 0; i < m_valuesCount; ++i ) ss << GetUInt32Value(i) << " "; ss << "', '" << text << "')"; CharacterDatabase.Execute( ss.str().c_str() ); } break; case ITEM_CHANGED: { std::string text = m_text; CharacterDatabase.escape_string(text); std::ostringstream ss; ss << "UPDATE item_instance SET data = '"; for(uint16 i = 0; i < m_valuesCount; ++i ) ss << GetUInt32Value(i) << " "; ss << "', owner_guid = '" << GetOwnerGuid().GetCounter(); ss << "', text = '" << text << "' WHERE guid = '" << guid << "'"; CharacterDatabase.Execute( ss.str().c_str() ); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GetOwnerGuid().GetCounter(), GetGUIDLow()); } break; case ITEM_REMOVED: { CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow()); if (HasSavedLoot()) CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u'", GetGUIDLow()); delete this; return; } case ITEM_UNCHANGED: return; } if (m_lootState == ITEM_LOOT_CHANGED || m_lootState == ITEM_LOOT_REMOVED) CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u'", GetGUIDLow()); if (m_lootState == ITEM_LOOT_NEW || m_lootState == ITEM_LOOT_CHANGED) { if(Player* owner = GetOwner()) { // save money as 0 itemid data if (loot.gold) CharacterDatabase.PExecute("INSERT INTO item_loot (guid,owner_guid,itemid,amount,suffix,property) " "VALUES (%u, %u, 0, %u, 0, 0)", GetGUIDLow(), owner->GetGUIDLow(), loot.gold); // save items and quest items (at load its all will added as normal, but this not important for item loot case) for (size_t i = 0; i < loot.GetMaxSlotInLootFor(owner); ++i) { QuestItem *qitem = NULL; LootItem *item = loot.LootItemInSlot(i,owner,&qitem); if(!item) continue; // questitems use the blocked field for other purposes if (!qitem && item->is_blocked) continue; CharacterDatabase.PExecute("INSERT INTO item_loot (guid,owner_guid,itemid,amount,suffix,property) " "VALUES (%u, %u, %u, %u, %u, %i)", GetGUIDLow(), owner->GetGUIDLow(), item->itemid, item->count, item->randomSuffix, item->randomPropertyId); } } } if (m_lootState != ITEM_LOOT_NONE && m_lootState != ITEM_LOOT_TEMPORARY) SetLootState(ITEM_LOOT_UNCHANGED); SetState(ITEM_UNCHANGED); }
void Vehicle::_AddToSlot(Unit* pPassenger, uint8 slot) { assert( slot < m_seatSlotMax ); if(pPassenger->IsPlayer() && TO_PLAYER(pPassenger)->m_CurrentCharm) return; if(pPassenger->IsPlayer() && TO_PLAYER(pPassenger)->m_isGmInvisible) { sChatHandler.GreenSystemMessage(TO_PLAYER(pPassenger)->GetSession(), "Please turn off invis before entering vehicle."); return; } CreatureProtoVehicle* vehicleproto = CreatureProtoVehicleStorage.LookupEntry(GetEntry()); m_passengers[slot] = pPassenger; LocationVector v; v.x = m_vehicleSeats[slot]->m_attachmentOffsetX; /* pPassenger->m_TransporterX = */ v.y = m_vehicleSeats[slot]->m_attachmentOffsetY; /* pPassenger->m_TransporterY = */ v.z = m_vehicleSeats[slot]->m_attachmentOffsetZ; /* pPassenger->m_TransporterZ = */ v.o = 0; /* pPassenger->m_TransporterO = */ //pPassenger->m_transportPosition =& v; // This is handled elsewhere, do not initialize here. pPassenger->movement_info.flags |= MOVEFLAG_TAXI; pPassenger->movement_info.transX = v.x; pPassenger->movement_info.transY = v.y; pPassenger->movement_info.transZ = v.z; pPassenger->movement_info.transO = GetOrientation(); pPassenger->movement_info.transSeat = slot; pPassenger->movement_info.transGuid = WoWGuid(GetGUID()); pPassenger->SetSeatID(slot); pPassenger->m_TransporterGUID = GetGUID(); if( m_CastSpellOnMount ) pPassenger->CastSpell( pPassenger, m_CastSpellOnMount, true ); RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SELF_RES); // This is where the real magic happens if( pPassenger->IsPlayer() ) { Player* pPlayer = TO_PLAYER(pPassenger); //pPlayer->Root(); //Dismount if(pPlayer->m_MountSpellId && pPlayer->m_MountSpellId != m_mountSpell) pPlayer->RemoveAura(pPlayer->m_MountSpellId); //Remove morph spells if(pPlayer->GetUInt32Value(UNIT_FIELD_DISPLAYID) != pPlayer->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)) { pPlayer->RemoveAllAurasOfType(SPELL_AURA_TRANSFORM); pPlayer->RemoveAllAurasOfType(SPELL_AURA_MOD_SHAPESHIFT); } //Dismiss any pets if(pPlayer->GetSummon()) { if(pPlayer->GetSummon()->GetUInt32Value(UNIT_CREATED_BY_SPELL) > 0) pPlayer->GetSummon()->Dismiss(false); // warlock summon -> dismiss else pPlayer->GetSummon()->Remove(false, true, true); // hunter pet -> just remove for later re-call } pPlayer->SetVehicle(this); pPlayer->SetUInt64Value(PLAYER_FARSIGHT, GetGUID()); pPlayer->SetPlayerStatus(TRANSFER_PENDING); sEventMgr.AddEvent(pPlayer, &Player::CheckPlayerStatus, (uint8)TRANSFER_PENDING, EVENT_PLAYER_CHECK_STATUS_Transfer, 5000, 0, 0); pPlayer->m_sentTeleportPosition.ChangeCoords(GetPositionX(), GetPositionY(), GetPositionZ()); WorldPacket data(SMSG_MONSTER_MOVE_TRANSPORT, 100); data << pPlayer->GetNewGUID(); // Passengerguid data << GetNewGUID(); // Transporterguid (vehicleguid) data << uint8(slot); // Vehicle Seat ID data << uint8(0); // Unknown data << GetPositionX() - pPlayer->GetPositionX(); // OffsetTransporterX data << GetPositionY() - pPlayer->GetPositionY(); // OffsetTransporterY data << GetPositionZ() - pPlayer->GetPositionZ(); // OffsetTransporterZ data << getMSTime(); // Timestamp data << uint8(0x04); // Flags data << float(0); // Orientation Offset data << uint32(MOVEFLAG_TB_MOVED); // MovementFlags data << uint32(0); // MoveTime data << uint32(1); // Points data << v.x; // GetTransOffsetX(); data << v.y; // GetTransOffsetY(); data << v.z; // GetTransOffsetZ(); SendMessageToSet(&data, true); if(vehicleproto) { // We have proto, no accessory in slot, and slot sets unselectable, unlike some seats if(!vehicleproto->seats[slot].accessoryentry && vehicleproto->seats[slot].unselectableaccessory) pPlayer->SetFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION | UNIT_FLAG_NOT_SELECTABLE)); } else pPlayer->SetFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION | UNIT_FLAG_NOT_SELECTABLE)); if(slot == 0) { if(m_vehicleSeats[slot]->IsControllable()) { m_redirectSpellPackets = pPlayer; SetSpeed(RUN, m_runSpeed); SetSpeed(FLY, m_flySpeed); // send "switch mover" packet data.Initialize(SMSG_CLIENT_CONTROL_UPDATE); data << GetNewGUID() << uint8(1); pPlayer->GetSession()->SendPacket(&data); pPlayer->m_CurrentCharm = TO_UNIT(this); pPlayer->SetUInt64Value(UNIT_FIELD_CHARM, GetGUID()); SetUInt64Value(UNIT_FIELD_CHARMEDBY, pPlayer->GetGUID()); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED_CREATURE); if(!m_faction || m_faction->ID == 35 || m_faction->ID == 2105) { SetCharmTempVal(pPlayer->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE)); SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, pPlayer->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE)); } if(vehicleproto && vehicleproto->healthfromdriver) { uint32 health = GetUInt32Value(UNIT_FIELD_HEALTH); uint32 maxhealth = GetUInt32Value(UNIT_FIELD_MAXHEALTH); uint32 healthdiff = maxhealth - health; SetUInt32Value(UNIT_FIELD_MAXHEALTH, (maxhealth+((pPlayer->GetTotalItemLevel())*(vehicleproto->healthunitfromitemlev)))); SetUInt32Value(UNIT_FIELD_HEALTH, (health+((pPlayer->GetTotalItemLevel())*(vehicleproto->healthunitfromitemlev))) - healthdiff); } SendSpells(GetEntry(), pPlayer); if(pPlayer->HasAura(62064)) { uint32 stack = pPlayer->FindActiveAura(62064)->stackSize; AddAura(new Aura(dbcSpell.LookupEntry(62064),-1,this,this)); FindActiveAura(62064)->ModStackSize(stack); } } } else { data.Initialize(SMSG_CLIENT_CONTROL_UPDATE); data << GetNewGUID() << uint8(0); pPlayer->GetSession()->SendPacket(&data); } data.Initialize(SMSG_PET_DISMISS_SOUND); data << uint32(m_vehicleSeats[slot]->m_enterUISoundID); data << pPlayer->GetPosition(); pPlayer->GetSession()->SendPacket(&data); ++m_ppassengerCount; } else { pPassenger->SetVehicle(this); if(vehicleproto != NULL) if(vehicleproto->seats[slot].accessoryentry == pPassenger->GetEntry()) if(vehicleproto->seats[slot].unselectableaccessory == true) pPassenger->SetFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION | UNIT_FLAG_NOT_SELECTABLE)); else pPassenger->SetFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION)); else pPassenger->SetFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION | UNIT_FLAG_NOT_SELECTABLE)); pPassenger->SetPosition(GetPositionX()+v.x, GetPositionY()+v.y, GetPositionZ()+v.z, GetOrientation()); } SendHeartBeatMsg(false); if(IsFull()) RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK); if(canFly()) EnableFlight(); _setFaction(); }
//----------------------------------------------------------------------------- void Unit::ApplyModifier(const Modifier *mod, bool apply, Affect* parent) { //Player * player; Creature * creature; Unit * unit; WorldPacket data; Unit * caster = WorldGetUnit (parent->GetCasterGUID()); if (caster != NULL && Call_Aura_ApplyModifier (mod->GetType(), caster, this, apply, mod->GetAmount(), mod->GetMiscValue(), mod->GetMiscValue2())) { sLog.outDebug ("ApplyModifier->SCRIPT: Type=%d Amount=%d V1=%d V2=%d", mod->GetType(), mod->GetAmount(), mod->GetMiscValue(), mod->GetMiscValue2()); return; } sLog.outDebug ("ApplyModifier: Type=%d Amount=%d V1=%d V2=%d", mod->GetType(), mod->GetAmount(), mod->GetMiscValue(), mod->GetMiscValue2()); switch(mod->GetType()) { case SPELL_AURA_NONE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_NONE"); break; } case SPELL_AURA_BIND_SIGHT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_BIND_SIGHT"); break; } case SPELL_AURA_MOD_THREAT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_THREAT"); break; } case SPELL_AURA_AURAS_VISIBLE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_AURAS_VISIBLE"); break; } case SPELL_AURA_MOD_RESISTANCE_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RESISTANCE_PCT"); break; } case SPELL_AURA_MOD_CREATURE_ATTACK_POWER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_CREATURE_ATTACK_POWER"); break; } case SPELL_AURA_MOD_TOTAL_THREAT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_TOTAL_THREAT"); break; } case SPELL_AURA_WATER_WALK: { apply ? data.Initialize(SMSG_MOVE_WATER_WALK) : data.Initialize(SMSG_MOVE_LAND_WALK); data << GetGUID(); SendMessageToSet(&data,true); break; } case SPELL_AURA_FEATHER_FALL: { apply ? data.Initialize(SMSG_MOVE_FEATHER_FALL) : data.Initialize(SMSG_MOVE_NORMAL_FALL); data << GetGUID(); SendMessageToSet(&data,true); break; } case SPELL_AURA_HOVER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_HOVER"); break; } case SPELL_AURA_ADD_FLAT_MODIFIER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_ADD_FLAT_MODIFIER"); break; } case SPELL_AURA_ADD_PCT_MODIFIER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_ADD_PCT_MODIFIER"); break; } case SPELL_AURA_ADD_TARGET_TRIGGER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_ADD_TARGET_TRIGGER"); break; } case SPELL_AURA_MOD_TAUNT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_TAUNT"); break; } case SPELL_AURA_MOD_POWER_REGEN_PERCENT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POWER_REGEN_PERCENT"); break; } case SPELL_AURA_ADD_CASTER_HIT_TRIGGER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_ADD_CASTER_HIT_TRIGGER"); break; } case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_OVERRIDE_CLASS_SCRIPTS"); break; } case SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN"); break; } case SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT"); break; } case SPELL_AURA_MOD_HEALING: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HEALING"); break; } case SPELL_AURA_IGNORE_REGEN_INTERRUPT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_IGNORE_REGEN_INTERRUPT"); break; } case SPELL_AURA_MOD_MECHANIC_RESISTANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_MECHANIC_RESISTANCE"); break; } case SPELL_AURA_MOD_HEALING_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HEALING_PCT"); break; } case SPELL_AURA_SHARE_PET_TRACKING: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_SHARE_PET_TRACKING"); break; } case SPELL_AURA_MOD_CONFUSE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_CONFUSE"); break; } case SPELL_AURA_MOD_STUN: { //sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_STUN"); if (apply) SetTarget (0); break; } case SPELL_AURA_UNTRACKABLE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_UNTRACKABLE"); break; } case SPELL_AURA_EMPATHY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_EMPATHY"); break; } case SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT"); break; } case SPELL_AURA_MOD_POWER_COST_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POWER_COST_PCT"); break; } case SPELL_AURA_MOD_RANGED_ATTACK_POWER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RANGED_ATTACK_POWER"); break; } case SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN"); break; } case SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT"); break; } case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS"); break; } case SPELL_AURA_MOD_POSSESS_PET: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POSSESS_PET"); break; } case SPELL_AURA_MOD_INCREASE_SPEED_ALWAYS: { unit = WorldGetUnit (GetGUID()); if (unit != NULL) { if (apply) unit->ModifySpeedMod (mod->GetAmount() / 100.0f); else { if (mod->GetAmount() != 0) unit->ModifySpeedMod (100.0f / mod->GetAmount()); else unit->SetSpeedMod (1.0f); } } else { sLog.outDebug ("ApplyModifier SPELL_AURA_MOD_INCREASE_SPEED_ALWAYS: Unit %X not found", GetGUIDLow()); } break; } case SPELL_AURA_MOD_DAMAGE_DONE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DAMAGE_DONE"); break; } case SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS"); break; } case SPELL_AURA_MOD_CREATURE_RANGED_ATTACK_POWER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_CREATURE_RANGED_ATTACK_POWER"); break; } case SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT: { uint32 percent = mod->GetAmount(); uint32 current = GetUInt32Value(UNIT_FIELD_POWER4); apply ? SetUInt32Value(UNIT_FIELD_POWER4,current+current/100*percent) : SetUInt32Value(UNIT_FIELD_POWER4,current-current/(100+percent)*100); break; } case SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT: { uint32 percent = mod->GetAmount(); uint32 current = GetUInt32Value(UNIT_FIELD_MAXHEALTH); apply ? SetUInt32Value(UNIT_FIELD_MAXHEALTH,current+current/100*percent) : SetUInt32Value(UNIT_FIELD_MAXHEALTH,current-current/(100+percent)*100); break; } case SPELL_AURA_MOD_MANA_REGEN_INTERRUPT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_MANA_REGEN_INTERRUPT"); break; } case SPELL_AURA_MOD_HEALING_DONE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HEALING_DONE"); break; } case SPELL_AURA_MOD_HEALING_DONE_PERCENT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HEALING_DONE_PERCENT"); break; } case SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE"); break; } case SPELL_AURA_MOD_HASTE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HASTE"); break; } case SPELL_AURA_FORCE_REACTION: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_FORCE_REACTION"); break; } case SPELL_AURA_MOD_DAMAGE_TAKEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DAMAGE_TAKEN"); break; } case SPELL_AURA_MOD_RANGED_HASTE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RANGED_HASTE"); break; } case SPELL_AURA_MOD_RANGED_AMMO_HASTE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RANGED_AMMO_HASTE"); break; } case SPELL_AURA_MOD_BASE_RESISTANCE_PCT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_BASE_RESISTANCE_PCT"); break; } case SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE"); break; } case SPELL_AURA_SAFE_FALL: { apply ? data.Initialize(SMSG_MOVE_FEATHER_FALL) : data.Initialize(SMSG_MOVE_NORMAL_FALL); data << GetGUID(); SendMessageToSet(&data,true); break; } case SPELL_AURA_CHARISMA: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_CHARISMA"); break; } case SPELL_AURA_PERSUADED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERSUADED"); break; } case SPELL_AURA_ADD_CREATURE_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_ADD_CREATURE_IMMUNITY"); break; } case SPELL_AURA_RETAIN_COMBO_POINTS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_RETAIN_COMBO_POINTS"); break; } case SPELL_AURA_DAMAGE_SHIELD: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_DAMAGE_SHIELD"); break; } case SPELL_AURA_MOD_STEALTH: { //sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_STEALTH"); // Convert float stored into integer field to normal view float amountf; *((int *)&amountf) = mod->GetAmount(); // Clip effective stealth level by spell level int amount = min (GetLevel() * 5, (int)amountf + 95); if (apply) m_stealthLevel += amount; else m_stealthLevel -= amount; sLog.outDebug ("ApplyModifier: STEALTH value set to %d", m_stealthLevel); break; } case SPELL_AURA_MOD_DETECT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DETECT"); break; } case SPELL_AURA_MOD_INVISIBILITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_INVISIBILITY"); break; } case SPELL_AURA_MOD_INVISIBILITY_DETECTION: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_INVISIBILITY_DETECTION"); break; } case SPELL_AURA_MOD_POSSESS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POSSESS"); break; } case SPELL_AURA_MOD_RESISTANCE: { uint16 index = 0; uint16 index2 = 0; switch(mod->GetMiscValue()) { case DMG_PHYSICAL: { index = UNIT_FIELD_RESISTANCES; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE; break; } case DMG_HOLY: { index = UNIT_FIELD_RESISTANCES + DMG_HOLY; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_HOLY : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_HOLY; break; } case DMG_FIRE: { index = UNIT_FIELD_RESISTANCES + DMG_FIRE; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_FIRE : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_FIRE; break; } case DMG_NATURE: { index = UNIT_FIELD_RESISTANCES + DMG_NATURE; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_NATURE : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_NATURE; break; } case DMG_FROST: { index = UNIT_FIELD_RESISTANCES + DMG_FROST; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_FROST : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_FROST; break; } case DMG_SHADOW:{ index = UNIT_FIELD_RESISTANCES + DMG_SHADOW; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_SHADOW : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_SHADOW; break; } case DMG_ARCANE:{ index = UNIT_FIELD_RESISTANCES + DMG_ARCANE; mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_RESISTANCEBUFFMODSPOSITIVE + DMG_ARCANE : index2 = PLAYER_FIELD_RESISTANCEBUFFMODSNEGATIVE + DMG_ARCANE; break; } default:{ sLog.outDetail ("WARNING: Misc Value for SPELL_AURA_MOD_STAT not valid\n"); return; break; } } if(apply){ SetUInt32Value(index,GetUInt32Value(index)+mod->GetAmount()); if (isPlayer()) SetUInt32Value(index2,GetUInt32Value(index2)+mod->GetAmount()); }else{ SetUInt32Value(index,GetUInt32Value(index)-mod->GetAmount()); if (isPlayer()) SetUInt32Value(index2,GetUInt32Value(index2)-mod->GetAmount()); } break; } case SPELL_AURA_PERIODIC_TRIGGER_SPELL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_TRIGGER_SPELL"); break; } case SPELL_AURA_PERIODIC_ENERGIZE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_ENERGIZE"); break; } case SPELL_AURA_MOD_PACIFY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_PACIFY"); break; } case SPELL_AURA_MOD_ROOT: { apply ? data.Initialize(MSG_MOVE_ROOT) : data.Initialize(MSG_MOVE_UNROOT); data << GetGUID(); SendMessageToSet(&data,true); break; } case SPELL_AURA_MOD_SILENCE: { apply ? m_silenced = true : m_silenced = false; break; } case SPELL_AURA_REFLECT_SPELLS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_REFLECT_SPELLS"); break; } case SPELL_AURA_MOD_STAT: { uint16 index = 0; uint16 index2 = 0; int32 v = mod->GetAmount(); switch(mod->GetMiscValue()) { case 0:{ //index = UNIT_FIELD_STAT0; ModifyStrength (apply ? v : -v); mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_POSSTAT0 : index2 = PLAYER_FIELD_NEGSTAT0; break; } case 1:{ //index = UNIT_FIELD_STAT1; ModifyAgility (apply ? v : -v); mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_POSSTAT1 : index2 = PLAYER_FIELD_NEGSTAT1; break; } case 2:{ //index = UNIT_FIELD_STAT2; ModifyStamina (apply ? v : -v); mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_POSSTAT2 : index2 = PLAYER_FIELD_NEGSTAT2; break; } case 3:{ //index = UNIT_FIELD_STAT3; ModifyIntellect (apply ? v : -v); mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_POSSTAT3 : index2 = PLAYER_FIELD_NEGSTAT3; break; } case 4:{ //index = UNIT_FIELD_STAT4; ModifySpirit (apply ? v : -v); mod->GetMiscValue2() == 0 ? index2 = PLAYER_FIELD_POSSTAT4 : index2 = PLAYER_FIELD_NEGSTAT4; break; } default:{ printf("WARNING: Misc Value for SPELL_AURA_MOD_STAT not valid\n"); return; break; } } if(apply){ if (isPlayer()) SetUInt32Value(index2,GetUInt32Value(index2) + v); }else{ if (isPlayer()) SetUInt32Value(index2,GetUInt32Value(index2) - v); } break; } case SPELL_AURA_PERIODIC_DAMAGE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_DAMAGE"); break; } case SPELL_AURA_MOD_SKILL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_SKILL"); break; } case SPELL_AURA_MOD_INCREASE_SPEED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_INCREASE_SPEED"); break; } case SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED: { if (GetUInt32Value(UNIT_FIELD_FLAGS) & UNIT_FLAG_MOUNTED ) { float newspeed = (float)mod->GetAmount() / 100.0f; newspeed = newspeed + 1.0f; sLog.outDebug("New Speed (With mount): %.1f", newspeed); unit = WorldGetUnit (GetGUID()); if (unit != NULL) unit->SetSpeedMod(newspeed); } else { unit = WorldGetUnit (GetGUID()); if (unit != NULL) unit->SetSpeedMod(1.0f); } sLog.outDebug ("ApplyModifier: SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED"); break; } case SPELL_AURA_MOD_DECREASE_SPEED: { unit = WorldGetUnit (GetGUID()); if (unit != NULL) { if (apply) unit->ModifySpeedMod (mod->GetAmount() / 100.0f); else { if (mod->GetAmount() != 0) unit->ModifySpeedMod (100.0f / mod->GetAmount()); else unit->SetSpeedMod (1.0f); } } break; } case SPELL_AURA_MOD_INCREASE_HEALTH: { uint32 newValue; newValue = GetUInt32Value(UNIT_FIELD_MAXHEALTH); apply ? newValue += mod->GetAmount() : newValue -= mod->GetAmount(); SetUInt32Value(UNIT_FIELD_MAXHEALTH,newValue); break; } case SPELL_AURA_MOD_INCREASE_ENERGY: { uint32 powerField = 23; uint8 powerType = (uint8)(GetUInt32Value(UNIT_FIELD_BYTES_0) >> 24); if(powerType == 0) // Mana powerField = UNIT_FIELD_POWER1; else if(powerType == 1) // Rage powerField = UNIT_FIELD_POWER2; else if(powerType == 3) // Energy powerField = UNIT_FIELD_POWER4; uint32 newValue = GetUInt32Value(powerType); apply ? newValue += mod->GetAmount() : newValue -= mod->GetAmount(); SetUInt32Value(powerType,newValue); break; } case SPELL_AURA_MOD_SHAPESHIFT: { Affect* tmpAff; uint32 spellId; switch(mod->GetMiscValue()) { case FORM_CAT: { spellId = 3025; break; } case FORM_TREE:{ spellId = 3122; break; } case FORM_TRAVEL:{ spellId = 5419; break; } case FORM_AQUA:{ spellId = 5421; break; } case FORM_BEAR:{ spellId = 1178; break; } case FORM_AMBIENT:{ spellId = 0; break; } case FORM_GHOUL:{ spellId = 0; break; } case FORM_DIREBEAR:{ spellId = 9635; break; } case FORM_CREATUREBEAR:{ spellId = 2882; break; } case FORM_GHOSTWOLF:{ spellId = 0; break; } case FORM_BATTLESTANCE:{ spellId = 2457; break; } case FORM_DEFENSIVESTANCE:{ spellId = 7376; break; } case FORM_BERSERKERSTANCE:{ spellId = 7381; break; } case FORM_SHADOW:{ spellId = 0; break; } case FORM_STEALTH:{ //spellId = 0; // Turn on Sneaky Stance, Switch stealth button to unstealth and switch spellbar SetUInt32Value (UNIT_FIELD_BYTES_1, apply? 0x021E0000: 0); if (apply == false && isPlayer()) { data.Initialize (SMSG_COOLDOWN_EVENT); data << (uint32)1784 << GetGUID(); ((Player*)this)->GetSession()->SendPacket (&data); } return; } default:{ printf("Unknown Shapeshift Type\n"); break; } } // check for spell id SpellEntry *spellInfo = sSpellStore.LookupEntry( spellId ); if(!spellInfo) { sLog.outError("WORLD: unknown spell id %i\n", spellId); break; } tmpAff = new Affect(spellInfo,parent->GetDuration(),parent->GetCasterGUID()); for(uint8 i=0; i<3; ++i){ if(spellInfo->Effect[i] == 6){ uint32 value = 0; uint32 type = 0; uint32 damage = 0; if(spellInfo->EffectBasePoints[i] < 0){ tmpAff->SetNegative(); type = 1; } uint32 sBasePoints = (uint32)sqrt((float)(spellInfo->EffectBasePoints[i]*spellInfo->EffectBasePoints[i])); if(spellInfo->EffectApplyAuraName[i] == 3){ // Periodic Trigger Damage damage = spellInfo->EffectBasePoints[i]+rand()%spellInfo->EffectDieSides[i]+1; //TODO: why the hell it takes uint16? tmpAff->SetDamagePerTick((uint16)damage, spellInfo->EffectAmplitude[i]); tmpAff->SetNegative(); }else if(spellInfo->EffectApplyAuraName[i] == 23)// Periodic Trigger Spell tmpAff->SetPeriodicTriggerSpell(spellInfo->EffectTriggerSpell[i],spellInfo->EffectAmplitude[i]); else{ if(spellInfo->EffectDieSides[i] != 0) value = sBasePoints+rand()%spellInfo->EffectDieSides[i]; else value = sBasePoints; if(spellInfo->EffectDieSides[i] <= 1) value += 1; //TODO: why the hell it takes uint8? tmpAff->AddMod((uint8)spellInfo->EffectApplyAuraName[i],value,spellInfo->EffectMiscValue[i],type); } } } if(tmpAff){ parent->SetCoAffect(tmpAff); AddAffect(tmpAff); } break; } case SPELL_AURA_EFFECT_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_EFFECT_IMMUNITY"); break; } case SPELL_AURA_STATE_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_STATE_IMMUNITY"); break; } case SPELL_AURA_SCHOOL_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_SCHOOL_IMMUNITY"); break; } case SPELL_AURA_DAMAGE_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_DAMAGE_IMMUNITY"); break; } case SPELL_AURA_DISPEL_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_DISPEL_IMMUNITY"); break; } case SPELL_AURA_PROC_TRIGGER_SPELL: { apply ? m_triggerSpell = mod->GetAmount() : m_triggerSpell = 0; break; } case SPELL_AURA_PROC_TRIGGER_DAMAGE: { apply ? m_triggerDamage = mod->GetAmount() : m_triggerDamage = 0; break; } case SPELL_AURA_TRACK_CREATURES: { apply ? SetUInt32Value(PLAYER_TRACK_CREATURES,mod->GetMiscValue()) : SetUInt32Value(PLAYER_TRACK_CREATURES,0); break; } case SPELL_AURA_TRACK_RESOURCES: { apply ? SetUInt32Value(PLAYER_TRACK_RESOURCES,mod->GetMiscValue()) : SetUInt32Value(PLAYER_TRACK_RESOURCES,0); break; } case SPELL_AURA_MOD_PARRY_SKILL: { break; } case SPELL_AURA_MOD_PARRY_PERCENT: { //uint32 current = GetUInt32Value(PLAYER_PARRY_PERCENTAGE); //apply ? SetUInt32Value(PLAYER_PARRY_PERCENTAGE,current+mod->GetAmount()) : SetUInt32Value(PLAYER_PARRY_PERCENTAGE,current-mod->GetAmount()); ModifyParryChance (apply ? mod->GetAmount() : -mod->GetAmount()); break; } case SPELL_AURA_MOD_DODGE_SKILL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DODGE_SKILL"); break; } case SPELL_AURA_MOD_DODGE_PERCENT: { //uint32 current = GetUInt32Value(PLAYER_DODGE_PERCENTAGE); //apply ? SetUInt32Value(PLAYER_DODGE_PERCENTAGE,current+mod->GetAmount()) : SetUInt32Value(PLAYER_DODGE_PERCENTAGE,current-mod->GetAmount()); ModifyDodgeChance (apply ? mod->GetAmount() : -mod->GetAmount()); break; } case SPELL_AURA_MOD_BLOCK_SKILL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_BLOCK_SKILL"); break; } case SPELL_AURA_MOD_BLOCK_PERCENT: { //uint32 current = GetUInt32Value(PLAYER_BLOCK_PERCENTAGE); //apply ? SetUInt32Value(PLAYER_BLOCK_PERCENTAGE,current+mod->GetAmount()) : SetUInt32Value(PLAYER_BLOCK_PERCENTAGE,current-mod->GetAmount()); ModifyBlockChance (apply ? mod->GetAmount() : -mod->GetAmount()); break; } case SPELL_AURA_MOD_CRIT_PERCENT: { //uint32 current = GetUInt32Value(PLAYER_CRIT_PERCENTAGE); //apply ? SetUInt32Value(PLAYER_CRIT_PERCENTAGE,current+mod->GetAmount()) : SetUInt32Value(PLAYER_CRIT_PERCENTAGE,current-mod->GetAmount()); ModifyCritChance (apply ? mod->GetAmount() : -mod->GetAmount()); break; } case SPELL_AURA_PERIODIC_LEECH: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_LEECH"); break; } case SPELL_AURA_MOD_HIT_CHANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_HIT_CHANCE"); break; } case SPELL_AURA_MOD_SPELL_HIT_CHANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_SPELL_HIT_CHANCE"); break; } case SPELL_AURA_TRANSFORM: { if (parent->GetId() == 118) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 228) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 304); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 851) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 4060) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 131); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 5254) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 12824) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 12825) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 12826) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 13323) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 15534) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 856); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } if (parent->GetId() == 17738) { if (apply) { //((Modifier *)mod)->SetValue1 (GetUInt32Value (UNIT_FIELD_DISPLAYID)); SetUInt32Value (UNIT_FIELD_DISPLAYID, 1141); } else { SetUInt32Value (UNIT_FIELD_DISPLAYID, GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID)); if (caster != NULL) AddHate (caster, 1.0f); } } break; } case SPELL_AURA_MOD_SPELL_CRIT_CHANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_SPELL_CRIT_CHANCE"); break; } case SPELL_AURA_MOD_INCREASE_SWIM_SPEED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_INCREASE_SWIM_SPEED"); break; } case SPELL_AURA_MOD_DAMAGE_DONE_CREATURE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DAMAGE_DONE_CREATURE"); break; } case SPELL_AURA_MOD_CHARM: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_CHARM"); break; } case SPELL_AURA_MOD_PACIFY_SILENCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_PACIFY_SILENCE"); break; } case SPELL_AURA_MOD_SCALE: { float current = GetFloatValue(OBJECT_FIELD_SCALE_X); apply ? SetFloatValue(OBJECT_FIELD_SCALE_X,current+current/100*10) : SetFloatValue(OBJECT_FIELD_SCALE_X,current-current/110*100); break; } case SPELL_AURA_PERIODIC_HEALTH_FUNNEL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_HEALTH_FUNNEL"); break; } case SPELL_AURA_PERIODIC_MANA_FUNNEL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_MANA_FUNNEL"); break; } case SPELL_AURA_PERIODIC_MANA_LEECH: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_MANA_LEECH"); break; } case SPELL_AURA_MOD_CASTING_SPEED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_CASTING_SPEED"); break; } case SPELL_AURA_FEIGN_DEATH: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_FEIGN_DEATH"); break; } case SPELL_AURA_MOD_DISARM: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DISARM"); break; } case SPELL_AURA_MOD_STALKED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_STALKED"); break; } case SPELL_AURA_SCHOOL_ABSORB: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_SCHOOL_ABSORB"); break; } case SPELL_AURA_MOD_FEAR: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_FEAR"); break; } case SPELL_AURA_EXTRA_ATTACKS: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_EXTRA_ATTACKS"); break; } case SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL"); break; } case SPELL_AURA_MOD_POWER_COST: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POWER_COST"); break; } case SPELL_AURA_MOD_POWER_COST_SCHOOL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POWER_COST_SCHOOL"); break; } case SPELL_AURA_REFLECT_SPELLS_SCHOOL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_REFLECT_SPELLS_SCHOOL"); break; } case SPELL_AURA_MOD_LANGUAGE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_LANGUAGE"); break; } case SPELL_AURA_FAR_SIGHT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_FAR_SIGHT"); break; } case SPELL_AURA_MECHANIC_IMMUNITY: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MECHANIC_IMMUNITY"); break; } case SPELL_AURA_MOUNTED: { sLog.outDebug ("ApplyModifier: SPELL_AURA_MOUNTED"); if (GetUInt32Value(UNIT_FIELD_FLAGS) & UNIT_FLAG_MOUNTED ) { SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID , 0); RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNTED ); // Remove the "player locked" flag, to allow movement if (GetUInt32Value(UNIT_FIELD_FLAGS) & UNIT_FLAG_LOCKED ) RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_LOCKED ); // Make sure we're standing ;) SetUInt32Value(UNIT_FIELD_BYTES_1, STANDSTATE_STAND); } else { // Set mount ID from creatures_templ CreatureTemplate *ptempl = objmgr.GetCreatureTemplate(mod->GetMiscValue(), true); SetUInt32Value( UNIT_FIELD_MOUNTDISPLAYID , ptempl->Model); //SetUInt32Value( UNIT_FIELD_FLAGS , UNIT_FLAG_MOUNTED ); SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNTED ); } break; } case SPELL_AURA_MOD_DAMAGE_PERCENT_DONE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DAMAGE_PERCENT_DONE"); break; } case SPELL_AURA_PERIODIC_HEAL: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_HEAL"); break; } case SPELL_AURA_MOD_PERCENT_STAT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_PERCENT_STAT"); break; } case SPELL_AURA_SPLIT_DAMAGE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_SPLIT_DAMAGE"); break; } case SPELL_AURA_WATER_BREATHING: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_WATER_BREATHING"); break; } case SPELL_AURA_MOD_BASE_RESISTANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_BASE_RESISTANCE"); break; } case SPELL_AURA_MOD_REGEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_REGEN"); break; } case SPELL_AURA_MOD_POWER_REGEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_POWER_REGEN"); break; } case SPELL_AURA_CHANNEL_DEATH_ITEM: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_CHANNEL_DEATH_ITEM"); break; } case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN"); break; } case SPELL_AURA_MOD_PERCENT_REGEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_PERCENT_REGEN"); break; } case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PERIODIC_DAMAGE_PERCENT"); break; } case SPELL_AURA_MOD_ATTACKSPEED: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_ATTACKSPEED"); break; } case SPELL_AURA_MOD_RESIST_CHANCE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_RESIST_CHANCE"); break; } case SPELL_AURA_MOD_DETECT_RANGE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_DETECT_RANGE"); break; } case SPELL_AURA_PREVENTS_FLEEING: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_PREVENTS_FLEEING"); break; } case SPELL_AURA_MOD_UNATTACKABLE: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_UNATTACKABLE"); break; } case SPELL_AURA_INTERRUPT_REGEN: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_INTERRUPT_REGEN"); break; } case SPELL_AURA_GHOST: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_GHOST"); break; } case SPELL_AURA_SPELL_MAGNET: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_SPELL_MAGNET"); break; } case SPELL_AURA_MANA_SHIELD: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MANA_SHIELD"); break; } case SPELL_AURA_MOD_SKILL_TALENT: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_SKILL_TALENT"); break; } case SPELL_AURA_MOD_ATTACK_POWER: { sLog.outDebug ("ApplyModifier: Unsupported SPELL_AURA_MOD_ATTACK_POWER"); break; } default: { sLog.outError("Unknown affect id %u", (uint32)mod->GetType()); } } }
void Vehicle::RemovePassenger(Unit* pPassenger) { if(pPassenger == NULL) // We have enough problems that we need to do this :( return; uint8 slot = pPassenger->GetSeatID(); pPassenger->SetVehicle(NULL); pPassenger->SetSeatID(NULL); pPassenger->RemoveFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_UNKNOWN_5 | UNIT_FLAG_PREPARATION | UNIT_FLAG_NOT_SELECTABLE)); if( pPassenger->IsPlayer() && TO_PLAYER(pPassenger)->m_MountSpellId != m_mountSpell ) pPassenger->RemoveAura(TO_PLAYER(pPassenger)->m_MountSpellId); if( m_mountSpell ) pPassenger->RemoveAura( m_mountSpell ); if( m_CastSpellOnMount ) pPassenger->RemoveAura( m_CastSpellOnMount ); WorldPacket data(SMSG_MONSTER_MOVE, 85); data << pPassenger->GetNewGUID(); // PlayerGUID data << uint8(0x40); // Unk - blizz uses 0x40 data << pPassenger->GetPosition(); // Player Position xyz data << getMSTime(); // Timestamp data << uint8(0x4); // Flags data << pPassenger->GetOrientation(); // Orientation data << uint32(MOVEFLAG_AIR_SUSPENSION); // MovementFlags data << uint32(0); // MovementTime data << uint32(1); // Pointcount data << GetPosition(); // Vehicle Position xyz SendMessageToSet(&data, false); pPassenger->movement_info.flags &= ~MOVEFLAG_TAXI; pPassenger->movement_info.transX = 0; pPassenger->movement_info.transY = 0; pPassenger->movement_info.transZ = 0; pPassenger->movement_info.transO = 0; pPassenger->movement_info.transTime = 0; pPassenger->movement_info.transSeat = 0; pPassenger->movement_info.transGuid = WoWGuid(uint64(NULL)); if(pPassenger->IsPlayer()) { Player* plr = TO_PLAYER(pPassenger); if(plr == GetControllingUnit()) { plr->m_CurrentCharm = NULL; data.Initialize(SMSG_CLIENT_CONTROL_UPDATE); data << GetNewGUID() << (uint8)0; plr->GetSession()->SendPacket(&data); } RemoveFlag(UNIT_FIELD_FLAGS, (UNIT_FLAG_PLAYER_CONTROLLED_CREATURE | UNIT_FLAG_PLAYER_CONTROLLED)); plr->SetPlayerStatus(TRANSFER_PENDING); // We get an ack later, if we don't set this now, we get disconnected. sEventMgr.AddEvent(plr, &Player::CheckPlayerStatus, (uint8)TRANSFER_PENDING, EVENT_PLAYER_CHECK_STATUS_Transfer, 5000, 0, 0); plr->m_sentTeleportPosition.ChangeCoords(GetPositionX(), GetPositionY(), GetPositionZ()); plr->SetPosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); data.Initialize(MSG_MOVE_TELEPORT_ACK); data << plr->GetNewGUID(); data << plr->m_teleportAckCounter; plr->m_teleportAckCounter++; data << uint32(MOVEFLAG_FLYING); data << uint16(0x40); data << getMSTime(); data << GetPositionX(); data << GetPositionY(); data << GetPositionZ(); data << GetOrientation(); data << uint32(0); plr->GetSession()->SendPacket(&data); plr->SetUInt64Value( PLAYER_FARSIGHT, 0 ); data.Initialize(SMSG_PET_DISMISS_SOUND); data << uint32(m_vehicleSeats[slot]->m_exitUISoundID); data << plr->GetPosition(); plr->GetSession()->SendPacket(&data); data.Initialize(SMSG_PET_SPELLS); data << uint64(0); data << uint32(0); plr->GetSession()->SendPacket(&data); CreatureProtoVehicle* vehicleproto = CreatureProtoVehicleStorage.LookupEntry(GetEntry()); if(vehicleproto && vehicleproto->healthfromdriver) { if(slot == 0) { uint32 health = GetUInt32Value(UNIT_FIELD_HEALTH); uint32 maxhealth = GetUInt32Value(UNIT_FIELD_MAXHEALTH); uint32 protomaxhealth = GetProto()->MaxHealth; uint32 healthdiff = maxhealth - health; uint32 plritemlevel = plr->GetTotalItemLevel(); uint32 convrate = vehicleproto->healthunitfromitemlev; if(plritemlevel != 0 && convrate != 0) { uint32 healthloss = healthdiff+plritemlevel*convrate; SetUInt32Value(UNIT_FIELD_HEALTH, GetProto()->MaxHealth - healthloss); } else if(protomaxhealth > healthdiff) SetUInt32Value(UNIT_FIELD_HEALTH, protomaxhealth-healthdiff); else SetUInt32Value(UNIT_FIELD_HEALTH, 1); SetUInt32Value(UNIT_FIELD_MAXHEALTH, protomaxhealth); } } } if(slot == 0) { m_redirectSpellPackets = NULLPLR; CombatStatus.Vanished(); pPassenger->SetUInt64Value( UNIT_FIELD_CHARM, 0 ); SetUInt64Value(UNIT_FIELD_CHARMEDBY, 0); if(!m_faction || m_faction->ID == 35 || m_faction->ID == 2105) SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, GetCharmTempVal()); RemoveAura(62064); } SendHeartBeatMsg(false); m_passengers[slot] = NULL; pPassenger->m_TransporterGUID = NULL; // We need to null this out if(pPassenger->IsPlayer()) --m_ppassengerCount; //note: this is not blizz like we should despawn //and respawn at spawn point. //Well actually this is how blizz wanted it //but they couldnt get it to work xD bool haspassengers = false; for(uint8 i = 0; i < m_seatSlotMax; i++) { if(m_passengers[i] != NULL && m_passengers[i]->IsPlayer()) { haspassengers = true; break; } } if(!haspassengers && !GetVehicle()) // Passenger and accessory checks. { if( m_spawn == NULL ) SafeDelete(); } if(!IsFull()) SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK); if(canFly()) DisableFlight(); _setFaction(); }
bool Item::IsRefundOrSoulboundTradeExpired(Player* owner) const { return GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + (2 * HOUR) < owner->GetTotalPlayedTime(); }
void GameObject::UseFishingNode(Player *player) { sEventMgr.RemoveEvents( this ); if( GetUInt32Value( GAMEOBJECT_FLAGS ) != 32 ) // Clicking on the bobber before something is hooked { player->GetSession()->OutPacket( SMSG_FISH_NOT_HOOKED ); EndFishing( player, true ); return; } /* Unused code: sAreaStore.LookupEntry(GetMapMgr()->GetAreaID(GetPositionX(),GetPositionY()))->ZoneId*/ uint32 zone = player->GetAreaID(); if( zone == 0 ) // If the player's area ID is 0, use the zone ID instead zone = player->GetZoneId(); FishingZoneEntry *entry = FishingZoneStorage.LookupEntry( zone ); if( entry == NULL ) // No fishing information found for area or zone, log an error, and end fishing { sLog.outError( "ERROR: Fishing zone information for zone %d not found!", zone ); EndFishing( player, true ); return; } uint32 maxskill = entry->MaxSkill; uint32 minskill = entry->MinSkill; if( player->_GetSkillLineCurrent( SKILL_FISHING, false ) < maxskill ) player->_AdvanceSkillLine( SKILL_FISHING, float2int32( 1.0f * sWorld.getRate( RATE_SKILLRATE ) ) ); GameObject * school = NULL; this->AquireInrangeLock(); //make sure to release lock before exit function ! for ( InRangeSet::iterator it = GetInRangeSetBegin(); it != GetInRangeSetEnd(); ++it ) { if ( (*it) == NULL || (*it)->GetTypeId() != TYPEID_GAMEOBJECT || (*it)->GetUInt32Value(GAMEOBJECT_TYPE_ID) != GAMEOBJECT_TYPE_FISHINGHOLE) continue; school = static_cast<GameObject *>( *it ); if ( !isInRange( school, (float)school->GetInfo()->sound1 ) ) { school = NULL; continue; } else break; } this->ReleaseInrangeLock(); if ( school != NULL ) // open school loot if school exists { lootmgr.FillGOLoot( &school->loot, school->GetEntry(), school->GetMapMgr() ? ( school->GetMapMgr()->iInstanceMode ? true : false ) : false ); player->SendLoot( school->GetGUID(), LOOT_FISHING ); EndFishing( player, false ); school->CatchFish(); if ( !school->CanFish() ) sEventMgr.AddEvent( school, &GameObject::Despawn, ( 1800000 + RandomUInt( 3600000 ) ), EVENT_GAMEOBJECT_EXPIRE, 10000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT ); // respawn in 30 - 90 minutes } else if( Rand( ( ( player->_GetSkillLineCurrent( SKILL_FISHING, true ) - minskill ) * 100 ) / maxskill ) ) // Open loot on success, otherwise FISH_ESCAPED. { lootmgr.FillFishingLoot( &loot, zone ); player->SendLoot( GetGUID(), LOOT_FISHING ); EndFishing( player, false ); } else // Failed { player->GetSession()->OutPacket( SMSG_FISH_ESCAPED ); EndFishing( player, true ); } }
void Item::SaveToDB( int16 containerslot, int16 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << (int32)GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << "," << random_suffix << ","; ss << GetTextID() << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); itr++) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 ) || ( itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ","; ss << uint32(itr->second.Dummy ? 1 : 0) << ";"; } } } ss << "','"; if(Gems[0] || Gems[1] || Gems[2]) { // We get socket. for(uint32 g = 0; g < 3; g++) { // Socket screen turn on. if(Gems[g]) { ss << g; // All your gem are belong to us. ss << ":" << Gems[g] << ";"; } } } ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
void Pet::CreateAsSummon(uint32 entry, CreatureInfo *ci, Creature* created_from_creature, Unit *owner, SpellEntry* created_by_spell, uint32 type, uint32 expiretime) { SetIsPet(true); std::string myname = sWorld.GenerateName(); if(!ci) return; m_Owner = static_cast<Player*>(owner); m_OwnerGuid = m_Owner->GetGUID(); // Create ourself Create(myname.c_str(), owner->GetMapId(), owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); creature_info = ci; SetUInt32Value(OBJECT_FIELD_ENTRY, entry); SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f); // better set this one // Fields common to both lock summons and pets if(type & 0x2 && created_from_creature != NULL) SetUInt32Value(UNIT_FIELD_LEVEL, created_from_creature->getLevel()); else SetUInt32Value(UNIT_FIELD_LEVEL,owner->GetUInt32Value(UNIT_FIELD_LEVEL)); SetUInt32Value(UNIT_FIELD_DISPLAYID, ci->DisplayID); SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, ci->DisplayID); SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()); SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID()); if(type & 0x1 && created_by_spell != NULL) SetUInt64Value(UNIT_CREATED_BY_SPELL, created_by_spell->Id); BaseStats[0] = uint32(20+getLevel()*1.55); BaseStats[1] = uint32(20+getLevel()*0.64); BaseStats[2] = uint32(20+getLevel()*1.27); BaseStats[3] = uint32(20+getLevel()*0.18); BaseStats[4] = uint32(20+getLevel()*0.36); if(type & 0x1 || created_from_creature == NULL) { Summon = true; float scale = 1.0f; switch(GetEntry()) { case 416: //Imp { scale = 0.4f; }break; case 417: //Felhunter { scale = 0.7f; }break; case 1860: //VoidWalker { scale = 0.75f; }break; case 1863: //Succubus { scale = 1.0f; }break; } SetFloatValue(OBJECT_FIELD_SCALE_X, scale); uint32 hp=uint32(28 + 10 * getLevel()); SetUInt32Value(UNIT_FIELD_MAXHEALTH, hp); SetUInt32Value(UNIT_FIELD_BASE_HEALTH,hp); uint32 mp=uint32(28 + 10 * getLevel()); SetUInt32Value(UNIT_FIELD_MAXPOWER1,mp ); SetUInt32Value(UNIT_FIELD_BASE_MANA,mp); SetFloatValue(OBJECT_FIELD_SCALE_X, scale); SetUInt32Value(UNIT_FIELD_BYTES_0, 2048 | (0 << 24)); SetUInt32Value(UNIT_FIELD_FLAGS, 8); SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, 2000); SetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01, 2000); SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.5f); SetFloatValue(UNIT_FIELD_COMBATREACH, 0.75f); SetFloatValue(UNIT_FIELD_MINDAMAGE,float(getLevel() * 1.88)); SetFloatValue(UNIT_FIELD_MAXDAMAGE,float(getLevel() * 3)); SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, float(GetFloatValue(UNIT_FIELD_MINDAMAGE)*0.5)); SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, float(GetFloatValue(UNIT_FIELD_MAXDAMAGE)*0.5)); SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,float((getLevel() * 1.88)/2)); SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,float((getLevel() * 3)/2)); SetUInt32Value(UNIT_FIELD_ATTACK_POWER, uint32(getLevel() * 1.7)); SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER, uint32(getLevel() * 2.4)); for(int x=0;x<5;x++) SetUInt32Value(UNIT_FIELD_STAT0 + x, BaseStats[x]); SetUInt32Value(UNIT_FIELD_RESISTANCES, 180); SetUInt32Value(UNIT_FIELD_BYTES_2, 0x01); SetUInt32Value(UNIT_FIELD_MAXPOWER1, uint32(28 + 10 * getLevel())); SetUInt32Value(UNIT_FIELD_PETNUMBER, GetGUIDLow()); } else { uint32 hp=created_from_creature->GetUInt32Value(UNIT_FIELD_MAXHEALTH); SetUInt32Value(UNIT_FIELD_MAXHEALTH, hp); SetUInt32Value(UNIT_FIELD_BASE_HEALTH,hp); SetFloatValue(OBJECT_FIELD_SCALE_X, created_from_creature->GetFloatValue(OBJECT_FIELD_SCALE_X)); SetUInt32Value(UNIT_FIELD_BYTES_0, created_from_creature->GetUInt32Value(UNIT_FIELD_BYTES_0)); SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, created_from_creature->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME)); SetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01, created_from_creature->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01)); SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, created_from_creature->GetFloatValue(UNIT_FIELD_BOUNDINGRADIUS)); SetFloatValue(UNIT_FIELD_COMBATREACH, created_from_creature->GetFloatValue(UNIT_FIELD_COMBATREACH)); SetFloatValue(UNIT_FIELD_MINDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINDAMAGE)); SetFloatValue(UNIT_FIELD_MAXDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXDAMAGE)); SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE)); SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE)); SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE)); SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, created_from_creature->GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE)); SetUInt32Value(UNIT_FIELD_ATTACK_POWER, created_from_creature->GetUInt32Value(UNIT_FIELD_ATTACK_POWER)); SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER, created_from_creature->GetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER));; SetUInt32Value(UNIT_FIELD_MAXPOWER1, 0); SetUInt32Value(UNIT_FIELD_BASE_MANA, 0); SetUInt32Value(UNIT_FIELD_MAXPOWER2, 0); SetUInt32Value(UNIT_FIELD_MAXPOWER3, 200); SetUInt32Value(UNIT_FIELD_MAXPOWER4, 0); SetUInt32Value(UNIT_FIELD_RESISTANCES, created_from_creature->GetUInt32Value(UNIT_FIELD_RESISTANCES)); // These need to be checked. SetUInt32Value(UNIT_FIELD_FLAGS, 0x00000828); SetUInt32Value(UNIT_FIELD_POWER5, 600000); SetUInt32Value(UNIT_FIELD_MAXPOWER5, 1000000); SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0); SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, GetNextLevelXP(getLevel())); // Change the power type to FOCUS SetPowerType(POWER_TYPE_FOCUS); for(int x=0;x<5;x++) SetUInt32Value(UNIT_FIELD_STAT0 + x, BaseStats[x]); // create our spellz SetDefaultSpells(); } BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE); BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE); BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, owner->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE)); // Set all values to full. SetUInt32Value(UNIT_FIELD_HEALTH, GetUInt32Value(UNIT_FIELD_MAXHEALTH)); SetUInt32Value(UNIT_FIELD_POWER1, GetUInt32Value(UNIT_FIELD_MAXPOWER1)); SetUInt32Value(UNIT_FIELD_POWER2, GetUInt32Value(UNIT_FIELD_MAXPOWER2)); SetUInt32Value(UNIT_FIELD_POWER3, GetUInt32Value(UNIT_FIELD_MAXPOWER3)); SetUInt32Value(UNIT_FIELD_POWER4, GetUInt32Value(UNIT_FIELD_MAXPOWER4)); // Set base values SetUInt32Value(UNIT_FIELD_BASE_HEALTH, GetUInt32Value(UNIT_FIELD_HEALTH)); SetUInt32Value(UNIT_FIELD_BASE_MANA, GetUInt32Value(UNIT_FIELD_POWER1)); memcpy(m_baseUint32Values, m_uint32Values,m_valuesCount*sizeof(uint32)); m_PartySpellsUpdateTimer = 0; m_PetNumber = static_cast<Player*>(owner)->GeneratePetNumber(); SetUInt32Value(UNIT_FIELD_PETNUMBER, m_GuidLow); m_ExpireTime = expiretime; bExpires = m_ExpireTime > 0 ? true : false; if(!bExpires) { // Create PlayerPet struct (Rest done by UpdatePetInfo) PlayerPet *pp = new PlayerPet; pp->number = m_PetNumber; static_cast<Player*>(owner)->AddPlayerPet(pp, pp->number); } InitializeMe(true); }
void Item::SaveToDB( int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << ", " << random_suffix << ", "; ss << GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); ++itr) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; /* if( !itr->second.RemoveAtLogout && (remaining_duration > 5 && itr->second.Slot != 2) || itr->second.Slot == 2) // no point saving stuff with < 5 seconds... unless is perm enchant { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } */ if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 ) || ( itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } } } ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
void GameObject::Update(uint32 p_time) { if(m_event_Instanceid != m_instanceId) { event_Relocate(); return; } if(!IsInWorld()) return; if(m_deleted) return; if(spell && (GetUInt32Value(GAMEOBJECT_STATE) == 1)) { if(checkrate > 1) { if(counter++%checkrate) return; } ObjectSet::iterator itr = GetInRangeSetBegin(); ObjectSet::iterator it2 = itr; ObjectSet::iterator iend = GetInRangeSetEnd(); Unit * pUnit; float dist; for(; it2 != iend;) { itr = it2; ++it2; dist = GetDistanceSq((*itr)); if( (*itr) != m_summoner && (*itr)->IsUnit() && dist <= range) { pUnit = static_cast<Unit*>(*itr); if(m_summonedGo) { if(!m_summoner) { ExpireAndDelete(); return; } if(!isAttackable(m_summoner,pUnit))continue; } Spell * sp=new Spell((Object*)this,spell,true,NULL); SpellCastTargets tgt((*itr)->GetGUID()); tgt.m_destX = GetPositionX(); tgt.m_destY = GetPositionY(); tgt.m_destZ = GetPositionZ(); sp->prepare(&tgt); if(m_summonedGo) { ExpireAndDelete(); return; } if(spell->EffectImplicitTargetA[0] == 16 || spell->EffectImplicitTargetB[0] == 16) return; // on area dont continue. } } } }
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()); } }
void Item::SaveToDB(SQLTransaction& trans) { bool isInTransaction = !(trans.null()); if (!isInTransaction) trans = CharacterDatabase.BeginTransaction(); uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: case ITEM_CHANGED: { uint8 index = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_REP_ITEM_INSTANCE : CHAR_UPD_ITEM_INSTANCE); stmt->setUInt32( index, GetEntry()); stmt->setUInt32(++index, GUID_LOPART(GetOwnerGUID())); stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR))); stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR))); stmt->setUInt32(++index, GetCount()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION)); std::ostringstream ssSpells; for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) ssSpells << GetSpellCharges(i) << ' '; stmt->setString(++index, ssSpells.str()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS)); std::ostringstream ssEnchants; for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i) { ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' '; } stmt->setString(++index, ssEnchants.str()); stmt->setInt16 (++index, GetItemRandomPropertyId()); stmt->setUInt16(++index, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME)); stmt->setString(++index, m_text); stmt->setUInt32(++index, guid); trans->Append(stmt); if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) trans->PAppend("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()), guid); break; } case ITEM_REMOVED: { trans->PAppend("DELETE FROM item_instance WHERE guid = '%u'", guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) trans->PAppend("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow()); if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); CharacterDatabase.PExecute("UPDATE character_donate SET state = 1 WHERE itemguid = '%u'", guid); delete this; return; } case ITEM_UNCHANGED: break; } SetState(ITEM_UNCHANGED); if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); }
ItemPrototype const *Item::GetProto() const { return objmgr.GetItemPrototype(GetUInt32Value(OBJECT_FIELD_ENTRY)); }
void Item::SaveToDB( int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << ", " << random_suffix << ", "; ss << GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); ++itr) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; /* if( !itr->second.RemoveAtLogout && (remaining_duration > 5 && itr->second.Slot != 2) || itr->second.Slot == 2) // no point saving stuff with < 5 seconds... unless is perm enchant { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } */ if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 || itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } } } ss << "','"; ss << ItemExpiresOn << "','"; ////////////////////////////////////////////////// Refund stuff ///////////////////////////////// // Check if the owner is instantiated. When sending mail he/she obviously will not be :P if( this->GetOwner() != NULL ){ std::pair< time_t, uint32 > refundentry; refundentry.first = 0; refundentry.second = 0; refundentry = this->GetOwner()->GetItemInterface()->LookupRefundable( this->GetGUID() ); ss << uint32( refundentry.first ) << "','"; ss << uint32( refundentry.second ); }else{ ss << uint32( 0 ) << "','"; ss << uint32( 0 ); } ///////////////////////////////////////////////////////////////////////////////////////////////// ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
bool Item::LoadFromDB(uint32 guidLow, Field* fields, ObjectGuid ownerGuid) { // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guidLow, 0, HIGHGUID_ITEM); if (!LoadValues(fields[0].GetString())) { sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.", guidLow); return false; } bool need_save = false; // need explicit save data at load fixes // overwrite possible wrong/corrupted guid ObjectGuid new_item_guid = ObjectGuid(HIGHGUID_ITEM, guidLow); if (GetGuidValue(OBJECT_FIELD_GUID) != new_item_guid) { SetGuidValue(OBJECT_FIELD_GUID, new_item_guid); need_save = true; } ItemPrototype const* proto = GetProto(); if (!proto) return false; // update max durability (and durability) if need if (proto->MaxDurability != GetUInt32Value(ITEM_FIELD_MAXDURABILITY)) { SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); if (GetUInt32Value(ITEM_FIELD_DURABILITY) > proto->MaxDurability) SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability); need_save = true; } // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_BINDED, false); need_save = true; } // update duration if need, and remove if not need if ((proto->Duration == 0) != (GetUInt32Value(ITEM_FIELD_DURATION) == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration); need_save = true; } // set correct owner if (ownerGuid && GetOwnerGuid() != ownerGuid) { SetOwnerGuid(ownerGuid); need_save = true; } // set correct wrapped state if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { // wrapped item must be wrapper (used version that not stackable) if (!(proto->Flags & ITEM_FLAG_IS_WRAPPER) || GetMaxStackCount() > 1) { RemoveFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED); need_save = true; static SqlStatementID delGifts ; // also cleanup for sure gift table SqlStatement stmt = CharacterDatabase.CreateStatement(delGifts, "DELETE FROM character_gifts WHERE item_guid = ?"); stmt.PExecute(GetGUIDLow()); } } if (need_save) // normal item changed state set not work at loading { static SqlStatementID updItem ; SqlStatement stmt = CharacterDatabase.CreateStatement(updItem, "UPDATE item_instance SET data = ?, owner_guid = ? WHERE guid = ?"); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; stmt.addString(ss); stmt.addUInt32(GetOwnerGuid().GetCounter()); stmt.addUInt32(guidLow); stmt.Execute(); } return true; }
void GameObject::Update(uint32 /*p_time*/) { if (IS_MO_TRANSPORT(GetGUID())) { //((Transport*)this)->Update(p_time); return; } switch (m_lootState) { case GO_NOT_READY: if (GetGoType()==GAMEOBJECT_TYPE_FISHINGNODE) { // fishing code (bobber ready) if( time(NULL) > m_respawnTime - FISHING_BOBBER_READY_TIME ) { // splash bobber (bobber ready now) Unit* caster = GetOwner(); if(caster && caster->GetTypeId()==TYPEID_PLAYER) { SetUInt32Value(GAMEOBJECT_STATE, 0); SetUInt32Value(GAMEOBJECT_FLAGS, 32); UpdateData udata; WorldPacket packet; BuildValuesUpdateBlockForPlayer(&udata,((Player*)caster)); udata.BuildPacket(&packet); ((Player*)caster)->GetSession()->SendPacket(&packet); WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM,8+4); data << GetGUID(); data << (uint32)(0); ((Player*)caster)->SendMessageToSet(&data,true); } m_lootState = GO_READY; // can be succesfully open with some chance } return; } m_lootState = GO_READY; // for other GOis same switched without delay to GO_READY // NO BREAK case GO_READY: { if (m_respawnTime > 0) // timer on { if (m_respawnTime <= time(NULL)) // timer expired { m_respawnTime = 0; m_SkillupList.clear(); m_usetimes = 0; switch (GetGoType()) { case GAMEOBJECT_TYPE_FISHINGNODE: // can't fish now { Unit* caster = GetOwner(); if(caster && caster->GetTypeId()==TYPEID_PLAYER) { if(caster->m_currentSpells[CURRENT_CHANNELED_SPELL]) { caster->m_currentSpells[CURRENT_CHANNELED_SPELL]->SendChannelUpdate(0); caster->m_currentSpells[CURRENT_CHANNELED_SPELL]->finish(false); } WorldPacket data(SMSG_FISH_NOT_HOOKED,0); ((Player*)caster)->GetSession()->SendPacket(&data); } // can be delete m_lootState = GO_JUST_DEACTIVATED; return; } case GAMEOBJECT_TYPE_DOOR: case GAMEOBJECT_TYPE_BUTTON: //we need to open doors if they are closed (add there another condition if this code breaks some usage, but it need to be here for battlegrounds) if( !GetUInt32Value(GAMEOBJECT_STATE) ) SwitchDoorOrButton(false); //flags in AB are type_button and we need to add them here so no break! default: if(!m_spawnedByDefault) // despawn timer { // can be despawned or destroyed SetLootState(GO_JUST_DEACTIVATED); return; } // respawn timer MapManager::Instance().GetMap(GetMapId(), this)->Add(this); break; } } } // traps can have time and can not have GameObjectInfo const* goInfo = GetGOInfo(); if(goInfo->type == GAMEOBJECT_TYPE_TRAP) { // traps Unit* owner = GetOwner(); Unit* ok = NULL; // pointer to appropriate target if found any if(m_cooldownTime >= time(NULL)) return; bool IsBattleGroundTrap = false; //FIXME: this is activation radius (in different casting radius that must be selected from spell data) //TODO: move activated state code (cast itself) to GO_ACTIVATED, in this place only check activating and set state float radius = goInfo->trap.radius; if(!radius) { if(goInfo->trap.cooldown != 3) // cast in other case (at some triggring/linked go/etc explicit call) return; else { if(m_respawnTime > 0) break; radius = goInfo->trap.cooldown; // battlegrounds gameobjects has data2 == 0 && data5 == 3 IsBattleGroundTrap = true; } } bool NeedDespawn = (goInfo->trap.charges != 0); CellPair p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; // Note: this hack with search required until GO casting not implemented // search unfriendly creature if(owner && NeedDespawn) // hunter trap { MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, owner, radius); MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck> checker(ok, u_check); CellLock<GridReadGuard> cell_lock(cell, p); TypeContainerVisitor<MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker); cell_lock->Visit(cell_lock, grid_object_checker, *MapManager::Instance().GetMap(GetMapId(), this)); // or unfriendly player/pet if(!ok) { TypeContainerVisitor<MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker); cell_lock->Visit(cell_lock, world_object_checker, *MapManager::Instance().GetMap(GetMapId(), this)); } } else // environmental trap { // environmental damage spells already have around enemies targeting but this not help in case not existed GO casting support // affect only players Player* p_ok = NULL; MaNGOS::AnyPlayerInObjectRangeCheck p_check(this, radius); MaNGOS::PlayerSearcher<MaNGOS::AnyPlayerInObjectRangeCheck> checker(p_ok, p_check); CellLock<GridReadGuard> cell_lock(cell, p); TypeContainerVisitor<MaNGOS::PlayerSearcher<MaNGOS::AnyPlayerInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker); cell_lock->Visit(cell_lock, world_object_checker, *MapManager::Instance().GetMap(GetMapId(), this)); ok = p_ok; } if (ok) { Unit *caster = owner ? owner : ok; caster->CastSpell(ok, goInfo->trap.spellId, true); m_cooldownTime = time(NULL) + 4; // 4 seconds if(NeedDespawn) SetLootState(GO_JUST_DEACTIVATED); // can be despawned or destroyed if(IsBattleGroundTrap && ok->GetTypeId() == TYPEID_PLAYER) { //BattleGround gameobjects case if(((Player*)ok)->InBattleGround()) if(BattleGround *bg = ((Player*)ok)->GetBattleGround()) bg->HandleTriggerBuff(GetGUID()); } } } if (m_charges && m_usetimes >= m_charges) SetLootState(GO_JUST_DEACTIVATED); // can be despawned or destroyed break; } case GO_ACTIVATED: { switch(GetGoType()) { case GAMEOBJECT_TYPE_DOOR: case GAMEOBJECT_TYPE_BUTTON: if(GetAutoCloseTime() && (m_cooldownTime < time(NULL))) { SwitchDoorOrButton(false); SetLootState(GO_JUST_DEACTIVATED); } break; } break; } case GO_JUST_DEACTIVATED: { //if Gameobject should cast spell, then this, but some GOs (type = 10) should be destroyed if (GetGoType() == GAMEOBJECT_TYPE_GOOBER) { uint32 spellId = GetGOInfo()->goober.spellId; if(spellId) { std::set<uint32>::iterator it = m_unique_users.begin(); std::set<uint32>::iterator end = m_unique_users.end(); for (; it != end; it++) { Unit* owner = Unit::GetUnit(*this, uint64(*it)); if (owner) owner->CastSpell(owner, spellId, false); } m_unique_users.clear(); m_usetimes = 0; } //any return here in case battleground traps } if(GetOwnerGUID()) { m_respawnTime = 0; Delete(); return; } //burning flags in some battlegrounds, if you find better condition, just add it if (this->GetUInt32Value(GAMEOBJECT_ANIMPROGRESS) > 0) { this->SendObjectDeSpawnAnim(this->GetGUID()); //reset flags SetUInt32Value(GAMEOBJECT_FLAGS, m_flags); } loot.clear(); SetLootState(GO_READY); if(!m_respawnDelayTime) return; if(!m_spawnedByDefault) { m_respawnTime = 0; return; } m_respawnTime = time(NULL) + m_respawnDelayTime; // if option not set then object will be saved at grid unload if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY)) SaveRespawnTime(); ObjectAccessor::UpdateObjectVisibility(this); break; } } }
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entry) { // 0 1 2 3 4 5 6 7 8 9 10 //result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text FROM item_instance WHERE guid = '%u'", guid); // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HIGHGUID_ITEM); // Set entry, MUST be before proto check SetEntry(entry); SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f); ItemPrototype const* proto = GetProto(); if (!proto) return false; // set owner (not if item is only loaded for gbank/auction/mail if (owner_guid != 0) SetOwnerGUID(owner_guid); bool need_save = false; // need explicit save data at load fixes SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER)); SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER)); SetCount(fields[2].GetUInt32()); uint32 duration = fields[3].GetUInt32(); SetUInt32Value(ITEM_FIELD_DURATION, duration); // update duration if need, and remove if not need if ((proto->Duration == 0) != (duration == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, abs(proto->Duration)); need_save = true; } Tokens tokens(fields[4].GetString(), ' ', MAX_ITEM_PROTO_SPELLS); if (tokens.size() == MAX_ITEM_PROTO_SPELLS) for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i, atoi(tokens[i])); SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32()); // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND, false); need_save = true; } std::string enchants = fields[6].GetString(); //_LoadIntoDataField(enchants.c_str(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET); { // NOTE: // in the recent update of reforge system, definition of EnchantmentSlot has been changed, // and MAX_ENCHANTMENT_SLOT has been changed from 13 to 14, // which makes enchantments column of item_instance table incompatible with previous version. // in this case we will load only first 9 enchantment slots (0-8, for permanent, temporary, sockets, bonus, prismatic and reforge) // and ignore the remaining ones (9-13, for random properties). // which means item random properties will be lost after this update. // after player logging in and saving the inventory, enchantments column will be properly updated. uint32 count = MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET; Tokens tokens(enchants, ' ', count); if (tokens.size() < MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET) count = REFORGE_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET; for (uint32 index = 0; index < count; ++index) m_uint32Values[ITEM_FIELD_ENCHANTMENT_1_1 + index] = index < tokens.size() ? atol(tokens[index]) : 0; } SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt16()); // recalculate suffix factor if (GetItemRandomPropertyId() < 0) UpdateItemSuffixFactor(); uint32 durability = fields[8].GetUInt16(); SetUInt32Value(ITEM_FIELD_DURABILITY, durability); // update max durability (and durability) if need SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); if (durability > proto->MaxDurability) { SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability); need_save = true; } SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32()); SetText(fields[10].GetString()); if (need_save) // normal item changed state set not work at loading { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_ITEM_INSTANCE_ON_LOAD); stmt->setUInt32(0, GetUInt32Value(ITEM_FIELD_DURATION)); stmt->setUInt32(1, GetUInt32Value(ITEM_FIELD_FLAGS)); stmt->setUInt32(2, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(3, guid); CharacterDatabase.Execute(stmt); } return true; }
GameObjectInfo const *GameObject::GetGOInfo() const { return objmgr.GetGameObjectInfo(GetUInt32Value (OBJECT_FIELD_ENTRY)); }
void Item::SaveToDB(SQLTransaction& trans) { bool isInTransaction = bool(trans); if (!isInTransaction) trans = CharacterDatabase.BeginTransaction(); ObjectGuid::LowType guid = GetGUID().GetCounter(); switch (uState) { case ITEM_NEW: case ITEM_CHANGED: { uint8 index = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_REP_ITEM_INSTANCE : CHAR_UPD_ITEM_INSTANCE); stmt->setUInt32( index, GetEntry()); stmt->setUInt32(++index, GetOwnerGUID().GetCounter()); stmt->setUInt32(++index, GetGuidValue(ITEM_FIELD_CREATOR).GetCounter()); stmt->setUInt32(++index, GetGuidValue(ITEM_FIELD_GIFTCREATOR).GetCounter()); stmt->setUInt32(++index, GetCount()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION)); std::ostringstream ssSpells; for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) ssSpells << GetSpellCharges(i) << ' '; stmt->setString(++index, ssSpells.str()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS)); std::ostringstream ssEnchants; for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i) { ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' '; } stmt->setString(++index, ssEnchants.str()); stmt->setInt16 (++index, GetItemRandomPropertyId()); stmt->setUInt16(++index, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME)); stmt->setString(++index, m_text); stmt->setUInt32(++index, guid); trans->Append(stmt); if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER); stmt->setUInt32(0, GetOwnerGUID().GetCounter()); stmt->setUInt32(1, guid); trans->Append(stmt); } break; } case ITEM_REMOVED: { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE); stmt->setUInt32(0, guid); trans->Append(stmt); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); stmt->setUInt32(0, guid); trans->Append(stmt); } if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); // Delete the items if this is a container if (!loot.isLooted()) ItemContainerDeleteLootMoneyAndLootItemsFromDB(); delete this; return; } case ITEM_UNCHANGED: break; } SetState(ITEM_UNCHANGED); if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); }
bool Creature::Load(CreatureSpawn *spawn, uint32 mode, MapInfo *info) { m_spawn = spawn; proto = CreatureProtoStorage.LookupEntry(spawn->entry); if(!proto) return false; creature_info = CreatureNameStorage.LookupEntry(spawn->entry); if(!creature_info) return false; spawnid = spawn->id; m_walkSpeed = m_base_walkSpeed = proto->walk_speed; //set speeds m_runSpeed = m_base_runSpeed = proto->run_speed; //set speeds m_flySpeed = proto->fly_speed; //Set fields SetUInt32Value(OBJECT_FIELD_ENTRY,proto->Id); SetFloatValue(OBJECT_FIELD_SCALE_X,proto->Scale); //SetUInt32Value(UNIT_FIELD_HEALTH, (mode ? long2int32(proto->Health * 1.5) : proto->Health)); //SetUInt32Value(UNIT_FIELD_BASE_HEALTH, (mode ? long2int32(proto->Health * 1.5) : proto->Health)); //SetUInt32Value(UNIT_FIELD_MAXHEALTH, (mode ? long2int32(proto->Health * 1.5) : proto->Health)); uint32 health = proto->MinHealth + RandomUInt(proto->MaxHealth - proto->MinHealth); if(mode) health = long2int32(double(health) * 1.5); SetUInt32Value(UNIT_FIELD_HEALTH, health); SetUInt32Value(UNIT_FIELD_MAXHEALTH, health); SetUInt32Value(UNIT_FIELD_BASE_HEALTH, health); SetUInt32Value(UNIT_FIELD_POWER1,proto->Mana); SetUInt32Value(UNIT_FIELD_MAXPOWER1,proto->Mana); SetUInt32Value(UNIT_FIELD_BASE_MANA,proto->Mana); // Whee, thank you blizz, I love patch 2.2! Later on, we can randomize male/female mobs! xD // Determine gender (for voices) //if(spawn->displayid != creature_info->Male_DisplayID) // setGender(1); // Female uint32 model; uint32 gender = creature_info->GenerateModelId(&model); setGender(gender); SetUInt32Value(UNIT_FIELD_DISPLAYID,model); SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID,model); SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,proto->MountedDisplayID); //SetUInt32Value(UNIT_FIELD_LEVEL, (mode ? proto->Level + (info ? info->lvl_mod_a : 0) : proto->Level)); SetUInt32Value(UNIT_FIELD_LEVEL, proto->MinLevel + (RandomUInt(proto->MaxLevel - proto->MinLevel))); if(mode && info) ModUnsigned32Value(UNIT_FIELD_LEVEL, info->lvl_mod_a); for(uint32 i = 0; i < 7; ++i) SetUInt32Value(UNIT_FIELD_RESISTANCES+i,proto->Resistances[i]); SetUInt32Value(UNIT_FIELD_BASEATTACKTIME,proto->AttackTime); SetFloatValue(UNIT_FIELD_MINDAMAGE, (mode ? proto->MinDamage * 1.5f : proto->MinDamage)); SetFloatValue(UNIT_FIELD_MAXDAMAGE, (mode ? proto->MaxDamage * 1.5f : proto->MaxDamage)); SetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME,proto->RangedAttackTime); SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,proto->RangedMinDamage); SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,proto->RangedMaxDamage); SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, proto->Item1SlotDisplay); SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, proto->Item2SlotDisplay); SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, proto->Item3SlotDisplay); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO, proto->Item1Info1); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_01, proto->Item1Info2); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_02, proto->Item2Info1); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_03, proto->Item2Info2); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_04, proto->Item3Info1); SetUInt32Value(UNIT_VIRTUAL_ITEM_INFO_05, proto->Item3Info2); SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, spawn->factionid); SetUInt32Value(UNIT_FIELD_FLAGS, spawn->flags); SetUInt32Value(UNIT_NPC_EMOTESTATE, spawn->emote_state); SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, proto->BoundingRadius); SetFloatValue(UNIT_FIELD_COMBATREACH, proto->CombatReach); original_emotestate = spawn->emote_state; // set position m_position.ChangeCoords( spawn->x, spawn->y, spawn->z, spawn->o ); m_spawnLocation.ChangeCoords(spawn->x, spawn->y, spawn->z, spawn->o); m_aiInterface->setMoveType(spawn->movetype); m_aiInterface->m_waypoints = objmgr.GetWayPointMap(spawn->id); m_faction = dbcFactionTemplate.LookupEntry(spawn->factionid); if(m_faction) { m_factionDBC = dbcFaction.LookupEntry(m_faction->Faction); // not a neutral creature if(!(m_factionDBC->RepListId == -1 && m_faction->HostileMask == 0 && m_faction->FriendlyMask == 0)) { GetAIInterface()->m_canCallForHelp = true; } } //SETUP NPC FLAGS SetUInt32Value(UNIT_NPC_FLAGS,proto->NPCFLags); if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ) ) m_SellItems = objmgr.GetVendorList(GetEntry()); if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ) ) _LoadQuests(); if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TAXIVENDOR) ) m_TaxiNode = sTaxiMgr.GetNearestTaxiNode( m_position.x, m_position.y, m_position.z, GetMapId() ); if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER) || HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER_PROF)) mTrainer = objmgr.GetTrainer(GetEntry()); if ( HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ) ) auctionHouse = sAuctionMgr.GetAuctionHouse(GetEntry()); //NPC FLAGS m_aiInterface->m_waypoints=objmgr.GetWayPointMap(spawn->id); //load resistances for(uint32 x=0;x<7;x++) BaseResistance[x]=GetUInt32Value(UNIT_FIELD_RESISTANCES+x); for(uint32 x=0;x<5;x++) BaseStats[x]=GetUInt32Value(UNIT_FIELD_STAT0+x); BaseDamage[0]=GetFloatValue(UNIT_FIELD_MINDAMAGE); BaseDamage[1]=GetFloatValue(UNIT_FIELD_MAXDAMAGE); BaseOffhandDamage[0]=GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); BaseOffhandDamage[1]=GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); BaseRangedDamage[0]=GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); BaseRangedDamage[1]=GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); BaseAttackType=proto->AttackType; SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f); // better set this one SetUInt32Value(UNIT_FIELD_BYTES_0, spawn->bytes); SetUInt32Value(UNIT_FIELD_BYTES_2, spawn->bytes2); ////////////AI // kek for(list<AI_Spell*>::iterator itr = proto->spells.begin(); itr != proto->spells.end(); ++itr) { m_aiInterface->addSpellToList(*itr); } //m_aiInterface->m_canCallForHelp = proto->m_canCallForHelp; //m_aiInterface->m_CallForHelpHealth = proto->m_callForHelpHealth; m_aiInterface->m_canFlee = proto->m_canFlee; m_aiInterface->m_FleeHealth = proto->m_fleeHealth; m_aiInterface->m_FleeDuration = proto->m_fleeDuration; //these fields are always 0 in db GetAIInterface()->setMoveType(0); GetAIInterface()->setMoveRunFlag(0); // load formation data if( spawn->form != NULL ) { m_aiInterface->m_formationLinkSqlId = spawn->form->fol; m_aiInterface->m_formationFollowDistance = spawn->form->dist; m_aiInterface->m_formationFollowAngle = spawn->form->ang; } else { m_aiInterface->m_formationLinkSqlId = 0; m_aiInterface->m_formationFollowDistance = 0; m_aiInterface->m_formationFollowAngle = 0; } //////////////AI myFamily = dbcCreatureFamily.LookupEntry(creature_info->Family); // PLACE FOR DIRTY FIX BASTARDS // HACK! set call for help on civ health @ 100% if(creature_info->Civilian >= 1) m_aiInterface->m_CallForHelpHealth = 100; //HACK! if(m_uint32Values[UNIT_FIELD_DISPLAYID] == 17743 || m_uint32Values[UNIT_FIELD_DISPLAYID] == 20242 || m_uint32Values[UNIT_FIELD_DISPLAYID] == 15435 || (creature_info->Family == UNIT_TYPE_MISC)) { m_useAI = false; } /* more hacks! */ if(proto->Mana != 0) SetPowerType(POWER_TYPE_MANA); else SetPowerType(0); has_combat_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_ENTER_COMBAT); has_waypoint_text = objmgr.HasMonsterSay(GetEntry(), MONSTER_SAY_EVENT_RANDOM_WAYPOINT); m_aiInterface->m_isGuard = isGuard(GetEntry()); m_aiInterface->getMoveFlags(); /* creature death state */ if(proto->death_state == 1) { uint32 newhealth = m_uint32Values[UNIT_FIELD_HEALTH] / 100; if(!newhealth) newhealth = 1; SetUInt32Value(UNIT_FIELD_HEALTH, 1); m_limbostate = true; bInvincible = true; SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_DEAD); } m_invisFlag = proto->invisibility_type; if( spawn->stand_state ) SetStandState( (uint8)spawn->stand_state ); return true; }
uint32 Item::GetPlayedTime() { time_t curtime = time(NULL); uint32 elapsed = uint32(curtime - m_lastPlayedTimeUpdate); return GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + elapsed; }
void Player::UpdateManaRegen() { // Mana regen from spirit float spirit_regen = OCTRegenMPPerSpirit(); spirit_regen *= GetTotalAuraMultiplierByMiscValue(SPELL_AURA_MOD_POWER_REGEN_PERCENT, POWER_MANA); float HastePct = 1.0f + GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + CR_HASTE_MELEE) * GetRatingMultiplier(CR_HASTE_MELEE) / 100.0f; float combat_regen = 0.004f * GetMaxPower(POWER_MANA) + spirit_regen + (GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA) / 5.0f); float base_regen = 0.004f * GetMaxPower(POWER_MANA) + (GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA) / 5.0f); if (getClass() == CLASS_WARLOCK) { combat_regen = 0.01f * GetMaxPower(POWER_MANA) + spirit_regen + GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA); base_regen = 0.01f * GetMaxPower(POWER_MANA) + GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA); } // Mana Meditation && Meditation if (HasAuraType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT)) base_regen += 0.5 * spirit_regen; // Allows 50% of your mana regeneration from Spirit to continue while in combat. // Rune of Power : Increase Mana regeneration by 100% if (HasAura(116014)) { combat_regen *= 2; base_regen *= 2; } // Incanter's Ward : Increase Mana regen by 65% if (HasAura(118858)) { combat_regen *= 1.65f; base_regen *= 1.65f; } // Chaotic Energy : Increase Mana regen by 625% if (HasAura(111546)) { // haste also increase your mana regeneration HastePct = 1.0f + GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + CR_HASTE_MELEE) * GetRatingMultiplier(CR_HASTE_MELEE) / 100.0f; combat_regen = combat_regen + (combat_regen * 6.25f); combat_regen *= HastePct; base_regen = base_regen + (base_regen * 6.25f); base_regen *= HastePct; } // Nether Attunement - 117957 : Haste also increase your mana regeneration if (HasAura(117957)) { HastePct = 1.0f + GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + CR_HASTE_MELEE) * GetRatingMultiplier(CR_HASTE_MELEE) / 100.0f; combat_regen *= HastePct; base_regen *= HastePct; } // Mana Attunement : Increase Mana regen by 50% if (HasAura(121039)) { combat_regen = combat_regen + (combat_regen * 0.5f); combat_regen *= HastePct; base_regen = base_regen + (base_regen * 0.5f); base_regen *= HastePct; } // Invocation : Decrease your mana regen by 50% if (HasAura(114003)) { combat_regen *= 0.5f; base_regen *= 0.5f; } // Not In Combat : 2% of base mana + spirit_regen SetStatFloatValue(UNIT_FIELD_POWER_REGEN_INTERRUPTED_FLAT_MODIFIER, base_regen); // In Combat : 2% of base mana SetStatFloatValue(UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER, combat_regen); }