private void InitPostureSpeedScale() { _postureTransitionSpeedScale.Clear(); foreach (var info in _postureCurve) { _postureTransitionSpeedScale.Add(CharacterStateConfigHelper.GenerateId(info.StateOne, info.StateTwo), info.ScaleCurve); } }
private void InitMovementSpeedScale() { _movementTransitionSpeedScale.Clear(); foreach (var info in _movementCurve) { _movementTransitionSpeedScale.Add(CharacterStateConfigHelper.GenerateId(info.StateOne, info.StateTwo), info.ScaleCurve); } }
/// <summary> /// 默认不受武器影响 /// </summary> /// <param name="posture"></param> /// <param name="movement"></param> /// <returns></returns> public bool IsInfluencedByWeapon(PostureInConfig posture, MovementInConfig movement) { bool ret = false; int id = CharacterStateConfigHelper.GenerateId(posture, movement); if (_influencedByWeapon.ContainsKey(id)) { ret = _influencedByWeapon[id] > 0; } return(ret); }
public float GetPostureTransitionSpeedScale(PostureInConfig stateOne, PostureInConfig stateTwo, float normalizeTime) { int id = CharacterStateConfigHelper.GenerateId(stateOne, stateTwo); if (_postureTransitionSpeedScale.ContainsKey(id)) { return(_postureTransitionSpeedScale[id].Evaluate(normalizeTime)); } return(0.0f); }
private float GetMaxSpeed(float buff) { float maxSpeed = 0; var totalBuff = 1 + buff; bool valid = false; var candidateId1 = CharacterStateConfigHelper.GenerateId(_postureInConfig.InTransition() ? _postureInConfig.NextPosture() : _postureInConfig.CurrentPosture(), _movementInConfig.InTransition() ? _movementInConfig.NextMovement() : _movementInConfig.CurrentMovement()); var candidateId2 = CharacterStateConfigHelper.GenerateId(_postureInConfig.NextPosture(), MovementInConfig.Null); var candidateId3 = CharacterStateConfigHelper.GenerateId(_postureInConfig.CurrentPosture(), MovementInConfig.Null); var candidateId4 = CharacterStateConfigHelper.GenerateId(PostureInConfig.Null, _movementInConfig.CurrentMovement()); //_logger.InfoFormat("posture in transition:{0}, next posture:{1}, cur posture:{2}, move in transition:{3}, next move:{4}, CURRENT MOVE:{5}",_postureInConfig.InTransition() , _postureInConfig.NextPosture() , _postureInConfig.CurrentPosture(), // _movementInConfig.InTransition() , _movementInConfig.NextMovement() , _movementInConfig.CurrentMovement()); if (_speedConditionDictionary.ContainsKey(candidateId4)) { valid = true; _speedConditionDictionary[candidateId4].Invoke(); } else if (_speedConditionDictionary.ContainsKey(candidateId3)) { valid = true; _speedConditionDictionary[candidateId3].Invoke(); } else if (_speedConditionDictionary.ContainsKey(candidateId2)) { valid = true; _speedConditionDictionary[candidateId2].Invoke(); } else if (_speedConditionDictionary.ContainsKey(candidateId1)) { valid = true; _speedConditionDictionary[candidateId1].Invoke(); } if (valid) { float weaponSpeed = GetWeaponSpeed(_currentPosture, _currentMovement, _player.WeaponController().HeldWeaponAgent.BaseSpeed, _player.WeaponController().HeldWeaponAgent.DefaultSpeed); maxSpeed = SingletonManager.Get <CharacterStateConfigManager>().GetSpeed(_currentPosture, _currentMovement, _movement.IsForth, _movement.IsBack, _movement.IsLeft, _movement.IsRight, weaponSpeed); //_logger.InfoFormat("_currentPosture:{0}, _currentMovement:{1},_movement hor:{2}, _movemnt vert:{3}", _currentPosture, _currentMovement, _movement.HorizontalValue, _movement.VerticalValue); } //_logger.InfoFormat("valid:{4}, _currentPosture:{0}, _currentMovement:{1},_movement hor:{2}, _movemnt vert:{3}", _currentPosture, _currentMovement, _movement.HorizontalValue, _movement.VerticalValue, valid); return(maxSpeed * totalBuff); }
public float GetMovementTransitionSpeedScale(MovementInConfig stateOne, MovementInConfig stateTwo, float normalizeTime, float targetTime) { int id = CharacterStateConfigHelper.GenerateId(stateOne, stateTwo); if (_movementTransitionSpeedScale.ContainsKey(id)) { return((_movementTransitionSpeedScale[id].Evaluate(targetTime) - _movementTransitionSpeedScale[id].Evaluate(normalizeTime)) / (targetTime - normalizeTime)); } else { return(1.0f); } }
public int GetMovementTransitionTime(MovementInConfig stateOne, MovementInConfig stateTwo) { int id = CharacterStateConfigHelper.GenerateId(stateOne, stateTwo); if (_movementTransitionTime.ContainsKey(id)) { return(_movementTransitionTime[id]); } else { Logger.WarnFormat("duration not defined for {0} to {1}", stateOne, stateTwo); return(DefaultTransitionTime); } }
public float GetSpeed(PostureInConfig posture, MovementInConfig movement, bool isFront, bool isBack, bool isLeft, bool isRight, float standardSpeed) { float ret = 0; int id = CharacterStateConfigHelper.GenerateId(posture, movement); if (_coefficients.ContainsKey(id)) { var v = isFront ? Vertical.Front : isBack ? Vertical.Back : Vertical.Neutral; var h = isLeft ? Horizontal.Left : isRight ? Horizontal.Right : Horizontal.Neutral; ret = _coefficients[id].CoefficientByDirection[(int)v, (int)h] * standardSpeed; } return(ret); }
public override void ParseConfig(string xml) { if (string.IsNullOrEmpty(xml)) { Logger.ErrorFormat("SpeedConfig is Empty"); return; } ClearData(); var cfg = XmlConfigParser <CharacterStateConfig> .Load(xml); if (null == cfg) { Logger.ErrorFormat("character speed is illegal content:{0}", xml); return; } foreach (var v in cfg.SpeedCoefficients) { int id = CharacterStateConfigHelper.GenerateId(v.PostureState, v.MovementState); _coefficients.Add(id, new SpeedCoefficient ( v.Coefficient.Front, v.Coefficient.Rear, v.Coefficient.Left, v.Coefficient.Right, v.Coefficient.LeftFront, v.Coefficient.LeftRear, v.Coefficient.RightFront, v.Coefficient.RightRear )); _influencedByWeapon.Add(id, v.InfluencedByWeapon); } foreach (var v in cfg.PostureTransitions) { int id = CharacterStateConfigHelper.GenerateId(v.StateOne, v.StateTwo); _postureTransitionTime.Add(id, v.Duration); } foreach (var v in cfg.MovementTransitions) { int id = CharacterStateConfigHelper.GenerateId(v.StateOne, v.StateTwo); _movementTransitionTime.Add(id, v.Duration); } _jumpAcceleration = cfg.JumpAcceleration; _diveSpeed = cfg.DiveSpeed; _swimSpeed = cfg.SwimSpeed; _standardAnimationSpeed = cfg.StandardAnimationSpeed; _horizontalSpeed = cfg.SightShiftHorizontalSpeed; _horizontalLimit = cfg.SightShiftHorizontalLimit; _verticalSpeed = cfg.SightShiftVerticalSpeed; _verticalLimitMax = cfg.SightShiftVerticalLimitMax; _verticalLimitMin = cfg.SightShiftVerticalLimitMin; _verticalPeriodTimeMax = cfg.SightShiftVerticalPeriodTimeMax; _verticalPeriodTimeMin = cfg.SightShiftVerticalPeriodTimeMin; AirMoveCurveAssetInfo = new AssetInfo(cfg.JumpCurveInfo.BundleName, cfg.JumpCurveInfo.AssetName); _skyMoveConfig = new CharacterSkyMoveConfig() { SkyGravity = cfg.SkyGravity, SkyYawSpeed = cfg.SkyYawSpeed, SkyPitchSpeed = cfg.SkyPitchSpeed, SkyRollSpeed = cfg.SkyRollSpeed, SkyRollBackSpeed = cfg.SkyRollBackSpeed, SkyAcceleration = cfg.SkyAcceleration, MaxGlidingRollAngle = cfg.MaxGlidingRollAngle, MaxGlidingPitchUpAngle = cfg.MaxGlidingPitchUpAngle, GlidinRollVelocityDamper = cfg.GlidingRollVelocityDamper, MaxGlidingGravityVelocity = cfg.MaxGlidingGravityVelocity, MaxGlidingPitchUpVerticalVelocity = cfg.MaxGlidingPitchUpVerticalVelocity, MaxGlidingPitchDownVerticalVelocity = cfg.MaxGlidingPitchDownVerticalVelocity, GlidingAirResistance = cfg.GlidingAirResistance, GlidingAirKeyInputResistance = cfg.GlidingAirKeyInputResistance, ParachuteTime = cfg.ParachuteTime, MinParachuteHeight = cfg.MinParachuteHeight, ParachuteIdlePitchAngle = cfg.ParachuteIdlePitchAngle, MaxParachutePitchDownAngle = cfg.MaxParachutePitchDownAngle, MaxParachutePitchUpAngle = cfg.MaxParachutePitchUpAngle, MaxParachuteRollAngle = cfg.MaxParachuteRollAngle, MaxParachuteGravityVelocity = cfg.MaxParachuteGravityVelocity, ParachuteGravityDamper = cfg.ParachuteGravityDamper, ParachuteHorizontalDamper = cfg.ParachuteHorizontalDamper, MaxParachutePitchUpVerticalVelocity = cfg.MaxParachutePitchUpVerticalVelocity, MaxParachutePitchDownVerticalVelocity = cfg.MaxParachutePitchDownVerticalVelocity, ParachuteSwingAcceleration = cfg.ParachuteSwingAcceleration, ParachuteSwingDeacceleration = cfg.ParachuteSwingDeacceleration, ParachuteSwingAirResistance = cfg.ParachuteSwingAirResistance, MaxParachuteSwingVelocity = cfg.MaxParachuteSwingVelocity, SkyLandDeacceleration = cfg.SkyLandDeacceleration }; _skyMoveConfig.ValidateConfiguartion(); _steepConfig = new SteepConfig() { DownSteepAngles = cfg.DownSteepAngle, DownSteepBuffs = cfg.DownSteepBuff, UpSteepAngles = cfg.UpSteepAngle, UpSteepBuffs = cfg.UpSteepBuff, }; _longLayerWeightTransitionTime = cfg.LongLayerWeightTransitionTime; _holsterTransitionTime = cfg.HolsterTransitionTime; _attackTransitionTime = cfg.AttackTransitionTime; _shortLayerWeightTransitionTime = cfg.ShortLayerWeightTransitionTime; _zeroLayerWeightTransitionTime = cfg.ZeroLayerWeightTransitionTime; _beginSlowDownInWater = cfg.BeginSlowDownInWater; _stopSlowDownInWater = cfg.StopSlowDownInWater; _steepAverRatio = cfg.SteepAverRatio; _steepLimitSprintBegin = cfg.SteepLimitBegin; _steepLimitSprintStop = cfg.SteepLimitStop; _steepLimitRunBegin = cfg.SteepLimitRunBegin; _steepLimitRunStop = cfg.SteepLimitRunStop; //_maxSlopeNum = cfg.MaxSlopeNum; _headFollowRotateMax = cfg.HeadFollowRotateMaxH; _headFollowRotateMin = cfg.HeadFollowRotateMinH; _heckRotHorizontalIndex = cfg.NeckRotHorizontalIndex; _verticalHeadRotMax = cfg.HeadFollowRotateMaxV; _verticalHeadRotMin = cfg.HeadFollowRotateMinV; _neckRotVerticalIndex = cfg.NeckRotVerticalIndex; _headRotReversalTime = cfg.HeadRotReversalTime; _handRotMax = cfg.HandFollowRotateMax; _handRotMin = cfg.HandFollowRotateMin; PeekXTransition = cfg.PeekXTransition; PeekYTransition = cfg.PeekYTransition; PeekDegreeP1 = cfg.PeekDegreeP1; SightPeekDegree = cfg.SightPeekDegree; _landSlowDownTime = cfg.LandSlowDownTime; }
public SpeedManager(PlayerEntity player, Contexts contexts, ICharacterPosture posture, ICharacterMovement movement, ICharacterPostureInConfig postureInConfig, ICharacterMovementInConfig movementInConfig, ICharacterInfoProvider characterInfoProvider) { _contexts = contexts; _player = player; _posture = posture; _movement = movement; _postureInConfig = postureInConfig; _movementInConfig = movementInConfig; _characterInfoProvider = characterInfoProvider; _speedConditionDictionary = new Dictionary <int, Action>() { // 落地 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Land, MovementInConfig.Null), () => { SetCurrentState(PostureInConfig.Null, MovementInConfig.Null); } }, // 站立&静走 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Stand, MovementInConfig.Walk), () => { SetCurrentState(PostureInConfig.Stand, MovementInConfig.Walk); } }, // 站立&跑步 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Stand, MovementInConfig.Run), () => { SetCurrentState(PostureInConfig.Stand, MovementInConfig.Run); } }, // 站立&冲刺 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Stand, MovementInConfig.Sprint), () => { SetCurrentState(PostureInConfig.Stand, MovementInConfig.Sprint); } }, // 蹲下&静走 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Crouch, MovementInConfig.Walk), () => { SetCurrentState(PostureInConfig.Crouch, MovementInConfig.Walk); } }, // 蹲下&跑步 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Crouch, MovementInConfig.Run), () => { SetCurrentState(PostureInConfig.Crouch, MovementInConfig.Run); } }, // 蹲下&冲刺 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Crouch, MovementInConfig.Sprint), () => { SetCurrentState(PostureInConfig.Crouch, MovementInConfig.Sprint); } }, // 趴下&匍匐 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Prone, MovementInConfig.Null), () => { SetCurrentState(PostureInConfig.Prone, MovementInConfig.Walk); } }, // 游泳 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Swim, MovementInConfig.Null), () => { SetCurrentState(PostureInConfig.Swim, MovementInConfig.Swim); } }, // 潜水 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Dive, MovementInConfig.Null), () => { SetCurrentState(PostureInConfig.Dive, MovementInConfig.Dive); } }, // 受伤 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Dying, MovementInConfig.Null), () => { SetCurrentState(PostureInConfig.Dying, MovementInConfig.Walk); } }, // 受伤 { CharacterStateConfigHelper.GenerateId(PostureInConfig.Null, MovementInConfig.Ladder), () => { SetCurrentState(PostureInConfig.Null, MovementInConfig.Ladder); } } }; }