コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <param name="room"></param>
        /// <param name="direction"></param>
        public static async Task MobMove(Player mob, Player ThingYourFollowing, 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.StartsWith(direction, StringComparison.CurrentCultureIgnoreCase));


                if (exit != null)
                {
                    if (exit.open == false)
                    {
                        return;
                    }

                    if (roomData.players.Count > 0)
                    {
                        foreach (var player in roomData.players)
                        {
                            HubContext.Instance.SendToClient(mob.Name + " leaves " + exit.name, player.HubGuid);
                        }
                    }

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

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

                    //Get new room
                    try
                    {
                        Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(mob);

                        if (getNewRoom != null)
                        {
                            //enter message
                            EnterRoom(mob, getNewRoom, direction);
                            //add player to new room
                            PlayerManager.AddMobToRoom(getNewRoom, mob);


                            //NPC Enter event here
                            foreach (var mobb in getNewRoom.mobs.Where(x => x.EventOnEnter != null).ToList())
                            {
                                if (!string.IsNullOrEmpty(mobb.EventOnEnter))
                                {
                                    Event.ParseCommand(mob.EventOnEnter, ThingYourFollowing, mobb, room);
                                }
                            }

                            if (!string.IsNullOrEmpty(room.EventOnEnter))
                            {
                                Event.ParseCommand(room.EventOnEnter, mob, null, room);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //log error
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <param name="room"></param>
        /// <param name="direction"></param>
        public static async Task MobMove(Player mob, Player ThingYourFollowing, Room room, string direction)
        {
            await Task.Delay(250);

            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)
                    {
                        return;
                    }

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

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

                    //Get new room
                    try
                    {
                        Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(mob);

                        if (getNewRoom != null)
                        {
                            //enter message
                            EnterRoom(mob, getNewRoom, direction);
                            //add player to new room
                            PlayerManager.AddMobToRoom(getNewRoom, mob);


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



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

                                if (!string.IsNullOrEmpty(room.EventOnEnter))
                                {
                                    Event.ParseCommand(room.EventOnEnter, mobb, null, room);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //log error
                    }
                }
            }
        }