コード例 #1
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(BasePainStateSystem <TStateEvent>);
#endif

            for (int i = 0; i < Events.EntitiesCount; i++)
            {
                var changeEvent = Events.Components1[i];
                var pedEntity   = changeEvent.Entity;
                if (!EcsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = EcsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed == null || woundedPed.IsDead)
                {
                    continue;
                }
                if (woundedPed.PainState == CurrentState && !changeEvent.ForceUpdate)
                {
                    continue;
                }

                ExecuteState(woundedPed, pedEntity);
                woundedPed.PainState = CurrentState;
            }
            Events.RemoveAllEntities();
        }
コード例 #2
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(CheckSystem);
#endif

            for (int i = 0; i < _events.EntitiesCount; i++)
            {
                int pedEntity = _events.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed == null)
                {
                    continue;
                }

                ShowHealth(woundedPed);
                ShowArmor(woundedPed);
                ShowPain(woundedPed, pedEntity);
                ShowCrits(woundedPed);
                ShowBleedings(woundedPed, pedEntity);
            }

            _events.RemoveAllEntities();
        }
コード例 #3
0
 public void Run()
 {
     if(_events.EntitiesCount <= 0) return;
     
     Function.Call(Hash.SET_FLASH, 0, 0, 100, 500, 100);
     _events.RemoveAllEntities();
 }
コード例 #4
0
ファイル: EcsNetSystems.cs プロジェクト: SH42913/leoecsnet
        private void StartStopListener()
        {
            if (_startEvents.EntitiesCount > 0)
            {
                if (!_config.Data.EcsNetworkListener.IsRunning)
                {
                    _config.Data.EcsNetworkListener.Start(_config.Data);
                }
#if DEBUG
                else
                {
                    throw new Exception("EcsNetworkListener is already started");
                }
#endif

                _startEvents.RemoveAllEntities();
            }

            if (_stopEvents.EntitiesCount > 0)
            {
                if (_config.Data.EcsNetworkListener.IsRunning)
                {
                    _config.Data.EcsNetworkListener.Stop();
                }
#if DEBUG
                else
                {
                    throw new Exception("EcsNetworkListener is already stopped");
                }
#endif

                _stopEvents.RemoveAllEntities();
            }
        }
コード例 #5
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(DebugInfoSystem);
#endif

            for (int i = 0; i < _events.EntitiesCount; i++)
            {
#if DEBUG
                int pedEntity = _events.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed == null)
                {
                    continue;
                }

                SendDebug($"{woundedPed}");
                _ecsWorld.CreateEntityWith <ShowHealthStateEvent>().Entity = pedEntity;
#endif
            }
            _events.RemoveAllEntities();
        }
コード例 #6
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(HelmetRequestSystem);
#endif

            if (_requests.EntitiesCount <= 0)
            {
                return;
            }

            var player = Game.Player;
            if (player.Character.IsWearingHelmet)
            {
                player.Character.RemoveHelmet(false);
            }
            else
            {
                if (player.Money > _config.Data.PlayerConfig.MoneyForHelmet)
                {
                    player.Money -= _config.Data.PlayerConfig.MoneyForHelmet;
                    player.Character.GiveHelmet(false, HelmetType.RegularMotorcycleHelmet, Random.Next(0, 15));
                }
                else
                {
                    var message = _ecsWorld.CreateEntityWith <ShowNotificationEvent>();
                    message.StringToShow = _locale.Data.DontHaveMoneyForHelmet;
                    message.Level        = NotifyLevels.COMMON;
                }
            }

            _requests.RemoveAllEntities();
        }
コード例 #7
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(SwitchAnimationSystem);
#endif

            for (int i = 0; i < _events.EntitiesCount; i++)
            {
                int pedEntity = _events.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed == null)
                {
                    continue;
                }

                var animationName = _events.Components1[i].AnimationName;
                if (string.IsNullOrEmpty(animationName) || !woundedPed.ThisPed.IsAlive)
                {
                    continue;
                }

                Function.Call(Hash.REQUEST_ANIM_SET, animationName);
                if (!Function.Call <bool>(Hash.HAS_ANIM_SET_LOADED, animationName))
                {
                    Function.Call(Hash.REQUEST_ANIM_SET, animationName);
                }
                Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET, woundedPed.ThisPed, animationName, 1.0f);
            }
            _events.RemoveAllEntities();
        }
コード例 #8
0
        private void FindPeds()
        {
            float addRange = _config.Data.NpcConfig.AddingPedRange;

            if (addRange <= GunshotWound2.MINIMAL_RANGE_FOR_WOUNDED_PEDS)
            {
                return;
            }
            Ped playerPed = Game.Player.Character;

            if (CheckNeedToUpdateWorldPeds())
            {
                _config.Data.NpcConfig.WorldPeds           = World.GetNearbyPeds(playerPed, addRange);
                _config.Data.NpcConfig.LastCheckedPedIndex = 0;
                _forceUpdates.RemoveAllEntities();
            }

            Ped[] allPeds   = _config.Data.NpcConfig.WorldPeds;
            var   pedsToAdd = new Queue <Ped>();

            _stopwatch.Restart();
            for (int worldPedIndex = _config.Data.NpcConfig.LastCheckedPedIndex; worldPedIndex < allPeds.Length; worldPedIndex++)
            {
                if (_stopwatch.ElapsedMilliseconds > _config.Data.NpcConfig.UpperBoundForFindInMs)
                {
                    break;
                }

                _config.Data.NpcConfig.LastCheckedPedIndex = worldPedIndex;
                Ped pedToCheck = allPeds[worldPedIndex];

                if (!pedToCheck.IsHuman || pedToCheck.IsDead || pedToCheck.IsPlayer)
                {
                    continue;
                }
                if (!PedInTargetList(playerPed, pedToCheck))
                {
                    continue;
                }
                if (_config.Data.NpcConfig.ScanOnlyDamaged && !Function.Call <bool>(Hash.HAS_ENTITY_BEEN_DAMAGED_BY_ANY_PED, pedToCheck))
                {
                    continue;
                }
                if (CheckWoundedPedExist(pedToCheck))
                {
                    continue;
                }

                pedsToAdd.Enqueue(pedToCheck);
            }
            _stopwatch.Stop();

            if (pedsToAdd.Count <= 0)
            {
                return;
            }
            _ecsWorld.CreateEntityWith <ConvertPedToNpcGswPedEvent>().PedsToAdd = pedsToAdd;
        }
コード例 #9
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(WoundSystem);
#endif

            for (int i = 0; i < _components.EntitiesCount; i++)
            {
                ProcessWoundEvent component = _components.Components1[i];
                int pedEntity = component.Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed == null)
                {
                    continue;
                }

                float damageDeviation = component.Damage > 0
                    ? _config.Data.WoundConfig.DamageDeviation * component.Damage
                    : 0;
                float bleedingDeviation = component.BleedSeverity > 0
                    ? _config.Data.WoundConfig.BleedingDeviation * component.BleedSeverity
                    : 0;

                if (!woundedPed.IsDead)
                {
                    woundedPed.Health -= _config.Data.WoundConfig.DamageMultiplier * component.Damage +
                                         Random.NextFloat(-damageDeviation, damageDeviation);
                    woundedPed.ThisPed.Health = (int)woundedPed.Health;
                }

                CreateBleeding(woundedPed, pedEntity, component.BleedSeverity +
                               Random.NextFloat(-bleedingDeviation, bleedingDeviation), component.Name);
                woundedPed.BleedingCount++;

                CreatePain(pedEntity, component.Pain);
                CreateCritical(pedEntity, component.Crits);

                if (component.ArterySevered)
                {
                    CreateBleeding(woundedPed, pedEntity, 1f, _locale.Data.SeveredArtery);
                    woundedPed.BleedingCount++;
                }

#if DEBUG
                _ecsWorld.CreateEntityWith <ShowDebugInfoEvent>().Entity = pedEntity;
#endif
                SendWoundInfo(component, woundedPed);
            }
            _components.RemoveAllEntities();
        }
コード例 #10
0
        public void Run()
        {
            for (int i = 0; i < _events.EntitiesCount; i++)
            {
                if (Function.Call <bool>(Hash.IS_SPECIAL_ABILITY_ACTIVE, Game.Player))
                {
                    Function.Call(Hash.SPECIAL_ABILITY_DEACTIVATE_FAST, Game.Player);
                }

                Function.Call(_events.Components1[i].Lock
                        ? Hash.SPECIAL_ABILITY_LOCK
                        : Hash.SPECIAL_ABILITY_UNLOCK,
                              Game.Player.Character.Model.Hash);
            }

            _events.RemoveAllEntities();
        }
コード例 #11
0
        public void Run()
        {
            for (int i = 0; i < _events.EntitiesCount; i++)
            {
                AddCameraShakeEvent newEvent = _events.Components1[i];

                switch (newEvent.Length)
                {
                case CameraShakeLength.ONE_TIME:
                    if (_config.Data.PlayerConfig.CameraIsShaking)
                    {
                        continue;
                    }
                    Function.Call(Hash._SET_CAM_EFFECT, 1);
                    _config.Data.PlayerConfig.CameraIsShaking = false;
                    break;

                case CameraShakeLength.PERMANENT:
                    if (_config.Data.PlayerConfig.CameraIsShaking)
                    {
                        continue;
                    }
                    Function.Call(Hash._SET_CAM_EFFECT, 2);
                    _config.Data.PlayerConfig.CameraIsShaking = true;
                    break;

                case CameraShakeLength.CLEAR:
                    if (!_config.Data.PlayerConfig.CameraIsShaking)
                    {
                        continue;
                    }
                    Function.Call(Hash._SET_CAM_EFFECT, 0);
                    _config.Data.PlayerConfig.CameraIsShaking = false;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _events.RemoveAllEntities();
        }
コード例 #12
0
ファイル: EcsNetSystems.cs プロジェクト: SH42913/leoecsnet
        private void ReceiveComponents()
        {
            _newEntities.RemoveAllEntities();
#if DEBUG
            if (_receivedComponents.EntitiesCount > 0)
            {
                throw new Exception("Not all received components was processed. " +
                                    "Did you register all NetworkComponentProcessSystems?");
            }
#endif
            foreach (var receivedComponent in _config.Data.EcsNetworkListener.GetReceivedComponents())
            {
                ReceivedNetworkComponentEvent receivedNetworkComponentEvent;
                _ecsWorld.CreateEntityWith(out receivedNetworkComponentEvent);
                receivedNetworkComponentEvent.ComponentFlags   = receivedComponent.ComponentFlags;
                receivedNetworkComponentEvent.NetworkEntityUid = receivedComponent.NetworkEntityUid;
                receivedNetworkComponentEvent.ComponentTypeUid = receivedComponent.ComponentTypeUid;
                receivedNetworkComponentEvent.ComponentBytes   = receivedComponent.ComponentBytes;
            }
        }
コード例 #13
0
ファイル: EcsNetSystems.cs プロジェクト: SH42913/leoecsnet
        public void Run()
        {
            for (int i = 0; i < ReceivedComponents.EntitiesCount; i++)
            {
                var receivedComponent = ReceivedComponents.Components1[i];
                if (receivedComponent.ComponentTypeUid != ComponentUid)
                {
                    continue;
                }

                ProcessReceivedComponent(receivedComponent);
                receivedComponent.ComponentBytes = null;
                EcsWorld.RemoveEntity(ReceivedComponents.Entities[i]);
            }

            for (int i = 0; i < ComponentsToPrepare.EntitiesCount; i++)
            {
                PrepareComponentToNetwork(ComponentsToPrepare.Components1[i]);
            }

            ComponentsToPrepare.RemoveAllEntities();
        }
コード例 #14
0
ファイル: EcsNetSystems.cs プロジェクト: SH42913/leoecsnet
        private void SendComponents()
        {
#if DEBUG
            int prepareCount = _prepareEvents.EntitiesCount;
            int sendCount    = _sendEvents.EntitiesCount;
            if (prepareCount != sendCount)
            {
                throw new Exception(string.Format("You have {0} PrepareEvents and {1} SendEvents." +
                                                  "Did you register all NetworkComponentProcessSystems?", prepareCount, sendCount));
            }
            _prepareEvents.RemoveAllEntities();
#endif

            for (int i = 0; i < _sendEvents.EntitiesCount; i++)
            {
                var sendEvent = _sendEvents.Components1[i];
                _config.Data.EcsNetworkListener.AddComponentsForSend(sendEvent);
                sendEvent.ComponentBytes = null;
            }

            _sendEvents.RemoveAllEntities();
            _config.Data.EcsNetworkListener.Send();
        }
コード例 #15
0
        public void Run()
        {
            for (int i = 0; i < _requestEvents.EntitiesCount; i++)
            {
                int pedEntity = _requestEvents.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed?.MostDangerBleedingEntity == null)
                {
                    continue;
                }
                if (woundedPed.InPermanentRagdoll)
                {
                    continue;
                }

                if (woundedPed.IsPlayer)
                {
                    if (Game.Player.Money < _config.Data.WoundConfig.BandageCost)
                    {
                        SendMessage(_localeConfig.Data.DontHaveMoneyForBandage, pedEntity);
                        continue;
                    }
                    Game.Player.Money -= _config.Data.WoundConfig.BandageCost;
                }

                var progress = _ecsWorld.EnsureComponent <BandageInProgressComponent>(pedEntity, out bool isNew);
                if (!isNew)
                {
                    SendMessage(_localeConfig.Data.AlreadyBandaging, pedEntity);
                    continue;
                }

                float timeToBandage = _config.Data.WoundConfig.ApplyBandageTime;
                progress.EstimateTime = timeToBandage;
                SendMessage(string.Format(_localeConfig.Data.YouTryToBandage, timeToBandage), pedEntity);
            }
            _requestEvents.RemoveAllEntities();

            float frameTimeInSec = Game.LastFrameTime;

            for (int i = 0; i < _pedsWithBandageInProgress.EntitiesCount; i++)
            {
                WoundedPedComponent woundedPed = _pedsWithBandageInProgress.Components1[i];
                Ped thisPed = woundedPed.ThisPed;
                BandageInProgressComponent progress = _pedsWithBandageInProgress.Components2[i];
                int pedEntity = _pedsWithBandageInProgress.Entities[i];

                if (woundedPed.InPermanentRagdoll || thisPed.IsWalking || thisPed.IsRunning ||
                    thisPed.IsSprinting || thisPed.IsShooting || thisPed.IsRagdoll ||
                    thisPed.IsJumping || thisPed.IsReloading || thisPed.IsSwimming)
                {
                    SendMessage($"~r~{_localeConfig.Data.BandageFailed}", pedEntity);
                    _ecsWorld.RemoveComponent <BandageInProgressComponent>(pedEntity);
                    continue;
                }
                progress.EstimateTime -= frameTimeInSec;

                if (progress.EstimateTime > 0)
                {
                    continue;
                }
                _ecsWorld.RemoveComponent <BandageInProgressComponent>(pedEntity);
                _ecsWorld.CreateEntityWith <SuccessfulBandageEvent>().Entity = pedEntity;
            }

            for (int i = 0; i < _successfulEvents.EntitiesCount; i++)
            {
                int pedEntity = _successfulEvents.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed?.MostDangerBleedingEntity == null)
                {
                    continue;
                }

                int bleedingEntity = woundedPed.MostDangerBleedingEntity.Value;
                if (!_ecsWorld.IsEntityExists(bleedingEntity))
                {
                    continue;
                }

                var bleeding = _ecsWorld.GetComponent <BleedingComponent>(woundedPed.MostDangerBleedingEntity.Value);
                if (bleeding == null)
                {
                    continue;
                }

                bleeding.BleedSeverity = bleeding.BleedSeverity / 2;
                UpdateMostDangerWound(woundedPed, pedEntity);
                SendMessage(string.Format("~g~" + _localeConfig.Data.BandageSuccess, bleeding.Name), pedEntity);
            }
            _successfulEvents.RemoveAllEntities();
        }
コード例 #16
0
        public void Run()
        {
#if DEBUG
            GunshotWound2.LastSystem = nameof(InstantHealSystem);
#endif

            for (int i = 0; i < _events.EntitiesCount; i++)
            {
                int pedEntity = _events.Components1[i].Entity;
                if (!_ecsWorld.IsEntityExists(pedEntity))
                {
                    continue;
                }

                var woundedPed = _ecsWorld.GetComponent <WoundedPedComponent>(pedEntity);
                if (woundedPed != null)
                {
                    if (woundedPed.IsPlayer)
                    {
                        _ecsWorld.CreateEntityWith <AddCameraShakeEvent>().Length = CameraShakeLength.CLEAR;
                        Function.Call(Hash.SET_PLAYER_SPRINT, Game.Player, true);
                        Function.Call(Hash._SET_CAM_EFFECT, 0);
                        Function.Call(Hash._STOP_ALL_SCREEN_EFFECTS);
                        woundedPed.Health             = _mainConfig.Data.PlayerConfig.MaximalHealth;
                        Game.Player.IgnoredByEveryone = false;
                    }
                    else
                    {
                        woundedPed.Health           = Random.Next(50, _mainConfig.Data.NpcConfig.MaxStartHealth);
                        woundedPed.ThisPed.Accuracy = woundedPed.DefaultAccuracy;
                    }

                    woundedPed.IsDead                   = false;
                    woundedPed.Crits                    = 0;
                    woundedPed.ThisPed.Health           = (int)woundedPed.Health;
                    woundedPed.Armor                    = woundedPed.ThisPed.Armor;
                    woundedPed.BleedingCount            = 0;
                    woundedPed.MostDangerBleedingEntity = null;

                    _ecsWorld.RemoveComponent <PainComponent>(pedEntity, true);

                    Function.Call(Hash.CLEAR_PED_BLOOD_DAMAGE, woundedPed.ThisPed);
                    Function.Call(Hash.SET_PED_MOVE_RATE_OVERRIDE, woundedPed.ThisPed, 1f);

                    _ecsWorld.CreateEntityWith(out NoPainChangeStateEvent noPainEvent);
                    noPainEvent.Entity      = pedEntity;
                    noPainEvent.ForceUpdate = true;
                }

                for (int bleedIndex = 0; bleedIndex < _bleedingComponents.EntitiesCount; bleedIndex++)
                {
                    if (_bleedingComponents.Components1[bleedIndex].Entity != pedEntity)
                    {
                        continue;
                    }

                    _ecsWorld.RemoveEntity(_bleedingComponents.Entities[bleedIndex]);
                }
            }

            _events.RemoveAllEntities();
        }