Skip to content

Commit

Permalink
[Fix] remove summon bug and added new config tag for teleport summon (#…
Browse files Browse the repository at this point in the history
…428)

Added new config.lua tag: teleportSummons = false
Usage: if false, the summon will not teleport when the player goes up/down stairs and moves far away, if true, it will teleport the summon
Fixed the bug that did not remove the summon when the player leaves the summon range, thus preventing the player from summoning a new monster
  • Loading branch information
beats-dh authored Jul 19, 2022
1 parent d30923f commit 5bd86e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ autoLoot = false
-- autoBank = true, the dropped coins from monsters will be automatically
-- deposited to your bank account.
autoBank = false
-- teleporte summon
-- true will never remove the summon
teleportSummons = false

-- Stamina in Trainers
staminaTrainer = false
Expand Down
1 change: 1 addition & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum booleanConfig_t {
AUTOBANK,
RATE_USE_STAGES,
INVENTORY_GLOW,
TELEPORT_SUMMONS,
TOGGLE_DOWNLOAD_MAP,

LAST_BOOLEAN_CONFIG
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ bool ConfigManager::load()
boolean[SORT_LOOT_BY_CHANCE] = getGlobalBoolean(L, "sortLootByChance", false);
boolean[TOGGLE_SAVE_INTERVAL] = getGlobalBoolean(L, "toggleSaveInterval", false);
boolean[TOGGLE_SAVE_INTERVAL_CLEAN_MAP] = getGlobalBoolean(L, "toggleSaveIntervalCleanMap", false);
boolean[TELEPORT_SUMMONS] = getGlobalBoolean(L, "teleportSummons", false);

boolean[ONLY_PREMIUM_ACCOUNT] = getGlobalBoolean(L, "onlyPremiumAccount", false);
boolean[RATE_USE_STAGES] = getGlobalBoolean(L, "rateUseStages", false);
Expand Down
31 changes: 20 additions & 11 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,29 +447,38 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone)
void Creature::checkSummonMove(const Position& newPos, bool teleportSummon) const
{
if (hasSummons()) {
// Check if any of our summons is out of range (+/- 2 floors or 30 tiles away)
std::forward_list<Creature*> despawnMonsterList;
std::vector<Creature*> despawnMonsterList;
for (Creature* creature : getSummons()) {
if (!creature) {
continue;
}

const Monster* monster = creature->getMonster();
// Check is is familiar for teleport to the master, if "teleportSummon" is true, this is not executed
const Position& pos = creature->getPosition();
if (!teleportSummon && !monster->isFamiliar()) {
SPDLOG_DEBUG("[Creature::checkSummonMove] - Creature name {}", creature->getName());
const Monster* monster = creature->getMonster();
bool protectionZoneCheck = this->getTile()->hasFlag(TILESTATE_PROTECTIONZONE);
// Check if any of our summons is out of range (+/- 0 floors or 15 tiles away)
bool checkSummonDist = Position::getDistanceZ(newPos, pos) > 0 ||
(std::max<int32_t>(Position::getDistanceX(newPos, pos),
Position::getDistanceY(newPos, pos)) > 15);
// Check if any of our summons is out of range (+/- 2 floors or 30 tiles away)
bool checkRemoveDist = Position::getDistanceZ(newPos, pos) > 2 ||
(std::max<int32_t>(Position::getDistanceX(newPos, pos),
Position::getDistanceY(newPos, pos)) > 30);

if (monster->isFamiliar() && checkSummonDist || teleportSummon && !protectionZoneCheck && checkSummonDist) {
g_game().internalTeleport(creature, creature->getMaster()->getPosition(), true);
continue;
}

if (Position::getDistanceZ(newPos, pos) > 0 || (std::max<int32_t>(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 15))
{
g_game().internalTeleport(creature, creature->getMaster()->getPosition(), true);
if (monster->isSummon() && !monster->isFamiliar() && !teleportSummon && checkRemoveDist) {
despawnMonsterList.push_back(creature);
}
}

for (Creature* despawnCreature : despawnMonsterList) {
g_game().removeCreature(despawnCreature, true);
if (!despawnMonsterList.empty()) {
g_game().removeCreature(despawnCreature, true);
}
}
}
}
Expand All @@ -493,7 +502,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos
stopEventWalk();
}

checkSummonMove(newPos, false);
checkSummonMove(newPos, g_configManager().getBoolean(TELEPORT_SUMMONS));

if (Player* player = creature->getPlayer()) {
if (player->isExerciseTraining()){
Expand Down

0 comments on commit 5bd86e6

Please sign in to comment.