Ejemplo n.º 1
0
        private bool TryHandleSpell(string spellName, string[] args)
        {
            ISpellCast spellCast;
            Spell      spell;

            if (!TryMatchSpell(spellName, out spellCast))
            {
                throw new InvalidOperationException(
                          String.Format(
                              "...I don't know what kind of spell '{0}' is, but you probably shouldn't mess around with it.",
                              spellName));
            }

            if (!_player.Spells.TryGetValue(spellName, out spell))
            {
                throw new InvalidOperationException(String.Format("...You don't know that spell"));
            }

            // check to see if they have all of the required reagents.
            if (!spell.Reagents.All(x => _player.Items.Any(y => y.Id == x.Id)))
            {
                throw new InvalidOperationException(String.Format("...You feel that the spell is missing something."));
            }

            // Enough Mp?
            if (spell.MpRequired > _player.CurrentMp)
            {
                throw new InvalidOperationException(String.Format("...You're too tired to cast that spell."));
            }

            // High enough level?
            if (spell.MinLevel > _player.Level)
            {
                throw new InvalidOperationException(String.Format("...You're not skilled enough to cast that spell yet."));
            }

            var attrs = Attribute.GetCustomAttributes(spellCast.GetType());

            foreach (var attr in attrs) // Pehaps more attritubes in the future, so for now, iterate through the only 1 posssible ;)
            {
                if (attr is RequiresTargetAttribute && (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])))
                {
                    throw new InvalidOperationException(String.Format("...Who would you like to cast {0} on?", spellName));
                }
            }

            // Good to go, dock them the Mp's
            _player.CurrentMp -= spell.MpRequired;

            var context = new SpellContext
            {
                World = _world,
                NotificationService = _notificationService,
            };

            spellCast.Execute(context, _player, args);

            return(true);
        }
Ejemplo n.º 2
0
        public override void Execute(SpellContext context, Player callingPlayer, string[] args)
        {
            var completeRoom = context.World.GetCompleteRoom(callingPlayer.RoomReference);
            var target       = completeRoom.Players.FindByName(String.Join(" ", args[0]));
            var bystanders   = completeRoom.Players.ExcludePlayers(new [] { callingPlayer, target });

            if (target == null)
            {
                context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...The spell fizzles."));
                context.NotificationService.ToPlayers(completeRoom.Players.ExcludePlayer(callingPlayer),
                                                      new PlayerMessages(String.Format(
                                                                             "{0} attempts to cast a spell, but fails miserably.",
                                                                             callingPlayer.Name), MessageType.Important));
            }
            else
            {
                context.NotificationService.ToPlayers(bystanders,
                                                      new PlayerMessages(String.Format(
                                                                             "A gigantic ball of flame erupts from {0}'s hands and strikes {1} full on!",
                                                                             callingPlayer.Name, target.Name), MessageType.Attack));

                context.NotificationService.ToPlayer(target,
                                                     new PlayerMessages(
                                                         String.Format(
                                                             "A gigantic ball of flame erupts from {0}'s hands and strikes you in the chest!",
                                                             callingPlayer.Name), MessageType.Attack));

                context.NotificationService.ToPlayer(callingPlayer,
                                                     new PlayerMessages(String.Format(
                                                                            "A gigantic ball of flame leaps from your hands and strikes {0} full on!",
                                                                            target.Name), MessageType.Attack));

                if (target.IsDead(15))
                {
                    context.NotificationService.Die(target);
                }
            }
        }
Ejemplo n.º 3
0
        public override void Execute(SpellContext context, Player callingPlayer, string[] args)
        {
            var completeRoom = context.World.GetCompleteRoom(callingPlayer.RoomReference);
            var target = completeRoom.Players.FindByName(String.Join(" ", args[0]));
            var bystanders = completeRoom.Players.ExcludePlayers(new []{callingPlayer, target});

            if(target == null)
            {
                context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...The spell fizzles."));
                context.NotificationService.ToPlayers(completeRoom.Players.ExcludePlayer(callingPlayer),
                                                      new PlayerMessages(String.Format(
                                                          "{0} attempts to cast a spell, but fails miserably.",
                                                          callingPlayer.Name), MessageType.Important));
            }
            else
            {
                context.NotificationService.ToPlayers(bystanders,
                                                      new PlayerMessages(String.Format(
                                                          "A gigantic ball of flame erupts from {0}'s hands and strikes {1} full on!",
                                                          callingPlayer.Name, target.Name), MessageType.Attack));

                context.NotificationService.ToPlayer(target,
                                                     new PlayerMessages(
                                                         String.Format(
                                                             "A gigantic ball of flame erupts from {0}'s hands and strikes you in the chest!",
                                                             callingPlayer.Name), MessageType.Attack));

                context.NotificationService.ToPlayer(callingPlayer,
                                                      new PlayerMessages(String.Format(
                                                          "A gigantic ball of flame leaps from your hands and strikes {0} full on!",
                                                          target.Name), MessageType.Attack));

                if (target.IsDead(15))
                    context.NotificationService.Die(target);
            }
        }
Ejemplo n.º 4
0
 public override void Execute(SpellContext context, Player callingPlayer, string[] args)
 {
     context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("Got your teleport spell request."));
 }
Ejemplo n.º 5
0
 public override void Execute(SpellContext context, Player callingPlayer, string[] args)
 {
     context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("Got your teleport spell request."));
 }
Ejemplo n.º 6
0
 public abstract void Execute(SpellContext context, Player callingPlayer, string[] args);
Ejemplo n.º 7
0
        private bool TryHandleSpell(string spellName, string[] args)
        {
            ISpellCast spellCast;
            Spell spell;

            if (!TryMatchSpell(spellName, out spellCast))
            {
                throw new InvalidOperationException(
                    String.Format(
                        "...I don't know what kind of spell '{0}' is, but you probably shouldn't mess around with it.",
                        spellName));
            }

            if(!_player.Spells.TryGetValue(spellName, out spell))
                throw new InvalidOperationException(String.Format("...You don't know that spell"));

            // check to see if they have all of the required reagents.
            if (!spell.Reagents.All(x => _player.Items.Any(y => y.Id == x.Id)))
                throw new InvalidOperationException(String.Format("...You feel that the spell is missing something."));

            // Enough Mp?
            if(spell.MpRequired > _player.CurrentMp)
                throw new InvalidOperationException(String.Format("...You're too tired to cast that spell."));

            // High enough level?
            if(spell.MinLevel > _player.Level)
                throw new InvalidOperationException(String.Format("...You're not skilled enough to cast that spell yet."));

            var attrs = Attribute.GetCustomAttributes(spellCast.GetType());
            foreach (var attr in attrs) // Pehaps more attritubes in the future, so for now, iterate through the only 1 posssible ;)
            {
                if (attr is RequiresTargetAttribute && (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])))
                    throw new InvalidOperationException(String.Format("...Who would you like to cast {0} on?", spellName));
            }

            // Good to go, dock them the Mp's
            _player.CurrentMp -= spell.MpRequired;

            var context = new SpellContext
            {
                World = _world,
                NotificationService = _notificationService,
            };

            spellCast.Execute(context, _player, args);

            return true;
        }