/// <summary> /// Performs necessary setup and preprocessing to use a Currency in-game. /// </summary> /// <param name="id"></param> internal void OnInitialize(int id) { Id = id; NamesToQuadrants = createNamesToQuadrants(); currencyConverter = new CurrencyConverter(this); //set defaults if (currencyConverter.TryParse(DefaultMiningValueString, out var parsedResult)) { DefaultMiningValue = parsedResult; } if (currencyConverter.TryParse(DefaultPlacingValueString, out parsedResult)) { DefaultPlacingValue = parsedResult; } if (currencyConverter.TryParse(DefaultFishingValueString, out parsedResult)) { DefaultFishingValue = parsedResult; } if (currencyConverter.TryParse(DefaultPlayingValueString, out parsedResult)) { DefaultPlayingValue = parsedResult; } //set overrides KillingOverrides.Initialize(this); MiningOverrides.Initialize(this); PlacingOverrides.Initialize(this); FishingOverrides.Initialize(this); //set group overrides for tiles var tileGroupOverrides = new List <GroupValueOverrides <TileKey> >() { GroupMiningOverrides, GroupPlacingOverrides }; foreach (var go in tileGroupOverrides) { foreach (var vol in go.Values) { vol.Initialize(this); } } //set group overrides for playing foreach (var vol in GroupPlayingOverrides.Values) { vol.Initialize(this); } InitializeDisplayString(); }
private static void payPlayerSmart(TSPlayer client, string targetName, IEnumerable <string> amounts) { var combinedAmounts = new StringBuilder(); amounts.ForEach(s => combinedAmounts.Append(s)); //we should really think about changing the below code to using CurrencyManager.TryFindCurrencyFromString(), since its adapted from below. //but for better error reporting, we use this original version. var quadNames = CurrencyConverter.ParseQuadrantNames(combinedAmounts.ToString()); if (quadNames.Count < 1) { client.SendErrorMessage("Invalid input. Please check your formatting, and try again."); return; } var mgr = BankingPlugin.Instance.Bank.CurrencyManager; var firstQuad = quadNames.First(); var currency = mgr.GetCurrencyByQuadName(firstQuad); if (currency == null) { client.SendErrorMessage($"'{firstQuad}' does not belong to a known Currency."); return; } //ensure all quads lead to the same currency foreach (var quadName in quadNames) { var cur = mgr.GetCurrencyByQuadName(quadName); if (cur != currency) { client.SendErrorMessage($"'{quadName}' is not valid for currency '{currency.InternalName}'."); return; } } payPlayer(client, currency.InternalName, targetName, combinedAmounts.ToString()); }
/// <summary> /// Attempts to find the Currency represented by the value string. /// </summary> /// <param name="value">A string containing a valid currency amount.</param> /// <param name="currency">The Currency, if valid. Null otherwise.</param> /// <returns>True or false if a Currency was found.</returns> public bool TryFindCurrencyFromString(string value, out CurrencyDefinition currency) { currency = null; if (string.IsNullOrWhiteSpace(value)) { return(false); } var quadNames = CurrencyConverter.ParseQuadrantNames(value); if (quadNames.Count < 1) { return(false); } //try to find if the first suffix/quad name is valid var firstQuad = quadNames.First(); var selectedCurrency = GetCurrencyByQuadName(firstQuad); if (selectedCurrency == null) { return(false); } //ensure all quads are valid, and lead to the same currency foreach (var quadName in quadNames) { var cur = GetCurrencyByQuadName(quadName); if (cur != selectedCurrency) { return(false); } } currency = selectedCurrency; return(true); }