public async Task CreateStructureAsync(string aEBPFile, PlayfieldGlobalStructureInfo aStructure) { var NewID = await Request_NewEntityId(); aStructure.Type = GetStructureInfo(aEBPFile); var SpawnInfo = new EntitySpawnInfo() { forceEntityId = NewID.id, playfield = aStructure.Playfield, pos = aStructure.Pos, rot = aStructure.Rot, name = $"EBP:{Path.GetFileNameWithoutExtension(aStructure.Name)}", type = (byte)Array.IndexOf(new[] { "Undef", "", "BA", "CV", "SV", "HV", "", "AstVoxel" }, aStructure.Type), // Entity.GetFromEntityType 'Kommentare der Devs: Set this Undef = 0, BA = 2, CV = 3, SV = 4, HV = 5, AstVoxel = 7 entityTypeName = "", // 'Kommentare der Devs: ...or set this to f.e. 'ZiraxMale', 'AlienCivilian1Fat', etc prefabName = Path.GetFileNameWithoutExtension(aEBPFile), prefabDir = Path.GetDirectoryName(aEBPFile), factionGroup = 0, factionId = 0, // erstmal auf "public" aStructure.Faction, }; try { await Request_Load_Playfield(new PlayfieldLoad(20, aStructure.Playfield, 0)); } catch { } // Playfield already loaded try { await Request_Entity_Spawn(SpawnInfo); await Request_Structure_Touch(NewID); // Sonst wird die Struktur sofort wieder gelöscht !!! } finally { try { File.Delete(aEBPFile); } catch { } } }
public async Task CreateStructure(string aSelectBackupDir, PlayfieldGlobalStructureInfo aStructure) { var NewID = await Request_NewEntityId(); var SourceDir = Path.Combine(BackupDir, aSelectBackupDir == CurrentSaveGame ? EmpyrionConfiguration.ProgramPath : aSelectBackupDir, @"Saves\Games", Path.GetFileName(EmpyrionConfiguration.SaveGamePath), "Shared", aStructure.structureName); var sourceExportDat = Path.Combine(SourceDir, "Export.dat"); var TargetDir = Path.Combine(EmpyrionConfiguration.SaveGamePath, "Shared", $"{NewID.id}"); var SpawnInfo = new EntitySpawnInfo() { forceEntityId = NewID.id, playfield = aStructure.Playfield, pos = aStructure.Pos, rot = aStructure.Rot, name = aStructure.Name, type = (byte)Array.IndexOf(new[] { "Undef", "", "BA", "CV", "SV", "HV", "", "AstVoxel" }, aStructure.Type), // Entity.GetFromEntityType 'Kommentare der Devs: Set this Undef = 0, BA = 2, CV = 3, SV = 4, HV = 5, AstVoxel = 7 entityTypeName = "", // 'Kommentare der Devs: ...or set this to f.e. 'ZiraxMale', 'AlienCivilian1Fat', etc prefabName = $"{aStructure.Type}_Player", factionGroup = 0, factionId = 0, // erstmal auf "public" aStructure.Faction, exportedEntityDat = File.Exists(sourceExportDat) ? sourceExportDat : null }; Directory.CreateDirectory(Path.GetDirectoryName(TargetDir)); CopyAll(new DirectoryInfo(SourceDir), new DirectoryInfo(TargetDir)); try { await Request_Load_Playfield(new PlayfieldLoad(20, aStructure.Playfield, 0)); } catch { } // Playfield already loaded await Request_Entity_Spawn(SpawnInfo); for (int i = 0; i < 10; i++) { try { await Request_Structure_Touch(NewID); // Sonst wird die Struktur sofort wieder gelöscht !!! break; } catch { await Task.Delay(5000); } } }
public IActionResult CreateStructure([FromBody] PlayfieldGlobalStructureInfo aData) { StructureManager.CreateStructureAsync(StructureManager.CurrentEBPFile, aData).Wait(); return(Ok()); }
public static PlayfieldGlobalStructureInfo GenerateGlobalStructureInfo(string aInfoTxtFile) { var Info = new PlayfieldGlobalStructureInfo(); Info.structureName = Path.GetFileNameWithoutExtension(aInfoTxtFile); try { var Lines = System.IO.File.ReadAllLines(aInfoTxtFile); var FirstLine = Lines.FirstOrDefault(); var LastLine = Lines.LastOrDefault(); if (FirstLine == null || LastLine == null) { return(Info); } var FieldNames = FirstLine.Split(','); var FieldValues = LastLine.Split(',').ToList(); var posField = Array.FindIndex(FieldNames, N => N == "pos"); if (FieldValues.Count > 22) { var startPos = 0; for (int i = 0; i <= posField; i++) { startPos = LastLine.IndexOf(',', startPos + 1); } var endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, startPos); if (LastLine[endPos] == ',') { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, endPos + 1); if (LastLine[endPos] == ',') { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, endPos + 1); if (LastLine[endPos] == ',') { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } } var rotField = Array.FindIndex(FieldNames, N => N == "rot"); if (FieldValues.Count > 22) { var startPos = 0; for (int i = 0; i <= rotField; i++) { startPos = LastLine.IndexOf(',', startPos + 1); } var endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, startPos); if (LastLine[endPos] == ',' && Char.IsDigit(LastLine[endPos + 1])) { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, endPos + 1); if (LastLine[endPos] == ',' && Char.IsDigit(LastLine[endPos + 1])) { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } endPos = LastLine.IndexOfAny(new[] { ',', ' ' }, endPos + 1); if (LastLine[endPos] == ',' && Char.IsDigit(LastLine[endPos + 1])) { LastLine = LastLine.Substring(0, endPos) + '.' + LastLine.Substring(endPos + 1); endPos = LastLine.IndexOf(' ', endPos) + 1; } } FieldValues = LastLine.Split(',').ToList(); string StringValue(string N) { var pos = Array.IndexOf(FieldNames, N); return(pos == -1 ? null : FieldValues[pos]); } int IntValue(string N) { var pos = Array.IndexOf(FieldNames, N); return(pos == -1 ? 0 : ToIntOrZero(FieldValues[pos])); } bool BoolValue(string N) { var pos = Array.IndexOf(FieldNames, N); return(pos != -1 && bool.TryParse(FieldValues[pos], out bool Result) && Result); } PVector3 PVector3Value(string N) { var pos = Array.IndexOf(FieldNames, N); return(pos == -1 ? new PVector3() : GetPVector3(FieldValues[pos])); } DateTime DateTimeValue(string N) { var pos = Array.IndexOf(FieldNames, N); return(pos != -1 && DateTime.TryParseExact(FieldValues[pos], "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime Result) ? Result : DateTime.MinValue); } Info.Playfield = StringValue("playfield"); Info.Id = IntValue("id"); Info.Name = StringValue("name")?.Trim('\''); Info.Type = StringValue("type"); var faction = StringValue("faction")?.Trim(); Info.Faction = ToIntOrZero(faction?.Replace("]", "").Substring(faction.IndexOf(' ') + 1).Trim()); Info.Blocks = IntValue("blocks"); Info.Devices = IntValue("devices"); Info.Touched_ticks = IntValue("touched_ticks"); Info.Touched_id = IntValue("touched_id"); Info.Saved_ticks = IntValue("saved_ticks"); Info.Docked = BoolValue("docked"); Info.Powered = BoolValue("powered"); Info.Core = BoolValue("core"); Info.Pos = PVector3Value("pos"); Info.Rot = PVector3Value("rot"); Info.Saved_time = DateTimeValue("saved_time"); Info.Touched_time = DateTimeValue("touched_time"); Info.Touched_name = StringValue("touched_name")?.Trim('\''); Info.Add_info = $"{StringValue("add_info")} {faction}"; } catch (Exception) { } return(Info); }