feat(Core/ItemHandler): Optional item recovery (#2442)

This commit is contained in:
IntelligentQuantum
2019-12-09 10:33:33 +03:30
committed by Stoabrogga
parent e337f1e38d
commit b6c0f58dda
8 changed files with 125 additions and 13 deletions

View File

@@ -283,6 +283,8 @@ void WorldSession::HandleDestroyItemOpcode(WorldPacket & recvData)
return;
}
recoveryItem(pItem);
if (count)
{
uint32 i_count = count;
@@ -437,7 +439,7 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket & recvData)
{
std::string Name = pProto->Name1;
std::string Description = pProto->Description;
int loc_idx = GetSessionDbLocaleIndex();
if (loc_idx >= 0)
{
@@ -492,7 +494,7 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket & recvData)
queryData << pProto->Damage[i].DamageMax;
queryData << pProto->Damage[i].DamageType;
}
// resistances (7)
queryData << pProto->Armor;
queryData << pProto->HolyRes;
@@ -501,11 +503,11 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket & recvData)
queryData << pProto->FrostRes;
queryData << pProto->ShadowRes;
queryData << pProto->ArcaneRes;
queryData << pProto->Delay;
queryData << pProto->AmmoType;
queryData << pProto->RangedModRange;
for (int s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
{
// send DBC data for cooldowns in same way as it used in Spell::SendSpellCooldown
@@ -514,11 +516,11 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket & recvData)
if (spell)
{
bool db_data = pProto->Spells[s].SpellCooldown >= 0 || pProto->Spells[s].SpellCategoryCooldown >= 0;
queryData << pProto->Spells[s].SpellId;
queryData << pProto->Spells[s].SpellTrigger;
queryData << uint32(-abs(pProto->Spells[s].SpellCharges));
if (db_data)
{
queryData << uint32(pProto->Spells[s].SpellCooldown);
@@ -699,6 +701,9 @@ void WorldSession::HandleSellItemOpcode(WorldPacket & recvData)
{
if (pProto->SellPrice > 0)
{
if (sWorld->getBoolConfig(CONFIG_ITEMDELETE_VENDOR))
recoveryItem(pItem);
if (count < pItem->GetCount()) // need split items
{
Item* pNewItem = pItem->CloneItem(count, _player);
@@ -784,6 +789,14 @@ void WorldSession::HandleBuybackItem(WorldPacket & recvData)
_player->ItemAddedQuestCheck(pItem->GetEntry(), pItem->GetCount());
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, pItem->GetEntry(), pItem->GetCount());
_player->StoreItem(dest, pItem, true);
if (sWorld->getBoolConfig(CONFIG_ITEMDELETE_VENDOR))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RECOVERY_ITEM);
stmt->setUInt32(0, _player->GetGUID());
stmt->setUInt32(1, pItem->GetEntry());
CharacterDatabase.Execute(stmt);
}
}
else
_player->SendEquipError(msg, pItem, NULL);
@@ -1241,7 +1254,7 @@ void WorldSession::HandleItemNameQueryOpcode(WorldPacket & recvData)
if (loc_idx >= 0)
if (ItemSetNameLocale const* isnl = sObjectMgr->GetItemSetNameLocale(itemid))
ObjectMgr::GetLocaleString(isnl->Name, loc_idx, Name);
WorldPacket data(SMSG_ITEM_NAME_QUERY_RESPONSE, (4+Name.size()+1+4));
data << uint32(itemid);
data << Name;
@@ -1632,7 +1645,7 @@ void WorldSession::HandleItemRefund(WorldPacket &recvData)
#endif
return;
}
// Don't try to refund item currently being disenchanted
if (_player->GetLootGUID() == guid)
return;
@@ -1687,3 +1700,23 @@ bool WorldSession::CanUseBank(uint64 bankerGUID) const
return true;
}
bool WorldSession::recoveryItem(Item* pItem)
{
if (sWorld->getBoolConfig(CONFIG_ITEMDELETE_METHOD)
&& pItem->GetTemplate()->Quality >= sWorld->getIntConfig(CONFIG_ITEMDELETE_QUALITY)
&& pItem->GetTemplate()->ItemLevel >= sWorld->getIntConfig(CONFIG_ITEMDELETE_ITEM_LEVEL))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_RECOVERY_ITEM);
stmt->setUInt32(0, pItem->GetOwnerGUID());
stmt->setUInt32(1, pItem->GetTemplate()->ItemId);
stmt->setUInt32(2, pItem->GetCount());
CharacterDatabase.Query(stmt);
return true;
}
return false;
}

View File

@@ -952,6 +952,8 @@ class WorldSession
bool CanUseBank(uint64 bankerGUID = 0) const;
bool recoveryItem(Item* pItem);
// EnumData helpers
bool IsLegitCharacterForAccount(uint32 lowGUID)
{

View File

@@ -1192,6 +1192,12 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_CHARDELETE_MIN_LEVEL] = sConfigMgr->GetIntDefault("CharDelete.MinLevel", 0);
m_int_configs[CONFIG_CHARDELETE_KEEP_DAYS] = sConfigMgr->GetIntDefault("CharDelete.KeepDays", 30);
///- Load the ItemDelete related config options
m_bool_configs[CONFIG_ITEMDELETE_METHOD] = sConfigMgr->GetBoolDefault("ItemDelete.Method", 0);
m_bool_configs[CONFIG_ITEMDELETE_VENDOR] = sConfigMgr->GetBoolDefault("ItemDelete.Vendor", 0);
m_int_configs[CONFIG_ITEMDELETE_QUALITY] = sConfigMgr->GetIntDefault("ItemDelete.Quality", 3);
m_int_configs[CONFIG_ITEMDELETE_ITEM_LEVEL] = sConfigMgr->GetIntDefault("ItemDelete.ItemLevel", 80);
///- Read the "Data" directory from the config file
std::string dataPath = sConfigMgr->GetStringDefault("DataDir", "./");
if (dataPath.empty() || (dataPath.at(dataPath.length()-1) != '/' && dataPath.at(dataPath.length()-1) != '\\'))

View File

@@ -171,6 +171,8 @@ enum WorldBoolConfigs
CONFIG_LFG_LOCATION_ALL, // Player can join LFG anywhere
CONFIG_PRELOAD_ALL_NON_INSTANCED_MAP_GRIDS,
CONFIG_ALLOW_TWO_SIDE_INTERACTION_EMOTE,
CONFIG_ITEMDELETE_METHOD,
CONFIG_ITEMDELETE_VENDOR,
BOOL_CONFIG_VALUE_COUNT
};
@@ -344,6 +346,8 @@ enum WorldIntConfigs
CONFIG_AFK_PREVENT_LOGOUT,
CONFIG_ICC_BUFF_HORDE,
CONFIG_ICC_BUFF_ALLIANCE,
CONFIG_ITEMDELETE_QUALITY,
CONFIG_ITEMDELETE_ITEM_LEVEL,
INT_CONFIG_VALUE_COUNT
};

View File

@@ -25,6 +25,7 @@
# NETWORK CONFIG
# CONSOLE AND REMOTE ACCESS
# CHARACTER DELETE OPTIONS
# ITEM DELETE OPTIONS
# CUSTOM SERVER OPTIONS
#
###################################################################################################
@@ -1456,11 +1457,11 @@ Motd = "Welcome to an AzerothCore server."
# All the AzerothCore contributors, as well as its father projects (MaNGOS, TrinityCore, etc..),
# have worked for free to provide you this software. Please do not remove the credits.
#
# Changing or removing such hardcoded text is considered a violation of our license
# Changing or removing such hardcoded text is considered a violation of our license
# and it's not allowed. We reserve the right to take legal action in case of violations.
# Furthermore, any kind of support will be always denied.
#
# All AzerothCore contributors and its father projects are publicly listed in
# All AzerothCore contributors and its father projects are publicly listed in
# our official repository. Credits to open source contributions should always be shown.
#
@@ -2966,6 +2967,55 @@ CharDelete.KeepDays = 30
#
###################################################################################################
###################################################################################################
# ITEM DELETE OPTIONS
#
# ItemDelete.Method
# Description: Item deletion behavior.
# Default: 0 - (Completely remove item from the database)
# 1 - (Save Item to database)
ItemDelete.Method = 0
#
# ItemDelete.Vendor
# Description: Saving items into database when the player sells items to vendor
# Default: 0 (disabled)
# 1 (enabled)
#
ItemDelete.Vendor = 0
#
# ItemDelete.Quality
# Description: Saving items into database that have quality greater or equal to ItemDelete.Quality
#
# ID | Color | Quality
# 0 | Grey | Poor
# 1 | White | Common
# 2 | Green | Uncommon
# 3 | Blue | Rare
# 4 | Purple| Epic
# 5 | Orange| Legendary
# 6 | Red | Artifact
# 7 | Gold | Bind to Account
#
# Default: 3
#
ItemDelete.Quality = 3
#
# ItemDelete.ItemLevel
# Description: Saving items into database that are Item Levels greater or equal to ItemDelete.ItemLevel
# Default: 80
#
ItemDelete.ItemLevel = 80
#
###################################################################################################
###################################################################################################
# CUSTOM SERVER OPTIONS
#
@@ -3265,7 +3315,7 @@ Minigob.Manabonk.Enable = 1
# Description: Logs actions, e.g. account login and logout to name a few, based on IP of current session.
# Default: 0 - (Disabled)
# 1 - (Enabled)
Allow.IP.Based.Action.Logging = 0
# Calculate.Creature.Zone.Area.Data
@@ -3284,8 +3334,8 @@ Calculate.Gameoject.Zone.Area.Data = 0
# LFG SETTINGS
#
# Includes satellite to search for work elsewhere LFG
# Default: 0 - Disable
# 1 - Enable
# Default: 0 - Disable
# 1 - Enable
LFG.Location.All = 0