@nice2dev/game-engine 1.3.14 → 1.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (434) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,1018 +1,943 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- /* ────────────────────────────────────────────────────────────────
6
- Inventory System
7
-
8
- A comprehensive inventory management system with:
9
- - Multiple container types (player, chest, shop, crafting)
10
- - Equipment slots with stat modifiers
11
- - Item stacking, splitting, and merging
12
- - Weight/capacity limits
13
- - Item categories and rarity
14
- - Crafting recipes
15
- - Trade/shop transactions
16
- - Loot tables and drop rates
17
- - Item durability and repair
18
- - Consumables with effects
19
- - State persistence
20
- ──────────────────────────────────────────────────────────────── */
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
21
4
  const DEFAULT_CONFIG = {
22
- defaultSlots: 40,
23
- enableWeight: true,
24
- enableDurability: true,
25
- autoStack: true,
26
- autoSort: false,
27
- maxContainersPerEntity: 5,
5
+ defaultSlots: 40,
6
+ enableWeight: true,
7
+ enableDurability: true,
8
+ autoStack: true,
9
+ autoSort: false,
10
+ maxContainersPerEntity: 5
28
11
  };
29
12
  class InventoryManager {
30
- constructor(config = {}) {
31
- this.eventBus = null;
32
- // Registries
33
- this.itemDefinitions = new Map();
34
- this.containers = new Map();
35
- this.equipment = new Map();
36
- this.recipes = new Map();
37
- this.lootTables = new Map();
38
- this.shops = new Map();
39
- this.learnedRecipes = new Map();
40
- this.cooldowns = new Map(); // instanceId -> lastUsed
41
- this.config = { ...DEFAULT_CONFIG, ...config };
42
- }
43
- /* ── Initialization ─────────────────────────────────────────── */
44
- setEventBus(bus) {
45
- this.eventBus = bus;
46
- }
47
- emit(event) {
48
- this.eventBus?.emit(`inventory:${event.type}`, event);
49
- }
50
- /* ── Item Definitions ───────────────────────────────────────── */
51
- registerItem(definition) {
52
- this.itemDefinitions.set(definition.id, definition);
53
- }
54
- registerItems(definitions) {
55
- definitions.forEach((def) => this.registerItem(def));
56
- }
57
- getItemDefinition(itemId) {
58
- return this.itemDefinitions.get(itemId);
59
- }
60
- getAllItemDefinitions() {
61
- return Array.from(this.itemDefinitions.values());
62
- }
63
- /* ── Container Management ───────────────────────────────────── */
64
- createContainer(type, ownerId, options = {}) {
65
- const id = options.id ?? `container_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
66
- const maxSlots = options.maxSlots ?? this.config.defaultSlots;
67
- const container = {
68
- id,
69
- type,
70
- name: options.name ?? `${type} container`,
71
- ownerId,
72
- maxSlots,
73
- maxWeight: options.maxWeight,
74
- slots: Array.from({ length: maxSlots }, (_, i) => ({ index: i, item: null })),
75
- currency: options.currency ?? new Map(),
76
- allowedCategories: options.allowedCategories,
77
- disallowedCategories: options.disallowedCategories,
78
- };
79
- this.containers.set(id, container);
80
- this.emit({ type: 'container:created', containerId: id, ownerId, timestamp: Date.now() });
81
- return container;
82
- }
83
- getContainer(containerId) {
84
- return this.containers.get(containerId);
85
- }
86
- getContainersByOwner(ownerId) {
87
- return Array.from(this.containers.values()).filter((c) => c.ownerId === ownerId);
88
- }
89
- destroyContainer(containerId) {
90
- const container = this.containers.get(containerId);
91
- if (!container) {
92
- return false;
93
- }
94
- this.containers.delete(containerId);
95
- this.emit({
96
- type: 'container:destroyed',
97
- containerId,
98
- ownerId: container.ownerId,
99
- timestamp: Date.now(),
100
- });
101
- return true;
102
- }
103
- /* ── Item Instance Creation ─────────────────────────────────── */
104
- createItemInstance(itemId, count = 1, options = {}) {
105
- const def = this.itemDefinitions.get(itemId);
106
- if (!def) {
107
- return null;
108
- }
109
- // Extract count from options to prevent override
110
- const { count: _ignoredCount, ...restOptions } = options;
111
- const instance = {
112
- instanceId: restOptions.instanceId ?? `item_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`,
113
- itemId,
114
- count: Math.min(count, def.maxStack),
115
- durability: def.maxDurability,
116
- createdAt: Date.now(),
117
- ...restOptions,
118
- };
119
- return instance;
120
- }
121
- /* ── Basic Operations ───────────────────────────────────────── */
122
- addItem(containerId, itemId, count = 1, options = {}) {
123
- const container = this.containers.get(containerId);
124
- if (!container) {
125
- return null;
126
- }
127
- const def = this.itemDefinitions.get(itemId);
128
- if (!def) {
129
- return null;
130
- }
131
- // Check category restrictions
132
- if (container.allowedCategories && !container.allowedCategories.includes(def.category)) {
133
- return null;
134
- }
135
- if (container.disallowedCategories?.includes(def.category)) {
136
- return null;
137
- }
138
- // Check weight
139
- if (this.config.enableWeight && container.maxWeight !== undefined) {
140
- const currentWeight = this.getContainerWeight(containerId);
141
- if (currentWeight + def.weight * count > container.maxWeight) {
142
- return null;
143
- }
144
- }
145
- // Try to stack with existing items first
146
- if (this.config.autoStack && def.maxStack > 1) {
147
- for (const slot of container.slots) {
148
- if (slot.item && slot.item.itemId === itemId && slot.item.count < def.maxStack) {
149
- const space = def.maxStack - slot.item.count;
150
- const toAdd = Math.min(count, space);
151
- slot.item.count += toAdd;
152
- count -= toAdd;
153
- this.emit({
154
- type: 'item:stacked',
155
- containerId,
156
- ownerId: container.ownerId,
157
- item: slot.item,
158
- slot: slot.index,
159
- count: toAdd,
160
- timestamp: Date.now(),
161
- });
162
- if (count <= 0) {
163
- return slot.item;
164
- }
165
- }
166
- }
167
- }
168
- // Find empty slot for remaining
169
- while (count > 0) {
170
- const emptySlot = container.slots.find((s) => !s.item && !s.locked);
171
- if (!emptySlot) {
172
- return null;
173
- } // No space
174
- const stackCount = Math.min(count, def.maxStack);
175
- const instance = this.createItemInstance(itemId, stackCount, options);
176
- if (!instance) {
177
- return null;
178
- }
179
- emptySlot.item = instance;
180
- count -= stackCount;
181
- this.emit({
182
- type: 'item:added',
183
- containerId,
184
- ownerId: container.ownerId,
185
- item: instance,
186
- slot: emptySlot.index,
187
- count: stackCount,
188
- timestamp: Date.now(),
189
- });
190
- }
191
- return container.slots.find((s) => s.item?.itemId === itemId)?.item ?? null;
192
- }
193
- removeItem(containerId, slotIndex, count = 1) {
194
- const container = this.containers.get(containerId);
195
- if (!container) {
196
- return null;
197
- }
198
- const slot = container.slots[slotIndex];
199
- if (!slot?.item) {
200
- return null;
201
- }
202
- const removed = { ...slot.item };
203
- if (slot.item.count <= count) {
204
- slot.item = null;
205
- // removed already has the correct count from the spread above
206
- }
207
- else {
208
- slot.item.count -= count;
209
- removed.count = count;
210
- }
211
- this.emit({
212
- type: 'item:removed',
213
- containerId,
214
- ownerId: container.ownerId,
215
- item: removed,
216
- slot: slotIndex,
217
- count: removed.count,
218
- timestamp: Date.now(),
219
- });
220
- return removed;
221
- }
222
- moveItem(fromContainerId, fromSlot, toContainerId, toSlot) {
223
- const fromContainer = this.containers.get(fromContainerId);
224
- const toContainer = this.containers.get(toContainerId);
225
- if (!fromContainer || !toContainer) {
226
- return false;
227
- }
228
- const sourceSlot = fromContainer.slots[fromSlot];
229
- const targetSlot = toContainer.slots[toSlot];
230
- if (!sourceSlot?.item || !targetSlot) {
231
- return false;
232
- }
233
- const def = this.itemDefinitions.get(sourceSlot.item.itemId);
234
- if (!def) {
235
- return false;
236
- }
237
- // Check target container restrictions
238
- if (toContainer.allowedCategories && !toContainer.allowedCategories.includes(def.category)) {
239
- return false;
240
- }
241
- // Swap or stack
242
- if (targetSlot.item) {
243
- if (targetSlot.item.itemId === sourceSlot.item.itemId &&
244
- targetSlot.item.count < def.maxStack) {
245
- // Stack
246
- const space = def.maxStack - targetSlot.item.count;
247
- const toMove = Math.min(sourceSlot.item.count, space);
248
- targetSlot.item.count += toMove;
249
- sourceSlot.item.count -= toMove;
250
- if (sourceSlot.item.count <= 0) {
251
- sourceSlot.item = null;
252
- }
253
- }
254
- else {
255
- // Swap
256
- const temp = sourceSlot.item;
257
- sourceSlot.item = targetSlot.item;
258
- targetSlot.item = temp;
259
- }
260
- }
261
- else {
262
- // Move to empty slot
263
- targetSlot.item = sourceSlot.item;
264
- sourceSlot.item = null;
265
- }
266
- this.emit({
267
- type: 'item:moved',
268
- containerId: fromContainerId,
269
- ownerId: fromContainer.ownerId,
270
- fromSlot,
271
- toSlot,
272
- timestamp: Date.now(),
273
- });
274
- return true;
275
- }
276
- splitStack(containerId, slotIndex, splitCount) {
277
- const container = this.containers.get(containerId);
278
- if (!container) {
279
- return false;
280
- }
281
- const slot = container.slots[slotIndex];
282
- if (!slot?.item || slot.item.count <= splitCount) {
283
- return false;
284
- }
285
- const emptySlot = container.slots.find((s) => !s.item && !s.locked);
286
- if (!emptySlot) {
287
- return false;
288
- }
289
- const newInstance = this.createItemInstance(slot.item.itemId, splitCount, {
290
- ...slot.item,
291
- instanceId: undefined,
292
- });
293
- if (!newInstance) {
294
- return false;
295
- }
296
- slot.item.count -= splitCount;
297
- emptySlot.item = newInstance;
298
- this.emit({
299
- type: 'item:split',
300
- containerId,
301
- ownerId: container.ownerId,
302
- item: newInstance,
303
- fromSlot: slotIndex,
304
- toSlot: emptySlot.index,
305
- count: splitCount,
306
- timestamp: Date.now(),
307
- });
308
- return true;
309
- }
310
- /* ── Weight & Capacity ──────────────────────────────────────── */
311
- getContainerWeight(containerId) {
312
- const container = this.containers.get(containerId);
313
- if (!container) {
314
- return 0;
315
- }
316
- let weight = 0;
317
- for (const slot of container.slots) {
318
- if (slot.item) {
319
- const def = this.itemDefinitions.get(slot.item.itemId);
320
- if (def) {
321
- weight += def.weight * slot.item.count;
322
- }
323
- }
324
- }
325
- return weight;
326
- }
327
- getContainerFreeSlots(containerId) {
328
- const container = this.containers.get(containerId);
329
- if (!container) {
330
- return 0;
331
- }
332
- return container.slots.filter((s) => !s.item && !s.locked).length;
333
- }
334
- /* ── Equipment System ───────────────────────────────────────── */
335
- initializeEquipment(ownerId) {
336
- const state = {
337
- ownerId,
338
- slots: new Map(),
339
- totalStats: new Map(),
340
- };
341
- // Initialize all slots as empty
342
- const allSlots = [
343
- 'head',
344
- 'chest',
345
- 'legs',
346
- 'feet',
347
- 'hands',
348
- 'shoulders',
349
- 'back',
350
- 'waist',
351
- 'mainHand',
352
- 'offHand',
353
- 'ring1',
354
- 'ring2',
355
- 'neck',
356
- 'trinket1',
357
- 'trinket2',
358
- ];
359
- allSlots.forEach((slot) => state.slots.set(slot, null));
360
- this.equipment.set(ownerId, state);
361
- return state;
362
- }
363
- getEquipment(ownerId) {
364
- return this.equipment.get(ownerId);
365
- }
366
- equipItem(ownerId, containerId, slotIndex) {
367
- let equipState = this.equipment.get(ownerId);
368
- if (!equipState) {
369
- equipState = this.initializeEquipment(ownerId);
370
- }
371
- const container = this.containers.get(containerId);
372
- if (!container) {
373
- return false;
374
- }
375
- const invSlot = container.slots[slotIndex];
376
- if (!invSlot?.item) {
377
- return false;
378
- }
379
- const def = this.itemDefinitions.get(invSlot.item.itemId);
380
- if (!def?.equipSlot) {
381
- return false;
382
- }
383
- // Check requirements
384
- // (In real implementation, would check level, class, stats)
385
- // Handle two-hand weapons
386
- let targetSlot = def.equipSlot;
387
- if (targetSlot === 'twoHand') {
388
- // Unequip both hands
389
- const mainHand = equipState.slots.get('mainHand');
390
- const offHand = equipState.slots.get('offHand');
391
- if (mainHand) {
392
- this.unequipToContainer(ownerId, 'mainHand', containerId);
393
- }
394
- if (offHand) {
395
- this.unequipToContainer(ownerId, 'offHand', containerId);
396
- }
397
- targetSlot = 'mainHand';
398
- }
399
- // Clone the item to equip BEFORE modifying the slot
400
- const itemToEquip = { ...invSlot.item };
401
- // Swap with existing equipped item
402
- const currentEquipped = equipState.slots.get(targetSlot);
403
- if (currentEquipped) {
404
- // Put currently equipped item back in inventory
405
- invSlot.item = currentEquipped;
406
- }
407
- else {
408
- invSlot.item = null;
409
- }
410
- equipState.slots.set(targetSlot, itemToEquip);
411
- // Apply binding
412
- if (def.binding === 'onEquip' && !itemToEquip.boundTo) {
413
- itemToEquip.boundTo = String(ownerId);
414
- }
415
- // Recalculate stats
416
- this.recalculateEquipmentStats(ownerId);
417
- this.emit({
418
- type: 'item:equipped',
419
- ownerId,
420
- item: itemToEquip,
421
- slot: slotIndex,
422
- timestamp: Date.now(),
423
- });
424
- return true;
425
- }
426
- unequipItem(ownerId, equipSlot, containerId) {
427
- return this.unequipToContainer(ownerId, equipSlot, containerId);
428
- }
429
- unequipToContainer(ownerId, equipSlot, containerId) {
430
- const equipState = this.equipment.get(ownerId);
431
- if (!equipState) {
432
- return false;
433
- }
434
- const equippedItem = equipState.slots.get(equipSlot);
435
- if (!equippedItem) {
436
- return false;
437
- }
438
- const container = this.containers.get(containerId);
439
- if (!container) {
440
- return false;
441
- }
442
- // Find empty slot in container
443
- const emptySlot = container.slots.find((s) => !s.item && !s.locked);
444
- if (!emptySlot) {
445
- return false;
446
- } // Inventory full
447
- emptySlot.item = equippedItem;
448
- equipState.slots.set(equipSlot, null);
449
- this.recalculateEquipmentStats(ownerId);
450
- this.emit({
451
- type: 'item:unequipped',
452
- ownerId,
453
- item: equippedItem,
454
- slot: emptySlot.index,
455
- timestamp: Date.now(),
456
- });
457
- return true;
458
- }
459
- recalculateEquipmentStats(ownerId) {
460
- const equipState = this.equipment.get(ownerId);
461
- if (!equipState) {
462
- return;
463
- }
464
- equipState.totalStats.clear();
465
- for (const [, item] of equipState.slots) {
466
- if (!item) {
467
- continue;
468
- }
469
- const def = this.itemDefinitions.get(item.itemId);
470
- if (!def?.stats) {
471
- continue;
472
- }
473
- for (const mod of def.stats) {
474
- const current = equipState.totalStats.get(mod.stat) ?? 0;
475
- equipState.totalStats.set(mod.stat, current + (mod.flat ?? 0));
476
- // Percent modifiers would need separate handling
477
- }
478
- }
479
- }
480
- /* ── Durability & Repair ────────────────────────────────────── */
481
- damageDurability(instance, damage) {
482
- if (!this.config.enableDurability) {
483
- return false;
484
- }
485
- if (instance.durability === undefined) {
486
- return false;
487
- }
488
- instance.durability = Math.max(0, instance.durability - damage);
489
- if (instance.durability <= 0) {
490
- this.emit({
491
- type: 'item:destroyed',
492
- item: instance,
493
- timestamp: Date.now(),
494
- });
495
- return true; // Item broken
496
- }
497
- return false;
498
- }
499
- repairItem(instance, amount) {
500
- const def = this.itemDefinitions.get(instance.itemId);
501
- if (!def?.maxDurability || instance.durability === undefined) {
502
- return false;
503
- }
504
- instance.durability = Math.min(def.maxDurability, amount !== undefined ? instance.durability + amount : def.maxDurability);
505
- this.emit({
506
- type: 'item:repaired',
507
- item: instance,
508
- timestamp: Date.now(),
509
- });
510
- return true;
511
- }
512
- /* ── Consumables ────────────────────────────────────────────── */
513
- useItem(containerId, slotIndex, targetEntityId) {
514
- const container = this.containers.get(containerId);
515
- if (!container) {
516
- return false;
517
- }
518
- const slot = container.slots[slotIndex];
519
- if (!slot?.item) {
520
- return false;
521
- }
522
- const def = this.itemDefinitions.get(slot.item.itemId);
523
- if (!def) {
524
- return false;
525
- }
526
- // Check cooldown
527
- if (def.cooldown) {
528
- const lastUsed = this.cooldowns.get(slot.item.instanceId) ?? 0;
529
- if (Date.now() - lastUsed < def.cooldown) {
530
- return false; // On cooldown
531
- }
532
- }
533
- // Set cooldown
534
- if (def.cooldown) {
535
- this.cooldowns.set(slot.item.instanceId, Date.now());
536
- }
537
- this.emit({
538
- type: 'item:used',
13
+ // instanceId -> lastUsed
14
+ constructor(config = {}) {
15
+ this.eventBus = null;
16
+ this.itemDefinitions = /* @__PURE__ */ new Map();
17
+ this.containers = /* @__PURE__ */ new Map();
18
+ this.equipment = /* @__PURE__ */ new Map();
19
+ this.recipes = /* @__PURE__ */ new Map();
20
+ this.lootTables = /* @__PURE__ */ new Map();
21
+ this.shops = /* @__PURE__ */ new Map();
22
+ this.learnedRecipes = /* @__PURE__ */ new Map();
23
+ this.cooldowns = /* @__PURE__ */ new Map();
24
+ this.config = { ...DEFAULT_CONFIG, ...config };
25
+ }
26
+ /* ── Initialization ─────────────────────────────────────────── */
27
+ setEventBus(bus) {
28
+ this.eventBus = bus;
29
+ }
30
+ emit(event) {
31
+ this.eventBus?.emit(`inventory:${event.type}`, event);
32
+ }
33
+ /* ── Item Definitions ───────────────────────────────────────── */
34
+ registerItem(definition) {
35
+ this.itemDefinitions.set(definition.id, definition);
36
+ }
37
+ registerItems(definitions) {
38
+ definitions.forEach((def) => this.registerItem(def));
39
+ }
40
+ getItemDefinition(itemId) {
41
+ return this.itemDefinitions.get(itemId);
42
+ }
43
+ getAllItemDefinitions() {
44
+ return Array.from(this.itemDefinitions.values());
45
+ }
46
+ /* ── Container Management ───────────────────────────────────── */
47
+ createContainer(type, ownerId, options = {}) {
48
+ const id = options.id ?? `container_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
49
+ const maxSlots = options.maxSlots ?? this.config.defaultSlots;
50
+ const container = {
51
+ id,
52
+ type,
53
+ name: options.name ?? `${type} container`,
54
+ ownerId,
55
+ maxSlots,
56
+ maxWeight: options.maxWeight,
57
+ slots: Array.from({ length: maxSlots }, (_, i) => ({ index: i, item: null })),
58
+ currency: options.currency ?? /* @__PURE__ */ new Map(),
59
+ allowedCategories: options.allowedCategories,
60
+ disallowedCategories: options.disallowedCategories
61
+ };
62
+ this.containers.set(id, container);
63
+ this.emit({ type: "container:created", containerId: id, ownerId, timestamp: Date.now() });
64
+ return container;
65
+ }
66
+ getContainer(containerId) {
67
+ return this.containers.get(containerId);
68
+ }
69
+ getContainersByOwner(ownerId) {
70
+ return Array.from(this.containers.values()).filter((c) => c.ownerId === ownerId);
71
+ }
72
+ destroyContainer(containerId) {
73
+ const container = this.containers.get(containerId);
74
+ if (!container) {
75
+ return false;
76
+ }
77
+ this.containers.delete(containerId);
78
+ this.emit({
79
+ type: "container:destroyed",
80
+ containerId,
81
+ ownerId: container.ownerId,
82
+ timestamp: Date.now()
83
+ });
84
+ return true;
85
+ }
86
+ /* ── Item Instance Creation ─────────────────────────────────── */
87
+ createItemInstance(itemId, count = 1, options = {}) {
88
+ const def = this.itemDefinitions.get(itemId);
89
+ if (!def) {
90
+ return null;
91
+ }
92
+ const { count: _ignoredCount, ...restOptions } = options;
93
+ const instance = {
94
+ instanceId: restOptions.instanceId ?? `item_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`,
95
+ itemId,
96
+ count: Math.min(count, def.maxStack),
97
+ durability: def.maxDurability,
98
+ createdAt: Date.now(),
99
+ ...restOptions
100
+ };
101
+ return instance;
102
+ }
103
+ /* ── Basic Operations ───────────────────────────────────────── */
104
+ addItem(containerId, itemId, count = 1, options = {}) {
105
+ const container = this.containers.get(containerId);
106
+ if (!container) {
107
+ return null;
108
+ }
109
+ const def = this.itemDefinitions.get(itemId);
110
+ if (!def) {
111
+ return null;
112
+ }
113
+ if (container.allowedCategories && !container.allowedCategories.includes(def.category)) {
114
+ return null;
115
+ }
116
+ if (container.disallowedCategories?.includes(def.category)) {
117
+ return null;
118
+ }
119
+ if (this.config.enableWeight && container.maxWeight !== void 0) {
120
+ const currentWeight = this.getContainerWeight(containerId);
121
+ if (currentWeight + def.weight * count > container.maxWeight) {
122
+ return null;
123
+ }
124
+ }
125
+ if (this.config.autoStack && def.maxStack > 1) {
126
+ for (const slot of container.slots) {
127
+ if (slot.item && slot.item.itemId === itemId && slot.item.count < def.maxStack) {
128
+ const space = def.maxStack - slot.item.count;
129
+ const toAdd = Math.min(count, space);
130
+ slot.item.count += toAdd;
131
+ count -= toAdd;
132
+ this.emit({
133
+ type: "item:stacked",
539
134
  containerId,
540
135
  ownerId: container.ownerId,
541
136
  item: slot.item,
542
- slot: slotIndex,
543
- customData: { targetEntityId, effectId: def.effectId },
544
- timestamp: Date.now(),
545
- });
546
- // Consume if applicable
547
- if (def.consumeOnUse) {
548
- slot.item.count--;
549
- if (slot.item.count <= 0) {
550
- slot.item = null;
551
- }
552
- }
553
- return true;
554
- }
555
- /* ── Crafting System ────────────────────────────────────────── */
556
- registerRecipe(recipe) {
557
- this.recipes.set(recipe.id, recipe);
558
- }
559
- learnRecipe(entityId, recipeId) {
560
- const recipe = this.recipes.get(recipeId);
561
- if (!recipe || !recipe.requiresLearning) {
562
- return false;
563
- }
564
- let learned = this.learnedRecipes.get(entityId);
565
- if (!learned) {
566
- learned = new Set();
567
- this.learnedRecipes.set(entityId, learned);
568
- }
569
- learned.add(recipeId);
570
- return true;
571
- }
572
- canCraft(entityId, recipeId, containerId) {
573
- const recipe = this.recipes.get(recipeId);
574
- if (!recipe) {
575
- return false;
576
- }
577
- // Check if recipe is learned
578
- if (recipe.requiresLearning) {
579
- const learned = this.learnedRecipes.get(entityId);
580
- if (!learned?.has(recipeId)) {
581
- return false;
582
- }
583
- }
584
- // Check ingredients
585
- const container = this.containers.get(containerId);
586
- if (!container) {
587
- return false;
588
- }
589
- for (const ingredient of recipe.ingredients) {
590
- const available = this.countItemsInContainer(containerId, ingredient.itemId);
591
- if (available < ingredient.count) {
592
- return false;
593
- }
594
- }
595
- return true;
596
- }
597
- craft(entityId, recipeId, containerId) {
598
- if (!this.canCraft(entityId, recipeId, containerId)) {
599
- return null;
600
- }
601
- const recipe = this.recipes.get(recipeId);
602
- this.containers.get(containerId);
603
- // Check success
604
- if (Math.random() > recipe.successRate) {
605
- // Failed - consume ingredients anyway if consumed flag set
606
- for (const ingredient of recipe.ingredients) {
607
- if (ingredient.consumed) {
608
- this.removeItemsByIdFromContainer(containerId, ingredient.itemId, ingredient.count);
609
- }
610
- }
611
- this.emit({
612
- type: 'craft:failed',
613
- ownerId: entityId,
614
- recipeId,
615
- containerId,
616
- timestamp: Date.now(),
617
- });
618
- return null;
619
- }
620
- // Consume ingredients
621
- for (const ingredient of recipe.ingredients) {
622
- if (ingredient.consumed) {
623
- this.removeItemsByIdFromContainer(containerId, ingredient.itemId, ingredient.count);
624
- }
625
- }
626
- // Create output
627
- const output = this.addItem(containerId, recipe.outputItemId, recipe.outputCount);
628
- this.emit({
629
- type: 'craft:completed',
630
- ownerId: entityId,
631
- recipeId,
632
- containerId,
633
- item: output ?? undefined,
634
- timestamp: Date.now(),
635
- });
636
- return output;
637
- }
638
- /* ── Loot Tables ────────────────────────────────────────────── */
639
- registerLootTable(table) {
640
- this.lootTables.set(table.id, table);
641
- }
642
- generateLoot(tableId, modifiers = {}) {
643
- const table = this.lootTables.get(tableId);
644
- if (!table) {
645
- return [];
646
- }
647
- const loot = [];
648
- // Guaranteed drops
649
- if (table.guaranteedDrops) {
650
- for (const drop of table.guaranteedDrops) {
651
- const instance = this.createItemInstance(drop.itemId, drop.count);
652
- if (instance) {
653
- loot.push(instance);
654
- }
655
- }
656
- }
657
- // Roll on table
658
- const validEntries = table.entries.filter((e) => {
659
- if (e.conditions?.minLevel &&
660
- modifiers.levelContext &&
661
- modifiers.levelContext < e.conditions.minLevel) {
662
- return false;
663
- }
664
- if (e.conditions?.maxLevel &&
665
- modifiers.levelContext &&
666
- modifiers.levelContext > e.conditions.maxLevel) {
667
- return false;
668
- }
669
- return true;
670
- });
671
- const totalWeight = validEntries.reduce((sum, e) => sum + e.weight, 0);
672
- for (let roll = 0; roll < table.rolls; roll++) {
673
- let random = Math.random() * totalWeight;
674
- for (const entry of validEntries) {
675
- random -= entry.weight;
676
- if (random <= 0) {
677
- // Apply drop chance with luck modifier
678
- const effectiveChance = Math.min(1, entry.dropChance + (modifiers.luckBonus ?? 0));
679
- if (Math.random() <= effectiveChance) {
680
- const count = Math.floor(entry.minCount + Math.random() * (entry.maxCount - entry.minCount + 1));
681
- const instance = this.createItemInstance(entry.itemId, count);
682
- if (instance) {
683
- loot.push(instance);
684
- }
685
- }
686
- break;
687
- }
688
- }
689
- }
690
- this.emit({
691
- type: 'loot:generated',
692
- customData: { tableId, loot },
693
- timestamp: Date.now(),
694
- });
695
- return loot;
696
- }
697
- /* ── Shop System ────────────────────────────────────────────── */
698
- registerShop(shop) {
699
- this.shops.set(shop.id, shop);
700
- }
701
- getShop(shopId) {
702
- return this.shops.get(shopId);
703
- }
704
- buyFromShop(shopId, listingIndex, quantity, buyerContainerId) {
705
- const shop = this.shops.get(shopId);
706
- const container = this.containers.get(buyerContainerId);
707
- if (!shop || !container) {
708
- return false;
709
- }
710
- const listing = shop.listings[listingIndex];
711
- if (!listing) {
712
- return false;
713
- }
714
- // Check stock
715
- if (listing.stock !== -1 && listing.stock < quantity) {
716
- return false;
717
- }
718
- // Calculate price
719
- const def = this.itemDefinitions.get(listing.itemId);
720
- if (!def) {
721
- return false;
722
- }
723
- const unitPrice = listing.price ?? Math.ceil(def.value * shop.sellRate);
724
- const totalPrice = unitPrice * quantity;
725
- // Check buyer currency
726
- const buyerCurrency = container.currency?.get(listing.currencyId) ?? 0;
727
- if (buyerCurrency < totalPrice) {
728
- return false;
729
- }
730
- // Execute transaction
731
- container.currency.set(listing.currencyId, buyerCurrency - totalPrice);
732
- const purchased = this.addItem(buyerContainerId, listing.itemId, quantity);
733
- if (!purchased) {
734
- // Refund if couldn't add item
735
- container.currency.set(listing.currencyId, buyerCurrency);
736
- return false;
737
- }
738
- // Update stock
739
- if (listing.stock !== -1) {
740
- listing.stock -= quantity;
741
- }
742
- this.emit({
743
- type: 'shop:bought',
744
- shopId,
745
- containerId: buyerContainerId,
746
- ownerId: container.ownerId,
747
- itemId: listing.itemId,
748
- count: quantity,
749
- currencyId: listing.currencyId,
750
- amount: totalPrice,
751
- timestamp: Date.now(),
752
- });
753
- return true;
754
- }
755
- sellToShop(shopId, sellerContainerId, slotIndex, quantity) {
756
- const shop = this.shops.get(shopId);
757
- const container = this.containers.get(sellerContainerId);
758
- if (!shop || !container) {
759
- return false;
760
- }
761
- const slot = container.slots[slotIndex];
762
- if (!slot?.item || slot.item.count < quantity) {
763
- return false;
764
- }
137
+ slot: slot.index,
138
+ count: toAdd,
139
+ timestamp: Date.now()
140
+ });
141
+ if (count <= 0) {
142
+ return slot.item;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ while (count > 0) {
148
+ const emptySlot = container.slots.find((s) => !s.item && !s.locked);
149
+ if (!emptySlot) {
150
+ return null;
151
+ }
152
+ const stackCount = Math.min(count, def.maxStack);
153
+ const instance = this.createItemInstance(itemId, stackCount, options);
154
+ if (!instance) {
155
+ return null;
156
+ }
157
+ emptySlot.item = instance;
158
+ count -= stackCount;
159
+ this.emit({
160
+ type: "item:added",
161
+ containerId,
162
+ ownerId: container.ownerId,
163
+ item: instance,
164
+ slot: emptySlot.index,
165
+ count: stackCount,
166
+ timestamp: Date.now()
167
+ });
168
+ }
169
+ return container.slots.find((s) => s.item?.itemId === itemId)?.item ?? null;
170
+ }
171
+ removeItem(containerId, slotIndex, count = 1) {
172
+ const container = this.containers.get(containerId);
173
+ if (!container) {
174
+ return null;
175
+ }
176
+ const slot = container.slots[slotIndex];
177
+ if (!slot?.item) {
178
+ return null;
179
+ }
180
+ const removed = { ...slot.item };
181
+ if (slot.item.count <= count) {
182
+ slot.item = null;
183
+ } else {
184
+ slot.item.count -= count;
185
+ removed.count = count;
186
+ }
187
+ this.emit({
188
+ type: "item:removed",
189
+ containerId,
190
+ ownerId: container.ownerId,
191
+ item: removed,
192
+ slot: slotIndex,
193
+ count: removed.count,
194
+ timestamp: Date.now()
195
+ });
196
+ return removed;
197
+ }
198
+ moveItem(fromContainerId, fromSlot, toContainerId, toSlot) {
199
+ const fromContainer = this.containers.get(fromContainerId);
200
+ const toContainer = this.containers.get(toContainerId);
201
+ if (!fromContainer || !toContainer) {
202
+ return false;
203
+ }
204
+ const sourceSlot = fromContainer.slots[fromSlot];
205
+ const targetSlot = toContainer.slots[toSlot];
206
+ if (!sourceSlot?.item || !targetSlot) {
207
+ return false;
208
+ }
209
+ const def = this.itemDefinitions.get(sourceSlot.item.itemId);
210
+ if (!def) {
211
+ return false;
212
+ }
213
+ if (toContainer.allowedCategories && !toContainer.allowedCategories.includes(def.category)) {
214
+ return false;
215
+ }
216
+ if (targetSlot.item) {
217
+ if (targetSlot.item.itemId === sourceSlot.item.itemId && targetSlot.item.count < def.maxStack) {
218
+ const space = def.maxStack - targetSlot.item.count;
219
+ const toMove = Math.min(sourceSlot.item.count, space);
220
+ targetSlot.item.count += toMove;
221
+ sourceSlot.item.count -= toMove;
222
+ if (sourceSlot.item.count <= 0) {
223
+ sourceSlot.item = null;
224
+ }
225
+ } else {
226
+ const temp = sourceSlot.item;
227
+ sourceSlot.item = targetSlot.item;
228
+ targetSlot.item = temp;
229
+ }
230
+ } else {
231
+ targetSlot.item = sourceSlot.item;
232
+ sourceSlot.item = null;
233
+ }
234
+ this.emit({
235
+ type: "item:moved",
236
+ containerId: fromContainerId,
237
+ ownerId: fromContainer.ownerId,
238
+ fromSlot,
239
+ toSlot,
240
+ timestamp: Date.now()
241
+ });
242
+ return true;
243
+ }
244
+ splitStack(containerId, slotIndex, splitCount) {
245
+ const container = this.containers.get(containerId);
246
+ if (!container) {
247
+ return false;
248
+ }
249
+ const slot = container.slots[slotIndex];
250
+ if (!slot?.item || slot.item.count <= splitCount) {
251
+ return false;
252
+ }
253
+ const emptySlot = container.slots.find((s) => !s.item && !s.locked);
254
+ if (!emptySlot) {
255
+ return false;
256
+ }
257
+ const newInstance = this.createItemInstance(slot.item.itemId, splitCount, {
258
+ ...slot.item,
259
+ instanceId: void 0
260
+ });
261
+ if (!newInstance) {
262
+ return false;
263
+ }
264
+ slot.item.count -= splitCount;
265
+ emptySlot.item = newInstance;
266
+ this.emit({
267
+ type: "item:split",
268
+ containerId,
269
+ ownerId: container.ownerId,
270
+ item: newInstance,
271
+ fromSlot: slotIndex,
272
+ toSlot: emptySlot.index,
273
+ count: splitCount,
274
+ timestamp: Date.now()
275
+ });
276
+ return true;
277
+ }
278
+ /* ── Weight & Capacity ──────────────────────────────────────── */
279
+ getContainerWeight(containerId) {
280
+ const container = this.containers.get(containerId);
281
+ if (!container) {
282
+ return 0;
283
+ }
284
+ let weight = 0;
285
+ for (const slot of container.slots) {
286
+ if (slot.item) {
765
287
  const def = this.itemDefinitions.get(slot.item.itemId);
766
- if (!def || !def.sellable) {
767
- return false;
768
- }
769
- // Calculate sell price
770
- const unitPrice = Math.floor(def.value * shop.buyRate);
771
- const totalPrice = unitPrice * quantity;
772
- // Use first accepted currency
773
- const currencyId = shop.acceptedCurrencies[0];
774
- if (!currencyId) {
775
- return false;
776
- }
777
- // Remove items
778
- this.removeItem(sellerContainerId, slotIndex, quantity);
779
- // Add currency
780
- const currentCurrency = container.currency?.get(currencyId) ?? 0;
781
- container.currency.set(currencyId, currentCurrency + totalPrice);
782
- this.emit({
783
- type: 'shop:sold',
784
- shopId,
785
- containerId: sellerContainerId,
786
- ownerId: container.ownerId,
787
- itemId: def.id,
788
- count: quantity,
789
- currencyId,
790
- amount: totalPrice,
791
- timestamp: Date.now(),
792
- });
793
- return true;
794
- }
795
- /* ── Currency ───────────────────────────────────────────────── */
796
- addCurrency(containerId, currencyId, amount) {
797
- const container = this.containers.get(containerId);
798
- if (!container) {
799
- return false;
800
- }
801
- if (!container.currency) {
802
- container.currency = new Map();
803
- }
804
- const current = container.currency.get(currencyId) ?? 0;
805
- container.currency.set(currencyId, current + amount);
806
- this.emit({
807
- type: 'currency:changed',
808
- containerId,
809
- ownerId: container.ownerId,
810
- currencyId,
811
- amount,
812
- timestamp: Date.now(),
813
- });
814
- return true;
815
- }
816
- removeCurrency(containerId, currencyId, amount) {
817
- const container = this.containers.get(containerId);
818
- if (!container?.currency) {
819
- return false;
820
- }
821
- const current = container.currency.get(currencyId) ?? 0;
822
- if (current < amount) {
823
- return false;
824
- }
825
- container.currency.set(currencyId, current - amount);
826
- this.emit({
827
- type: 'currency:changed',
828
- containerId,
829
- ownerId: container.ownerId,
830
- currencyId,
831
- amount: -amount,
832
- timestamp: Date.now(),
833
- });
834
- return true;
835
- }
836
- getCurrency(containerId, currencyId) {
837
- return this.containers.get(containerId)?.currency?.get(currencyId) ?? 0;
838
- }
839
- /* ── Sorting ────────────────────────────────────────────────── */
840
- sortContainer(containerId, criteria = 'category') {
841
- const container = this.containers.get(containerId);
842
- if (!container) {
843
- return;
844
- }
845
- const items = container.slots
846
- .filter((s) => s.item && !s.locked)
847
- .map((s) => s.item)
848
- .sort((a, b) => {
849
- const defA = this.itemDefinitions.get(a.itemId);
850
- const defB = this.itemDefinitions.get(b.itemId);
851
- if (!defA || !defB) {
852
- return 0;
853
- }
854
- switch (criteria) {
855
- case 'category':
856
- return defA.category.localeCompare(defB.category) || defA.name.localeCompare(defB.name);
857
- case 'rarity': {
858
- const rarityOrder = [
859
- 'common',
860
- 'uncommon',
861
- 'rare',
862
- 'epic',
863
- 'legendary',
864
- 'mythic',
865
- 'unique',
866
- ];
867
- return rarityOrder.indexOf(defB.rarity) - rarityOrder.indexOf(defA.rarity);
868
- }
869
- case 'name':
870
- return defA.name.localeCompare(defB.name);
871
- case 'value':
872
- return defB.value - defA.value;
873
- default:
874
- return 0;
875
- }
876
- });
877
- // Clear unlocked slots
878
- container.slots.forEach((s) => {
879
- if (!s.locked) {
880
- s.item = null;
881
- }
882
- });
883
- // Fill with sorted items
884
- let itemIndex = 0;
885
- for (const slot of container.slots) {
886
- if (!slot.locked && itemIndex < items.length) {
887
- slot.item = items[itemIndex++];
888
- }
889
- }
890
- container.sorted = true;
891
- this.emit({
892
- type: 'container:sorted',
893
- containerId,
894
- ownerId: container.ownerId,
895
- timestamp: Date.now(),
896
- });
897
- }
898
- /* ── Utility Methods ────────────────────────────────────────── */
899
- countItemsInContainer(containerId, itemId) {
900
- const container = this.containers.get(containerId);
901
- if (!container) {
902
- return 0;
903
- }
904
- return container.slots.reduce((sum, slot) => {
905
- if (slot.item?.itemId === itemId) {
906
- return sum + slot.item.count;
907
- }
908
- return sum;
909
- }, 0);
288
+ if (def) {
289
+ weight += def.weight * slot.item.count;
290
+ }
291
+ }
292
+ }
293
+ return weight;
294
+ }
295
+ getContainerFreeSlots(containerId) {
296
+ const container = this.containers.get(containerId);
297
+ if (!container) {
298
+ return 0;
299
+ }
300
+ return container.slots.filter((s) => !s.item && !s.locked).length;
301
+ }
302
+ /* ── Equipment System ───────────────────────────────────────── */
303
+ initializeEquipment(ownerId) {
304
+ const state = {
305
+ ownerId,
306
+ slots: /* @__PURE__ */ new Map(),
307
+ totalStats: /* @__PURE__ */ new Map()
308
+ };
309
+ const allSlots = [
310
+ "head",
311
+ "chest",
312
+ "legs",
313
+ "feet",
314
+ "hands",
315
+ "shoulders",
316
+ "back",
317
+ "waist",
318
+ "mainHand",
319
+ "offHand",
320
+ "ring1",
321
+ "ring2",
322
+ "neck",
323
+ "trinket1",
324
+ "trinket2"
325
+ ];
326
+ allSlots.forEach((slot) => state.slots.set(slot, null));
327
+ this.equipment.set(ownerId, state);
328
+ return state;
329
+ }
330
+ getEquipment(ownerId) {
331
+ return this.equipment.get(ownerId);
332
+ }
333
+ equipItem(ownerId, containerId, slotIndex) {
334
+ let equipState = this.equipment.get(ownerId);
335
+ if (!equipState) {
336
+ equipState = this.initializeEquipment(ownerId);
337
+ }
338
+ const container = this.containers.get(containerId);
339
+ if (!container) {
340
+ return false;
341
+ }
342
+ const invSlot = container.slots[slotIndex];
343
+ if (!invSlot?.item) {
344
+ return false;
345
+ }
346
+ const def = this.itemDefinitions.get(invSlot.item.itemId);
347
+ if (!def?.equipSlot) {
348
+ return false;
349
+ }
350
+ let targetSlot = def.equipSlot;
351
+ if (targetSlot === "twoHand") {
352
+ const mainHand = equipState.slots.get("mainHand");
353
+ const offHand = equipState.slots.get("offHand");
354
+ if (mainHand) {
355
+ this.unequipToContainer(ownerId, "mainHand", containerId);
356
+ }
357
+ if (offHand) {
358
+ this.unequipToContainer(ownerId, "offHand", containerId);
359
+ }
360
+ targetSlot = "mainHand";
361
+ }
362
+ const itemToEquip = { ...invSlot.item };
363
+ const currentEquipped = equipState.slots.get(targetSlot);
364
+ if (currentEquipped) {
365
+ invSlot.item = currentEquipped;
366
+ } else {
367
+ invSlot.item = null;
368
+ }
369
+ equipState.slots.set(targetSlot, itemToEquip);
370
+ if (def.binding === "onEquip" && !itemToEquip.boundTo) {
371
+ itemToEquip.boundTo = String(ownerId);
372
+ }
373
+ this.recalculateEquipmentStats(ownerId);
374
+ this.emit({
375
+ type: "item:equipped",
376
+ ownerId,
377
+ item: itemToEquip,
378
+ slot: slotIndex,
379
+ timestamp: Date.now()
380
+ });
381
+ return true;
382
+ }
383
+ unequipItem(ownerId, equipSlot, containerId) {
384
+ return this.unequipToContainer(ownerId, equipSlot, containerId);
385
+ }
386
+ unequipToContainer(ownerId, equipSlot, containerId) {
387
+ const equipState = this.equipment.get(ownerId);
388
+ if (!equipState) {
389
+ return false;
390
+ }
391
+ const equippedItem = equipState.slots.get(equipSlot);
392
+ if (!equippedItem) {
393
+ return false;
394
+ }
395
+ const container = this.containers.get(containerId);
396
+ if (!container) {
397
+ return false;
398
+ }
399
+ const emptySlot = container.slots.find((s) => !s.item && !s.locked);
400
+ if (!emptySlot) {
401
+ return false;
402
+ }
403
+ emptySlot.item = equippedItem;
404
+ equipState.slots.set(equipSlot, null);
405
+ this.recalculateEquipmentStats(ownerId);
406
+ this.emit({
407
+ type: "item:unequipped",
408
+ ownerId,
409
+ item: equippedItem,
410
+ slot: emptySlot.index,
411
+ timestamp: Date.now()
412
+ });
413
+ return true;
414
+ }
415
+ recalculateEquipmentStats(ownerId) {
416
+ const equipState = this.equipment.get(ownerId);
417
+ if (!equipState) {
418
+ return;
419
+ }
420
+ equipState.totalStats.clear();
421
+ for (const [, item] of equipState.slots) {
422
+ if (!item) {
423
+ continue;
424
+ }
425
+ const def = this.itemDefinitions.get(item.itemId);
426
+ if (!def?.stats) {
427
+ continue;
428
+ }
429
+ for (const mod of def.stats) {
430
+ const current = equipState.totalStats.get(mod.stat) ?? 0;
431
+ equipState.totalStats.set(mod.stat, current + (mod.flat ?? 0));
432
+ }
433
+ }
434
+ }
435
+ /* ── Durability & Repair ────────────────────────────────────── */
436
+ damageDurability(instance, damage) {
437
+ if (!this.config.enableDurability) {
438
+ return false;
439
+ }
440
+ if (instance.durability === void 0) {
441
+ return false;
442
+ }
443
+ instance.durability = Math.max(0, instance.durability - damage);
444
+ if (instance.durability <= 0) {
445
+ this.emit({
446
+ type: "item:destroyed",
447
+ item: instance,
448
+ timestamp: Date.now()
449
+ });
450
+ return true;
451
+ }
452
+ return false;
453
+ }
454
+ repairItem(instance, amount) {
455
+ const def = this.itemDefinitions.get(instance.itemId);
456
+ if (!def?.maxDurability || instance.durability === void 0) {
457
+ return false;
458
+ }
459
+ instance.durability = Math.min(
460
+ def.maxDurability,
461
+ amount !== void 0 ? instance.durability + amount : def.maxDurability
462
+ );
463
+ this.emit({
464
+ type: "item:repaired",
465
+ item: instance,
466
+ timestamp: Date.now()
467
+ });
468
+ return true;
469
+ }
470
+ /* ── Consumables ────────────────────────────────────────────── */
471
+ useItem(containerId, slotIndex, targetEntityId) {
472
+ const container = this.containers.get(containerId);
473
+ if (!container) {
474
+ return false;
475
+ }
476
+ const slot = container.slots[slotIndex];
477
+ if (!slot?.item) {
478
+ return false;
479
+ }
480
+ const def = this.itemDefinitions.get(slot.item.itemId);
481
+ if (!def) {
482
+ return false;
483
+ }
484
+ if (def.cooldown) {
485
+ const lastUsed = this.cooldowns.get(slot.item.instanceId) ?? 0;
486
+ if (Date.now() - lastUsed < def.cooldown) {
487
+ return false;
488
+ }
489
+ }
490
+ if (def.cooldown) {
491
+ this.cooldowns.set(slot.item.instanceId, Date.now());
492
+ }
493
+ this.emit({
494
+ type: "item:used",
495
+ containerId,
496
+ ownerId: container.ownerId,
497
+ item: slot.item,
498
+ slot: slotIndex,
499
+ customData: { targetEntityId, effectId: def.effectId },
500
+ timestamp: Date.now()
501
+ });
502
+ if (def.consumeOnUse) {
503
+ slot.item.count--;
504
+ if (slot.item.count <= 0) {
505
+ slot.item = null;
506
+ }
507
+ }
508
+ return true;
509
+ }
510
+ /* ── Crafting System ────────────────────────────────────────── */
511
+ registerRecipe(recipe) {
512
+ this.recipes.set(recipe.id, recipe);
513
+ }
514
+ learnRecipe(entityId, recipeId) {
515
+ const recipe = this.recipes.get(recipeId);
516
+ if (!recipe || !recipe.requiresLearning) {
517
+ return false;
518
+ }
519
+ let learned = this.learnedRecipes.get(entityId);
520
+ if (!learned) {
521
+ learned = /* @__PURE__ */ new Set();
522
+ this.learnedRecipes.set(entityId, learned);
523
+ }
524
+ learned.add(recipeId);
525
+ return true;
526
+ }
527
+ canCraft(entityId, recipeId, containerId) {
528
+ const recipe = this.recipes.get(recipeId);
529
+ if (!recipe) {
530
+ return false;
531
+ }
532
+ if (recipe.requiresLearning) {
533
+ const learned = this.learnedRecipes.get(entityId);
534
+ if (!learned?.has(recipeId)) {
535
+ return false;
536
+ }
910
537
  }
911
- removeItemsByIdFromContainer(containerId, itemId, count) {
912
- const container = this.containers.get(containerId);
913
- if (!container) {
914
- return 0;
915
- }
916
- let removed = 0;
917
- for (const slot of container.slots) {
918
- if (!slot.item || slot.item.itemId !== itemId) {
919
- continue;
920
- }
921
- const toRemove = Math.min(count - removed, slot.item.count);
922
- slot.item.count -= toRemove;
923
- removed += toRemove;
924
- if (slot.item.count <= 0) {
925
- slot.item = null;
926
- }
927
- if (removed >= count) {
928
- break;
929
- }
930
- }
931
- return removed;
538
+ const container = this.containers.get(containerId);
539
+ if (!container) {
540
+ return false;
932
541
  }
933
- findItem(containerId, itemId) {
934
- const container = this.containers.get(containerId);
935
- if (!container) {
936
- return null;
937
- }
938
- for (const slot of container.slots) {
939
- if (slot.item?.itemId === itemId) {
940
- return { slot, instance: slot.item };
542
+ for (const ingredient of recipe.ingredients) {
543
+ const available = this.countItemsInContainer(containerId, ingredient.itemId);
544
+ if (available < ingredient.count) {
545
+ return false;
546
+ }
547
+ }
548
+ return true;
549
+ }
550
+ craft(entityId, recipeId, containerId) {
551
+ if (!this.canCraft(entityId, recipeId, containerId)) {
552
+ return null;
553
+ }
554
+ const recipe = this.recipes.get(recipeId);
555
+ this.containers.get(containerId);
556
+ if (Math.random() > recipe.successRate) {
557
+ for (const ingredient of recipe.ingredients) {
558
+ if (ingredient.consumed) {
559
+ this.removeItemsByIdFromContainer(containerId, ingredient.itemId, ingredient.count);
560
+ }
561
+ }
562
+ this.emit({
563
+ type: "craft:failed",
564
+ ownerId: entityId,
565
+ recipeId,
566
+ containerId,
567
+ timestamp: Date.now()
568
+ });
569
+ return null;
570
+ }
571
+ for (const ingredient of recipe.ingredients) {
572
+ if (ingredient.consumed) {
573
+ this.removeItemsByIdFromContainer(containerId, ingredient.itemId, ingredient.count);
574
+ }
575
+ }
576
+ const output = this.addItem(containerId, recipe.outputItemId, recipe.outputCount);
577
+ this.emit({
578
+ type: "craft:completed",
579
+ ownerId: entityId,
580
+ recipeId,
581
+ containerId,
582
+ item: output ?? void 0,
583
+ timestamp: Date.now()
584
+ });
585
+ return output;
586
+ }
587
+ /* ── Loot Tables ────────────────────────────────────────────── */
588
+ registerLootTable(table) {
589
+ this.lootTables.set(table.id, table);
590
+ }
591
+ generateLoot(tableId, modifiers = {}) {
592
+ const table = this.lootTables.get(tableId);
593
+ if (!table) {
594
+ return [];
595
+ }
596
+ const loot = [];
597
+ if (table.guaranteedDrops) {
598
+ for (const drop of table.guaranteedDrops) {
599
+ const instance = this.createItemInstance(drop.itemId, drop.count);
600
+ if (instance) {
601
+ loot.push(instance);
602
+ }
603
+ }
604
+ }
605
+ const validEntries = table.entries.filter((e) => {
606
+ if (e.conditions?.minLevel && modifiers.levelContext && modifiers.levelContext < e.conditions.minLevel) {
607
+ return false;
608
+ }
609
+ if (e.conditions?.maxLevel && modifiers.levelContext && modifiers.levelContext > e.conditions.maxLevel) {
610
+ return false;
611
+ }
612
+ return true;
613
+ });
614
+ const totalWeight = validEntries.reduce((sum, e) => sum + e.weight, 0);
615
+ for (let roll = 0; roll < table.rolls; roll++) {
616
+ let random = Math.random() * totalWeight;
617
+ for (const entry of validEntries) {
618
+ random -= entry.weight;
619
+ if (random <= 0) {
620
+ const effectiveChance = Math.min(1, entry.dropChance + (modifiers.luckBonus ?? 0));
621
+ if (Math.random() <= effectiveChance) {
622
+ const count = Math.floor(
623
+ entry.minCount + Math.random() * (entry.maxCount - entry.minCount + 1)
624
+ );
625
+ const instance = this.createItemInstance(entry.itemId, count);
626
+ if (instance) {
627
+ loot.push(instance);
941
628
  }
942
- }
943
- return null;
944
- }
945
- /* ── Serialization ──────────────────────────────────────────── */
946
- serialize() {
947
- return {
948
- containers: Array.from(this.containers.entries()).map(([_id, c]) => ({
949
- ...c,
950
- currency: c.currency ? Array.from(c.currency.entries()) : [],
951
- })),
952
- equipment: Array.from(this.equipment.entries()).map(([id, e]) => ({
953
- ownerId: id,
954
- slots: Array.from(e.slots.entries()),
955
- totalStats: Array.from(e.totalStats.entries()),
956
- })),
957
- learnedRecipes: Array.from(this.learnedRecipes.entries()).map(([id, recipes]) => ({
958
- entityId: id,
959
- recipes: Array.from(recipes),
960
- })),
961
- };
962
- }
963
- deserialize(snapshot) {
964
- this.containers.clear();
965
- this.equipment.clear();
966
- this.learnedRecipes.clear();
967
- for (const c of snapshot.containers) {
968
- this.containers.set(c.id, {
969
- ...c,
970
- currency: new Map(c.currency),
971
- });
972
- }
973
- for (const e of snapshot.equipment) {
974
- this.equipment.set(e.ownerId, {
975
- ownerId: e.ownerId,
976
- slots: new Map(e.slots),
977
- totalStats: new Map(e.totalStats),
978
- });
979
- }
980
- for (const r of snapshot.learnedRecipes) {
981
- this.learnedRecipes.set(r.entityId, new Set(r.recipes));
982
- }
983
- }
629
+ }
630
+ break;
631
+ }
632
+ }
633
+ }
634
+ this.emit({
635
+ type: "loot:generated",
636
+ customData: { tableId, loot },
637
+ timestamp: Date.now()
638
+ });
639
+ return loot;
640
+ }
641
+ /* ── Shop System ────────────────────────────────────────────── */
642
+ registerShop(shop) {
643
+ this.shops.set(shop.id, shop);
644
+ }
645
+ getShop(shopId) {
646
+ return this.shops.get(shopId);
647
+ }
648
+ buyFromShop(shopId, listingIndex, quantity, buyerContainerId) {
649
+ const shop = this.shops.get(shopId);
650
+ const container = this.containers.get(buyerContainerId);
651
+ if (!shop || !container) {
652
+ return false;
653
+ }
654
+ const listing = shop.listings[listingIndex];
655
+ if (!listing) {
656
+ return false;
657
+ }
658
+ if (listing.stock !== -1 && listing.stock < quantity) {
659
+ return false;
660
+ }
661
+ const def = this.itemDefinitions.get(listing.itemId);
662
+ if (!def) {
663
+ return false;
664
+ }
665
+ const unitPrice = listing.price ?? Math.ceil(def.value * shop.sellRate);
666
+ const totalPrice = unitPrice * quantity;
667
+ const buyerCurrency = container.currency?.get(listing.currencyId) ?? 0;
668
+ if (buyerCurrency < totalPrice) {
669
+ return false;
670
+ }
671
+ container.currency.set(listing.currencyId, buyerCurrency - totalPrice);
672
+ const purchased = this.addItem(buyerContainerId, listing.itemId, quantity);
673
+ if (!purchased) {
674
+ container.currency.set(listing.currencyId, buyerCurrency);
675
+ return false;
676
+ }
677
+ if (listing.stock !== -1) {
678
+ listing.stock -= quantity;
679
+ }
680
+ this.emit({
681
+ type: "shop:bought",
682
+ shopId,
683
+ containerId: buyerContainerId,
684
+ ownerId: container.ownerId,
685
+ itemId: listing.itemId,
686
+ count: quantity,
687
+ currencyId: listing.currencyId,
688
+ amount: totalPrice,
689
+ timestamp: Date.now()
690
+ });
691
+ return true;
692
+ }
693
+ sellToShop(shopId, sellerContainerId, slotIndex, quantity) {
694
+ const shop = this.shops.get(shopId);
695
+ const container = this.containers.get(sellerContainerId);
696
+ if (!shop || !container) {
697
+ return false;
698
+ }
699
+ const slot = container.slots[slotIndex];
700
+ if (!slot?.item || slot.item.count < quantity) {
701
+ return false;
702
+ }
703
+ const def = this.itemDefinitions.get(slot.item.itemId);
704
+ if (!def || !def.sellable) {
705
+ return false;
706
+ }
707
+ const unitPrice = Math.floor(def.value * shop.buyRate);
708
+ const totalPrice = unitPrice * quantity;
709
+ const currencyId = shop.acceptedCurrencies[0];
710
+ if (!currencyId) {
711
+ return false;
712
+ }
713
+ this.removeItem(sellerContainerId, slotIndex, quantity);
714
+ const currentCurrency = container.currency?.get(currencyId) ?? 0;
715
+ container.currency.set(currencyId, currentCurrency + totalPrice);
716
+ this.emit({
717
+ type: "shop:sold",
718
+ shopId,
719
+ containerId: sellerContainerId,
720
+ ownerId: container.ownerId,
721
+ itemId: def.id,
722
+ count: quantity,
723
+ currencyId,
724
+ amount: totalPrice,
725
+ timestamp: Date.now()
726
+ });
727
+ return true;
728
+ }
729
+ /* ── Currency ───────────────────────────────────────────────── */
730
+ addCurrency(containerId, currencyId, amount) {
731
+ const container = this.containers.get(containerId);
732
+ if (!container) {
733
+ return false;
734
+ }
735
+ if (!container.currency) {
736
+ container.currency = /* @__PURE__ */ new Map();
737
+ }
738
+ const current = container.currency.get(currencyId) ?? 0;
739
+ container.currency.set(currencyId, current + amount);
740
+ this.emit({
741
+ type: "currency:changed",
742
+ containerId,
743
+ ownerId: container.ownerId,
744
+ currencyId,
745
+ amount,
746
+ timestamp: Date.now()
747
+ });
748
+ return true;
749
+ }
750
+ removeCurrency(containerId, currencyId, amount) {
751
+ const container = this.containers.get(containerId);
752
+ if (!container?.currency) {
753
+ return false;
754
+ }
755
+ const current = container.currency.get(currencyId) ?? 0;
756
+ if (current < amount) {
757
+ return false;
758
+ }
759
+ container.currency.set(currencyId, current - amount);
760
+ this.emit({
761
+ type: "currency:changed",
762
+ containerId,
763
+ ownerId: container.ownerId,
764
+ currencyId,
765
+ amount: -amount,
766
+ timestamp: Date.now()
767
+ });
768
+ return true;
769
+ }
770
+ getCurrency(containerId, currencyId) {
771
+ return this.containers.get(containerId)?.currency?.get(currencyId) ?? 0;
772
+ }
773
+ /* ── Sorting ────────────────────────────────────────────────── */
774
+ sortContainer(containerId, criteria = "category") {
775
+ const container = this.containers.get(containerId);
776
+ if (!container) {
777
+ return;
778
+ }
779
+ const items = container.slots.filter((s) => s.item && !s.locked).map((s) => s.item).sort((a, b) => {
780
+ const defA = this.itemDefinitions.get(a.itemId);
781
+ const defB = this.itemDefinitions.get(b.itemId);
782
+ if (!defA || !defB) {
783
+ return 0;
784
+ }
785
+ switch (criteria) {
786
+ case "category":
787
+ return defA.category.localeCompare(defB.category) || defA.name.localeCompare(defB.name);
788
+ case "rarity": {
789
+ const rarityOrder = [
790
+ "common",
791
+ "uncommon",
792
+ "rare",
793
+ "epic",
794
+ "legendary",
795
+ "mythic",
796
+ "unique"
797
+ ];
798
+ return rarityOrder.indexOf(defB.rarity) - rarityOrder.indexOf(defA.rarity);
799
+ }
800
+ case "name":
801
+ return defA.name.localeCompare(defB.name);
802
+ case "value":
803
+ return defB.value - defA.value;
804
+ default:
805
+ return 0;
806
+ }
807
+ });
808
+ container.slots.forEach((s) => {
809
+ if (!s.locked) {
810
+ s.item = null;
811
+ }
812
+ });
813
+ let itemIndex = 0;
814
+ for (const slot of container.slots) {
815
+ if (!slot.locked && itemIndex < items.length) {
816
+ slot.item = items[itemIndex++];
817
+ }
818
+ }
819
+ container.sorted = true;
820
+ this.emit({
821
+ type: "container:sorted",
822
+ containerId,
823
+ ownerId: container.ownerId,
824
+ timestamp: Date.now()
825
+ });
826
+ }
827
+ /* ── Utility Methods ────────────────────────────────────────── */
828
+ countItemsInContainer(containerId, itemId) {
829
+ const container = this.containers.get(containerId);
830
+ if (!container) {
831
+ return 0;
832
+ }
833
+ return container.slots.reduce((sum, slot) => {
834
+ if (slot.item?.itemId === itemId) {
835
+ return sum + slot.item.count;
836
+ }
837
+ return sum;
838
+ }, 0);
839
+ }
840
+ removeItemsByIdFromContainer(containerId, itemId, count) {
841
+ const container = this.containers.get(containerId);
842
+ if (!container) {
843
+ return 0;
844
+ }
845
+ let removed = 0;
846
+ for (const slot of container.slots) {
847
+ if (!slot.item || slot.item.itemId !== itemId) {
848
+ continue;
849
+ }
850
+ const toRemove = Math.min(count - removed, slot.item.count);
851
+ slot.item.count -= toRemove;
852
+ removed += toRemove;
853
+ if (slot.item.count <= 0) {
854
+ slot.item = null;
855
+ }
856
+ if (removed >= count) {
857
+ break;
858
+ }
859
+ }
860
+ return removed;
861
+ }
862
+ findItem(containerId, itemId) {
863
+ const container = this.containers.get(containerId);
864
+ if (!container) {
865
+ return null;
866
+ }
867
+ for (const slot of container.slots) {
868
+ if (slot.item?.itemId === itemId) {
869
+ return { slot, instance: slot.item };
870
+ }
871
+ }
872
+ return null;
873
+ }
874
+ /* ── Serialization ──────────────────────────────────────────── */
875
+ serialize() {
876
+ return {
877
+ containers: Array.from(this.containers.entries()).map(([_id, c]) => ({
878
+ ...c,
879
+ currency: c.currency ? Array.from(c.currency.entries()) : []
880
+ })),
881
+ equipment: Array.from(this.equipment.entries()).map(([id, e]) => ({
882
+ ownerId: id,
883
+ slots: Array.from(e.slots.entries()),
884
+ totalStats: Array.from(e.totalStats.entries())
885
+ })),
886
+ learnedRecipes: Array.from(this.learnedRecipes.entries()).map(([id, recipes]) => ({
887
+ entityId: id,
888
+ recipes: Array.from(recipes)
889
+ }))
890
+ };
891
+ }
892
+ deserialize(snapshot) {
893
+ this.containers.clear();
894
+ this.equipment.clear();
895
+ this.learnedRecipes.clear();
896
+ for (const c of snapshot.containers) {
897
+ this.containers.set(c.id, {
898
+ ...c,
899
+ currency: new Map(c.currency)
900
+ });
901
+ }
902
+ for (const e of snapshot.equipment) {
903
+ this.equipment.set(e.ownerId, {
904
+ ownerId: e.ownerId,
905
+ slots: new Map(e.slots),
906
+ totalStats: new Map(e.totalStats)
907
+ });
908
+ }
909
+ for (const r of snapshot.learnedRecipes) {
910
+ this.learnedRecipes.set(r.entityId, new Set(r.recipes));
911
+ }
912
+ }
984
913
  }
985
- /* ═══════════════════════════════════════════════════════════════
986
- REACT INTEGRATION
987
- ══════════════════════════════════════════════════════════════════ */
988
914
  const InventoryContext = /* @__PURE__ */ React.createContext(null);
989
915
  const InventoryProvider = ({ manager, children }) => {
990
- return React.createElement(InventoryContext.Provider, { value: manager }, children);
916
+ return React.createElement(InventoryContext.Provider, { value: manager }, children);
991
917
  };
992
918
  function useInventoryManager() {
993
- const ctx = React.useContext(InventoryContext);
994
- if (!ctx) {
995
- throw new Error('useInventoryManager must be used within InventoryProvider');
996
- }
997
- return ctx;
919
+ const ctx = React.useContext(InventoryContext);
920
+ if (!ctx) {
921
+ throw new Error("useInventoryManager must be used within InventoryProvider");
922
+ }
923
+ return ctx;
998
924
  }
999
925
  function useContainer(containerId) {
1000
- const manager = useInventoryManager();
1001
- const [container, setContainer] = React.useState(() => manager.getContainer(containerId));
1002
- React.useEffect(() => {
1003
- setContainer(manager.getContainer(containerId));
1004
- }, [manager, containerId]);
1005
- return container;
926
+ const manager = useInventoryManager();
927
+ const [container, setContainer] = React.useState(() => manager.getContainer(containerId));
928
+ React.useEffect(() => {
929
+ setContainer(manager.getContainer(containerId));
930
+ }, [manager, containerId]);
931
+ return container;
1006
932
  }
1007
933
  function useEquipment(ownerId) {
1008
- const manager = useInventoryManager();
1009
- const [equipment, setEquipment] = React.useState(() => manager.getEquipment(ownerId));
1010
- React.useEffect(() => {
1011
- setEquipment(manager.getEquipment(ownerId));
1012
- }, [manager, ownerId]);
1013
- return equipment;
934
+ const manager = useInventoryManager();
935
+ const [equipment, setEquipment] = React.useState(() => manager.getEquipment(ownerId));
936
+ React.useEffect(() => {
937
+ setEquipment(manager.getEquipment(ownerId));
938
+ }, [manager, ownerId]);
939
+ return equipment;
1014
940
  }
1015
-
1016
941
  exports.InventoryManager = InventoryManager;
1017
942
  exports.InventoryProvider = InventoryProvider;
1018
943
  exports.useContainer = useContainer;