Esempio n. 1
0
        public void UpgradeEffectStatEffect()
        {
            var effect = new UpgradeEffect(UpgradeType.Suffix);

            effect.SetStatEffect(UpgradeStat.STR, 20, UpgradeValueType.Fix);
            Assert.Equal((
                             "01 00 00 00  00 00 00 00  00 00 00 00  0A 03 14 00" +
                             "00 00 00 00  0A 00 00 00  00 00 00 00  0A 00 00 00" +
                             "00 00 00 00"
                             ).Replace(" ", ""), ToHex(effect));

            effect.SetType(UpgradeType.Elemental);
            effect.SetStatEffect(UpgradeStat.Fire, 1, UpgradeValueType.Value);
            Assert.Equal((
                             "02 00 00 00  00 00 00 00  02 00 00 00  1B 00 01 00" +
                             "00 00 00 00  0A 00 00 00  00 00 00 00  0A 00 00 00" +
                             "00 00 00 00"
                             ).Replace(" ", ""), ToHex(effect));
        }
Esempio n. 2
0
    protected override async Task Talk()
    {
        Msg("A... a customer? Uhm, okay, what... what can I do for you?<br/>Sorry, I'm new to this.", Button("Upgrade item", "@upgrade"), Button("End conversation", "@end"));

        if (await Select() == "@upgrade")
        {
            Msg("<selectitem stringid='*/equip/*' />");
            var select = await Select();

            if (select != "@cancel")
            {
                var entityId = Convert.ToInt64(select.Substring("@select:".Length));
                var item     = Player.Inventory.GetItem(entityId);
                if (item != null)
                {
                    Msg("This one...? Of course, uhm, which upgrade would you like?");
                    Msg(List("Select Upgrade", Button("500 STR", "@str"), Button("5 INT", "@int"), Button("5 DEX", "@dex"), Button("5 Will", "@will"), Button("5 Luck", "@luck")));

                    UpgradeStat stat;
                    short       value = 5;
                    switch (await Select())
                    {
                    default:
                    case "@str": stat = UpgradeStat.STR; value = 500; break;

                    case "@int": stat = UpgradeStat.Intelligence; break;

                    case "@dex": stat = UpgradeStat.Dexterity; break;

                    case "@will": stat = UpgradeStat.Will; break;

                    case "@luck": stat = UpgradeStat.Luck; break;
                    }

                    var effect = new UpgradeEffect(UpgradeType.ItemAttribute);
                    effect.SetStatEffect(stat, value, UpgradeValueType.Value);

                    if (stat == UpgradeStat.STR)
                    {
                        Msg("Heh, that's my favorite upgrade as well.<br/>Let's see.", Button("Continue"));
                    }
                    else
                    {
                        Msg("Eh...? But... nevermind, you surely know what you're doing!<br/>Let's see.", Button("Continue"));
                    }

                    await Select();

                    for (int i = 0; i < 3; ++i)
                    {
                        Task.Delay(i * 500).ContinueWith(_ => Send.PlaySound(Player, "data/sound/blacksmith_click_best.wav"));
                        Task.Delay(i * 500 + 250).ContinueWith(_ => Send.PlaySound(Player, "data/sound/blacksmith_click_normal.wav"));
                        Task.Delay(i * 500 + 350).ContinueWith(_ => Send.PlaySound(Player, "data/sound/blacksmith_click_normal.wav"));
                    }
                    Task.Delay(1750).ContinueWith(_ => Send.PlaySound(Player, "data/sound/emotion_fail.wav"));
                    Msg("...<autopass duration='500'/><p/>... ...<autopass duration='500'/><p/>... ... ...<autopass duration='750'/><p/>Uh-oh...<br/>Uhm, could you wait a second?", Button("..."));
                    await Select();

                    for (int i = 0; i < 10; ++i)
                    {
                        Task.Delay(i * 250).ContinueWith(_ => Send.PlaySound(Player, "data/sound/blacksmith_click_best.wav"));
                    }
                    Task.Delay(3000).ContinueWith(_ => Send.PlaySound(Player, "data/sound/emotion_success.wav"));
                    Msg("...<autopass duration='3000'/><p/>There it is, good as new, and with your upgrade!<br/>Have a good day!");

                    item.AddUpgradeEffect(effect);
                    Send.ItemUpdate(Player, item);

                    End();
                }
            }
        }

        Close(Hide.None, "(phew) See you.");
    }
Esempio n. 3
0
        public UpgradeEffect GetUpgradeEffect(Random rnd)
        {
            var effect = new UpgradeEffect(this.Type);

            // Stat effect
            if (this.Stat != null)
            {
                // Stat
                var stat = (UpgradeStat)this.Stat;

                // Value type
                UpgradeValueType valueType;
                if (this.Value.EndsWith("%"))
                {
                    valueType = UpgradeValueType.Percent;
                }
                else
                {
                    valueType = UpgradeValueType.Value;
                }

                // Value
                if (this.Value == null)
                {
                    throw new NullReferenceException("Value can't be empty if Stat is set.");
                }

                var match = _valueRegex.Match(this.Value);
                if (!match.Success)
                {
                    throw new FormatException("Invalid value format: " + this.Value);
                }

                var min  = Convert.ToInt32(match.Groups["min"].Value);
                var maxs = match.Groups["max"].Value;
                var max  = (maxs == "" ? min : (int)Math.Max(min, Convert.ToInt32(maxs)));
                if (match.Groups["sign"].Value == "-")
                {
                    // For negative numbers min and max must be reversed,
                    // e.g. -1~2 becomes "from -2 to -1".
                    var temp = min;
                    min = -max;
                    max = -temp;
                }
                var value = (short)rnd.Next(min, max + 1);

                // Set
                effect.SetStatEffect(stat, value, valueType);
            }

            // Stat check
            if (this.Check == "gte" || this.Check == "lte" || this.Check == "gt" || this.Check == "lt" || this.Check == "equal")
            {
                // Check type
                UpgradeCheckType checkType;
                switch (this.Check)
                {
                case "gte": checkType = UpgradeCheckType.GreaterEqualThan; break;

                case "lte": checkType = UpgradeCheckType.LowerEqualThan; break;

                case "gt": checkType = UpgradeCheckType.GreaterThan; break;

                case "lt": checkType = UpgradeCheckType.LowerThan; break;

                case "equal": checkType = UpgradeCheckType.Equal; break;

                default: throw new NotSupportedException("Unknown check type: " + this.Check);
                }

                // Stat
                var stat = (UpgradeStat)Enum.Parse(typeof(UpgradeStat), this.If);

                // Value type
                var valueType = UpgradeValueType.Value;
                if (this.CheckValue.EndsWith("%"))
                {
                    valueType = UpgradeValueType.Percent;
                }

                // Value
                var value = short.Parse(this.CheckValue.TrimEnd('%'));

                // Set
                effect.SetStatCheck(stat, checkType, value, valueType);
            }
            // Skill check
            else if (this.Check == "rank_gte" || this.Check == "rank_lte" || this.Check == "rank_equal")
            {
                // Check type
                UpgradeCheckType checkType;
                switch (this.Check)
                {
                case "rank_gte": checkType = UpgradeCheckType.SkillRankGreaterThan; break;

                case "rank_lte": checkType = UpgradeCheckType.SkillRankLowerThan; break;

                case "rank_equal": checkType = UpgradeCheckType.SkillRankEqual; break;

                default: throw new NotSupportedException("Unknown check type: " + this.Check);
                }

                // Skill id
                var skillId = (SkillId)Enum.Parse(typeof(SkillId), this.If);

                // Rank
                var rank = (this.CheckValue == "N" ? SkillRank.Novice : (SkillRank)(16 - Convert.ToInt32(this.CheckValue, 16)));

                // Set
                effect.SetSkillCheck(skillId, checkType, rank);
            }
            // Ptj check
            else if (this.Check == "ptj_gte")
            {
                // Ptj type
                var ptjType = (PtjType)Enum.Parse(typeof(PtjType), this.If);

                // Count
                var count = int.Parse(this.CheckValue);

                // Set
                effect.SetPtjCheck(ptjType, count);
            }
            // Broken check
            else if (this.If == "intact" || this.If == "broken")
            {
                var broken = (this.If == "intact" ? false : true);
                effect.SetBrokenCheck(broken);
            }
            // Title check
            else if (this.If == "title")
            {
                var titleId = int.Parse(this.CheckValue);
                effect.SetTitleCheck(titleId);
            }
            // Condition check
            else if (this.If == "condition")
            {
                var condition = int.Parse(this.CheckValue);
                effect.SetConditionCheck(condition);
            }
            // Month check
            else if (this.If == "month")
            {
                var month = (Month)Enum.Parse(typeof(Month), this.CheckValue);
                effect.SetMonthCheck(month);
            }
            // Summon check
            else if (this.If == "summoned")
            {
                var summonStat = (UpgradeStat)Enum.Parse(typeof(UpgradeStat), this.CheckValue);
                effect.SetSummonCheck(summonStat);
            }
            // Support check
            else if (this.If == "supporting")
            {
                var race = (SupportRace)Enum.Parse(typeof(SupportRace), this.CheckValue);
                effect.SetSupportCheck(race);
            }

            return(effect);
        }