private Player CreatePlayer(int userId, string playerName, Appearance appearance)
        {
            var random = new Random();
            var pos    = new Vector3((float)random.NextDouble() * 2f, 7.5f, (float)random.NextDouble() * 2f);

            if (appearance == null)
            {
                appearance = gameData.GenerateRandomAppearance();
            }
            else
            {
                appearance = gameData.CreateAppearance(appearance);
            }

            var transform = gameData.CreateTransform();

            transform.SetPosition(pos);
            transform.SetDestination(pos);

            var attributes  = gameData.CreateAttributes();
            var professions = gameData.CreateProfessions();

            var player = gameData.CreatePlayer();

            player.UserId        = userId;
            player.Name          = playerName;
            player.AttributesId  = attributes.Id;
            player.ProfessionsId = professions.Id;
            player.TransformId   = transform.Id;
            player.AppearanceId  = appearance.Id;

            inventoryProvider.CreateInventory(player.Id);

            //var addedPlayer = new Player()
            //{
            //    Id = id,
            //    Name = playerName,
            //    UserId = userId,
            //    TransformId = transform.Id,
            //    Created = DateTime.UtcNow,
            //    AppearanceId = appearance.Id
            //};

            //gameData.Add(player);
            return(player);
        }
Beispiel #2
0
        static void ImportGameObjects(ILogger logger, IGameData gameData)
        {
            var repo = new JsonBasedWorldObjectRepository();
            var objs = repo.AllObjects();

            if (objs.Count > 0)
            {
                logger.LogDebug("Removing existing objects..");
                var objects = gameData.GetAllGameObjects();
                foreach (GameObject obj in objects)
                {
                    var transform = gameData.GetTransform(obj.TransformId);
                    if (transform != null)
                    {
                        gameData.Remove(transform);
                    }

                    gameData.Remove(obj);
                }

                logger.LogDebug("Importing objects from json file..");
                foreach (var obj in objs)
                {
                    var transform = gameData.CreateTransform();
                    transform.SetPosition(obj.Position);
                    transform.SetRotation(obj.Rotation);

                    var newObj = gameData.CreateGameObject();
                    newObj.Id                  = obj.Id;
                    newObj.Type                = obj.Type;
                    newObj.InteractItemType    = obj.InteractItemType;
                    newObj.RespawnMilliseconds = obj.RespawnMilliseconds;
                    newObj.Static              = obj.Static;
                    newObj.Experience          = obj.Experience;
                    newObj.TransformId         = transform.Id;
                }
            }

            gameData.Flush();
        }