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);
        }
        private void AddNewObject(ushort id, ViewTransformCompressed viewTransform)
        {
            ServerGameEntity gameEntity = gameContext.CreateEntity();

            gameEntity.AddId(id);
            gameEntity.AddViewType(viewTransform.viewTypeEnum);
            Quaternion quaternion = Quaternion.AngleAxis(viewTransform.Angle, Vector3.up);

            gameEntity.AddSpawnTransform(viewTransform.GetPosition(), quaternion);
        }
Example #3
0
        public void Execute()
        {
            var entities = needHealthBar.GetEntities();

            for (var index = 0; index < entities.Length; index++)
            {
                var entity = entities[index];
                if (!entity.hasView)
                {
                    log.Error("Если есть NeedHealthBar, то обязательно должен быть view");
                    continue;
                }

                //Создать полоску
                ServerGameEntity healthBarEntity = gameContext.CreateEntity();
                GameObject       prefab          = healthBarStorage.GetPrefab();
                GameObject       go = Object.Instantiate(prefab);
                go.Link(entity);
                go.transform.position = new Vector3(0, healthBarHeightStorage.GetHeight(entity.viewType.value));
                Slider slider = go.transform.Find("Slider").GetComponent <Slider>();
                if (slider == null)
                {
                    log.Error("Не найден слайдер на полоске хп");
                    continue;
                }

                TextMeshProUGUI username = go.transform.Find("Text_Username").GetComponent <TextMeshProUGUI>();
                if (username == null)
                {
                    log.Error("Не найден text username на полоске хп");
                    continue;
                }

                TextMeshProUGUI healthPoints = go.transform.Find("Slider/Text_HealthPoints")
                                               .GetComponent <TextMeshProUGUI>();
                if (healthPoints == null)
                {
                    log.Error("Не найден text healthPoints на полоске хп");
                    continue;
                }


                healthBarEntity.AddView(go);
                healthBarEntity.AddTransform(go.transform);
                healthBarEntity.AddHealthBar(slider, username, healthPoints, entity);

                if (entity.hasHealthBarParent)
                {
                    log.Error("У этой сущности не должно быть этого компонета.");
                    continue;
                }
                entity.AddHealthBarParent(healthBarEntity);
            }
        }
        // public override GameState PastState { get; set; }
        // public override GameState PresentState { get; set; }

        public override void Execute(ServerGameEntity damageEntity)
        {
            if (!damageEntity.hasTransform)
            {
                return;
            }

            if (!damageEntity.hasDamage)
            {
                return;
            }

            var testTransform = damageEntity.transform.value;

            if (testTransform == null)
            {
                log.Error("Transform пуст");
                return;
            }
            Vector3 currentPosition = damageEntity.transform.value.position;
            Vector3 direction       = damageEntity.transform.value.rotation * Vector3.forward;
            Vector3 velocity        = damageEntity.rigidbody.value.velocity * tickDeltaTimeStorage.GetDeltaTimeSec();

            //Есть столкновение?
            bool collisionOccurred = physicsRaycaster
                                     .Raycast(currentPosition, direction, velocity.magnitude, out RaycastHit raycastHit);

            if (!collisionOccurred)
            {
                return;
            }

            EntityLink       entityLink   = raycastHit.transform.gameObject.GetEntityLink();
            ServerGameEntity targetEntity = (ServerGameEntity)entityLink.entity;

            if (targetEntity == null)
            {
                return;
            }

            ushort entityId = targetEntity.id.value;

            //Проверка попадания по самому себе
            if (damageEntity.parentWarship.entity.id.value == entityId)
            {
                log.Error($"Попадание по самому себе parentId = {entityId}");
                return;
            }

            ServerGameEntity hitEntity = gameContext.CreateEntity();

            hitEntity.AddHit(damageEntity, targetEntity);
        }
Example #5
0
        public void Shoot(ServerGameEntity playerEntity, ServerInputEntity inputEntity)
        {
            if (playerEntity.hasCannonCooldown)
            {
                return;
            }

            float attackStickDirection = inputEntity.attack.direction;

            if (float.IsNaN(attackStickDirection))
            {
                return;
            }

            if (!playerEntity.hasShootingPoints)
            {
                log.Error("Если есть Attack то должен быть ShootingPoints");
                return;
            }

            //выстрел
            Transform        warshipTransform = playerEntity.transform.value;
            List <Transform> shootingPoints   = playerEntity.shootingPoints.values;

            playerEntity.ReplaceCannonCooldown(0.5f);
            foreach (var shootingTransform in shootingPoints)
            {
                //спавн пуль
                var projectileEntity = gameContext.CreateEntity();
                projectileEntity.AddTickNumber(inputEntity.creationTickNumber.value);
                projectileEntity.AddDamage(100);
                projectileEntity.AddViewType(ViewTypeEnum.DefaultShoot);
                // projectileEntity.isSpawnProjectile = true;
                Vector3 position = shootingTransform.position;
                // Debug.LogError($"shootingPoint.position {position.x} {position.y} {position.z}");
                Vector3 spawnPosition = warshipTransform.localPosition + position;
                projectileEntity.AddSpawnTransform(position, shootingTransform.rotation);
                Vector3 direction = shootingTransform.transform.rotation * Vector3.forward;
                projectileEntity.AddSpawnForce(direction.normalized * 20f);
                projectileEntity.AddParentWarship(playerEntity);
            }
        }