Beispiel #1
0
 /// <summary>
 /// Create a spell that a player casts by speaking.
 /// </summary>
 /// <param name="name">The name of the spell.</param>
 /// <param name="player">The player casting.</param>
 /// <returns></returns>
 public static Spell CreateSpell(string name, Player player)
 {
     string arg = GetArgument(name);
     Spell spell = new Spell();
     name = GetSpellName(name);
     instantSpells[name.ToLower()].InitDelegate.
         Invoke(new object[] { arg, player, spell });
     return spell;
 }
Beispiel #2
0
 public static Spell CreateRuneSpell(string name, Player player, Position pos)
 {
     Spell spell = new Spell();
     otherSpells[name.ToLower()].InitDelegate.Invoke
         (new object[] { name, player, pos, spell });
     return spell;
 }
Beispiel #3
0
 public static Spell CreateCreatureSpell(string name, string argument,
     Creature creature, int min, int max, Position spellCenter)
 {
     Spell spell = new Spell();
     otherSpells[name.ToLower()].InitDelegate.Invoke
         (new object[] { name, creature, min, max, spellCenter, spell, argument });
     return spell;
 }
Beispiel #4
0
        /// <summary>
        /// Use this method cast the specified spell. Note: This method only
        /// appends and does not send protocol data.
        /// </summary>
        /// <param name="caster">The creature casting the spell</param>
        /// <param name="spell">The spell to cast</param>
        /// <param name="tSet">The set of affected things</param>
        public void CastSpell(string msg, Creature caster, Spell spell, GameWorld world)
        {
            /*string error = caster.CanCastSpell(spell);
            if (error != null) {
                caster.AddAnonymousChat(ChatAnonymous.WHITE, error);
                return;
            }*/ //TODO: Uncomment

            if (spell.IsSpellValid != null && !spell.IsSpellValid(world, msg)) {
                world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                return;
            }
            if (spell.RequiresTarget) {
                Tile tile = map.GetTile(spell.SpellCenter);
                if (tile == null || !tile.ContainsType(Constants.TYPE_CREATURE)) {
                    world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                    caster.AddAnonymousChat(ChatAnonymous.WHITE, "No target selected.");
                    return;
                }
            }
            //Constants.
            //Not the most efficient method but it is simple and works.
            int length = spell.SpellArea.GetLength(0);
            int width = spell.SpellArea.GetLength(1);

            Position startPos = new Position();
            startPos.x = (ushort)(spell.SpellCenter.x - (width / 2));
            startPos.y = (ushort)(spell.SpellCenter.y - (length / 2));
            startPos.z = spell.SpellCenter.z;
            Position local = new Position();

            List<Thing> things = new List<Thing>();
            for (int i = 0; i < length; i++) {
                for (int j = 0; j < width; j++) {
                    local.x = (ushort)(startPos.x + j);
                    local.y = (ushort)(startPos.y + i);
                    local.z = startPos.z;
                    if (map.GetTile(local) == null
                        /*|| !map.GetTile(local).CanMoveTo(caster)
                         * TODO: Finish*/) {
                        continue;
                    }

                    if (spell.SpellArea[i, j] &&
                        !map.GetTile(local).ContainsType(Constants.TYPE_BLOCKS_MAGIC)) {
                        ThingSet tSet = map.GetThingsInVicinity(local);
                        foreach (Thing thing in tSet.GetThings()) {
                            thing.AddEffect(spell.SpellEffect, local);
                            if (spell.HasDistanceType()) {
                                thing.AddShootEffect((byte)spell.DistanceEffect,
                                    caster.CurrentPosition, spell.SpellCenter);
                            }
                        }

                        List<Thing> localThings = map.GetTile(local).GetThings();

                        if (spell.Action != null) {
                            spell.Action.Invoke(world, local, localThings);
                        }

                        foreach (Thing thing in map.GetTile(local).GetThings()) {
                            things.Add(thing);
                        }
                    }
                }
            }

            foreach (Thing thing in things) {
                thing.AppendHandleDamage(spell.GetDamage(), caster, spell.Immunity, world, true);
            }

            //caster.NotifyOfSuccessfulCast(spell); TODO: Uncomment
        }
Beispiel #5
0
 /// <summary>
 /// Notify this creature that the spell has been successfully
 /// cast.
 /// </summary>
 /// <param name="spell"></param>
 public virtual void NotifyOfSuccessfulCast(Spell spell)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Gets whether this creature can cast the specified spell.
 /// Returns null if the creature can or an error message if the
 /// creature can not.
 /// </summary>
 /// <param name="spell">The spell to check</param>
 /// <returns>Null if the creature can, an error message otherwise.
 /// </returns>
 public virtual string CanCastSpell(Spell spell)
 {
     return null;
 }