private void GrenadeDamageHandler(ThrowingEntity throwing)
        {
            PlayerEntity sourcePlayer = null;

            if (throwing.hasOwnerId)
            {
                sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value);
            }

            Vector3 hitPoint;

            foreach (PlayerEntity player in _players)
            {
                float dis = Vector3.Distance(throwing.position.Value, player.position.Value);
                //头部
                Vector3   headPos = player.position.Value;
                Transform tran;
                if (player.appearanceInterface.Appearance.IsFirstPerson)
                {
                    var root = player.RootGo();
                    tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName);
                }
                else
                {
                    var root = player.RootGo();
                    tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName);
                }
                if (null != tran)
                {
                    headPos = tran.position;
                }
                if (dis < throwing.throwingData.Config.DamageRadius &&
                    ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) ||
                     !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) ||
                     !CommonMathUtil.Raycast(throwing.position.Value, headPos, dis, _layerMask, out hitPoint)))
                {
                    float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage;
                    _throwingHitHandler.OnPlayerDamage(sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.Chest, GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType)));
                }
            }
            foreach (VehicleEntity vehicle in _vehicles)
            {
                float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value);
                if (dis < throwing.throwingData.Config.DamageRadius &&
                    !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint))
                {
                    float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage;
                    _throwingHitHandler.OnVehicleDamage(vehicle, damage);
                }
            }
        }
        private void NewRaycast()
        {
            RaycastHit hit;

            foreach (var segment in _allThrowingSegments)
            {
                if (!segment.IsValid)
                {
                    continue;
                }

                bool isHit = CommonMathUtil.Raycast(segment.RaySegment.Ray, segment.RaySegment.Length, _layerMask, out hit);
                if (isHit)
                {
                    CollisionHandler(segment, hit);
                    break;
                }
            }
        }
Example #3
0
        private void CheckFlash(ClientEffectEntity entity)
        {
            PlayerEntity player = AllContexts.player.flagSelfEntity;

            //闪光弹位置
            Vector3 pos = entity.position.Value;

            //水里1米
            if (SingletonManager.Get <MapConfigManager>().InWater(pos))
            {
                float wy = SingletonManager.Get <MapConfigManager>().WaterSurfaceHeight(pos);
                if (!float.IsNaN(wy) && wy - pos.y > 1)
                {
                    return;
                }
            }

            bool    isShow = false;
            float   alpha = 0, keepTime = 0, decayTime = 0;
            Vector3 playerPos = player.position.Value;

            //位置稍上抬
            pos.y += 0.1f;

            //玩家头部位置
            Transform tran;

            if (player.appearanceInterface.Appearance.IsFirstPerson)
            {
                var root = player.RootGo();
                tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName);
            }
            else
            {
                var root = player.RootGo();
                tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName);
            }
            if (null != tran)
            {
                playerPos = tran.position;
            }

            //距离
            float dis = Vector3.Distance(playerPos, pos);

            if (dis >= 40)
            {
                return;
            }

            float diffAngle = 0;

            //判断是否手上爆炸
            bool isHandBomb = entity.hasEffectRotation && entity.effectRotation.Yaw > 0;

            if (!(entity.ownerId.Value == player.entityKey.Value && isHandBomb))
            {
                //遮挡
                Vector3 hitPoint;
                bool    isHit = CommonMathUtil.Raycast(playerPos, pos, dis, _layerMask, out hitPoint);
                if (isHit)
                {
                    return;
                }

                //角度
                float yaw   = CommonMathUtil.TransComAngle(player.orientation.Yaw);
                float angle = CommonMathUtil.GetAngle(new Vector2(pos.x, pos.z), new Vector2(playerPos.x, playerPos.z));
                diffAngle = Mathf.Abs(angle - yaw);
                diffAngle = Mathf.Min(360 - diffAngle, diffAngle);
            }

            if (diffAngle <= 60)
            {
                if (dis < 20)
                {
                    isShow    = true;
                    alpha     = 1;
                    keepTime  = Mathf.Max(1.2f, 3 * Mathf.Pow(0.4f, dis / 30));
                    decayTime = alpha / 0.4f;
                }
                else if (dis < 40)
                {
                    isShow    = true;
                    alpha     = 1 - dis * 0.00025f;
                    keepTime  = 0;
                    decayTime = alpha / 0.4f;
                }
            }
            else if (diffAngle <= 90)
            {
                if (dis <= 20)
                {
                    isShow    = true;
                    alpha     = Mathf.Max(0, 1 - dis * 0.00025f);
                    keepTime  = 0;
                    decayTime = alpha / 0.4f;
                }
            }
            else if (diffAngle <= 180)
            {
                if (dis <= 10)
                {
                    isShow    = true;
                    alpha     = Mathf.Max(0, 0.8f - dis * 0.00025f);
                    keepTime  = 0;
                    decayTime = alpha / 0.5f;
                }
            }

            if (isShow)
            {
                ScreenFlashInfo screenFlashInfo = new ScreenFlashInfo();
                screenFlashInfo.IsShow            = true;
                screenFlashInfo.Alpha             = alpha;
                screenFlashInfo.KeepTime          = keepTime;
                screenFlashInfo.DecayTime         = decayTime;
                AllContexts.ui.uI.ScreenFlashInfo = screenFlashInfo;
                player.AudioController().PlayDizzyAudio(dis, 40);
                //      GameAudioMedia.PlayFlashDizzyAudio(pos,Math.Min(0,40-dis));
            }
        }
        private void DrawThrowingLine(Vector3 pos, Vector3 vel, float gravity, float decay, float lineWidth, float deltaTime, float length)
        {
            if (null == _throwingMesh || !_assetLoaded)
            {
                return;
            }

            Vector3 movePos;
            Vector3 moveVel   = vel;
            float   sumLength = 0;

            _Vertices.Clear();
            _Uvs.Clear();

            Vector3 offset = Vector3.Cross(new Vector3(0, 1, 0), vel);

            offset = offset.normalized * lineWidth / 2;

            Vector3 oldPos;
            Vector3 hitPoint = new Vector3();
            float   moveLen  = 0;
            bool    isHit    = false;

            while (sumLength < length)
            {
                oldPos  = pos;
                movePos = moveVel * deltaTime;
                pos    += movePos;
                _Vertices.Add(new Vector3(pos.x - offset.x, pos.y, pos.z - offset.z));
                _Vertices.Add(new Vector3(pos.x + offset.x, pos.y, pos.z + offset.z));
                _Uvs.Add(new Vector2(sumLength / length, 0));
                _Uvs.Add(new Vector2(sumLength / length, 1));
                moveLen    = movePos.magnitude;
                sumLength += moveLen;
                moveVel.y  = moveVel.y - gravity * deltaTime;
                moveVel    = moveVel * Mathf.Pow(decay, deltaTime);
                isHit      = false;
                if (sumLength > _beginCollLength)
                {
                    isHit = CommonMathUtil.Raycast(oldPos, pos, moveLen, _layerMask, out hitPoint);
                }
                if (isHit)
                {
                    break;
                }
            }

            //triangles
            int vertLen = _Vertices.Count - 2;
            int triLen  = vertLen * 3;

            int[] triangles = new int[triLen];
            for (int i = 0, j = 0; i < triLen; i += 6, j += 2)
            {
                triangles[i]     = j;
                triangles[i + 1] = j + 1;
                triangles[i + 2] = j + 3;

                triangles[i + 3] = j;
                triangles[i + 4] = j + 3;
                triangles[i + 5] = j + 2;
            }

            _throwingMesh.Clear();
            _throwingMesh.vertices  = _Vertices.ToArray();
            _throwingMesh.triangles = triangles;
            _throwingMesh.uv        = _Uvs.ToArray();

            //Sphere
            if (isHit)
            {
                SetSpherePos(hitPoint);
            }
            else
            {
                SetSphereActive(false);
            }

            _isDrawLine = true;
        }
        private void GrenadeDamageHandler(ThrowingEntity throwing)
        {
            PlayerEntity sourcePlayer = null;

            if (throwing.hasOwnerId)
            {
                sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value);
            }

            Vector3 hitPoint;

            foreach (PlayerEntity player in _players)
            {
                if (player.hasPlayerMask && player.playerMask.SelfMask == (int)EPlayerMask.Invincible)
                {
                    continue;
                }

                float dis = Vector3.Distance(throwing.position.Value, player.position.Value);

                if (dis < throwing.throwingData.ThrowConfig.DamageRadius &&
                    ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) ||
                     !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) ||
                     !CommonMathUtil.Raycast(throwing.position.Value, player.bones.Head.position, dis, _layerMask, out hitPoint)))
                {
                    float damage = (1 - dis / throwing.throwingData.ThrowConfig.DamageRadius) * throwing.throwingData.ThrowConfig.BaseDamage;
                    _throwingHitHandler.OnPlayerDamage(_contexts, sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.None,
                                                                                                             GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType), false, false, false, player.position.Value, player.position.Value - throwing.position.Value));
                }
            }
            foreach (VehicleEntity vehicle in _vehicles)
            {
                float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value);
                if (dis < throwing.throwingData.ThrowConfig.DamageRadius &&
                    !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint))
                {
                    float damage = (1 - dis / throwing.throwingData.ThrowConfig.DamageRadius) * throwing.throwingData.ThrowConfig.BaseDamage;
                    _throwingHitHandler.OnVehicleDamage(vehicle, damage);
                }
            }
            var colliders = Physics.OverlapSphere(throwing.position.Value, throwing.throwingData.ThrowConfig.DamageRadius, UnityLayerManager.GetLayerMask(EUnityLayerName.UserInputRaycast) | UnityLayerManager.GetLayerMask(EUnityLayerName.Glass));

            foreach (var collider in colliders)
            {
                CreateMapObjWhenBomb(collider, sourcePlayer);

                var   distance   = Vector3.Distance(collider.transform.position, throwing.position.Value);
                float trueDamage = distance > throwing.throwingData.ThrowConfig.DamageRadius ? 0f : Mathf.Max(0f, throwing.throwingData.ThrowConfig.BaseDamage * (1 - distance / throwing.throwingData.ThrowConfig.DamageRadius));

                if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.UserInputRaycast))
                {
                    var parent = collider.transform;
                    while (null != parent)
                    {
                        var fractured = parent.GetComponent <FracturedObject>();
                        if (null != fractured)
                        {
                            if (!HasObstacle(collider.transform.position, throwing.position.Value, (obstacleTrans) =>
                            {
                                var obstacleParent = obstacleTrans.parent;
                                while (null != obstacleParent)
                                {
                                    if (obstacleParent == fractured.transform)
                                    {
                                        return(true);
                                    }
                                    obstacleParent = obstacleParent.parent;
                                }
                                return(false);
                            }))
                            {
                                fractured.Explode(Vector3.zero, trueDamage);
                            }
                            break;
                        }
                        parent = parent.parent;
                    }
                }
                if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Glass))
                {
                    var parent = collider.transform;
                    while (null != parent)
                    {
                        var fractured = parent.GetComponent <FracturedGlassyChunk>();
                        if (null != fractured)
                        {
                            fractured.MakeBroken();
                        }
                        parent = parent.parent;
                    }
                }
            }
        }