Пример #1
0
 private void dequeueAddedEntities()
 {
     foreach (var entity in queueAddedEntities)
     {
         if (entity is IMyCubeGrid)
         {
             var grid = entity as IMyCubeGrid;
             //                ModLog.Info("Added Grid:" + grid.CustomName);
             if (grid.Physics != null)
             {
                 //                    ModLog.Info(" Has Physics");
                 GridInit(grid);
             }
             else
             {
                 // it's a projection or a paste in progress
                 //                    ModLog.Info(" NO Physics!");
             }
         }
         else if (entity is IMyPlayer)
         {
             IMyPlayer player = (IMyPlayer)entity;
             ModLog.Info("Added Player:" + player.DisplayName);
         }
     }
     queueAddedEntities.Clear();
 }
Пример #2
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                updateCount = ++updateCount % MaxUpdatesCount;

                if (!init && updateCount > UpdatesUntilInitAttempted)
                {
                    ModLog.Init();
//                    (MyAPIGateway.Multiplayer.IsServer && MyAPIGateway.Utilities.IsDedicated)

                    machineType = MyAPIGateway.Multiplayer.IsServer ? MachineType.Host : MachineType.Client;
                    MyAPIGateway.Entities.OnEntityAdd += OnEntityAdd;
                    InitCommon(modProxy);
                    if (machineType == MachineType.Host)
                    {
                        InitHostPreLoading();
                        LoadSaveData();
                        InitHostPostLoading(modProxy);
                    }
                    else
                    {
                        InitClient(modProxy);
                    }
                    modProxy.InitModSystems();
                    init = true;
                }

                modProxy.Update1();

                if (updateCount % UpdatesUntilInitAttempted == 0)
                {
                    dequeueAddedEntities();
                }
                if (updateCount % 30 == 0)
                {
                    modProxy.Update30();
                }

                if (updateCount % 60 == 0)
                {
                    modProxy.Update60();                     // There are 60 updates per second with simspeed at normal
                }

                if (updateCount % 300 == 0)
                {
                    modProxy.Update300();
                }

                if (updateCount % 1200 == 0)
                {
                    modProxy.Update1200();
                }
            }
            catch (Exception e)
            {
                ModLog.Error(e);
            }
        }
Пример #3
0
        internal static void SetPlayerReputation(long playerID, string toFactionTag, int reputation)
        {
            var faction1 = MyAPIGateway.Session.Factions.TryGetFactionByTag(toFactionTag);

            if (faction1 == null)
            {
                ModLog.Error("Can't find faction: " + toFactionTag);
                return;
            }
            MyAPIGateway.Session.Factions.SetReputationBetweenPlayerAndFaction(playerID, faction1.FactionId, reputation);
        }
Пример #4
0
        internal static void PutPlayerIntoFaction(long playerIdentityID, string tag)
        {
            var faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag);

            if (faction == null)
            {
                ModLog.Error("Can't find faction: " + tag);
                return;
            }
            MyAPIGateway.Session.Factions.SendJoinRequest(faction.FactionId, playerIdentityID);
            MyAPIGateway.Session.Factions.AcceptJoin(faction.FactionId, playerIdentityID);
        }
Пример #5
0
 protected override void UnloadData()
 {
     try
     {
         Close();
         init = false;
         modProxy.Shutdown();
     }
     catch (Exception ex)
     {
         ModLog.Error(ex);
     }
     ModLog.Close();
 }
Пример #6
0
        /// <summary>
        /// Puts LOCAL player into faction.  Safe to call even if no local player
        /// </summary>
        /// <param name="tag"></param>
        internal static void PutPlayerIntoFaction(string tag)
        {
            var faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag);

            if (faction == null)
            {
                ModLog.Error("Can't find faction: " + tag);
                return;
            }

            var player = MyAPIGateway.Session.Player;

            if (player == null)
            {
                return;
            }
            PutPlayerIntoFaction(player.IdentityId, tag);
        }
Пример #7
0
        internal static void SetAllPlayerReputation(string toFactionTag, int reputation)
        {
            var faction2 = MyAPIGateway.Session.Factions.TryGetFactionByTag(toFactionTag);

            if (faction2 == null)
            {
                ModLog.Error("Can't find faction: " + toFactionTag);
                return;
            }

            var players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players);

            foreach (var player in players)
            {
                MyAPIGateway.Session.Factions.SetReputationBetweenPlayerAndFaction(player.IdentityId, faction2.FactionId, reputation);
            }
        }
Пример #8
0
 private void LoadSaveData()
 {
     try
     {
         string xmlData;
         if (MyAPIGateway.Utilities.GetVariable(GetSaveDataFileName(), out xmlData))                 // New saving system
         {
             LoadPreviousGame(MyAPIGateway.Utilities.SerializeFromXML <T>(xmlData));
         }
         else
         {
             StartedNewGame();
         }
     }
     catch (Exception e)
     {
         ModLog.Error(e);
     }
 }
Пример #9
0
        internal static void DeclareWarBetweenFactions(string tag, string tag2)
        {
            var faction1 = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag);

            if (faction1 == null)
            {
                ModLog.Error("Can't find faction: " + tag);
                return;
            }

            var faction2 = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag2);

            if (faction2 == null)
            {
                ModLog.Error("Can't find faction: " + tag2);
                return;
            }

            MyAPIGateway.Session.Factions.DeclareWar(faction2.FactionId, faction1.FactionId);
        }
Пример #10
0
 public override void SaveData()
 {
     try
     {
         T saveData = GetSaveData();
         MyAPIGateway.Utilities.SetVariable(GetSaveDataFileName(), MyAPIGateway.Utilities.SerializeToXML(saveData));
         if (DebugSaveData)
         {
             MyAPIGateway.Parallel.Start(() =>
             {
                 using (var sw = MyAPIGateway.Utilities.WriteFileInWorldStorage("SaveDataSnapshot.xml",
                                                                                typeof(EfmCore))) sw.Write(MyAPIGateway.Utilities.SerializeToXML(saveData));
             });
         }
     }
     catch (Exception e)
     {
         ModLog.Error(e);
     }
 }
Пример #11
0
        internal static void MakePeaceBetweenFactions(string tag, string tag2)
        {
            var faction1 = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag);

            if (faction1 == null)
            {
                ModLog.Error("Can't find faction: " + tag);
                return;
            }

            var faction2 = MyAPIGateway.Session.Factions.TryGetFactionByTag(tag2);

            if (faction2 == null)
            {
                ModLog.Error("Can't find faction: " + tag2);
                return;
            }
            MyAPIGateway.Session.Factions.SendPeaceRequest(faction1.FactionId, faction2.FactionId);
            MyAPIGateway.Session.Factions.AcceptPeace(faction2.FactionId, faction1.FactionId);
        }
Пример #12
0
        public static T GetTerminalBlockMatchingName <T>(this IMyCubeGrid grid, string name) where T : IMyTerminalBlock
        {
            var slimBlocks = new List <IMySlimBlock>();

            if (grid == null)
            {
                return(default(T));
            }
            grid.GetBlocks(slimBlocks, b => b.FatBlock is T);
            foreach (var slim in slimBlocks)
            {
                var terminalBlock = (T)slim.FatBlock;
                if (terminalBlock.CustomName.Contains(name))
                {
                    return(terminalBlock);
                }
            }
            ModLog.Info("Can't find terminal block matching name: " + name);

            return(default(T));// throw new InvalidOperationException("Can't find terminal block matching name: " + name);
        }