Exemplo n.º 1
0
        /// <summary>
        /// 获取一个地块对象
        /// </summary>
        /// <param name="coordinate">地块坐标</param>
        /// <returns></returns>
        public Place GetPlace(Coordinate coordinate)
        {
            lock ( _sync )
            {
                Place place;
                if (places.TryGetValue(coordinate, out place))
                {
                    return(place);
                }


                var filepath = Path.ChangeExtension(Path.Combine(placesDirectory, coordinate.ToString()), _extensions);
                var data     = JsonDataItem.LoadData(filepath, new { CheckPoint = DateTime.UtcNow });

                place = GameHost.GameRules.CreatePlace(coordinate);
                place.InitializeData(this, data);

                return(place);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取一个玩家对象
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public GamePlayer GetPlayer(Guid userId)
        {
            lock ( _sync )
            {
                JsonPlayer player;
                if (players.TryGetValue(userId, out player))
                {
                    return(player);
                }


                var filepath = Path.ChangeExtension(Path.Combine(playersDirectory, userId.ToString("D")), _extensions);

                var data = JsonDataItem.LoadData(filepath, new { Nickname = NameService.AllocateName(), Initiation = GameHost.GameRules.GetInitiation(), Init = true, Resources = new ItemCollection() });


                player = new JsonPlayer(this, userId, data);
                player.Init();


                return(players[userId] = player);
            }
        }