public static SendMessage ( ulong steamId, string title, string prefix, string content ) : void | ||
steamId | ulong | |
title | string | |
prefix | string | |
content | string | |
Результат | void |
public override void ProcessServer() { var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); if (player != null && player.IsAdmin()) // hold on there, are we an admin first? { var description = new StringBuilder(); var index = 1; //probably should add column headings too.. ie number, opened, name, balance, lastseen etc foreach (var account in EconomyScript.Instance.Data.Clients.OrderBy(s => s.NickName)) { description.AppendFormat("#{0}: {1} : {2} : {3}\r\n", index++, account.NickName, account.BankBalance, account.Date); // TODO: https://github.com/jpcsupplies/Economy_mod/issues/54 } MessageClientDialogMessage.SendMessage(SenderSteamId, "List Accounts", string.Format("Count: {0}", EconomyScript.Instance.Data.Clients.Count), description.ToString()); // update our own timestamp here AccountManager.UpdateLastSeen(SenderSteamId, SenderLanguage); } }
public override void ProcessServer() { var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); // Only Admin can change Npc Market prices. if (!player.IsAdmin() && MarketId == EconomyConsts.NpcMerchantId) { EconomyScript.Instance.ServerLogger.WriteWarning("A Player without Admin \"{0}\" {1} attempted to set Default Market characteristics of item {2}/{3} to Quantity={4}.", SenderDisplayName, SenderSteamId, ItemTypeId, ItemSubTypeName, ItemQuantity); return; } // Only Player can change their own Market prices. if (SenderSteamId != MarketId && MarketId != EconomyConsts.NpcMerchantId) { EconomyScript.Instance.ServerLogger.WriteWarning("A Player \"{0}\" {1} attempted to set another Market characteristics of item {2}/{3} to Quantity={4}.", SenderDisplayName, SenderSteamId, ItemTypeId, ItemSubTypeName, ItemQuantity); return; } // TODO: do we check range to market? MyDefinitionBase definition = null; MyObjectBuilderType result; if (MyObjectBuilderType.TryParse(ItemTypeId, out result)) { var id = new MyDefinitionId(result, ItemSubTypeName); MyDefinitionManager.Static.TryGetDefinition(id, out definition); } if (definition == null) { // Passing bad data? MessageClientTextMessage.SendMessage(SenderSteamId, "SET", "Sorry, the item you specified doesn't exist!"); return; } if (SetType.HasFlag(SetMarketItemType.Quantity)) { // Do a floating point check on the item item. Tools and components cannot have decimals. They must be whole numbers. if (definition.Id.TypeId != typeof(MyObjectBuilder_Ore) && definition.Id.TypeId != typeof(MyObjectBuilder_Ingot)) { if (ItemQuantity != Math.Truncate(ItemQuantity)) { MessageClientTextMessage.SendMessage(SenderSteamId, "SET", "You must provide a whole number for the quantity of that item."); return; } //ItemQuantity = Math.Round(ItemQuantity, 0); // Or do we just round the number? } if (ItemQuantity <= 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "SET", "Invalid quantity specified"); return; } } // Find the specified market. List <MarketStruct> markets; if (string.IsNullOrEmpty(MarketZone)) { var character = player.GetCharacter(); if (character == null) { // Player has no body. Could mean they are dead. MessageClientTextMessage.SendMessage(SenderSteamId, "SET", "There is no market at your location to set."); return; } var position = ((IMyEntity)character).WorldMatrix.Translation; markets = MarketManager.FindMarketsFromLocation(position).Where(m => m.MarketId == MarketId).ToList(); } else { markets = EconomyScript.Instance.Data.Markets.Where(m => m.MarketId == MarketId && (MarketZone == "*" || m.DisplayName.Equals(MarketZone, StringComparison.InvariantCultureIgnoreCase))).ToList(); } if (markets.Count == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "SET", "Sorry, you are not near any markets currently or the market does not exist!"); return; } var msg = new StringBuilder(); msg.AppendFormat("Applying changes to : '{0}' {1}/{2}\r\n\r\n", definition.GetDisplayName(), ItemTypeId, ItemSubTypeName); foreach (var market in markets) { msg.AppendFormat("Market: '{0}'\r\n", market.DisplayName); var marketItem = market.MarketItems.FirstOrDefault(e => e.TypeId == ItemTypeId && e.SubtypeName == ItemSubTypeName); if (marketItem == null) { msg.AppendLine("Sorry, the items you are trying to set doesn't have a market entry!"); // In reality, this shouldn't happen as all markets have their items synced up on start up of the mod. continue; } if (SetType.HasFlag(SetMarketItemType.Quantity)) { marketItem.Quantity = ItemQuantity; msg.AppendFormat("Stock on hand to {0} units", ItemQuantity); } // Validation to prevent admins setting prices too low for items. if (SetType.HasFlag(SetMarketItemType.BuyPrice)) { if (ItemBuyPrice >= 0) { marketItem.BuyPrice = ItemBuyPrice; msg.AppendFormat("Buy price to {0}", ItemBuyPrice); } else { msg.AppendFormat("Could not set buy price to less than 0."); } } // Validation to prevent admins setting prices too low for items. if (SetType.HasFlag(SetMarketItemType.SellPrice)) { if (ItemSellPrice >= 0) { marketItem.SellPrice = ItemSellPrice; msg.AppendFormat("Sell price to {0}", ItemSellPrice); } else { msg.AppendFormat("Could not set sell price to less than 0."); } } if (SetType.HasFlag(SetMarketItemType.Blacklisted)) { marketItem.IsBlacklisted = !marketItem.IsBlacklisted; msg.AppendFormat("Blacklist to {0}", marketItem.IsBlacklisted ? "On" : "Off"); } msg.AppendLine(); msg.AppendLine(); } #region update config for the item MarketItemStruct configItem = null; if (player.IsAdmin() && MarketId == EconomyConsts.NpcMerchantId) { configItem = EconomyScript.Instance.ServerConfig.DefaultPrices.FirstOrDefault(e => e.TypeId == ItemTypeId && e.SubtypeName == ItemSubTypeName); } if (configItem != null) { if (SetType.HasFlag(SetMarketItemType.BuyPrice)) { if (ItemBuyPrice >= 0) { configItem.BuyPrice = ItemBuyPrice; msg.AppendFormat("Config updated Buy price to {0}", ItemBuyPrice); } } // Validation to prevent admins setting prices too low for items. if (SetType.HasFlag(SetMarketItemType.SellPrice)) { if (ItemSellPrice >= 0) { configItem.SellPrice = ItemSellPrice; msg.AppendFormat("Config updated Sell price to {0}", ItemSellPrice); } } if (SetType.HasFlag(SetMarketItemType.Blacklisted)) { configItem.IsBlacklisted = !configItem.IsBlacklisted; msg.AppendFormat("Config updated Blacklist to {0}", configItem.IsBlacklisted ? "On" : "Off"); // If config blacklisted, then all markets should be updated. if (configItem.IsBlacklisted) { int counter = 0; foreach (var market in EconomyScript.Instance.Data.Markets) { var marketItem = market.MarketItems.FirstOrDefault(e => e.TypeId == ItemTypeId && e.SubtypeName == ItemSubTypeName); if (marketItem != null && !marketItem.IsBlacklisted) { counter++; marketItem.IsBlacklisted = true; } } msg.AppendFormat("Config updated {0} Markets to also Blacklist to {1}.", counter, configItem.IsBlacklisted ? "On" : "Off"); } } } #endregion MessageClientDialogMessage.SendMessage(SenderSteamId, "SET", " ", msg.ToString()); }
public override void ProcessServer() { // update our own timestamp here AccountManager.UpdateLastSeen(SenderSteamId, SenderLanguage); EconomyScript.Instance.ServerLogger.WriteVerbose("Manage Npc Market Request for from '{0}'", SenderSteamId); var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); if (player == null || !player.IsAdmin()) // hold on there, are we an admin first? { return; } switch (CommandType) { case NpcMarketManage.Add: { if (string.IsNullOrWhiteSpace(MarketName) || MarketName == "*") { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC ADD", "Invalid name supplied for the market name."); return; } var checkMarket = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.DisplayName.Equals(MarketName, StringComparison.InvariantCultureIgnoreCase)); if (checkMarket != null) { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC ADD", "A market of name '{0}' already exists.", checkMarket.DisplayName); return; } // TODO: market inside market check? EconDataManager.CreateNpcMarket(MarketName, X, Y, Z, Size, Shape); MessageClientTextMessage.SendMessage(SenderSteamId, "NPC ADD", "A new market called '{0}' has been created.", MarketName); } break; case NpcMarketManage.Delete: { var market = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.DisplayName.Equals(MarketName, StringComparison.InvariantCultureIgnoreCase)); if (market == null) { var markets = EconomyScript.Instance.Data.Markets.Where(m => m.DisplayName.IndexOf(MarketName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray(); if (markets.Length == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC DELETE", "The specified market name could not be found."); return; } if (markets.Length > 1) { var str = new StringBuilder(); str.Append("The specified market name could not be found.\r\n Which did you mean?\r\n"); foreach (var m in markets) { str.AppendLine(m.DisplayName); } MessageClientDialogMessage.SendMessage(SenderSteamId, "NPC DELETE", " ", str.ToString()); return; } market = markets[0]; } EconomyScript.Instance.Data.Markets.Remove(market); MessageClientTextMessage.SendMessage(SenderSteamId, "NPC DELETE", "The market '{0}' has been removed and all inventory.", market.DisplayName); } break; case NpcMarketManage.List: { var str = new StringBuilder(); foreach (var market in EconomyScript.Instance.Data.Markets) { if (market.MarketId != EconomyConsts.NpcMerchantId) { continue; } str.AppendFormat("Market: {0}\r\n", market.DisplayName); str.AppendFormat("{0}", market.MarketZoneType); if (market.MarketZoneType == MarketZoneType.FixedSphere && market.MarketZoneSphere.HasValue) { str.AppendFormat(" Center Position=X:{0:N} | Y:{1:N} | Z:{2:N} Radius={3:N}m\r\n\r\n", market.MarketZoneSphere.Value.Center.X, market.MarketZoneSphere.Value.Center.Y, market.MarketZoneSphere.Value.Center.Z, market.MarketZoneSphere.Value.Radius); } else if (market.MarketZoneType == MarketZoneType.FixedBox && market.MarketZoneBox.HasValue) { str.AppendFormat(" Center Position=X:{0:N} | Y:{1:N} | Z:{2:N} Size={3:N}m\r\n\r\n", market.MarketZoneBox.Value.Center.X, market.MarketZoneBox.Value.Center.Y, market.MarketZoneBox.Value.Center.Z, market.MarketZoneBox.Value.Size.X); } else { str.AppendLine("\r\n"); } } MessageClientDialogMessage.SendMessage(SenderSteamId, "NPC Market List", " ", str.ToString()); } break; case NpcMarketManage.Rename: { var market = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.DisplayName.Equals(OldMarketName, StringComparison.InvariantCultureIgnoreCase)); if (market == null) { var markets = EconomyScript.Instance.Data.Markets.Where(m => m.DisplayName.IndexOf(OldMarketName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray(); if (markets.Length == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC RENAME", "The specified market name could not be found."); return; } if (markets.Length > 1) { var str = new StringBuilder(); str.Append("The specified market name could not be found.\r\n Which did you mean?\r\n"); foreach (var m in markets) { str.AppendLine(m.DisplayName); } MessageClientDialogMessage.SendMessage(SenderSteamId, "NPC RENAME", " ", str.ToString()); return; } market = markets[0]; } if (string.IsNullOrWhiteSpace(MarketName) || MarketName == "*") { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC RENAME", "Invalid name supplied for the market name."); return; } var checkMarket = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.DisplayName.Equals(MarketName, StringComparison.InvariantCultureIgnoreCase)); if (checkMarket != null) { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC RENAME", "A market of name '{0}' already exists.", checkMarket.DisplayName); return; } var oldName = market.DisplayName; market.DisplayName = MarketName; MessageClientTextMessage.SendMessage(SenderSteamId, "NPC RENAME", "The market '{0}' has been renamed to '{1}.", oldName, market.DisplayName); } break; case NpcMarketManage.Move: { var market = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.DisplayName.Equals(MarketName, StringComparison.InvariantCultureIgnoreCase)); if (market == null) { var markets = EconomyScript.Instance.Data.Markets.Where(m => m.DisplayName.IndexOf(MarketName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray(); if (markets.Length == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "NPC MOVE", "The specified market name could not be found."); return; } if (markets.Length > 1) { var str = new StringBuilder(); str.Append("The specified market name could not be found.\r\n Which did you mean?\r\n"); foreach (var m in markets) { str.AppendLine(m.DisplayName); } MessageClientDialogMessage.SendMessage(SenderSteamId, "NPC MOVE", " ", str.ToString()); return; } market = markets[0]; } EconDataManager.SetMarketShape(market, X, Y, Z, Size, Shape); MessageClientTextMessage.SendMessage(SenderSteamId, "NPC MOVE", "The market '{0}' has been moved and resized.", market.DisplayName); } break; } }
public override void ProcessServer() { var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); // Only Admin can change config. if (!player.IsAdmin()) { EconomyScript.Instance.ServerLogger.WriteWarning("A Player without Admin \"{0}\" {1} attempted to access EConfig.", SenderDisplayName, SenderSteamId); return; } MyTexts.LanguageDescription myLanguage; // These will match with names defined in the RegEx patterm <EconomyScript.EconfigPattern> switch (ConfigName) { #region language case "language": if (string.IsNullOrEmpty(Value)) { myLanguage = MyTexts.Languages[(MyLanguagesEnum)EconomyScript.Instance.ServerConfig.Language]; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "Language: {0} ({1})", myLanguage.Name, myLanguage.FullCultureName); } else { int intTest; if (int.TryParse(Value, out intTest)) { if (MyTexts.Languages.ContainsKey((MyLanguagesEnum)intTest)) { EconomyScript.Instance.ServerConfig.Language = intTest; EconomyScript.Instance.SetLanguage(); myLanguage = MyTexts.Languages[(MyLanguagesEnum)intTest]; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "Language updated to: {0} ({1})", myLanguage.Name, myLanguage.FullCultureName); return; } } foreach (var lang in MyTexts.Languages) { if (lang.Value.Name.Equals(Value, StringComparison.InvariantCultureIgnoreCase) || lang.Value.CultureName.Equals(Value, StringComparison.InvariantCultureIgnoreCase) || lang.Value.FullCultureName.Equals(Value, StringComparison.InvariantCultureIgnoreCase)) { EconomyScript.Instance.ServerConfig.Language = (int)lang.Value.Id; EconomyScript.Instance.SetLanguage(); MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "Language updated to: {0} ({1})", lang.Value.Name, lang.Value.FullCultureName); return; } } myLanguage = MyTexts.Languages[(MyLanguagesEnum)EconomyScript.Instance.ServerConfig.Language]; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "Language: {0} ({1})", myLanguage.Name, myLanguage.FullCultureName); } break; #endregion #region tradenetworkname case "tradenetworkname": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeNetworkName: {0}", EconomyScript.Instance.ServerConfig.TradeNetworkName); } else { EconomyScript.Instance.ServerConfig.TradeNetworkName = Value; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeNetworkName updated to: \"{0}\"", EconomyScript.Instance.ServerConfig.TradeNetworkName); MessageUpdateClient.SendServerConfig(EconomyScript.Instance.ServerConfig); } break; #endregion #region currencyname case "currencyname": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "CurrencyName: {0}", EconomyScript.Instance.ServerConfig.CurrencyName); } else { EconomyScript.Instance.ServerConfig.CurrencyName = Value; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "CurrencyName updated to: \"{0}\"", EconomyScript.Instance.ServerConfig.CurrencyName); MessageUpdateClient.SendServerConfig(EconomyScript.Instance.ServerConfig); } break; #endregion #region limitedrange case "limitedrange": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedRange: {0}", EconomyScript.Instance.ServerConfig.LimitedRange ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.LimitedRange = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedRange updated to: {0}", EconomyScript.Instance.ServerConfig.LimitedRange ? "On" : "Off"); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedRange: {0}", EconomyScript.Instance.ServerConfig.LimitedRange ? "On" : "Off"); } break; #endregion #region limitedsupply case "limitedsupply": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedSupply: {0}", EconomyScript.Instance.ServerConfig.LimitedSupply ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.LimitedSupply = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedSupply updated to: {0}", EconomyScript.Instance.ServerConfig.LimitedSupply ? "On" : "Off"); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LimitedSupply: {0}", EconomyScript.Instance.ServerConfig.LimitedSupply ? "On" : "Off"); } break; #endregion #region enablelcds case "enablelcds": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableLcds: {0}", EconomyScript.Instance.ServerConfig.EnableLcds ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { var clearRefresh = EconomyScript.Instance.ServerConfig.EnableLcds && !boolTest; EconomyScript.Instance.ServerConfig.EnableLcds = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableLcds updated to: {0}", EconomyScript.Instance.ServerConfig.EnableLcds ? "On" : "Off"); if (clearRefresh) { LcdManager.BlankLcds(); } return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableLcds: {0}", EconomyScript.Instance.ServerConfig.EnableLcds ? "On" : "Off"); } break; #endregion #region EnableNpcTradezones case "enablenpctradezones": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableNpcTradezones: {0}", EconomyScript.Instance.ServerConfig.EnableNpcTradezones ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { var clearRefresh = EconomyScript.Instance.ServerConfig.EnableNpcTradezones != boolTest; EconomyScript.Instance.ServerConfig.EnableNpcTradezones = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableNpcTradezones updated to: {0}", EconomyScript.Instance.ServerConfig.EnableNpcTradezones ? "On" : "Off"); if (clearRefresh) { MessageUpdateClient.SendServerTradeZones(); } return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableNpcTradezones: {0}", EconomyScript.Instance.ServerConfig.EnableNpcTradezones ? "On" : "Off"); } break; #endregion #region EnablePlayerTradezones case "enableplayertradezones": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerTradezones: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerTradezones ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { var clearRefresh = EconomyScript.Instance.ServerConfig.EnablePlayerTradezones != boolTest; EconomyScript.Instance.ServerConfig.EnablePlayerTradezones = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerTradezones updated to: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerTradezones ? "On" : "Off"); if (clearRefresh) { MessageUpdateClient.SendServerTradeZones(); } return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerTradezones: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerTradezones ? "On" : "Off"); } break; #endregion #region EnablePlayerPayments case "enableplayerpayments": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerPayments: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerPayments ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.EnablePlayerPayments = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerPayments updated to: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerPayments ? "On" : "Off"); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnablePlayerPayments: {0}", EconomyScript.Instance.ServerConfig.EnablePlayerPayments ? "On" : "Off"); } break; #endregion #region tradetimeout case "tradetimeout": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeTimeout: {0}", EconomyScript.Instance.ServerConfig.TradeTimeout); } else { TimeSpan timeTest; if (TimeSpan.TryParse(Value, out timeTest)) { EconomyScript.Instance.ServerConfig.TradeTimeout = timeTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeTimeout updated to: {0} ", EconomyScript.Instance.ServerConfig.TradeTimeout); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeTimeout: {0}", EconomyScript.Instance.ServerConfig.TradeTimeout); } break; #endregion #region accountexpiry case "accountexpiry": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "AccountExpiry: {0}", EconomyScript.Instance.ServerConfig.AccountExpiry); } else { TimeSpan timeTest; if (TimeSpan.TryParse(Value, out timeTest)) { EconomyScript.Instance.ServerConfig.AccountExpiry = timeTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "AccountExpiry updated to: {0} ", EconomyScript.Instance.ServerConfig.AccountExpiry); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "AccountExpiry: {0}", EconomyScript.Instance.ServerConfig.AccountExpiry); } break; #endregion #region startingbalance case "startingbalance": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "StartingBalance: {0}", EconomyScript.Instance.ServerConfig.DefaultStartingBalance); } else { decimal decimalTest; if (decimal.TryParse(Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { EconomyScript.Instance.ServerConfig.DefaultStartingBalance = decimalTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "StartingBalance updated to: {0} ", EconomyScript.Instance.ServerConfig.DefaultStartingBalance); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "StartingBalance: {0}", EconomyScript.Instance.ServerConfig.DefaultStartingBalance); } break; #endregion #region LicenceMin case "licencemin": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMin: {0}", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin); } else { decimal decimalTest; if (decimal.TryParse(Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { if (EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax < decimalTest) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMin cannot be more than LicenceMax."); return; } EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin = decimalTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMin updated to: {0} ", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMin: {0}", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin); } break; #endregion #region LicenceMax case "licencemax": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMax: {0}", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax); } else { decimal decimalTest; if (decimal.TryParse(Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { if (decimalTest < EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMax cannot be less than LicenceMin."); return; } EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax = decimalTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMax updated to: {0} ", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LicenceMax: {0}", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax); } break; #endregion #region RelinkRatio case "relinkratio": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "RelinkRatio: {0}", EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio); } else { var numFormat = CultureInfo.CurrentCulture.NumberFormat; NumberFormatInfo nfi = new NumberFormatInfo() { CurrencyDecimalDigits = numFormat.PercentDecimalDigits, CurrencyDecimalSeparator = numFormat.PercentDecimalSeparator, CurrencyGroupSeparator = numFormat.PercentGroupSeparator, CurrencyGroupSizes = numFormat.PercentGroupSizes, CurrencyNegativePattern = numFormat.PercentNegativePattern, CurrencyPositivePattern = numFormat.PercentPositivePattern, CurrencySymbol = numFormat.PercentSymbol }; decimal decimalTest; if (decimal.TryParse(Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio = decimalTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "RelinkRatio updated to: {0:P} ", EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio); return; } } else if (decimal.TryParse(Value, NumberStyles.Currency, nfi, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio = decimalTest / 100; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "RelinkRatio updated to: {0:P} ", EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "RelinkRatio: {0:P}", EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio); } break; #endregion #region MaximumPlayerZones case "maximumplayerzones": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "MaximumPlayerZones: {0}", EconomyScript.Instance.ServerConfig.MaximumPlayerTradeZones); } else { int intTest; if (int.TryParse(Value, out intTest)) { if (intTest >= 0) { EconomyScript.Instance.ServerConfig.MaximumPlayerTradeZones = intTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "MaximumPlayerZones updated to: {0} ", EconomyScript.Instance.ServerConfig.MaximumPlayerTradeZones); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "TradeZoneLicence: {0}", EconomyScript.Instance.ServerConfig.MaximumPlayerTradeZones); } break; #endregion #region pricescaling case "pricescaling": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "PriceScaling: {0}", EconomyScript.Instance.ServerConfig.PriceScaling ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.PriceScaling = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "PriceScaling updated to: {0}", EconomyScript.Instance.ServerConfig.PriceScaling ? "On" : "Off"); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "PriceScaling: {0}", EconomyScript.Instance.ServerConfig.PriceScaling ? "On" : "Off"); } break; #endregion #region shiptrading case "shiptrading": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "ShipTrading: {0}", EconomyScript.Instance.ServerConfig.ShipTrading ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.ShipTrading = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "ShipTrading updated to: {0}", EconomyScript.Instance.ServerConfig.ShipTrading ? "On" : "Off"); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "ShipTrading: {0}", EconomyScript.Instance.ServerConfig.ShipTrading ? "On" : "Off"); } break; #endregion #region MinimumLcdDisplayInterval case "lcddisplayinterval": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LcdDisplayInterval: {0}", EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval); } else { decimal decimalTest; if (decimal.TryParse(Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimalTest)) { // TODO: perhaps we should truncate the value. if (decimalTest >= 0) { if (decimalTest < 1) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LcdDisplayInterval cannot be less than 1 second."); return; } if (decimalTest > 1000) // no particular reason for 1000, apart from it been a reasonable limit. { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LcdDisplayInterval cannot be more than 1000 second."); return; } EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval = decimalTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LcdDisplayInterval updated to: {0} seconds", EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval); return; } } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "LcdDisplayInterval: {0} seconds", EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval); } break; #endregion #region EnableMissions case "enablemissions": if (string.IsNullOrEmpty(Value)) { MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableMissions: {0}", EconomyScript.Instance.ServerConfig.EnableMissions ? "On" : "Off"); } else { bool boolTest; if (Value.TryWordParseBool(out boolTest)) { EconomyScript.Instance.ServerConfig.EnableMissions = boolTest; MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableMissions updated to: {0}", EconomyScript.Instance.ServerConfig.EnableMissions ? "On" : "Off"); MessageUpdateClient.SendServerConfig(EconomyScript.Instance.ServerConfig); return; } MessageClientTextMessage.SendMessage(SenderSteamId, "ECONFIG", "EnableMissions: {0}", EconomyScript.Instance.ServerConfig.EnableMissions ? "On" : "Off"); } break; #endregion #region default default: var msg = new StringBuilder(); myLanguage = MyTexts.Languages[(MyLanguagesEnum)EconomyScript.Instance.ServerConfig.Language]; msg.AppendFormat("Language: {0} ({1})\r\n", myLanguage.Name, myLanguage.FullCultureName); msg.AppendFormat("TradeNetworkName: \"{0}\"\r\n", EconomyScript.Instance.ServerConfig.TradeNetworkName); msg.AppendFormat("LimitedRange: {0}\r\n", EconomyScript.Instance.ServerConfig.LimitedRange ? "On" : "Off"); msg.AppendFormat("LimitedSupply: {0}\r\n", EconomyScript.Instance.ServerConfig.LimitedSupply ? "On" : "Off"); msg.AppendFormat("TradeTimeout: {0} (days.hours:mins:secs)\r\n", EconomyScript.Instance.ServerConfig.TradeTimeout); msg.AppendFormat("StartingBalance: {0:#,#.######}\r\n", EconomyScript.Instance.ServerConfig.DefaultStartingBalance); msg.AppendFormat("CurrencyName: \"{0}\"\r\n", EconomyScript.Instance.ServerConfig.CurrencyName); msg.AppendFormat("AccountExpiry: {0} (days.hours:mins:secs)\r\n", EconomyScript.Instance.ServerConfig.AccountExpiry); msg.AppendFormat("EnableLcds: {0}\r\n", EconomyScript.Instance.ServerConfig.EnableLcds ? "On" : "Off"); msg.AppendFormat("EnableNpcTradezones: {0}\r\n", EconomyScript.Instance.ServerConfig.EnableNpcTradezones ? "On" : "Off"); msg.AppendFormat("PriceScaling: {0}\r\n", EconomyScript.Instance.ServerConfig.PriceScaling ? "On" : "Off"); msg.AppendFormat("ShipTrading: {0}\r\n", EconomyScript.Instance.ServerConfig.ShipTrading ? "On" : "Off"); msg.AppendFormat("LcdDisplayInterval: {0:#,#.######} seconds\r\n", EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval); msg.AppendLine(); msg.AppendLine("--- Player Tradezones ---"); msg.AppendFormat("EnablePlayerTradezones: {0}\r\n", EconomyScript.Instance.ServerConfig.EnablePlayerTradezones ? "On" : "Off"); msg.AppendFormat("EnablePlayerPayments: {0}\r\n", EconomyScript.Instance.ServerConfig.EnablePlayerPayments ? "On" : "Off"); msg.AppendFormat("LicenceMin: {0:#,#.######} (at {1:#,#.######}m)\r\n", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMin, EconomyScript.Instance.ServerConfig.TradeZoneMinRadius); msg.AppendFormat("LicenceMax: {0:#,#.######} (at {1:#,#.######}m)\r\n", EconomyScript.Instance.ServerConfig.TradeZoneLicenceCostMax, EconomyScript.Instance.ServerConfig.TradeZoneMaxRadius); msg.AppendFormat("RelinkRatio: {0:P}\r\n", EconomyScript.Instance.ServerConfig.TradeZoneRelinkRatio); msg.AppendFormat("MaximumPlayerZones: {0}\r\n", EconomyScript.Instance.ServerConfig.MaximumPlayerTradeZones); // Not yet ready for general use. //msg.AppendFormat("EnableMissions: {0}\r\n", EconomyScript.Instance.ServerConfig.EnableMissions ? "On" : "Off"); MessageClientDialogMessage.SendMessage(SenderSteamId, "ECONFIG", " ", msg.ToString()); break; #endregion } }
public override void ProcessServer() { // update our own timestamp here AccountManager.UpdateLastSeen(SenderSteamId, SenderLanguage); EconomyScript.Instance.ServerLogger.WriteVerbose("Price List Request for from '{0}'", SenderSteamId); var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); var character = player.GetCharacter(); if (character == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "You are dead. You get market items values while dead."); return; } List <MarketStruct> markets; if (string.IsNullOrEmpty(FindMarket)) { var position = ((IMyEntity)character).WorldMatrix.Translation; markets = MarketManager.FindMarketsFromLocation(position); } else { markets = MarketManager.FindMarketsFromName(FindMarket); } if (markets.Count == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Sorry, your are not in range of any markets!"); return; } // TODO: combine multiple markets to list best Buy and Sell prices that isn't blacklisted. var market = markets.FirstOrDefault(); if (market == null) //hmmm looks like market name parameter checking was started but never done { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "That market does not exist."); return; //as I understand it this would only trigger if no markets are defined? //in which case should it read no markets exist? but in that case // wont the count check above halt execution before this if statement??? // remove these comments once read :) } string reply = null; MyAPIGateway.Parallel.StartBackground(delegate() // Background processing occurs within this block. { try { bool showAll = !ShowOre && !ShowIngot && !ShowComponent && !ShowAmmo && !ShowTools && !ShowGasses; var orderedList = new Dictionary <MarketItemStruct, string>(); foreach (var marketItem in market.MarketItems) { if (marketItem.IsBlacklisted) { continue; } MyObjectBuilderType result; if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result)) { var id = new MyDefinitionId(result, marketItem.SubtypeName); var content = Support.ProducedType(id); // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject(). if (showAll || (ShowOre && content is MyObjectBuilder_Ore) || (ShowIngot && content is MyObjectBuilder_Ingot) || (ShowComponent && content is MyObjectBuilder_Component) || (ShowAmmo && content is MyObjectBuilder_AmmoMagazine) || (ShowTools && content is MyObjectBuilder_PhysicalGunObject) || // guns, welders, hand drills, grinders. (ShowGasses && content is MyObjectBuilder_GasContainerObject) || // aka gas bottle. (ShowGasses && content is MyObjectBuilder_GasProperties)) // Type check here allows mods that inherit from the same type to also appear in the lists. { var definition = MyDefinitionManager.Static.GetDefinition(marketItem.TypeId, marketItem.SubtypeName); var name = definition == null ? marketItem.SubtypeName : definition.GetDisplayName(); orderedList.Add(marketItem, name); } } } orderedList = orderedList.OrderBy(kvp => kvp.Value).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var str = new SeTextBuilder(); str.AppendLine("Market: {0}\r\n", market.DisplayName); str.AddLeftTrim(550, "Item"); str.AddRightText(650, "Buy at"); str.AddRightText(850, "Sell at"); str.AppendLine(); foreach (var kvp in orderedList) { decimal showBuy = kvp.Key.BuyPrice; decimal showSell = kvp.Key.SellPrice; if ((EconomyScript.Instance.ServerConfig.PriceScaling) && (market.MarketId == EconomyConsts.NpcMerchantId)) { showBuy = EconDataManager.PriceAdjust(kvp.Key.BuyPrice, kvp.Key.Quantity, PricingBias.Buy); showSell = EconDataManager.PriceAdjust(kvp.Key.SellPrice, kvp.Key.Quantity, PricingBias.Sell); } // TODO: formatting of numbers, and currency name. str.AddLeftTrim(550, kvp.Value); str.AddRightText(650, showBuy.ToString("0.00", EconomyScript.ServerCulture)); str.AddRightText(850, showSell.ToString("0.00", EconomyScript.ServerCulture)); str.AppendLine(); } reply = str.ToString(); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Failed and died. Please contact the administrator."); } }, delegate() // when the background processing is finished, this block will run foreground. { if (reply != null) { try { MessageClientDialogMessage.SendMessage(SenderSteamId, "PRICELIST", " ", reply); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Failed and died. Please contact the administrator."); } } }); }
public override void ProcessServer() { // update our own timestamp here AccountManager.UpdateLastSeen(SenderSteamId, SenderLanguage); EconomyScript.Instance.ServerLogger.WriteVerbose("Price List Request for from '{0}'", SenderSteamId); var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); var character = player.GetCharacter(); if (character == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "You are dead. You get market items values while dead."); return; } var position = ((IMyEntity)character).WorldMatrix.Translation; var markets = MarketManager.FindMarketsFromLocation(position); if (markets.Count == 0) { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Sorry, your are not in range of any markets!"); return; } // TODO: combine multiple markets to list best Buy and Sell prices that isn't blacklisted. var market = markets.FirstOrDefault(); if (market == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "That market does not exist."); return; } string reply = null; MyAPIGateway.Parallel.StartBackground(delegate() // Background processing occurs within this block. { try { bool showAll = !ShowOre && !ShowIngot && !ShowComponent && !ShowAmmo && !ShowTools; var orderedList = new Dictionary <MarketItemStruct, string>(); foreach (var marketItem in market.MarketItems) { if (marketItem.IsBlacklisted) { continue; } MyObjectBuilderType result; if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result)) { var id = new MyDefinitionId(result, marketItem.SubtypeName); var content = Support.ProducedType(id); // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject(). if (showAll || (ShowOre && content is MyObjectBuilder_Ore) || (ShowIngot && content is MyObjectBuilder_Ingot) || (ShowComponent && content is MyObjectBuilder_Component) || (ShowAmmo && content is MyObjectBuilder_AmmoMagazine) || (ShowTools && content is MyObjectBuilder_PhysicalGunObject) || (ShowTools && content is MyObjectBuilder_GasContainerObject)) // Type check here allows mods that inherit from the same type to also appear in the lists. { var definition = MyDefinitionManager.Static.GetDefinition(marketItem.TypeId, marketItem.SubtypeName); var name = definition == null ? marketItem.SubtypeName : definition.GetDisplayName(); orderedList.Add(marketItem, name); } } } orderedList = orderedList.OrderBy(kvp => kvp.Value).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var str = new SeTextBuilder(); str.AppendLine("Market: {0}\r\n", market.DisplayName); str.AddLeftTrim(550, "Item"); str.AddRightText(650, "Buy at"); str.AddRightText(850, "Sell at"); str.AppendLine(); foreach (var kvp in orderedList) { // TODO: formatting of numbers, and currency name. str.AddLeftTrim(550, kvp.Value); str.AddRightText(650, kvp.Key.BuyPrice.ToString("0.00", EconomyScript.ServerCulture)); str.AddRightText(850, kvp.Key.SellPrice.ToString("0.00", EconomyScript.ServerCulture)); str.AppendLine(); } reply = str.ToString(); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Failed and died. Please contact the administrator."); } }, delegate() // when the background processing is finished, this block will run foreground. { if (reply != null) { try { MessageClientDialogMessage.SendMessage(SenderSteamId, "PRICELIST", " ", reply); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "PRICELIST", "Failed and died. Please contact the administrator."); } } }); }
public override void ProcessServer() { // update our own timestamp here AccountManager.UpdateLastSeen(SenderSteamId, SenderLanguage); EconomyScript.Instance.ServerLogger.WriteVerbose("Worth Request for {0} from '{1}'", EntityId, SenderSteamId); var player = MyAPIGateway.Players.FindPlayerBySteamId(SenderSteamId); var character = player.GetCharacter(); if (character == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "You are dead. You get market items values while dead."); return; } var position = ((IMyEntity)character).WorldMatrix.Translation; var markets = MarketManager.FindMarketsFromLocation(position); // TODO: find market with best Buy price that isn't blacklisted. var market = markets.FirstOrDefault(); string marketDetail = null; if (market == null) { market = EconomyScript.Instance.Data.Markets.FirstOrDefault(m => m.MarketId == EconomyConsts.NpcMerchantId); if (market != null) { marketDetail = string.Format("No markets in range, using default market '{0}' for appraisal.", market.DisplayName); } } if (market == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "That market does not exist."); return; } if (marketDetail == null) { marketDetail = string.Format("Using market '{0}' for appraisal.", market.DisplayName); } if (!MyAPIGateway.Entities.EntityExists(EntityId)) { MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "Sorry, the entity no longer exists!"); return; } var selectedShip = MyAPIGateway.Entities.GetEntityById(EntityId) as IMyCubeGrid; if (selectedShip == null) { MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "Sorry, the entity no longer exists!"); return; } int terminalBlocks = 0; int armorBlocks = 0; decimal shipValue = 0; decimal inventoryValue = 0; int gridCount = 0; var gridComponents = new Dictionary <MyDefinitionId, decimal>(); var inventoryComponents = new Dictionary <MyDefinitionId, decimal>(); MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "Calculating the worth..."); MyAPIGateway.Parallel.StartBackground(delegate() // Background processing occurs within this block. { EconomyScript.Instance.ServerLogger.WriteInfo("Worth:background start"); try { var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static); gridCount = grids.Count; foreach (var grid in grids) { var blocks = new List <IMySlimBlock>(); grid.GetBlocks(blocks); foreach (var block in blocks) { MyCubeBlockDefinition blockDefintion; if (block.FatBlock == null) { armorBlocks++; blockDefintion = MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetObjectBuilder()); } else { terminalBlocks++; blockDefintion = MyDefinitionManager.Static.GetCubeBlockDefinition(block.FatBlock.BlockDefinition); } //EconomyScript.Instance.ServerLogger.Write("Cube Worth '{0}' '{1}' {2} {3}.", blockDefintion.Id.TypeId, blockDefintion.Id.SubtypeName, block.BuildIntegrity, block.BuildLevelRatio); #region Go through component List based on construction level. foreach (var component in blockDefintion.Components) { //EconomyScript.Instance.ServerLogger.Write("Component Worth '{0}' '{1}' x {2}.", component.Definition.Id.TypeId, component.Definition.Id.SubtypeName, component.Count); if (!gridComponents.ContainsKey(component.Definition.Id)) { gridComponents.Add(component.Definition.Id, 0); } gridComponents[component.Definition.Id] += component.Count; } // This will subtract off components missing from a partially built cube. // This also includes the Construction Inventory. var missingComponents = new Dictionary <string, int>(); block.GetMissingComponents(missingComponents); foreach (var kvp in missingComponents) { var definitionid = new MyDefinitionId(typeof(MyObjectBuilder_Component), kvp.Key); gridComponents[definitionid] -= kvp.Value; } #endregion if (block.FatBlock != null) { var cube = (MyEntity)block.FatBlock; #region Go through Gasses for tanks and cockpits. var tank = cube as IMyGasTank; var gasTankDefintion = blockDefintion as MyGasTankDefinition; if (gasTankDefintion != null && tank != null) { decimal volume = (decimal)gasTankDefintion.Capacity * (decimal)tank.FilledRatio; if (!inventoryComponents.ContainsKey(gasTankDefintion.StoredGasId)) { inventoryComponents.Add(gasTankDefintion.StoredGasId, 0); } inventoryComponents[gasTankDefintion.StoredGasId] += volume; //MessageClientTextMessage.SendMessage(SenderSteamId, "GAS tank", "{0} detected {1}", gasTankDefintion.StoredGasId, volume); } // Check through Cockpits. var cockpit = cube as Sandbox.Game.Entities.MyCockpit; // For some reason, the o2 is on the MyCockpit Class. There is no Interface. if (cockpit != null) { // Hardcoded, because Oxygen and Hydrogen do not have available defintions. var oxygenDefintion = new MyDefinitionId(typeof(MyObjectBuilder_GasProperties), "Oxygen"); if (!inventoryComponents.ContainsKey(oxygenDefintion)) { inventoryComponents.Add(oxygenDefintion, 0); } inventoryComponents[oxygenDefintion] += (decimal)cockpit.OxygenAmount; //MessageClientTextMessage.SendMessage(SenderSteamId, "COCKPIT tank", "{0} detected {1}", null, cockpit.OxygenAmount); } #endregion #region Go through all other Inventories for components/items. // Inventory check based on normal game access. var relation = block.FatBlock.GetUserRelationToOwner(player.IdentityId); if (relation != MyRelationsBetweenPlayerAndBlock.Enemies && relation != MyRelationsBetweenPlayerAndBlock.Neutral) { for (var i = 0; i < cube.InventoryCount; i++) { var inventory = cube.GetInventory(i); var list = inventory.GetItems(); foreach (var item in list) { var id = item.Content.GetId(); if (!inventoryComponents.ContainsKey(id)) { inventoryComponents.Add(id, 0); } inventoryComponents[id] += (decimal)item.Amount; // Go through Gas bottles. var gasContainer = item.Content as MyObjectBuilder_GasContainerObject; if (gasContainer != null) { var defintion = (MyOxygenContainerDefinition)MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content.GetId()); decimal volume = (decimal)defintion.Capacity * (decimal)gasContainer.GasLevel; if (!inventoryComponents.ContainsKey(defintion.StoredGasId)) { inventoryComponents.Add(defintion.StoredGasId, 0); } inventoryComponents[defintion.StoredGasId] += volume; //MessageClientTextMessage.SendMessage(SenderSteamId, "GAS bottle", "{0} detected {1}", defintion.StoredGasId, volume); } } } } #endregion } } } shipValue += SumComponents(market, gridComponents); inventoryValue += SumComponents(market, inventoryComponents); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "Failed and died. Please contact the administrator."); } EconomyScript.Instance.ServerLogger.WriteInfo("Worth:background end"); }, delegate() // when the background processing is finished, this block will run foreground. { EconomyScript.Instance.ServerLogger.WriteInfo("Worth:foreground"); try { var str = new StringBuilder(); //foreach (var kvp in gridComponents) //{ // MyDefinitionBase definition = null; // MyDefinitionManager.Static.TryGetDefinition(kvp.Key, out definition); // str.AppendFormat("'{0}' x {1}.\r\n", definition == null ? kvp.Key.SubtypeName : definition.GetDisplayName(), kvp.Value); //} //foreach (var kvp in inventoryComponents) //{ // MyDefinitionBase definition = null; // MyDefinitionManager.Static.TryGetDefinition(kvp.Key, out definition); // str.AppendFormat("'{0}' x {1}.\r\n", definition == null ? kvp.Key.SubtypeName : definition.GetDisplayName(), kvp.Value); //} //var prefix = string.Format("{0:#,##0.00000}", totalValue); var shipSale = ShipManager.CheckSellOrder(selectedShip.EntityId); str.AppendLine(marketDetail); str.AppendFormat("{0}: {1}\r\n", selectedShip.IsStatic ? "Station" : selectedShip.GridSizeEnum.ToString() + " Ship", selectedShip.DisplayName); str.AppendFormat("Grids={2}\r\nArmor Blocks={0}\r\nTerminal Blocks={1}\r\n", armorBlocks, terminalBlocks, gridCount); str.AppendLine("-----------------------------------"); str.AppendFormat("Ship Value: {0:#,##0.00000} {1}.\r\n", shipValue, EconomyScript.Instance.ServerConfig.CurrencyName); str.AppendFormat("Inventory Value: {0:#,##0.00000} {1}.\r\n", inventoryValue, EconomyScript.Instance.ServerConfig.CurrencyName); str.AppendFormat("Final Value: {0:#,##0.00000} {1}.\r\n", shipValue + inventoryValue, EconomyScript.Instance.ServerConfig.CurrencyName); str.AppendLine("-----------------------------------"); if (shipSale != 0) { str.AppendFormat("Sale Price: {0:#,##0.00000} {1}.\r\n", shipSale, EconomyScript.Instance.ServerConfig.CurrencyName); } else { str.AppendLine("Sale Price: Not for Sale.\r\n"); } MessageClientDialogMessage.SendMessage(SenderSteamId, "WORTH", selectedShip.DisplayName, str.ToString()); } catch (Exception ex) { EconomyScript.Instance.ServerLogger.WriteException(ex); MessageClientTextMessage.SendMessage(SenderSteamId, "WORTH", "Failed and died. Please contact the administrator."); } }); }