public RewardEventArgs(Reward reward, ref decimal rewardValue, CurrencyDefinition currency, string playerName)
 {
     Reward      = reward;
     RewardValue = rewardValue;
     Currency    = currency;
     PlayerName  = playerName;
 }
Esempio n. 2
0
        internal void PreParseValues(CurrencyDefinition parent)
        {
            ParsedValues.Clear();

            foreach (var kvp in Values)
            {
                decimal unitValue;

                if (parent.GetCurrencyConverter().TryParse(kvp.Value, out unitValue))
                {
                    ParsedValues.Add(kvp.Key, unitValue);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This is a standard Currency that matches the Terraria Platinum/Gold/Silver/Copper currency. The n
        /// </summary>
        /// <returns></returns>
        internal static CurrencyDefinition CreateDefaultCurrency()
        {
            const string DefaultCurrencyName = "TerrariaCoin";

            var result = new CurrencyDefinition();

            result.InternalName = DefaultCurrencyName;
            //result.GainBy.Add(RewardReason.Killing);
            //result.SendCombatText = true;

            var q = new CurrencyQuadrant();

            q.BaseUnitMultiplier = 1;
            q.FullName           = "Copper";
            q.ShortName          = "copper";
            q.Abbreviation       = "c";

            result.Quadrants.Add(q);

            q = new CurrencyQuadrant();
            q.BaseUnitMultiplier = 100;
            q.FullName           = "Silver";
            q.ShortName          = "silver";
            q.Abbreviation       = "s";

            result.Quadrants.Add(q);

            q = new CurrencyQuadrant();
            q.BaseUnitMultiplier = 10_000;
            q.FullName           = "Gold";
            q.ShortName          = "gold";
            q.Abbreviation       = "g";

            result.Quadrants.Add(q);

            q = new CurrencyQuadrant();
            q.BaseUnitMultiplier = 1_000_000;
            q.FullName           = "Platinum";
            q.ShortName          = "platinum";
            q.Abbreviation       = "p";

            result.Quadrants.Add(q);

            return(result);
        }
Esempio n. 4
0
        protected internal override decimal OnEvaluate(CurrencyDefinition currency)        //, IRewardModifier rewardModifier = null)
        {
            var bank             = BankingPlugin.Instance.Bank;
            var playerAccountMap = bank[PlayerName];
            var votingConfig     = Config.Instance.Voting;

            if (votingConfig.Rewards.TryGetValue(currency.InternalName, out var moneyString))
            {
                if (currency.GetCurrencyConverter().TryParse(moneyString, out var value))
                {
                    value *= (decimal)currency.Multiplier;
                    return(value);
                }

                Debug.Print($"Transaction skipped. Couldn't parse '{value}' as a valid {currency.InternalName} value for {PlayerName}.");
            }

            return(0m);
        }
        private void generateParser(CurrencyDefinition def)
        {
            var    sb          = new StringBuilder();
            string regexString = "";

            sortedQuadrants = def.Quadrants.ToList();
            sortedQuadrants.Sort((a, b) =>
            {
                if (a.BaseUnitMultiplier == b.BaseUnitMultiplier)
                {
                    return(0);
                }
                else
                {
                    return(a.BaseUnitMultiplier > b.BaseUnitMultiplier ? 1 : -1);
                }
            });

            sortedQuadrants.Reverse();

            sb.Append($"(-|\\+)?");            //pos/neg

            foreach (var quad in sortedQuadrants)
            {
                //value-quad pair
                if (!string.IsNullOrWhiteSpace(quad.Abbreviation))
                {
                    sb.Append($"((\\d+)({quad.FullName}|{quad.Abbreviation}))?");
                }
                else
                {
                    sb.Append($"((\\d+)({quad.FullName}))?");
                }

                sb.Append(@",?");                //optional separator between value/quad
                //sb.Append(@"(\W*)");//optional separator between value/quad pairs
            }

            regexString = sb.ToString();
            //Debug.Print($"Created {Currency} regex = {regexString}");

            parseCurrencyRegex = new Regex(regexString, RegexOptions.Compiled);
        }
 internal CurrencyConverter(CurrencyDefinition currency)
 {
     Currency = currency;
     generateParser(currency);
 }
 public bool TryGetCurrency(string currencyType, out CurrencyDefinition result)
 {
     result = Bank.CurrencyManager.GetCurrencyByName(currencyType);
     return(result != null);
 }