Ejemplo n.º 1
0
        public override void Execute(List <string> parameters, CommandSenderInfo senderInfo)
        {
            TelemetryTools.CollectEvent("command", "execute", GetCommands()[0]);
            try
            {
                ParseParams(parameters, out var tasks, out bool simulate, out bool auto, out int?timerInterval);
                timerInterval = timerInterval ?? 60 * 10; // every 10 minutes by default

                if (auto)
                {
                    if (!PersistentData.Instance.RepairAuto)
                    {
                        PersistentData.Instance.RepairAuto     = true;
                        PersistentData.Instance.RepairTasks    = tasks;
                        PersistentData.Instance.RepairSimulate = simulate;
                        PersistentData.Instance.RepairInterval = timerInterval.Value; // every 10 minutes by default;
                        PersistentData.Instance.Save();
                        RepairEngine.AutoOn();
                    }
                    else
                    {
                        RepairEngine.AutoOff();
                        PersistentData.Instance.RepairAuto    = false;
                        PersistentData.Instance.RepairCounter = 0;
                        PersistentData.Instance.Save();
                    }
                }
                else
                {
                    ThreadManager.AddSingleTask(delegate
                    {
                        try
                        {
                            var repairEngine = new RepairEngine(tasks, simulate, senderInfo);
                            repairEngine.Start();
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                            SdtdConsole.Instance.OutputAsync(senderInfo, string.Format(Resources.ErrorDuringCommand, ex.Message));
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                CommandTools.HandleCommandException(ex);
            }
        }
Ejemplo n.º 2
0
        private static void SaveTileEntities(string prefabName, Vector3i pos1, Vector3i pos2)
        {
            Dictionary <Vector3i, TileEntity> tileEntities = CollectTileEntities(pos1, pos2);

            var filePath = Path.Combine(Constants.PrefabsFolder, prefabName + TileEntityFileExtension);

            // Save all tile entities
            using (var writer = new BinaryWriter(new FileStream(filePath, FileMode.Create)))
            {
                writer.Write(TileEntityFileMarker);                                   // [string]   constant "7DTD-TE"
                writer.Write(TileEntityFileVersion);                                  // [Int32]    file version number
                NetworkUtils.Write(writer, pos1);                                     // [Vector3i] original area worldPos1
                NetworkUtils.Write(writer, pos2);                                     // [Vector3i] original area worldPos2

                // see Assembly-CSharp::Chunk.write() -> search "tileentity.write"
                writer.Write(tileEntities.Count);                                     // [Int32]    number of tile entities
                foreach (var keyValue in tileEntities)
                {
                    var posInWorld  = keyValue.Key;
                    var tileEntity  = keyValue.Value;
                    var posInPrefab = posInWorld - pos1;

                    NetworkUtils.Write(writer, posInPrefab);                          // [3xInt32]  position relative to prefab
                    writer.Write((byte)tileEntity.GetTileEntityType());               // [byte]     TileEntityType enum
                    tileEntity.write(writer, TileEntity.StreamModeWrite.Persistency); // [dynamic]  tile entity data depending on type
                    Log.Debug($"Wrote tile entity {tileEntity}.");

                    var tileEntityPowered = tileEntity as TileEntityPowered;
                    if (tileEntityPowered != null)
                    {
                        if (!RepairEngine.IsValidTileEntityPowered(tileEntityPowered))
                        {
                            throw new FriendlyMessageException("The area contains a corrupt power block. Please fix it first with the \"dj-repair\" command.");
                        }

                        var powerItem = tileEntityPowered.GetPowerItem()
                                        ?? PowerItem.CreateItem(tileEntityPowered.PowerItemType);
                        SavePowerItem(writer, powerItem);                             // [dynamic]  PowerItem data
                    }
                }
            }

            Log.Out($"Exported {tileEntities.Count} tile entities for prefab {prefabName} from area {pos1} to {pos2}.");
        }
Ejemplo n.º 3
0
 public Workshop()
 {
     ChangeColor  = new ChangeColor();
     RepairEngine = new RepairEngine();
     ChangeOil    = new ChangeOil();
 }