From a0f37f79f409cbd1680915c002418a0d2df0f78d Mon Sep 17 00:00:00 2001 From: Winfidonarleyan Date: Sat, 7 Oct 2023 23:44:16 +0700 Subject: [PATCH] feat(Modules/ItemAddTalent): implement module for add talents via item --- .../conf/ItemAddTalent.conf.dist | 27 +++++++++++ .../2023_10_07_00_item_add_talent.sql | 8 ++++ .../mod-item-add-talent/src/ItemAddTalent.cpp | 43 +++++++++++++++++ .../mod-item-add-talent/src/ItemAddTalent.h | 48 +++++++++++++++++++ .../src/ItemAddTalent_SC.cpp | 48 +++++++++++++++++++ .../src/item_add_talent_loader.cpp | 25 ++++++++++ 6 files changed, 199 insertions(+) create mode 100644 modules/mod-item-add-talent/conf/ItemAddTalent.conf.dist create mode 100644 modules/mod-item-add-talent/sql/db_world/2023_10_07_00_item_add_talent.sql create mode 100644 modules/mod-item-add-talent/src/ItemAddTalent.cpp create mode 100644 modules/mod-item-add-talent/src/ItemAddTalent.h create mode 100644 modules/mod-item-add-talent/src/ItemAddTalent_SC.cpp create mode 100644 modules/mod-item-add-talent/src/item_add_talent_loader.cpp diff --git a/modules/mod-item-add-talent/conf/ItemAddTalent.conf.dist b/modules/mod-item-add-talent/conf/ItemAddTalent.conf.dist new file mode 100644 index 000000000..811139c47 --- /dev/null +++ b/modules/mod-item-add-talent/conf/ItemAddTalent.conf.dist @@ -0,0 +1,27 @@ +# +# This file is part of the WarheadCore Project. See AUTHORS file for Copyright information +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by the +# Free Software Foundation; either version 3 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 Affero 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 . +# + +######################################## +# ItemAddTalent module configuration +######################################## +# +# ItemAddTalent.Enable +# Description: Enable this module +# Default: 0 +# + +ItemAddTalent.Enable = 0 diff --git a/modules/mod-item-add-talent/sql/db_world/2023_10_07_00_item_add_talent.sql b/modules/mod-item-add-talent/sql/db_world/2023_10_07_00_item_add_talent.sql new file mode 100644 index 000000000..8571ee5f5 --- /dev/null +++ b/modules/mod-item-add-talent/sql/db_world/2023_10_07_00_item_add_talent.sql @@ -0,0 +1,8 @@ +-- Add item +SET @ITEM_ID := 114000; + +DELETE FROM `item_template` +WHERE `entry` = @ITEM_ID; + +INSERT INTO `item_template` + VALUES (@ITEM_ID, 0, 0, - 1, 'Add talent token', 46787, 6, 0, 0, 1, 0, 0, 0, - 1, - 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000, 0, 0, 18282, 0, 0, 0, 8000, 0, - 1, 0, 0, 0, 0, - 1, 0, - 1, 0, 0, 0, 0, - 1, 0, - 1, 0, 0, 0, 0, - 1, 0, - 1, 0, 0, 0, 0, - 1, 0, - 1, 0, '|cff00FF00Использование: Добавить себе 1 талант.|r', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 'ItemAddTalent_Item', 0, 0, 0, 0, 0, - 4); \ No newline at end of file diff --git a/modules/mod-item-add-talent/src/ItemAddTalent.cpp b/modules/mod-item-add-talent/src/ItemAddTalent.cpp new file mode 100644 index 000000000..6676a8f0f --- /dev/null +++ b/modules/mod-item-add-talent/src/ItemAddTalent.cpp @@ -0,0 +1,43 @@ +/* + * This file is part of the WarheadCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 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 Affero 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 . + */ + +#include "ItemAddTalent.h" +#include "ModulesConfig.h" +#include "Player.h" +#include "Item.h" + +ItemAddTalentMgr* ItemAddTalentMgr::instance() +{ + static ItemAddTalentMgr instance; + return &instance; +} + +void ItemAddTalentMgr::LoadConfig(bool /*reload*/) +{ + _isEnable = MOD_CONF_GET_BOOL("ItemAddTalent.Enable"); +} + +bool ItemAddTalentMgr::OnPlayerItemUse(Player* player, Item* item) +{ + if (!_isEnable) + return false; + + player->RewardExtraBonusTalentPoints(1); + player->InitTalentForLevel(); + player->DestroyItemCount(item->GetEntry(), 1, true); + return true; +} \ No newline at end of file diff --git a/modules/mod-item-add-talent/src/ItemAddTalent.h b/modules/mod-item-add-talent/src/ItemAddTalent.h new file mode 100644 index 000000000..d63beeee7 --- /dev/null +++ b/modules/mod-item-add-talent/src/ItemAddTalent.h @@ -0,0 +1,48 @@ +/* + * This file is part of the WarheadCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 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 Affero 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 . + */ + +#ifndef _ITEM_ADD_TALENT_H_ +#define _ITEM_ADD_TALENT_H_ + +#include "Define.h" + +class Player; +class Item; + +class ItemAddTalentMgr +{ +public: + static ItemAddTalentMgr* instance(); + + void LoadConfig(bool reload); + bool OnPlayerItemUse(Player* player, Item* item); + +private: + bool _isEnable{ false }; + + ItemAddTalentMgr() = default; + ~ItemAddTalentMgr() = default; + + ItemAddTalentMgr(ItemAddTalentMgr const&) = delete; + ItemAddTalentMgr(ItemAddTalentMgr&&) = delete; + ItemAddTalentMgr& operator=(ItemAddTalentMgr const&) = delete; + ItemAddTalentMgr& operator=(ItemAddTalentMgr&&) = delete; +}; + +#define sItemAddTalentMgr ItemAddTalentMgr::instance() + +#endif // _ITEM_ADD_TALENT_H_ \ No newline at end of file diff --git a/modules/mod-item-add-talent/src/ItemAddTalent_SC.cpp b/modules/mod-item-add-talent/src/ItemAddTalent_SC.cpp new file mode 100644 index 000000000..ff9604d0a --- /dev/null +++ b/modules/mod-item-add-talent/src/ItemAddTalent_SC.cpp @@ -0,0 +1,48 @@ +/* + * This file is part of the WarheadCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 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 Affero 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 . + */ + +#include "ItemAddTalent.h" +#include "ScriptObject.h" + +class ItemAddTalent_Item : public ItemScript +{ +public: + ItemAddTalent_Item() : ItemScript("ItemAddTalent_Item") {} + + bool OnUse(Player* player, Item* item, const SpellCastTargets& /*Targets*/) override + { + return sItemAddTalentMgr->OnPlayerItemUse(player, item); + } +}; + +class ItemAddTalent_World : public WorldScript +{ +public: + ItemAddTalent_World() : WorldScript("ItemAddTalent_World") { } + + void OnAfterConfigLoad(bool reload) override + { + sItemAddTalentMgr->LoadConfig(reload); + } +}; + +// Group all custom scripts +void AddSC_ItemAddTalent() +{ + new ItemAddTalent_Item(); + new ItemAddTalent_World(); +} \ No newline at end of file diff --git a/modules/mod-item-add-talent/src/item_add_talent_loader.cpp b/modules/mod-item-add-talent/src/item_add_talent_loader.cpp new file mode 100644 index 000000000..8f120cc05 --- /dev/null +++ b/modules/mod-item-add-talent/src/item_add_talent_loader.cpp @@ -0,0 +1,25 @@ +/* + * This file is part of the WarheadCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 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 Affero 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 . + */ + +// From SC +void AddSC_ItemAddTalent(); + +// Add all +void Addmod_item_add_talentScripts() +{ + AddSC_ItemAddTalent(); +} \ No newline at end of file