public void Die() { Ants.Clear(); AntCount = 0; RecalcSpeed(); OnCompositionChanged?.Invoke(this); }
public void SetComposition(Models.Domain.Composition composition, bool isFresh = false) { var args = new CompositionChangedArgs { NewComposition = composition, IsFresh = isFresh }; OnCompositionChanged?.Invoke(this, args); }
//sends ants from nest to the field public void ToTheField(AntSwarm swarm) { if (HasFreeAnts(swarm)) { AntDecline(swarm); AntsOnFields.Add(swarm); 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(); } }
//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(); }
//adds ants from nowhere to the nest public void AntIncome(AntTypes type, int quantity) { if (AntsInNest.ContainsKey(type)) { AntsInNest[type] += quantity; } else { AntsInNest.Add(type, quantity); } FixOvergrow(); OnCompositionChanged?.Invoke(); }
public void Add(AntTypes type, int quantity) { if (Ants.ContainsKey(type)) { Ants[type] += quantity; } else { Ants.Add(type, quantity); } AntCount += quantity; RecalcSpeed(); OnCompositionChanged?.Invoke(this); }
public void GetHit(int damage) { HP = Mathf.Max(0, HP - damage); if (HP == 0) { Ants.Clear(); AntCount = 0; } else { var configs = new List <AntConfig>(); foreach (var item in Ants) { if (item.Value > 0) { configs.Add(Owner.Anter.AntConfigs[item.Key]); } } var temp = Ants; Ants = new Dictionary <AntTypes, int>(); AntCount = 0; configs.SortByDescending(x => x.HP); var currHp = 0; var quantity = 0; for (int i = 0; i < configs.Count; i++) { quantity = Mathf.Min((HP - currHp) / configs[i].HP, temp[configs[i].Type]); currHp += configs[i].HP * quantity; Ants.Add(configs[i].Type, quantity); AntCount += quantity; } for (int i = configs.Count - 1; i >= 0; i--) { if (Ants[configs[i].Type] < temp[configs[i].Type]) { Ants[configs[i].Type] += 1; AntCount += 1; } } } RecalcSpeed(); OnCompositionChanged?.Invoke(this); }
//removes ants from the nest to nowhere public void AntDecline(AntTypes type, int quantity) { if (AntsInNest.ContainsKey(type)) { AntsInNest[type] -= quantity; if (AntsInNest[type] < 0) { AntsInNest[type] = 0; } OnCompositionChanged?.Invoke(); } }
public void Remove(AntTypes type, int quantity) { if (Ants.ContainsKey(type)) { Ants[type] = Mathf.Max(Ants[type] - quantity, 0); AntCount = 0; foreach (var amount in Ants.Values) { AntCount += amount; } RecalcSpeed(); OnCompositionChanged?.Invoke(this); } }
//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(); }
public void Update() { FixOvergrow(); OnCompositionChanged?.Invoke(); }