CheatAction.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using ExitGames.Client.Photon;
  2. public class CheatAction : MainPhaseAction
  3. {
  4. public enum Type
  5. {
  6. None,
  7. Draw,
  8. TrashCard,
  9. PlaceCardOnDeck,
  10. PlaceCardInSecurity,
  11. PlaceCardInSecurityFaceup,
  12. GainMemory,
  13. LoseMemory,
  14. }
  15. Type CheatType;
  16. int PlayerID;
  17. public CheatAction(int playerID, Type cheatType)
  18. {
  19. PlayerID = playerID;
  20. CheatType = cheatType;
  21. }
  22. public CheatAction(byte[] bytes)
  23. {
  24. CheatType = Type.None;
  25. PlayerID = -1;
  26. Deserialize(bytes);
  27. }
  28. public override void Execute(TurnStateMachine stateMachine)
  29. {
  30. GManager gameManager = GManager.instance;
  31. Player player = gameManager.GetPlayerFromID(PlayerID);
  32. if (player == null)
  33. {
  34. return;
  35. }
  36. if (gameManager.AllowCheats())
  37. {
  38. switch (CheatType)
  39. {
  40. case Type.Draw:
  41. gameManager.StartCoroutine(gameManager.DrawCard(player));
  42. break;
  43. case Type.TrashCard:
  44. gameManager.StartCoroutine(gameManager.TrashCard(player));
  45. break;
  46. case Type.PlaceCardOnDeck:
  47. gameManager.StartCoroutine(gameManager.TopDeckCard(player));
  48. break;
  49. case Type.PlaceCardInSecurity:
  50. gameManager.StartCoroutine(gameManager.PlaceInSecurity(player, false));
  51. break;
  52. case Type.PlaceCardInSecurityFaceup:
  53. gameManager.StartCoroutine(gameManager.PlaceInSecurity(player, true));
  54. break;
  55. case Type.GainMemory:
  56. gameManager.StartCoroutine(gameManager.AlterMemory(player, 1));
  57. break;
  58. case Type.LoseMemory:
  59. gameManager.StartCoroutine(gameManager.AlterMemory(player, -1));
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. }
  66. public override void Deserialize(byte[] bytes)
  67. {
  68. int index = 0;
  69. Protocol.Deserialize(out int cheatTypeInt, bytes, ref index);
  70. CheatType = (Type)cheatTypeInt;
  71. Protocol.Deserialize(out PlayerID, bytes, ref index);
  72. }
  73. public override byte[] Serialize()
  74. {
  75. byte[] bytes = new byte[sizeof(int) * 2];
  76. int index = 0;
  77. Protocol.Serialize((int)CheatType, bytes, ref index);
  78. Protocol.Serialize(PlayerID, bytes, ref index);
  79. return bytes;
  80. }
  81. }