Beispiel #1
0
    // calculate price. calculate effects based on native effects + magic effects.
    public void UpdateItem()
    {
        if (Class == null || Class.IsMoney)
        {
            return;
        }

        // concat native and magic effects
        Effects.Clear();
        Effects.AddRange(NativeEffects);
        Effects.AddRange(MagicEffects);

        // base price.
        Price = Class.Price;

        /*
         * if (!Class.IsSpecial)
         * {
         *  Price = (int)(Price * Class.Class.Price);
         *  Price = (int)(Price * Class.Material.Price);
         * }
         */

        int manaUsage = 0;

        for (int i = 0; i < Effects.Count; i++)
        {
            Templates.TplModifier modifier = TemplateLoader.GetModifierById((int)Effects[i].Type1);
            if (modifier == null)
            {
                continue; // wtf was that lol.
            }
            manaUsage += modifier.ManaCost;
        }

        Price = Math.Max(Price, (int)(Price * ((float)manaUsage / 10)));

        // search for override price effect
        for (int i = 0; i < Effects.Count; i++)
        {
            if (Effects[i].Type1 == ItemEffect.Effects.Price)
            {
                Price = Effects[i].Value1;
            }
        }

        if (Price < 2)
        {
            Price = 2; // min price
        }
    }
Beispiel #2
0
        private ItemEffect GenerateEffect(Item item)
        {
            Random rnd          = new Random();
            float  itemPriceMax = 2 * PriceMax - item.Class.Price;
            float  manaMax      = item.Class.Material.MagicVolume * item.Class.Class.MagicVolume - item.ManaUsage;
            // note: this will not work correctly if SlotsWarrior or SlotsMage values for a slot are not sorted by ascending order.
            //       parameters that appear first will "override" parameters with the same weight appearing later.
            int lastValue;

            Templates.TplModifier lastModifier = TemplateLoader.Templates.Modifiers[TemplateLoader.Templates.Modifiers.Count - 1];
            if ((item.Class.Option.SuitableFor & 1) != 0)
            {
                lastValue = lastModifier.SlotsFighter[item.Class.Option.Slot - 1];
            }
            else
            {
                lastValue = lastModifier.SlotsMage[item.Class.Option.Slot - 1];
            }
            int randomValue = rnd.Next(0, lastValue) + 1;

            Templates.TplModifier matchingModifier = null;
            if (item.Class.Option.SuitableFor == 2 && item.Class.Option.Slot == 1)
            {
                matchingModifier = TemplateLoader.Templates.Modifiers[(int)ItemEffect.Effects.CastSpell];
            }
            else
            {
                for (int i = 1; i < TemplateLoader.Templates.Modifiers.Count; i++)
                {
                    Templates.TplModifier prevModifier = TemplateLoader.Templates.Modifiers[i - 1];
                    Templates.TplModifier modifier     = TemplateLoader.Templates.Modifiers[i];
                    int prevValue;
                    int value;
                    if ((item.Class.Option.SuitableFor & 1) != 0)
                    {
                        prevValue = prevModifier.SlotsFighter[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsFighter[item.Class.Option.Slot - 1];
                    }
                    else
                    {
                        prevValue = prevModifier.SlotsMage[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsMage[item.Class.Option.Slot - 1];
                    }
                    if (prevValue < randomValue && randomValue <= value)
                    {
                        matchingModifier = modifier;
                        break;
                    }
                }
            }
            if (matchingModifier == null)
            {
                // parameter not found. weird, but happens.
                return(null);
            }
            if ((matchingModifier.UsableBy & item.Class.Option.SuitableFor) == 0)
            {
                // parameter for class not found in the item.
                return(null);
            }
            // parameter found. calculate max possible power
            ItemEffect effect = new ItemEffect();

            effect.Type1 = (ItemEffect.Effects)matchingModifier.Index;
            float maxPower;
            float absoluteMax = manaMax / matchingModifier.ManaCost;

            if (matchingModifier.Index == (int)ItemEffect.Effects.CastSpell)
            {
                // select spell to cast.
                // if for fighter, choose between fighter-specific spells.
                // if for mage, choose between mage-specific spells.
                Spell.Spells[] spells;
                if ((item.Class.Option.SuitableFor & 1) != 0)
                {
                    spells = new Spell.Spells[] { Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life }
                }
                ;
                else
                {
                    spells = new Spell.Spells[] { Spell.Spells.Fire_Arrow, Spell.Spells.Lightning, Spell.Spells.Prismatic_Spray, Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life, Spell.Spells.Ice_Missile, Spell.Spells.Diamond_Dust }
                };
                // choose random spell
                Spell.Spells spell = spells[rnd.Next(0, spells.Length)];
                effect.Value1 = (int)spell;
                // calculate max power
                Templates.TplSpell spellTemplate = TemplateLoader.Templates.Spells[effect.Value1];
                maxPower = Mathf.Log(itemPriceMax / (spellTemplate.ScrollCost * 10f)) / Mathf.Log(2);
                if (!float.IsNaN(maxPower) && maxPower > 0)
                {
                    maxPower = (Mathf.Pow(1.2f, maxPower) - 1) * 30;
                }
                else
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, 100);
            }
            else
            {
                maxPower = Mathf.Log(itemPriceMax / (manaMax * 50) - 1) / Mathf.Log(1.5f) * 70f / matchingModifier.ManaCost;
                if (float.IsNaN(maxPower))
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, matchingModifier.AffectMax);
                if (maxPower < matchingModifier.AffectMin)
                {
                    return(null);
                }
            }

            if (maxPower <= 1)
            {
                // either some limit hit, or something else
                return(null);
            }

            // max parameter power found. randomize values
            switch (effect.Type1)
            {
            case ItemEffect.Effects.CastSpell:
                effect.Value2 = rnd.Next(1, (int)maxPower + 1);
                break;

            case ItemEffect.Effects.DamageFire:
            case ItemEffect.Effects.DamageWater:
            case ItemEffect.Effects.DamageAir:
            case ItemEffect.Effects.DamageEarth:
            case ItemEffect.Effects.DamageAstral:
                effect.Value1 = rnd.Next(1, (int)maxPower + 1);
                effect.Value2 = rnd.Next(1, (int)(maxPower / 2) + 1);
                break;

            default:
                effect.Value1 = (int)Mathf.Max(matchingModifier.AffectMin, rnd.Next(1, (int)maxPower + 1));
                break;
            }

            return(effect);
        }
Beispiel #3
0
    // calculate price. calculate effects based on native effects + magic effects.
    public void UpdateItem()
    {
        if (Class == null || Class.IsMoney)
        {
            return;
        }

        // concat native and magic effects
        Effects.Clear();
        Effects.AddRange(NativeEffects);
        Effects.AddRange(MagicEffects);

        // base price.
        Price = Class.Price;

        /*
         * if (!Class.IsSpecial)
         * {
         *  Price = (int)(Price * Class.Class.Price);
         *  Price = (int)(Price * Class.Material.Price);
         * }
         */

        ManaUsage = 0;
        for (int i = 0; i < MagicEffects.Count; i++)
        {
            Templates.TplModifier modifier = TemplateLoader.GetModifierById((int)Effects[i].Type1);
            if (modifier == null)
            {
                continue; // wtf was that lol.
            }
            switch (Effects[i].Type1)
            {
            case ItemEffect.Effects.CastSpell:
                ManaUsage += modifier.ManaCost * Effects[i].Value2;
                break;

            case ItemEffect.Effects.DamageFire:
            case ItemEffect.Effects.DamageWater:
            case ItemEffect.Effects.DamageAir:
            case ItemEffect.Effects.DamageEarth:
            case ItemEffect.Effects.DamageAstral:
                ManaUsage += modifier.ManaCost * (Effects[i].Value1 + Effects[i].Value2);
                break;

            default:
                ManaUsage += modifier.ManaCost * Effects[i].Value1;
                break;
            }
        }

        Price = Math.Max(Price, (int)(Price * ((float)ManaUsage / 10)));

        // search for override price effect
        for (int i = 0; i < Effects.Count; i++)
        {
            if (Effects[i].Type1 == ItemEffect.Effects.Price)
            {
                Price = Effects[i].Value1;
            }
        }

        if (Price < 2)
        {
            Price = 2; // min price
        }
    }