aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers/ToyHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Handlers/ToyHandler.cpp')
-rw-r--r--src/server/game/Handlers/ToyHandler.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/server/game/Handlers/ToyHandler.cpp b/src/server/game/Handlers/ToyHandler.cpp
new file mode 100644
index 00000000000..89ed9426c0f
--- /dev/null
+++ b/src/server/game/Handlers/ToyHandler.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Item.h"
+#include "ToyPackets.h"
+#include "WorldSession.h"
+
+void WorldSession::HandleAddToy(WorldPackets::Toy::AddToy& packet)
+{
+ if (!packet.Guid)
+ return;
+
+ Item* item = _player->GetItemByGuid(packet.Guid);
+ if (!item)
+ {
+ _player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, nullptr, nullptr);
+ return;
+ }
+
+ if (!sDB2Manager.GetToyItemIdMatch(item->GetEntry()))
+ return;
+
+ InventoryResult msg = _player->CanUseItem(item);
+ if (msg != EQUIP_ERR_OK)
+ {
+ _player->SendEquipError(msg, item, nullptr);
+ return;
+ }
+
+ if (_player->AddToy(item->GetEntry(), false))
+ _player->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
+}
+
+void WorldSession::HandleUseToy(WorldPackets::Toy::UseToy& packet)
+{
+ ItemTemplate const* item = sObjectMgr->GetItemTemplate(packet.ItemID);
+ if (!item)
+ return;
+
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(packet.Cast.SpellID);
+ if (!spellInfo)
+ {
+ TC_LOG_ERROR("network", "HandleUseToy: unknown spell id: %u used by Toy Item entry %u", packet.Cast.SpellID, packet.ItemID);
+ return;
+ }
+
+ if (_player->isPossessing())
+ return;
+
+ SpellCastTargets targets(_player, packet.Cast);
+
+ Spell* spell = new Spell(_player, spellInfo, TRIGGERED_NONE, ObjectGuid::Empty, false);
+ spell->m_castItemEntry = packet.ItemID;
+ spell->m_cast_count = packet.Cast.CastID;
+ spell->m_misc.Raw.Data[0] = packet.Cast.Misc[0];
+ spell->m_misc.Raw.Data[1] = packet.Cast.Misc[1];
+ spell->m_castFlagsEx |= CAST_FLAG_EX_USE_TOY_SPELL;
+ spell->prepare(&targets);
+}
+
+void WorldSession::HandleToySetFavorite(WorldPackets::Toy::ToySetFavorite& packet)
+{
+ ToyBoxContainer::iterator itr = _toys.find(packet.ItemID);
+ if (itr == _toys.end())
+ return;
+
+ itr->second = packet.Favorite;
+}