JumpAbilityEffect.cs (3341B)
1 using Slimecing.Characters; 2 using System; 3 using System.Collections; 4 using System.Collections.Generic; 5 using Slimecing.Abilities.UseAbilities; 6 using UnityEngine; 7 8 namespace Slimecing.Abilities.AbilityEffects 9 { 10 public class JumpAbilityEffect : AbilityEffect 11 { 12 private readonly JumpAbility _ability; 13 private readonly AbilityUser _aUser; 14 private readonly CharacterMovementController _characterMovementController; 15 private readonly float _jumpForce; 16 private readonly float _doubleForce; 17 private readonly float _jumpForceMultiplier; 18 private readonly float _simulatedJumpUpMass; 19 private readonly float _simulatedFallingMass; 20 private readonly int _jumpUseAmount; 21 22 private Vector3 _jumpDir; 23 private float _lastJumpMass; 24 private bool _fallMassSet; 25 private int _currentJumpUseAmount; 26 public bool canJump { get; set; } 27 28 public JumpAbilityEffect(Ability ability, AbilityUser aUser, CharacterMovementController controller, 29 float jumpForce, float doubleForce, float jumpForceMultiplier, float simulatedJumpUpMass, 30 float simulatedFallingUpMass, int jumpUseAmount ) : base(ability, aUser) 31 { 32 _ability = (JumpAbility) ability; 33 _aUser = aUser; 34 _characterMovementController = controller; 35 _jumpForce = jumpForce; 36 _doubleForce = doubleForce; 37 _jumpForceMultiplier = jumpForceMultiplier; 38 _simulatedJumpUpMass = simulatedJumpUpMass; 39 _simulatedFallingMass = simulatedFallingUpMass; 40 _jumpUseAmount = jumpUseAmount; 41 } 42 public override void Activate() 43 { 44 _jumpDir = -_characterMovementController.GravityDirection; 45 _lastJumpMass = _characterMovementController.SimulatedFallingMass; 46 _characterMovementController.SimulatedFallingMass = _simulatedJumpUpMass; 47 BeginJump(); 48 } 49 public override void DoUpdate() { 50 if (canJump) 51 { 52 _characterMovementController.AddForceTo(_jumpDir, _jumpForceMultiplier); 53 } 54 else 55 { 56 if (!_fallMassSet) 57 { 58 _characterMovementController.SimulatedFallingMass = _simulatedFallingMass; 59 _fallMassSet = true; 60 } 61 62 if (_characterMovementController.IsGrounded()) 63 { 64 End(); 65 } 66 } 67 } 68 69 private void BeginJump() 70 { 71 _currentJumpUseAmount = _jumpUseAmount; 72 _characterMovementController.AddForceTo(_jumpDir, _jumpForce); 73 _currentJumpUseAmount--; 74 } 75 76 public bool BeginDouble() 77 { 78 if (_currentJumpUseAmount <= 0) return false; 79 _characterMovementController.AddForceTo(_jumpDir, _doubleForce); 80 canJump = true; 81 _currentJumpUseAmount--; 82 return true; 83 } 84 85 public override void End() 86 { 87 _fallMassSet = false; 88 _characterMovementController.SimulatedFallingMass = _lastJumpMass; 89 _aUser.RemoveAbilityEffect(this); 90 } 91 92 public override bool DoesUpdate() => true; 93 } 94 }