private void CollisionHandler(IThrowingSegment segment, RaycastHit hit) { // Debug.LogFormat("Throwing collision dir:{0}, pos:{1}, normal:{2}", segment.RaySegment.Ray.direction, segment.RaySegment.Ray.origin, hit.normal); //glass broken var reflectiveFace = true; if (hit.collider.gameObject.layer == UnityLayers.GlassLayer) { var glassChunk = hit.collider.GetComponent <FracturedGlassyChunk>(); if (glassChunk != null) { glassChunk.MakeBroken(); } reflectiveFace = false; } if (DebugConfig.DrawThrowingLine) { RuntimeDebugDraw.Draw.DrawLine(segment.RaySegment.Ray.origin, (segment.RaySegment.Ray.origin + hit.normal * 5), Color.red, 60f); } ThrowingEntity throwing = segment.ThrowingEntity; //位置 throwing.position.Value = segment.RaySegment.Ray.origin; if (reflectiveFace) { //反射 throwing.throwingData.Velocity = Vector3.Reflect(throwing.throwingData.Velocity, hit.normal); //衰减 throwing.throwingData.Velocity *= (1 - throwing.throwingData.Config.CollisionVelocityDecay); } }
public static ThrowingEntity CreateThrowingEntity(PlayerWeaponController controller, int serverTime, Vector3 dir, Vector3 viePos, float initVel, WeaponResConfigItem newWeaponConfig, ThrowingConfig throwingConfig) { int throwingEntityId = EntityIdGenerator.GetNextEntityId(); Vector3 velocity = dir * initVel; ThrowingEntity throwingEntity = ThrowingContext.CreateEntity(); throwingEntity.AddEntityKey(new EntityKey(throwingEntityId, (int)EEntityType.Throwing)); // throwingEntity.AddThrowingData(velocity, false, false, 0, serverTime, false, initVel, throwingConfig, // newWeaponConfig.SubType); throwingEntity.AddThrowingData(throwingConfig, newWeaponConfig, initVel, 0, serverTime, velocity, newWeaponConfig.SubType); throwingEntity.AddPosition(); //TODO:EmitPos,ViewPos做射线检测取合适的点 throwingEntity.position.Value = viePos; throwingEntity.AddOwnerId(controller.Owner); throwingEntity.isFlagSyncNonSelf = true; throwingEntity.AddLifeTime(DateTime.Now, throwingConfig.CountdownTime + 2000); _logger.InfoFormat("CreateThrowing from {0} with velocity {1}, entity key {2}", throwingEntity.position.Value, throwingEntity.throwingData.Velocity, throwingEntity.entityKey); return(throwingEntity); }
private void CheckVisible(ThrowingEntity throwing) { if (throwing.hasThrowingGameObject && throwing.throwingData.IsThrow && throwing.throwingData.IsFly) { throwing.throwingGameObject.UnityObjWrapper.Value.SetActive(true); } }
private void StartFlying(PlayerEntity playerEntity, ThrowingEntity throwingEntity) { IPlayerWeaponState playerWeapon = playerEntity.weaponLogic.State; var dir = BulletDirUtility.GetThrowingDir(playerWeapon); Vector3 vel = dir * throwingEntity.throwingData.InitVelocity; Vector3 pos = PlayerEntityUtility.GetThrowingEmitPosition(playerEntity); throwingEntity.position.Value = pos; throwingEntity.throwingData.Velocity = vel; throwingEntity.throwingData.IsFly = true; //扔掉手雷 playerWeapon.LastGrenadeId = playerEntity.grenade.Id; if (SharedConfig.IsServer) { IEventArgs args = (IEventArgs)_contexts.session.commonSession.FreeArgs; if (!args.Triggers.IsEmpty((int)EGameEvent.WeaponState)) { SimpleParaList dama = new SimpleParaList(); dama.AddFields(new ObjectFields(playerWeapon)); dama.AddPara(new IntPara("CarryClip", playerWeapon.ReservedBulletCount)); dama.AddPara(new IntPara("Clip", playerWeapon.LoadedBulletCount)); dama.AddPara(new IntPara("ClipType", (int)playerWeapon.Caliber)); dama.AddPara(new IntPara("id", (int)playerWeapon.CurrentWeapon)); SimpleParable sp = new SimpleParable(dama); args.Trigger((int)EGameEvent.WeaponState, new TempUnit[] { new TempUnit("state", sp), new TempUnit("current", (FreeData)((PlayerEntity)playerWeapon.Owner).freeData.FreeData) }); } } playerWeapon.LastGrenadeId = 0; playerWeapon.IsThrowingStartFly = false; //清理状态 CastGrenade(playerEntity); }
public DefaultThrowingSegment(int serverTime, RaySegment raySegment, ThrowingEntity throwingEntity, PlayerContext playerContext) { _serverTime = serverTime; _raySegment = raySegment; _throwingEntity = throwingEntity; _playerContext = playerContext; }
private void ExplosionEffect(ThrowingEntity throwing) { //特效 int effectId; Vector3 effectPos = throwing.position.Value; if (SingletonManager.Get <MapConfigManager>().InWater(throwing.position.Value)) { effectId = throwing.throwingData.Config.WaterBombEffectId; float wy = SingletonManager.Get <MapConfigManager>().WaterSurfaceHeight(effectPos); if (!float.IsNaN(wy) && throwing.throwingData.WeaponSubType == (int)EWeaponSubType.Grenade) {//破片手雷水里特效拉到水面 effectPos.y = wy; } } else { effectId = throwing.throwingData.Config.BombEffectId; } //烟雾弹位置计算 if (throwing.throwingData.WeaponSubType == (int)EWeaponSubType.FogBomb) { effectPos = CommonMathUtil.GetSpacePos(effectPos, 0.5f, _layerMask); } PlayOneEffect(throwing, effectId, effectPos, true); }
public void DestroyThrowing(EntityKey entityKey) { ThrowingEntity throwing = _throwingContext.GetEntityWithEntityKey(entityKey); if (null != throwing) { throwing.isFlagDestroy = true; } }
public void UpdateThrowing(EntityKey entityKey, bool isThrow, float initVel) { ThrowingEntity throwing = _throwingContext.GetEntityWithEntityKey(entityKey); if (null != throwing) { throwing.throwingData.IsThrow = isThrow; throwing.throwingData.InitVelocity = initVel; } }
public static void StartThrowingEntityFly(EntityKey entityKey, bool isThrow, float initVel) { ThrowingEntity throwing = ThrowingContext.GetEntityWithEntityKey(entityKey); if (null != throwing) { throwing.throwingData.IsThrow = isThrow; throwing.throwingData.InitVelocity = initVel; } }
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 PlayOneEffect(ThrowingEntity throwing, int effectId, Vector3 effectPos, bool isBomb) { var entityIdGenerator = _contexts.session.commonSession.EntityIdGenerator; EClientEffectType effectType = EClientEffectType.GrenadeExplosion; int effectTime = _bombEffectTime; var bombAudioId = Core.EAudioUniqueId.GrenadeExplosion; if (isBomb) { //爆炸特效类型 switch ((EWeaponSubType)throwing.throwingData.WeaponSubType) { case EWeaponSubType.Grenade: effectType = EClientEffectType.GrenadeExplosion; break; case EWeaponSubType.FlashBomb: effectType = EClientEffectType.FlashBomb; bombAudioId = Core.EAudioUniqueId.FlashBombExplosion; break; case EWeaponSubType.FogBomb: effectType = EClientEffectType.FogBomb; bombAudioId = Core.EAudioUniqueId.FoggyBombExplosion; effectTime = _fogBombEffectTime; break; case EWeaponSubType.BurnBomb: effectType = EClientEffectType.BurnBomb; break; } } else { bombAudioId = EAudioUniqueId.None; } if (effectId > 0) { float effectYaw = throwing.throwingData.IsFly ? 0 : 1; var effectEntity = ClientEffectFactory.CreateGrenadeExplosionEffect(_contexts.clientEffect, entityIdGenerator, throwing.ownerId.Value, effectPos, effectYaw, 0, effectId, effectTime, effectType); if (effectEntity.hasAudio) { effectEntity.RemoveAudio(); } effectEntity.AddAudio((int)AudioClientEffectType.ThrowExplosion); effectEntity.audio.AudioClientEffectArg1 = (int)bombAudioId; } }
public List <IThrowingSegment> MoveThrowing(ThrowingEntity throwingEntity, int frameTime) { _entityAdapter.SetEntity(throwingEntity); List <IThrowingSegment> rc = new List <IThrowingSegment>(); _entityAdapter.RemainFrameTime += frameTime; while (_entityAdapter.RemainFrameTime >= _stepInterval) { int oldServerTime = _entityAdapter.ServerTime; int t = oldServerTime / _stepInterval; _entityAdapter.ServerTime = _stepInterval * (t + 1); float interval = (_entityAdapter.ServerTime - oldServerTime) / 1000.0f; Vector3 oldOrigin = _entityAdapter.Origin; // O(1) = O(0) + V(0) * t; _entityAdapter.Origin = _entityAdapter.Origin + _entityAdapter.Velocity * interval; if (DebugConfig.DrawThrowingLine) { RuntimeDebugDraw.Draw.DrawLine(oldOrigin, _entityAdapter.Origin, Color.blue, 60f); } // V(1) = V(0) + a * t Vector3 v = _entityAdapter.Velocity; v.y = v.y - _entityAdapter.Gravity * interval; v = v * Mathf.Pow(_entityAdapter.VelocityDecay, interval); _entityAdapter.Velocity = v; RaySegment raySegment = new RaySegment(); raySegment.Ray.origin = oldOrigin; var direction = _entityAdapter.Origin - oldOrigin; raySegment.Ray.direction = direction; raySegment.Length = direction.magnitude; DefaultThrowingSegment segment = new DefaultThrowingSegment(oldServerTime, raySegment, throwingEntity, _playerContext); rc.Add(segment); _entityAdapter.RemainFrameTime -= _stepInterval; } return(rc); }
private void BombingHandler(ThrowingEntity throwing) { switch ((EWeaponSubType)throwing.throwingData.WeaponSubType) { case EWeaponSubType.Grenade: GrenadeDamageHandler(throwing); break; case EWeaponSubType.FlashBomb: FlashDamageHandler(throwing); break; case EWeaponSubType.FogBomb: FogDamageHandler(throwing); break; case EWeaponSubType.BurnBomb: BurnDamageHandler(throwing); break; } }
private void PlayOneEffect(ThrowingEntity throwing, int effectId, Vector3 effectPos, bool isBomb) { var entityIdGenerator = _contexts.session.commonSession.EntityIdGenerator; EClientEffectType effectType = EClientEffectType.GrenadeExplosion; int effectTime = _bombEffectTime; if (isBomb) { //爆炸特效类型 switch ((EWeaponSubType)throwing.throwingData.WeaponSubType) { case EWeaponSubType.Grenade: effectType = EClientEffectType.GrenadeExplosion; break; case EWeaponSubType.FlashBomb: effectType = EClientEffectType.FlashBomb; break; case EWeaponSubType.FogBomb: effectType = EClientEffectType.FogBomb; effectTime = _fogBombEffectTime; break; case EWeaponSubType.BurnBomb: effectType = EClientEffectType.BurnBomb; break; } } if (effectId > 0) { float effectYaw = throwing.throwingData.IsFly ? 0 : 1; ClientEffectFactory.CreateGrenadeExplosionEffect(_contexts.clientEffect, entityIdGenerator, throwing.ownerId.Value, effectPos, effectYaw, 0, effectId, effectTime, effectType); } }
private void StartFlying(PlayerEntity playerEntity, ThrowingEntity throwingEntity) { var dir = BulletDirUtility.GetThrowingDir(playerEntity.WeaponController()); Vector3 vel = dir * throwingEntity.throwingData.InitVelocity; Vector3 pos = PlayerEntityUtility.GetThrowingEmitPosition(playerEntity.WeaponController()); throwingEntity.position.Value = pos; throwingEntity.throwingData.Velocity = vel; throwingEntity.throwingData.IsFly = true; if (SharedConfig.IsServer) { IEventArgs args = (IEventArgs)_contexts.session.commonSession.FreeArgs; if (!args.Triggers.IsEmpty((int)EGameEvent.WeaponState)) { SimpleParaList dama = new SimpleParaList(); //TODO 确认逻辑 dama.AddFields(new ObjectFields(playerEntity)); var weaponData = playerEntity.WeaponController().HeldWeaponAgent.ComponentScan; if (!weaponData.IsSafeVailed) { return; } dama.AddPara(new IntPara("CarryClip", playerEntity.WeaponController().GetReservedBullet())); dama.AddPara(new IntPara("Clip", weaponData.Bullet)); var config = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(weaponData.ConfigId); dama.AddPara(new IntPara("ClipType", null == config ? 0 : config.Caliber)); dama.AddPara(new IntPara("id", weaponData.ConfigId)); SimpleParable sp = new SimpleParable(dama); args.Trigger((int)EGameEvent.WeaponState, new TempUnit("state", sp), new TempUnit("current", (FreeData)(playerEntity).freeData.FreeData)); } } //清理状态 CastGrenade(_contexts, playerEntity); }
private void StartFlying(PlayerEntity playerEntity, ThrowingEntity throwingEntity) { var throwAmm = SingletonManager.Get <ThrowAmmunitionCalculator>(); var dir = throwAmm.GetFireDir(0, playerEntity.WeaponController(), 0); Vector3 pos = throwAmm.GetFireEmitPosition(playerEntity.WeaponController()); Vector3 vel = dir * throwingEntity.throwingData.InitVelocity; throwingEntity.position.Value = pos; throwingEntity.throwingData.Velocity = vel; throwingEntity.throwingData.IsFly = true; // DebugUtil.MyLog("StartFly Pos:{0} dir:{1}",pos,dir); /*if (SharedConfig.IsServer) * { * IEventArgs args = (IEventArgs)_contexts.session.commonSession.FreeArgs; * * if (!args.Triggers.IsEmpty(FreeTriggerConstant.WEAPON_STATE)) * { * SimpleParaList dama = new SimpleParaList(); * dama.AddFields(new ObjectFields(playerEntity)); * var weaponData = playerEntity.WeaponController().HeldWeaponAgent.ComponentScan; * if (!weaponData.IsSafeVailed) * return; * dama.AddPara(new IntPara("CarryClip", playerEntity.WeaponController().GetReservedBullet())); * dama.AddPara(new IntPara("Clip", weaponData.Bullet)); * var config = SingletonManager.Get<WeaponResourceConfigManager>().GetConfigById(weaponData.ConfigId); * dama.AddPara(new IntPara("ClipType", null == config ? 0 : config.Caliber)); * dama.AddPara(new IntPara("id", weaponData.ConfigId)); * SimpleParable sp = new SimpleParable(dama); * * args.Trigger(FreeTriggerConstant.WEAPON_STATE, new TempUnit("state", sp), new TempUnit("current", (FreeData)(playerEntity).freeData.FreeData) ); * } * }*/ //清理状态 AfterAttack(_contexts, playerEntity); }
public void SetEntity(ThrowingEntity throwingEntity) { _throwingEntity = throwingEntity; }
public ThrowingEntityAdapter(ThrowingEntity throwingEntity) { _throwingEntity = throwingEntity; }
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; } } } }
public static bool CanExplosion(this ThrowingEntity throwingEntity) { return(throwingEntity.hasLifeTime && (DateTime.Now - throwingEntity.lifeTime.CreateTime).TotalMilliseconds > throwingEntity.throwingData.ThrowConfig.CountdownTime); }
private void BurnDamageHandler(ThrowingEntity throwing) { }
private void FogDamageHandler(ThrowingEntity throwing) { }
public static bool CanStartFlySimulation(this ThrowingEntity throwingEntity) { return(throwingEntity.throwingData.IsThrow && !throwingEntity.throwingData.IsFly && !throwingEntity.isFlagDestroy); }