public static bool CheckExecutable(PlayerManager player, AbCellData target, AntSwarm swarm) { return(player.Anter.HasFreeAnts(swarm) && swarm.AntCount > 0 && player.Anter.CalculateFightPower(swarm) >= 3 && MapManager.Instance.GetPath(player.Nest, target).Count > 0); }
public static bool CheckExecutable(PlayerManager player, AbCellData data, AntSwarm ants) { return(player.Anter.HasFreeAnts(ants) && player.Anter.CalculateFightPower(ants) > 0 && !(data as EnviromentCellData).IsOccupied && (data as EnviromentCellData).IsBugged); }
public ReturnToNestPlan(PlayerManager player, AntSwarm swarm) { this.Player = player; this.PlanType = PlanTypes.Going; this.TargetCell = player.Nest; this.Ants = swarm; this.Delay = 1; }
//sends ants to the nest from the fields public void ComeHome(AntSwarm swarm) { if (AntsOnFields.Contains(swarm)) { AntsOnFields.Remove(swarm); AntIncome(swarm); } }
public ScoutPlan(PlayerManager player, AbCellData target, AntSwarm swarm) { this.Player = player; this.PlanType = PlanTypes.Scout; this.TargetCell = target; this.Ants = swarm; this.Delay = 1; this.Ants.Position = Player.Nest; }
public GatherPlan(PlayerManager player, AbCellData target, AntSwarm ants) { this.Player = player; this.PlanType = PlanTypes.Gather; this.Ants = ants; this.TargetCell = target; this.Delay = 1; this.Ants.Position = Player.Nest; }
//sends ants from nest to the field public void ToTheField(AntSwarm swarm) { if (HasFreeAnts(swarm)) { AntDecline(swarm); AntsOnFields.Add(swarm); OnCompositionChanged?.Invoke(); } }
public bool HasFreeAnts(AntSwarm swarm) { foreach (var type in swarm.Ants) { if (GetFreeAnts(type.Key) < type.Value) { return(false); } } return(true); }
public bool HasPlaceForAnts(AntSwarm swarm) { foreach (var type in swarm.Ants) { if (!HasPlaceForAnts(type.Key, type.Value)) { return(false); } } return(true); }
public static bool CheckExecutable(PlayerManager player, AntSwarm swarm) { if (swarm.Ants.Count > 1) { return(false); } bool isLarvaSpawn = swarm.Ants.ContainsKey(AntTypes.Larva); return(player.Resourcer.IsEnough(ResourceTypes.Meat, 10) && player.Anter.HasPlaceForAnts(swarm) && (isLarvaSpawn || player.Anter.HasFreeAnts(AntTypes.Larva, swarm.AntCount))); }
//removes ants from the nest to nowhere public void AntDecline(AntSwarm swarm) { foreach (var type in swarm.Ants) { if (AntsInNest.ContainsKey(type.Key)) { AntsInNest[type.Key] = Mathf.Max(AntsInNest[type.Key] - type.Value, 0); } } OnCompositionChanged?.Invoke(); }
//sends ants from nest to the field public void ToTheField(AntTypes type, int quantity) { if (HasFreeAnts(type, quantity)) { AntsInNest[type] -= quantity; var swarm = new AntSwarm(Owner, type, quantity); AntsOnFields.Add(swarm); OnCompositionChanged?.Invoke(); } }
public int CalculateScoutPower(AntSwarm swarm) { var result = 0; foreach (var item in swarm.Ants) { if (swarm.Ants.ContainsKey(item.Key)) { result += AntConfigs[item.Key].Gather * item.Value; } } return(result); }
public override bool Fight(AntSwarm swarm) { swarm.CalculateHP(); while (swarm.AntCount > 0 && this.isAlive) { this.GetHit(swarm.Owner.Anter.CalculateFightPower(swarm)); if (this.isAlive) { swarm.GetHit(this.Damage * currentCount); } } return(swarm.AntCount > 0); }
private void AntElementOnCountChangedHandler() { var swarm = new AntSwarm(); ForageActionAntsData data; foreach (var elem in antList.value) { data = elem as ForageActionAntsData; if (data.IsTypeChosen && data.Count > 0) { swarm.Add(data.ChosenType, data.Count); } } isSendCheckPassed.value = (sendCheck != null ? sendCheck(swarm) : true) && swarm.AntCount > 0; }
//adds swarm from nowhere to the nest public void AntIncome(AntSwarm swarm) { foreach (var type in swarm.Ants) { if (AntsInNest.ContainsKey(type.Key)) { AntsInNest[type.Key] += type.Value; } else { AntsInNest.Add(type.Key, type.Value); } } FixOvergrow(); OnCompositionChanged?.Invoke(); }
private void UpdatePath(bool isShow) { if (selectedSwarm == null) { return; } var plan = GameplayManager.Instance.Player.Planer.Plans.Find(x => x.Ants == selectedSwarm); if (plan == null) { return; } var path = MapManager.Instance.GetPath(plan.Ants.Position, plan.TargetCell); if (isShow) { if (path.Count > 0) { foreach (var pos in path) { MapManager.Instance.Field[pos].SetColor(new Color32(100, 100, 255, 255)); } } MapManager.Instance.Field[plan.TargetCell.FieldPosition].SetColor(new Color32(0, 0, 255, 255)); } else { if (path.Count > 0) { foreach (var pos in path) { MapManager.Instance.Field[pos].UpdateInfo(); } } MapManager.Instance.Field[plan.TargetCell.FieldPosition].UpdateInfo(); } if (!isShow) { selectedSwarm = null; } }
public void Send() { var swarm = new AntSwarm(GameplayManager.Instance.Player); ForageActionAntsData data; foreach (var elem in antList.value) { data = elem as ForageActionAntsData; if (data.IsTypeChosen && data.Count > 0) { swarm.Add(data.ChosenType, data.Count); } } if (swarm.AntCount > 0) { OnSend?.Invoke(swarm); } Close(); }
public void OnCellClick(AbCellData cellData) { if (cellData is NestCellData) { var data = cellData as NestCellData; //todo: get player? if (data == GameplayManager.Instance.Player.Nest) { MapManager.Instance.Hide(); WindowManagerUT.Instance.OpenNewPanel <NestPanel>(); } else { // enemy nest. attack options. } } else { var data = cellData as EnviromentCellData; if (data.IsAllyArmy) { if (selectedSwarm != data.Occupant) { UpdatePath(false); selectedSwarm = data.Occupant; UpdatePath(true); return; } } if (selectedSwarm != null) { var selectedPlan = GameplayManager.Instance.Player.Planer.Plans.Find(x => x.Ants == selectedSwarm); if (selectedPlan != null && selectedPlan.TargetCell == data) { UpdatePath(false); selectedPlan.Cancel(); return; } } UpdatePath(false); if (!data.isExplored) { //show gather popup var types = new List <AntTypes> { AntTypes.Worker, AntTypes.Gatherer, AntTypes.Builder, AntTypes.Warrior, AntTypes.Scout, AntTypes.Stopper, }; if (GameplayManager.Instance.Player.Planer.CheckCell(data)) { var actionPanel = WindowManagerUT.Instance.OpenNewPanel <ForageActionPanel>(WindowCloseModes.CloseNothing); System.Func <AntSwarm, bool> check = (s) => { return(ScoutPlan.CheckExecutable(GameplayManager.Instance.Player, cellData, s)); }; actionPanel.SetParameters(types, AntTypes.Worker, 3, check); actionPanel.OnSend = (swarm => { var plan = new ScoutPlan(GameplayManager.Instance.Player, data, swarm); GameplayManager.Instance.Player.Planer.TryToAddPlan(plan); }); } } else if (data.IsEmpty) { //show smth like "you can't do a shit here" message } else if (data.IsAllyArmy) { //show ally popup; } else if (data.IsEnemyArmy) { //show enemy popup; } else if (data.IsGatherable) { //show gather popup var types = new List <AntTypes> { AntTypes.Worker, AntTypes.Gatherer, AntTypes.Builder, AntTypes.Warrior, AntTypes.Scout, AntTypes.Stopper, }; if (GameplayManager.Instance.Player.Planer.CheckCell(data)) { var actionPanel = WindowManagerUT.Instance.OpenNewPanel <ForageActionPanel>(WindowCloseModes.CloseNothing); System.Func <AntSwarm, bool> check = (s) => { return(GatherPlan.CheckExecutable(GameplayManager.Instance.Player, s)); }; actionPanel.SetParameters(types, AntTypes.Worker, 10, check); actionPanel.OnSend = (swarm => { var plan = new GatherPlan(GameplayManager.Instance.Player, data, swarm); GameplayManager.Instance.Player.Planer.TryToAddPlan(plan); }); } } else if (data.IsBugged) { //show fight popup var types = new List <AntTypes> { AntTypes.Warrior, AntTypes.Scout, AntTypes.Stopper, }; if (GameplayManager.Instance.Player.Planer.CheckCell(data)) { var actionPanel = WindowManagerUT.Instance.OpenNewPanel <ForageActionPanel>(WindowCloseModes.CloseNothing); System.Func <AntSwarm, bool> check = (s) => { return(HuntPlan.CheckExecutable(GameplayManager.Instance.Player, data, s)); }; actionPanel.SetParameters(types, AntTypes.Warrior, 5, check); actionPanel.OnSend = (swarm => { var plan = new HuntPlan(GameplayManager.Instance.Player, data, swarm); GameplayManager.Instance.Player.Planer.TryToAddPlan(plan); }); } } } }
public static bool CheckExecutable(PlayerManager player, AntSwarm swarm) { return(player.Anter.HasFreeAnts(swarm) && player.Anter.CalculateGatherPower(swarm) > 0); }
public abstract bool Fight(AntSwarm swarm);
public static bool CheckExecutable(PlayerManager player, AntSwarm ants) { return(ants.AntCount > 0); }