Пример #1
0
        public void OnHitEnvrionment(Contexts contexts, PlayerEntity src, RaycastHit hit, MeleeAttackInfo attackInfo,
                                     MeleeFireLogicConfig config)
        {
            var                    heldConfigId = src.WeaponController().HeldConfigId;
            RaycastHit             effectHit;
            bool                   showAttackEffect  = (MeleeHitUtil.CanMeleeAttackShowHit(src, out effectHit, config.Range));
            var                    collider          = effectHit.collider != null ? effectHit.collider : hit.collider;
            FracturedHittable      fracturedHittable = collider.GetComponent <FracturedHittable>();
            FracturedAbstractChunk fracturedChunk    = HitFracturedHandler.HitFracturedObj(src, effectHit, fracturedHittable);
            var                    hasHole           = fracturedChunk == null || (fracturedChunk.HasBulletHole && !fracturedChunk.IsBroken());

            if (showAttackEffect && hasHole)
            {
                int audioId = SingletonManager.Get <AudioWeaponManager>().FindById(heldConfigId).HitList.Body;
                ClientEffectFactory.AdHitEnvironmentEffectEvent(src, effectHit.point, effectHit.normal,
                                                                EEnvironmentType.Wood, audioId, 0, heldConfigId != WeaponUtil.EmptyHandId);
            }
        }
Пример #2
0
        public void OnHitVehicle(Contexts contexts, PlayerEntity src, VehicleEntity target, RaycastHit hit,
                                 MeleeAttackInfo attackInfo, MeleeFireLogicConfig config)
        {
            VehiclePartIndex partIndex;
            var baseDamage = MeleeHitUtil.GetVehicleFactor(hit, target, out partIndex) *
                             MeleeHitUtil.GetBaseDamage(attackInfo, config);
            var gameData = target.GetGameData();

            gameData.DecreaseHp(partIndex, baseDamage);
            if (!src.WeaponController().IsHeldSlotEmpty)
            {
                RaycastHit effectHit;
                if (MeleeHitUtil.CanMeleeAttackShowHit(src, out effectHit, config.Range))
                {
                    ClientEffectFactory.AddHitVehicleEffectEvent(src, target.entityKey.Value, effectHit.point,
                                                                 effectHit.point - target.position.Value, effectHit.normal);
                }
            }
        }
Пример #3
0
        public void OnHitPlayer(Contexts contexts, PlayerEntity src, PlayerEntity target, RaycastHit hit,
                                MeleeAttackInfo attackInfo, MeleeFireLogicConfig config, int seq)
        {
            EBodyPart part       = BulletPlayerUtil.GetBodyPartByHitBoxName(hit.collider);
            var       baseDamage = MeleeHitUtil.GetPlayerFactor(hit, config, part) *
                                   MeleeHitUtil.GetBaseDamage(attackInfo, config);

            if (src.hasStatisticsData)
            {
                src.statisticsData.Statistics.AttackType = (int)attackInfo.AttackType;
            }

            //有效命中

            /*if (target.gamePlay.IsLastLifeState(EPlayerLifeState.Alive))
             * {
             *  src.statisticsData.Statistics.ShootingPlayerCount++;
             * }*/
            var playerWeaponId            = src.WeaponController().HeldConfigId;
            WeaponResConfigItem newConfig =
                SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(playerWeaponId);
            EUIDeadType euiDeadType = (null != newConfig && newConfig.SubType == (int)EWeaponSubType.Hand)
                            ? EUIDeadType.Unarmed
                            : EUIDeadType.Weapon;

            BulletPlayerUtil.ProcessPlayerHealthDamage(contexts, _damager, src, target,
                                                       new PlayerDamageInfo(Mathf.CeilToInt(baseDamage), (int)euiDeadType, (int)part,
                                                                            src.WeaponController().HeldWeaponAgent.ConfigId, false, false, false, hit.point,
                                                                            target.position.Value - src.position.Value));

            //   Logger.InfoFormat("[Hit] process damage sucess,dvalue:{0}", baseDamage);
            //由于动画放在客户端做了,服务器调用的命令会被忽视,需要发送事件到客户端
            //            if (target.hasStateInterface && target.stateInterface.State.CanBeenHit())
            //            {
            //                target.stateInterface.State.BeenHit();
            //            }

            ClientEffectFactory.AddBeenHitEvent(src, target, AttackUtil.GeneraterUniqueHitId(src, seq),
                                                contexts.session.currentTimeObject.CurrentTime);
            int audioId = SingletonManager.Get <AudioWeaponManager>().FindById(playerWeaponId).HitList.Body;

            ClientEffectFactory.AddHitPlayerEffectEvent(src, target.entityKey.Value, hit.point, audioId, part);
        }
Пример #4
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");
        }