Skip to content

Commit

Permalink
Added Player:onInventoryUpgrade, thanks @oen432
Browse files Browse the repository at this point in the history
Added this needed method to work along with upgrade system, here: https://github.com/Oen44/TFS-Upgrade-System/tree/master/scripts/UpgradeSystem

Co-Authored-By: Oen44 <lach@includespark.eu>
  • Loading branch information
ralke23 and Oen44 committed Mar 17, 2023
1 parent fdcdabd commit dbbccb9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define FS_DEFINITIONS_H_877452FEC245450C9F96B8FD268D8963

static constexpr auto STATUS_SERVER_NAME = "The Forgotten Server";
static constexpr auto STATUS_SERVER_VERSION = "1.5 (Nekiro's 8.60 downgrade)";
static constexpr auto STATUS_SERVER_DEVELOPERS = "Mark Samman";
static constexpr auto STATUS_SERVER_VERSION = "1.5 (GreedOT)";
static constexpr auto STATUS_SERVER_DEVELOPERS = "Mark Samman, later modified by ralke";

static constexpr auto CLIENT_VERSION_MIN = 860;
static constexpr auto CLIENT_VERSION_MAX = 860;
Expand Down
32 changes: 32 additions & 0 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ bool Events::load()
info.playerOnLoseExperience = event;
} else if (methodName == "onGainSkillTries") {
info.playerOnGainSkillTries = event;
} else if (methodName == "onInventoryUpdate") {
info.playerOnInventoryUpdate = event;
} else {
std::cout << "[Warning - Events::load] Unknown player method: " << methodName << std::endl;
}
Expand Down Expand Up @@ -935,6 +937,36 @@ void Events::eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_
scriptInterface.resetScriptEnv();
}

void Events::eventPlayerOnInventoryUpdate(Player* player, Item* item, slots_t slot, bool equip)
{
// Player:onInventoryUpdate(item, slot, equip)
if (info.playerOnInventoryUpdate == -1) {
return;
}

if (!scriptInterface.reserveScriptEnv()) {
std::cout << "[Error - Events::eventPlayerOnInventoryUpdate] Call stack overflow" << std::endl;
return;
}

ScriptEnvironment* env = scriptInterface.getScriptEnv();
env->setScriptId(info.playerOnInventoryUpdate, &scriptInterface);

lua_State* L = scriptInterface.getLuaState();
scriptInterface.pushFunction(info.playerOnInventoryUpdate);

LuaScriptInterface::pushUserdata<Player>(L, player);
LuaScriptInterface::setMetatable(L, -1, "Player");

LuaScriptInterface::pushUserdata<Item>(L, item);
LuaScriptInterface::setItemMetatable(L, -1, item);

lua_pushnumber(L, slot);
LuaScriptInterface::pushBoolean(L, equip);

scriptInterface.callVoidFunction(4);
}

void Events::eventMonsterOnDropLoot(Monster* monster, Container* corpse)
{
// Monster:onDropLoot(corpse)
Expand Down
3 changes: 3 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "luascript.h"
#include "const.h"
#include "creature.h"

class Party;
class ItemType;
Expand Down Expand Up @@ -59,6 +60,7 @@ class Events
int32_t playerOnGainExperience = -1;
int32_t playerOnLoseExperience = -1;
int32_t playerOnGainSkillTries = -1;
int32_t playerOnInventoryUpdate = -1;

// Monster
int32_t monsterOnDropLoot = -1;
Expand Down Expand Up @@ -99,6 +101,7 @@ class Events
void eventPlayerOnGainExperience(Player* player, Creature* source, uint64_t& exp, uint64_t rawExp);
void eventPlayerOnLoseExperience(Player* player, uint64_t& exp);
void eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_t& tries);
void eventPlayerOnInventoryUpdate(Player* player, Item* item, slots_t slot, bool equip);

// Monster
void eventMonsterOnDropLoot(Monster* monster, Container* corpse);
Expand Down
2 changes: 2 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,7 @@ void Player::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_
if (link == LINK_OWNER) {
//calling movement scripts
g_moveEvents->onPlayerEquip(this, thing->getItem(), static_cast<slots_t>(index), false);
g_events->eventPlayerOnInventoryUpdate(this, thing->getItem(), static_cast<slots_t>(index), true);
}

bool requireListUpdate = false;
Expand Down Expand Up @@ -2982,6 +2983,7 @@ void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int
if (link == LINK_OWNER) {
//calling movement scripts
g_moveEvents->onPlayerDeEquip(this, thing->getItem(), static_cast<slots_t>(index));
g_events->eventPlayerOnInventoryUpdate(this, thing->getItem(), static_cast<slots_t>(index), false);
}

bool requireListUpdate = false;
Expand Down

0 comments on commit dbbccb9

Please sign in to comment.