Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <param name="room"></param>
        /// <param name="direction"></param>
        public static void Move(Player player, Room room, string direction)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            if (player.Status == Player.PlayerStatus.Fighting)
            {
                HubContext.Instance.SendToClient("You are fighting! Try fleeing.", player.HubGuid);
                return;
            }

            if (player.Status == Player.PlayerStatus.Resting || player.Status == Player.PlayerStatus.Sleeping)
            {
                HubContext.Instance.SendToClient("You need to get up before you move.", player.HubGuid);
                return;
            }


            var isBlind = player.Effects?.FirstOrDefault(
                x => x.Name.Equals("Blindness", StringComparison.CurrentCultureIgnoreCase)) != null;



            if (player.MovePoints <= 0)
            {
                HubContext.Instance.SendToClient("You are exhausted an unable to move", player.HubGuid);

                foreach (var character in room.players)
                {
                    if (character != player)
                    {
                        HubContext.Instance.SendToClient(
                            $"{Helpers.ReturnName(player, character, string.Empty)} tries to move but is too exhausted.",
                            player.HubGuid);
                    }
                }
                return;
            }

            if (player.ActiveSkill != null)
            {
                HubContext.Instance.SendToClient("You are too busy to move.", player.HubGuid);
                return;
            }



            if (room.exits == null)
            {
                room.exits = new List <Exit>();
            }


            //Find Exit
            if (room.exits != null)
            {
                var exit = room.exits.Find(x => x.name == direction);


                if (exit != null)
                {
                    if (exit.open == false)
                    {
                        HubContext.Instance.AddNewMessageToPage(player.HubGuid, "The " + exit.doorName + " is close");
                        return;
                    }

                    //remove player from old room
                    PlayerManager.RemovePlayerFromRoom(room, player);

                    //exit message
                    ExitRoom(player, room, direction);

                    //change player Location
                    player.Area   = exit.area;
                    player.AreaId = exit.areaId;
                    player.Region = exit.region;

                    //Get new room
                    try
                    {
                        //Room getNewRoom =  await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid);
                        Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player);

                        if (getNewRoom != null)
                        {
                            //add player to new room
                            PlayerManager.AddPlayerToRoom(getNewRoom, player);


                            //enter message
                            EnterRoom(player, getNewRoom, direction);

                            var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name);

                            if (!isBlind)
                            {
                                HubContext.Instance.AddNewMessageToPage(player.HubGuid, roomDescription);
                            }
                            else
                            {
                                HubContext.Instance.SendToClient("You can't see a thing.", player.HubGuid);
                            }


                            foreach (var mob in getNewRoom.mobs)
                            {
                                if (mob.Greet)
                                {
                                    Event.ParseCommand("greet", player, mob, getNewRoom);
                                }


                                if (mob.MobTalkOnEnter && mob.DialogueTree != null && mob.DialogueTree.Count > 0)
                                {
                                    var speak = mob.DialogueTree[0];

                                    HubContext.Instance.AddNewMessageToPage(player.HubGuid, "<span class='sayColor'>" + mob.Name + " says to you \"" + speak.Message + "\"</span>");
                                    var i = 1;
                                    foreach (var respond in speak.PossibleResponse)
                                    {
                                        var textChoice =
                                            "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " +
                                            respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " +
                                            respond.Response + "</a>";
                                        HubContext.Instance.AddNewMessageToPage(player.HubGuid, textChoice);
                                        i++;
                                    }
                                }


                                if (mob.Aggro)
                                {
                                    HubContext.Instance.SendToClient($"{mob.Name} screams and attacks you", player.HubGuid);
                                    Player.MobAttack(player, mob, getNewRoom);
                                }

                                if (mob.EventOnEnter != null)
                                {
                                    Event.ParseCommand(mob.EventOnEnter, player, mob, room);
                                }



                                foreach (var quest in player.QuestLog.Where(x => x.Completed == false))
                                {
                                    if (quest.QuestHint != null && mob.Name == quest.QuestFindMob)
                                    {
                                        HubContext.Instance.SendToClient(quest.QuestHint, player.HubGuid);
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(getNewRoom.EventOnEnter))
                            {
                                Event.ParseCommand(getNewRoom.EventOnEnter, player, null, room);
                            }


                            Score.ReturnScoreUI(player);
                        }

                        stopwatch.Stop();
                        System.Diagnostics.Debug.WriteLine("Move room command speed: " + stopwatch.Elapsed);
                    }
                    catch (Exception e)
                    {
                        //log error
                    }
                }
                else
                {
                    HubContext.Instance.AddNewMessageToPage(player.HubGuid, "There is no exit here");
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <param name="room"></param>
        /// <param name="direction"></param>
        public static void Move(Player player, Room room, string direction)
        {
            if (player.MovePoints <= 0)
            {
                HubContext.SendToClient("You are exhausted an unable to move", player.HubGuid);

                foreach (var character in room.players)
                {
                    if (character != player)
                    {
                        HubContext.SendToClient($"{Helpers.ReturnName(player, character, string.Empty)} tries to move but is too exhausted.", player.HubGuid);
                    }
                }
                return;
            }


            Room roomData = room;

            if (roomData.exits == null)
            {
                room.exits = new List <Exit>();
            }


            //Find Exit
            if (roomData.exits != null)
            {
                var exit = roomData.exits.Find(x => x.name == direction);


                if (exit != null)
                {
                    if (exit.open == false)
                    {
                        HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("The " + exit.doorName + " is close");
                        return;
                    }

                    //remove player from old room
                    PlayerManager.RemovePlayerFromRoom(roomData, player);

                    //exit message
                    ExitRoom(player, roomData, direction);

                    //change player Location
                    player.Area   = exit.area;
                    player.AreaId = exit.areaId;
                    player.Region = exit.region;

                    //Get new room
                    try
                    {
                        //Room getNewRoom =  await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid);
                        Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player);

                        if (getNewRoom != null)
                        {
                            //add player to new room
                            PlayerManager.AddPlayerToRoom(getNewRoom, player);

                            //enter message
                            EnterRoom(player, getNewRoom, direction);

                            var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name);

                            HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(roomDescription);

                            //Show exits UI
                            ShowUIExits(getNewRoom, player.HubGuid);

                            //NPC Enter event here
                            foreach (var mob in getNewRoom.mobs)
                            {
                                if (mob.Greet)
                                {
                                    // Event.ParseCommand("greet", player, mob, getNewRoom);
                                }
                                else
                                {
                                    //mob might be aggro
                                }

                                if (mob.DialogueTree != null)
                                {
                                    var speak = mob.DialogueTree[0];

                                    HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(mob.Name + " says to you " + speak.Message);
                                    var i = 1;
                                    foreach (var respond in speak.PossibleResponse)
                                    {
                                        var textChoice = "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " + respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response + "</a>";
                                        HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(textChoice);
                                        i++;
                                    }
                                }

                                //if (!string.IsNullOrEmpty(mob.EventOnEnter))
                                //{
                                //   Event.ParseCommand(mob.EventOnEnter, player, mob, room);
                                //}

                                //if (!string.IsNullOrEmpty(room.EventOnEnter))
                                //{
                                //    Event.ParseCommand(room.EventOnEnter, player, null, room);
                                //}

                                foreach (var quest in player.QuestLog.Where(x => x.Completed == false))
                                {
                                    if (quest.QuestHint != null && mob.Name == quest.QuestFindMob)
                                    {
                                        HubContext.SendToClient(quest.QuestHint, player.HubGuid);
                                    }
                                }
                            }

                            Score.ReturnScoreUI(player);
                        }
                    }
                    catch (Exception e)
                    {
                        //log error
                    }
                }
                else
                {
                    HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("There is no exit here");
                }
            }
        }
Example #3
0
        //Create transport method

        public static void Teleport(Player player, Room room, Exit exit = null)
        {
            Room roomData = room;


            //remove player from old room
            PlayerManager.RemovePlayerFromRoom(roomData, player);

            if (exit != null)
            {
                //exit message
                ExitRoom(player, roomData, null, true);
            }

            //change player Location
            if (exit != null)
            {
                //change player Location
                player.Area   = exit.area;
                player.AreaId = exit.areaId;
                player.Region = exit.region;
            }
            else
            {
                player.Area   = room.area;
                player.AreaId = room.areaId;
                player.Region = room.region;
            }

            //Get new room
            try
            {
                //Room getNewRoom =  await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid);
                Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player);

                if (getNewRoom != null)
                {
                    //add player to new room
                    PlayerManager.AddPlayerToRoom(getNewRoom, player);

                    //enter message
                    EnterRoom(player, getNewRoom, null, true);

                    var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name);

                    if (player.Status != Player.PlayerStatus.Sleeping)
                    {
                        HubContext.Instance.AddNewMessageToPage(player.HubGuid, roomDescription);
                    }


                    //NPC Enter event here
                    foreach (var mob in getNewRoom.mobs)
                    {
                        if (mob.Greet)
                        {
                            Event.ParseCommand("greet", player, mob, getNewRoom);
                        }
                        else
                        {
                            //mob might be aggro
                        }

                        if (mob.MobTalkOnEnter && mob.DialogueTree != null && mob.DialogueTree.Count >= 1)
                        {
                            var speak = mob.DialogueTree[0];

                            HubContext.Instance.AddNewMessageToPage(player.HubGuid, "<span class='sayColor'>" + mob.Name + " says to you \"" + speak.Message + "\"</span>");
                            var i = 1;
                            foreach (var respond in speak.PossibleResponse)
                            {
                                var textChoice =
                                    "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " +
                                    respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response +
                                    "</a>";
                                HubContext.Instance.AddNewMessageToPage(player.HubGuid, textChoice);
                                i++;
                            }
                        }
                    }

                    ShowUIExits(getNewRoom, player.HubGuid);
                }
            }
            catch (Exception e)
            {
                //log error
            }
        }
Example #4
0
        public static void Move(Player player, Room room, string direction)
        {
            Room roomData = room;

            if (roomData.exits == null)
            {
                room.exits = new List <Exit>();
            }

            //Find Exit
            if (roomData.exits != null)
            {
                var exit = roomData.exits.Find(x => x.name == direction);


                if (exit != null)
                {
                    if (exit.open == false)
                    {
                        HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("The " + exit.doorName + " is close");
                        return;
                    }

                    //remove player from old room
                    PlayerManager.RemovePlayerFromRoom(roomData, player);

                    //exit message
                    ExitRoom(player, roomData, direction);

                    //change player Location
                    player.Area   = exit.area;
                    player.AreaId = exit.areaId;
                    player.Region = exit.region;

                    //Get new room
                    try
                    {
                        //Room getNewRoom =  await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid);
                        Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player.HubGuid);

                        if (getNewRoom != null)
                        {
                            //add player to new room
                            PlayerManager.AddPlayerToRoom(getNewRoom, player);

                            //enter message
                            EnterRoom(player, getNewRoom, direction);

                            var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name);

                            HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(roomDescription);

                            //NPC Enter event here
                            foreach (var mob in getNewRoom.mobs)
                            {
                                if (mob.Greet)
                                {
                                    Event.ParseCommand("greet", player, mob, getNewRoom);
                                }
                                else
                                {
                                    //mob might be aggro
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //log error
                    }
                }
                else
                {
                    HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("There is no exit here");
                }
            }
        }