SwapManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SwapManager
  4. {
  5. public const float PREPARING_SWAP_DURATION = 3f;
  6. public const float SWAP_CD = 3f;
  7. public int targetSwapId;
  8. public bool isPreparingSwap;
  9. public float preparingSwapStartTime;
  10. public bool requestedSwap;
  11. public float lastSwapTime;
  12. private Craft craft;
  13. public SwapManager(Craft craft)
  14. {
  15. this.craft = craft;
  16. lastSwapTime = GameTime.time;
  17. }
  18. public void PrepareSwap(int targetSwapId)
  19. {
  20. this.targetSwapId = targetSwapId;
  21. isPreparingSwap = true;
  22. preparingSwapStartTime = GameTime.time;
  23. craft.StopMove();
  24. }
  25. public float GetPreparingSwapTime()
  26. {
  27. if(preparingSwapStartTime < 0)
  28. return 0;
  29. return Mathf.Min(GameTime.time - preparingSwapStartTime, PREPARING_SWAP_DURATION);
  30. }
  31. public bool IsReadySwap()
  32. {
  33. return GetPreparingSwapTime() == PREPARING_SWAP_DURATION;
  34. }
  35. public void AbortSwap()
  36. {
  37. if(requestedSwap)
  38. return;
  39. preparingSwapStartTime = -1f;
  40. isPreparingSwap = false;
  41. craft.GetHeadBar().HideSpell();
  42. }
  43. public int GetTargetSwapId()
  44. {
  45. return targetSwapId;
  46. }
  47. public void RequestedSwap()
  48. {
  49. preparingSwapStartTime = -1f;
  50. requestedSwap = true;
  51. }
  52. public void Swap(CraftModel craftModel, int craftId, CraftEquipModify equipModify)
  53. {
  54. if(craft.IsDead())
  55. return;
  56. lastSwapTime = GameTime.time;
  57. craft.GetHeadBar().HideSpell();
  58. isPreparingSwap = false;
  59. requestedSwap = false;
  60. craft.SetEquipModify (equipModify);
  61. craft.SetCraftId (craftId);
  62. craft.SetCraftModel (craftModel);
  63. craft.Init();
  64. craft.team = craft.team;
  65. craft.SwapComplete();
  66. }
  67. public float GetSwapCoolDown()
  68. {
  69. return Mathf.Min(GameTime.time - lastSwapTime, SWAP_CD);
  70. }
  71. }