Пример #1
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);
        }
Пример #3
0
        public void InitStats(MyStatsDefinition definition)
        {
            if (definition == null || !definition.Enabled || (!definition.AvailableInSurvival && MySession.Static.SurvivalMode))
            {
                return;
            }

            foreach (var statId in definition.Stats)
            {
                MyEntityStatDefinition statDefinition = null;
                if (!MyDefinitionManager.Static.TryGetDefinition(statId, out statDefinition))
                {
                    continue;
                }

                if (!statDefinition.Enabled ||
                    (!statDefinition.EnabledInCreative && MySession.Static.CreativeMode) ||
                    (!statDefinition.AvailableInSurvival && MySession.Static.SurvivalMode))
                {
                    continue;
                }

                var          nameHash     = MyStringHash.GetOrCompute(statDefinition.Name);
                MyEntityStat existingStat = null;
                if (m_stats.TryGetValue(statId.SubtypeId, out existingStat) && existingStat.StatId == nameHash)
                {
                    continue;
                }

                var builder = new MyObjectBuilder_EntityStat();
                builder.SubtypeName = statId.SubtypeName;
                builder.MaxValue    = 1.0f;
                builder.Value       = 1.0f;
                AddStat(nameHash, builder);
            }

            if (Sync.IsServer)                  // Only init scripts on server
            {
                foreach (var scriptName in definition.Scripts)
                {
                    MyStatLogic script = null;
                    if ((script = m_scripts.Find((otherScript) => { return(otherScript.Name == scriptName); })) != null)
                    {
                        script.Close();
                        m_scripts.Remove(script);                               // On load we might've had less stats to consider (moving from creative to survival for example) so replace the old script
                    }

                    InitScript(scriptName);
                }
            }
            else
            {
                RequestStatActions();                   // Only request the stat actions from the server
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
 private void InitScript(string scriptName)
 {
     if (scriptName == "SpaceStatEffect")
     {
         MySpaceStatEffect item = new MySpaceStatEffect();
         item.Init(base.Entity as IMyCharacter, this.m_stats, "SpaceStatEffect");
         this.m_scripts.Add(item);
     }
     else
     {
         Type type;
         if (MyScriptManager.Static.StatScripts.TryGetValue(scriptName, out type))
         {
             MyStatLogic item = (MyStatLogic)Activator.CreateInstance(type);
             if (item != null)
             {
                 item.Init(base.Entity as IMyCharacter, this.m_stats, scriptName);
                 this.m_scripts.Add(item);
             }
         }
     }
 }
		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 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);
		}