| 478 | let plan = target.getMetadata(PlayerID, "plan"); |
| 479 | |
| 480 | if (gameState.getGameType() == "regicide" && target.hasClass("Hero") && |
| 481 | target.healthLevel() < 0.5 && target.hasClass("Infantry") || target.healthLevel() < 0.3 && target.hasClass("Cavalry") || |
| 482 | target.healthLevel() < 0.95 && !target.attackTypes() || target.healthLevel() < 0.7 && target.hasClass("Elephant") && |
| 483 | plan !== -2 && plan !== -3) |
| 484 | { |
| 485 | if (plan >= 0) |
| 486 | { |
| 487 | let attackPlan = gameState.ai.HQ.attackManager.getPlan(target.getMetadata(PlayerID, "plan")); |
| 488 | if (attackPlan) |
| 489 | attackPlan.removeUnit(target, true); |
| 490 | } |
| 491 | if (target.getMetadata(PlayerID, "PartOfArmy")) |
| 492 | { |
| 493 | let army = gameState.ai.HQ.defenseManager.getArmy(target.getMetadata(PlayerID, "PartOfArmy")); |
| 494 | if (army) |
| 495 | army.removeOwn(gameState, target.id()); |
| 496 | } |
| 497 | |
| 498 | this.garrisonUnitForHealing(gameState, target); |
| 499 | |
| 500 | if (plan >= 0) // couldn't find a place to garrison, so the hero will flee from attacks |
| 501 | { |
| 502 | target.setStance("passive"); |
| 503 | let accessIndex = gameState.ai.accessibility.getAccessValue(target.position()); |
| 504 | let basePos = m.getBestBase(gameState, target); |
| 505 | if (basePos && basePos.accessIndex == accessIndex) |
| 506 | target.move(basePos.anchor.position()[0], basePos.anchor.position()[1]); |
| 507 | } |
| 508 | continue; |
| 509 | } |
| 510 | |