* Returns true when the creature is in a low-health (< 30 %) or * low-energy (< 25 %) state and should try to retreat. * Unit strategies may override this via `UnitBotStrategy.isRetreating`.
(creature: Creature)
| 1064 | * Unit strategies may override this via `UnitBotStrategy.isRetreating`. |
| 1065 | */ |
| 1066 | isRetreating(creature: Creature): boolean { |
| 1067 | const strategy = this.getStrategyFor(creature); |
| 1068 | if (strategy?.isRetreating) { |
| 1069 | const override = strategy.isRetreating(creature, this); |
| 1070 | if (override !== undefined) return override; |
| 1071 | } |
| 1072 | |
| 1073 | const engagementPressure = this.getTeamEngagementPressure(creature); |
| 1074 | const healthThreshold = Math.max(0.12, Math.min(0.5, 0.3 - engagementPressure * 0.04)); |
| 1075 | const energyThreshold = Math.max(0.1, Math.min(0.45, 0.25 - engagementPressure * 0.03)); |
| 1076 | const healthRatio = creature.health / creature.stats.health; |
| 1077 | const energyRatio = creature.energy / creature.stats.energy; |
| 1078 | return healthRatio < healthThreshold || energyRatio < energyThreshold; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * Scores a hex for a retreating creature. |
no test coverage detected