public void OnFrame(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { if (!_initialized) { _initialized = true; } if (cmd.IsFire && cmd.FilteredInput.IsInput(EPlayerInput.IsLeftAttack)) { DoReady(playerWeapon, cmd); } if (cmd.SwitchThrowMode) { DoSwitchMode(playerWeapon, cmd); } if (cmd.IsReload && cmd.FilteredInput.IsInput(EPlayerInput.IsReload)) { DoPull(playerWeapon, cmd); } if (cmd.IsThrowing && cmd.FilteredInput.IsInput(EPlayerInput.IsThrowing)) { DoThrowing(playerWeapon, cmd); } //判断打断 CheckBrokeThrow(playerWeapon, cmd); }
protected override float UpdateSpread(IPlayerWeaponState playerWeapon, float accuracy) { float param; if (playerWeapon.IsAir) { param = _config.AirParam; } else if (playerWeapon.HorizontalVeocity > Length2D1) { param = _config.LengthParam1; } else if (playerWeapon.HorizontalVeocity > Length2D2) { param = _config.LengthParam2; } else if (playerWeapon.IsDuckOrProneState) { param = _config.DuckParam; } else { param = _config.DefaultParam; } if (!playerWeapon.IsAiming) { param += _config.FovAddParam; } return(param); }
public AbstractWeaponSoundLogic(IPlayerWeaponState playerWeapon, ISoundEntityFactory soundEntityFactory, T1 config) : base(config) { _playerWeapon = playerWeapon; _soundEntityFactory = soundEntityFactory; }
public void OnFrame(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { int frameInterval = cmd.FrameInterval; if (playerWeapon.PunchDecayCdTime > 0) { playerWeapon.PunchDecayCdTime -= frameInterval; } else { var punchYaw = playerWeapon.NegPunchYaw; var punchPitch = playerWeapon.NegPunchPitch; var frameTime = frameInterval / 1000f; var len = (float)Mathf.Sqrt(punchYaw * punchYaw + punchPitch * punchPitch); if (len > 0) { punchYaw = punchYaw / len; punchPitch = punchPitch / len; len = UpdateLen(len, frameTime); var lastYaw = playerWeapon.NegPunchYaw; playerWeapon.NegPunchYaw = punchYaw * len; playerWeapon.NegPunchPitch = punchPitch * len; var factor = GetWeaponPunchYawFactor(playerWeapon); playerWeapon.WeaponPunchYaw = playerWeapon.NegPunchYaw * factor; playerWeapon.WeaponPunchPitch = playerWeapon.NegPunchPitch * factor; } } }
public MeleeWeaponSoundLogic( IPlayerWeaponState playerWeapon, ISoundEntityFactory soundEntityFactory, MeleeWeaponSoundConfig config) : base(playerWeapon, soundEntityFactory, config) { _playerWeapon = playerWeapon; }
public void OnFrame(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { playerWeapon.IsPrevCmdFire = cmd.IsFire; if (cmd.IsSwitchFireMode && cmd.FilteredInput.IsInput(XmlConfig.EPlayerInput.IsSwitchFireMode)) { EFireMode mode = playerWeapon.FireMode; EFireMode nextMode = _config.AvaiableModes[0]; for (int i = 0; i < _config.AvaiableModes.Length; i++) { if (_config.AvaiableModes[i] == mode) { nextMode = _config.AvaiableModes[(i + 1) % _config.AvaiableModes.Length]; } } if (nextMode == mode) { playerWeapon.ShowFireModeUnchangeTip(); } else { playerWeapon.ShowFireModeChangeTip(nextMode); } playerWeapon.FireMode = nextMode; playerWeapon.OnSwitchMode(_common); } }
/// <summary> /// 判断特殊换弹逻辑 /// </summary> /// <param name="playerWeapon"></param> /// <param name="cmd"></param> /// <returns>是否可以射击</returns> private bool BreakSpecialReload(IPlayerWeaponState playerWeapon) { if (!playerWeapon.IsReload) { _fireAfterBreakReload = false; return(true); } if (!_fireAfterBreakReload && playerWeapon.SpecialReloadCount > 0 && playerWeapon.LoadedBulletCount > 0) { if (playerWeapon.IsBolted) { //如果已经上膛,直接打断并开枪 playerWeapon.ForceBreakReloading(null); return(true); } else { //如果没有上膛,执行上膛,结束后开枪 playerWeapon.BreakReloading(); playerWeapon.IsBolted = true; _fireAfterBreakReload = true; } } return(false); }
private void CallOnFrame(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { foreach (var beforeFire in _frames) { beforeFire.OnFrame(playerWeapon, cmd); } }
private void CallOnIdle(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { foreach (var fireIdle in _idles) { fireIdle.OnIdle(playerWeapon, cmd); } }
public override void BeforeFireBullet(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bullet) { float spread = UpdateSpread(playerWeapon, playerWeapon.LastAccuracy); playerWeapon.LastSpreadX = spread * _config.SpreadScale.ScaleX; playerWeapon.LastSpreadY = spread * _config.SpreadScale.ScaleY; }
public void PlayBulletDropEffect(IPlayerWeaponState playerState) { var player = playerState.Owner as PlayerEntity; if (null == player) { Logger.Error("player state owner is not player or null !"); return; } var appearance = player.appearanceInterface.Appearance; var characterBone = player.characterBoneInterface.CharacterBone; var owner = player.entityKey.Value; var ejectTrans = characterBone.GetLocation(SpecialLocation.EjectionLocation, appearance.IsFirstPerson ? CharacterView.FirstPerson : CharacterView.ThirdPerson); if (null != ejectTrans) { ClientEffectFactory.CreateBulletDrop(_context, _idGenerator, owner, ejectTrans.position, playerState.ViewYaw, playerState.ViewPitch, _config.BulletDrop); } else { Logger.Error("Get ejectionLocation location failed"); } }
public void AfterFireBullet(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bullet) { if (playerWeapon.FireMode != WeaponConfigNs.EFireMode.Burst) { playerWeapon.BurstShootCount = 0; Running = false; return; } playerWeapon.BurstShootCount += 1; if (playerWeapon.BurstShootCount < MaxBurstCount) { playerWeapon.NextAttackTimer = (playerWeapon.ClientTime + BurstInterval); Running = true; } else { playerWeapon.NextAttackTimer = (playerWeapon.ClientTime + AttackInterval); playerWeapon.BurstShootCount = 0; Running = false; } if (IsTheLastBullet(playerWeapon)) { playerWeapon.BurstShootCount = 0; Running = false; } }
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); }
private void CallAfterFireCmds(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bulletCount) { foreach (var afterfire in _afterFireCmds) { afterfire.AfterFireCmd(playerWeapon, cmd, bulletCount); } }
public override void Update(IPlayerWeaponState playerWeapon, IUserCmd cmd) { _leftcmd.SetCurrentCmd(cmd); _rightCmd.SetCurrentCmd(cmd); _leftFireLogic.OnFrame(playerWeapon, _leftcmd); _rightFireLogic.OnFrame(playerWeapon, _rightCmd); }
public override void OnIdle(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { if (playerWeapon.ContinuesShootCount == 0) { playerWeapon.LastAccuracy = _config.InitAccuracy; } }
public void AfterAttack(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { playerWeapon.MeleeAttacking = true; playerWeapon.NextAttackingTimeLimit = playerWeapon.ClientTime + _maxCD; if (null != _soundLogic) { //_soundLogic.PlaySound(playerWeapon.Key, XmlConfig.EWeaponSoundType.LeftFire1); } if (null != _effectLogic) { } if (cmd.IsFire) { playerWeapon.StartMeleeAttack(cmd.RenderTime + _config.AttackInterval / 2, new MeleeAttackInfo { AttackType = MeleeAttckType.LeftMeleeAttack }, _config); } else { playerWeapon.StartMeleeAttack(cmd.RenderTime + _config.SpecialAttackInterval / 2, new MeleeAttackInfo { AttackType = MeleeAttckType.RightMeleeAttack }, _config); } playerWeapon.OnWeaponCost(); }
public void CreateBullet(IPlayerWeaponState playerWeapon, Vector3 direction, IBulletFireInfoProviderDispatcher bulletFireInfoProviderDispatcher, int cmdSeq, int renderTime) { PlayerEntity playerEntity = (PlayerEntity)playerWeapon.Owner; var bulletEntity = _bulletEntityFactory.CreateBulletEntity( cmdSeq, playerEntity.weaponLogicInfo.WeaponId, playerEntity.entityKey.Value, renderTime, direction, bulletFireInfoProviderDispatcher, _config, playerWeapon.Caliber) as BulletEntity; if (null != bulletEntity) { _logger.DebugFormat("Fire from {0} with velocity {1}, entity key {2}, cmd {3}", bulletEntity.position.Value, bulletEntity.bulletData.Velocity, bulletEntity.entityKey, cmdSeq); } }
private void Reload(IPlayerWeaponState weaponState) { var target = weaponState.BulletCountLimit - weaponState.LoadedBulletCount; target = Mathf.Max(0, target); DoRealod(weaponState, target); }
private void DoRealod(IPlayerWeaponState weaponState, int target) { target = Mathf.Min(target, weaponState.ReservedBulletCount); weaponState.LoadedBulletCount += target; weaponState.ReservedBulletCount -= target; IEventArgs args = (IEventArgs)(_sessonObjects).FreeArgs; if (!args.Triggers.IsEmpty((int)EGameEvent.WeaponState)) { SimpleParaList dama = new SimpleParaList(); dama.AddFields(new ObjectFields(weaponState)); dama.AddPara(new IntPara("CarryClip", weaponState.ReservedBulletCount)); dama.AddPara(new IntPara("Clip", weaponState.LoadedBulletCount)); dama.AddPara(new IntPara("ClipType", (int)weaponState.Caliber)); dama.AddPara(new IntPara("id", (int)weaponState.CurrentWeapon)); SimpleParable sp = new SimpleParable(dama); args.Trigger((int)EGameEvent.WeaponState, new TempUnit[] { new TempUnit("state", sp), new TempUnit("current", (FreeData)((PlayerEntity)weaponState.Owner).freeData.FreeData) }); } if (weaponState.LoadedBulletCount >= weaponState.BulletCountLimit || weaponState.ReservedBulletCount < 1) { //如果前置弹夹已满,或者后备弹夹已空,这时应该执行了最后一次换弹,应附带有拉栓动作 weaponState.IsBolted = true; } }
public BulletFireInfoProviderDispatcher(IPlayerWeaponState playerWeaponState) { _playerWeaponState = playerWeaponState; _sightBulletFireInfoProvider = new SightBulletFireInfoProvider(playerWeaponState); _defaultBulletFireInfoProvider = new DefaultBulletFireInfoProvider(playerWeaponState); _currentBulletFireInfoProvider = _defaultBulletFireInfoProvider; }
private void CallBeforeFire(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bullet) { foreach (var beforeFire in _beforeFires) { beforeFire.BeforeFireBullet(playerWeapon, cmd, bullet); } }
public DefaultWeaponSoundLogic( ISoundEntityFactory soundEntityFactory, IPlayerWeaponState playerWeapon, DefaultWeaponSoundConfig config) : base(config) { _playerWeapon = playerWeapon; _soundEntityFactory = soundEntityFactory; }
private void SpecialReload(IPlayerWeaponState weaponState) { var loadCount = weaponState.SpecialReloadCount; var target = weaponState.BulletCountLimit - weaponState.LoadedBulletCount; loadCount = Mathf.Min(loadCount, target); DoRealod(weaponState, loadCount); }
public static Vector3 GetBulletDir(IPlayerWeaponState playerWeapon, int seed, float spreadX, float spreadY) { var yaw = playerWeapon.ViewYaw - playerWeapon.NegPunchYaw * 2; var pitch = playerWeapon.ViewPitch - playerWeapon.NegPunchPitch * 2; var dir = CalculateShotingDir(seed, yaw, pitch, spreadX, spreadY); return(dir.normalized); }
public override void AfterFireBullet(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bullet) { KickbackGroup kickbackGroup = null; var hOffsetFactor = 1f; var vOffsetFactor = 1f; if (playerWeapon.IsAiming) { kickbackGroup = _config.Aiming; hOffsetFactor = _config.Aiming.HPunchOffsetFactor; vOffsetFactor = _config.Aiming.VPunchOffsetFactor; Logger.DebugFormat("animing offset {0}, {1}", hOffsetFactor, vOffsetFactor); } else { kickbackGroup = _config.Default; hOffsetFactor = _config.Default.HPunchOffsetFactor; vOffsetFactor = _config.Default.VPunchOffsetFactor; Logger.DebugFormat("default offset {0}, {1}", hOffsetFactor, vOffsetFactor); } WeaponConfigNs.Kickback kickBackParams; if (playerWeapon.IsAir) { kickBackParams = kickbackGroup.Air; } else if (playerWeapon.HorizontalVeocity > _config.FastMoveSpeed) { kickBackParams = kickbackGroup.FastMove; } else if (playerWeapon.IsProne) { kickBackParams = kickbackGroup.Prone; } else if (playerWeapon.IsDuckOrProneState) { kickBackParams = kickbackGroup.Duck; } else { kickBackParams = kickbackGroup.Base; } BaseKickBack(playerWeapon, cmd.CmdSeq + bullet, kickBackParams.UpBase, kickBackParams.LateralBase, kickBackParams.UpModifier, kickBackParams.LateralModifier, kickBackParams.UpMax, kickBackParams.LateralMax, kickBackParams.LateralTurnback, hOffsetFactor, vOffsetFactor); }
public WeaponFactory(IPlayerWeaponState playerWeaponState, CharacterStateManager characterState, IWeaponLogicFactory weaponLogicFactory, IFreeArgs freeArgs) { _playerWeaponState = playerWeaponState; _weaponLogicFactory = weaponLogicFactory; _bulletInfoProviderDispatcher = new BulletFireInfoProviderDispatcher(playerWeaponState); _freeArgs = freeArgs; }
public void OnFrame(IPlayerWeaponState playerWeapon, IWeaponCmd cmd) { if ((null != cmd.FilteredInput && cmd.FilteredInput.IsInput(XmlConfig.EPlayerInput.MeleeAttack)) && playerWeapon.CanMeleeFire()) { if (playerWeapon.MeleeAttacking) { if (playerWeapon.ClientTime > playerWeapon.NextAttackingTimeLimit) { playerWeapon.MeleeAttacking = false; } } if (playerWeapon.MeleeAttacking) { return; } if (cmd.IsFire) { // 轻击1 if (playerWeapon.ClientTime > playerWeapon.ContinuousAttackTime) { playerWeapon.OnLightMeleeFire(() => { playerWeapon.MeleeAttacking = false; playerWeapon.ContinuousAttackTime = playerWeapon.ClientTime + _config.AttackInterval; }); } // 轻击2 else { playerWeapon.OnSecondLightMeleeFire(() => { playerWeapon.MeleeAttacking = false; playerWeapon.ContinuousAttackTime = playerWeapon.ClientTime; }); } AfterAttack(playerWeapon, cmd); } else if (cmd.IsSpecialFire) { playerWeapon.OnMeleeSpecialFire(() => { playerWeapon.MeleeAttacking = false; }); AfterAttack(playerWeapon, cmd); } } else { if (null == cmd.FilteredInput) { Logger.Error("FilteredInput in cmd should never be null !"); } } }
public override void AfterFireBullet(IPlayerWeaponState playerWeapon, IWeaponCmd cmd, int bullet) { if (null == _config) { Logger.Error("config is null"); return; } playerWeapon.NegPunchPitch += _config.PunchPitch; playerWeapon.WeaponPunchPitch += _config.PunchPitch * _config.PunchOffsetFactor; }
protected override float GetWeaponPunchYawFactor(IPlayerWeaponState playerWeapon) { if (playerWeapon.IsAiming) { return(_config.Aiming.WeaponFallbackFactor); } else { return(_config.Default.WeaponFallbackFactor); } }