inventoryinputuserdata.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. class InventoryInputUserData
  2. {
  3. ///@{ move
  4. static void SerializeMove(ParamsWriteContext ctx, int type, notnull InventoryLocation src, notnull InventoryLocation dst)
  5. {
  6. ctx.Write(INPUT_UDT_INVENTORY);
  7. ctx.Write(type);
  8. src.WriteToContext(ctx);
  9. dst.WriteToContext(ctx);
  10. }
  11. static void SendInputUserDataMove(int type, notnull InventoryLocation src, notnull InventoryLocation dst)
  12. {
  13. if (GetGame().IsClient())
  14. {
  15. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms sending cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  16. ScriptInputUserData ctx = new ScriptInputUserData;
  17. SerializeMove(ctx, type, src, dst);
  18. ctx.Send();
  19. }
  20. }
  21. static void SendServerMove(Man player, int type, notnull InventoryLocation src, notnull InventoryLocation dst)
  22. {
  23. if (GetGame().IsServer())
  24. {
  25. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] server sending cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  26. ScriptInputUserData ctx = new ScriptInputUserData;
  27. SerializeMove(ctx, type, src, dst);
  28. GameInventory.ServerLocationSyncMoveEntity(player, src.GetItem(), ctx);
  29. }
  30. }
  31. ///@} move
  32. ///@{ swap
  33. static void SerializeSwap(ParamsWriteContext ctx, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, bool skippedSwap)
  34. {
  35. ctx.Write(INPUT_UDT_INVENTORY);
  36. ctx.Write(InventoryCommandType.SWAP);
  37. src1.WriteToContext(ctx);
  38. src2.WriteToContext(ctx);
  39. dst1.WriteToContext(ctx);
  40. dst2.WriteToContext(ctx);
  41. ctx.Write(skippedSwap);
  42. }
  43. static void SendInputUserDataSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, bool skippedSwap = false)
  44. {
  45. if (GetGame().IsClient())
  46. {
  47. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms sending cmd=SWAP src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  48. ScriptInputUserData ctx = new ScriptInputUserData;
  49. SerializeSwap(ctx, src1, src2, dst1, dst2, skippedSwap);
  50. ctx.Send();
  51. }
  52. }
  53. static void SendServerSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, bool skippedSwap = false)
  54. {
  55. if (GetGame().IsServer())
  56. {
  57. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] server sending cmd=SWAP src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  58. ScriptInputUserData ctx = new ScriptInputUserData;
  59. SerializeSwap(ctx, src1, src2, dst1, dst2, skippedSwap);
  60. GameInventory.ServerLocationSwap(src1, src2, dst1, dst2, ctx);
  61. }
  62. }
  63. ///@} swap
  64. ///@{ hand
  65. static void SerializeHandEvent(ParamsWriteContext ctx, HandEventBase e)
  66. {
  67. ctx.Write(INPUT_UDT_INVENTORY);
  68. ctx.Write(InventoryCommandType.HAND_EVENT);
  69. e.WriteToContext(ctx);
  70. }
  71. static void SendInputUserDataHandEvent(HandEventBase e)
  72. {
  73. if (GetGame().IsClient())
  74. {
  75. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms SendInputUserDataHandEvent e=" + e.DumpToString());
  76. ScriptInputUserData ctx = new ScriptInputUserData;
  77. SerializeHandEvent(ctx, e);
  78. ctx.Send();
  79. }
  80. }
  81. static void SendServerHandEventViaInventoryCommand(notnull Man player, HandEventBase e)
  82. {
  83. // Warning: this uses NetworkMessageInventoryCommand
  84. if (GetGame().IsServer())
  85. {
  86. if (e.IsServerSideOnly())
  87. Error("[syncinv] SendServerHandEvent - called on server side event only, e=" + e.DumpToString());
  88. if (player.IsAlive())
  89. Error("[syncinv] SendServerHandEvent - called on living thing.. server hand command is only for dead people, e=" + e.DumpToString());
  90. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] SendServerHandEventViaInventoryCommand SendInputUserDataHandEvent e=" + e.DumpToString());
  91. ScriptInputUserData ctx = new ScriptInputUserData;
  92. SerializeHandEvent(ctx, e);
  93. GameInventory.ServerHandEvent(player, e.GetSrcEntity(), ctx);
  94. }
  95. }
  96. ///@} hand
  97. static void SerializeDestroy(ParamsWriteContext ctx, notnull InventoryLocation src)
  98. {
  99. ctx.Write(INPUT_UDT_INVENTORY);
  100. ctx.Write(InventoryCommandType.DESTROY);
  101. src.WriteToContext(ctx);
  102. }
  103. static void SendInputUserDataDestroy(notnull InventoryLocation src)
  104. {
  105. if (GetGame().IsClient())
  106. {
  107. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] SendInputUserDataDestroy src=" + InventoryLocation.DumpToStringNullSafe(src));
  108. ScriptInputUserData ctx = new ScriptInputUserData;
  109. SerializeDestroy(ctx, src);
  110. ctx.Send();
  111. }
  112. }
  113. };