public CreatureGauges(CreatureGauges toCopy) { _hunger = new Gauge(); _hunger.UpdateMax(toCopy._hunger.MaxSize); _hunger.Rate = toCopy._hunger.Rate; _hunger.ModifPerSecond = toCopy._hunger.ModifPerSecond; _reproduction = new Gauge(); _reproduction.UpdateMax(toCopy._reproduction.MaxSize); _reproduction.Rate = toCopy._reproduction.Rate; _reproduction.ModifPerSecond = toCopy._reproduction.ModifPerSecond; _life = new Gauge(); _life.UpdateMax(toCopy._life.MaxSize); _life.Rate = toCopy._life.Rate; _life.ModifPerSecond = toCopy._life.ModifPerSecond; }
public void InitializeGauges(Creature toInitialize = null, bool initilizeRate = true, bool keepRate = true, bool test = false, CreatureTraits testTraits = null, CreatureGauges testGauges = null) { if (!test && toInitialize == null) { Debug.LogError("Warning ! No creature has been passed ! Aborting !"); return; } CreatureTraits traits = null; if (!test) { traits = toInitialize.Traits; } else { traits = testTraits; } if (traits == null) { Debug.LogError("Tests are null ! Aborting"); return; } if (test && testGauges == null) { Debug.LogError("Can't produce test without testGauges, Aborting !"); return; } Dictionary <CREATURE_GAUGES, Dictionary <GAUGE_VALUE, float> > values = new Dictionary <CREATURE_GAUGES, Dictionary <GAUGE_VALUE, float> >(); foreach (CREATURE_GAUGES TYPE_GAUGE in (CREATURE_GAUGES[])System.Enum.GetValues(typeof(CREATURE_GAUGES))) { values.Add(TYPE_GAUGE, new Dictionary <GAUGE_VALUE, float>()); foreach (GAUGE_VALUE VAL in (GAUGE_VALUE[])System.Enum.GetValues(typeof(GAUGE_VALUE))) { values[TYPE_GAUGE].Add(VAL, 0f); } } foreach (GaugeOperation op in modifiers) { if (op.valueChanges == GAUGE_VALUE.RATE && initilizeRate) { if (test) { values[op.influenced][GAUGE_VALUE.RATE] = Mathf.Lerp(op.minValue, op.maxValue, traits.Get(op.influence)); } else { values[op.influenced][GAUGE_VALUE.RATE] = UnityEngine.Random.Range(op.minValue, op.maxValue); } } else { values[op.influenced][op.valueChanges] += Mathf.Lerp(op.minValue, op.maxValue, traits.Get(op.influence)); } } foreach (KeyValuePair <CREATURE_GAUGES, Dictionary <GAUGE_VALUE, float> > value in values) { foreach (KeyValuePair <GAUGE_VALUE, float> f in value.Value) { switch (f.Key) { case GAUGE_VALUE.RATE: if (!initilizeRate) { break; } if (!test) { toInitialize.Gauges.Get(value.Key).Rate = f.Value; } else { testGauges.Get(value.Key).Rate = f.Value; } break; case GAUGE_VALUE.MAXVALUE: if (!test) { toInitialize.Gauges.Get(value.Key).UpdateMax((int)f.Value, keepRate); } else { testGauges.Get(value.Key).UpdateMax((int)f.Value, keepRate); } break; case GAUGE_VALUE.MODIFIER: if (!test) { toInitialize.Gauges.Get(value.Key).ModifPerSecond = f.Value; } else { testGauges.Get(value.Key).ModifPerSecond = f.Value; } break; default: Debug.LogError("This isn't supposed to happen. Please update this function"); break; } } } }
/*public void Reproduce(GameObject parent1, GameObject parent2) * { * Assert.IsNotNull(parent1); * Assert.IsNotNull(parent2); * GetCreature(parent1.transform.parent, (parent1.transform.position + parent2.transform.position) / 2f + new Vector3(0, 1f, 0), * Quaternion.Slerp(parent1.transform.rotation, parent2.transform.rotation, 0.5f), * spawnedCreatures[parent1].values.attackPower, spawnedCreatures[parent1].values.nutritionnal, * spawnedCreatures[parent1].values.maxLifeNumber, spawnedCreatures[parent1].values.SpecieID, * spawnedCreatures[parent1].values.Traits, null); * //ARDUINO ISLAND * parent1.GetComponent<Creature>(); * // * }*/ /*public Creature Reproduce(Creature parent1, Creature parent2) * { * Assert.IsNotNull(parent1); * Assert.IsNotNull(parent2); * * // TODO * // faudrais merge les listes d'alimentation des deux parent en vrai, là je prend juste le parent 1 pour implémenter le changement rapidement * IReadOnlyCollection<CarnivorousFood> carnivorousFoodsParent1 = parent1.agentCreature.Memory.Species.GetByKey(parent1.SpecieID).CarnivorousFoods; * IReadOnlyCollection<HerbivorFood> herbivorFoodsParent1 = parent1.agentCreature.Memory.Species.GetByKey(parent1.SpecieID).HerbivorFoods; * * List<int> carnivorousFoods = new List<int>(carnivorousFoodsParent1.Select(food => food.preyID)); * List<FoodType> herbivorFoods = new List<FoodType>(herbivorFoodsParent1.Select(food => food.foodType)); * * Creature creature = GetCreature((parent1.transform.position + parent2.transform.position) / 2f + new Vector3(0, 1f, 0), * Quaternion.Slerp(parent1.transform.rotation, parent2.transform.rotation, 0.5f), * parent1.SpecieID, * parent1.Traits, null, * carnivorousFoods, herbivorFoods); * * creature.agentCreature.Memory.MergeFrom(parent1.agentCreature, MemoryType.Species); * creature.agentCreature.Memory.MergeFrom(parent2.agentCreature, MemoryType.Species); * * return creature; * }*/ /*public GameObject[] AllSpawnedGameObjects * { * get * { * return spawnedCreatures.Keys.ToArray(); * } * }*/ /*public Creature[] AllSpawnedCreatures * { * get * { * Creature[] returned = new Creature[spawnedCreatures.Count]; * int i = -1; * foreach (CreatureReferences value in spawnedCreatures.Values) * { ++i; * returned[i] = value.values; * } * * return returned; * } * }*/ //private Dictionary<GameObject, CreatureReferences> spawnedCreatures; /*public Creature GetCreature(Transform newParent, Vector3 worldPosition, Quaternion rotation, int attackPower, int nutritionnal, int maxLifeNumber, int SpecieID, CreatureTraits newTrait, CreatureGauges newGauge) * { * CreatureReferences refCreat = new CreatureReferences(); * Creature newCreature = Instantiate(CreaturePrefab, worldPosition, rotation); * * if(newParent != null) * newCreature.transform.SetParent(newParent); * newCreature.transform.position = worldPosition; * newCreature.transform.rotation = rotation; * newCreature.nutritionnal = nutritionnal; * newCreature.attackPower = attackPower; * newCreature.maxLifeNumber = maxLifeNumber; * newCreature.SpecieID = SpecieID; * * if(newTrait != null) * newCreature.Traits = new CreatureTraits(newTrait); * if(newGauge != null) * newCreature.Gauges = new CreatureGauges(newGauge); * * newCreature.gameObject.SetActive(true); * * configGauges.InitializeGauges(newCreature, true, false, false); * * refCreat.go = newCreature.gameObject; * refCreat.values = newCreature; * refCreat.listenerEvent = (x) => updateGaugesOnTraitModified(x, refCreat.values); * refCreat.values.Traits.UpdatedTrait += refCreat.listenerEvent; * spawnedCreatures[newCreature] = refCreat; * refCreat.values.ColorSwap.Swap(CreatureTraits.GetColor(refCreat.values.Traits)); * //Metrics.NotifyCreatureCreated(refCreat.values); * return newCreature; * }*/ public Creature GetCreature(Vector3 worldPosition, Quaternion rotation, int SpecieID, CreatureTraits newTrait, CreatureGauges newGauge, List <int> carnivorousFoods, List <FoodType> herbivorFoods, List <ParticularityType> particularities, Color color) { Creature newCreature = Instantiate(CreaturePrefab, worldPosition, rotation); //newCreature.attackPower = attackPower; //newCreature.maxLifeNumber = maxLifeNumber; newCreature.SpecieID = SpecieID; if (newTrait != null) { newCreature.Traits = new CreatureTraits(newTrait); } if (newGauge != null) { newCreature.Gauges = new CreatureGauges(newGauge); } foreach (ParticularityType particularityType in particularities) { newCreature.DNADistortion.AddParticularity(ParticularitiesManager.Instance.CreateParticularity(newCreature, particularityType)); } newCreature.agentCreature.Init(); DataSpecies data = newCreature.agentCreature.Memory.Species.GetByKey(SpecieID); if (newTrait.Carnivorous > 0.5f) { foreach (int food in carnivorousFoods) { if (food == SpecieID) { continue; } data.addCarnivorousFood(new CarnivorousFood(food, Time.time)); } } else { foreach (FoodType food in herbivorFoods) { data.addHerbivorFood(new HerbivorFood(food, Time.time)); } } Nest nest = nests != null?nests.FirstOrDefault(n => n.SpecieID == SpecieID) : null; if (nest) { newCreature.agentCreature.Memory.Nests.Write(new DataNest(nest)); } newCreature.gameObject.SetActive(true); configGauges.InitializeGauges(newCreature, true, false, false); if (customColor) { newCreature.ColorSwap.Swap(color); } else { newCreature.ColorSwap.Swap(CreatureTraits.GetColor(newCreature.Traits)); } aliveCreatures.Add(newCreature); //ARDUINO ISLAND if (CreatureCountTable != null) { ++CreatureCountTable[newCreature.SpecieID]; } // Jirachi creaturePopulationChangedEvent?.Invoke(); // Lucas CreatureBirth?.Invoke(); newCreature.CreatureDoing.CreatureEatCreature += CreatureEatCreature; newCreature.CreatureDoing.CreatureEatFood += CreatureEatFood; /*Debug.Log("--------------CreatureList-------------"); * foreach (int specie in CreatureCountTable) * { * Debug.Log(specie); * } * Debug.Log("-----------");*/ // //Metrics.NotifyCreatureCreated(refCreat.values); return(newCreature); }