Skip to content

Commit

Permalink
fix: hazard spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Dec 19, 2024
1 parent 34b6fa8 commit dbd8ab6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions data/libs/systems/hazard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ function HazardMonster.onSpawn(monster, position)
if not zones then
return true
end

logger.debug("Monster {} spawned in hazard zone, position {}", monster:getName(), position:toString())
for _, zone in ipairs(zones) do
local hazard = Hazard.getByName(zone:getName())
if hazard then
monster:hazard(true)
if hazard then
monster:hazardCrit(hazard.crit)
monster:hazardDodge(hazard.dodge)
monster:hazardDamageBoost(hazard.damageBoost)
monster:hazardDefenseBoost(hazard.defenseBoost)
end
monster:hazardCrit(hazard.crit)
monster:hazardDodge(hazard.dodge)
monster:hazardDamageBoost(hazard.damageBoost)
monster:hazardDefenseBoost(hazard.defenseBoost)
end
end
return true
Expand Down
3 changes: 2 additions & 1 deletion data/scripts/lib/register_monster_type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ registerMonsterType.flags = function(mtype, mask)
end
if mask.flags.rewardBoss then
mtype:isRewardBoss(mask.flags.rewardBoss)
mtype.onSpawn = function(monster)
mtype.onSpawn = function(monster, spawnPosition)
monster:setRewardBoss()
HazardMonster.onSpawn(monster, spawnPosition)
end
end
if mask.flags.familiar then
Expand Down
7 changes: 4 additions & 3 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ void Monster::onAttackedByPlayer(const std::shared_ptr<Player> &attackerPlayer)
}
}

void Monster::onSpawn() {
void Monster::onSpawn(const Position &position) {
if (mType->info.spawnEvent != -1) {
// onSpawn(self)
// onSpawn(self, spawnPosition)
LuaScriptInterface* scriptInterface = mType->info.scriptInterface;
if (!scriptInterface->reserveScriptEnv()) {
g_logger().error("Monster {} creature {}] Call stack overflow. Too many lua "
Expand All @@ -532,8 +532,9 @@ void Monster::onSpawn() {

LuaScriptInterface::pushUserdata<Monster>(L, getMonster());
LuaScriptInterface::setMetatable(L, -1, "Monster");
LuaScriptInterface::pushPosition(L, position);

scriptInterface->callVoidFunction(1);
scriptInterface->callVoidFunction(2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Monster final : public Creature {
void onCreatureMove(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Tile> &newTile, const Position &newPos, const std::shared_ptr<Tile> &oldTile, const Position &oldPos, bool teleport) override;
void onCreatureSay(const std::shared_ptr<Creature> &creature, SpeakClasses type, const std::string &text) override;
void onAttackedByPlayer(const std::shared_ptr<Player> &attackerPlayer);
void onSpawn();
void onSpawn(const Position &position);

void drainHealth(const std::shared_ptr<Creature> &attacker, int32_t damage) override;
void changeHealth(int32_t healthChange, bool sendHealthChange = true) override;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ bool SpawnMonster::spawnMonster(uint32_t spawnMonsterId, spawnBlock_t &sb, const

spawnedMonsterMap[spawnMonsterId] = monster;
sb.lastSpawn = OTSYS_TIME();
monster->onSpawn();
monster->onSpawn(sb.pos);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) {
const bool extended = Lua::getBoolean(L, 3, false);
const bool force = Lua::getBoolean(L, 4, false);
if (g_game().placeCreature(monster, position, extended, force)) {
monster->onSpawn();
monster->onSpawn(position);
const auto &mtype = monster->getMonsterType();
if (mtype && mtype->info.raceid > 0 && mtype->info.bosstiaryRace == BosstiaryRarity_t::RARITY_ARCHFOE) {
for (const auto &spectator : Spectators().find<Player>(monster->getPosition(), true)) {
Expand Down

0 comments on commit dbd8ab6

Please sign in to comment.