Skip to content

Commit

Permalink
fix bug summon
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Jul 7, 2022
1 parent b996fbe commit 24d44b7
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,

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 @@ -181,6 +181,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 24d44b7

Please sign in to comment.