diff options
author | Spp <spp@jorge.gr> | 2011-10-18 10:44:45 +0200 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2011-10-18 10:44:45 +0200 |
commit | ee69fc940e8bccba0f61032e37bde77ccc10e27c (patch) | |
tree | 2ef0d7831812aa7182fe2d336fa185d195496f70 | |
parent | be34ae68bbf29ba326a2ad6f030253ff065da0a1 (diff) |
Core/Items: Split SetSoulboundTradeable in two functions (Set and Clear)
Note: this is mostly for clarify action being done: ClearSoulboundTradeable better than SetSoulboundTradeable(..., ..., false)
-rwxr-xr-x | src/server/game/Entities/Item/Item.cpp | 34 | ||||
-rwxr-xr-x | src/server/game/Entities/Item/Item.h | 3 | ||||
-rwxr-xr-x | src/server/game/Entities/Player/Player.cpp | 30 | ||||
-rwxr-xr-x | src/server/game/Entities/Player/Player.h | 8 | ||||
-rwxr-xr-x | src/server/game/Groups/Group.cpp | 11 | ||||
-rwxr-xr-x | src/server/game/Loot/LootMgr.h | 2 | ||||
-rwxr-xr-x | src/server/game/Server/Protocol/Handlers/ItemHandler.cpp | 2 | ||||
-rwxr-xr-x | src/server/game/Server/Protocol/Handlers/LootHandler.cpp | 4 | ||||
-rwxr-xr-x | src/server/game/Spells/SpellEffects.cpp | 4 |
9 files changed, 53 insertions, 45 deletions
diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp index d3832ad9151..07275166130 100755 --- a/src/server/game/Entities/Item/Item.cpp +++ b/src/server/game/Entities/Item/Item.cpp @@ -1194,25 +1194,23 @@ bool Item::IsRefundExpired() return (GetPlayedTime() > 2*HOUR); } -void Item::SetSoulboundTradeable(AllowedLooterSet* allowedLooters, Player* currentOwner, bool apply) +void Item::SetSoulboundTradeable(AllowedLooterSet& allowedLooters) { - if (apply) - { - SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); - allowedGUIDs = *allowedLooters; - } - else - { - RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); - if (allowedGUIDs.empty()) - return; + SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); + allowedGUIDs = allowedLooters; +} - allowedGUIDs.clear(); - SetState(ITEM_CHANGED, currentOwner); - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_BOP_TRADE); - stmt->setUInt32(0, GetGUIDLow()); - CharacterDatabase.Execute(stmt); - } +void Item::ClearSoulboundTradeable(Player* currentOwner) +{ + RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); + if (allowedGUIDs.empty()) + return; + + allowedGUIDs.clear(); + SetState(ITEM_CHANGED, currentOwner); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_BOP_TRADE); + stmt->setUInt32(0, GetGUIDLow()); + CharacterDatabase.Execute(stmt); } bool Item::CheckSoulboundTradeExpire() @@ -1220,7 +1218,7 @@ bool Item::CheckSoulboundTradeExpire() // called from owner's update - GetOwner() MUST be valid if (GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + 2*HOUR < GetOwner()->GetTotalPlayedTime()) { - SetSoulboundTradeable(NULL, GetOwner(), false); + ClearSoulboundTradeable(GetOwner()); return true; // remove from tradeable list } diff --git a/src/server/game/Entities/Item/Item.h b/src/server/game/Entities/Item/Item.h index b872b354ea7..4a72e7fea2b 100755 --- a/src/server/game/Entities/Item/Item.h +++ b/src/server/game/Entities/Item/Item.h @@ -352,7 +352,8 @@ class Item : public Object bool IsRefundExpired(); // Soulbound trade system - void SetSoulboundTradeable(AllowedLooterSet* allowedLooters, Player* currentOwner, bool apply); + void SetSoulboundTradeable(AllowedLooterSet& allowedLooters); + void ClearSoulboundTradeable(Player* currentOwner); bool CheckSoulboundTradeExpire(); void BuildUpdate(UpdateDataMapType&); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 203f52ca7c5..ec4e7eba4f8 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -11898,8 +11898,14 @@ void Player::RemoveAmmo() UpdateDamagePhysical(RANGED_ATTACK); } +Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId) +{ + AllowedLooterSet allowedLooters; + return StoreNewItem(dest, item, update, randomPropertyId, allowedLooters); +} + // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case. -Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet* allowedLooters) +Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet& allowedLooters) { uint32 count = 0; for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr) @@ -11919,16 +11925,18 @@ Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update if (proto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_NO_DELAY_USE && proto->Spells[i].SpellId > 0) // On obtain trigger CastSpell(this, proto->Spells[i].SpellId, true, pItem); - if (allowedLooters && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound()) + if (allowedLooters.size() > 1 && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound()) { - pItem->SetSoulboundTradeable(allowedLooters, this, true); + pItem->SetSoulboundTradeable(allowedLooters); pItem->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime()); m_itemSoulboundTradeable.push_back(pItem); // save data std::ostringstream ss; - for (AllowedLooterSet::iterator itr = allowedLooters->begin(); itr != allowedLooters->end(); ++itr) - ss << *itr << ' '; + AllowedLooterSet::const_iterator itr = allowedLooters.begin(); + ss << *itr; + for (++itr; itr != allowedLooters.end(); ++itr) + ss << ' ' << *itr; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_ITEM_BOP_TRADE); stmt->setUInt32(0, pItem->GetGUIDLow()); @@ -12051,7 +12059,7 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool pItem->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); pItem->SetState(ITEM_REMOVED, this); } @@ -12168,7 +12176,7 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) pItem->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); pItem->SetState(ITEM_REMOVED, this); pItem2->SetState(ITEM_CHANGED, this); @@ -12388,7 +12396,7 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) RemoveItemDurations(pItem); pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); const ItemTemplate* proto = pItem->GetTemplate(); @@ -17474,7 +17482,7 @@ Item* Player::_LoadItem(SQLTransaction& trans, uint32 zoneId, uint32 timeDiff, F AllowedLooterSet looters; for (Tokens::iterator itr = GUIDlist.begin(); itr != GUIDlist.end(); ++itr) looters.insert(atol(*itr)); - item->SetSoulboundTradeable(&looters, this, true); + item->SetSoulboundTradeable(looters); m_itemSoulboundTradeable.push_back(item); } else @@ -23202,8 +23210,8 @@ void Player::StoreLootItem(uint8 lootSlot, Loot* loot) InventoryResult msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, item->itemid, item->count); if (msg == EQUIP_ERR_OK) { - AllowedLooterSet* looters = item->GetAllowedLooters(); - Item* newitem = StoreNewItem(dest, item->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + Item* newitem = StoreNewItem(dest, item->itemid, true, item->randomPropertyId, looters); if (qitem) { diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index a5067a66d55..7d0803a4c8a 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -743,8 +743,8 @@ enum RestType enum DuelCompleteType { DUEL_INTERRUPTED = 0, - DUEL_WON = 1, - DUEL_FLED = 2 + DUEL_WON = 1, + DUEL_FLED = 2 }; enum TeleportToOptions @@ -1269,8 +1269,8 @@ class Player : public Unit, public GridObject<Player> bool HasItemTotemCategory(uint32 TotemCategory) const; InventoryResult CanUseItem(ItemTemplate const* pItem) const; InventoryResult CanUseAmmo(uint32 item) const; - - Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0, AllowedLooterSet* allowedLooters = NULL); + Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0); + Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet &allowedLooters); Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update); Item* EquipNewItem(uint16 pos, uint32 item, bool update); Item* EquipItem(uint16 pos, Item* pItem, bool update); diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 0442172b0fd..5f73485c06e 100755 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -1052,8 +1052,8 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet* looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); } else { @@ -1105,8 +1105,8 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet* looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); } else { @@ -2065,4 +2065,5 @@ void Group::ToggleGroupMemberFlag(member_witerator slot, uint8 flag, bool apply) slot->flags |= flag; else slot->flags &= ~flag; -}
\ No newline at end of file +} + diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index b0adeb03784..10ae786a7d6 100755 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -149,7 +149,7 @@ struct LootItem bool AllowedForPlayer(Player const* player) const; void AddAllowedLooter(Player const* player); - AllowedLooterSet* GetAllowedLooters() { return &allowedGUIDs; } + const AllowedLooterSet & GetAllowedLooters() const { return allowedGUIDs; } }; struct QuestItem diff --git a/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp b/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp index eca466436be..f4e3af72892 100755 --- a/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp @@ -1341,7 +1341,7 @@ void WorldSession::HandleSocketOpcode(WorldPacket& recv_data) _player->ToggleMetaGemsActive(slot, true); //turn on all metagems (except for target item) - itemTarget->SetSoulboundTradeable(NULL, _player, false); // clear tradeable flag + itemTarget->ClearSoulboundTradeable(_player); // clear tradeable flag } void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPacket& recv_data) diff --git a/src/server/game/Server/Protocol/Handlers/LootHandler.cpp b/src/server/game/Server/Protocol/Handlers/LootHandler.cpp index 83d3fad3b21..05b4afc99e7 100755 --- a/src/server/game/Server/Protocol/Handlers/LootHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/LootHandler.cpp @@ -489,10 +489,10 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPacket & recv_data) } // list of players allowed to receive this item in trade - AllowedLooterSet* looters = item.GetAllowedLooters(); + AllowedLooterSet looters = item.GetAllowedLooters(); // not move item from loot to target inventory - Item* newitem = target->StoreNewItem(dest, item.itemid, true, item.randomPropertyId, (looters->size() > 1) ? looters : NULL); + Item* newitem = target->StoreNewItem(dest, item.itemid, true, item.randomPropertyId, looters); target->SendNewItem(newitem, uint32(item.count), false, false, true); target->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, item.itemid, item.count); target->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE, pLoot->loot_type, item.count); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 19f84854ae4..8d68569ecb1 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3575,7 +3575,7 @@ void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex) // add new enchanting if equipped item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, true); - itemTarget->SetSoulboundTradeable(NULL, item_owner, false); + itemTarget->ClearSoulboundTradeable(item_owner); } } @@ -3639,7 +3639,7 @@ void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex) // add new enchanting if equipped item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, true); - itemTarget->SetSoulboundTradeable(NULL, item_owner, false); + itemTarget->ClearSoulboundTradeable(item_owner); } void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex) |