コード例 #1
0
ファイル: WelderHUD.cs プロジェクト: Cheetah97/LaserWelders
        void ComplainMissingLocal(string Missing)
        {
            try
            {
                var Player = MyAPIGateway.Session.LocalHumanPlayer;
                if (Player == null)
                {
                    return;
                }
                if (Player.IdentityId != Tool.OwnerId)
                {
                    return;
                }

                var Dist = Player.GetPosition().DistanceTo(Tool.GetPosition());
                if (Dist > 200)
                {
                    //SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing() exit - local player too far ({Math.Round(Dist)}m)", WriteOnlyIfDebug: true);
                    return;
                }
                //SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing() successfully complained. Missing length: {Missing.Length}", WriteOnlyIfDebug: true);
                ToolComp.MissingHUD.Text = Missing;
                HUDMessageUpdate         = DateTime.Now;
                ToolComp.MissingHUD.Show();
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"{Tool.CustomName}.ComplainMissing()", Scrap);
            }
        }
コード例 #2
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
 public override void Close()
 {
     try
     {
         if (SessionCore.Settings.Debug)
         {
             DebugNote.Hide();
             DebugNote.AliveTime = 0;
             DebugNote           = null;
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill?.CustomName}.Close().DebugClose", Scrap);
     }
     try
     {
         SessionCore.SaveUnregister(Save);
         SyncHarvestEfficiency.GotValueFromServer -= Drill.UpdateVisual;
         SyncHarvestEfficiency.Close();
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill?.CustomName}.Close()", Scrap);
     }
 }
コード例 #3
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
        public override void UpdateOnceBeforeFrame()
        {
            try
            {
                if (Drill.CubeGrid.Physics?.Enabled != true || !Networker.Inited)
                {
                    NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                    if (!Networker.Inited)
                    {
                        Networker.Init(SessionCore.ModID);
                    }
                    return;
                }
                SyncHarvestEfficiency = new Syncer <float>(Drill, "HarvestEfficiency", 1, Checker: val => val >= 1 && val <= 4);
                SyncHarvestEfficiency.GotValueFromServer += Drill.UpdateVisual;
                Drill.PowerConsumptionMultiplier          = PowerConsumptionMultiplier();

                CheckInitControls();
                Load();

                SessionCore.SaveRegister(Save);
                NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
                DebugNote    = MyAPIGateway.Utilities.CreateNotification($"{Drill?.CustomName}", int.MaxValue, "Blue");
                Owner        = MyAPIGateway.Players.GetPlayer(Drill.OwnerId);
                if (SessionCore.Settings.Debug)
                {
                    DebugNote.Show();
                }
            }
            catch { }
        }
コード例 #4
0
        public static Dictionary <string, int> CalculateMissingComponents(this IMyCubeGrid Grid)
        {
            if (Grid == null)
            {
                return(new Dictionary <string, int>());
            }
            try
            {
                Dictionary <string, int> MissingComponents = new Dictionary <string, int>();
                List <IMySlimBlock>      Blocks            = new List <IMySlimBlock>();
                Grid.GetBlocks(Blocks);

                foreach (IMySlimBlock Block in Blocks)
                {
                    try
                    {
                        Block.ReadMissingComponents(MissingComponents);
                    }
                    catch (Exception Scrap)
                    {
                        SessionCore.LogError($"CalculateMissing[{Grid.CustomName}].Iterate", Scrap, DebugPrefix: "LaserWelders.");
                    }
                }
                return(MissingComponents);
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"CalculateMissing[{Grid.CustomName}]", Scrap, DebugPrefix: "LaserWelders.");
                return(new Dictionary <string, int>());
            }
        }
コード例 #5
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
 public void Save()
 {
     try
     {
         Persistent persistent;
         persistent.HarvestMultiplier = SyncHarvestEfficiency.Get();
         string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent));
         //MyAPIGateway.Utilities.SetVariable($"settings_{Drill.EntityId}", Raw);
         if (Drill.Storage != null)
         {
             if (Drill.Storage.ContainsKey(SessionCore.StorageGuid))
             {
                 Drill.Storage[SessionCore.StorageGuid] = Raw;
             }
             else
             {
                 Drill.Storage.Add(SessionCore.StorageGuid, Raw);
             }
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill.CustomName}.Save()", Scrap);
     }
 }
コード例 #6
0
 void CheckInitControls()
 {
     if (!SessionCore.InitedDrillControls)
     {
         SessionCore.InitDrillControls();
     }
 }
コード例 #7
0
ファイル: LaserWelder.cs プロジェクト: Cheetah97/LaserWelders
        protected override void ProcessGrid(IMyCubeGrid TargetGrid, int ticks)
        {
            List <IMySlimBlock> Blocks = new List <IMySlimBlock>();
            List <LineD>        RayGrid;

            if (!TermModule.DistanceMode)
            {
                Vector3D UpOffset    = Vector3D.Normalize(Tool.WorldMatrix.Up) * 0.5;
                Vector3D RightOffset = Vector3D.Normalize(Tool.WorldMatrix.Right) * 0.5;
                RayGrid = VectorExtensions.BuildLineGrid(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd, UpOffset, RightOffset, SessionCore.Settings.WorkingZoneWidth, SessionCore.Settings.WorkingZoneWidth);
                if (TargetGrid.Physics?.Enabled == true)
                {
                    TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsWeldable());
                    if (SessionCore.Settings.Debug && SessionCore.Settings.DebugPerformance)
                    {
                        SessionCore.DebugAsync(Tool.CustomName, $"Welding {Blocks.CollapseDuplicates().Count} blocks", WriteOnlyIfDebug: true);
                    }
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        Weld(Blocks, ticks);
                    }
                }
                else
                {
                    TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable());
                    if (Blocks.Count == 0)
                    {
                        return;
                    }
                    SessionCore.DebugAsync(Tool.CustomName, $"Placing {Blocks.Count} blocks", WriteOnlyIfDebug: true);
                    try
                    {
                        Place(Blocks);
                    }
                    catch (Exception Scrap)
                    {
                        SessionCore.DebugAsync(Tool.CustomName, $"Place() crashed: {Scrap.Message}\n{Scrap.StackTrace}");
                    }
                }
            }
            else
            {
                RayGrid = new List <LineD> {
                    new LineD(BeamCtlModule.BeamStart, BeamCtlModule.BeamEnd)
                };
                if (TargetGrid.Physics?.Enabled == true)
                {
                    TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsWeldable());
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        Weld(Blocks, ticks);
                    }
                }
                else
                {
                    TargetGrid.GetBlocksOnRay(RayGrid, Blocks, x => x.IsProjectable());
                    Place(Blocks);
                }
            }
        }
コード例 #8
0
 public override void Close()
 {
     try
     {
         if (SessionCore.Debug)
         {
             DebugNote.Hide();
             DebugNote.AliveTime = 0;
             DebugNote           = null;
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Close().DebugClose", Scrap);
     }
     try
     {
         SessionCore.SaveUnregister(Save);
         SyncBeamLength.GotValueFromServer      -= Tool.UpdateVisual;
         SyncDistanceMode.GotValueFromServer    -= Tool.UpdateVisual;
         SyncSpeedMultiplier.GotValueFromServer -= Tool.UpdateVisual;
         SyncBeamLength.Close();
         SyncDistanceMode.Close();
         SyncSpeedMultiplier.Close();
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Close()", Scrap);
     }
 }
コード例 #9
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
 public void Load()
 {
     try
     {
         if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
         {
             SyncHarvestEfficiency.Ask();
             return;
         }
         string Storage = "";
         //if (Tool.Storage.ContainsKey(SessionCore.StorageGuid))
         if (Drill.Storage?.TryGetValue(SessionCore.StorageGuid, out Storage) == true)
         {
             try
             {
                 Persistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <Persistent>(Convert.FromBase64String(Storage));
                 SyncHarvestEfficiency.Set(persistent.HarvestMultiplier);
             }
             catch (Exception Scrap)
             {
                 SessionCore.LogError($"{Drill.CustomName}.Load()", Scrap);
             }
         }
         else
         {
             SessionCore.DebugWrite($"{Drill.CustomName}.Load()", "Storage access failed.");
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill.CustomName}.Load().AccessStorage", Scrap);
     }
 }
コード例 #10
0
 public override void Close()
 {
     try
     {
         if (SessionCore.Settings.Debug)
         {
             DebugNote.Hide();
             DebugNote.AliveTime = 0;
             DebugNote           = null;
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Close().DebugClose", Scrap);
     }
     try
     {
         HUDModule.Close();
         PersistenceModule.Close();
         TermModule.Close();
         GridInventoryModule.RemoveWatcher(Tool);
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Close()", Scrap);
     }
 }
コード例 #11
0
        public void Load()
        {
            try
            {
                if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
                {
                    ToolComp.TermModule.LoadSyncersFromServer();
                    return;
                }
                string Storage = "";

                if (Tool.Storage == null)
                {
                    SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Tool's Storage doesn't exist.");
                    ToolComp.TermModule.BeamLength = ToolComp.BeamCtlModule.MaxBeamLengthBlocks;
                    return;
                }

                if (!Tool.Storage.ContainsKey(SessionCore.StorageGuid))
                {
                    SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Tool's Storage is empty.");
                    ToolComp.TermModule.BeamLength = ToolComp.BeamCtlModule.MaxBeamLengthBlocks;
                    return;
                }

                if (Tool.Storage.TryGetValue(SessionCore.StorageGuid, out Storage) == true /* ||
                                                                                            * MyAPIGateway.Utilities.GetVariable($"settings_{Tool.EntityId}", out Storage)*/)
                {
                    try
                    {
                        SessionCore.DebugWrite($"{Tool.CustomName}.Load()", $"Accessing storage. Raw data: {Storage}");
                        PersistentStruct persistent = MyAPIGateway.Utilities.SerializeFromBinary <PersistentStruct>(Convert.FromBase64String(Storage));
                        ToolComp.TermModule.BeamLength = (int)persistent.BeamLength;
                        if (ToolComp.TermModule.BeamLength > ToolComp.BeamCtlModule.MaxBeamLengthBlocks)
                        {
                            ToolComp.TermModule.BeamLength = ToolComp.BeamCtlModule.MaxBeamLengthBlocks;
                        }
                        ToolComp.TermModule.DistanceMode    = persistent.DistanceBased;
                        ToolComp.TermModule.SpeedMultiplier = (int)persistent.SpeedMultiplier;
                        SessionCore.DebugWrite($"{Tool.CustomName}.Load()", $"Loaded from storage. Persistent Beamlength: {persistent.BeamLength}; Sync Beamlength: {ToolComp.TermModule.BeamLength}");
                    }
                    catch (Exception Scrap)
                    {
                        SessionCore.LogError($"{Tool.CustomName}.Load()", Scrap);
                    }
                }
                else
                {
                    ToolComp.TermModule.BeamLength = ToolComp.BeamCtlModule.MaxBeamLengthBlocks;
                    SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Storage access failed.");
                }
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"{Tool.CustomName}.Load().AccessStorage", Scrap);
            }
        }
コード例 #12
0
 public override void Init()
 {
     try
     {
         SessionCore.SaveRegister(Save);
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Persistence.Init()", Scrap);
     }
 }
コード例 #13
0
ファイル: Controls.cs プロジェクト: Gauge/LaserWelders
 public static bool HasDrillLogic(IMyTerminalBlock Block)
 {
     try
     {
         return(Block.HasComponent <LaserDrill>());
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError("IsOurBlock", Scrap);
         return(false);
     }
 }
コード例 #14
0
        void Main(int ticks = 0)
        {
            try
            {
                if (ticks == 0)
                {
                    ticks = SessionCore.WorkSkipTicks;
                }
                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                if (Tool.IsToolWorking())
                {
                    watch.Start();
                }
                try
                {
                    if (IsWelder && LocalPlayerIsOwner && HUDModule.MessageExpired)
                    {
                        MissingHUD.Hide();
                    }
                    PowerModule.SetPowerUsage();

                    if (Tool.IsToolWorking() && PowerModule.HasEnoughPower)
                    {
                        Work(ticks);
                        BeamCtlModule.DrawBeam();
                    }
                    else if (!PowerModule.HasEnoughPower)
                    {
                        DebugNote.Text = $"{Tool.CustomName}: not enough power";
                    }
                    else
                    {
                        DebugNote.Text = $"{Tool.CustomName}: idle";
                        //UnbuiltBlocks.Clear();
                    }
                    Tool.RefreshCustomInfo();
                    //if (SessionCore.Debug) DebugNote.Text = $"{Tool.CustomName} perf. impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 5).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 5).ToString() : "--")} ms (avg/max)";
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.Main().Work()", Scrap);
                }
                if (Tool.IsToolWorking())
                {
                    watch.Stop();
                    watch.Report(Tool.CustomName, "Main()");
                }
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"{Tool.CustomName}.Main()", Scrap);
            }
        }
コード例 #15
0
 public override void Close()
 {
     UnsubscribeFromEvents();
     try
     {
         //InventoryList.Close();
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Grid.CustomName}.GridInventory.Close().CloseSyncer", Scrap);
     }
 }
コード例 #16
0
 public void Save()
 {
     try
     {
         Persistent persistent;
         persistent.HarvestMultiplier = SyncHarvestEfficiency.Get();
         string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent));
         MyAPIGateway.Utilities.SetVariable($"settings_{Drill.EntityId}", Raw);
         Drill.Storage?.AddOrUpdate(SessionCore.StorageGuid, Raw);
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill.CustomName}.Save()", Scrap);
     }
 }
コード例 #17
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
     //Tool.ResourceSink.SetRequiredInputFuncByType(Electricity, () => PowerConsumptionFunc());
     try
     {
         if (!Drill.HasComponent <MyModStorageComponent>())
         {
             Drill.Storage = new MyModStorageComponent();
             Drill.Components.Add(Drill.Storage);
             SessionCore.DebugWrite($"{Drill.CustomName}.Init()", "Block doesn't have a Storage component!", IsExcessive: false);
         }
     }
     catch { }
 }
コード例 #18
0
 public static void Report(this System.Diagnostics.Stopwatch Watch, string Source, string WatchedProcessName, bool UseAsync = false)
 {
     if (!SessionCore.Settings.DebugPerformance)
     {
         return;
     }
     if (!UseAsync)
     {
         SessionCore.DebugWrite(Source, $"{WatchedProcessName} took {Math.Round(Watch.ElapsedTicks * 1000f / System.Diagnostics.Stopwatch.Frequency, 2)} ms to run", WriteOnlyIfDebug: true);
     }
     else
     {
         SessionCore.DebugAsync(Source, $"{WatchedProcessName} took {Math.Round(Watch.ElapsedTicks * 1000f / System.Diagnostics.Stopwatch.Frequency, 2)} ms to run", WriteOnlyIfDebug: true);
     }
 }
コード例 #19
0
ファイル: Controls.cs プロジェクト: Gauge/LaserWelders
 public static T BlockReturn <T>(IMyTerminalBlock Block, Func <LaserToolBase, T> Getter, T Default = default(T))
 {
     try
     {
         LaserToolBase Logic;
         if (!Block.TryGetComponent(out Logic))
         {
             return(Default);
         }
         return(Getter(Logic));
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError("BlockReturn", Scrap);
         return(Default);
     }
 }
コード例 #20
0
ファイル: Controls.cs プロジェクト: Gauge/LaserWelders
 public static void DrillAction(IMyTerminalBlock Block, Action <LaserDrill> Action)
 {
     try
     {
         LaserDrill Logic;
         if (!Block.TryGetComponent(out Logic))
         {
             return;
         }
         Action(Logic);
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError("BlockAction", Scrap);
         return;
     }
 }
コード例 #21
0
 public void Save()
 {
     try
     {
         Persistent persistent;
         persistent.BeamLength      = SyncBeamLength.Get();
         persistent.DistanceBased   = SyncDistanceMode.Get();
         persistent.SpeedMultiplier = SyncSpeedMultiplier.Get();
         string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent));
         MyAPIGateway.Utilities.SetVariable($"settings_{Tool.EntityId}", Raw);
         Tool.Storage?.AddOrUpdate(SessionCore.StorageGuid, Raw);
         SessionCore.DebugWrite($"{Tool.CustomName}.Load()", $"Set settings to storage. Saved beamlength: {persistent.BeamLength}");
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Save()", Scrap);
     }
 }
コード例 #22
0
ファイル: LaserWelder.cs プロジェクト: Gauge/LaserWelders
        void Place(IMySlimBlock Block)
        {
            if (!Block.IsProjectable())
            {
                return;
            }
            var FirstItem = ((MyCubeBlockDefinition)Block.BlockDefinition).Components[0].Definition.Id;

            if (MyAPIGateway.Session.CreativeMode || ToolCargo.PullAny(OnboardInventoryOwners, FirstItem.SubtypeName, 1))
            {
                var Projector = ((Block.CubeGrid as MyCubeGrid).Projector as IMyProjector);
                Projector.Build(Block, 0, Tool.EntityId, false);
                ToolCargo.RemoveItemsOfType(1, FirstItem);
            }
            else
            {
                UnbuiltBlocks.Add(Block);
                SessionCore.DebugWrite($"{Tool.CustomName}.Place()", $"Tool can't pull the component {FirstItem.SubtypeName}!", IsExcessive: false);
            }
        }
コード例 #23
0
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     NeedsUpdate      |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
     Tool              = Entity as IMyShipToolBase;
     TermModule        = new ToolTermCtl(this);
     BeamCtlModule     = new BeamController(this);
     PersistenceModule = new ToolPersistence(this);
     HUDModule         = new WelderHUDModule(this);
     PowerModule       = new ToolPowerModule(this);
     //Tool.ResourceSink.SetRequiredInputFuncByType(Electricity, () => PowerConsumptionFunc());
     try
     {
         if (!Tool.HasComponent <MyModStorageComponent>())
         {
             Tool.Storage = new MyModStorageComponent();
             Tool.Components.Add(Tool.Storage);
             SessionCore.DebugWrite($"{Tool.CustomName}.Init()", "Block doesn't have a Storage component!", IsExcessive: false);
         }
     }
     catch { }
 }
コード例 #24
0
 public void Load()
 {
     try
     {
         if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
         {
             SyncBeamLength.Ask();
             SyncDistanceMode.Ask();
             SyncSpeedMultiplier.Ask();
             return;
         }
         string Storage = "";
         //if (Tool.Storage.ContainsKey(SessionCore.StorageGuid))
         if (Tool.Storage?.TryGetValue(SessionCore.StorageGuid, out Storage) == true ||
             MyAPIGateway.Utilities.GetVariable($"settings_{Tool.EntityId}", out Storage))
         {
             try
             {
                 Persistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <Persistent>(Convert.FromBase64String(Storage));
                 SyncBeamLength.Set(persistent.BeamLength);
                 SyncDistanceMode.Set(persistent.DistanceBased);
                 SyncSpeedMultiplier.Set(persistent.SpeedMultiplier);
                 SessionCore.DebugWrite($"{Tool.CustomName}.Load()", $"Loaded from storage. Persistent Beamlength: {persistent.BeamLength}; Sync Beamlength: {SyncBeamLength.Get()}");
             }
             catch (Exception Scrap)
             {
                 SessionCore.LogError($"{Tool.CustomName}.Load()", Scrap);
             }
         }
         else
         {
             SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Storage access failed.");
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.Load().AccessStorage", Scrap);
     }
 }
コード例 #25
0
        public void Save()
        {
            if (Tool.Storage == null)
            {
                SessionCore.DebugWrite($"{Tool.CustomName}.Save()", "Tool's Storage doesn't exist.");
                return;
            }

            if (!Tool.Storage.ContainsKey(SessionCore.StorageGuid))
            {
                SessionCore.DebugWrite($"{Tool.CustomName}.Save()", "Tool's Storage is empty.");
                Tool.Storage[SessionCore.StorageGuid] = "";
            }

            try
            {
                PersistentStruct persistent;
                persistent.BeamLength      = ToolComp.TermModule.BeamLength;
                persistent.DistanceBased   = ToolComp.TermModule.DistanceMode;
                persistent.SpeedMultiplier = ToolComp.TermModule.SpeedMultiplier;
                string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent));
                //MyAPIGateway.Utilities.SetVariable($"settings_{Tool.EntityId}", Raw);
                if (!Tool.Storage.ContainsKey(SessionCore.StorageGuid))
                {
                    Tool.Storage.Add(SessionCore.StorageGuid, Raw);
                }
                else
                {
                    Tool.Storage[SessionCore.StorageGuid] = Raw;
                }
                SessionCore.DebugWrite($"{Tool.CustomName}.Save()", $"Saved to storage. Raw data: {Raw}");
                SessionCore.DebugWrite($"{Tool.CustomName}.Save()", $"Checked raw data: {Tool.Storage[SessionCore.StorageGuid]}");
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"{Tool.CustomName}.Save()", Scrap);
            }
        }
コード例 #26
0
 void Main(int ticks)
 {
     try
     {
         Tool.ResourceSink.SetRequiredInputByType(Electricity, PowerConsumptionFunc());
         if (Tool.IsToolWorking() && HasEnoughPower)
         {
             Work(ticks);
             DrawBeam();
         }
         else
         {
             DebugNote.Text = $"{Tool.CustomName}: idle";
             UnbuiltBlocks.Clear();
         }
         Tool.RefreshCustomInfo();
         //if (SessionCore.Debug) DebugNote.Text = $"{Tool.CustomName} perf. impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 5).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 5).ToString() : "--")} ms (avg/max)";
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError(Tool.CustomName, Scrap);
     }
 }
コード例 #27
0
        public override void UpdateOnceBeforeFrame()
        {
            try
            {
                if (Tool.CubeGrid.Physics?.Enabled != true || !Networker.Inited)
                {
                    NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                    if (!Networker.Inited)
                    {
                        Networker.Init(SessionCore.ModID);
                    }
                    return;
                }
                ToolCargo = Tool.GetInventory();

                SyncBeamLength      = new AutoSet <float>(Tool, "BeamLength", 1, Checker: val => val >= MinBeamLengthBlocks && val <= MaxBeamLengthBlocks);
                SyncDistanceMode    = new AutoSet <bool>(Tool, "DistanceBasedMode");
                SyncSpeedMultiplier = new AutoSet <float>(Tool, "SpeedMultiplier", 1, Checker: val => val >= 1 && val <= 4);
                SyncBeamLength.GotValueFromServer      += Tool.UpdateVisual;
                SyncDistanceMode.GotValueFromServer    += Tool.UpdateVisual;
                SyncSpeedMultiplier.GotValueFromServer += Tool.UpdateVisual;

                CheckInitControls();
                Load();

                Tool.AppendingCustomInfo += Tool_AppendingCustomInfo;
                SessionCore.SaveRegister(Save);
                NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
                DebugNote    = MyAPIGateway.Utilities.CreateNotification($"{Tool.CustomName}", int.MaxValue, (IsWelder ? "Blue" : "Red"));
                Owner        = MyAPIGateway.Players.GetPlayer(Tool.OwnerId);
                if (SessionCore.Debug)
                {
                    DebugNote.Show();
                }
            }
            catch { }
        }
コード例 #28
0
        void CheckInitControls()
        {
            string Message = "Attention! Due to a bug in the game itself, you might not be able to work with these tools via mouse-click.\nIf you run into this issue, you have to use the Toggle switch in terminal or on/off switch on toolbar.\nSorry for inconvenience.";

            if (IsWelder)
            {
                if (!SessionCore.InitedWelderControls)
                {
                    SessionCore.InitWelderControls();
                    MyAPIGateway.Utilities.ShowMessage("Laser Welders", Message);
                }
            }
            else if (IsGrinder)
            {
                if (!SessionCore.InitedGrinderControls)
                {
                    SessionCore.InitGrinderControls();
                    MyAPIGateway.Utilities.ShowMessage("Laser Grinders", Message);
                }
            }
            else if (IsDrill)
            {
            }
        }
コード例 #29
0
ファイル: WelderHUD.cs プロジェクト: Cheetah97/LaserWelders
 public override void Init()
 {
     try
     {
         if (ToolComp.Tool == null)
         {
             throw new Exception("ToolComp.Tool is null");
         }
         MissingText      = new Syncer <string>(Tool, "Missing", "");
         HUDMessageUpdate = DateTime.Now - TimeSpan.FromSeconds(10);
         try
         {
             MissingText.GotValueFromServer += ComplainMissingLocal;
         }
         catch (Exception Scrap)
         {
             SessionCore.LogError($"{Tool.CustomName}.HudModule.Init().Subscribe", Scrap);
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Tool.CustomName}.HudModule.Init().New", Scrap);
     }
 }
コード例 #30
0
        public override void UpdateOnceBeforeFrame()
        {
            try
            {
                if (!Networker.Inited)
                {
                    Networker.Init(SessionCore.ModID);
                }
                try
                {
                    if (Tool.CubeGrid.Physics?.Enabled != true)
                    {
                        NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                        return;
                    }
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().PhysicsCheck", Scrap);
                }


                try
                {
                    ToolCargo = Tool.GetInventory();
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().GetInventory", Scrap);
                }

                try
                {
                    TermModule.Init();
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().TermModuleInit", Scrap);
                }

                try
                {
                    PersistenceModule.Init();
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().PersistenceModuleInit", Scrap);
                }

                try
                {
                    PersistenceModule.Load();
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().PersistenceModuleLoad", Scrap);
                }

                try
                {
                    GridInventoryModule = ToolGrid.GetComponent <GridInventories>();
                    if (IsWelder)
                    {
                        GridInventoryModule.AddWatcher(Tool);
                    }
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().InventoryModule", Scrap);
                }

                try
                {
                    HUDModule.Init();
                }
                catch (Exception Scrap)
                {
                    SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame().HudModule", Scrap);
                }

                if (IsWelder && MyAPIGateway.Session.LocalHumanPlayer?.IdentityId == Tool.OwnerId)
                {
                    MissingHUD = MyAPIGateway.Utilities.CreateNotification("", int.MaxValue, "Red");
                }

                CheckInitControls();
                NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
                Tool.AppendingCustomInfo += Tool_AppendingCustomInfo;
                DebugNote = MyAPIGateway.Utilities.CreateNotification($"{Tool.CustomName}", int.MaxValue, (IsWelder ? "Blue" : "Red"));
                Owner     = MyAPIGateway.Players.GetPlayer(Tool.OwnerId);
                if (SessionCore.Settings.Debug)
                {
                    DebugNote.Show();
                }
            }
            catch (Exception Scrap)
            {
                SessionCore.LogError($"{Tool.CustomName}.OnceBeforeFrame()", Scrap);
            }
        }