Пример #1
0
        /// <summary>
        /// Add everything to the caster that this spell requires
        /// </summary>
        public void AddSpellRequirements(Spell spell)
        {
            var chr = OwnerChar;

            // add reagents
            foreach (var reagent in spell.Reagents)
            {
                var templ = reagent.Template;
                if (templ != null)
                {
                    var amt = reagent.Amount * 10;
                    chr.Inventory.Ensure(templ, amt);
                }
            }

            // add tools
            if (spell.RequiredTools != null)
            {
                foreach (var tool in spell.RequiredTools)
                {
                    chr.Inventory.Ensure(tool.Template, 1);
                }
            }
            if (spell.RequiredToolCategories != null)
            {
                foreach (var cat in spell.RequiredToolCategories)
                {
                    var tool = ItemMgr.GetFirstItemOfToolCategory(cat);
                    if (tool != null)
                    {
                        chr.Inventory.Ensure(tool, 1);
                    }
                }
            }

            // Profession
            if (spell.Ability != null && spell.Ability.Skill != null)
            {
                chr.Skills.TryLearn(spell.Ability.Skill.Id);
            }


            // add spellfocus object (if not present)
            if (spell.RequiredSpellFocus != 0)
            {
                var range = Owner.GetSpellMaxRange(spell);
                var go    = chr.Map.GetGOWithSpellFocus(chr.Position, spell.RequiredSpellFocus,
                                                        range > 0 ? (range) : 5f, chr.Phase);

                if (go == null)
                {
                    foreach (var entry in GOMgr.Entries.Values)
                    {
                        if (entry is GOSpellFocusEntry &&
                            ((GOSpellFocusEntry)entry).SpellFocus == spell.RequiredSpellFocus)
                        {
                            entry.Spawn(chr, chr);
                            break;
                        }
                    }
                }
            }
        }