public BulletSimulationSystem(Contexts contexts, ICompensationWorldFactory compensationWorldFactory,
                                      IBulletHitHandler bulletHitHandler)
        {
            _bulletEntityCollector = new BulletEntityCollector(contexts.bullet, contexts.player);
            int layerMask = BulletLayers.GetBulletLayerMask();

            _bulletSimulator = new BulletHitSimulator(layerMask, compensationWorldFactory, bulletHitHandler,
                                                      SharedConfig.BulletSimulationIntervalTime);
        }
Пример #2
0
        private bool TryGetEffectShowHit(PlayerEntity playerEntity, out RaycastHit effectHit, float distance)
        {
            Vector3    pos;
            Quaternion rot;

            effectHit = new RaycastHit();
            if (playerEntity.TryGetMeleeAttackPosition(out pos) && playerEntity.TryGetMeleeAttackRotation(out rot))
            {
                if (Physics.Raycast(pos, rot.Forward(), out effectHit, distance, BulletLayers.GetBulletLayerMask()))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        protected override void ExecuteUserCmd(PlayerEntity player, IUserCmd cmd)
        {
            if (player.time.ClientTime < player.meleeAttackInfoSync.AttackTime)
            {
                return;
            }
            // Logger.Info("Try Attack One Time, Interval:"+ (player.meleeAttackInfoSync.AttackTime - player.meleeAttackInfoSync.BeforeAttackTime));
            // Logger.Info("Try Attack One Time, Interval:"+ (player.time.ClientTime - player.meleeAttackInfoSync.BeforeAttackTime));

            var config = player.meleeAttackInfo.AttackConfig;

            if (null == config)
            {
                Logger.Error("attack info in player MeleeAttackInfo is null");
                return;
            }
            var attackInfo = player.meleeAttackInfo.AttackInfo;

            player.RemoveMeleeAttackInfoSync();
            var compensationWorld = _compensationWorldFactory.CreateCompensationWorld(cmd.RenderTime);

            if (null == compensationWorld)
            {
                Logger.ErrorFormat("CompensationWorld is null for time {0}", cmd.RenderTime);
                return;
            }

            compensationWorld.Self = player.entityKey.Value;
            compensationWorld.ExcludePlayerList =
                player.playerHitMaskController.HitMaskController.MeleeExcludeTargetList;

            Quaternion rotation;

            player.TryGetMeleeAttackRotation(out rotation);
            RaycastHit hit;
            //小于这个距离没有检测,设一个足够小的值
            var     minDistance = 0.01f;
            var     extens      = new Vector3(config.Width, config.Height, minDistance);
            Vector3 emitPos;

            if (!PlayerEntityUtility.TryGetMeleeAttackPosition(player, out emitPos))
            {
                Logger.Error("get melee attack position failed ");
                emitPos = player.position.Value + Vector3.up * MeleeHitUtil.GetDefaultHeight(player);
            }

            var box = new BoxInfo
            {
                Length      = config.Range,
                Direction   = rotation.Forward(),
                Origin      = emitPos,
                Orientation = rotation,
                HalfExtens  = extens / 2f,
            };

            if (compensationWorld.BoxCast(box, out hit, BulletLayers.GetBulletLayerMask()))
            {
                PlayerEntity  targetPlayer  = null;
                VehicleEntity targetVehicle = null;
                var           comp          = hit.collider.transform.gameObject.GetComponent <HitBoxOwnerComponent>();
                if (comp != null)
                {
                    targetPlayer  = _contexts.player.GetEntityWithEntityKey(comp.OwnerEntityKey);
                    targetVehicle = _contexts.vehicle.GetEntityWithEntityKey(comp.OwnerEntityKey);
                }

                if (targetPlayer != null)
                {
                    hitHandler.OnHitPlayer(_contexts, player, targetPlayer, hit, attackInfo, config, cmd.Seq);
                }
                else if (targetVehicle != null)
                {
                    hitHandler.OnHitVehicle(_contexts, player, targetVehicle, hit, attackInfo, config);
                }
                else
                {
                    hitHandler.OnHitEnvrionment(_contexts, player, hit, attackInfo, config);
                }
            }

            compensationWorld.Release();
            // Logger.Info("Try Attack Finish");
        }