Beispiel #1
0
        public void Run()
        {
            foreach (int i in _damagedPeds)
            {
                DamagedByWeaponComponent damagedComponent = _damagedPeds.Components1[i];
                EcsEntity weaponEntity = damagedComponent.WeaponEntity;
                EcsEntity pedEntity    = _damagedPeds.Entities[i];

                var woundRandomizer = _ecsWorld.GetComponent <WoundRandomizerComponent>(weaponEntity);
                if (woundRandomizer == null || woundRandomizer.WoundRandomizer.Count <= 0)
                {
                    _logger.MakeLog($"!!!WARNING!!! Weapon {weaponEntity.GetEntityName()} " +
                                    $"doesn't have {nameof(WoundRandomizerComponent)}");
                    _ecsWorld.RemoveComponent <DamagedByWeaponComponent>(pedEntity);
                    continue;
                }

                EcsEntity woundEntity = woundRandomizer.WoundRandomizer.NextWithReplacement();
                damagedComponent.MainWoundEntity = woundEntity;

                var wounded = _ecsWorld.EnsureComponent <WoundedComponent>(pedEntity, out _);
                wounded.WoundEntities.Add(woundEntity);

#if DEBUG
                _logger.MakeLog($"{pedEntity.GetEntityName()} have got wound {woundEntity.GetEntityName()}");
#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()
        {
            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
            }
        }