Example #1
0
        public ServerGameEntity Create(Vector3 position, ushort tmpPlayerId, int accountId,
                                       ViewTypeEnum viewTypeEnum, WarshipSO warshipSo)
        {
            warshipSoValidator.Validate(warshipSo);

            ServerGameEntity entity = gameContext.CreateEntity();

            entity.AddPlayer(tmpPlayerId);
            entity.AddNickname("warship");
            entity.AddAccount(accountId);
            entity.AddMaxSpeed(warshipSo.maxVelocity);
            entity.AddAngularVelocity(warshipSo.angularVelocity);
            if (warshipSo.maxHealth <= 0)
            {
                throw new Exception($"Нельзя спавнить корабли таких хп {warshipSo.maxHealth}");
            }

            entity.AddHealthPoints(warshipSo.maxHealth);
            entity.AddMaxHealthPoints(warshipSo.maxHealth);
            entity.AddTeam((byte)(tmpPlayerId + 1));
            entity.AddViewType(viewTypeEnum);
            entity.AddSpawnTransform(position, Quaternion.identity);

            return(entity);
        }
        public ServerGameEntity CreateWarship(Vector3 position, ushort tmpPlayerId, int accountId,
                                              ViewTypeEnum viewTypeEnum)
        {
            WarshipSO warshipSo = warshipsCharacteristicsStorage.Get(viewTypeEnum);
            var       entity    = warshipEntityFactory.Create(position, tmpPlayerId, accountId, viewTypeEnum, warshipSo);

            log.Info($"accountId = {accountId} tmpPlayerId = {tmpPlayerId} id = {entity.id.value}");
            return(entity);
        }
        public void Validate(WarshipSO warshipSo)
        {
            if (warshipSo.prefab == null)
            {
                throw new Exception("3d модель не установлена");
            }

            if (warshipSo.maxHealth <= 0)
            {
                throw new Exception("Недопустимый показатель здоровья " + warshipSo.maxHealth);
            }

            if (warshipSo.angularVelocity <= 0)
            {
                throw new Exception("Недопустимый показатель угловой скорости " + warshipSo.angularVelocity);
            }

            if (warshipSo.maxVelocity <= 0)
            {
                throw new Exception("Недопустимый показатель линейной скорости " + warshipSo.maxVelocity);
            }
        }