private void DetectWeaponHash(Ped ped, EcsEntity pedEntity)
        {
            foreach (int i in _weapons)
            {
                HashesComponent hashesComponent = _weapons.Components1[i];
                foreach (uint hash in hashesComponent.Hashes)
                {
                    if (!NativeFunction.Natives.HAS_PED_BEEN_DAMAGED_BY_WEAPON <bool>(ped, hash, 0))
                    {
                        continue;
                    }

                    EcsEntity weaponEntity = _weapons.Entities[i];
#if DEBUG
                    _logger.MakeLog($"{pedEntity.GetEntityName()} was damaged by {weaponEntity.GetEntityName()}({hash})");
#endif

                    var damaged = _ecsWorld.AddComponent <DamagedByWeaponComponent>(pedEntity);
                    damaged.WeaponEntity = weaponEntity;
                    return;
                }
            }

            _logger.MakeLog($"!!!WARNING!!! Ped {pedEntity.GetEntityName()} was damaged by UNKNOWN weapon");
        }
Beispiel #2
0
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement ragdoll = partRoot.Element("EnableRagdoll");

            if (ragdoll != null)
            {
                var component = EcsWorld.AddComponent <EnableRagdollComponent>(partEntity);
                component.LengthInMs        = ragdoll.GetInt("LengthInMs");
                component.Type              = ragdoll.GetInt("Type");
                component.Permanent         = ragdoll.GetBool("Permanent");
                component.DisableOnlyOnHeal = ragdoll.GetBool("DisableOnlyOnHeal");

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} have got {component}");
#endif
            }

            XElement disable = partRoot.Element("DisablePermanentRagdoll");
            if (disable != null)
            {
                EcsWorld.AddComponent <DisablePermanentRagdollComponent>(partEntity);

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} will disable permanent ragdoll");
#endif
            }
        }
Beispiel #3
0
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement enable = partRoot.Element("EnableFacialAnimation");

            if (enable != null)
            {
                var component = EcsWorld.AddComponent <EnableFacialAnimationComponent>(partEntity);
                component.MaleDict   = enable.GetAttributeValue("MaleDict");
                component.FemaleDict = enable.GetAttributeValue("FemaleDict");
                component.Permanent  = enable.GetBool("Permanent");

                foreach (string animation in enable.GetAttributeValue("Animations").Split(';'))
                {
                    if (!string.IsNullOrEmpty(animation))
                    {
                        component.Animations.Add(animation);
                    }
                }

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} have got {component}");
#endif
            }

            XElement disable = partRoot.Element("DisableFacialAnimation");
            if (disable != null)
            {
                EcsWorld.AddComponent <DisableFacialAnimationComponent>(partEntity);

#if DEBUG
                Logger.MakeLog($"{partEntity.GetEntityName()} will disable facial animation");
#endif
            }
        }
Beispiel #4
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            var permanent = EcsWorld.GetComponent <PermanentRagdollComponent>(pedEntity);
            var enable    = EcsWorld.GetComponent <EnableRagdollComponent>(woundEntity);

            if (permanent == null && enable != null)
            {
                if (enable.Permanent)
                {
                    var create = EcsWorld.EnsureComponent <CreatePermanentRagdollComponent>(pedEntity, out _);
                    create.DisableOnlyOnHeal = enable.DisableOnlyOnHeal;
                    create.Type = enable.Type;
                }
                else
                {
                    int length = enable.LengthInMs;
                    NativeFunction
                    .Natives
                    .SET_PED_TO_RAGDOLL(ped, length, length, enable.Type, 0, 0, 0);
#if DEBUG
                    Logger.MakeLog($"{pedEntity.GetEntityName()} got ragdoll for {length} ms");
#endif
                }
            }

            var disable = EcsWorld.GetComponent <DisablePermanentRagdollComponent>(woundEntity);
            if (permanent != null && !permanent.DisableOnlyOnHeal && disable != null)
            {
                NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, 1, 1, 1, 0, 0, 0);
                EcsWorld.RemoveComponent <PermanentRagdollComponent>(pedEntity);
#if DEBUG
                Logger.MakeLog($"{pedEntity.GetEntityName()} was restored from permanent ragdoll");
#endif
            }
        }
Beispiel #5
0
        public void Run()
        {
            foreach (int i in _damagedPeds)
            {
                Ped ped = _damagedPeds.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                EcsEntity pedEntity = _damagedPeds.Entities[i];
                if (!ped.IsWearingHelmet)
                {
#if DEBUG
                    _logger.MakeLog($"{pedEntity.GetEntityName()} doesn't have helmet");
#endif
                    continue;
                }

                EcsEntity bodyPartEntity = _damagedPeds.Components2[i].DamagedBodyPartEntity;
                var       bodyArmor      = _ecsWorld.GetComponent <BodyPartArmorComponent>(bodyPartEntity);
                if (bodyArmor == null || !bodyArmor.ProtectedByHelmet)
                {
#if DEBUG
                    string partName = bodyPartEntity.GetEntityName();
                    _logger.MakeLog($"Helmet of {pedEntity.GetEntityName()} doesn't protect {partName}");
#endif
                    continue;
                }

                EcsEntity weaponEntity = _damagedPeds.Components3[i].WeaponEntity;
                var       weaponStats  = _ecsWorld.GetComponent <ArmorWeaponStatsComponent>(weaponEntity);
                if (weaponStats == null)
                {
#if DEBUG
                    _logger.MakeLog($"Weapon {weaponEntity.GetEntityName()} doesn't have {nameof(ArmorWeaponStatsComponent)}");
#endif
                    continue;
                }

                float chance           = weaponStats.ChanceToPenetrateHelmet;
                bool  helmetPenetrated = _random.IsTrueWithProbability(chance);
                if (!helmetPenetrated)
                {
#if DEBUG
                    _logger.MakeLog($"Helmet of {pedEntity.GetEntityName()} was not penetrated, " +
                                    $"when chance was {chance:0.00}");
#endif
                    _ecsWorld.RemoveComponent <DamagedByWeaponComponent>(pedEntity);
                    _ecsWorld.RemoveComponent <DamagedBodyPartComponent>(pedEntity);
                    continue;
                }

#if DEBUG
                _logger.MakeLog($"Helmet of {pedEntity.GetEntityName()} was penetrated, when chance was {chance:0.00}");
#endif
            }
        }
Beispiel #6
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            var permanentDisabled = EcsWorld.GetComponent <PermanentDisabledSprintComponent>(pedEntity);
            var player            = EcsWorld.GetComponent <PlayerMarkComponent>(pedEntity);

            if (permanentDisabled == null && player != null)
            {
                var disable = EcsWorld.GetComponent <DisableSprintComponent>(woundEntity);
                if (disable != null)
                {
                    NativeFunction.Natives.SET_PLAYER_SPRINT(Game.LocalPlayer, false);
                    if (disable.RestoreOnlyOnHeal)
                    {
                        EcsWorld.AddComponent <PermanentDisabledSprintComponent>(pedEntity);
                    }
#if DEBUG
                    Logger.MakeLog($"Sprint disabled for player, permanent = {disable.RestoreOnlyOnHeal}");
#endif
                }

                var enable = EcsWorld.GetComponent <EnableSprintComponent>(woundEntity);
                if (enable != null)
                {
                    NativeFunction.Natives.SET_PLAYER_SPRINT(Game.LocalPlayer, true);
#if DEBUG
                    Logger.MakeLog("Sprint enabled for player");
#endif
                }
            }

            var permanentRate = EcsWorld.GetComponent <PermanentDisabledSprintComponent>(pedEntity);
            if (permanentRate == null)
            {
                var newRate = EcsWorld.GetComponent <NewMovementRateComponent>(woundEntity);
                if (newRate != null)
                {
                    NativeFunction.Natives.SET_PED_MOVE_RATE_OVERRIDE(ped, newRate.Rate);
                    if (newRate.RestoreOnlyOnHeal)
                    {
                        EcsWorld.AddComponent <PermanentDisabledSprintComponent>(pedEntity);
                    }
#if DEBUG
                    Logger.MakeLog($"Move rate for {pedEntity.GetEntityName()} " +
                                   $"was changed to {newRate.Rate}, permanent = {newRate.RestoreOnlyOnHeal}");
#endif
                }

                var restore = EcsWorld.GetComponent <RestoreMovementComponent>(woundEntity);
                if (restore != null)
                {
                    NativeFunction.Natives.SET_PED_MOVE_RATE_OVERRIDE(ped, 1.0f);
#if DEBUG
                    Logger.MakeLog($"Move rate for {pedEntity.GetEntityName()} was restored");
#endif
                }
            }
        }
Beispiel #7
0
        private static void Command_GetBleedingListForAllWoundedPeds()
        {
            EcsWorld world  = GunshotWound3.EcsWorld;
            var      filter = world.GetFilter <EcsFilter <GswPedComponent, PedBleedingInfoComponent> >();

            if (filter.IsEmpty())
            {
                Game.Console.Print("There are no peds with bleedings!");
                return;
            }

            Game.Console.Print("Wounded Ped List:");
            foreach (int i in filter)
            {
                PedBleedingInfoComponent info = filter.Components2[i];
                if (info.BleedingEntities.Count > 0)
                {
                    EcsEntity pedEntity = filter.Entities[i];
                    Game.Console.Print($"Ped {pedEntity.GetEntityName()} has bleedings:");
                    foreach (EcsEntity bleedingEntity in info.BleedingEntities)
                    {
                        PrintInfoAboutBleeding(world, bleedingEntity, info);
                    }
                }
            }
        }
Beispiel #8
0
        public void Initialize()
        {
            var dict = _ecsWorld.AddComponent <UidToEntityDictComponent>(GunshotWound3.StatsContainerEntity);

            foreach (int i in _items)
            {
                XElement itemRoot   = _items.Components1[i].ElementRoot;
                XElement uidElement = itemRoot.Element("Uid");
                if (uidElement == null)
                {
                    continue;
                }

                EcsEntity entity = _items.Entities[i];
                string    uid    = uidElement.GetAttributeValue("Value");
                if (dict.UidToEntityDict.ContainsKey(uid))
                {
                    _logger.MakeLog($"!!!WARNING!!! Uid {uid} already exists! {itemRoot.Name} skipped!");
                    return;
                }

                _ecsWorld.AddComponent <UidComponent>(entity).Uid = uid;
                dict.UidToEntityDict.Add(uid, entity);

#if DEBUG
                _logger.MakeLog($"{entity.GetEntityName()} added to UidDict as {uid}");
#endif
            }
        }
Beispiel #9
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            NaturalMotionMessagesDictComponent dict = _dict.Components1[0];

            var nmMessages = EcsWorld.GetComponent <NaturalMotionMessagesComponent>(woundEntity);

            if (nmMessages == null || nmMessages.MessageList.Count <= 0)
            {
                return;
            }

            var permanentRagdoll = EcsWorld.GetComponent <PermanentRagdollComponent>(pedEntity);

            if (permanentRagdoll != null && !nmMessages.PlayInPermanentRagdoll)
            {
                return;
            }
            if (permanentRagdoll != null && !permanentRagdoll.DisableOnlyOnHeal)
            {
                NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, 0, 0, 1, 0, 0, 0);
            }

            foreach (string messageName in nmMessages.MessageList)
            {
                NaturalMotionMessage nmMessage = dict.MessageDict[messageName];
                PlayNaturalMotionMessage(nmMessage, ped, _random);
            }
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} have got NM-message {nmMessages}");
#endif
        }
Beispiel #10
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()
        {
            if (_gameService.GameIsPaused)
            {
                return;
            }

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

                bool damaged = NativeFunction.Natives.HAS_ENTITY_BEEN_DAMAGED_BY_ANY_PED <bool>(ped);
                if (!damaged)
                {
                    continue;
                }

                EcsEntity pedEntity = _peds.Entities[i];
                _ecsWorld.AddComponent <HasBeenHitMarkComponent>(pedEntity);
#if DEBUG
                _logger.MakeLog($"{pedEntity.GetEntityName()} has been damaged");
#endif
            }
        }
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement listElement = partRoot.Element("NaturalMotionMessages");

            if (listElement == null)
            {
                return;
            }

            Dictionary <string, NaturalMotionMessage> dict = _dict.Components1[0].MessageDict;
            var messages = EcsWorld.AddComponent <NaturalMotionMessagesComponent>(partEntity);

            string[] messageStrings = listElement.GetAttributeValue("List").Split(';');
            foreach (string messageString in messageStrings)
            {
                if (string.IsNullOrEmpty(messageString))
                {
                    continue;
                }

                if (!dict.ContainsKey(messageString))
                {
                    throw new Exception($"NaturalMotionMessage {messageString} doesn't exist!");
                }

                messages.MessageList.Add(messageString);
            }

            messages.PlayInPermanentRagdoll = listElement.GetBool("PlayInPermanentRagdoll");
#if DEBUG
            Logger.MakeLog($"{partEntity.GetEntityName()} have got {messages}");
#endif
        }
Beispiel #13
0
        private void MarkEntityAsPed(EcsEntity entity)
        {
            _ecsWorld.AddComponent <PlayerMarkComponent>(entity);
            NativeFunction.Natives.SET_PLAYER_HEALTH_RECHARGE_MULTIPLIER(Game.LocalPlayer, 0f);
            NativeFunction.Natives.SET_PLAYER_MELEE_WEAPON_DAMAGE_MODIFIER(Game.LocalPlayer, 0.01f);
#if DEBUG
            _logger.MakeLog($"Ped {entity.GetEntityName()} was marked as player");
#endif
        }
        public void Run()
        {
            if (_woundedPlayer.IsEmpty())
            {
                return;
            }

            EcsEntity weaponEntity = _woundedPlayer.Components1[0].WeaponEntity;
            DamagedBodyPartComponent damagedBodyPart = _woundedPlayer.Components2[0];
            List <EcsEntity>         woundList       = _woundedPlayer.Components3[0].WoundEntities;

            int woundCount = 1;

            foreach (EcsEntity woundEntity in woundList)
            {
                var wounded = _ecsWorld.GetComponent <WoundComponent>(woundEntity);
                if (wounded == null)
                {
                    continue;
                }

                string boneName = damagedBodyPart.DamagedBoneId.ToString();
                if (Enum.TryParse(boneName, out PedBoneId boneId))
                {
                    boneName = boneId.ToString();
                }

                _ecsWorld.CreateEntityWith(out NotificationComponent notification);
                if (woundCount++ <= 1)
                {
                    notification.Message = $"~s~Wound:~n~ ~o~{woundEntity.GetEntityName()} " +
                                           $"~s~on {damagedBodyPart.DamagedBodyPartEntity.GetEntityName()}" +
                                           $"~c~({boneName})~s~ " +
                                           $"by ~y~{weaponEntity.GetEntityName()}";
                }
                else
                {
                    notification.Message = $"~s~Crit:~n~ ~r~{woundEntity.GetEntityName()} " +
                                           $"~s~on {damagedBodyPart.DamagedBodyPartEntity.GetEntityName()}" +
                                           $"~c~({boneName})~s~ " +
                                           $"by ~y~{weaponEntity.GetEntityName()}";
                }
            }
        }
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            var enable = EcsWorld.GetComponent <EnableFacialAnimationComponent>(woundEntity);

            if (enable != null)
            {
                string animationName = _random.NextFromList(enable.Animations);
                string dict          = ped.IsMale
                    ? enable.MaleDict
                    : enable.FemaleDict;

                if (enable.Permanent)
                {
                    var permanent = EcsWorld.EnsureComponent <PermanentFacialAnimationComponent>(pedEntity, out _);
                    permanent.Name = animationName;
                    permanent.Dict = dict;
#if DEBUG
                    Logger.MakeLog($"{pedEntity.GetEntityName()} got permanent facial animation {animationName}");
#endif
                }
                else
                {
                    NativeFunction.Natives.PLAY_FACIAL_ANIM(ped, animationName, dict);
#if DEBUG
                    Logger.MakeLog($"{pedEntity.GetEntityName()} got short facial animation {animationName}");
#endif
                }
            }

            var disable = EcsWorld.GetComponent <DisableFacialAnimationComponent>(woundEntity);
            if (disable != null)
            {
                EcsWorld.RemoveComponent <PermanentFacialAnimationComponent>(pedEntity, true);
#if DEBUG
                Logger.MakeLog($"{pedEntity.GetEntityName()} clean facial animation");
#endif
            }
        }
Beispiel #16
0
        protected override void ResetEffect(Ped ped, EcsEntity pedEntity)
        {
            if (!ped.IsRagdoll)
            {
                return;
            }

            NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, 1, 1, 1, 0, 0, 0);
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} was restored from ragdoll");
#endif

            var permanent = EcsWorld.GetComponent <PermanentRagdollComponent>(pedEntity);
            if (permanent == null)
            {
                return;
            }

            EcsWorld.RemoveComponent <PermanentRagdollComponent>(pedEntity);
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} was restored from permanent ragdoll");
#endif
        }
Beispiel #17
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            WeaponDropStatsComponent stats = _stats.Components1[0];
            bool isPlayer  = EcsWorld.GetComponent <PlayerMarkComponent>(pedEntity) != null;
            var  component = EcsWorld.GetComponent <WeaponDropComponent>(woundEntity);

            if (component == null || ped.CurrentVehicle.Exists() || ped.Inventory.EquippedWeapon == null ||
                isPlayer && !stats.PlayerCanDropWeapon)
            {
                return;
            }

            ped.Inventory.EquippedWeapon.Drop();
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} drop weapon");
#endif
            if (!ped.CombatTarget.Exists())
            {
                return;
            }

            if (component.FleeIfHasNoWeapons && ped.Inventory.Weapons.Count <= 0)
            {
                ped.Tasks.ReactAndFlee(ped.CombatTarget);
#if DEBUG
                Logger.MakeLog($"{pedEntity.GetEntityName()} has no weapons and try to flee");
#endif
            }
            else if (component.TakeCoverDuration > 0)
            {
                ped.Tasks.TakeCoverFrom(ped.CombatTarget, component.TakeCoverDuration);
#if DEBUG
                Logger.MakeLog($"{pedEntity.GetEntityName()} try to take cover");
#endif
            }
        }
Beispiel #18
0
        public void Run()
        {
            GswWorldComponent gswWorld = _world.Components1[0];

            foreach (int i in _pedsToRemove)
            {
                Ped       ped       = _pedsToRemove.Components1[i].ThisPed;
                EcsEntity pedEntity = _pedsToRemove.Entities[i];

                gswWorld.PedsToEntityDict.Remove(ped);
                _ecsWorld.RemoveEntity(pedEntity);

#if DEBUG
                _logger.MakeLog($"{pedEntity.GetEntityName()} was removed");
#endif
            }
        }
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            var ikComponent = EcsWorld.GetComponent <InstantKillComponent>(woundEntity);
            var health      = EcsWorld.GetComponent <HealthComponent>(pedEntity);

            if (ikComponent == null || health == null)
            {
                return;
            }

            int newHealth = (int)health.MinHealth - 2;

            ped.SetHealth(newHealth);
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} was killed due {ikComponent.ReasonKey}!");
#endif
        }
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            XElement element = partRoot.Element("InstantKill");

            if (element == null)
            {
                return;
            }

            EcsWorld
            .AddComponent <InstantKillComponent>(partEntity)
            .ReasonKey = element.GetAttributeValue("ReasonKey");

#if DEBUG
            Logger.MakeLog($"{partEntity.GetEntityName()} will instant kill");
#endif
        }
        private void ApplyClipset(Ped ped, string clipset, EcsEntity pedEntity)
        {
            if (string.IsNullOrEmpty(clipset))
            {
                return;
            }

            if (!NativeFunction.Natives.HAS_ANIM_SET_LOADED <bool>(clipset))
            {
                NativeFunction.Natives.REQUEST_ANIM_SET(clipset);
            }

            NativeFunction.Natives.SET_PED_MOVEMENT_CLIPSET(ped, clipset, 1.0f);
#if DEBUG
            Logger.MakeLog($"{pedEntity.GetEntityName()} changed movement clipset to {clipset}");
#endif
        }
Beispiel #22
0
        protected override void ProcessWound(Ped ped, EcsEntity pedEntity, EcsEntity woundEntity)
        {
            bool isPlayer   = EcsWorld.GetComponent <PlayerMarkComponent>(pedEntity) != null;
            var  changeFlag = EcsWorld.GetComponent <ChangePedFlagComponent>(woundEntity);

            if (changeFlag == null || !changeFlag.ForPlayer && isPlayer)
            {
                return;
            }

            var changedFlags = EcsWorld.EnsureComponent <ChangedPedFlagsComponent>(pedEntity, out _);

            NativeFunction.Natives.SET_PED_CONFIG_FLAG(ped, changeFlag.Id, changeFlag.Value);
            changedFlags.ChangedFlags.Add(changeFlag.Id);
#if DEBUG
            Logger.MakeLog($"Changed Flag {changeFlag.Id} to {changeFlag.Value} for {pedEntity.GetEntityName()}");
#endif
        }
        protected override void CheckPart(XElement partRoot, EcsEntity partEntity)
        {
            var clipset = partRoot.Element("MovementClipset");

            if (clipset == null)
            {
                return;
            }

            var component = EcsWorld.AddComponent <NewMovementClipsetComponent>(partEntity);

            component.Player    = clipset.GetAttributeValue("Player");
            component.PedMale   = clipset.GetAttributeValue("PedMale");
            component.PedFemale = clipset.GetAttributeValue("PedFemale");

#if DEBUG
            Logger.MakeLog($"{partEntity.GetEntityName()} have got {component}");
#endif
        }
Beispiel #24
0
        protected override void PreExecuteActions()
        {
            foreach (int i in _needRagdollPeds)
            {
                Ped       ped       = _needRagdollPeds.Components1[i].ThisPed;
                EcsEntity pedEntity = _needRagdollPeds.Entities[i];
                if (!ped.Exists() || EcsWorld.GetComponent <PermanentRagdollComponent>(pedEntity) != null)
                {
                    EcsWorld.RemoveComponent <CreatePermanentRagdollComponent>(pedEntity);
                    continue;
                }

                if (ped.IsRagdoll)
                {
                    continue;
                }

                CreatePermanentRagdollComponent createRagdoll = _needRagdollPeds.Components2[i];
                NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, -1, -1, createRagdoll.Type, 0, 0, 0);

                var permanentRagdoll = EcsWorld.EnsureComponent <PermanentRagdollComponent>(pedEntity, out _);
                permanentRagdoll.DisableOnlyOnHeal = createRagdoll.DisableOnlyOnHeal;
                permanentRagdoll.Type = createRagdoll.Type;

                EcsWorld.RemoveComponent <CreatePermanentRagdollComponent>(pedEntity);
#if DEBUG
                Logger.MakeLog($"{pedEntity.GetEntityName()} have got permanent ragdoll");
#endif
            }

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

                PermanentRagdollComponent ragdoll = _permanentRagdollPeds.Components2[i];
                NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, -1, -1, ragdoll.Type, 0, 0, 0);
            }
        }
Beispiel #25
0
        public void Run()
        {
            foreach (int i in _damagedPeds)
            {
                Ped ped = _damagedPeds.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                EcsEntity pedEntity      = _damagedPeds.Entities[i];
                PedBoneId lastBone       = ped.LastDamageBone;
                EcsEntity bodyPartEntity = GetDamagedBodyPart(ped);

#if DEBUG
                string partName = bodyPartEntity.GetEntityName();
                _logger.MakeLog($"{pedEntity.GetEntityName()} has damaged {partName} with boneId {(uint) lastBone}");

                var          history = _ecsWorld.EnsureComponent <DamagedBoneHistoryComponent>(pedEntity, out bool isNew);
                PedBoneId?[] bones   = history.LastDamagedBones;
                if (isNew)
                {
                    bones[0] = lastBone;
                    bones[1] = null;
                    bones[2] = null;
                }
                else
                {
                    bones[2] = bones[1];
                    bones[1] = bones[0];
                    bones[0] = lastBone;
                }
#endif

                var damagedBodyPart = _ecsWorld.AddComponent <DamagedBodyPartComponent>(pedEntity);
                damagedBodyPart.DamagedBodyPartEntity = bodyPartEntity;
                damagedBodyPart.DamagedBoneId         = (uint)lastBone;
                ped.ClearLastDamageBone();
            }
        }
Beispiel #26
0
        protected override void ResetEffect(Ped ped, EcsEntity pedEntity)
        {
            var permanentRate = EcsWorld.GetComponent <PermanentMovementRateComponent>(pedEntity);

            if (permanentRate != null)
            {
                NativeFunction.Natives.SET_PED_MOVE_RATE_OVERRIDE(ped, 1.0f);
                EcsWorld.RemoveComponent <PermanentMovementRateComponent>(pedEntity);
#if DEBUG
                Logger.MakeLog($"Permanent move rate for {pedEntity.GetEntityName()} was reset");
#endif
            }

            var player = EcsWorld.GetComponent <PlayerMarkComponent>(pedEntity);
            if (player == null)
            {
                return;
            }

            NativeFunction.Natives.SET_PLAYER_SPRINT(Game.LocalPlayer, true);
            EcsWorld.RemoveComponent <PermanentDisabledSprintComponent>(pedEntity, true);
        }
Beispiel #27
0
        public void Initialize()
        {
            foreach (int i in _configParts)
            {
                XElement root          = _configParts.Components1[i].ElementRoot;
                XElement hashesElement = root.Element(HASHES);
                if (hashesElement == null)
                {
                    continue;
                }

                EcsEntity entity          = _configParts.Entities[i];
                var       hashesComponent = _ecsWorld.AddComponent <HashesComponent>(entity);

                string[] hashStrings = hashesElement.GetAttributeValue("Hashes").Split(';');
                foreach (string hashString in hashStrings)
                {
                    if (string.IsNullOrEmpty(hashString))
                    {
                        continue;
                    }

                    if (uint.TryParse(hashString, out uint hash))
                    {
                        hashesComponent.Hashes.Add(hash);
                    }
                    else
                    {
                        _logger.MakeLog($"!!!WARNING!!! Wrong hash: {hashString}");
                    }
                }

#if DEBUG
                _logger.MakeLog($"{entity.GetEntityName()} have got {hashesComponent}");
#endif
            }
        }
        public void Run()
        {
            foreach (int i in _pedsToCheck)
            {
                Ped ped = _pedsToCheck.Components1[i].ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                HealthComponent health     = _pedsToCheck.Components2[i];
                float           realHealth = ped.GetHealth();
                if (realHealth <= health.MaxHealth)
                {
                    continue;
                }

                EcsEntity entity = _pedsToCheck.Entities[i];
                _ecsWorld.AddComponent <FullyHealedComponent>(entity);
#if DEBUG
                _logger.MakeLog($"{entity.GetEntityName()} was fully healed!");
#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
            }
        }
Beispiel #30
0
        public void Run()
        {
            foreach (int i in _pedsWithArmor)
            {
                GswPedComponent   gswPed = _pedsWithArmor.Components1[i];
                PedArmorComponent armor  = _pedsWithArmor.Components2[i];

                Ped ped = gswPed.ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                if (ped.Armor > armor.Armor)
                {
                    armor.Armor = ped.Armor;
                }
#if DEBUG
                if (armor.Armor <= 0)
                {
                    continue;
                }

                Vector3 position = ped.AbovePosition;
                float   maxArmor = ped.IsLocalPlayer
                    ? NativeFunction.Natives.GET_PLAYER_MAX_ARMOUR <int>(Game.LocalPlayer)
                    : 100;
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(1.05f, 0.15f, 0.1f), Color.LightSkyBlue);
                Debug.DrawWireBoxDebug(position, ped.Orientation, new Vector3(armor.Armor / maxArmor, 0.1f, 0.1f), Color.MediumBlue);
#endif
            }

            foreach (int i in _damagedPedsWithArmor)
            {
                GswPedComponent   gswPed = _damagedPedsWithArmor.Components1[i];
                PedArmorComponent armor  = _damagedPedsWithArmor.Components4[i];
                Ped ped = gswPed.ThisPed;
                if (!ped.Exists())
                {
                    continue;
                }

                EcsEntity pedEntity = _damagedPedsWithArmor.Entities[i];
                if (armor.Armor <= 0)
                {
#if DEBUG
                    _logger.MakeLog($"{pedEntity.GetEntityName()} doesn't have armor");
#endif
                    ped.Armor = armor.Armor;
                    continue;
                }

                EcsEntity bodyPartEntity = _damagedPedsWithArmor.Components2[i].DamagedBodyPartEntity;
                var       bodyArmor      = _ecsWorld.GetComponent <BodyPartArmorComponent>(bodyPartEntity);
                if (bodyArmor == null || !bodyArmor.ProtectedByBodyArmor)
                {
#if DEBUG
                    var partName = bodyPartEntity.GetEntityName();
                    _logger.MakeLog($"{partName} of {pedEntity.GetEntityName()} is not protected by armor");
#endif
                    ped.Armor = armor.Armor;
                    continue;
                }

                EcsEntity weaponEntity = _damagedPedsWithArmor.Components3[i].WeaponEntity;
                var       weaponStats  = _ecsWorld.GetComponent <ArmorWeaponStatsComponent>(weaponEntity);
                if (weaponStats == null)
                {
#if DEBUG
                    _logger.MakeLog($"Weapon {weaponEntity.GetEntityName()} " +
                                    $"doesn't have {nameof(ArmorWeaponStatsComponent)}");
#endif
                    ped.Armor = armor.Armor;
                    continue;
                }

                armor.Armor -= weaponStats.ArmorDamage;
                var newPain = _ecsWorld.EnsureComponent <AdditionalPainComponent>(pedEntity, out bool _);
                newPain.AdditionalPain = weaponStats.ArmorDamage;
#if DEBUG
                _logger.MakeLog($"Added pain {newPain.AdditionalPain:0.00} " +
                                $"by armor hit for {pedEntity.GetEntityName()}");
#endif

                if (armor.Armor <= 0)
                {
#if DEBUG
                    _logger.MakeLog($"Armor of {pedEntity.GetEntityName()} was destroyed");
#endif
                    ped.Armor = armor.Armor;
                    continue;
                }

                float maxArmor = ped.IsLocalPlayer
                    ? NativeFunction.Natives.GET_PLAYER_MAX_ARMOUR <int>(Game.LocalPlayer)
                    : 100;

                float armorPercent = armor.Armor / maxArmor;
                if (!weaponStats.CanPenetrateArmor || weaponStats.MinArmorPercentForPenetration < armorPercent)
                {
#if DEBUG
                    _logger.MakeLog($"Armor of {pedEntity.GetEntityName()} was not penetrated");
#endif
                    _ecsWorld.RemoveComponent <DamagedByWeaponComponent>(pedEntity);
                    _ecsWorld.RemoveComponent <DamagedBodyPartComponent>(pedEntity);
                    ped.Armor = armor.Armor;
                    continue;
                }

                float chanceToPenetrate = 1 - armorPercent / weaponStats.MinArmorPercentForPenetration;
                bool  wasPenetrated     = _random.IsTrueWithProbability(chanceToPenetrate);
                if (!wasPenetrated)
                {
#if DEBUG
                    _logger.MakeLog($"Armor of {pedEntity.GetEntityName()} was not penetrated, " +
                                    $"when chance was {chanceToPenetrate:0.00}");
#endif
                    _ecsWorld.RemoveComponent <DamagedByWeaponComponent>(pedEntity);
                    _ecsWorld.RemoveComponent <DamagedBodyPartComponent>(pedEntity);
                    ped.Armor = armor.Armor;
                    continue;
                }

#if DEBUG
                _logger.MakeLog($"Armor of {pedEntity.GetEntityName()} was penetrated, " +
                                $"when chance was {chanceToPenetrate:0.00}");
#endif
                ped.Armor = armor.Armor;
            }
        }