Esempio n. 1
0
        private HealthModifiedInfo HandleModifyHealthRequest(HealthModifier modifier, ref HealthComponent.Component healthComp)
        {
            var newHealth = Mathf.Clamp(healthComp.Health + modifier.Amount, 0, healthComp.MaxHealth);
            var died      = newHealth <= 0;

            var healthModifiedInfo = new HealthModifiedInfo(
                modifier: modifier,
                healthBefore: healthComp.Health,
                healthAfter: newHealth,
                died: died);

            healthComp.Health = newHealth;

            return(healthModifiedInfo);
        }
Esempio n. 2
0
 public static void Serialize(HealthModifiedInfo instance, global::Improbable.Worker.CInterop.SchemaObject obj)
 {
     {
         global::Improbable.Gdk.Health.HealthModifier.Serialization.Serialize(instance.Modifier, obj.AddObject(1));
     }
     {
         obj.AddFloat(2, instance.HealthBefore);
     }
     {
         obj.AddFloat(3, instance.HealthAfter);
     }
     {
         obj.AddBool(4, instance.Died);
     }
 }
Esempio n. 3
0
            public static HealthModifiedInfo Deserialize(global::Improbable.Worker.CInterop.SchemaObject obj)
            {
                var instance = new HealthModifiedInfo();

                {
                    instance.Modifier = global::Improbable.Gdk.Health.HealthModifier.Serialization.Deserialize(obj.GetObject(1));
                }
                {
                    instance.HealthBefore = obj.GetFloat(2);
                }
                {
                    instance.HealthAfter = obj.GetFloat(3);
                }
                {
                    instance.Died = obj.GetBool(4);
                }
                return(instance);
            }
Esempio n. 4
0
        protected override void OnUpdate()
        {
            for (var i = 0; i < entitiesWithModifiedHealth.Length; i++)
            {
                var health = entitiesWithModifiedHealth.Health[i];
                var healthModifiedEventSender = entitiesWithModifiedHealth.HealthModifiedEventSenders[i];

                if (health.Health <= 0)
                {
                    continue;
                }

                foreach (var request in entitiesWithModifiedHealth.ModifyHealthRequests[i].Requests)
                {
                    var modifier = request.Payload;

                    var healthModifiedInfo = new HealthModifiedInfo
                    {
                        Modifier     = modifier,
                        HealthBefore = health.Health
                    };

                    health.Health = Mathf.Clamp(health.Health + modifier.Amount, 0, health.MaxHealth);
                    healthModifiedInfo.HealthAfter = health.Health;


                    if (health.Health <= 0)
                    {
                        healthModifiedInfo.Died = true;
                        healthModifiedEventSender.Events.Add(healthModifiedInfo);
                        break;
                    }

                    healthModifiedEventSender.Events.Add(healthModifiedInfo);
                }

                entitiesWithModifiedHealth.Health[i] = health;
            }
        }