void GoToMyNearestCity(EnemyAgent owner) { TargetableObject building = null; TargetableObject dockedIn = owner.GetDockedIn(); if (dockedIn) { if (dockedIn.GetComponent <City>()) { building = dockedIn; dockedIn.GetArmy().MoveAllUnitsToOtherArmy(owner.GetArmy()); // dockedIn.GetArmy().MoveUnitToOtherArmy(0, owner.GetArmy()); //GoToMyPosition(owner); } else { building = owner.MyCountry.GetNearestUndockedCity(owner); owner.MoveToTargetObject(owner); } } else { building = owner.MyCountry.GetNearestUndockedCity(owner); if (building) { owner.MoveToTargetObject(building); } else { GoToMyPosition(owner); } } }
public static void QuickBattle(TargetableObject attacker, TargetableObject defender) { Debug.Log("Starting quick battle by " + attacker.name, attacker.gameObject); BattleInfo bInfo = new BattleInfo(); bInfo.Setup(attacker, defender); thisFrameBattles.Add(bInfo); battleInfo.Setup(attacker, defender); battleResult.isStarted = true; ///////////// BATTLE END ///////////// bool attackerWin = false; float attackerStrength = attacker.GetArmy().GetArmyStrength(); float defenderStrength = defender.GetArmy().GetArmyStrength(); float result = (Mathf.Max(attackerStrength, defenderStrength) - Mathf.Min(defenderStrength, attackerStrength)) / Mathf.Max(attackerStrength, defenderStrength); if (defenderStrength <= 0f || attackerStrength <= 0f) { result = 1f; } Debug.Log("Battle result for Astrength " + attackerStrength + " and Dstrength " + defenderStrength + " result: " + result); if (attacker.GetArmy().IsThisArmyStrongerThan(defender.GetArmy())) { attackerWin = true; defender.GetArmy().RemoveAllUnits(); attacker.GetArmy().ChangeUnitsAmountByPercentage(result); } else { attackerWin = false; attacker.GetArmy().RemoveAllUnits(); defender.GetArmy().ChangeUnitsAmountByPercentage(result); } BattleManager.RemoveAllUnitInstancesThatShouldBeDestroyed(); battleResult = new BattleResult(attackerWin, false, true); EndBattleImmediate(); FinishBattle(); }
void MoveOneRandomUnitFromAttackerArmy(TargetableObject attacker) { Army attackerArmy = attacker.GetArmy(); int armyUnitsCount = attackerArmy.GetUnits().Count; if (attackerArmy.GetUnits().Count > 0) { int randomUnitFromAttackerArmy = Random.Range(0, armyUnitsCount); attackerArmy.MoveUnitToOtherArmy(randomUnitFromAttackerArmy, GetArmy(), 1); } }
private void SpawnPlayerArmy() { TargetableObject player = BattleManager.GetPlayer(); if (player != null) { int rowIndex = 0; //Spawn on other side if blayer is defending FitRowIndex(ref rowIndex, 0, true); foreach (UnitInstance unit in player.GetArmy().GetUnits()) { Card card = SpawnUnitInRow(unit, rowIndex, player.MyCountry); playerCards.AddCard(card); } } }
private void SpawnAIArmy() { TargetableObject ai = BattleManager.GetAI(); if (ai != null) { int rowIndex = 0; //Spawn on other side if player is defending FitRowIndex(ref rowIndex, 0, false); foreach (UnitInstance unit in ai.GetArmy().GetUnits()) { Card card = SpawnUnitInRow(unit, rowIndex, ai.MyCountry); BattleAI.instance.AddCard(card); } } }
void RefreshUI() { armyUI.Refresh(snapTarget.GetArmy()); }