public HangarLog GetHangarLog(Alliance alliance) { if (!Directory.Exists(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId)) { Directory.CreateDirectory(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//"); } if (!File.Exists(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json")) { HangarLog log = new HangarLog { allianceId = alliance.AllianceId }; utils.WriteToJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json", log); return(log); } return(utils.ReadFromJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json")); }
public void BankLog(string timeformat = "MM-dd-yyyy") { if (Context.Player != null) { //Do stuff with taking components from grid storage //GridCosts localGridCosts = GetComponentsAndCost(projectedGrid); //gridCosts.setComponents(localGridCosts.getComponents()); IMyFaction faction = FacUtils.GetPlayersFaction(Context.Player.IdentityId); if (faction == null) { Context.Respond("You must be in a faction to use alliance features."); return; } Alliance alliance = AlliancePlugin.GetAlliance(faction as MyFaction); if (alliance == null) { Context.Respond("You are not a member of an alliance with an unlocked shipyard."); return; } if (AlliancePlugin.HasFailedUpkeep(alliance)) { Context.Respond("Alliance failed to pay upkeep. Upgrades disabled."); return; } if (alliance.hasUnlockedHangar) { HangarData data = alliance.LoadHangar(); HangarLog log = data.GetHangarLog(alliance); StringBuilder sb = new StringBuilder(); log.log.Reverse(); foreach (HangarLogItem item in log.log) { sb.AppendLine(item.time.ToString(timeformat) + " : " + AlliancePlugin.GetPlayerName(item.steamid) + " " + item.action + " " + item.GridName.Split('_')[0]); continue; } DialogMessage m = new DialogMessage("Alliance Hangar Records", alliance.name, sb.ToString()); ModCommunication.SendMessageTo(m, Context.Player.SteamUserId); } else { Context.Respond("Alliance has not unlocked hangar."); } } }
public Boolean SaveGridToHangar(String gridName, ulong steamid, Alliance alliance, Vector3D position, MyFaction faction, List <MyCubeGrid> gridsToSave, long IdentityId) { if (!CheckGrids(position, IdentityId)) { AlliancePlugin.Log.Info("Failed grid check"); return(false); } if (!CheckCharacters(position, IdentityId)) { AlliancePlugin.Log.Info("Failed character check"); return(false); } HangarLog log = GetHangarLog(alliance); HangarLogItem item = new HangarLogItem(); item.action = "Saved"; item.steamid = steamid; item.GridName = gridName; item.time = DateTime.Now; log.log.Add(item); utils.WriteToJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json", log); HangarItem hangItem = new HangarItem(); hangItem.name = gridName; hangItem.steamid = steamid; hangItem.position = position; ItemsInHangar.Add(getAvailableSlot(), hangItem); GridManager.SaveGridNoDelete(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + gridName + ".xml"), gridName, true, false, gridsToSave); if (AlliancePlugin.GridBackupInstalled) { List <MyObjectBuilder_CubeGrid> obBuilders = new List <MyObjectBuilder_CubeGrid>(); foreach (MyCubeGrid grid in gridsToSave) { obBuilders.Add(grid.GetObjectBuilder() as MyObjectBuilder_CubeGrid); } AlliancePlugin.BackupGridMethod(obBuilders, IdentityId); } utils.WriteToJsonFile <HangarData>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//hangar.json", this); return(true); }
public Boolean LoadGridFromHangar(int slotNum, ulong steamid, Alliance alliance, MyIdentity identity, MyFaction faction) { HangarItem hangItem = ItemsInHangar[slotNum]; if (!CheckGrids(hangItem.position, identity.IdentityId)) { return(false); } if (!CheckCharacters(hangItem.position, identity.IdentityId)) { return(false); } if (!GridManager.LoadGrid(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"), ItemsInHangar[slotNum].position, true, steamid, ItemsInHangar[slotNum].name)) { if (!GridManager.LoadGrid(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"), ItemsInHangar[slotNum].position, false, steamid, ItemsInHangar[slotNum].name)) { return(false); } } HangarLog log = GetHangarLog(alliance); HangarLogItem item = new HangarLogItem(); item.action = "Loaded"; item.steamid = steamid; item.GridName = ItemsInHangar[slotNum].name; item.time = DateTime.Now; log.log.Add(item); utils.WriteToJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json", log); if (AlliancePlugin.GridBackupInstalled) { List <MyObjectBuilder_CubeGrid> obBuilders = new List <MyObjectBuilder_CubeGrid>(); obBuilders = GridManager.GetObjectBuilders(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"); if (obBuilders != null) { AlliancePlugin.BackupGridMethod(obBuilders, identity.IdentityId); } else { AlliancePlugin.Log.Error("Error saving a backup when loading this grid"); } } File.Delete(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"); ItemsInHangar.Remove(slotNum); List <HangarItem> temp = new List <HangarItem>(); foreach (HangarItem hangitem in ItemsInHangar.Values) { temp.Add(hangitem); } ItemsInHangar.Clear(); int i = 1; foreach (HangarItem hangitem in temp) { ItemsInHangar.Add(i, hangitem); i++; } utils.WriteToJsonFile <HangarData>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//hangar.json", this); return(true); }