Beispiel #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);
            }
        }
Beispiel #2
0
        public override void Execute(Session session, CommandContext context)
        {
            var room = RoomHelper.GetRoom(session.Player.Location);

            if (room != null)
            {
                room.Description = StringHelpers.AutoTruncate(context.ArgumentString);
                RoomHelper.SaveRoom(room);
                session.WriteLine("Room description changed...");
            }
        }
Beispiel #3
0
        public override void Execute(Session session, CommandContext context)
        {
            var room = RoomHelper.GetRoom(session.Player.Location);

            if (room != null)
            {
                room.Title = context.ArgumentString;
                RoomHelper.SaveRoom(room);
                session.WriteLine("Room title changed...");
            }
        }
Beispiel #4
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrWhiteSpace(context.ArgumentString))
            {
                PrintSyntax(session);
                return;
            }

            // confirm room doesn't exist
            // todo: there will inevitably be rooms with similar names, so they'll need to be key'ed different
            var room = RoomHelper.GetRoom(context.ArgumentString);

            if (room != null)
            {
                session.WriteLine(string.Format("Room already exists: {0}", context.ArgumentString));
                return;
            }

            // get player area
            var  playerRoom = RoomHelper.GetRoom(session.Player.Location);
            var  areaKey    = string.Empty;
            Area area       = null;

            if (playerRoom != null)
            {
                areaKey = playerRoom.Area;
                if (!string.IsNullOrEmpty(areaKey))
                {
                    area = RoomHelper.GetArea(areaKey);
                }
            }

            // create room
            room = new Room()
            {
                Key         = context.ArgumentString.ToLower(),
                Title       = context.ArgumentString,
                Description = RoomHelper.GetDefaultRoomDescription(),
                Area        = areaKey,
            };

            // save room
            Server.Current.Database.Save <Room>(room);
            if (area != null)
            {
                area.Rooms.Add(room.Key);
                Server.Current.Database.Save <Area>(area);
            }

            // tell the admin player what the id is, so they can get to it
            session.WriteLine(string.Format("Room created: {0}", context.ArgumentString));
        }
Beispiel #5
0
        public override void Execute(Session session, CommandContext context)
        {
            // get room
            var room = RoomHelper.GetPlayerRoom(session.Player.Location);

            if (room == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find room");
                return;
            }

            // get area
            var area = RoomHelper.GetArea(room.Area);

            if (area == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find area");
                return;
            }

            Dictionary <string, string> players = new Dictionary <string, string>();

            // for each room in area, add players to list
            foreach (var roomKey in area.Rooms)
            {
                var theRoom = RoomHelper.GetRoom(roomKey);
                foreach (var playerInRoom in theRoom.GetPlayers())
                {
                    if (!players.ContainsKey(playerInRoom.Forename))
                    {
                        // get proper room name
                        var playerRoomName = RoomHelper.GetRoom(playerInRoom.Location);
                        players.Add(playerInRoom.Forename, playerRoomName.Title);
                    }
                }
            }

            session.WriteLine("Players in {0}:", area.Name);

            foreach (var player in players)
            {
                session.WriteLine(string.Format("{0,-20}{1}", player.Key, player.Value));
            }
        }
Beispiel #6
0
        public override void Execute(Session session, CommandContext context)
        {
            var room = RoomHelper.GetRoom(context.ArgumentString);

            if (room != null)
            {
                // remove player from current room
                var currentRoom = RoomHelper.GetRoom(session.Player.Location);
                if (currentRoom != null)
                {
                    currentRoom.RemovePlayer(session.Player);
                }

                room.AddPlayer(session.Player);
                session.Player.Location = context.ArgumentString;
            }

            var commandInfo = Server.Current.CommandLookup.FindCommand("look", session.Player);

            commandInfo.Command.Execute(session, CommandContext.Create("look"));
        }
Beispiel #7
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrEmpty(context.ArgumentString))
            {
                session.WriteLine("Pull what?");
                return;
            }

            var arg1 = context.Arguments[0];

            var room = RoomHelper.GetRoom(session.Player.Location);
            var item = ItemHelper.FindFloorItem(room, arg1.ToLower());

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

            if (!item.CanPull)
            {
                session.WriteLine("You can't pull that.");
                return;
            }

            session.WriteLine("You pull {0}", item.Name);

            switch (item.TemplateKey)
            {
            // this means new code every time a new pull object is created
            case "a dark lever":
                session.WriteLine("A bell echoes through eternity...");
                foreach (var admin in Server.Current.Database.GetAll <Player>().Where(p => p.IsAdmin))
                {
                    admin.Send(string.Format("`R{0} needs authorization...", session.Player.Forename), session.Player);
                }

                break;
            }
        }
Beispiel #8
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrEmpty(context.ArgumentString))
            {
                PrintSyntax(session);
                return;
            }

            var player = Server.Current.Database.Get <Player>(context.ArgumentString.ToLower());

            if (player == null)
            {
                session.WriteLine("Couldn't find {0}.", context.ArgumentString.ToLower());
                return;
            }

            if (player.Approved)
            {
                session.WriteLine("{0} doesn't need authorization right now.");
                return;
            }

            player.Approved = true;

            var srcRoom = RoomHelper.GetRoom(player.Location);
            var dstRoom = RoomHelper.GetRoom(Server.StartRoom);

            srcRoom.RemovePlayer(player);
            player.Location = dstRoom.Key;
            dstRoom.AddPlayer(player);
            dstRoom.SendPlayers(string.Format("{0} arrives in a blinding column of light.", player.Forename),
                                player, null, player);

            player.Experience = ExperienceResolver.FirstLevel;
            Server.Current.Database.Save(player);
            var commandInfo = Server.Current.CommandLookup.FindCommand("look", player);

            commandInfo.Command.Execute(Server.Current.SessionMonitor.GetPlayerSession(player), CommandContext.Create("look"));
            player.WritePrompt();
        }
Beispiel #9
0
        public override void Execute(Session session, CommandContext context)
        {
            var player = session.Player;

            session.WriteLine("`G--------------------------------------------------------------------------------");
            session.WriteLine("`G|Scorecard                                                                     |");
            session.WriteLine("`G--------------------------------------------------------------------------------");
            session.WriteLine("`G|`gName: `G{0,-20} `gGold: `Y${1,-44:N0}`G|", player.Forename, player.Gold, string.Empty);
            session.WriteLine("`G|`gLevel: `G{0,-4} `gExperience: `G{1,9:N0}`g/`G{2,-44:N0}`G|", player.Level, player.Experience,
                              ExperienceResolver.ExperienceRequired(player.Level + 1));
            session.WriteLine("`G--------------------------------------------------------------------------------");
            session.WriteLine("`G|`gSTR: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Strength, player.BaseStrength, string.Empty);
            session.WriteLine("`G|`gDEX: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Dexterity, player.BaseDexterity, string.Empty);
            session.WriteLine("`G|`gCON: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Constitution, player.BaseConstitution, string.Empty);
            session.WriteLine("`G|`gINT: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Intelligence, player.BaseIntelligence, string.Empty);
            session.WriteLine("`G|`gWIS: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Wisdom, player.BaseWisdom, string.Empty);
            session.WriteLine("`G|`gCHA: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Charisma, player.BaseCharisma, string.Empty);
            session.WriteLine("`G|`gLCK: `G{0,-2}`g[{1,-2}]{2,-67}`G|", player.Luck, player.BaseLuck, string.Empty);
            session.WriteLine("`G--------------------------------------------------------------------------------");
            session.WriteLine("`G|`gCurrent Location: `G{0,-60}`G|", RoomHelper.GetRoom(session.Player.Location).Title);
            session.WriteLine("`G--------------------------------------------------------------------------------");
        }
Beispiel #10
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;
            }
        }
Beispiel #11
0
        public override void Execute(Session session, CommandContext context)
        {
            var currentRoom = RoomHelper.GetRoom(session.Player.Location);

            if (currentRoom != null)
            {
                try
                {
                    string direction = context.Arguments[0];
                    context.Arguments.Remove(direction);

                    if (!DirectionHelper.isValidDirection(direction))
                    {
                        session.WriteLine("{0} is not a valid direction", direction);
                        PrintSyntax(session);
                    }
                    if (currentRoom.HasExit(direction))
                    {
                        session.WriteLine("Room already has {0} exit", direction);
                        PrintSyntax(session);
                        return;
                    }

                    // handle doors
                    string openClose = context.Arguments[0];
                    bool   isDoor;
                    bool   isOpen;
                    if (openClose == "<open>" || openClose == "<close>")
                    {
                        isDoor = true;
                        isOpen = openClose == "<open>";
                        context.Arguments.Remove(openClose);
                    }
                    else
                    {
                        isDoor = false;
                        isOpen = true;
                    }

                    // at this point, direction has been removed. all that remains if the new room key/name
                    string dstRoomKey = string.Join(" ", context.Arguments).Trim().ToLower();
                    var    dstRoom    = RoomHelper.GetRoom(dstRoomKey);
                    if (dstRoom == null)
                    {
                        session.WriteLine("Room key not found: {0}", dstRoomKey);
                        PrintSyntax(session);
                        return;
                    }

                    // fixme: confirm dstRoom doesn't already have the opposite exit e.g. if creating
                    // north exit, dstRoom should not already have south exit

                    currentRoom.Exits.Add(direction, new RoomExit()
                    {
                        LeadsTo = dstRoomKey,
                        IsDoor  = isDoor,
                        IsOpen  = isOpen
                    });

                    string oppositeDirection = DirectionHelper.GetOppositeDirection(direction);

                    dstRoom.Exits.Add(oppositeDirection, new RoomExit()
                    {
                        LeadsTo = currentRoom.Key,
                        IsDoor  = isDoor,
                        IsOpen  = isOpen
                    });

                    RoomHelper.SaveRoom(currentRoom);
                    RoomHelper.SaveRoom(dstRoom);
                }
                catch
                {
                    PrintSyntax(session);
                }
            }
        }
Beispiel #12
0
        public override void Execute(Session session, CommandContext context)
        {
            var skillsByLevel = Server.Current.CommandLookup.FindCommands(session.Player.Level);

            if (string.IsNullOrEmpty(context.ArgumentString))
            {
                // show list of skills
                foreach (
                    var command in
                    skillsByLevel
                    .Where(c => c.Command.GetType() == typeof(SkillCommands)))
                {
                    session.WriteLine("`B{0,-15}`C{1:#0%}", command.CommandName,
                                      session.Player.Skills.ContainsKey(command.CommandName.ToLower())
                                          ? session.Player.Skills[command.CommandName.ToLower()]
                                          : 0);
                }

                session.WriteLine("You have {0} skill points left.", session.Player.SkillPoints);

                return;
            }

            if (session.Player.SkillPoints == 0)
            {
                session.WriteLine("You need more skill points to practice that.");
                return;
            }

            var room = RoomHelper.GetRoom(session.Player.Location);

            if (!room.CanPracticeHere)
            {
                session.WriteLine("You can't practice here.");
                return;
            }

            // validate skill
            if (session.Player.Skills.ContainsKey(context.ArgumentString.ToLower()))
            {
                session.WriteLine("You've already practiced that.");
                return;
            }

            var arg1  = context.ArgumentString.ToLower();
            var skill = Server.Current.CombatSkills.FirstOrDefault(s => s.Name.ToLower() == arg1);

            if (skill == null || !skillsByLevel.Any(s => s.CommandName.ToLower() == arg1))
            {
                session.WriteLine("Can't practice that.");
                return;
            }

            // skill found, practice
            session.Player.Skills[skill.Key] = skill.Effectiveness;
            session.Player.SkillPoints--;
            session.WriteLine("You practice {0}.", skill.Name);

            // save player
            Server.Current.Database.Save(session.Player);
        }