CheatAction.cs 2.7 KB

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