예제 #1
0
        /// <summary>
        /// Cast a spell. Returns if time passes.
        /// </summary>
        /// <returns></returns>
        private bool SelectAndCastSpell()
        {
            Dungeon dungeon = Game.Dungeon;
            Player player = Game.Dungeon.Player;

            //No casting in town or wilderness
            /*
            if (player.LocationLevel < 2)
            {
                Game.MessageQueue.AddMessage("You want to save your spells for the dungeons.");
                LogFile.Log.LogEntryDebug("Attempted to cast spell outside of dungeon", LogDebugLevel.Low);

                return false;
            }*/

            //Get the user's selection
            Spell toCast = SelectSpell();

            //User exited
            if (toCast == null)
                return false;

            //Get a target if needed

            Point target = new Point();
            bool targettingSuccess = true;

            if (toCast.NeedsTarget())
            {
                //Find spell range
                int range = toCast.GetRange();
                TargettingType targetType = toCast.TargetType();
                //Calculate FOV
                CreatureFOV currentFOV = Game.Dungeon.CalculateCreatureFOV(Game.Dungeon.Player);
                targettingSuccess = TargetAttack(out target, range, targetType, 0, 'z', currentFOV);
            }

            //User exited
            if (!targettingSuccess)
                return false;

            bool success = Game.Dungeon.Player.CastSpell(toCast, target);

            //Store details for a recast

            //If we successfully cast, store the target
            if (success)
            {
                //Only do this for certain spells
                if (toCast.GetType() != typeof(Spells.MagicMissile) && toCast.GetType() != typeof(Spells.FireLance) && toCast.GetType() != typeof(Spells.FireBall) && toCast.GetType() != typeof(Spells.EnergyBlast))
                    return success;

                lastSpell = toCast;

                //Spell target is the creature (monster or PC)

                SquareContents squareContents = dungeon.MapSquareContents(player.LocationLevel, target);

                //Is there a creature here? If so, store
                if (squareContents.monster != null)
                    lastSpellTarget = squareContents.monster;

                if (squareContents.player != null)
                    lastSpellTarget = squareContents.player;
            }
            else
            {
                //Failure store the spell anyway
                lastSpell = toCast;
            }

            //Time only goes past if successfully cast
            return success;
        }
예제 #2
0
        public bool CastSpell(Spell toCast, Point target)
        {
            //Check MP
            if (toCast.MPCost() > MagicPoints)
            {
                Game.MessageQueue.AddMessage("Not enough MP! " + toCast.MPCost().ToString() + " required.");
                LogFile.Log.LogEntryDebug("Not enough MP to cast " + toCast.SpellName(), LogDebugLevel.Medium);

                return false;
            }

            //Check we are in target
            int range = toCast.GetRange();
            /*
            if (Inventory.ContainsItem(new Items.ExtendOrb()))
            {
                range += 1;
            }*/

            if (toCast.NeedsTarget() && Utility.GetDistanceBetween(LocationMap, target) > range)
            {
                Game.MessageQueue.AddMessage("Out of range!");
                LogFile.Log.LogEntryDebug("Out of range for " + toCast.SpellName(), LogDebugLevel.Medium);

                return false;
            }

            //Actually cast the spell
            bool success = toCast.DoSpell(target);

            //Remove MP if successful
            if (success)
            {
                MagicPoints -= toCast.MPCost();
                if (MagicPoints < 0)
                    MagicPoints = 0;

                //Using magic is an instrinsic
                MagicUse = true;
            }

            return success;
        }
예제 #3
0
        private bool RecastSpellCastAtCreature(Spell spell, Creature target)
        {
            //Convert the stored Creature last target into a square
            Point spellTargetSq = new Point(target.LocationMap.x, target.LocationMap.y);

            return Game.Dungeon.Player.CastSpell(spell, spellTargetSq);
        }