public void AddTag(int number, string tag) { 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; } string[] split = Context.RawArgs.Split(' '); int count = 0; foreach (String s in split) { if (count <= 1) { count++; continue; } item.AddTag(s); } utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json", item); }
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 ChangeDescription(int number, string description) { 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; } item.Description = description; Context.Respond("Description updated."); utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json", item); }
public Boolean AddItem(MarketItem item) { bool added = false; int attempt = count += 1; while (!added) { if (!items.ContainsKey(attempt)) { items.Add(attempt, item); count = attempt; return(true); } attempt++; } return(false); }
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 RefreshList() { tempKeys.Clear(); foreach (KeyValuePair <int, MarketItem> i in items) { if (!tempKeys.ContainsKey(i.Value.ItemId)) { tempKeys.Add(i.Value.ItemId, i.Key); } } items.Clear(); foreach (String s in Directory.GetFiles(AlliancePlugin.path + "//ShipMarket//ForSale")) { MarketItem item = utils.ReadFromJsonFile <MarketItem>(s); if (tempKeys.ContainsKey(item.ItemId)) { items.Add(tempKeys[item.ItemId], item); } else { AddItem(item); } } }
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 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 Sell(string price, string name) { 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 sell here, too close to a denied location."); confirmations.Remove(Context.Player.IdentityId); return; } } Int64 amount; price = price.Replace(",", ""); price = price.Replace(".", ""); price = price.Replace(" ", ""); try { amount = Int64.Parse(price); } 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; } ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group> gridWithSubGrids = GridFinder.FindLookAtGridGroupMechanical(Context.Player.Character); List <MyCubeGrid> grids = new List <MyCubeGrid>(); foreach (var item1 in gridWithSubGrids) { foreach (MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Node groupNodes in item1.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, false)) { if (!grids.Contains(grid)) { foreach (MySurvivalKit block in grid.GetFatBlocks().OfType <MySurvivalKit>()) { block.CustomData = "Custom Data was cleared."; } foreach (MyMedicalRoom block in grid.GetFatBlocks().OfType <MyMedicalRoom>()) { block.CustomData = "Custom Data was cleared."; } List <MyProgrammableBlock> removeThese = new List <MyProgrammableBlock>(); foreach (MyProgrammableBlock block in grid.GetFatBlocks().OfType <MyProgrammableBlock>()) { removeThese.Add(block); } foreach (MyProgrammableBlock block in removeThese) { grid.RemoveBlock(block.SlimBlock); } grids.Add(grid); } } } } if (grids.Count == 0) { Context.Respond("Could not find any grids you own. Are you looking directly at it?"); return; } MarketItem item = new MarketItem(); item.Setup(grids, name, amount, Context.Player.SteamUserId); if (list.AddItem(item)) { if (GridManager.SaveGridNoDelete(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", item.ItemId.ToString(), false, false, grids)) { Context.Respond("Added the item to the market!"); utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json", item); foreach (MyCubeGrid grid in grids) { if (grid != null) { grid.Close(); } } } } else { Context.Respond("Failed to add the grid to the market. Try again."); } }