Beispiel #1
0
        public void Run()
        {
            if (_notifications.IsEmpty() || _gameService.GameIsPaused)
            {
                return;
            }

            float delta = GswExtensions.GetDeltaTime();
            NotificationSettingsComponent settings = _settings.Components1[0];

            if (settings.CombineToOne)
            {
                string finalMessage = "";
                foreach (int i in _notifications)
                {
                    NotificationComponent notification = _notifications.Components1[i];
                    notification.Delay -= delta;
                    if (notification.Delay <= 0)
                    {
                        finalMessage += notification.Message + "~n~";
                        _ecsWorld.RemoveComponent <NotificationComponent>(_notifications.Entities[i]);
                    }
                }

                if (!string.IsNullOrEmpty(finalMessage))
                {
                    Game.DisplayNotification(finalMessage);
                }
            }
            else
            {
                foreach (int i in _notifications)
                {
                    NotificationComponent notification = _notifications.Components1[i];
                    notification.Delay -= delta;
                    if (notification.Delay <= 0)
                    {
                        if (!string.IsNullOrEmpty(notification.Message))
                        {
                            Game.DisplayNotification(notification.Message);
                        }
                        _ecsWorld.RemoveComponent <NotificationComponent>(_notifications.Entities[i]);
                    }
                }
            }
        }
        public void Run()
        {
            if (_gameService.GameIsPaused)
            {
                return;
            }

            float dt   = GswExtensions.GetDeltaTime();
            float rate = _healthStats.Components1[0].SelfHealingRate;

            if (dt <= 0 || rate <= 0)
            {
                return;
            }

            foreach (int i in _pedsWithHealth)
            {
                Ped ped = _pedsWithHealth.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                PedBleedingInfoComponent info = _pedsWithHealth.Components3[i];
                if (info.BleedingEntities.Count > 0)
                {
                    continue;
                }

                HealthComponent health = _pedsWithHealth.Components2[i];
                if (health.MaxHealth - health.Health < 5f)
                {
                    continue;
                }

                health.Health += rate * dt;
                ped.SetHealth(health.Health);
            }
        }
Beispiel #3
0
        public void Run()
        {
            foreach (int i in _entities)
            {
                Ped ped = _entities.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                HealthComponent health = _entities.Components2[i];
                if (health.Health <= 0)
                {
                    continue;
                }

                BleedingInfoComponent info = _entities.Components3[i];
                int   pedEntity            = _entities.Entities[i];
                float bleedingDamage       = 0;

                for (int bleedingIndex = info.BleedingEntities.Count - 1; bleedingIndex >= 0; bleedingIndex--)
                {
                    int bleedingEntity = info.BleedingEntities[bleedingIndex];
                    if (!_ecsWorld.IsEntityExists(bleedingEntity))
                    {
                        info.BleedingEntities.RemoveAt(bleedingIndex);
                        continue;
                    }

                    var bleeding = _ecsWorld.GetComponent <BleedingComponent>(bleedingEntity);
                    if (bleeding == null)
                    {
                        info.BleedingEntities.RemoveAt(bleedingIndex);
                        continue;
                    }

                    float delta = GswExtensions.GetDeltaTime();
                    if (delta <= 0)
                    {
                        continue;
                    }

                    bleedingDamage    += bleeding.Severity * delta;
                    bleeding.Severity -= info.BleedingHealRate / HEAL_RATE_SLOWER * delta;
                    if (bleeding.Severity > 0)
                    {
                        continue;
                    }

#if DEBUG
                    _logger.MakeLog($"Bleeding {bleedingEntity} on Entity ({pedEntity}) was healed");
#endif
                    _ecsWorld.RemoveComponent <BleedingComponent>(bleedingEntity);
                    info.BleedingEntities.RemoveAt(bleedingIndex);
                }

                if (bleedingDamage <= 0)
                {
                    continue;
                }

                health.Health -= bleedingDamage;
                ped.SetHealth(health.Health);
            }
        }
Beispiel #4
0
        public void Run()
        {
            if (_gameService.GameIsPaused)
            {
                return;
            }

            BleedingStatsComponent bleedingStats = _bleedingStats.Components1[0];

            foreach (int i in _entities)
            {
                Ped ped = _entities.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                HealthComponent health = _entities.Components2[i];
                if (health.Health <= 0)
                {
                    continue;
                }

                PedBleedingInfoComponent info = _entities.Components3[i];
                EcsEntity pedEntity           = _entities.Entities[i];
                float     bleedingDamage      = 0;

                for (int bleedingIndex = info.BleedingEntities.Count - 1; bleedingIndex >= 0; bleedingIndex--)
                {
                    EcsEntity bleedingEntity = info.BleedingEntities[bleedingIndex];
                    if (!_ecsWorld.IsEntityExists(bleedingEntity))
                    {
                        info.BleedingEntities.RemoveAt(bleedingIndex);
                        continue;
                    }

                    var bleeding = _ecsWorld.GetComponent <BleedingComponent>(bleedingEntity);
                    if (bleeding == null)
                    {
                        info.BleedingEntities.RemoveAt(bleedingIndex);
                        continue;
                    }

                    float delta = GswExtensions.GetDeltaTime();
                    if (delta <= 0)
                    {
                        continue;
                    }

                    bleedingDamage    += bleedingStats.BleedingDamageMultiplier * bleeding.Severity * delta;
                    bleeding.Severity -= info.BleedingHealRate * delta;
                    if (bleeding.Severity > 0)
                    {
                        continue;
                    }

#if DEBUG
                    _logger.MakeLog($"Bleeding {bleedingEntity} on {pedEntity.GetEntityName()} was healed");
#endif
                    _ecsWorld.RemoveComponent <BleedingComponent>(bleedingEntity);
                    info.BleedingEntities.RemoveAt(bleedingIndex);
                }

                if (bleedingDamage <= 0)
                {
                    continue;
                }
                health.Health -= bleedingDamage;
                ped.SetHealth(health.Health);
            }
        }
Beispiel #5
0
        public void Run()
        {
            foreach (int i in _entitiesToClean)
            {
                EcsEntity entity = _entitiesToClean.Entities[i];
                _ecsWorld.RemoveComponent <PainIsGoneComponent>(entity);
            }

            PainStatsComponent stats = _painStats.Components1[0];

            foreach (int i in _woundedPeds)
            {
                WoundedComponent wounded = _woundedPeds.Components1[i];
                EcsEntity        entity  = _woundedPeds.Entities[i];

                float basePain = 0;
                foreach (EcsEntity woundEntity in wounded.WoundEntities)
                {
                    var pain = _ecsWorld.GetComponent <BasePainComponent>(woundEntity);
                    if (pain == null)
                    {
                        continue;
                    }

                    basePain += pain.BasePain;
#if DEBUG
                    _logger.MakeLog($"{woundEntity.GetEntityName()} increased pain for {pain.BasePain:0.00}");
#endif
                }

                var additionalPain = _ecsWorld.GetComponent <AdditionalPainComponent>(entity);
                if (additionalPain != null)
                {
                    basePain += additionalPain.AdditionalPain;
                }

                if (basePain <= 0)
                {
                    continue;
                }
                EcsEntity bodyPartEntity   = _woundedPeds.Components3[i].DamagedBodyPartEntity;
                float     bodyPartPainMult = _ecsWorld.GetComponent <PainMultComponent>(bodyPartEntity).Multiplier;
                float     painWithMult     = stats.PainMultiplier * bodyPartPainMult * basePain;

                float painDeviation = painWithMult * stats.PainDeviation;
                painDeviation = _random.NextFloat(-painDeviation, painDeviation);
                float finalPain = painWithMult + painDeviation;

                var painComponent = _ecsWorld.EnsureComponent <PainComponent>(entity, out bool isNew);
                if (isNew)
                {
                    painComponent.PainAmount = finalPain;
                }
                else
                {
                    painComponent.PainAmount += finalPain;
                }
#if DEBUG
                float     maxPain     = _woundedPeds.Components2[i].UnbearablePain;
                EcsEntity pedEntity   = _woundedPeds.Entities[i];
                float     painPercent = painComponent.PainAmount / maxPain * 100f;
                _logger.MakeLog($"{pedEntity.GetEntityName()}: " +
                                $"Base pain is {basePain:0.00}; " +
                                $"Final pain is {finalPain:0.00}; " +
                                $"Pain percent is {painPercent:0.00}");
#endif
            }

            foreach (int i in _healedEntities)
            {
                EcsEntity entity = _healedEntities.Entities[i];
                _ecsWorld.AddComponent <PainIsGoneComponent>(entity);
                _ecsWorld.RemoveComponent <PainComponent>(entity);
            }

            if (_gameService.GameIsPaused)
            {
                return;
            }

            float delta = GswExtensions.GetDeltaTime();
            foreach (int i in _painToReduce)
            {
                PainComponent painComponent     = _painToReduce.Components1[i];
                float         painRecoverySpeed = _painToReduce.Components2[i].PainRecoverySpeed;
                EcsEntity     entity            = _painToReduce.Entities[i];

                painComponent.PainAmount -= painRecoverySpeed * delta;
                if (painComponent.PainAmount > 0)
                {
                    continue;
                }

                _ecsWorld.AddComponent <PainIsGoneComponent>(entity);
                _ecsWorld.RemoveComponent <PainComponent>(entity);
            }

#if DEBUG
            foreach (int i in _pedsWithPain)
            {
                Ped   ped     = _pedsWithPain.Components1[i].ThisPed;
                float pain    = _pedsWithPain.Components2[i].PainAmount;
                float maxPain = _pedsWithPain.Components3[i].UnbearablePain;
                if (!ped.Exists() || pain <= 0)
                {
                    continue;
                }

                Vector3 position = ped.AbovePosition + 0.2f * Vector3.WorldUp;
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(1.05f, 0.15f, 0.1f), Color.Orange);
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(pain / maxPain, 0.1f, 0.1f), Color.Red);
            }
#endif
        }