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

fix: hazard spawn initialization #3184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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 @@ -501,9 +501,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 @@ -520,8 +520,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
Loading