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); }
public bool LoadGrid(string GridName, MyCharacter Player, long TargetPlayerID, bool keepOriginalLocation, Chat chat, Hangar Plugin, Vector3D GridSaveLocation, 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); } 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. if (keepOriginalLocation) { foreach (var shipBlueprint in shipBlueprints) { if (!LoadShipBlueprint(shipBlueprint, GridSaveLocation, true, chat, Plugin)) { Hangar.Debug("Error Loading ShipBlueprints from File '" + path + "'"); return(false); } } File.Delete(path); return(true); } else { AlignToGravity GravityAligner = new AlignToGravity(shipBlueprints, Player.PositionComp.GetPosition(), chat); if (GravityAligner.Start()) { 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); }