@nice2dev/game-engine 1.3.15 → 1.3.17
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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- package/package.json +7 -12
|
@@ -1,1018 +1,943 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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:
|
|
543
|
-
|
|
544
|
-
timestamp: Date.now()
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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 (
|
|
767
|
-
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
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
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
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
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
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
|
-
|
|
916
|
+
return React.createElement(InventoryContext.Provider, { value: manager }, children);
|
|
991
917
|
};
|
|
992
918
|
function useInventoryManager() {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
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
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
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;
|