Beispiel #1
0
        private static void OnStatChangedMessage(long entityId, List <StatInfo> changedStats)
        {
            MyEntity entity;

            if (!MyEntities.TryGetEntityById(entityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComp = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComp))
            {
                return;
            }

            foreach (var statChange in changedStats)
            {
                MyEntityStat localStat;
                if (!statComp.TryGetStat(statChange.StatId, out localStat))
                {
                    continue;
                }
                localStat.Value         = statChange.Amount;
                localStat.StatRegenLeft = statChange.RegenLeft;
            }
        }
        private static void OnStatChangedMessage(ref EntityStatChangedMsg msg, MyNetworkClient sender)
        {
            MyEntity entity;

            if (!MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComp = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComp))
            {
                return;
            }

            foreach (var statChange in msg.ChangedStats)
            {
                MyEntityStat localStat;
                if (!statComp.TryGetStat(statChange.StatId, out localStat))
                {
                    continue;
                }
                localStat.Value         = statChange.Amount;
                localStat.StatRegenLeft = statChange.RegenLeft;
            }
        }
Beispiel #3
0
        private static void OnStatActionMessage(long entityId, Dictionary <string, MyStatLogic.MyStatAction> statActions)
        {
            MyEntity entity = null;

            if (!MyEntities.TryGetEntityById(entityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComponent = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComponent))
            {
                return;
            }

            MyStatLogic script = new MyStatLogic();

            script.Init(entity as IMyCharacter, statComponent.m_stats, "LocalStatActionScript");
            foreach (var actionPair in statActions)
            {
                script.AddAction(actionPair.Key, actionPair.Value);
            }

            statComponent.m_scripts.Add(script);
        }
        private static void OnStatActionMessage(ref StatActionMsg msg, MyNetworkClient sender)
        {
            if (msg.StatActions == null)
            {
                return;
            }

            MyEntity entity = null;

            if (!MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComponent = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComponent))
            {
                return;
            }

            MyStatLogic script = new MyStatLogic();

            script.Init(entity as IMyCharacter, statComponent.m_stats, "LocalStatActionScript");
            foreach (var actionPair in msg.StatActions)
            {
                script.AddAction(actionPair.Key, actionPair.Value);
            }

            statComponent.m_scripts.Add(script);
        }
        private static void OnStatChangedRequest(ref EntityStatChangedMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(Sync.IsServer);

            MyEntity entity;

            if (!MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComp = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComp))
            {
                return;
            }

            foreach (var statChange in msg.ChangedStats)
            {
                MyEntityStat localStat;
                if (!statComp.TryGetStat(statChange.StatId, out localStat))
                {
                    continue;
                }
                localStat.Value = statChange.Amount;
            }
        }
Beispiel #6
0
        private static void OnStatActionRequest(long entityId)
        {
            MyEntity entity = null;

            if (MyEntities.TryGetEntityById(entityId, out entity, false))
            {
                MyEntityStatComponent component = null;
                if (entity.Components.TryGet <MyEntityStatComponent>(out component))
                {
                    Dictionary <string, MyStatLogic.MyStatAction> statActions = new Dictionary <string, MyStatLogic.MyStatAction>();
                    using (List <MyStatLogic> .Enumerator enumerator = component.m_scripts.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            foreach (KeyValuePair <string, MyStatLogic.MyStatAction> pair in enumerator.Current.StatActions)
                            {
                                if (!statActions.ContainsKey(pair.Key))
                                {
                                    statActions.Add(pair.Key, pair.Value);
                                }
                            }
                        }
                    }
                    if (MyEventContext.Current.IsLocallyInvoked)
                    {
                        OnStatActionMessage(entityId, statActions);
                    }
                    else
                    {
                        Vector3D?position = null;
                        MyMultiplayer.RaiseStaticEvent <long, Dictionary <string, MyStatLogic.MyStatAction> >(s => new Action <long, Dictionary <string, MyStatLogic.MyStatAction> >(MyEntityStatComponent.OnStatActionMessage), entityId, statActions, MyEventContext.Current.Sender, position);
                    }
                }
            }
        }
Beispiel #7
0
        private static void OnStatActionRequest(ref StatActionRequestMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(Sync.IsServer);
            MyEntity entity = null;

            if (!MyEntities.TryGetEntityById(msg.EntityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComponent = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComponent))
            {
                return;
            }

            StatActionMsg actionMsg = new StatActionMsg()
            {
                EntityId    = msg.EntityId,
                StatActions = new Dictionary <string, MyStatLogic.MyStatAction>(),
            };

            foreach (var script in statComponent.m_scripts)
            {
                foreach (var actionPair in script.StatActions)
                {
                    actionMsg.StatActions.Add(actionPair.Key, actionPair.Value);
                }
            }

            MySession.Static.SyncLayer.SendMessage(ref actionMsg, sender.SteamUserId, MyTransportMessageEnum.Success);
        }
Beispiel #8
0
        private static void OnStatActionMessage(long entityId, Dictionary <string, MyStatLogic.MyStatAction> statActions)
        {
            MyEntity entity = null;

            if (MyEntities.TryGetEntityById(entityId, out entity, false))
            {
                MyEntityStatComponent component = null;
                if (entity.Components.TryGet <MyEntityStatComponent>(out component))
                {
                    MyStatLogic item = new MyStatLogic();
                    item.Init(entity as IMyCharacter, component.m_stats, "LocalStatActionScript");
                    foreach (KeyValuePair <string, MyStatLogic.MyStatAction> pair in statActions)
                    {
                        item.AddAction(pair.Key, pair.Value);
                    }
                    component.m_scripts.Add(item);
                }
            }
        }
Beispiel #9
0
        private static void OnStatChangedMessage(long entityId, List <StatInfo> changedStats)
        {
            MyEntity entity;

            if (MyEntities.TryGetEntityById(entityId, out entity, false))
            {
                MyEntityStatComponent component = null;
                if (entity.Components.TryGet <MyEntityStatComponent>(out component))
                {
                    foreach (StatInfo info in changedStats)
                    {
                        MyEntityStat stat;
                        if (component.TryGetStat(info.StatId, out stat))
                        {
                            stat.Value         = info.Amount;
                            stat.StatRegenLeft = info.RegenLeft;
                        }
                    }
                }
            }
        }
Beispiel #10
0
        private static void OnStatActionRequest(long entityId)
        {
            MyEntity entity = null;

            if (!MyEntities.TryGetEntityById(entityId, out entity))
            {
                return;
            }

            MyEntityStatComponent statComponent = null;

            if (!entity.Components.TryGet <MyEntityStatComponent>(out statComponent))
            {
                return;
            }

            var statActions = new Dictionary <string, MyStatLogic.MyStatAction>();

            foreach (var script in statComponent.m_scripts)
            {
                foreach (var actionPair in script.StatActions)
                {
                    if (!statActions.ContainsKey(actionPair.Key))
                    {
                        statActions.Add(actionPair.Key, actionPair.Value);
                    }
                }
            }

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                OnStatActionMessage(entityId, statActions);
            }
            else
            {
                MyMultiplayer.RaiseStaticEvent(s => MyEntityStatComponent.OnStatActionMessage, entityId, statActions, MyEventContext.Current.Sender);
            }
        }