public IActionResult GlobalStructureList() { if (UserService.CurrentUser.Role == Role.VIP) { var Result = new GlobalStructureList() { globalStructures = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.List <GlobalStructureInfo> >() }; var CurrentPlayer = PlayerManager.CurrentPlayer; if (CurrentPlayer == null) { return(Ok()); } StructureManager.GlobalStructureList().globalStructures .ForEach(P => { var L = P.Value.Where(S => (S.factionGroup == (byte)Factions.Faction && S.factionId == CurrentPlayer.FactionId) || (S.factionGroup == (byte)Factions.Private && S.factionId == CurrentPlayer.EntityId) ).ToList(); if (L.Count > 0) { Result.globalStructures.Add(P.Key, L); } }); return(Ok(Result)); } return(Ok(StructureManager.GlobalStructureList())); }
public void AddPassenderDestination(GlobalStructureList aGlobalStructureList, int aVesselId, PlayerInfo aPlayer) { var FoundEntity = SearchEntity(aGlobalStructureList, aVesselId); if (FoundEntity == null) { return; } var RelativePos = GetVector3(aPlayer.pos) - GetVector3(FoundEntity.Data.pos); var NormRot = GetVector3(aPlayer.rot) - GetVector3(FoundEntity.Data.rot); var EntityRot = GetMatrix4x4(GetVector3(FoundEntity.Data.rot)).Transpose(); RelativePos = Vector3.Transform(RelativePos, EntityRot); RelativePos = new Vector3(RelativePos.X, ((float)Math.Round(RelativePos.Y + 1.9) - 1), RelativePos.Z); var Target = Configuration.Current.PassengersDestinations.FirstOrDefault(P => P.PassengerId == aPlayer.entityId); if (Target == null) { Configuration.Current.PassengersDestinations.Add(Target = new TeleporterRoute()); } Target.PassengerId = aPlayer.entityId; Target.PassengerName = aPlayer.playerName; Target.Destination = new TeleporterData() { Id = aVesselId, Position = RelativePos, Rotation = NormRot }; Configuration.Current.PassengersDestinations = Configuration.Current.PassengersDestinations.OrderBy(T => T.PassengerName).ToList(); }
public string ToString(GlobalStructureList G) { var Sa = SearchEntity(G, Destination.Id); return($"[c][ff0000]{PassengerName}/{PassengerId}[-][/c]: " + (Sa == null ? Destination.ToString() : $"[c][ff00ff]{Sa.Data.name}[-][/c] [[c][ffffff]{Sa.Data.id}[-][/c]/[c][ffffff]{Sa.Playfield}[-][/c]]")); }
public void Game_Event(CmdId eventId, ushort seqNr, object data) { broker.HandleMessage(eventId, seqNr, data); if (settlementOperations.ContainsKey(seqNr)) { var op = settlementOperations[seqNr]; HandleSettlementWokflowEvent(GameAPI, op, eventId, data); } GameAPI.Console_Write($"ID:EVENT! {eventId} - {seqNr}"); try { switch (eventId) { case CmdId.Event_Playfield_Stats: var playfieldData = (PlayfieldStats)data; var pstatstring = $"id: {Serializer.Serialize(playfieldData)}"; GameAPI.Console_Write(pstatstring); break; case CmdId.Event_Player_Connected: GameAPI.Game_Request(CmdId.Request_Player_Info, (ushort)CmdId.Request_Player_Info, (Id)data); break; case CmdId.Event_Statistics: StatisticsParam stats = (StatisticsParam)data; Handle_event_statistics(stats); break; case CmdId.Event_ChatMessage: ChatInfo ci = (ChatInfo)data; Handle_chat_message(ci); break; case CmdId.Event_GlobalStructure_List: GlobalStructureList info = (GlobalStructureList)data; writeGlobalStructureList(info); break; default: GameAPI.Console_Write($"event: {eventId}"); var outmessage = "NO DATA"; if (data != null) { outmessage = "data: " + data.ToString(); } GameAPI.Console_Write(outmessage); break; } } catch (Exception ex) { GameAPI.Console_Write(ex.Message); GameAPI.Console_Write(ex.ToString()); } }
public TeleporterTargetData SearchRoute(GlobalStructureList aGlobalStructureList, PlayerInfo aPlayer) { //log($"T:{TeleporterRoutes.Aggregate("", (s, t) => s + " " + t.ToString())} => {aGlobalStructureList.globalStructures.Aggregate("", (s, p) => s + p.Key + ":" + p.Value.Aggregate("", (ss, pp) => ss + " " + pp.id + "/" + pp.name))}"); return(Configuration.Current.PassengersDestinations .Where(D => D.PassengerId == aPlayer.entityId) .Select(I => GetCurrentTeleportTargetPosition(aGlobalStructureList, I.Destination)) .FirstOrDefault()); }
public string ToString(GlobalStructureList G) { var Sa = SearchEntity(G, A.Id); var Sb = SearchEntity(G, B.Id); return($"[c][ff0000]{Permission}{(PermissionId == 0 ? "" : $"[PermissionId]")}[-][/c]: " + (Sa == null ? A.ToString() : $"[c][ff00ff]{Sa.Data.name}[-][/c] [[c][ffffff]{Sa.Data.id}[-][/c]/[c][ffffff]{Sa.Playfield}[-][/c]]") + " <=> " + (Sb == null ? B.ToString() : $"[c][ff00ff]{Sb.Data.name}[-][/c] [[c][ffffff]{Sb.Data.id}[-][/c]/[c][ffffff]{Sb.Playfield}[-][/c]]")); }
public static GlobalStructureInfo SearchEntity(GlobalStructureList aGlobalStructureList, int aSourceId) { foreach (var TestPlayfieldEntites in aGlobalStructureList.globalStructures) { var FoundEntity = TestPlayfieldEntites.Value.FirstOrDefault(E => E.id == aSourceId); if (FoundEntity.id != 0) { return(FoundEntity); } } return(new GlobalStructureInfo()); }
private void writeGlobalStructureList(GlobalStructureList data) { foreach (var kvp in data.globalStructures) { foreach (var y in kvp.Value) { string message = $"playfield: {kvp.Key}; struct: ${Serializer.Serialize(y)}"; GameAPI.Console_Write(message); AlertMessage("sending to log"); } } }
public void AddRoute(GlobalStructureList aGlobalStructureList, TeleporterPermission aPermission, int aSourceId, int aTargetId, PlayerInfo aPlayer) { var FoundEntity = SearchEntity(aGlobalStructureList, aSourceId); if (FoundEntity == null) { return; } var FoundRoute = TeleporterRoutes.FirstOrDefault(R => R.Permission == aPermission && IsPermissionGranted(R, aPlayer) && ((R.A.Id == aSourceId && R.B.Id == aTargetId) || (R.B.Id == aSourceId && R.A.Id == aTargetId))); var RelativePos = GetVector3(aPlayer.pos) - GetVector3(FoundEntity.Data.pos); var NormRot = GetVector3(aPlayer.rot) - GetVector3(FoundEntity.Data.rot); var EntityRot = GetMatrix4x4(GetVector3(FoundEntity.Data.rot)).Transpose(); RelativePos = Vector3.Transform(RelativePos, EntityRot); RelativePos = new Vector3(RelativePos.X, ((float)Math.Round(RelativePos.Y + 1.9) - 1), RelativePos.Z); if (FoundRoute == null) { TeleporterRoutes.Add(FoundRoute = new TeleporterRoute() { Permission = aPermission, PermissionId = aPermission == TeleporterPermission.PublicAccess ? 0 : aPermission == TeleporterPermission.FactionAccess ? aPlayer.factionId : aPermission == TeleporterPermission.PrivateAccess ? aPlayer.entityId : 0, A = new TeleporterData() { Id = aSourceId, Position = RelativePos, Rotation = NormRot }, B = new TeleporterData() { Id = aTargetId } }); TeleporterRoutes = TeleporterRoutes.OrderBy(T => T.Permission).ToList(); } else if (FoundRoute.A.Id == aSourceId && FoundRoute.B.Id == aTargetId) { FoundRoute.Permission = aPermission; FoundRoute.A.Position = RelativePos; FoundRoute.A.Rotation = NormRot; } else if (FoundRoute.A.Id == aTargetId && FoundRoute.B.Id == aSourceId) { FoundRoute.Permission = aPermission; FoundRoute.B.Position = RelativePos; FoundRoute.B.Rotation = NormRot; } }
public static PlayfieldStructureInfo SearchEntity(GlobalStructureList aGlobalStructureList, int aSourceId) { foreach (var TestPlayfieldEntites in aGlobalStructureList.globalStructures) { var FoundEntity = TestPlayfieldEntites.Value.FirstOrDefault(E => E.id == aSourceId); if (FoundEntity.id != 0) { return new PlayfieldStructureInfo() { Playfield = TestPlayfieldEntites.Key, Data = FoundEntity } } ; } return(null); }
public TeleporterTargetData SearchRoute(GlobalStructureList aGlobalStructureList, PlayerInfo aPlayer) { //log($"T:{TeleporterRoutes.Aggregate("", (s, t) => s + " " + t.ToString())} => {aGlobalStructureList.globalStructures.Aggregate("", (s, p) => s + p.Key + ":" + p.Value.Aggregate("", (ss, pp) => ss + " " + pp.id + "/" + pp.name))}"); foreach (var I in TeleporterRoutes.Where(T => T.B.Position != Vector3.Zero && IsPermissionGranted(T, aPlayer))) { if (IsNearPos(aGlobalStructureList, I.A, aPlayer.pos)) { return(GetCurrentTeleportTargetPosition(aGlobalStructureList, I.B)); } if (IsNearPos(aGlobalStructureList, I.B, aPlayer.pos)) { return(GetCurrentTeleportTargetPosition(aGlobalStructureList, I.A)); } } return(null); }
private void ProcessEvent_GlobalStructure_List(GlobalStructureList obj) { // from Request_GlobalStructure_List // and Request_GlobalStructure_Update ? DebugLog("Event_GlobalStructure_List - Global structures. Count: {0}", obj.globalStructures != null ? obj.globalStructures.Count : 0); //if (obj.globalStructures != null) //{ // foreach (KeyValuePair<string, List<Eleon.Modding.GlobalStructureInfo>> kvp in obj.globalStructures) // { // DebugLog("Playfield {0}", kvp.Key); // foreach (Eleon.Modding.GlobalStructureInfo g in kvp.Value) // { // DebugLog(" id={0} name={1} type={2} #blocks={3} #devices={4} playfield={5} pos={6}/{7}/{8}", g.id, g.name, g.type, g.cntBlocks, g.cntDevices, kvp.Key, g.pos.x, g.pos.y, g.pos.z); // } // } //} }
private async Task CheckPlayfields() { try { var playfields = (await Request_Playfield_List()).playfields; GlobalStructureList GSL = null; playfields? .Where(P => Configuration.Current.PoiData.ContainsKey(P)) .ToList() .ForEach(async P => { CheckPoiPositions(P, GSL ?? (GSL = await Request_GlobalStructure_List())); }); } catch (Exception error) { Log($"**EmpyrionPoiRestore CheckPlayfields Error: {error}", LogLevel.Error); } }
public void TestTeleportDB() { var G = new GlobalStructureList() { globalStructures = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.List <GlobalStructureInfo> >() }; G.globalStructures.Add("Akua", (new GlobalStructureInfo[] { new GlobalStructureInfo() { factionId = 1, id = 4004, pos = new PVector3(-182.306f, 71.67924f, 233.075f), rot = new PVector3(0, 4.48f, 0) }, new GlobalStructureInfo() { factionId = 1, id = 4005, pos = new PVector3(-1082.306f, 71.67924f, 2033.075f), rot = new PVector3(0, 34.48f, 0) }, }).ToList()); var P = new PlayerInfo() { factionId = 1, playfield = "Akua", pos = new PVector3(-1082.451f, 77.67921f, 2034.332f) }; var P2 = new PlayerInfo() { factionId = 1, playfield = "Akua", pos = new PVector3(-182.451f, 77.67921f, 234.332f) }; TeleporterDB db = new TeleporterDB(); db.AddRoute(G, TeleporterPermission.PublicAccess, 4005, 4004, P); db.AddRoute(G, TeleporterPermission.PublicAccess, 4004, 4005, P2); db.SaveDB("./TeleportDB.xml"); var Found = db.SearchRoute(G, P); Assert.IsNotNull(Found); Assert.IsTrue(Found.Id != 0); var Test = TeleporterDB.ReadDB("./TeleportDB.xml"); Assert.AreEqual(1, Test.TeleporterRoutes.Count); }
bool IsNearPos(GlobalStructureList aGlobalStructureList, TeleporterData aTarget, PVector3 aTestPos) { var StructureInfo = SearchEntity(aGlobalStructureList, aTarget.Id); if (StructureInfo == null) { log($"TargetStructure missing:{aTarget.Id} pos={aTarget.Position.String()}", LogLevel.Error); return(false); } var StructureRotation = GetMatrix4x4(GetVector3(StructureInfo.Data.rot)); var TeleporterPos = Vector3.Transform(aTarget.Position, StructureRotation) + GetVector3(StructureInfo.Data.pos); var Distance = Math.Abs(Vector3.Distance(TeleporterPos, GetVector3(aTestPos))); log($"FoundTarget:{StructureInfo.Data.id}/{StructureInfo.Data.type} pos={StructureInfo.Data.pos.String()} TeleportPos={TeleporterPos.String()} TEST {aTestPos.String()} => {Distance}", LogLevel.Message); return(Distance < 4); }
TeleporterTargetData GetCurrentTeleportTargetPosition(GlobalStructureList aGlobalStructureList, TeleporterData aTarget) { var StructureInfo = SearchEntity(aGlobalStructureList, aTarget.Id); if (StructureInfo == null) { log($"TargetStructure missing:{aTarget.Id} pos={aTarget.Position.String()}", LogLevel.Error); return(null); } var StructureInfoRot = GetVector3(StructureInfo.Data.rot); var StructureRotation = GetMatrix4x4(StructureInfoRot); var TeleportTargetPos = Vector3.Transform(aTarget.Position, StructureRotation) + GetVector3(StructureInfo.Data.pos); log($"CurrentTeleportTargetPosition:{StructureInfo.Data.id}/{StructureInfo.Data.type} pos={StructureInfo.Data.pos.String()} TeleportPos={TeleportTargetPos.String()}", LogLevel.Message); return(new TeleporterTargetData() { Id = aTarget.Id, Playfield = StructureInfo.Playfield, Position = TeleportTargetPos, Rotation = aTarget.Rotation + StructureInfoRot }); }
void HandleGlobalStructureList(GlobalStructureList gsl) { if (gsl == null) { return; } foreach (KeyValuePair <string, List <GlobalStructureInfo> > pfstructs in gsl.globalStructures) { mGameAPI.Console_Write("GSL for " + pfstructs.Key); foreach (GlobalStructureInfo gsi in pfstructs.Value) { if (gsi.coreType == 1) //player core { mGameAPI.Console_Write("Player Structure: " + gsi.name + ", ID: " + gsi.id); mGameAPI.Console_Write("Powered: " + gsi.powered); mGameAPI.Console_Write("Fuel Remaining: " + gsi.fuel); mGameAPI.Game_Request(CmdId.Request_Structure_BlockStatistics, (ushort)0, new Id(gsi.id)); } } } }
private void CheckPoiPositions(string playfield, GlobalStructureList gsl) { if (!Configuration.Current.PoiData.TryGetValue(playfield, out var pois)) { return; } if (!gsl.globalStructures.TryGetValue(playfield, out var gsi)) { return; } bool saveConfig = false; pois.ForEach(S => { var currentPositions = gsi.Where(G => G.name == S.Name).Select(G => new { G, Pos = Vector(G.pos), Rot = Vector(G.rot) }).ToList(); if (S.Positions == null) { S.Positions = currentPositions.Select(G => new PoiPosition() { Pos = G.Pos, Rot = G.Rot }).ToList(); saveConfig = true; } else { var changePos = new List <GlobalStructureInfo>(); var checkPos = S.Positions.ToList(); currentPositions.ForEach(G => { var found = checkPos.FirstOrDefault(C => C.Pos == G.Pos && C.Rot == G.Rot); if (found != null) { checkPos.Remove(found); } else { changePos.Add(G.G); } }); changePos.ForEach( G => { var setPos = checkPos.FirstOrDefault(); if (setPos != null) { checkPos.Remove(setPos); try { Request_Entity_Teleport(new IdPositionRotation(G.id, new PVector3(setPos.Pos.X, setPos.Pos.Y, setPos.Pos.Z), new PVector3(setPos.Rot.X, setPos.Rot.Y, setPos.Rot.Z))) .Wait(2000); } catch (Exception error) { Log($"EntityMove failed: {G.id} '{G.name}' Pos:{setPos.Pos} Rot:{setPos.Rot} => {error}", LogLevel.Debug); } } }); } }); if (saveConfig) { Configuration.Save(); } }
private SettlementOperation updateOperationFromStructureList(SettlementOperation operation, GlobalStructureList globalStructureList) { foreach (var kvp in globalStructureList.globalStructures) { var structureList = kvp.Value; var applicableStructure = structureList.FirstOrDefault(x => x.id == operation.originalStructureId); if (object.Equals(applicableStructure, default(GlobalStructureInfo))) { continue; } operation.playfieldName = kvp.Key; operation.originalStructureInfo = applicableStructure; operation.originalStructureName = applicableStructure.name; if (!operation.originalStructureName.Contains("Infested")) { operation.stage = SettlementStage.SettlementInvalidated; return(operation); } operation.newStructureName = operation.originalStructureName.Replace("Infested", "Settled"); operation.stage = SettlementStage.IdentifiedReplacement; return(operation); } return(operation); }
private async Task <bool> ExecTeleportPlayer(GlobalStructureList aGlobalStructureList, PlayerInfo aPlayer, int aPlayerId) { var FoundDestination = PassengersDB.SearchRoute(aGlobalStructureList, aPlayer); if (FoundDestination == null) { Log($"EmpyrionPassenger: Exec: {aPlayer.playerName}/{aPlayer.entityId}/{aPlayer.clientId} -> no logout vessel found for", LogLevel.Message); return(false); } if (Math.Abs(Vector3.Distance(FoundDestination.Position, GetVector3(aPlayer.pos))) <= PassengersDB.Configuration.Current.NoTeleportNearVesselDistance) { Log($"EmpyrionPassenger: Exec: {aPlayer.playerName}/{aPlayer.entityId}/{aPlayer.clientId} -> near logout vessel pos={GetVector3(aPlayer.pos).String()} on '{aPlayer.playfield}'", LogLevel.Message); PassengersDB.DeletePassenger(aPlayer.entityId); PassengersDB.Configuration.Save(); return(false); } Log($"EmpyrionPassenger: Exec: {aPlayer.playerName}/{aPlayer.entityId}-> {FoundDestination.Id} on '{FoundDestination.Playfield}' pos={FoundDestination.Position.String()} rot={FoundDestination.Rotation.String()}", LogLevel.Message); if (!PlayerLastGoodPosition.ContainsKey(aPlayer.entityId)) { PlayerLastGoodPosition.Add(aPlayer.entityId, null); } PlayerLastGoodPosition[aPlayer.entityId] = new IdPlayfieldPositionRotation(aPlayer.entityId, aPlayer.playfield, aPlayer.pos, aPlayer.rot); Action <PlayerInfo> ActionTeleportPlayer = async(P) => { if (FoundDestination.Playfield == P.playfield) { try { await Request_Entity_Teleport(new IdPositionRotation(aPlayer.entityId, GetVector3(FoundDestination.Position), GetVector3(FoundDestination.Rotation))); } catch (Exception error) { InformPlayer(aPlayerId, $"Entity_Teleport: {error.Message}"); } } else { try { await Request_Player_ChangePlayerfield(new IdPlayfieldPositionRotation(aPlayer.entityId, FoundDestination.Playfield, GetVector3(FoundDestination.Position), GetVector3(FoundDestination.Rotation))); } catch (Exception error) { InformPlayer(aPlayerId, $"Player_ChangePlayerfield: {error.Message}"); } } }; try { await Request_Player_SetPlayerInfo(new PlayerInfoSet() { entityId = aPlayer.entityId, health = (int)aPlayer.healthMax }); } catch (Exception error) { InformPlayer(aPlayerId, $"Player_SetHealth: {error.Message}"); } new Thread(new ThreadStart(() => { var TryTimer = new Stopwatch(); TryTimer.Start(); while (TryTimer.ElapsedMilliseconds < (PassengersDB.Configuration.Current.PreparePlayerForTeleport * 1000)) { var WaitTime = PassengersDB.Configuration.Current.PreparePlayerForTeleport - (int)(TryTimer.ElapsedMilliseconds / 1000); InformPlayer(aPlayerId, WaitTime > 1 ? $"Prepare for teleport in {WaitTime} sec." : $"Prepare for teleport now."); if (WaitTime > 0) { Thread.Sleep(2000); } } ActionTeleportPlayer(aPlayer); CheckPlayerStableTargetPos(aPlayerId, aPlayer, ActionTeleportPlayer, FoundDestination.Position); PassengersDB.DeletePassenger(aPlayer.entityId); PassengersDB.Configuration.Save(); })).Start(); return(true); }
private async Task <bool> ExecTeleportPlayer(GlobalStructureList aGlobalStructureList, PlayerInfo aPlayer, int aPlayerId) { var FoundRoute = TeleporterDB.SearchRoute(aGlobalStructureList, aPlayer); if (FoundRoute == null) { InformPlayer(aPlayerId, "No teleporter position here :-( wait 2min for structure update and try it again please."); Log($"EmpyrionTeleporter: Exec: {aPlayer.playerName}/{aPlayer.entityId}/{aPlayer.clientId} -> no route found for pos={GetVector3(aPlayer.pos).String()} on '{aPlayer.playfield}'", LogLevel.Error); return(false); } if (TeleporterDB.Settings.Current.ForbiddenPlayfields.Contains(aPlayer.playfield) || TeleporterDB.Settings.Current.ForbiddenPlayfields.Contains(FoundRoute.Playfield)) { InformPlayer(aPlayerId, "No teleport allowed here ;-)"); Log($"EmpyrionTeleporter: Exec: {aPlayer.playerName}/{aPlayer.entityId}/{aPlayer.clientId} -> no teleport allowed for pos={GetVector3(aPlayer.pos).String()} on '{aPlayer.playfield}'", LogLevel.Error); return(false); } Log($"EmpyrionTeleporter: Exec: {aPlayer.playerName}/{aPlayer.entityId}-> {FoundRoute.Id} on '{FoundRoute.Playfield}' pos={FoundRoute.Position.String()} rot={FoundRoute.Rotation.String()}", LogLevel.Message); if (!PlayerLastGoodPosition.ContainsKey(aPlayer.entityId)) { PlayerLastGoodPosition.Add(aPlayer.entityId, null); } PlayerLastGoodPosition[aPlayer.entityId] = new IdPlayfieldPositionRotation(aPlayer.entityId, aPlayer.playfield, aPlayer.pos, aPlayer.rot); Action <PlayerInfo> ActionTeleportPlayer = async(P) => { if (FoundRoute.Playfield == P.playfield) { try { await Request_Entity_Teleport(new IdPositionRotation(aPlayer.entityId, GetVector3(FoundRoute.Position), GetVector3(FoundRoute.Rotation))); } catch (Exception error) { Log($"Entity_Teleport [{aPlayerId} {P.playerName}]: {error}", LogLevel.Error); InformPlayer(aPlayerId, $"Entity_Teleport: {error.Message}"); } } else { try { await Request_Player_ChangePlayerfield(new IdPlayfieldPositionRotation(aPlayer.entityId, FoundRoute.Playfield, GetVector3(FoundRoute.Position), GetVector3(FoundRoute.Rotation))); } catch (Exception error) { Log($"Player_ChangePlayerfield [{aPlayerId} {P.playerName}]: {error}", LogLevel.Error); InformPlayer(aPlayerId, $"Player_ChangePlayerfield: {error.Message}"); } } }; try { await Request_Player_SetPlayerInfo(new PlayerInfoSet() { entityId = aPlayer.entityId, health = (int)aPlayer.healthMax }); } catch (Exception error) { Log($"Player_SetHealth [{aPlayerId} {aPlayer.playerName}]: {error}", LogLevel.Error); InformPlayer(aPlayerId, $"Player_SetHealth: {error.Message}"); } new Thread(new ThreadStart(() => { var TryTimer = new Stopwatch(); TryTimer.Start(); while (TryTimer.ElapsedMilliseconds < (TeleporterDB.Settings.Current.PreparePlayerForTeleport * 1000)) { var WaitTime = TeleporterDB.Settings.Current.PreparePlayerForTeleport - (int)(TryTimer.ElapsedMilliseconds / 1000); InformPlayer(aPlayerId, WaitTime > 1 ? $"Prepare for teleport in {WaitTime} sec." : $"Prepare for teleport now."); if (WaitTime > 0) { Thread.Sleep(2000); } } ActionTeleportPlayer(aPlayer); CheckPlayerStableTargetPos(aPlayerId, aPlayer, ActionTeleportPlayer, FoundRoute.Position); })).Start(); return(true); }
private GlobalStructureList ReadGlobalStructurList() { var gsl = new GlobalStructureList() { globalStructures = new Dictionary <string, List <GlobalStructureInfo> >() }; var globalStructuresList = new Dictionary <int, GlobalStructureInfo>(); var dockedToList = new Dictionary <int, List <int> >(); using (var DbConnection = new SQLiteConnection($"Data Source='{GlobalDbPath}'")) { DbConnection.Open(); Dictionary <int, string> playfields = ReadPlayfields(DbConnection); using (var cmd = new SQLiteCommand(DbConnection)) { cmd.CommandText = @" SELECT * FROM Structures LEFT JOIN Entities ON Structures.entityid = Entities.entityid ORDER BY pfid "; List <GlobalStructureInfo> currentPlayfieldStructures = null; int currentPlayfieldId = 0; bool initCols = true; int pfIdCol = 0; int entityIdCol = 0; int classNrCol = 0; int cntLightsCol = 0; int cntTrianglesCol = 0; int cntBlocksCol = 0; int cntDevicesCol = 0; int fuelCol = 0; int ispoweredCol = 0; int pilotidCol = 0; int rotXCol = 0; int rotYCol = 0; int rotZCol = 0; int posXCol = 0; int posYCol = 0; int posZCol = 0; int nameCol = 0; int facIdCol = 0; int lastvisitedticksCol = 0; int facgroupCol = 0; int etypeCol = 0; int coretypeCol = 0; int dockedToCol = 0; var reader = cmd.ExecuteReader(); while (reader.Read()) { if (initCols) { initCols = false; pfIdCol = reader.GetOrdinal("pfid"); entityIdCol = reader.GetOrdinal("entityid"); classNrCol = reader.GetOrdinal("classNr"); cntLightsCol = reader.GetOrdinal("cntLights"); cntTrianglesCol = reader.GetOrdinal("cntTriangles"); cntBlocksCol = reader.GetOrdinal("cntBlocks"); cntDevicesCol = reader.GetOrdinal("cntDevices"); fuelCol = reader.GetOrdinal("fuel"); ispoweredCol = reader.GetOrdinal("ispowered"); pilotidCol = reader.GetOrdinal("pilotid"); rotXCol = reader.GetOrdinal("rotX"); rotYCol = reader.GetOrdinal("rotY"); rotZCol = reader.GetOrdinal("rotZ"); posXCol = reader.GetOrdinal("posX"); posYCol = reader.GetOrdinal("posY"); posZCol = reader.GetOrdinal("posZ"); nameCol = reader.GetOrdinal("name"); facIdCol = reader.GetOrdinal("facid"); lastvisitedticksCol = reader.GetOrdinal("lastvisitedticks"); facgroupCol = reader.GetOrdinal("facgroup"); etypeCol = reader.GetOrdinal("etype"); coretypeCol = reader.GetOrdinal("coretype"); dockedToCol = reader.GetOrdinal("dockedTo"); } int pfid = reader.GetInt32(pfIdCol); if (pfid != currentPlayfieldId) { currentPlayfieldId = pfid; gsl.globalStructures.Add(playfields[pfid], currentPlayfieldStructures = new List <GlobalStructureInfo>()); } var gsi = new GlobalStructureInfo() { id = reader.GetInt32(entityIdCol), dockedShips = new List <int>(), classNr = reader.GetInt32(classNrCol), cntLights = reader.GetInt32(cntLightsCol), cntTriangles = reader.GetInt32(cntTrianglesCol), cntBlocks = reader.GetInt32(cntBlocksCol), cntDevices = reader.GetInt32(cntDevicesCol), fuel = (int)reader.GetFloat(fuelCol), powered = reader.GetBoolean(ispoweredCol), rot = new PVector3(reader.GetFloat(rotXCol), reader.GetFloat(rotYCol), reader.GetFloat(rotZCol)), pos = new PVector3(reader.GetFloat(posXCol), reader.GetFloat(posYCol), reader.GetFloat(posZCol)), lastVisitedUTC = reader.GetInt64(lastvisitedticksCol), name = reader.GetString(nameCol), factionId = reader.GetInt32(facIdCol), factionGroup = reader.GetByte(facgroupCol), type = reader.GetByte(etypeCol), coreType = (sbyte)reader.GetByte(coretypeCol), pilotId = reader[pilotidCol] is DBNull ? 0 : reader.GetInt32(pilotidCol), }; if (!(reader[dockedToCol] is DBNull)) { var dockedTo = reader.GetInt32(dockedToCol); if (dockedToList.TryGetValue(dockedTo, out var dockedShips)) { dockedShips.Add(gsi.id); } else { dockedToList.Add(dockedTo, new List <int> { gsi.id }); } } globalStructuresList.Add(gsi.id, gsi); currentPlayfieldStructures.Add(gsi); } } } foreach (var item in dockedToList) { globalStructuresList[item.Key].dockedShips.AddRange(item.Value); } return(gsl); }