Skip to content

Commit

Permalink
[Place Creature] Make it possible to set your desired effect (otland#…
Browse files Browse the repository at this point in the history
…3914)

(cherry picked from commit 76d4aa5)
  • Loading branch information
dbjorkholm authored and Codinablack committed Apr 5, 2022
1 parent 35c4c97 commit 5b44ea4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/game.cpp
Expand Up @@ -540,7 +540,7 @@ bool Game::internalPlaceCreature(Creature* creature, const Position& pos, bool e
return true;
}

bool Game::placeCreature(Creature* creature, const Position& pos, bool extendedPos /*=false*/, bool forced /*= false*/)
bool Game::placeCreature(Creature* creature, const Position& pos, bool extendedPos /*=false*/, bool forced /*= false*/, MagicEffectClasses magicEffect /*= CONST_ME_TELEPORT*/)
{
if (!internalPlaceCreature(creature, pos, extendedPos, forced)) {
return false;
Expand All @@ -550,7 +550,7 @@ bool Game::placeCreature(Creature* creature, const Position& pos, bool extendedP
map.getSpectators(spectators, creature->getPosition(), true);
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), true);
tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), magicEffect);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Expand Up @@ -183,7 +183,7 @@ class Game
* \param extendedPos If true, the creature will in first-hand be placed 2 tiles away
* \param force If true, placing the creature will not fail because of obstacles (creatures/items)
*/
bool placeCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool forced = false);
bool placeCreature(Creature* creature, const Position& pos, bool extendedPos = false, bool forced = false, MagicEffectClasses magicEffect = CONST_ME_TELEPORT);

/**
* Remove Creature from the map.
Expand Down
16 changes: 9 additions & 7 deletions src/luascript.cpp
Expand Up @@ -4503,7 +4503,7 @@ int LuaScriptInterface::luaGameCreateContainer(lua_State* L)

int LuaScriptInterface::luaGameCreateMonster(lua_State* L)
{
// Game.createMonster(monsterName, position[, extended = false[, force = false]])
// Game.createMonster(monsterName, position[, extended = false[, force = false[, magicEffect = CONST_ME_TELEPORT]]])
Monster* monster = Monster::createMonster(getString(L, 1));
if (!monster) {
lua_pushnil(L);
Expand All @@ -4513,8 +4513,9 @@ int LuaScriptInterface::luaGameCreateMonster(lua_State* L)
const Position& position = getPosition(L, 2);
bool extended = getBoolean(L, 3, false);
bool force = getBoolean(L, 4, false);
MagicEffectClasses magicEffect = getNumber<MagicEffectClasses>(L, 5, CONST_ME_TELEPORT);
if (g_events->eventMonsterOnSpawn(monster, position, false, true) || force) {
if (g_game.placeCreature(monster, position, extended, force)) {
if (g_game.placeCreature(monster, position, extended, force, magicEffect)) {
pushUserdata<Monster>(L, monster);
setMetatable(L, -1, "Monster");
} else {
Expand All @@ -4530,7 +4531,7 @@ int LuaScriptInterface::luaGameCreateMonster(lua_State* L)

int LuaScriptInterface::luaGameCreateNpc(lua_State* L)
{
// Game.createNpc(npcName, position[, extended = false[, force = false]])
// Game.createNpc(npcName, position[, extended = false[, force = false[, magicEffect = CONST_ME_TELEPORT]]])
Npc* npc = Npc::createNpc(getString(L, 1));
if (!npc) {
lua_pushnil(L);
Expand All @@ -4540,7 +4541,8 @@ int LuaScriptInterface::luaGameCreateNpc(lua_State* L)
const Position& position = getPosition(L, 2);
bool extended = getBoolean(L, 3, false);
bool force = getBoolean(L, 4, false);
if (g_game.placeCreature(npc, position, extended, force)) {
MagicEffectClasses magicEffect = getNumber<MagicEffectClasses>(L, 5, CONST_ME_TELEPORT);
if (g_game.placeCreature(npc, position, extended, force, magicEffect)) {
pushUserdata<Npc>(L, npc);
setMetatable(L, -1, "Npc");
} else {
Expand Down Expand Up @@ -10149,7 +10151,7 @@ int LuaScriptInterface::luaPlayerSetEditHouse(lua_State* L)

int LuaScriptInterface::luaPlayerSetGhostMode(lua_State* L)
{
// player:setGhostMode(enabled[, showEffect=true])
// player:setGhostMode(enabled[, magicEffect = CONST_ME_TELEPORT])
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
Expand All @@ -10162,7 +10164,7 @@ int LuaScriptInterface::luaPlayerSetGhostMode(lua_State* L)
return 1;
}

bool showEffect = getBoolean(L, 3, true);
MagicEffectClasses magicEffect = getNumber<MagicEffectClasses>(L, 3, CONST_ME_TELEPORT);

player->switchGhostMode();

Expand All @@ -10178,7 +10180,7 @@ int LuaScriptInterface::luaPlayerSetGhostMode(lua_State* L)
if (enabled) {
tmpPlayer->sendRemoveTileCreature(player, position, tile->getClientIndexOfCreature(tmpPlayer, player));
} else {
tmpPlayer->sendCreatureAppear(player, position, showEffect);
tmpPlayer->sendCreatureAppear(player, position, magicEffect);
}
} else {
if (isInvisible) {
Expand Down
1 change: 0 additions & 1 deletion src/monster.cpp
Expand Up @@ -999,7 +999,6 @@ void Monster::onThinkDefense(uint32_t interval)
summon->setSkillLoss(false);
summon->setMaster(this);
g_game.addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE);
g_game.addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT);
} else {
delete summon;
}
Expand Down
6 changes: 3 additions & 3 deletions src/player.h
Expand Up @@ -740,9 +740,9 @@ class Player final : public Creature, public Cylinder
client->sendChannelEvent(channelId, playerName, channelEvent);
}
}
void sendCreatureAppear(const Creature* creature, const Position& pos, bool isLogin) {
void sendCreatureAppear(const Creature* creature, const Position& pos, MagicEffectClasses magicEffect = CONST_ME_NONE) {
if (client) {
client->sendAddCreature(creature, pos, creature->getTile()->getClientIndexOfCreature(this, creature), isLogin);
client->sendAddCreature(creature, pos, creature->getTile()->getClientIndexOfCreature(this, creature), magicEffect);
}
}
void sendCreatureMove(const Creature* creature, const Position& newPos, int32_t newStackPos, const Position& oldPos, int32_t oldStackPos, bool teleport) {
Expand Down Expand Up @@ -799,7 +799,7 @@ class Player final : public Creature, public Cylinder
}

if (visible) {
client->sendAddCreature(creature, creature->getPosition(), stackpos, false);
client->sendAddCreature(creature, creature->getPosition(), stackpos);
} else {
client->sendRemoveTileCreature(creature, creature->getPosition(), stackpos);
}
Expand Down
18 changes: 9 additions & 9 deletions src/protocolgame.cpp
Expand Up @@ -265,7 +265,7 @@ void ProtocolGame::connect(uint32_t playerId, OperatingSystem_t operatingSystem)
player->isConnecting = false;

player->client = getThis();
sendAddCreature(player, player->getPosition(), 0, false);
sendAddCreature(player, player->getPosition(), 0);
player->lastIP = player->getIP();
player->lastLoginSaved = std::max<time_t>(time(nullptr), player->lastLoginSaved + 1);
player->resetIdleTime();
Expand Down Expand Up @@ -2493,7 +2493,7 @@ void ProtocolGame::sendFightModes()
writeToOutputBuffer(msg);
}

void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos, int32_t stackpos, bool isLogin)
void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos, int32_t stackpos, MagicEffectClasses magicEffect/*= CONST_ME_NONE*/)
{
if (!canSee(pos)) {
return;
Expand Down Expand Up @@ -2525,8 +2525,8 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos
writeToOutputBuffer(msg);
}

if (isLogin) {
sendMagicEffect(pos, CONST_ME_TELEPORT);
if (magicEffect != CONST_ME_NONE) {
sendMagicEffect(pos, magicEffect);
}
return;
}
Expand Down Expand Up @@ -2559,9 +2559,9 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos
sendPendingStateEntered();
sendEnterWorld();
sendMapDescription(pos);

if (isLogin) {
sendMagicEffect(pos, CONST_ME_TELEPORT);
// send login effect
if (magicEffect != CONST_ME_NONE) {
sendMagicEffect(pos, magicEffect);
}

for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) {
Expand Down Expand Up @@ -2633,7 +2633,7 @@ void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& ne
} else if (canSee(oldPos) && canSee(creature->getPosition())) {
if (teleport || (oldPos.z == 7 && newPos.z >= 8)) {
sendRemoveTileCreature(creature, oldPos, oldStackPos);
sendAddCreature(creature, newPos, newStackPos, false);
sendAddCreature(creature, newPos, newStackPos);
} else {
NetworkMessage msg;
msg.addByte(0x6D);
Expand All @@ -2650,7 +2650,7 @@ void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& ne
} else if (canSee(oldPos)) {
sendRemoveTileCreature(creature, oldPos, oldStackPos);
} else if (canSee(creature->getPosition())) {
sendAddCreature(creature, newPos, newStackPos, false);
sendAddCreature(creature, newPos, newStackPos);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocolgame.h
Expand Up @@ -237,7 +237,7 @@ class ProtocolGame final : public Protocol
void sendRemoveTileCreature(const Creature* creature, const Position& pos, uint32_t stackpos);
void sendUpdateTile(const Tile* tile, const Position& pos);

void sendAddCreature(const Creature* creature, const Position& pos, int32_t stackpos, bool isLogin);
void sendAddCreature(const Creature* creature, const Position& pos, int32_t stackpos, MagicEffectClasses magicEffect = CONST_ME_NONE);
void sendMoveCreature(const Creature* creature, const Position& newPos, int32_t newStackPos,
const Position& oldPos, int32_t oldStackPos, bool teleport);

Expand Down

0 comments on commit 5b44ea4

Please sign in to comment.