Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Podium feature #3858

Merged
merged 11 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<event class="Player" method="onTradeRequest" enabled="0" />
<event class="Player" method="onTradeAccept" enabled="0" />
<event class="Player" method="onTradeCompleted" enabled="0" />
<event class="Player" method="onPodiumRequest" enabled="1" />
<event class="Player" method="onPodiumEdit" enabled="1" />
<event class="Player" method="onGainExperience" enabled="1" />
<event class="Player" method="onLoseExperience" enabled="0" />
<event class="Player" method="onGainSkillTries" enabled="1" />
Expand Down
90 changes: 90 additions & 0 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,96 @@ function Player:onTradeCompleted(target, item, targetItem, isSuccess)
end
end

function Player:onPodiumRequest(item)
local podium = Podium(item.uid)
nekiro marked this conversation as resolved.
Show resolved Hide resolved
if not podium then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return
end

self:sendEditPodium(item)
end

function Player:onPodiumEdit(item, outfit, direction, isVisible)
local podium = Podium(item.uid)
if not podium then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return
end

if not self:getGroup():getAccess() then
-- check if the player is in melee range
if getDistanceBetween(self:getPosition(), item:getPosition()) > 1 then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return
end

-- reset outfit if unable to wear
if not self:canWearOutfit(outfit.lookType, outfit.lookAddons) then
outfit.lookType = 0
end

-- reset mount if unable to ride
local mount = Game.getMountIdByLookType(outfit.lookMount)
if not (mount and self:hasMount(mount)) then
outfit.lookMount = 0
end
end

local podiumOutfit = podium:getOutfit()
local playerOutfit = self:getOutfit()

-- use player outfit if podium is empty
if podiumOutfit.lookType == 0 then
podiumOutfit.lookType = playerOutfit.lookType
podiumOutfit.lookHead = playerOutfit.lookHead
podiumOutfit.lookBody = playerOutfit.lookBody
podiumOutfit.lookLegs = playerOutfit.lookLegs
podiumOutfit.lookFeet = playerOutfit.lookFeet
podiumOutfit.lookAddons = playerOutfit.lookAddons
end

-- set player mount colors podium is empty
if podiumOutfit.lookMount == 0 then
podiumOutfit.lookMount = playerOutfit.lookMount
podiumOutfit.lookMountHead = playerOutfit.lookMountHead
podiumOutfit.lookMountBody = playerOutfit.lookMountBody
podiumOutfit.lookMountLegs = playerOutfit.lookMountLegs
podiumOutfit.lookMountFeet = playerOutfit.lookMountFeet
end

-- "outfit" box checked
if outfit.lookType ~= 0 then
podiumOutfit.lookType = outfit.lookType
podiumOutfit.lookHead = outfit.lookHead
podiumOutfit.lookBody = outfit.lookBody
podiumOutfit.lookLegs = outfit.lookLegs
podiumOutfit.lookFeet = outfit.lookFeet
podiumOutfit.lookAddons = outfit.lookAddons
end

-- "mount" box checked
if outfit.lookMount ~= 0 then
podiumOutfit.lookMount = outfit.lookMount
podiumOutfit.lookMountHead = outfit.lookMountHead
podiumOutfit.lookMountBody = outfit.lookMountBody
podiumOutfit.lookMountLegs = outfit.lookMountLegs
podiumOutfit.lookMountFeet = outfit.lookMountFeet
end

-- prevent invisible podium state
if outfit.lookType == 0 and outfit.lookMount == 0 then
isVisible = true
end

-- save player choices
podium:setFlag(PODIUM_SHOW_PLATFORM, isVisible)
podium:setFlag(PODIUM_SHOW_OUTFIT, outfit.lookType ~= 0)
podium:setFlag(PODIUM_SHOW_MOUNT, outfit.lookMount ~= 0)
podium:setDirection(direction < DIRECTION_NORTHEAST and direction or DIRECTION_SOUTH)
podium:setOutfit(podiumOutfit)
end

local soulCondition = Condition(CONDITION_SOUL, CONDITIONID_DEFAULT)
soulCondition:setTicks(4 * 60 * 1000)
soulCondition:setParameter(CONDITION_PARAM_SOULGAIN, 1)
Expand Down
1 change: 1 addition & 0 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ do
rawgetmetatable("Item").__index = ItemIndex
rawgetmetatable("Container").__index = ItemIndex
rawgetmetatable("Teleport").__index = ItemIndex
rawgetmetatable("Podium").__index = ItemIndex
end

do
Expand Down
1 change: 1 addition & 0 deletions data/lib/core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dofile('data/lib/core/item.lua')
dofile('data/lib/core/itemtype.lua')
dofile('data/lib/core/party.lua')
dofile('data/lib/core/player.lua')
dofile('data/lib/core/podium.lua')
dofile('data/lib/core/position.lua')
dofile('data/lib/core/teleport.lua')
dofile('data/lib/core/tile.lua')
Expand Down
4 changes: 4 additions & 0 deletions data/lib/core/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function Item.isTeleport(self)
return false
end

function Item.isPodium(self)
return false
end

function Item.isTile(self)
return false
end
Expand Down
3 changes: 3 additions & 0 deletions data/lib/core/podium.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Podium.isPodium(self)
return true
end
1 change: 1 addition & 0 deletions data/scripts/actions/others/transforms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ local transformItems = {
[26091] = 26093, [26093] = 26091, -- predator lamp
[26096] = 26094, [26094] = 26096, -- protectress lamp
[26097] = 26095, [26095] = 26097, -- protectress lamp
[38629] = 38630, [38630] = 38629, -- toggle light on podium
}

local transformTo = Action()
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/outputmessage.cpp
${CMAKE_CURRENT_LIST_DIR}/party.cpp
${CMAKE_CURRENT_LIST_DIR}/player.cpp
${CMAKE_CURRENT_LIST_DIR}/podium.cpp
${CMAKE_CURRENT_LIST_DIR}/position.cpp
${CMAKE_CURRENT_LIST_DIR}/protocol.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolgame.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,12 @@ enum PlayerFlags : uint64_t {
PlayerFlag_IgnoreSendPrivateCheck = static_cast<uint64_t>(1) << 39,
};

enum PodiumFlags : uint8_t {
PODIUM_SHOW_PLATFORM = 1 << 0, // show the platform below the outfit
PODIUM_SHOW_OUTFIT = 1 << 1, // show outfit
PODIUM_SHOW_MOUNT = 1 << 2 // show mount
};

enum ReloadTypes_t : uint8_t {
RELOAD_TYPE_ALL,
RELOAD_TYPE_ACTIONS,
Expand Down
63 changes: 63 additions & 0 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ bool Events::load()
info.playerOnTradeAccept = event;
} else if (methodName == "onTradeCompleted") {
info.playerOnTradeCompleted = event;
} else if (methodName == "onPodiumRequest") {
info.playerOnPodiumRequest = event;
} else if (methodName == "onPodiumEdit") {
info.playerOnPodiumEdit = event;
} else if (methodName == "onMoveItem") {
info.playerOnMoveItem = event;
} else if (methodName == "onItemMoved") {
Expand Down Expand Up @@ -868,6 +872,65 @@ void Events::eventPlayerOnTradeCompleted(Player* player, Player* target, Item* i
return scriptInterface.callVoidFunction(5);
}

void Events::eventPlayerOnPodiumRequest(Player* player, Item* item)
{
// Player:onPodiumRequest(item) or Player.onPodiumRequest(self, item)
if (info.playerOnPodiumRequest == -1) {
return;
}

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

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

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

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

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

scriptInterface.callFunction(2);
}

void Events::eventPlayerOnPodiumEdit(Player* player, Item* item, const Outfit_t& outfit, bool podiumVisible, Direction direction)
{
// Player:onPodiumEdit(item, outfit, direction, isVisible) or Player.onPodiumEdit(self, item, outfit, direction, isVisible)
DSpeichert marked this conversation as resolved.
Show resolved Hide resolved
if (info.playerOnPodiumEdit == -1) {
return;
}

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

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

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

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

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

LuaScriptInterface::pushOutfit(L, outfit);

lua_pushnumber(L, direction);
lua_pushboolean(L, podiumVisible);

scriptInterface.callFunction(5);
}

void Events::eventPlayerOnGainExperience(Player* player, Creature* source, uint64_t& exp, uint64_t rawExp)
{
// Player:onGainExperience(source, exp, rawExp)
Expand Down
4 changes: 4 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Events
int32_t playerOnTradeRequest = -1;
int32_t playerOnTradeAccept = -1;
int32_t playerOnTradeCompleted = -1;
int32_t playerOnPodiumRequest = -1;
int32_t playerOnPodiumEdit = -1;
int32_t playerOnGainExperience = -1;
int32_t playerOnLoseExperience = -1;
int32_t playerOnGainSkillTries = -1;
Expand Down Expand Up @@ -99,6 +101,8 @@ class Events
bool eventPlayerOnTradeRequest(Player* player, Player* target, Item* item);
bool eventPlayerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem);
void eventPlayerOnTradeCompleted(Player* player, Player* target, Item* item, Item* targetItem, bool isSuccess);
void eventPlayerOnPodiumRequest(Player* player, Item* item);
void eventPlayerOnPodiumEdit(Player* player, Item* item, const Outfit_t& outfit, bool podiumVisible, Direction direction);
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);
Expand Down
103 changes: 99 additions & 4 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "items.h"
#include "monster.h"
#include "movement.h"
#include "podium.h"
#include "scheduler.h"
#include "server.h"
#include "spells.h"
Expand Down Expand Up @@ -2371,7 +2372,7 @@ void Game::playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stac
}

Item* item = thing->getItem();
if (!item || item->getClientID() != spriteId || !item->isRotatable() || item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID)) {
if (!item || item->getClientID() != spriteId || (!item->isRotatable() && !item->isPodium()) || item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID)) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
}
Expand All @@ -2391,9 +2392,15 @@ void Game::playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stac
return;
}

uint16_t newId = Item::items[item->getID()].rotateTo;
if (newId != 0) {
transformItem(item, newId);
if (item->isPodium()) {
nekiro marked this conversation as resolved.
Show resolved Hide resolved
Podium* podium = item->getPodium();
podium->setDirection(Direction((podium->getDirection() + 1) % 4));
updatePodium(podium);
} else {
uint16_t newId = Item::items[item->getID()].rotateTo;
if (newId != 0) {
transformItem(item, newId);
}
}
}

Expand Down Expand Up @@ -3322,6 +3329,76 @@ void Game::playerRequestOutfit(uint32_t playerId)
player->sendOutfitWindow();
}

void Game::playerRequestEditPodium(uint32_t playerId, const Position& position, uint8_t stackPos, const uint16_t spriteId)
{
Player* player = getPlayerByID(playerId);
if (!player) {
return;
}

Thing* thing = internalGetThing(player, position, stackPos, 0, STACKPOS_TOPDOWN_ITEM);
if (!thing) {
return;
}

const ItemType& it = Item::items.getItemIdByClientId(spriteId);
if (it.id == 0) {
return;
}

Item* item = thing->getItem();
if (!item || item->getClientID() != spriteId || it.type != ITEM_TYPE_PODIUM) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
}

// player has to walk to podium
// gm/god can edit instantly
if (!player->isAccessPlayer()) {
if (position.x != 0xFFFF && !Position::areInRange<1, 1, 0>(position, player->getPosition())) {
std::vector<Direction> listDir;
if (player->getPathTo(position, listDir, 0, 1, true, true)) {
g_dispatcher.addTask(createTask(std::bind(&Game::playerAutoWalk,
this, player->getID(), std::move(listDir))));

SchedulerTask* task = createSchedulerTask(400, std::bind(&Game::playerRequestEditPodium, this,
playerId, position, stackPos, spriteId));
player->setNextWalkActionTask(task);
} else {
player->sendCancelMessage(RETURNVALUE_THEREISNOWAY);
}
return;
}
}

g_events->eventPlayerOnPodiumRequest(player, item);
}

void Game::playerEditPodium(uint32_t playerId, Outfit_t outfit, const Position& position, uint8_t stackPos, const uint16_t spriteId, bool podiumVisible, Direction direction)
{
Player* player = getPlayerByID(playerId);
if (!player) {
return;
}

Thing* thing = internalGetThing(player, position, stackPos, 0, STACKPOS_TOPDOWN_ITEM);
if (!thing) {
return;
}

Item* item = thing->getItem();
if (!item) {
return;
}

const ItemType& it = Item::items.getItemIdByClientId(spriteId);
if (it.id == 0) {
return;
}

g_events->eventPlayerOnPodiumEdit(player, item, outfit, podiumVisible, direction);
}

void Game::playerToggleMount(uint32_t playerId, bool mount)
{
Player* player = getPlayerByID(playerId);
Expand Down Expand Up @@ -5636,6 +5713,24 @@ void Game::removeBedSleeper(uint32_t guid)
}
}

void Game::updatePodium(Item* item) {
EPuncker marked this conversation as resolved.
Show resolved Hide resolved
if (!item->getPodium()) {
return;
}

Tile* tile = item->getTile();
if (!tile) {
return;
}

//send to clients
SpectatorVec spectators;
map.getSpectators(spectators, item->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendUpdateTileItem(tile, item->getPosition(), item);
}
}

Item* Game::getUniqueItem(uint16_t uniqueId)
{
auto it = uniqueItems.find(uniqueId);
Expand Down
Loading