Skip to content

Commit 4df262e

Browse files
committed
Make fleeing last at least the imp revaluation time
1 parent e106880 commit 4df262e

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/toniarts/openkeeper/game/controller/creature/CreatureController.java

+22-13
Original file line numberDiff line numberDiff line change
@@ -1136,29 +1136,38 @@ public void imprison(short playerId) {
11361136
@Override
11371137
public boolean isStateTimeExceeded() {
11381138
double timeSpent = gameTimer.getGameTime() - entityData.getComponent(entityId, CreatureAi.class).stateStartTime;
1139+
double stateTargetTime;
11391140

11401141
switch (stateMachine.getCurrentState()) {
1141-
case STUNNED: {
1142+
case STUNNED -> {
11421143
// Hmm, this might actually be the level variable, the stun seems to be the time fallen when dropped
1143-
return timeSpent >= entityData.getComponent(entityId, CreatureComponent.class).stunDuration;
1144+
stateTargetTime = entityData.getComponent(entityId, CreatureComponent.class).stunDuration;
11441145
}
1145-
case FALLEN: {
1146-
return timeSpent >= entityData.getComponent(entityId, CreatureComponent.class).stunDuration;
1146+
case FALLEN -> {
1147+
stateTargetTime = entityData.getComponent(entityId, CreatureComponent.class).stunDuration;
11471148
}
1148-
case GETTING_UP: {
1149-
return timeSpent >= getAnimationTime(creature, Creature.AnimationType.GET_UP);
1149+
case GETTING_UP -> {
1150+
stateTargetTime = getAnimationTime(creature, Creature.AnimationType.GET_UP);
11501151
}
1151-
case ENTERING_DUNGEON: {
1152-
return timeSpent >= getAnimationTime(creature, Creature.AnimationType.ENTRANCE);
1152+
case ENTERING_DUNGEON -> {
1153+
stateTargetTime = getAnimationTime(creature, Creature.AnimationType.ENTRANCE);
11531154
}
1154-
case MELEE_ATTACK: {
1155-
return timeSpent >= getAnimationTime(creature, Creature.AnimationType.MELEE_ATTACK);
1155+
case MELEE_ATTACK -> {
1156+
stateTargetTime = getAnimationTime(creature, Creature.AnimationType.MELEE_ATTACK);
11561157
}
1157-
case EATING: {
1158-
return timeSpent >= getAnimationTime(creature, Creature.AnimationType.EATING);
1158+
case EATING -> {
1159+
stateTargetTime = getAnimationTime(creature, Creature.AnimationType.EATING);
1160+
}
1161+
case FLEE -> {
1162+
// I couldn't find a variable for this, so lets use this for now
1163+
stateTargetTime = gameSettings.get(Variable.MiscVariable.MiscType.IMP_IDLE_DELAY_BEFORE_REEVALUATION_SECONDS).getValue();
1164+
}
1165+
default -> {
1166+
stateTargetTime = Double.MAX_VALUE;
11591167
}
11601168
}
1161-
return false;
1169+
1170+
return stateTargetTime < timeSpent;
11621171
}
11631172

11641173
private static double getAnimationTime(Creature creature, Creature.AnimationType animation) {

src/toniarts/openkeeper/game/controller/creature/CreatureState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public void enter(ICreatureController entity) {
367367

368368
@Override
369369
public void update(ICreatureController entity) {
370-
if (!entity.shouldFleeOrAttack()) {
370+
if (entity.isStateTimeExceeded() && !entity.shouldFleeOrAttack()) {
371371
entity.getStateMachine().changeState(IDLE);
372372
}
373373
}

0 commit comments

Comments
 (0)