コード例 #1
0
ファイル: Item.cs プロジェクト: serg-bloim/UnityAllods
    private void InitItem()
    {
        if (Class == null)
        {
            return;
        }

        if (Class.IsSpecial)
        {
            // do nothing.
            // class has only option, no material or class.
        }
        else if (Class.IsMagic)
        {
            // generate effect list for native effects.
            Templates.TplMagicItem magicItem = TemplateLoader.GetMagicItemById(Class.MagicID);
            if (magicItem != null)
            {
                NativeEffects.Add(new ItemEffect(ItemEffect.Effects.Price, magicItem.Price));
                NativeEffects.AddRange(ItemEffect.ParseEffectList(magicItem.Effects));
            }
        }
        else
        {
            bool hasDamageMinMax = false;
            bool hasToHit        = false;
            bool hasDefense      = false;
            bool hasAbsorbtion   = false;
            for (int i = 0; i < Class.Effects.Count; i++)
            {
                ItemEffect eff       = new ItemEffect();
                ItemEffect sourceEff = Class.Effects[i];
                int        newValue  = sourceEff.Value1;
                if (sourceEff.Type1 == ItemEffect.Effects.Damage ||
                    sourceEff.Type1 == ItemEffect.Effects.DamageMin ||
                    sourceEff.Type1 == ItemEffect.Effects.DamageMax ||
                    sourceEff.Type1 == ItemEffect.Effects.DamageBonus)
                {
                    hasDamageMinMax = true;
                }
                else if (sourceEff.Type1 == ItemEffect.Effects.ToHit)
                {
                    hasToHit = true;
                }
                else if (sourceEff.Type1 == ItemEffect.Effects.Defence)
                {
                    hasDefense = true;
                }
                else if (sourceEff.Type1 == ItemEffect.Effects.Absorbtion)
                {
                    hasAbsorbtion = true;
                }

                eff.Type1  = sourceEff.Type1;
                eff.Value1 = newValue;
                eff.Type2  = sourceEff.Type2;
                eff.Value2 = sourceEff.Value2;
                NativeEffects.Add(eff);
            }

            if (!hasDamageMinMax)
            {
                int damageMin = (int)(Class.Option.PhysicalMin * Class.Material.Damage * Class.Class.Damage);
                int damageMax = (int)(Class.Option.PhysicalMax * Class.Material.Damage * Class.Class.Damage);
                if (damageMin != 0 || damageMax != 0)
                {
                    NativeEffects.Add(new ItemEffect(ItemEffect.Effects.DamageMin, damageMin));
                    NativeEffects.Add(new ItemEffect(ItemEffect.Effects.DamageMax, damageMax));
                }
            }

            if (!hasToHit)
            {
                int toHit = (int)(Class.Option.ToHit * Class.Material.ToHit * Class.Class.ToHit);
                if (toHit != 0)
                {
                    NativeEffects.Add(new ItemEffect(ItemEffect.Effects.ToHit, toHit));
                }
            }

            if (!hasDefense)
            {
                int defense = (int)(Class.Option.Defense * Class.Material.Defense * Class.Class.Defense);
                if (defense != 0)
                {
                    NativeEffects.Add(new ItemEffect(ItemEffect.Effects.Defence, defense));
                }
            }

            if (!hasAbsorbtion)
            {
                int absorbtion = (int)(Class.Option.Absorbtion * Class.Material.Absorbtion * Class.Class.Absorbtion);
                if (absorbtion != 0)
                {
                    NativeEffects.Add(new ItemEffect(ItemEffect.Effects.Absorbtion, absorbtion));
                }
            }
        }

        UpdateItem();
    }