private void InspectOldBulletHit(int cmdSeq, DefaultBulletSegment segment, CompensationWorld world) { RaycastHit camDirHit; if (world.Raycast(segment.RaySegment, out camDirHit, _hitboxLayerMask, cmdSeq)) { DebugUtil.AppendShootText(cmdSeq, "[Inspect]old world.Raycas sucess"); _bulletHitHandler.OnHit(cmdSeq, segment.BulletEntityAgent, camDirHit, world); } }
private void DoHitPlayer(PlayerEntity srcPlayer, IBulletEntityAgent bulletEntityAgent, RaycastHit hit) { Collider collider = hit.collider; bulletEntityAgent.SetAnimationAndColliderText(hitTargetPlayer.networkAnimator.ToStringExt(), GetCollidersDebugDatas(hitTargetPlayer)); EBodyPart part = BulletPlayerUtil.GetBodyPartByHitBoxName(collider); BulletHitHandler._logger.InfoFormat("[Hit{0}]HitPlayer in {1}", cmdSeq, part); float hitboxFactor = bulletEntityAgent.GetDamageFactor(part); float totalDamage = GetBulletDamage(bulletEntityAgent, hitboxFactor, Vector3.Distance(hit.point, bulletEntityAgent.GunEmitPosition)); bulletEntityAgent.IsValid = false; //由于动画放在客户端做了,服务器调用的命令会被忽视,需要发送事件到客户端 // if (hitTargetPlayer.hasStateInterface && hitTargetPlayer.stateInterface.State.CanBeenHit()) // { // hitTargetPlayer.stateInterface.State.BeenHit(); // } ClientEffectFactory.AddBeenHitEvent(srcPlayer, hitTargetPlayer, AttackUtil.GeneraterUniqueHitId(srcPlayer, cmdSeq), contexts.session.currentTimeObject.CurrentTime); //添加假红统计 if (hitTargetPlayer.gamePlay.IsAlive()) { srcPlayer.StatisticsController().AddShootPlayer(cmdSeq, bulletEntityAgent, hit.point, hitTargetPlayer.entityKey.Value, hitTargetPlayer.position.Value, part, totalDamage); } ClientEffectFactory.AddHitPlayerEffectEvent(srcPlayer, hitTargetPlayer.entityKey.Value, hit.point, (int)EAudioUniqueId.BulletHit, part); BulletHitHandler._logger.InfoFormat("[Hit{5}]bullet from {0} hit player {1}, part {2}, hitbox factor {3}, result damage {4}", bulletEntityAgent.OwnerEntityKey, hitTargetPlayer.entityKey.Value, collider, hitboxFactor, totalDamage, cmdSeq); if (!hitTargetPlayer.gamePlay.IsLastLifeState(EPlayerLifeState.Dead)) { //有效命中 if (hitTargetPlayer.gamePlay.IsLastLifeState(EPlayerLifeState.Alive)) { srcPlayer.statisticsData.Statistics.ShootingPlayerCount++; } srcPlayer.statisticsData.Statistics.ShootingSuccCount++; } BulletPlayerUtil.ProcessPlayerHealthDamage(contexts, damager, srcPlayer, hitTargetPlayer, new PlayerDamageInfo(totalDamage, (int)EUIDeadType.Weapon, (int)part, bulletEntityAgent.WeaponId, bulletEntityAgent.IsOverWall, false, false, bulletEntityAgent.HitPoint, bulletEntityAgent.Velocity)); DebugUtil.AppendShootText(cmdSeq, "[HitPlayer]hitPoint:{0},collider:{1},totalDamage:{2},part:{3}", hit.point, hit.collider, totalDamage, part); }
public void MoveBullet(IBulletEntityAgent bulletEntityAgent, int renderTime, List <DefaultBulletSegment> allBulletSegments, int cmdSeq) { if (renderTime < bulletEntityAgent.NextFrameTime) { return; } var origin = bulletEntityAgent.Position; var velocity = bulletEntityAgent.Velocity; var gravity = bulletEntityAgent.Gravity; var velocityDecay = bulletEntityAgent.VelocityDecay; var distance = bulletEntityAgent.Distance; float interval = (renderTime - bulletEntityAgent.ServerTime) / 1000.0f; Vector3 oldOrigin = origin; // O(1) = O(0) + V(0) * t; origin.x = origin.x + velocity.x * interval; origin.y = origin.y + velocity.y * interval; origin.z = origin.z + velocity.z * interval; if (DebugConfig.DrawBulletLine) { RuntimeDebugDraw.Draw.DrawLine(oldOrigin, origin, Color.blue, 60f); Debug.DrawLine(oldOrigin, origin, Color.red, 60f); } // V(1) = V(0) + a * t Vector3 v = velocity; v.y = v.y - gravity * interval; v = v * Mathf.Pow(velocityDecay, interval); velocity = v; RaySegment raySegment = new RaySegment(); raySegment.Ray.origin = oldOrigin; var direction = origin - oldOrigin; raySegment.Ray.direction = direction; raySegment.Length = direction.magnitude; distance += raySegment.Length; // string rayInfo = string.Format("direction {0}, length {1},readInterval {2}, move {3} -> {4}, stepinterval {5}",direction,raySegment.Length, interval, oldOrigin, origin, _stepInterval); DefaultBulletSegment segment = DefaultBulletSegment.Allocate(renderTime, raySegment, bulletEntityAgent); allBulletSegments.Add(segment); if (Mathf.Approximately(v.magnitude, 0)) { bulletEntityAgent.IsValid = false; _logger.ErrorFormat("bullet velocity is zero, set to invalid"); DebugUtil.AppendShootText(cmdSeq, "[Bullet Move] bullet {0}invalid", bulletEntityAgent.OwnerEntityKey); } bulletEntityAgent.Position = origin; bulletEntityAgent.ServerTime = renderTime; bulletEntityAgent.Velocity = velocity; bulletEntityAgent.Distance = distance; bulletEntityAgent.NextFrameTime = renderTime + _stepInterval; // DebugUtil.AppendShootText(cmdSeq,"[Bullet Move]rayInfo :{0} //// bulletInfo :{1} ",rayInfo,bulletEntityAgent.ToMoveString()); }
public virtual void UpdateHitBox(IGameEntity gameEntity, int renderTime, int cmdSeq) { DebugUtil.AppendShootText(cmdSeq, "[animator] {0}", gameEntity.GetComponent <NetworkAnimatorComponent>().ToStringExt()); DebugUtil.AppendShootText(cmdSeq, "[collider]\n{0}", GetCollidersDebugDatas(gameEntity.EntityKey)); }