static protected bool Fight(UnitAgent attacker, UnitAgent defender) { if (attacker.team == defender.team) { attacker.AddReward(-0.05f); return(false); } else if (attacker.attack >= defender.attack && attacker.attack > 0) { defender.SetReward(-.1f); defender.Dead(); defender.Done(); attacker.SetReward(1f); attacker.Done(); Debug.Log("Attacker Beat Defender"); return(true); } else { attacker.SetReward(-.1f); attacker.Dead(); attacker.Done(); Debug.Log("Defender Beat Attacker"); return(false); } }
public void Step() { foreach (GameObject unit in team) { UnitAgent agent = unit.GetComponent <UnitAgent>(); switch (agent.GetUnitType()) { case UnitAgent.Warrior: if (agent.IsDead() && resources > 100) { agent.Done(); resources -= 100; } break; case UnitAgent.Worker: if (agent.IsDead() && resources > 50) { agent.Done(); resources -= 50; } break; } } if (!academy.training) { if (team.Count < 6 && resources > 50) { GameObject newUnit = academy.BuildUnit(UnitAgent.Worker, teamNum); team.Add(newUnit); newUnit.GetComponent <UnitAgent>().castle = this; newUnit.GetComponent <UnitAgent>().ResetAgent(); resources -= 50; } else if (resources > 100) { GameObject newUnit = academy.BuildUnit(UnitAgent.Warrior, teamNum); team.Add(newUnit); newUnit.GetComponent <UnitAgent>().castle = this; newUnit.GetComponent <UnitAgent>().ResetAgent(); resources -= 100; } } }