private void OldRaycast() { ICompensationWorld lastCompensationWorld = null; foreach (var segment in _allThrowingSegments) { if (!segment.IsValid) { continue; } if (lastCompensationWorld != null) { if (lastCompensationWorld.ServerTime != segment.ServerTime) { lastCompensationWorld.Release(); lastCompensationWorld = _compensationWorldFactory.CreateCompensationWorld(segment.ServerTime); } } else { lastCompensationWorld = _compensationWorldFactory.CreateCompensationWorld(segment.ServerTime); if (lastCompensationWorld == null) { _logger.ErrorFormat("create compensation world at time {0}, FAILED", segment.ServerTime); } else { if (_logger.IsDebugEnabled) { _logger.DebugFormat("create compensation world at time {0}, SUCC", segment.ServerTime); } } } if (lastCompensationWorld != null) { RaycastHit hit; lastCompensationWorld.Self = segment.ThrowingEntity.ownerId.Value; lastCompensationWorld.ExcludePlayerList = segment.ExcludePlayerList; if (lastCompensationWorld.Raycast(segment.RaySegment, out hit, _layerMask)) { CollisionHandler(segment, hit); } } } if (lastCompensationWorld != null) { lastCompensationWorld.Release(); } }
private ICompensationWorld CreateWorld(DefaultBulletSegment segment) { var serverTime = segment.ServerTime; ICompensationWorld world; if (!_compensationWorlds.ContainsKey(serverTime)) { world = _compensationWorldFactory.CreateCompensationWorld(serverTime); if (world == null) { _logger.ErrorFormat("create compensation world at time {0}, FAILED", segment.ServerTime); segment.BulletEntity.IsValid = false; } else { _logger.DebugFormat("create compensation world at time {0}, SUCC", serverTime); _compensationWorlds[serverTime] = world; _compensationWorldList.Add(world); } } else { world = _compensationWorlds[serverTime]; } if (world == null) { return(null); } world.Self = segment.BulletEntity.OwnerEntityKey; world.ExcludePlayerList = segment.BulletEntity.ExcludePlayerList; return(world); }
private CompensationWorld CreateWorld(int cmdSeq, DefaultBulletSegment segment) { // DebugUtil.AppendShootText(cmdSeq,"Append Segment,renderTime:{0}",segment); var serverTime = segment.ServerTime; CompensationWorld world; if (!_compensationWorlds.TryGetValue(serverTime, out world)) { world = _compensationWorldCreator.CreateCompensationWorld(serverTime); if (world == null) { _logger.ErrorFormat("create compensation world at time {0}, FAILED", segment.ServerTime); segment.BulletEntityAgent.IsValid = false; } else { _logger.DebugFormat("create compensation world at time {0}, SUCC", serverTime); _compensationWorlds[serverTime] = world; _compensationWorldList.Add(world); } } if (world == null) { return(null); } world.Self = segment.BulletEntityAgent.OwnerEntityKey; world.ExcludePlayerList = segment.BulletEntityAgent.ExcludePlayerList; return(world); }
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"); }