Exemple #1
0
        private void AdvanceTime(DateTime stop)
        {
            if (Animal == null)
            {
                return;
            }

            decimal timePassedMins = (decimal)((stop - Animal.LastCalculated).TotalMinutes);

            if (timePassedMins <= 0)
            {
                return;
            }

            AnimalType animalType = ActiveRuleset.AnimalTypes[Animal.TypeId];

            foreach (string attributeId in animalType.Attributes.Keys)
            {
                if (!Animal.Attributes.ContainsKey(attributeId))
                {
                    continue;
                }

                AnimalTypeAttribute animalTypeAttribute = animalType.Attributes[attributeId];
                decimal             minValue            = animalTypeAttribute.MinValue;
                decimal             maxValue            = animalTypeAttribute.MaxValue;
                decimal             ratioPerMin         = animalTypeAttribute.RatioPerMinute;
                decimal             changeOverTime      = timePassedMins * ratioPerMin;
                decimal             newValue            = Animal.Attributes[attributeId] + changeOverTime;
                newValue = Math.Max(minValue, Math.Min(maxValue, newValue));
                Animal.Attributes[attributeId] = newValue;
            }

            Animal.LastCalculated = stop;
        }
Exemple #2
0
        public override void Apply(AnimalActionEvent e, IAnimalEventContext context)
        {
            Animal       animal     = context.Animal;
            AnimalAction action     = context.ActiveRuleset.AnimalActions[e.AnimalActionId];
            AnimalType   animalType = context.ActiveRuleset.AnimalTypes[animal.TypeId];

            foreach (string attributeId in action.AttributeEffects.Keys)
            {
                AnimalTypeAttribute animalTypeAttribute = animalType.Attributes[attributeId];
                decimal             minValue            = animalTypeAttribute.MinValue;
                decimal             maxValue            = animalTypeAttribute.MaxValue;
                decimal             newValue            = animal.Attributes[attributeId] + action.AttributeEffects[attributeId];
                newValue = Math.Max(minValue, Math.Min(maxValue, newValue));
                animal.Attributes[attributeId] = newValue;
            }
        }