public static void Login(IPlayer p) { if (p == null) { return; } MyIdentity id = AlliancePlugin.GetIdentityByNameOrId(p.SteamId.ToString()); if (id == null) { return; } IMyFaction playerFac = MySession.Static.Factions.GetPlayerFaction(id.IdentityId); MyFaction arrr = MySession.Static.Factions.TryGetFactionByTag("arrr"); if (arrr != null) { if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(arrr.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId)) { Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, arrr.FactionId); } } MyFaction ACME = MySession.Static.Factions.TryGetFactionByTag("ACME"); if (ACME != null) { MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, ACME.FactionId, 0); MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, ACME.FactionId, 0); } MyFaction GAIA = MySession.Static.Factions.TryGetFactionByTag("GAIA"); if (GAIA != null) { MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, GAIA.FactionId, 0); MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, GAIA.FactionId, 0); } MyFaction wolf = MySession.Static.Factions.TryGetFactionByTag("WOLF"); if (wolf != null) { if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(wolf.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId)) { Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, wolf.FactionId); } } if (File.Exists(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml") && playerFac != null) { PlayerData data = utils.ReadFromXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml"); if (data.InAllianceChat) { if (AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction) != null) { PeopleInAllianceChat.Remove(p.SteamId); PeopleInAllianceChat.Add(p.SteamId, AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction).AllianceId); } } } }
static void Postfix(long playerId1, long playerId2, ref MyRelationsBetweenPlayerAndBlock __result) { if (playerId1 == playerId2) { return; } IMyFaction playerFaction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1); IMyFaction playerFaction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2); if (playerFaction1 != null && playerFaction2 != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) != null && AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction) != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) == AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction)) { // AlliancePlugin.Log.Info("Same alliance?"); __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } if (MySession.Static.Factions.AreFactionsFriends(playerFaction1.FactionId, playerFaction2.FactionId)) { __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } return; // make sure you only skip if really necessary }
public void azazel() { AlliancePlugin.LoadConfig(); AlliancePlugin.config.KothEnabled = true; AlliancePlugin.saveConfig(); Context.Respond("KOTH is now enabled, at least it should be."); }
public void HangarList() { if (!AlliancePlugin.config.HangarEnabled) { Context.Respond("Hangar not enabled."); return; } 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("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 hangar."); return; } if (AlliancePlugin.HasFailedUpkeep(alliance)) { Context.Respond("Alliance failed to pay upkeep. Upgrades disabled."); return; } if (alliance.hasUnlockedHangar) { HangarData hangar = alliance.LoadHangar(); if (hangar == null) { Context.Respond("Error loading the hangar."); return; } Context.Respond("Hangar Slots available : " + hangar.SlotsAmount, Color.LightBlue, "Alliance Hangar"); for (int i = 1; i <= hangar.SlotsAmount; i++) { if (hangar.ItemsInHangar.ContainsKey(i)) { hangar.ItemsInHangar.TryGetValue(i, out HangarItem slot); Context.Respond(slot.name.Split('_')[0] + " : " + AlliancePlugin.GetPlayerName(slot.steamid), Color.LightBlue, "[ " + i + " ]"); } else { Context.Respond("", Color.Green, "[ Available ]"); } } } } }
public static Boolean Taxes(Dictionary <Guid, Dictionary <long, float> > taxes) { try { using (var db = new LiteDatabase(connectionString)) { var collection = db.GetCollection <BankData>("BankData"); foreach (KeyValuePair <Guid, Dictionary <long, float> > key in taxes) { Alliance alliance = AlliancePlugin.GetAlliance(key.Key); long amount = 0; foreach (float f in key.Value.Values) { amount += (long)f; } var bank = collection.FindById(key.Key); if (bank == null) { bank = new BankData { Id = key.Key, balance = amount }; collection.Insert(bank); } else { bank.balance += amount; collection.Update(bank); } foreach (KeyValuePair <long, float> tax in key.Value) { if (EconUtils.getBalance(tax.Key) >= tax.Value) { alliance.DepositTax((long)tax.Value, MySession.Static.Players.TryGetSteamId(tax.Key)); EconUtils.takeMoney(tax.Key, (long)tax.Value); } } AlliancePlugin.SaveAllianceData(alliance); } } } catch (Exception ex) { AlliancePlugin.Log.Error("Error with taxes"); AlliancePlugin.Log.Error(ex); return(false); } return(true); }
public void distress(string reason = "") { if (Context.Player == null) { Context.Respond("no no console no distress"); return; } IMyFaction playerFac = FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId); if (playerFac == null) { Context.Respond("You dont have a faction."); return; } if (reason != "") { reason = Context.RawArgs; } MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId); if (fac == null) { Context.Respond("A faction is required to use alliance features."); return; } if (distressCooldowns.TryGetValue(Context.Player.IdentityId, out DateTime time)) { if (DateTime.Now < time) { Context.Respond(AllianceCommands.GetCooldownMessage(time)); return; } else { distressCooldowns[Context.Player.IdentityId] = DateTime.Now.AddSeconds(30); } } else { distressCooldowns.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(30)); } Alliance alliance = AlliancePlugin.GetAllianceNoLoading(fac); if (alliance != null) { distressCount++; AllianceChat.SendChatMessage(alliance.AllianceId, "Distress Signal", CreateGps(Context.Player.Character.GetPosition(), Color.Yellow, 600, distressCount.ToString(), reason).ToString(), true, 0); } }
public void BuyShip(int key, long BuyerId) { if (items.ContainsKey(key)) { MarketItem item = items[key]; MyIdentity SellerId = AlliancePlugin.TryGetIdentity(item.SellerSteamId.ToString()); if (SellerId != null) { EconUtils.addMoney(SellerId.IdentityId, item.Price); EconUtils.takeMoney(BuyerId, item.Price); } } }
public void PayShipyardFee(Int64 amount, ulong steamid) { bankBalance += amount; BankLog log = GetLog(); BankLogItem item = new BankLogItem(); item.SteamId = steamid; item.Amount = amount; item.Action = "shipyard fee"; item.TimeClaimed = DateTime.Now; item.BankAmount = bankBalance; log.log.Add(item); utils.WriteToJsonFile <BankLog>(AlliancePlugin.path + "//AllianceBankLogs//" + AllianceId + "//log.json", log); AlliancePlugin.SaveAllianceData(this); }
public void DoAllianceChat(string message = "") { MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId); if (fac == null) { Context.Respond("Only factions can be in alliances."); return; } PlayerData data; if (File.Exists(AlliancePlugin.path + "//PlayerData//" + Context.Player.SteamUserId + ".xml")) { data = utils.ReadFromXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + Context.Player.SteamUserId + ".xml"); } else { data = new PlayerData(); } Alliance alliance = AlliancePlugin.GetAlliance(fac); if (AllianceChat.PeopleInAllianceChat.ContainsKey(Context.Player.SteamUserId)) { data.InAllianceChat = false; AllianceChat.IdentityIds.Remove(Context.Player.SteamUserId); AllianceChat.PeopleInAllianceChat.Remove(Context.Player.SteamUserId); Context.Respond("Leaving alliance chat.", Color.Red); utils.WriteToXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + Context.Player.SteamUserId + ".xml", data); return; } if (alliance != null) { { AllianceChat.IdentityIds.Remove(Context.Player.SteamUserId); AllianceChat.IdentityIds.Add(Context.Player.SteamUserId, Context.Player.Identity.IdentityId); data.InAllianceChat = true; AllianceChat.PeopleInAllianceChat.Add(Context.Player.SteamUserId, alliance.AllianceId); Context.Respond("Entering alliance chat.", Color.Cyan); utils.WriteToXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + Context.Player.SteamUserId + ".xml", data); } } else { Context.Respond("You must be in an alliance to use alliance chat."); } }
public static void SendChatMessageFromDiscord(Guid allianceId, string prefix, string message, ulong discordId = 0) { log.Info(allianceId.ToString() + " : " + prefix + " " + message); Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceId); List <ulong> OtherMembers = new List <ulong>(); foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { MyFaction fac = MySession.Static.Factions.TryGetPlayerFaction(player.Identity.IdentityId) as MyFaction; if (fac != null) { if (alliance.AllianceMembers.Contains(fac.FactionId)) { OtherMembers.Add(player.Id.SteamId); } } } if (discordId > 0) { log.Info(allianceId.ToString() + " : " + alliance.name + " : " + prefix + " " + message + " discord id " + discordId); } else { log.Info(allianceId.ToString() + " : " + alliance.name + " : " + prefix + " " + message + " the bot"); } foreach (ulong id in OtherMembers) { ShipyardCommands.SendMessage(prefix, message, new Color(alliance.r, alliance.g, alliance.b), (long)id); MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS; if (ScanChat(message, null) != null) { MyGps gpsRef = ScanChat(message, null); gpsRef.GPSColor = Color.Yellow; gpsRef.AlwaysVisible = true; gpsRef.ShowOnHud = true; long idenId = MySession.Static.Players.TryGetIdentityId(id); MyAPIGateway.Utilities.InvokeOnGameThread(() => { gpscol.SendAddGps(idenId, ref gpsRef); }); } } }
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 string OutputMembers() { StringBuilder sb = new StringBuilder(); foreach (long id in AllianceMembers) { IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id); if (fac != null) { sb.AppendLine(fac.Tag); foreach (KeyValuePair <long, MyFactionMember> member in fac.Members) { sb.AppendLine(AlliancePlugin.GetPlayerName(MySession.Static.Players.TryGetSteamId(member.Value.PlayerId))); } sb.AppendLine(""); } } return(sb.ToString()); }
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 void CreateGate(string name, int radiusToJump = 75) { AlliancePlugin.LoadAllGates(); foreach (JumpGate tempgate in AlliancePlugin.AllGates.Values) { if (tempgate.GateName.ToLower().Equals(name.ToLower())) { Context.Respond("Gate with that name already exists!"); return; } } JumpGate gate = new JumpGate { Position = Context.Player.Character.GetPosition(), GateName = name, RadiusToJump = radiusToJump }; AlliancePlugin.AllGates.Add(gate.GateId, gate); gate.Save(); Context.Respond("Gate created. To link to another gate use !jumpgate link gateName targetName"); Context.Respond("Entry radius " + gate.RadiusToJump); }
public void ViewItemInfo(int number) { if (!list.items.ContainsKey(number)) { Context.Respond("There is no item in the market for that slot number."); return; } StringBuilder sb = new StringBuilder(); MarketItem item = list.items[number]; sb.AppendLine("Seller Name: " + AlliancePlugin.GetPlayerName(item.SellerSteamId)); sb.AppendLine("Current ID: " + number); sb.AppendLine("Name: " + item.Name); sb.AppendLine("Price: " + String.Format("{0:n0}", item.Price) + " SC."); sb.AppendLine("PCU" + item.PCU); sb.AppendLine("Grid Weight:" + String.Format("{0:n0}", item.GridMass)); sb.AppendLine("Description: " + item.Description); sb.AppendLine(""); sb.AppendLine("Blocks on grid"); foreach (KeyValuePair <string, Dictionary <string, int> > keys in item.CountsOfBlocks) { sb.AppendLine(keys.Key.Replace("MyObjectBuilder_", "")); foreach (KeyValuePair <string, int> blocks in keys.Value) { sb.AppendLine(blocks.Key.Replace("MyObjectBuilder_", "") + " " + blocks.Value); } } sb.AppendLine(""); sb.AppendLine("Cargo Items"); foreach (KeyValuePair <string, MyFixedPoint> keys in item.Cargo) { sb.AppendLine(keys.Key.ToString().Replace("MyObjectBuilder_", "") + " " + keys.Value); } DialogMessage m = new DialogMessage("The Market", "", sb.ToString()); ModCommunication.SendMessageTo(m, Context.Player.SteamUserId); }
public void UnlockKoth(string name, string allianceName = "") { foreach (KothConfig koth in AlliancePlugin.KOTHs) { if (koth.KothName.Equals(name)) { koth.nextCaptureAvailable = DateTime.Now; koth.nextCaptureInterval = DateTime.Now; koth.CaptureStarted = true; koth.nextCaptureAvailable = DateTime.Now.AddSeconds(1); // koth.owner = Guid.Empty; if (!allianceName.Equals("")) { Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceName); koth.capturingNation = alliance.AllianceId; } else { koth.capturingNation = Guid.Empty; } Context.Respond("Unlocked the koth"); } } }
public void SetFee(string name, string target, string inputAmount) { MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId); if (fac == null) { Context.Respond("Only factions can be in alliances."); return; } Int64 amount; inputAmount = inputAmount.Replace(",", ""); inputAmount = inputAmount.Replace(".", ""); inputAmount = inputAmount.Replace(" ", ""); try { amount = Int64.Parse(inputAmount); } catch (Exception) { Context.Respond("Error parsing amount", Color.Red, "Bank Man"); return; } if (amount < 0 || amount == 0) { Context.Respond("Must be a positive amount", Color.Red, "Bank Man"); return; } if (amount >= AlliancePlugin.config.MaximumGateFee) { Context.Respond("Amount exceeds the maximum of " + String.Format("{0:n0}", AlliancePlugin.config.MaximumGateFee) + " SC."); return; } Alliance alliance = AlliancePlugin.GetAlliance(fac); if (alliance == null) { Context.Respond("Only members of an alliance can set a gate fee."); return; } if (alliance != null) { if (alliance.SupremeLeader == Context.Player.SteamUserId || alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.PayFromBank)) { JumpGate gate1 = null; JumpGate gate2 = null; foreach (JumpGate gate in AlliancePlugin.AllGates.Values) { if (gate.GateName.Equals(name) && gate.OwnerAlliance == alliance.AllianceId) { gate1 = gate; continue; } if (gate.GateName.Equals(target) && gate.OwnerAlliance == alliance.AllianceId) { gate2 = gate; continue; } } if (gate1 == null || gate2 == null) { Context.Respond("Could not find one of those gates, does the alliance own it?."); return; } Context.Respond("Fee updated."); gate1.fee = amount; gate2.fee = amount; AlliancePlugin.AllGates[gate1.GateId] = gate1; AlliancePlugin.AllGates[gate2.GateId] = gate2; gate1.Save(); gate2.Save(); } else { Context.Respond("You dont have the rank to do this."); } } }
public void BuyGrid(int number) { if (!list.items.ContainsKey(number)) { Context.Respond("There is no item in the market for that slot number."); confirmations.Remove(Context.Player.IdentityId); return; } MarketItem item = list.items[number]; if (!File.Exists(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json")) { Context.Respond("That grid is no longer available for sale."); confirmations.Remove(Context.Player.IdentityId); return; } if (!File.Exists(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml")) { Context.Respond("This grid should be available, but its file for the grid doesnt exist."); confirmations.Remove(Context.Player.IdentityId); return; } if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition())) { Context.Respond("You cannot use this command in natural gravity!"); confirmations.Remove(Context.Player.IdentityId); return; } foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations) { if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius) { Context.Respond("Cannot buy here, too close to a denied location."); confirmations.Remove(Context.Player.IdentityId); return; } } if (EconUtils.getBalance(Context.Player.IdentityId) >= item.Price) { if (confirmations.ContainsKey(Context.Player.IdentityId)) { if (confirmations[Context.Player.IdentityId] >= DateTime.Now) { if (GridManager.LoadGrid(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", Context.Player.GetPosition(), false, Context.Player.SteamUserId, item.Name)) { EconUtils.takeMoney(Context.Player.IdentityId, item.Price); long sellerId = MySession.Static.Players.TryGetIdentityId(item.SellerSteamId); EconUtils.addMoney(sellerId, item.Price); if (AlliancePlugin.GridBackupInstalled) { AlliancePlugin.BackupGridMethod(GridManager.GetObjectBuilders(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"), Context.Player.IdentityId); } item.Buyer = Context.Player.SteamUserId; item.soldAt = DateTime.Now; item.Status = ItemStatus.Sold; Context.Respond("The grid should appear near you."); confirmations.Remove(Context.Player.IdentityId); if (!Directory.Exists(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId)) { Directory.CreateDirectory(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId); } list.items.Remove(number); File.Delete(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json"); utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId + "//" + item.ItemId, item); } else { Context.Respond("Failed to load the grid! transaction cancelled."); return; } } else { Context.Respond("Time ran out, start again"); confirmations[Context.Player.IdentityId] = DateTime.Now.AddSeconds(20); } } else { Context.Respond("Run command again within 20 seconds to confirm. Target grid name is " + item.Name + " Sold by " + AlliancePlugin.GetPlayerName(item.SellerSteamId)); confirmations.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(20)); Context.Respond("It costs " + String.Format("{0:n0}", item.Price) + " SC."); } } else { Context.Respond("You cannot afford that. It costs " + String.Format("{0:n0}", item.Price) + " SC."); } }
public void ViewMarket() { StringBuilder sb = new StringBuilder(); sb.AppendLine("To view information on a listing use !market info number"); sb.AppendLine("To search the market use !market search input."); sb.AppendLine("To purchase a grid from the market use !market buy number"); sb.AppendLine(""); foreach (KeyValuePair <int, MarketItem> items in list.items) { sb.AppendLine("[" + items.Key + "] " + items.Value.Name + ", Seller " + AlliancePlugin.GetPlayerName(items.Value.SellerSteamId)); } DialogMessage m = new DialogMessage("The Market", "", sb.ToString()); ModCommunication.SendMessageTo(m, Context.Player.SteamUserId); }
public void EndListing(int number) { if (!list.items.ContainsKey(number)) { Context.Respond("There is no item in the market for that slot number."); return; } MarketItem item = list.items[number]; if (!item.SellerSteamId.Equals(Context.Player.SteamUserId)) { Context.Respond("This listing doesnt belong to you."); return; } if (!File.Exists(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json")) { Context.Respond("That grid is no longer available for sale."); return; } if (!File.Exists(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml")) { Context.Respond("This grid should be available, but its file for the grid doesnt exist."); return; } if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition())) { Context.Respond("You cannot use this command in natural gravity!"); return; } foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations) { if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius) { Context.Respond("Cannot buy here, too close to a denied location."); return; } } if (GridManager.LoadGrid(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", Context.Player.GetPosition(), true, Context.Player.SteamUserId, item.Name)) { EconUtils.takeMoney(Context.Player.IdentityId, item.Price); long sellerId = MySession.Static.Players.TryGetIdentityId(item.SellerSteamId); EconUtils.addMoney(sellerId, item.Price); if (AlliancePlugin.GridBackupInstalled) { AlliancePlugin.BackupGridMethod(GridManager.GetObjectBuilders(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"), Context.Player.IdentityId); } item.Buyer = Context.Player.SteamUserId; item.soldAt = DateTime.Now; if (!Directory.Exists(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId)) { Directory.CreateDirectory(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId); } list.items.Remove(number); File.Delete(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json"); File.Delete(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"); Context.Respond("Ended the listing, the grid should appear near you."); } else { Context.Respond("Failed to load the grid! transaction cancelled."); return; } }
public void UnlockKoth() { AlliancePlugin.LoadConfig(); Context.Respond("Reloaded"); }
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); }
public static void DoChatMessage(TorchChatMessage msg, ref bool consumed) { if (msg.AuthorSteamId == null) { return; } if (msg.Channel == Sandbox.Game.Gui.ChatChannel.Private || msg.Channel == Sandbox.Game.Gui.ChatChannel.Faction) { return; } if (msg.Message.StartsWith("!")) { return; } if (PeopleInAllianceChat.ContainsKey((ulong)msg.AuthorSteamId)) { MyIdentity identity; if (IdentityIds.ContainsKey((ulong)msg.AuthorSteamId)) { identity = MySession.Static.Players.TryGetIdentity(IdentityIds[(ulong)msg.AuthorSteamId]); } else { identity = AlliancePlugin.GetIdentityByNameOrId(msg.AuthorSteamId.ToString()); } if (identity == null) { return; } MyFaction fac = MySession.Static.Factions.GetPlayerFaction(identity.IdentityId); if (fac == null) { bool noFac = true; if (AlliancePlugin.GetIdentityByNameOrId(msg.Author) != null) { if (MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId) != null) { noFac = false; fac = MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId); } } if (noFac) { PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); AlliancePlugin.SendChatMessage("Failsafe", "Faction null"); } return; } if (AlliancePlugin.GetAllianceNoLoading(fac) == null) { PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); AlliancePlugin.SendChatMessage("Failsafe", "Alliance null"); return; } consumed = true; Guid allianceId = PeopleInAllianceChat[(ulong)msg.AuthorSteamId]; List <ulong> OtherMembers = new List <ulong>(); Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceId); // ShipyardCommands.SendMessage(msg.Author, "You are in alliance chat", Color.BlueViolet, (long)msg.AuthorSteamId); if (alliance.GetTitle((ulong)msg.AuthorSteamId).Equals("")) { SendChatMessage(allianceId, msg.Author, msg.Message, true, identity.IdentityId); } else { SendChatMessage(allianceId, alliance.GetTitle((ulong)msg.AuthorSteamId) + " | " + msg.Author, msg.Message, true, identity.IdentityId); } } else { // PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); } }
public static bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D playerPosition, bool keepOriginalLocation, long steamID, string Name, CommandContext context = null, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { Log.Warn("No grids in blueprint!"); if (context != null) { context.Respond("No grids in blueprint!"); } return(false); } foreach (var grid in grids) { foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks) { long ownerID = AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).IdentityId; block.Owner = ownerID; block.BuiltBy = ownerID; } } List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList()); if (!keepOriginalLocation) { /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(grids, playerPosition); if (pos == null) { Log.Warn("No free Space found!"); if (context != null) { context.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)) { if (context != null) { context.Respond("The File to be imported does not seem to be compatible with the server!"); } return(false); } Sandbox.Game.Entities.Character.MyCharacter player = MySession.Static.Players.GetPlayerByName(AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).DisplayName).Character; MyGps gps = CreateGps(pos.Value, Color.LightGreen, 60, Name); MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS; MyGps gpsRef = gps; long entityId = 0L; entityId = gps.EntityId; gpsCollection.SendAddGps(player.GetPlayerIdentityId(), ref gpsRef, entityId, true); } else if (!force) { var sphere = FindBoundingSphere(grids); var position = grids[0].PositionAndOrientation.Value; sphere.Center = position.Position; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities); foreach (var entity in entities) { if (entity is MyCubeGrid) { if (context != null) { context.Respond("There are potentially other grids in the way. If you are certain is free you can set 'force' to true!"); } return(false); } } } /* Stop grids */ foreach (var grid in grids) { grid.AngularVelocity = new SerializableVector3(); grid.LinearVelocity = new SerializableVector3(); Random random = new Random(); } /* Remapping to prevent any key problems upon paste. */ MyEntities.RemapObjectBuilderCollection(objectBuilderList); bool hasMultipleGrids = objectBuilderList.Count > 1; if (!hasMultipleGrids) { foreach (var ob in objectBuilderList) { MyEntities.CreateFromObjectBuilderParallel(ob, true); } } else { MyEntities.Load(objectBuilderList, out _); } return(true); }
public void DoTags() { Dictionary <String, String> tagsAndNames = new Dictionary <string, string>(); Dictionary <String, String> friends = new Dictionary <string, string>(); Dictionary <String, String> neutrals = new Dictionary <string, string>(); Dictionary <String, String> alliances = new Dictionary <String, string>(); foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { string name = MyMultiplayer.Static.GetMemberName(player.Id.SteamId); MyIdentity identity = AlliancePlugin.GetIdentityByNameOrId(player.Id.SteamId.ToString()); if (FacUtils.GetPlayersFaction(player.Identity.IdentityId) != null) { IMyFaction playerFac = null; if (FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId) != null) { playerFac = FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId); } if (playerFac == null) { Context.Respond("Make a faction. This command does not work without being in a faction."); return; } if (FacUtils.GetPlayersFaction(player.Identity.IdentityId) == null) { continue; } Alliance alliance = AlliancePlugin.GetAllianceNoLoading(FacUtils.GetPlayersFaction(player.Identity.IdentityId) as MyFaction); if (alliance != null) { if (alliances.ContainsKey(alliance.name)) { alliances.TryGetValue(alliance.name, out String temp); if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } alliances.Remove(alliance.name); alliances.Add(alliance.name, temp); } else { String temp = ""; if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } alliances.Add(alliance.name, temp); } } else { if (friends.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag)) { friends.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp); if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } friends.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag); friends.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp); } if (MySession.Static.Factions.AreFactionsEnemies(playerFac.FactionId, FacUtils.GetPlayersFaction(player.Identity.IdentityId).FactionId)) { if (tagsAndNames.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag)) { tagsAndNames.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp); if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } tagsAndNames.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag); tagsAndNames.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp); } else { String temp = ""; if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } tagsAndNames.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp); } } else { if (neutrals.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag)) { neutrals.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp); if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } neutrals.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag); neutrals.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp); } else { String temp = ""; if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)"; } else { if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId)) { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)"; } else { temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName; } } neutrals.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp); } } } } } var sb = new StringBuilder(); foreach (KeyValuePair <String, String> keys in alliances) { sb.AppendLine(keys.Key); sb.AppendLine(keys.Value); sb.AppendLine(""); } sb.Append("At War"); foreach (KeyValuePair <String, String> keys in tagsAndNames) { sb.Append(keys.Value); } sb.Append("\n "); sb.Append("\n Friends"); foreach (KeyValuePair <String, String> keys in friends) { sb.Append(keys.Value); } sb.Append("\n "); sb.Append("\n Neutral"); foreach (KeyValuePair <String, String> keys in neutrals) { sb.Append(keys.Value); } DialogMessage m = new DialogMessage("Tags of online players", "", sb.ToString()); ModCommunication.SendMessageTo(m, Context.Player.SteamUserId); }
public static MyObjectBuilder_ShipBlueprintDefinition[] getBluePrint(string name, long newOwner, bool keepProjection, List <MyCubeGrid> grids) { List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>(); foreach (MyCubeGrid grid in grids) { /* What else should it be? LOL? */ if (!(grid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder)) { throw new ArgumentException(grid + " has a ObjectBuilder thats not for a CubeGrid"); } objectBuilders.Add(objectBuilder); } MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>(); definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), name); definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray(); /* Reset ownership as it will be different on the new server anyway */ foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids) { cubeGrid.DisplayName = newOwner.ToString(); foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks) { long ownerID = AlliancePlugin.GetIdentityByNameOrId(newOwner.ToString()).IdentityId; cubeBlock.Owner = ownerID; cubeBlock.BuiltBy = ownerID; /* Remove Projections if not needed */ if (!keepProjection) { if (cubeBlock is MyObjectBuilder_ProjectorBase projector) { projector.ProjectedGrid = null; projector.ProjectedGrids = null; } } /* Remove Pilot and Components (like Characters) from cockpits */ if (cubeBlock is MyObjectBuilder_Cockpit cockpit) { cockpit.Pilot = null; if (cockpit.ComponentContainer != null) { var components = cockpit.ComponentContainer.Components; if (components != null) { for (int i = components.Count - 1; i >= 0; i--) { var component = components[i]; if (component.TypeId == "MyHierarchyComponentBase") { components.RemoveAt(i); continue; } } } } } } } MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>(); builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition }; return(builderDefinition.ShipBlueprints); }
public void RentGate(string name) { MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId); if (fac == null) { Context.Respond("Only factions can be in alliances."); return; } Alliance alliance = AlliancePlugin.GetAlliance(fac); if (alliance == null) { Context.Respond("Only members of an alliance may rent a gate."); return; } if (alliance != null) { if (alliance.SupremeLeader == Context.Player.SteamUserId || alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.PayFromBank)) { JumpGate gate1 = null; JumpGate gate2 = null; AlliancePlugin.LoadAllGates(); foreach (JumpGate gate in AlliancePlugin.AllGates.Values) { if (gate.GateName.Equals(name) && gate.CanBeRented && DateTime.Now >= gate.NextRentAvailable) { gate1 = gate; gate2 = AlliancePlugin.AllGates[gate.TargetGateId]; break; } } if (gate1 == null || gate2 == null) { Context.Respond("Could not find one of those gates."); return; } if (alliance.CurrentMetaPoints >= gate1.MetaPointRentCost) { alliance.CurrentMetaPoints -= gate1.MetaPointRentCost; gate1.OwnerAlliance = alliance.AllianceId; gate2.OwnerAlliance = alliance.AllianceId; gate1.NextRentAvailable = DateTime.Now.AddDays(gate1.DaysPerRent); gate2.NextRentAvailable = DateTime.Now.AddDays(gate1.DaysPerRent); AlliancePlugin.AllGates[gate1.GateId] = gate1; AlliancePlugin.AllGates[gate2.GateId] = gate2; gate1.Save(); gate2.Save(); Context.Respond("Successfully rented gate for " + gate1.DaysPerRent + " Days. Fees can now be set with !jumpgate fee <gateName> <amount>"); Context.Respond("Gate names, " + gate1.GateName + ", " + gate2.GateName); AlliancePlugin.SaveAllianceData(alliance); return; } else { Context.Respond("Cannot afford the meta point cost of " + gate1.MetaPointRentCost); return; } } else { Context.Respond("You dont have the rank to do this."); } } }
public string OutputAlliance() { StringBuilder sb = new StringBuilder(); sb.AppendLine(description); sb.AppendLine(""); bankBalance = DatabaseForBank.GetBalance(AllianceId); sb.AppendLine("Bank Balance : " + String.Format("{0:n0}", bankBalance) + " SC."); if (failedUpkeep > 0) { sb.AppendLine("Failed Upkeep : " + this.failedUpkeep + " Deleted at " + AlliancePlugin.config.UpkeepFailBeforeDelete); } sb.AppendLine("Expected Upkeep Value :" + String.Format("{0:n0}", this.GetUpkeep()) + " SC."); sb.AppendLine(""); sb.AppendLine("Meta Points : " + String.Format("{0:n0}", CurrentMetaPoints)); sb.AppendLine(""); sb.AppendLine(LeaderTitle); sb.AppendLine(AlliancePlugin.GetPlayerName(SupremeLeader)); StringBuilder perms = new StringBuilder(); foreach (KeyValuePair <String, RankPermissions> customs in CustomRankPermissions) { perms.Clear(); foreach (AccessLevel level in customs.Value.permissions) { perms.Append(level.ToString() + ", "); } sb.AppendLine(""); sb.AppendLine(customs.Key + " Permissions : " + perms.ToString()); sb.AppendLine(customs.Key + " tax rate : " + CustomRankPermissions[customs.Key].taxRate * 100 + "%"); } sb.AppendLine(""); perms.Clear(); foreach (AccessLevel level in UnrankedPerms.permissions) { perms.Append(level.ToString() + ", "); } sb.AppendLine("Unranked Permissions : " + perms.ToString()); sb.AppendLine("Unranked tax rate : " + UnrankedPerms.taxRate * 100 + "%"); sb.AppendLine(""); otherTitlesDic.Clear(); foreach (KeyValuePair <ulong, String> titles in PlayersCustomRank) { if (otherTitlesDic.ContainsKey(titles.Value)) { otherTitlesDic[titles.Value].AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key)); } else { StringBuilder sbb = new StringBuilder(); sbb.AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key)); otherTitlesDic.Add(titles.Value, sbb); } } foreach (KeyValuePair <String, StringBuilder> key in otherTitlesDic) { sb.AppendLine(key.Value.ToString()); } otherTitlesDic.Clear(); foreach (KeyValuePair <ulong, String> titles in otherTitles) { if (otherTitlesDic.ContainsKey(titles.Value)) { otherTitlesDic[titles.Value].AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key)); } else { StringBuilder sbb = new StringBuilder(); sbb.AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key)); otherTitlesDic.Add(titles.Value, sbb); } } foreach (KeyValuePair <String, StringBuilder> key in otherTitlesDic) { sb.AppendLine(key.Value.ToString()); } sb.AppendLine(""); sb.AppendLine("Hostile Factions and Hostile Alliances"); foreach (long id in EnemyFactions) { IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id); if (fac != null) { sb.AppendLine(fac.Tag); } foreach (String s in enemies) { sb.AppendLine(s); } } sb.AppendLine(""); sb.AppendLine("Member Factions"); int memberCount = 0; foreach (long id in AllianceMembers) { IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id); if (fac != null) { sb.AppendLine(fac.Tag + " - " + fac.Members.Count + " members"); memberCount += fac.Members.Count; } } sb.AppendLine("Total Members " + memberCount); sb.AppendLine(""); sb.AppendLine("Pending invites"); foreach (long id in Invites) { IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id); if (fac != null) { sb.AppendLine(fac.Name + " - " + fac.Tag); } } return(sb.ToString()); }
//public static void testConnection() //{ // MySqlConnection conn = new MySqlConnection(connStr); // try // { // AlliancePlugin.Log.Info("Connecting to MySQL..."); // conn.Open(); // string sql = "CREATE DATABASE IF NOT EXISTS AllianceBank"; // MySqlCommand cmd = new MySqlCommand(sql, conn); // cmd.ExecuteNonQuery(); // sql = "CREATE TABLE IF NOT EXISTS AllianceBank.BankBalances(allianceId CHAR(36) PRIMARY KEY, balance BIGINT)"; // cmd = new MySqlCommand(sql, conn); // cmd.ExecuteNonQuery(); // AlliancePlugin.Log.Info("Created the tables if it needed to"); // } // catch (Exception ex) // { // ReadyToSave = false; // conn.Close(); // AlliancePlugin.Log.Error("Error connecting to database, disabling bank features."); // AlliancePlugin.Log.Error(ex); // } // conn.Close(); // AlliancePlugin.Log.Info("Successfully connected to database!"); //} public static void DoUpkeepForOne(Alliance alliance) { try { using (var db = new LiteDatabase(connectionString)) { var collection = db.GetCollection <BankData>("BankData"); FileUtils jsonStuff = new FileUtils(); jsonStuff.WriteToJsonFile <Alliance>(AlliancePlugin.path + "//UpkeepBackups//" + alliance.AllianceId + ".json", alliance); var bank = collection.FindById(alliance.AllianceId); if (bank == null) { bank = new BankData { Id = alliance.AllianceId, balance = 1 }; collection.Insert(bank); alliance.failedUpkeep++; if (alliance.failedUpkeep >= AlliancePlugin.config.UpkeepFailBeforeDelete) { AllianceChat.SendChatMessage(alliance.AllianceId, "Upkeep", "Upkeep failed, met the threshold for delete. Deleting Alliance.", true, 0); AlliancePlugin.AllAlliances.Remove(alliance.name); File.Delete(AlliancePlugin.path + "//AllianceData//" + alliance.AllianceId + ".json"); foreach (long id in alliance.AllianceMembers) { AlliancePlugin.FactionsInAlliances.Remove(id); } } else { AllianceChat.SendChatMessage(alliance.AllianceId, "Upkeep", "Upkeep failed, Upgrades disabled.", true, 0); } } else { if (bank.balance >= alliance.GetUpkeep()) { bank.balance -= alliance.GetUpkeep(); collection.Update(bank); AllianceChat.SendChatMessage(alliance.AllianceId, "Upkeep", "Paying upkeep of " + String.Format("{0:n0}", alliance.GetUpkeep()) + " SC.", true, 0); alliance.Upkeep(alliance.GetUpkeep(), 1); alliance.bankBalance -= alliance.GetUpkeep(); alliance.failedUpkeep = 0; AlliancePlugin.SaveAllianceData(alliance); } else { alliance.failedUpkeep++; if (alliance.failedUpkeep >= AlliancePlugin.config.UpkeepFailBeforeDelete) { AllianceChat.SendChatMessage(alliance.AllianceId, "Upkeep", "Upkeep failed, met the threshold for delete. Deleting Alliance.", true, 0); AlliancePlugin.AllAlliances.Remove(alliance.name); File.Delete(AlliancePlugin.path + "//AllianceData//" + alliance.AllianceId + ".json"); foreach (long id in alliance.AllianceMembers) { AlliancePlugin.FactionsInAlliances.Remove(id); } } else { AllianceChat.SendChatMessage(alliance.AllianceId, "Upkeep", "Upkeep failed, Upgrades disabled.", true, 0); } } } } } catch (Exception ex) { AlliancePlugin.Log.Error("Error for all upkeep"); AlliancePlugin.Log.Error(ex); return; } }
public void CreateGate() { AlliancePlugin.LoadAllGates(); Context.Respond("Refreshed the gates!"); Context.Respond(AlliancePlugin.AllGates.Count + " Gates Loaded"); }