Exemplo n.º 1
0
 /// <summary>
 /// Notify this creature that the spell has been successfully
 /// cast.
 /// </summary>
 /// <param name="spell"></param>
 public virtual void NotifyOfSuccessfulCast(Spell spell)
 {
 }
Exemplo n.º 2
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
        }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Returns an error message if this player can not cast the
 /// specified spell. Returns null if the player can.
 /// </summary>
 /// <param name="spell">The spell to test.</param>
 /// <returns>Null if the play can, an error message if the player can't</returns>
 public override string CanCastSpell(Spell spell)
 {
     string error = null;
     if (MagicLevel < spell.RequiredMLevel) {
         error = "Your magic level is too low";
     } else if (CurrentMana < spell.ManaCost) {
         error = "You don't have enough mana.";
     } else if (!spell.VocationsFor.Contains(CurrentVocation)) {
         error = "Your vocation may not cast this spell.";
     }
     if (error != null) {
         World.AddMagicEffect(MagicEffect.PUFF, CurrentPosition);
     }
     return error;
 }
Exemplo n.º 8
0
 public override void NotifyOfSuccessfulCast(Spell spell)
 {
     CurrentMana = (ushort)(CurrentMana - spell.ManaCost);
     AppendAddManaSpent(spell.ManaCost * Config.GetManaRate());
     if (spell.Rune != null) {
         Item rune = spell.Rune;
         rune.Charges--;
         if (rune.Charges == 0) {
             World.AppendRemoveItem(rune);
         }
     }
     AddStats();
 }