Skip to content

Commit

Permalink
feat(Modules/ItemAddTalent): implement module for add talents via item
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfidonarleyan committed Oct 7, 2023
1 parent 319e1af commit a0f37f7
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/mod-item-add-talent/conf/ItemAddTalent.conf.dist
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#

########################################
# ItemAddTalent module configuration
########################################
#
# ItemAddTalent.Enable
# Description: Enable this module
# Default: 0
#

ItemAddTalent.Enable = 0
Original file line number Diff line number Diff line change
@@ -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);
43 changes: 43 additions & 0 deletions modules/mod-item-add-talent/src/ItemAddTalent.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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;
}
48 changes: 48 additions & 0 deletions modules/mod-item-add-talent/src/ItemAddTalent.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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_
48 changes: 48 additions & 0 deletions modules/mod-item-add-talent/src/ItemAddTalent_SC.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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();
}
25 changes: 25 additions & 0 deletions modules/mod-item-add-talent/src/item_add_talent_loader.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

// From SC
void AddSC_ItemAddTalent();

// Add all
void Addmod_item_add_talentScripts()
{
AddSC_ItemAddTalent();
}

0 comments on commit a0f37f7

Please sign in to comment.