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: interaction with fields and removal of unused flag #865

Merged
merged 1 commit into from
Feb 17, 2023
Merged
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
37 changes: 6 additions & 31 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ void Monster::onCreatureAppear(Creature* creature, bool isLogin) {
}

if (creature == this) {
// We just spawned lets look around to see who is there.
if (isSummon()) {
isMasterInRange = canSee(getMaster()->getPosition());
}

updateTargetList();
updateIdleStatus();
} else {
Expand Down Expand Up @@ -222,10 +217,6 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi
}

if (creature == this) {
if (isSummon()) {
isMasterInRange = canSee(getMaster()->getPosition());
}

updateTargetList();
updateIdleStatus();
} else {
Expand All @@ -238,10 +229,6 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi
onCreatureLeave(creature);
}

if (canSeeNewPos && isSummon() && getMaster() == creature) {
isMasterInRange = true; // Follow master again
}

updateIdleStatus();

if (!isSummon()) {
Expand Down Expand Up @@ -409,11 +396,6 @@ void Monster::onCreatureFound(Creature* creature, bool pushFront /* = false*/) {
}

void Monster::onCreatureEnter(Creature* creature) {
if (getMaster() == creature) {
// Follow master again
isMasterInRange = true;
}

onCreatureFound(creature, true);
}

Expand Down Expand Up @@ -462,11 +444,6 @@ bool Monster::isOpponent(const Creature* creature) const {
}

void Monster::onCreatureLeave(Creature* creature) {
if (getMaster() == creature) {
// Take random steps and only use defense abilities (e.g. heal) until its master comes back
isMasterInRange = false;
}

// update friendList
if (isFriend(creature)) {
removeFriend(creature);
Expand Down Expand Up @@ -730,21 +707,18 @@ void Monster::updateIdleStatus() {
}

void Monster::onAddCondition(ConditionType_t type) {
onConditionStatusChange(type);
}

void Monster::onConditionStatusChange(const ConditionType_t &type) {
if (type == CONDITION_FIRE || type == CONDITION_ENERGY || type == CONDITION_POISON) {
ignoreFieldDamage = true;
updateMapCache();
}

updateIdleStatus();
}

void Monster::onEndCondition(ConditionType_t type) {
if (type == CONDITION_FIRE || type == CONDITION_ENERGY || type == CONDITION_POISON) {
ignoreFieldDamage = false;
updateMapCache();
}

updateIdleStatus();
onConditionStatusChange(type);
}

void Monster::onThink(uint32_t interval) {
Expand Down Expand Up @@ -1224,6 +1198,7 @@ void Monster::doFollowCreature(uint32_t &flags, Direction &nextDirection, bool &
flags |= FLAG_PATHFINDING;
} else {
if (ignoreFieldDamage) {
ignoreFieldDamage = false;
updateMapCache();
}
// target dancing
Expand Down
3 changes: 2 additions & 1 deletion src/creatures/monsters/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ class Monster final : public Creature {

bool isIdle = true;
bool extraMeleeAttack = false;
bool isMasterInRange = false;
bool randomStepping = false;
bool ignoreFieldDamage = false;

Expand Down Expand Up @@ -415,6 +414,8 @@ class Monster final : public Creature {

void doFollowCreature(uint32_t &flags, Direction &nextDirection, bool &result);
void doRandomStep(Direction &nextDirection, bool &result);

void onConditionStatusChange(const ConditionType_t &type);
};

#endif // SRC_CREATURES_MONSTERS_MONSTER_H_