Example #1
0
        public void Run()
        {
            if (_bleedingStats.EntitiesCount <= 0)
            {
                throw new Exception("BleedingSystem was not init!");
            }

            BleedingStatsComponent stats = _bleedingStats.Components1[0];

            foreach (int i in _woundedPeds)
            {
                BleedingInfoComponent info    = _woundedPeds.Components1[i];
                WoundedComponent      wounded = _woundedPeds.Components2[i];
                int pedEntity = _woundedPeds.Entities[i];

                foreach (int woundEntity in wounded.WoundEntities)
                {
                    var baseBleeding = _ecsWorld.GetComponent <BaseBleedingComponent>(woundEntity);
                    if (baseBleeding == null)
                    {
                        continue;
                    }

                    float baseSeverity = baseBleeding.BaseBleeding;
                    if (baseSeverity <= 0)
                    {
                        continue;
                    }

                    int   bodyPartEntity = _woundedPeds.Components3[i].DamagedBodyPartEntity;
                    float bodyPartMult   = _ecsWorld.GetComponent <BleedingMultComponent>(bodyPartEntity).Multiplier;
                    float sevWithMult    = stats.BleedingMultiplier * bodyPartMult * baseSeverity;

                    float sevDeviation = sevWithMult * stats.BleedingDeviation;
                    sevDeviation = Random.NextFloat(-sevDeviation, sevDeviation);

                    float finalSeverity = sevWithMult + sevDeviation;

                    int bleedingEntity = _ecsWorld.CreateEntityWith(out BleedingComponent bleeding);
                    bleeding.Severity = finalSeverity;
#if DEBUG
                    _logger.MakeLog(
                        $"Created bleeding {woundEntity.GetEntityName(_ecsWorld)} for Entity ({pedEntity}). " +
                        $"Base severity {baseSeverity:0.00}; final severity {finalSeverity:0.00}");
#endif
                    info.BleedingEntities.Add(bleedingEntity);
                }

#if DEBUG
                _ecsWorld.ProcessDelayedUpdates();
                string bleedingList = "";
                foreach (int bleedEntity in info.BleedingEntities)
                {
                    bleedingList += $"{_ecsWorld.GetComponent<BleedingComponent>(bleedEntity).Severity:0.00} ";
                }

                _logger.MakeLog($"BleedingList: {bleedingList}");
#endif
            }
        }
Example #2
0
        public void Run()
        {
            PreExecuteActions();

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

                EcsEntity pedEntity = NewPeds.Entities[i];
                ResetEffect(ped, pedEntity);
            }

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

                EcsEntity pedEntity = HealedPeds.Entities[i];
                ResetEffect(ped, pedEntity);
            }

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

                EcsEntity        pedEntity = WoundedPeds.Entities[pedIndex];
                WoundedComponent wounded   = WoundedPeds.Components2[pedIndex];

                foreach (EcsEntity woundEntity in wounded.WoundEntities)
                {
                    ProcessWound(ped, pedEntity, woundEntity);
                }
            }

            PostExecuteActions();
        }
Example #3
0
        public void Run()
        {
#if DEBUG
            foreach (int i in _woundedPeds)
            {
                WoundedComponent wounded = _woundedPeds.Components1[i];
                int woundedEntity        = _woundedPeds.Entities[i];

                string woundList = "Wounds: ";
                foreach (int woundEntity in wounded.WoundEntities)
                {
                    woundList += $"{woundEntity.GetEntityName(_ecsWorld)}, ";
                }

                _logger.MakeLog($"Entity {woundedEntity} {woundList}");
            }
#endif
        }
        public void Run()
        {
            foreach (int i in _healedPeds)
            {
                _healedPeds.Components2[i].Reset();
            }

            foreach (int i in _woundedPeds)
            {
                DamagedByWeaponComponent damagedByWeapon = _woundedPeds.Components1[i];
                WoundedComponent         wounded         = _woundedPeds.Components3[i];
                CritListComponent        critList        = _woundedPeds.Components4[i];

                EcsEntity bodyPartEntity = _woundedPeds.Components2[i].DamagedBodyPartEntity;
                var       bodyPartCrits  = _ecsWorld.GetComponent <WoundRandomizerComponent>(bodyPartEntity);
                if (bodyPartCrits == null)
                {
#if DEBUG
                    _logger.MakeLog($"BodyPart {bodyPartEntity.GetEntityName()} doesn't have crits");
#endif
                    continue;
                }

                EcsEntity weaponEntity          = damagedByWeapon.WeaponEntity;
                var       weaponChanceComponent = _ecsWorld.GetComponent <CritChanceComponent>(weaponEntity);
                float     weaponChance          = weaponChanceComponent?.CritChance ?? 0f;

                EcsEntity woundEntity          = damagedByWeapon.MainWoundEntity;
                var       woundChanceComponent = _ecsWorld.GetComponent <CritChanceComponent>(woundEntity);
                float     woundChance          = woundChanceComponent?.CritChance ?? 0f;

                var   bodyPartChanceComponent = _ecsWorld.GetComponent <CritChanceComponent>(bodyPartEntity);
                float bodyPartChance          = bodyPartChanceComponent?.CritChance ?? 0f;

                if (weaponChance <= 0 || woundChance <= 0 || bodyPartChance <= 0)
                {
#if DEBUG
                    _logger.MakeLog("One of CritChances below 0! " +
                                    $"(WP {weaponChance:0.00}/" +
                                    $"WO {woundChance:0.00}/" +
                                    $"BP {bodyPartChance:0.00})");
#endif
                    continue;
                }

                float finalChance = weaponChance * woundChance * bodyPartChance;
                bool  critSuccess = bodyPartChance > 1f || _random.IsTrueWithProbability(finalChance);
#if DEBUG
                EcsEntity pedEntity = _woundedPeds.Entities[i];
                _logger.MakeLog(
                    $"{pedEntity.GetEntityName()} crit check is {critSuccess}, when chance was {finalChance:0.000}" +
                    $"(WP {weaponChance:0.00}/" +
                    $"WO {woundChance:0.00}/" +
                    $"BP {bodyPartChance:0.00})");
#endif
                if (!critSuccess)
                {
                    continue;
                }

                EcsEntity critEntity = bodyPartCrits.WoundRandomizer.NextWithReplacement();
                wounded.WoundEntities.Add(critEntity);
                critList.CritList.Add(critEntity);
#if DEBUG
                _logger.MakeLog($"{pedEntity.GetEntityName()} have got crit {critEntity.GetEntityName()}");
#endif
            }
        }
        public void Run()
        {
            HealthStatsComponent stats = _healthStats.Components1[0];

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

                HealthComponent health = _fullyHealedPeds.Components2[i];
                health.Health = health.MaxHealth;
                ped.SetHealth(health.Health);
            }

            foreach (int i in _woundedPeds)
            {
#if DEBUG
                EcsEntity pedEntity = _woundedPeds.Entities[i];
                _logger.MakeLog($"{pedEntity.GetEntityName()} was wounded");
#endif
                Ped ped = _woundedPeds.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                HealthComponent  health  = _woundedPeds.Components2[i];
                WoundedComponent wounded = _woundedPeds.Components3[i];

                float baseDamage = 0;
                foreach (EcsEntity woundEntity in wounded.WoundEntities)
                {
                    var damage = _ecsWorld.GetComponent <BaseDamageComponent>(woundEntity);
                    if (damage == null)
                    {
                        continue;
                    }

                    baseDamage += damage.BaseDamage;
#if DEBUG
                    _logger.MakeLog($"{woundEntity.GetEntityName()} increase damage for {damage.BaseDamage:0.00}");
#endif
                }

                if (baseDamage <= 0)
                {
                    continue;
                }
                EcsEntity bodyPartEntity     = _woundedPeds.Components4[i].DamagedBodyPartEntity;
                float     bodyPartDamageMult = _ecsWorld.GetComponent <DamageMultComponent>(bodyPartEntity).Multiplier;
                float     damageWithMult     = stats.DamageMultiplier * bodyPartDamageMult * baseDamage;

                float damageDeviation = damageWithMult * stats.DamageDeviation;
                damageDeviation = _random.NextFloat(-damageDeviation, damageDeviation);

                float finalDamage = damageWithMult + damageDeviation;
                health.Health -= finalDamage;
                ped.SetHealth(health.Health);
#if DEBUG
                _logger.MakeLog($"{pedEntity.GetEntityName()}:" +
                                $"Base damage is {baseDamage:0.00}; " +
                                $"Final damage is {finalDamage:0.00}; " +
                                $"New health is {health.Health:0.00}/{health.MaxHealth:0.00}");
#endif
            }

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

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

                Vector3 position = ped.AbovePosition + 0.1f * Vector3.WorldUp;
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(1.05f, 0.15f, 0.1f), Color.Gold);
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(health.Health / health.MaxHealth, 0.1f, 0.1f), Color.Green);
            }
#endif
        }
Example #6
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
        }
        public void Run()
        {
            BleedingStatsComponent stats = _bleedingStats.Components1[0];

            foreach (int i in _wounded)
            {
                PedBleedingInfoComponent info            = _wounded.Components1[i];
                WoundedComponent         wounded         = _wounded.Components2[i];
                DamagedBodyPartComponent damagedBodyPart = _wounded.Components3[i];
                DamagedByWeaponComponent damagedByWeapon = _wounded.Components4[i];

                EcsEntity pedEntity = _wounded.Entities[i];
                foreach (EcsEntity woundEntity in wounded.WoundEntities)
                {
                    var baseBleeding = _ecsWorld.GetComponent <BaseBleedingComponent>(woundEntity);
                    if (baseBleeding == null)
                    {
                        continue;
                    }

                    float baseSeverity = baseBleeding.BaseBleeding;
                    if (baseSeverity <= 0)
                    {
                        continue;
                    }

                    EcsEntity bodyPartEntity = damagedBodyPart.DamagedBodyPartEntity;
                    float     bodyPartMult   = _ecsWorld.GetComponent <BleedingMultiplierComponent>(bodyPartEntity).Multiplier;
                    float     sevWithMult    = stats.BleedingMultiplier * bodyPartMult * baseSeverity;

                    float sevDeviation = sevWithMult * stats.BleedingDeviation;
                    sevDeviation = _random.NextFloat(-sevDeviation, sevDeviation);

                    float finalSeverity = sevWithMult + sevDeviation;

                    EcsEntity bleedingEntity = _ecsWorld.CreateEntityWith(out BleedingComponent bleeding);
                    bleeding.DamagedBoneId     = damagedBodyPart.DamagedBoneId;
                    bleeding.BodyPartEntity    = damagedBodyPart.DamagedBodyPartEntity;
                    bleeding.Severity          = finalSeverity;
                    bleeding.MotherWoundEntity = woundEntity;
                    bleeding.WeaponEntity      = damagedByWeapon.WeaponEntity;

#if DEBUG
                    _logger.MakeLog(
                        $"Created bleeding {woundEntity.GetEntityName()} on bone {bleeding.DamagedBoneId} for {pedEntity.GetEntityName()}. " +
                        $"Base severity {baseSeverity:0.00}; final severity {finalSeverity:0.00}");
#endif
                    info.BleedingEntities.Add(bleedingEntity);
                }

#if DEBUG
                _ecsWorld.ProcessDelayedUpdates();
                string bleedingList = "";
                foreach (EcsEntity bleedEntity in info.BleedingEntities)
                {
                    bleedingList += $"{_ecsWorld.GetComponent<BleedingComponent>(bleedEntity).Severity:0.00} ";
                }

                _logger.MakeLog($"BleedingList for {pedEntity.GetEntityName()}: {bleedingList}");
#endif
            }
        }