private async Task ExecAlignCommand(SubCommand aCommand, TeleporterPermission aPermission, ChatInfo info, Dictionary <string, string> args) { Log($"**HandleEmpyrionTeleporter {info.type}:{info.msg} {args.Aggregate("", (s, i) => s + i.Key + "/" + i.Value + " ")}", LogLevel.Message); if (info.type != (byte)ChatType.Faction) { return; } switch (aCommand) { case SubCommand.Help: DisplayHelp(info.playerId); break; case SubCommand.Back: await ExecTeleportPlayerBack(info.playerId); break; case SubCommand.Delete: await DeleteTeleporterRoutes(info.playerId, getIntParam(args, "SourceId"), getIntParam(args, "TargetId")); break; case SubCommand.List: await ListTeleporterRoutes(info.playerId, getIntParam(args, "Id")); break; case SubCommand.ListAll: await ListAllTeleporterRoutes(info.playerId); break; case SubCommand.CleanUp: await CleanUpTeleporterRoutes(info.playerId); break; case SubCommand.Save: await SaveTeleporterRoute(info.playerId, aPermission, getIntParam(args, "SourceId"), getIntParam(args, "TargetId")); break; case SubCommand.Teleport: await TeleportPlayer(info.playerId); break; } }
private async Task SaveTeleporterRoute(int aPlayerId, TeleporterPermission aPermission, int aSourceId, int aTargetId) { var G = await Request_GlobalStructure_List(); var P = await Request_Player_Info(aPlayerId.ToId()); var SourceStructure = TeleporterDB.SearchEntity(G, aSourceId); var TargetStructure = TeleporterDB.SearchEntity(G, aSourceId); if (SourceStructure == null) { AlertPlayer(P.entityId, $"Structure not found: {aSourceId}"); } else if (TargetStructure == null) { AlertPlayer(P.entityId, $"Structure not found: {aTargetId}"); } else if (!CheckPermission(SourceStructure, TeleporterDB.Settings.Current)) { AlertPlayer(P.entityId, $"Structure not allowed: {aSourceId} {(EntityType)SourceStructure.Data.type}/{(FactionGroups)SourceStructure.Data.factionGroup}"); } else if (!CheckPermission(TargetStructure, TeleporterDB.Settings.Current)) { AlertPlayer(P.entityId, $"Structure not allowed: {aTargetId} {(EntityType)TargetStructure.Data.type}/{(FactionGroups)TargetStructure.Data.factionGroup}"); } else if (TeleporterDB.Settings.Current.ForbiddenPlayfields.Contains(P.playfield) || TeleporterDB.Settings.Current.ForbiddenPlayfields.Contains(SourceStructure.Playfield) || TeleporterDB.Settings.Current.ForbiddenPlayfields.Contains(TargetStructure.Playfield)) { InformPlayer(aPlayerId, "No teleporter allowed here ;-)"); Log($"EmpyrionTeleporter: Exec: {P.playerName}/{P.entityId}/{P.clientId} -> no teleport allowed for pos={GetVector3(P.pos).String()} on '{P.playfield}'", LogLevel.Error); } else { var foundRoute = TeleporterDB.SearchRoute(aPermission, aSourceId, aTargetId, P); var routeUpdate = foundRoute != null && foundRoute.A.Position != Vector3.Zero && foundRoute.B.Position != Vector3.Zero; if (!routeUpdate && P.credits < TeleporterDB.Settings.Current.CostsPerTeleporterPosition) { AlertPlayer(P.entityId, $"You need {TeleporterDB.Settings.Current.CostsPerTeleporterPosition} credits ;-)"); return; } TeleporterDB.AddRoute(G, aPermission, aSourceId, aTargetId, P); TeleporterDB.Settings.Save(); if (!routeUpdate && TeleporterDB.Settings.Current.CostsPerTeleporterPosition > 0) { await Request_Player_SetCredits(new IdCredits(P.entityId, P.credits - TeleporterDB.Settings.Current.CostsPerTeleporterPosition)); } await ShowDialog(aPlayerId, P, "Teleporters", $"\nTeleporter set\n{aSourceId} => {aTargetId}"); } }
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; } }
private void SaveTeleporterRoute(int aPlayerId, TeleporterPermission aPermission, int aSourceId, int aTargetId) { Request_GlobalStructure_List(G => { Request_Player_Info(aPlayerId.ToId(), (P) => { var SourceStructure = TeleporterDB.SearchEntity(G, aSourceId); var TargetStructure = TeleporterDB.SearchEntity(G, aSourceId); if (SourceStructure == null) { AlertPlayer(P.entityId, $"Structure not found: {aSourceId}"); } else if (TargetStructure == null) { AlertPlayer(P.entityId, $"Structure not found: {aTargetId}"); } else if (!CheckPermission(SourceStructure, TeleporterDB.Configuration)) { AlertPlayer(P.entityId, $"Structure not allowed: {aSourceId} {(EntityType)SourceStructure.Data.type}/{(FactionGroups)SourceStructure.Data.factionGroup}"); } else if (!CheckPermission(TargetStructure, TeleporterDB.Configuration)) { AlertPlayer(P.entityId, $"Structure not allowed: {aTargetId} {(EntityType)TargetStructure.Data.type}/{(FactionGroups)TargetStructure.Data.factionGroup}"); } else if (P.credits < TeleporterDB.Configuration.CostsPerTeleporterPosition) { AlertPlayer(P.entityId, $"You need {TeleporterDB.Configuration.CostsPerTeleporterPosition} credits ;-)"); } else if (TeleporterDB.Configuration.ForbiddenPlayfields.Contains(P.playfield) || TeleporterDB.Configuration.ForbiddenPlayfields.Contains(SourceStructure.Playfield) || TeleporterDB.Configuration.ForbiddenPlayfields.Contains(TargetStructure.Playfield)) { InformPlayer(aPlayerId, "No teleporter allowed here ;-)"); log($"EmpyrionTeleporter: Exec: {P.playerName}/{P.entityId}/{P.clientId} -> no teleport allowed for pos={GetVector3(P.pos).String()} on '{P.playfield}'", LogLevel.Error); } else { TeleporterDB.AddRoute(G, aPermission, aSourceId, aTargetId, P); SaveTeleporterDB(); if (TeleporterDB.Configuration.CostsPerTeleporterPosition > 0) { Request_Player_SetCredits(new IdCredits(P.entityId, P.credits - TeleporterDB.Configuration.CostsPerTeleporterPosition)); } ShowDialog(aPlayerId, P, "Teleporters", $"\nTeleporter set\n{aSourceId} => {aTargetId}"); } }); }); }