public Item(string specifier) { UID = LocalTopUID++; int spec_argStart = specifier.IndexOf('{'); int spec_argEnd = (spec_argStart >= 0) ? specifier.IndexOf('}', spec_argStart + 1) : 1; string spec_args = ""; if (spec_argStart >= 0 && spec_argEnd >= 0) { spec_args = specifier.Substring(spec_argStart + 1, spec_argEnd - spec_argStart - 1); } if (spec_argStart >= 0) { specifier = specifier.Substring(0, spec_argStart).Trim(); } Class = ItemClassLoader.GetItemClassBySpecifier(specifier); if (Class == null) { Debug.LogFormat("Invalid item created (specifier={0})", specifier); return; } InitItem(); // now go through effects MagicEffects.AddRange(ItemEffect.ParseEffectList(spec_args)); UpdateItem(); }
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(); }