Ticket #4142: petra_regicide_support_v1.patch

File petra_regicide_support_v1.patch, 1.3 KB (added by Sandarac, 8 years ago)

Petra will attempt to garrison the hero for healing if the hero's health drops lower than 60%, including cases when the hero is part of an army (hasn't been extensively tested).

  • binaries/data/mods/public/simulation/ai/petra/defenseManager.js

     
    475475        if (target.hasClass("Ship"))    // TODO integrate ships later   need to be sure it is accessible
    476476            continue;
    477477
     478        let plan = target.getMetadata(PlayerID, "plan");
     479
     480        if (gameState.getGameType() == "regicide" && target.hasClass("Hero") &&
     481            target.healthLevel() < 0.6 && plan !== -2 && plan !== -3)
     482        {
     483            if (plan >= 0)
     484            {
     485                let attackPlan = gameState.ai.HQ.attackManager.getPlan(target.getMetadata(PlayerID, "plan"));
     486                if (attackPlan)
     487                    attackPlan.removeUnit(target, true);
     488            }
     489            if (target.getMetadata(PlayerID, "PartOfArmy"))
     490            {
     491                let army = gameState.ai.HQ.defenseManager.getArmy(target.getMetadata(PlayerID, "PartOfArmy"));
     492                if (army)
     493                    army.removeOwn(gameState, target.id());
     494            }
     495
     496            this.garrisonUnitForHealing(gameState, target);
     497            continue;
     498        }
     499
    478500        // If inside a started attack plan, let the plan deal with this unit
    479         let plan = target.getMetadata(PlayerID, "plan");
    480501        if (plan !== undefined && plan >= 0)
    481502        {
    482503            let attack = gameState.ai.HQ.attackManager.getPlan(plan);