public static void GridOfferBought(MarketListing NewOffer, ulong Buyer) { if (!NexusSupport.RunningNexus) { return; } string Title = "Hangar Market - Offer Purchased"; if (!MySession.Static.Players.TryGetIdentityFromSteamID(NewOffer.SteamID, out MyIdentity Seller)) { return; } if (!MySession.Static.Players.TryGetIdentityFromSteamID(NewOffer.SteamID, out MyIdentity BuyerIdentity)) { return; } var Fac = MySession.Static.Factions.GetPlayerFaction(Seller.IdentityId); var BuyerFac = MySession.Static.Factions.GetPlayerFaction(BuyerIdentity.IdentityId); string Footer; if (Fac != null) { Footer = $"Seller: [{Fac.Tag}] {Seller.DisplayName}"; } else { Footer = $"Seller: {Seller.DisplayName}"; } StringBuilder Msg = new StringBuilder(); if (BuyerFac != null) { Msg.AppendLine($"Grid {NewOffer.Name} was purchased by [{BuyerFac.Tag}] {BuyerIdentity.DisplayName} for {NewOffer.Price}sc!"); } else { Msg.AppendLine($"Grid {NewOffer.Name} was purchased by {BuyerIdentity.DisplayName} for {NewOffer.Price}sc!"); } NexusAPI.SendEmbedMessageToDiscord(Hangar.Config.MarketUpdateChannel, Title, Msg.ToString(), Footer, "#FFFF00"); }
private static void GetReadMarketFile(string FilePath, out MarketListing Listing) { //Reads market file from path using var fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); using var sr = new StreamReader(fs, Encoding.UTF8); string Data = sr.ReadToEnd(); Listing = JsonConvert.DeserializeObject <MarketListing>(File.ReadAllText(FilePath)); }
/* Following are for discord status messages */ public static void NewGridOfferListed(MarketListing NewOffer) { if (!NexusSupport.RunningNexus) { return; } string Title = "Hangar Market - New Offer"; StringBuilder Msg = new StringBuilder(); Msg.AppendLine($"GridName: {NewOffer.Name}"); Msg.AppendLine($"Price: {NewOffer.Price}sc"); Msg.AppendLine($"PCU: {NewOffer.PCU}"); Msg.AppendLine($"Mass: {NewOffer.GridMass}kg"); Msg.AppendLine($"Jump Distance: {NewOffer.JumpDistance}m"); Msg.AppendLine($"Number Of Blocks: {NewOffer.NumberofBlocks}"); Msg.AppendLine($"PowerOutput: {NewOffer.MaxPowerOutput / 1000}kW"); Msg.AppendLine($"Built-Percent: {NewOffer.GridBuiltPercent * 100}%"); Msg.AppendLine($"Total Grids: {NewOffer.NumberOfGrids}"); Msg.AppendLine($"Static Grids: {NewOffer.StaticGrids}"); Msg.AppendLine($"Large Grids: {NewOffer.LargeGrids}"); Msg.AppendLine($"Small Grids: {NewOffer.SmallGrids}"); Msg.AppendLine(); Msg.AppendLine($"Description: {NewOffer.Description}"); if (!MySession.Static.Players.TryGetIdentityFromSteamID(NewOffer.SteamID, out MyIdentity Player)) { return; } var Fac = MySession.Static.Factions.GetPlayerFaction(Player.IdentityId); string Footer; if (Fac != null) { Footer = $"Seller: [{Fac.Tag}] {Player.DisplayName}"; } else { Footer = $"Seller: {Player.DisplayName}"; } NexusAPI.SendEmbedMessageToDiscord(Hangar.Config.MarketUpdateChannel, Title, Msg.ToString(), Footer, "#FFFF00"); }
private static bool ValidGrid(ulong Owner, string GridName, out MarketListing Offer, out string GridPath) { GridPath = string.Empty; string FileName = GetNameFormat(Owner, GridName); if (!MarketOffers.TryGetValue(FileName, out Offer)) { return(false); } //Check if file exsists if (!File.Exists(Path.Combine(MarketFolderDir, FileName))) { //Someone this happened? MarketOffers.TryRemove(FileName, out _); return(false); } if (Offer.ServerOffer) { GridPath = Offer.FileSBCPath; } else { string FolderPath; //Log.Error("3"); FolderPath = Path.Combine(Hangar.MainPlayerDirectory, Owner.ToString()); GridPath = Path.Combine(FolderPath, GridName + ".sbc"); } //Confirm files exsits if (!File.Exists(GridPath)) { RemoveMarketListing(Owner, GridName); return(false); } return(true); }
public static bool SaveNewMarketFile(MarketListing NewListing) { //Saves a new market listing string FileName = GetNameFormat(NewListing.SteamID, NewListing.Name); try { //Save new market offer File.WriteAllText(Path.Combine(MarketFolderDir, FileName), JsonConvert.SerializeObject(NewListing, Formatting.Indented)); return(true); } catch (Exception ex) { Log.Error(ex); return(false); } }
private static void PurchasePlayerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity, ulong Owner) { //Log.Error("A"); if (!MySession.Static.Players.TryGetIdentityFromSteamID(Owner, out MyIdentity OwnerIdentity)) { return; } //Have a successfull buy RemoveMarketListing(Owner, Offer.Name); //Transfer grid if (PlayerHangar.TransferGrid(Owner, Buyer, Offer.Name)) { Chat.Send($"Successfully purchased {Offer.Name} from {OwnerIdentity.DisplayName}! Check your hangar!", Buyer); MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price); MyBankingSystem.ChangeBalance(OwnerIdentity.IdentityId, Offer.Price); } }
private static void PurchaseServerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity) { if (!File.Exists(Offer.FileSBCPath)) { Log.Error($"{Offer.FileSBCPath} doesnt exsist! Was this removed prematurely?"); return; } var ToInfo = new PlayerInfo(); ToInfo.LoadFile(Hangar.MainPlayerDirectory, Buyer); //Log.Error("TotalBuys: " + ToInfo.GetServerOfferPurchaseCount(Offer.Name)); if (Offer.TotalPerPlayer != 0 && ToInfo.GetServerOfferPurchaseCount(Offer.Name) >= Offer.TotalPerPlayer) { Chat.Send($"You have reached your buy limit for this offer!", Buyer); return; } GridStamp Stamp = new GridStamp(Offer.FileSBCPath); Stamp.GridName = Offer.Name; //Log.Error("C"); if (PlayerHangar.TransferGrid(ToInfo, Stamp)) { //Log.Error("Changing Balance"); MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price); Chat.Send($"Successfully purchased {Offer.Name}! Check your hangar!", Buyer); GridOfferBought(Offer, Buyer); //Hangar.Config.RefreshModel(); } }
public static void GirdOfferRemoved(MarketListing NewOffer) { if (!NexusSupport.RunningNexus) { return; } string Title = "Hangar Market - Offer Removed"; if (!MySession.Static.Players.TryGetIdentityFromSteamID(NewOffer.SteamID, out MyIdentity Player)) { return; } StringBuilder Msg = new StringBuilder(); Msg.AppendLine($"Grid {NewOffer.Name} is no longer for sale!"); var Fac = MySession.Static.Factions.GetPlayerFaction(Player.IdentityId); string Footer; if (Fac != null) { Footer = $"Seller: [{Fac.Tag}] {Player.DisplayName}"; } else { Footer = $"Seller: {Player.DisplayName}"; } NexusAPI.SendEmbedMessageToDiscord(Hangar.Config.MarketUpdateChannel, Title, Msg.ToString(), Footer, "#FFFF00"); }