junctures.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. bool TryAcquireInventoryJunctureFromServer (notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst)
  2. {
  3. if (player.NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
  4. {
  5. if ( ( src.GetItem() && src.GetItem().IsSetForDeletion() ) || ( src.GetParent() && src.GetParent().IsSetForDeletion() ) || ( dst.GetParent() && dst.GetParent().IsSetForDeletion() ) )
  6. {
  7. return JunctureRequestResult.JUNCTURE_DENIED;
  8. }
  9. if (src.GetItem() && !src.GetItem().CanPutIntoHands(player))
  10. {
  11. return JunctureRequestResult.JUNCTURE_DENIED;
  12. }
  13. bool test_dst_occupancy = true;
  14. if (GetGame().AddInventoryJunctureEx(player, src.GetItem(), dst, test_dst_occupancy, GameInventory.c_InventoryReservationTimeoutMS))
  15. {
  16. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] juncture needed and acquired, player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  17. return JunctureRequestResult.JUNCTURE_ACQUIRED; // ok
  18. }
  19. else
  20. {
  21. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] juncture request DENIED, player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  22. return JunctureRequestResult.JUNCTURE_DENIED; // permission to perform juncture denied
  23. }
  24. }
  25. else
  26. {
  27. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] juncture not required, player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  28. return JunctureRequestResult.JUNCTURE_NOT_REQUIRED; // juncture not necessary
  29. }
  30. }
  31. bool TryAcquireTwoInventoryJuncturesFromServer (notnull Man player, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
  32. {
  33. #ifdef ENABLE_LOGGING
  34. if ( LogManager.IsInventoryReservationLogEnable() )
  35. {
  36. Debug.InventoryReservationLog("STS = " + player.GetSimulationTimeStamp() + " src1:" + src1.DumpToString() + " dst1: " + dst1.DumpToString()+ " src2:" + src2.DumpToString() + " dst2: " + dst2.DumpToString(), "InventoryJuncture" , "n/a", "TryAcquireTwoInventoryJuncturesFromServer",player.ToString() );
  37. }
  38. #endif
  39. //if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms TryAcquireTwoInventoryJuncturesFromServer src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  40. bool need_j1 = player.NeedInventoryJunctureFromServer(src1.GetItem(), src1.GetParent(), dst1.GetParent());
  41. bool need_j2 = player.NeedInventoryJunctureFromServer(src2.GetItem(), src2.GetParent(), dst2.GetParent());
  42. if (need_j1 || need_j2)
  43. {
  44. if (need_j1)
  45. {
  46. if ( ( src1.GetItem() && src1.GetItem().IsSetForDeletion() ) || ( src1.GetParent() && src1.GetParent().IsSetForDeletion() ) || ( dst1.GetParent() && dst1.GetParent().IsSetForDeletion() ) )
  47. {
  48. return JunctureRequestResult.JUNCTURE_DENIED;
  49. }
  50. if (src1.GetItem() && !src1.GetItem().CanPutIntoHands(player))
  51. {
  52. return JunctureRequestResult.JUNCTURE_DENIED;
  53. }
  54. if (!GetGame().AddInventoryJunctureEx(player, src1.GetItem(), dst1, false, GameInventory.c_InventoryReservationTimeoutMS))
  55. {
  56. /*#ifdef ENABLE_LOGGING
  57. if ( LogManager.IsInventoryReservationLogEnable() )
  58. {
  59. Debug.InventoryMoveLog("", "SWAP" , "n/a", "TryAcquireTwoInventoryJuncturesFromServer", player.ToString() );
  60. }
  61. #endif*/
  62. return JunctureRequestResult.JUNCTURE_DENIED; // permission to perform juncture denied
  63. }
  64. }
  65. //Need add log and change chanel to print
  66. if (need_j2)
  67. {
  68. if ( ( src2.GetItem() && src2.GetItem().IsSetForDeletion() ) || ( src2.GetParent() && src2.GetParent().IsSetForDeletion() ) || ( dst2.GetParent() && dst2.GetParent().IsSetForDeletion() ) )
  69. {
  70. if (need_j1)
  71. {
  72. GetGame().ClearJunctureEx(player, src1.GetItem()); // release already acquired juncture for item1
  73. }
  74. return JunctureRequestResult.JUNCTURE_DENIED;
  75. }
  76. if (src2.GetItem() && !src2.GetItem().CanPutIntoHands(player))
  77. {
  78. return JunctureRequestResult.JUNCTURE_DENIED;
  79. }
  80. if (!GetGame().AddInventoryJunctureEx(player, src2.GetItem(), dst2, false, GameInventory.c_InventoryReservationTimeoutMS))
  81. {
  82. //if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] item2 juncture request DENIED, player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  83. if (need_j1)
  84. {
  85. GetGame().ClearJunctureEx(player, src1.GetItem()); // release already acquired juncture for item1
  86. //if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] item2 juncture request DENIED, cleaning acquired juncture for item1, , player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  87. }
  88. return JunctureRequestResult.JUNCTURE_DENIED; // permission to perform juncture denied
  89. }
  90. }
  91. return JunctureRequestResult.JUNCTURE_ACQUIRED; // ok, both junctures acquired
  92. }
  93. else
  94. {
  95. #ifdef ENABLE_LOGGING
  96. if ( LogManager.IsInventoryReservationLogEnable() )
  97. {
  98. Debug.InventoryMoveLog("Remote - skipped", "SWAP" , "n/a", "ProcessInputData", player.ToString() );
  99. }
  100. #endif
  101. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] junctures not required, player=" + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  102. return JunctureRequestResult.JUNCTURE_NOT_REQUIRED; // juncture not necessary
  103. }
  104. }