Exemplo n.º 1
0
        public override void Execute(Session session, CommandContext context)
        {
            // validate combat
            switch (session.Player.Status)
            {
            case GameStatus.Sleeping:
            case GameStatus.Sitting:
                session.WriteLine("Do you really think it's a good idea to fight while you're sitting or sleeping?");
                return;

            case GameStatus.Fighting:
                session.WriteLine("You're already fighting!");
                return;

            case GameStatus.Incapacitated:
            case GameStatus.MortallyWounded:
                session.WriteLine("You're dying...");
                return;
            }

            if (string.IsNullOrWhiteSpace(context.ArgumentString))
            {
                session.WriteLine("Kill what?");
                return;
            }

            // find mob
            var room = RoomHelper.GetRoom(session.Player.Location);
            var npc  = room.GetNpcs().FirstOrDefault(n => n.Keywords.Contains(context.ArgumentString));

            if (npc == null)
            {
                session.WriteLine("You can't find that here.");
                return;
            }

            if (npc.IsShopkeeper)
            {
                session.WriteLine("You can't fight a shopkeeper.");
                return;
            }

            var combat = new Game.Combat();

            if (npc.Status == GameStatus.Fighting)
            {
                // add player to combat
                Server.Current.CombatHandler.AddToCombat(session.Player, npc.Key);
            }
            else
            {
                // start new combat
                combat.AddFighter(session.Player);
                combat.AddMob(npc);
                Server.Current.CombatHandler.StartFight(combat);
            }
        }
Exemplo n.º 2
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrEmpty(context.ArgumentString))
            {
                session.WriteLine("{0} what?", context.CommandName);
                return;
            }

            var arg1 = context.ArgumentString.ToLower();

            // command lookup, should never be null or command lookup will handle
            // level check should already be done by command lookup
            var skill = Server.Current.Database.Get <CombatSkill>(realCommandName);

            // skill check i.e. does player have it?
            if (!session.Player.Skills.ContainsKey(skill.Key))
            {
                session.WriteLine("You haven't practiced that yet.");
                return;
            }

            // status check, start combat if not already there
            if (session.Player.Status != GameStatus.Fighting && session.Player.Status != GameStatus.Standing)
            {
                session.WriteLine("You can't do that right now.");
                return;
            }

            // target check
            var room   = RoomHelper.GetRoom(session.Player.Location);
            var target = room.GetNpcs().FirstOrDefault(n => n.Keywords.Contains(arg1));

            if (target == null)
            {
                session.WriteLine("You can't find that here.");
                return;
            }

            // combat check
            var fight = Server.Current.CombatHandler.FindFight(session.Player);

            if (fight == null)
            {
                // start fight, since npc is found
                fight = new Game.Combat();
                fight.AddFighter(session.Player);
                fight.AddMob(target);
                Server.Current.CombatHandler.StartFight(fight);
            }

            // do it
            if (Server.Current.Random.NextDouble() < session.Player.Skills[skill.Key])
            {
                // get damage
                var damage = Server.Current.Random.Next(skill.MinDamage, skill.MaxDamage + 1);
                // hit
                target.HitPoints -= damage;

                // increase skill effectiveness
                if (session.Player.Skills[skill.Key] < skill.MaxEffectiveness)
                {
                    session.Player.Skills[skill.Key] += skill.HitEffectivenessIncrease + target.HitPoints <= 0
                                                            ? skill.KillingBlowEffectivenessIncrease
                                                            : 0;
                }

                var damageAction = CombatHelper.GetDamageAction(target, damage);

                // message
                session.WriteLine("Your {0} {1} {2} for {3} damage!", realCommandName, damageAction.Plural, target.Name, damage);
                // room message
                room.SendPlayers(
                    string.Format("{0}{1} {2} {3} {4}!", session.Player.Forename,
                                  session.Player.Forename.ToLower().EndsWith("s") ? "'" : "s", skill.Key, damageAction.Plural, target.Name),
                    session.Player,
                    null,
                    session.Player);

                // dead check
                // this feels hacky since it sort of duplicates some of the work of Combat.DoPlayerHits()
                if (target.HitPoints <= 0)
                {
                    fight.RemoveFromCombat(target);
                    target.Die();
                    var deadText = string.Format("`R{0} is DEAD!!!", target.Name);
                    session.WriteLine(deadText);
                    room.SendPlayers(deadText, session.Player, null, session.Player);
                }
            }
            else
            {
                // message
                session.WriteLine("Your {0} misses {1}!", realCommandName, target.Name);
                // room message
                room.SendPlayers(string.Format("{0}{1} {2} misses {3}!", session.Player.Forename,
                                               session.Player.Forename.ToLower().EndsWith("s") ? "'" : "s", skill.Key,
                                               target.Name),
                                 session.Player, null,
                                 session.Player);
                // increase skill effectiveness by less
                session.Player.Skills[skill.Key] += skill.MissEffectivenessIncrease;
            }
        }