public void List(string NameOrSteamID) { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); if (Utils.AdminTryGetPlayerSteamID(NameOrSteamID, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); if (!methods.LoadInfoFile(out PlayerInfo Data)) { return; } if (Data.Grids == null || Data.Grids.Count == 0) { chat.Respond("There are no grids in the hangar!"); return; } int MaxStorage = Plugin.Config.NormalHangarAmount; if (MySession.Static.PromotedUsers.ContainsKey(SteamID)) { //prob redundant but ill leave it incase some future leveling system MyPromoteLevel level = MySession.Static.PromotedUsers[SteamID]; if (level >= MyPromoteLevel.Scripter) { MaxStorage = Plugin.Config.ScripterHangarAmount; } } var sb = new StringBuilder(); sb.AppendLine("Player has " + Data.Grids.Count() + "/" + MaxStorage + " stored grids:"); //sb.AppendLine("Player has " + Data.Grids.Count() +" stored grids:"); int count = 1; foreach (var grid in Data.Grids) { sb.AppendLine(" [" + count + "] - " + grid.GridName); count++; } chat.Respond(sb.ToString()); } }
private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D TargetLocation, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { chat.Respond("No grids in blueprint!"); return(false); } try { MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID)); if (Plugin.GridBackup != null) { Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] { typeof(List <MyObjectBuilder_CubeGrid>), typeof(long) }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId }); Log.Warn("Successfully BackedUp grid!"); } } catch (Exception e) { Log.Fatal(e); } //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids, chat); return(Spawner.Start(keepOriginalLocation, TargetLocation)); }
public void AdminSyncAllPlayers() { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); var PlayerIdentities = MySession.Static.Players.GetAllIdentities().OfType <MyIdentity>(); int newGrids = 0; HashSet <ulong> processedIds = new HashSet <ulong>(); foreach (MyIdentity player in PlayerIdentities) { if (player == null) { continue; } ulong SteamID = MySession.Static.Players.TryGetSteamId(player.IdentityId); if (SteamID != 0) { if (processedIds.Contains(SteamID)) { continue; } processedIds.Add(SteamID); GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); newGrids += methods.SyncWithDisk(); } } chat.Respond($"Found {newGrids} grids for {processedIds.Count} players"); }
public static bool AdminTryGetPlayerSteamID(string NameOrSteamID, Chat chat, out ulong PSteamID) { ulong?SteamID; if (UInt64.TryParse(NameOrSteamID, out ulong PlayerSteamID)) { MyIdentity Identity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(PlayerSteamID, 0)); if (Identity == null) { chat.Respond(NameOrSteamID + " doesnt exsist as an Identity! Dafuq?"); PSteamID = 0; return(false); } PSteamID = PlayerSteamID; return(true); } else { try { MyIdentity MPlayer; MPlayer = MySession.Static.Players.GetAllIdentities().FirstOrDefault(x => x.DisplayName.Equals(NameOrSteamID)); SteamID = MySession.Static.Players.TryGetSteamId(MPlayer.IdentityId); } catch (Exception e) { //Hangar.Debug("Player "+ NameOrID + " dosnt exist on the server!", e, Hangar.ErrorType.Warn); chat.Respond("Player " + NameOrSteamID + " dosnt exist on the server!"); PSteamID = 0; return(false); } } if (!SteamID.HasValue) { chat.Respond("Invalid player format! Check logs for more details!"); Hangar.Debug("Player " + NameOrSteamID + " dosnt exist on the server!"); PSteamID = 0; return(false); } PSteamID = SteamID.Value; return(true); }
public bool Start(bool LoadInOriginalPosition, Vector3D Target) { if (_grids.Length == 0) { //Simple grid/objectbuilder null check. If there are no gridys then why continue? return(true); } MyEntities.RemapObjectBuilderCollection(_grids); if (_AlignToGravity) { EnableRequiredItemsOnLoad(_grids); CalculateGridPosition(Target); } Task <bool> Spawn = GameEvents.InvokeAsync <bool, Vector3D, bool>(CalculateSafePositionAndSpawn, LoadInOriginalPosition, Target); if (Spawn.Wait(Timeout)) { if (Spawn.Result) { foreach (var o in _grids) { MyAPIGateway.Entities.CreateFromObjectBuilderParallel(o, false, Increment); } return(true); } else { return(false); } } else { _Response.Respond("Parrallel Grid Spawner Timed out!"); return(false); } }
public bool GetGrids(Chat Response, MyCharacter character, string GridNameOREntityID = null) { if (!GridUtilities.FindGridList(GridNameOREntityID, character, out Grids)) { Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!"); return(false); } if (!GridUtilities.BiggestGrid(Grids, out BiggestGrid)) { Response.Respond("Grid incompatible!"); return(false); } if (!IsAdmin && !BiggestGrid.BigOwners.Contains(character.GetPlayerIdentityId())) { Response.Respond("You are not the owner of the biggest grid!"); return(false); } if (BiggestGrid.BigOwners.Count == 0) { BiggestOwner = 0; } else { BiggestOwner = BiggestGrid.BigOwners[0]; } if (!GetOwner(BiggestOwner, out OwnerSteamID)) { Response.Respond("Unable to get owners SteamID"); return(false); } GridName = BiggestGrid.DisplayName; return(true); }
public bool Start(bool LoadInOriginalPosition, Vector3D Target) { MyEntities.RemapObjectBuilderCollection(_grids); EnableRequiredItemsOnLoad(_grids); Task <bool> Spawn = GameEvents.InvokeAsync <bool, Vector3D, bool>(CalculateSafePositionAndSpawn, LoadInOriginalPosition, Target); if (Spawn.Wait(Timeout)) { if (Spawn.Result) { foreach (var o in _grids) { MyAPIGateway.Entities.CreateFromObjectBuilderParallel(o, false, Increment); } return(true); } else { return(false); } } else { _Response.Respond("Parrallel Grid Spawner Timed out!"); return(false); } }
public void HangarHelp() { Chat chat = new Chat(Context); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("!hangar save (Saves the grid you are looking at)"); stringBuilder.AppendLine("!hangar list (Lists all the grids in your hangar with their number)"); stringBuilder.AppendLine("!hangar load [NameOrNumber] (Loads the specified grid from hangar)"); stringBuilder.AppendLine("!hangar sell [NameOrNumber] [Price] [\"Description\"] (Put grid up for sale)"); stringBuilder.AppendLine("!hangar info [NameOrNumber] (Provides info about the grid in your hangar)"); stringBuilder.AppendLine("!hangar removeoffer [NameOrNumber] (Removes a ship form the market)"); chat.Respond(stringBuilder.ToString()); }
public void AdminSyncPlayer(string NameOrSteamId) { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); int newGrids = 0; if (Utils.AdminTryGetPlayerSteamID(NameOrSteamId, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); newGrids = methods.SyncWithDisk(); } chat.Respond($"Found {newGrids} grids"); }
public void HangarRemove(string NameOrSteamID, string GridNameOrNumber) { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); if (Utils.AdminTryGetPlayerSteamID(NameOrSteamID, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); if (!methods.LoadInfoFile(out PlayerInfo Data)) { return; } if (Int32.TryParse(GridNameOrNumber, out int result)) { if (result > Data.Grids.Count) { chat.Respond("This hangar slot is empty! Select a grid that is in the hangar!"); return; } if (result != 0) { GridStamp Grid = Data.Grids[result - 1]; Data.Grids.RemoveAt(result - 1); string path = Path.Combine(methods.FolderPath, Grid.GridName + ".sbc"); File.Delete(path); chat.Respond(string.Format("{0} was successfully deleted!", Grid.GridName)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } else if (result == 0) { int counter = 0; foreach (var grid in Data.Grids) { string path = Path.Combine(methods.FolderPath, grid.GridName + ".sbc"); File.Delete(path); counter++; } Data.Grids.Clear(); chat.Respond(string.Format("Successfully deleted {0} grids!", counter)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } } else { foreach (var grid in Data.Grids) { if (grid.GridName == GridNameOrNumber) { Data.Grids.Remove(grid); string path = Path.Combine(methods.FolderPath, grid.GridName + ".sbc"); File.Delete(path); chat.Respond(string.Format("{0} was successfully deleted!", grid.GridName)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } } } } }
public void HangarDetails(string NameOrSteamID, string GridNameOrNumber) { Parallel.Invoke(() => { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); if (Utils.AdminTryGetPlayerSteamID(NameOrSteamID, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); methods.LoadInfoFile(out PlayerInfo Data); if (Int32.TryParse(GridNameOrNumber, out int result)) { GridStamp Grid = Data.Grids[result - 1]; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("__________•°•[ Ship Properties ]•°•__________"); stringBuilder.AppendLine("Estimated Market Value: " + Grid.MarketValue + " [sc]"); stringBuilder.AppendLine("GridMass: " + Grid.GridMass + "kg"); stringBuilder.AppendLine("Num of Small Grids: " + Grid.SmallGrids); stringBuilder.AppendLine("Num of Large Grids: " + Grid.LargeGrids); stringBuilder.AppendLine("Max Power Output: " + Grid.MaxPowerOutput); stringBuilder.AppendLine("Build Percentage: " + Math.Round(Grid.GridBuiltPercent * 100, 2) + "%"); stringBuilder.AppendLine("Max Jump Distance: " + Grid.JumpDistance); stringBuilder.AppendLine("Ship PCU: " + Grid.GridPCU); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("__________•°•[ Block Count ]•°•__________"); foreach (KeyValuePair <string, int> pair in Grid.BlockTypeCount) { stringBuilder.AppendLine(pair.Key + ": " + pair.Value); } if (Context.Player != null) { ModCommunication.SendMessageTo(new DialogMessage(Grid.GridName, $"Ship Information", stringBuilder.ToString()), Context.Player.SteamUserId); } else { chat.Respond(stringBuilder.ToString()); } } else { //Scan containg Grids if the user typed one foreach (var grid in Data.Grids) { if (grid.GridName == GridNameOrNumber) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("__________•°•[ Ship Properties ]•°•__________"); stringBuilder.AppendLine("Estimated Market Value: " + grid.MarketValue + " [sc]"); stringBuilder.AppendLine("GridMass: " + grid.GridMass + "kg"); stringBuilder.AppendLine("Num of Small Grids: " + grid.SmallGrids); stringBuilder.AppendLine("Num of Large Grids: " + grid.LargeGrids); stringBuilder.AppendLine("Max Power Output: " + grid.MaxPowerOutput); stringBuilder.AppendLine("Build Percentage: " + Math.Round(grid.GridBuiltPercent * 100, 2) + "%"); stringBuilder.AppendLine("Max Jump Distance: " + grid.JumpDistance); stringBuilder.AppendLine("Ship PCU: " + grid.GridPCU); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("__________•°•[ Block Count ]•°•__________"); foreach (KeyValuePair <string, int> pair in grid.BlockTypeCount) { stringBuilder.AppendLine(pair.Key + ": " + pair.Value); } if (Context.Player != null) { ModCommunication.SendMessageTo(new DialogMessage(grid.GridName, $"Ship Information", stringBuilder.ToString()), Context.Player.SteamUserId); } else { chat.Respond(stringBuilder.ToString()); } // Context.Respond("You removed " + grid.GridName + " from the market!"); } } } } }); }
public bool Start(Vector3D Target, bool LoadInOriginalPosition = true) { TargetPos = Target; if (_grids.Count() == 0) { //Simple grid/objectbuilder null check. If there are no gridys then why continue? return(true); } // Fix for recent keen update. (if grids have projected grids saved then they will get the infinite streaming bug) foreach (var cubeGrid in _grids) { //cubeGrid.PlayerPresenceTier = MyUpdateTiersPlayerPresence.Normal; cubeGrid.CreatePhysics = true; // Set biggest grid in grid group if (_BiggestGrid == null || _BiggestGrid.CubeBlocks.Count < cubeGrid.CubeBlocks.Count) { _BiggestGrid = cubeGrid; } foreach (var block in cubeGrid.CubeBlocks.OfType <MyObjectBuilder_Projector>()) { block.ProjectedGrid = null; block.ProjectedGrids?.Clear(); } } //Remap to fix entity conflicts MyEntities.RemapObjectBuilderCollection(_grids); //This should return more than a bool (we only need to run on game thread to find a safe spot) Task <bool> Spawn = GameEvents.InvokeAsync <bool, bool>(CalculateSafePositionAndSpawn, LoadInOriginalPosition); if (Spawn.Wait(Timeout)) { if (Spawn.Result) { foreach (var o in _grids) { MyAPIGateway.Entities.CreateFromObjectBuilderParallel(o, false, Increment); } return(true); } else { return(false); } } else { _Response.Respond("Parallel Grid Spawner Timed out!"); return(false); } }
private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D playerPosition, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { Hangar.Debug("No grids in blueprint!"); chat.Respond("No grids in blueprint!"); return(false); } try { MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID)); if (Plugin.GridBackup != null) { Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] { typeof(List <MyObjectBuilder_CubeGrid>), typeof(long) }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId }); Log.Warn("Successfully BackedUp grid!"); } } catch (Exception e) { Log.Fatal(e); } bool LoadNearPosition = false; //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids); var position = grids[0].PositionAndOrientation.Value; if (keepOriginalLocation) { var sphere = FindBoundingSphere(grids); sphere.Center = position.Position; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities); foreach (var entity in entities) { if (entity is MyCubeGrid) { chat.Respond("There are potentially other grids in the way. Loading near the original point."); LoadNearPosition = true; } } if (!LoadNearPosition) { /* Remapping to prevent any key problems upon paste. */ MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); } } /* * Everything else is loading for near player * * * */ /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(grids, position.Position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition if that doesnt work get out of here. */ if (!UpdateGridsPosition(grids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); }
private bool BeginAlignToGravity(MyObjectBuilder_CubeGrid[] AllGrids, Vector3D position, Vector3D direction, Vector3D vector3D) { //Create WorldMatrix MatrixD worldMatrix = MatrixD.CreateWorld(position, direction, vector3D); int num = 0; MatrixD matrix = MatrixD.Identity; //Find biggest grid and get their postion matrix Parallel.For(0, AllGrids.Length, i => { //Option to clone the BP //array[i] = (MyObjectBuilder_CubeGrid)TotalGrids[i].Clone(); if (AllGrids[i].CubeBlocks.Count > num) { num = AllGrids[i].CubeBlocks.Count; matrix = (AllGrids[i].PositionAndOrientation.HasValue ? AllGrids[i].PositionAndOrientation.Value.GetMatrix() : MatrixD.Identity); } }); MatrixD matrix2; //Align to Main/Biggest grid Vector3D value = Vector3D.Zero; if (AllGrids[0].PositionAndOrientation.HasValue) { value = AllGrids[0].PositionAndOrientation.Value.Position; } matrix2 = MatrixD.CreateWorld(-value, direction, vector3D); //Huh? (Keen does this so i guess i will too) My guess so it can create large entities MyEntities.IgnoreMemoryLimits = true; //Update each grid in the array Parallel.For(0, AllGrids.Length, j => { MatrixD newWorldMatrix; if (AllGrids[j].PositionAndOrientation.HasValue) { MatrixD matrix3 = AllGrids[j].PositionAndOrientation.Value.GetMatrix() * MatrixD.Invert(matrix); newWorldMatrix = matrix3 * worldMatrix; AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(newWorldMatrix); } else { newWorldMatrix = worldMatrix; AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); } }); /* Where do we want to paste the grids? Lets find out. based from the character/position */ var pos = FindPastePosition(AllGrids, position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition via xyz. (We already have the orientation correct) if that doesnt work get out of here. */ if (!UpdateGridsPosition(AllGrids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } //Remap to prevent bad stuff MyEntities.RemapObjectBuilderCollection(AllGrids); //Use Rexxars spciy spaghetti code for parallel spawning of ALL grids ParallelSpawner spawner = new ParallelSpawner(AllGrids); spawner.Start(); //Return completeted return(true); }
public bool LoadGrid(string GridName, MyCharacter Player, long TargetPlayerID, bool keepOriginalLocation, Chat chat, Hangar Plugin, Vector3D GridSaveLocation, bool force = false, bool Admin = false) { string path = Path.Combine(FolderPath, GridName + ".sbc"); if (!File.Exists(path)) { chat.Respond("Grid doesnt exist! Admin should check logs for more information."); Log.Fatal("Grid doesnt exsist @" + path); return(false); } try { if (MyObjectBuilderSerializer.DeserializeXML(path, out MyObjectBuilder_Definitions myObjectBuilder_Definitions)) { var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints; if (shipBlueprints == null) { Hangar.Debug("No ShipBlueprints in File '" + path + "'"); chat.Respond("There arent any Grids in your file to import!"); return(false); } if (!HangarChecker.BlockLimitChecker(shipBlueprints)) { Hangar.Debug("Block Limiter Checker Failed"); return(false); } if (Config.OnLoadTransfer) { Log.Warn("Target player: " + TargetPlayerID); //Will transfer pcu to new player foreach (MyObjectBuilder_ShipBlueprintDefinition definition in shipBlueprints) { foreach (MyObjectBuilder_CubeGrid CubeGridDef in definition.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in CubeGridDef.CubeBlocks) { block.Owner = TargetPlayerID; block.BuiltBy = TargetPlayerID; } } } } //If the configs have keep originial position on, we dont want to align this to gravity. foreach (var shipBlueprint in shipBlueprints) { Vector3D TargetSpawnPos = Vector3D.Zero; if (Player != null) { TargetSpawnPos = Player.PositionComp.GetPosition(); } if (!LoadShipBlueprint(shipBlueprint, GridSaveLocation, TargetSpawnPos, keepOriginalLocation, chat, Plugin)) { Hangar.Debug("Error Loading ShipBlueprints from File '" + path + "'"); return(false); } } File.Delete(path); return(true); } } catch (Exception ex) { chat.Respond("This ship failed to load. Contact staff & Check logs!"); Log.Error(ex, "Failed to deserialize grid: " + path + " from file! Is this a shipblueprint?"); } return(false); }
public bool CheckGridLimits(Chat Response, MyIdentity TargetIdentity) { //No need to check limits if (Config.OnLoadTransfer) { return(true); } if (ShipPCU.Count == 0) { MyBlockLimits blockLimits = TargetIdentity.BlockLimits; MyBlockLimits a = MySession.Static.GlobalBlockLimits; if (a.PCU <= 0) { //PCU Limits on server is 0 //Skip PCU Checks //Hangar.Debug("PCU Server limits is 0!"); return(true); } //Main.Debug("PCU Limit from Server:"+a.PCU); //Main.Debug("PCU Limit from Player: " + blockLimits.PCU); //Main.Debug("PCU Built from Player: " + blockLimits.PCUBuilt); int CurrentPcu = blockLimits.PCUBuilt; //Hangar.Debug("Current PCU: " + CurrentPcu); int MaxPcu = blockLimits.PCU + CurrentPcu; int pcu = MaxPcu - CurrentPcu; //Find the difference if (MaxPcu - CurrentPcu <= GridPCU) { int Need = GridPCU - (MaxPcu - CurrentPcu); Response.Respond("PCU limit reached! You need an additional " + Need + " pcu to perform this action!"); return(false); } return(true); } foreach (KeyValuePair <long, int> Player in ShipPCU) { MyIdentity Identity = MySession.Static.Players.TryGetIdentity(Player.Key); if (Identity == null) { continue; } MyBlockLimits blockLimits = Identity.BlockLimits; MyBlockLimits a = MySession.Static.GlobalBlockLimits; if (a.PCU <= 0) { //PCU Limits on server is 0 //Skip PCU Checks //Hangar.Debug("PCU Server limits is 0!"); continue; } int CurrentPcu = blockLimits.PCUBuilt; int MaxPcu = blockLimits.PCU + CurrentPcu; int pcu = MaxPcu - CurrentPcu; //Find the difference if (MaxPcu - CurrentPcu <= Player.Value) { int Need = Player.Value - (MaxPcu - CurrentPcu); Response.Respond("PCU limit reached! " + Identity.DisplayName + " needs an additional " + Need + " PCU to load this grid!"); return(false); } } return(true); }
public bool GetGrids(Chat Response, MyCharacter character, string GridNameOrEntity = null) { if (!GridUtilities.FindGridList(GridNameOrEntity, character, out Grids)) { Response.Respond("No grids found. Check your viewing angle or make sure you spelled right!"); return(false); } Grids.BiggestGrid(out BiggestGrid); if (BiggestGrid == null) { Response.Respond("Grid incompatible!"); return(false); } if (!IsAdmin) { var FatBlocks = BiggestGrid.GetFatBlocks().ToList(); long OwnerID = character.GetPlayerIdentityId(); int TotalFatBlocks = 0; int OwnedFatBlocks = 0; foreach (var fat in FatBlocks) { //Only count blocks with ownership if (!fat.IsFunctional || fat.IDModule == null) { continue; } //WTF happened here? //if (fat.OwnerId == 0) // Log.Error($"WTF: {fat.BlockDefinition.Id} - {fat.GetType()} - {fat.OwnerId}"); TotalFatBlocks++; if (fat.OwnerId == OwnerID) { OwnedFatBlocks++; } } double Percent = Math.Round((double)OwnedFatBlocks / TotalFatBlocks * 100, 3); int TotalBlocksLeftNeeded = (TotalFatBlocks / 2) + 1 - (OwnedFatBlocks); if (Percent <= 50) { Response.Respond($"You own {Percent}% of the biggest grid! Need {TotalBlocksLeftNeeded} more blocks to be the majority owner!"); return(false); } } else { //Compute biggest owner } if (BiggestGrid.BigOwners.Count == 0) { BiggestOwner = 0; } else { BiggestOwner = BiggestGrid.BigOwners[0]; } if (!GetOwner(BiggestOwner, out OwnerSteamID)) { Response.Respond("Unable to get owners SteamID! Are you an NPC?"); return(false); } GridName = BiggestGrid.DisplayName; return(true); }
public bool LoadGrid(string GridName, MyCharacter Player, long TargetPlayerID, bool keepOriginalLocation, Chat chat, bool force = false) { string path = Path.Combine(FolderPath, GridName + ".sbc"); if (!File.Exists(path)) { chat.Respond("Grid doesnt exist! Admin should check logs for more information."); Log.Fatal("Grid doesnt exsist @" + path); return(false); } if (MyObjectBuilderSerializer.DeserializeXML(path, out MyObjectBuilder_Definitions myObjectBuilder_Definitions)) { var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints; if (shipBlueprints == null) { Hangar.Debug("No ShipBlueprints in File '" + path + "'"); chat.Respond("There arent any Grids in your file to import!"); return(false); } if (!HangarChecker.BlockLimitChecker(shipBlueprints)) { Hangar.Debug("Block Limiter Checker Failed"); return(false); } if (Config.OnLoadTransfer) { Log.Warn("Target player: " + TargetPlayerID); //Will transfer pcu to new player foreach (MyObjectBuilder_ShipBlueprintDefinition definition in shipBlueprints) { foreach (MyObjectBuilder_CubeGrid CubeGridDef in definition.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in CubeGridDef.CubeBlocks) { block.Owner = TargetPlayerID; block.BuiltBy = TargetPlayerID; } } } } if (keepOriginalLocation) { foreach (var shipBlueprint in shipBlueprints) { if (!LoadShipBlueprint(shipBlueprint, Player.PositionComp.GetPosition(), true, chat)) { Hangar.Debug("Error Loading ShipBlueprints from File '" + path + "'"); return(false); } } File.Move(path, path + ".bak"); //File.Delete(path); return(true); } else { Hangar.Debug("Attempting to align grid to gravity!"); AlignToGravity GravityAligner = new AlignToGravity(shipBlueprints, Player.PositionComp.GetPosition(), chat); if (GravityAligner.Start()) { File.Move(path, Path.Combine(FolderPath, GridName + ".bak")); //File.Delete(path); return(true); } } } return(false); }
private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D playerPosition, bool keepOriginalLocation, Chat chat, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { Hangar.Debug("No grids in blueprint!"); chat.Respond("No grids in blueprint!"); return(false); } bool LoadNearPosition = false; //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids); var position = grids[0].PositionAndOrientation.Value; if (keepOriginalLocation) { var sphere = FindBoundingSphere(grids); sphere.Center = position.Position; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities); foreach (var entity in entities) { if (entity is MyCubeGrid) { chat.Respond("There are potentially other grids in the way. Loading near the original point."); LoadNearPosition = true; } } if (!LoadNearPosition) { /* Remapping to prevent any key problems upon paste. */ MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); } } /* * Everything else is loading for near player * * * */ /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(grids, position.Position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition if that doesnt work get out of here. */ if (!UpdateGridsPosition(grids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); }