From b77f0235481ec56dc52cb709edf0a79a94f4cafb Mon Sep 17 00:00:00 2001 From: panfudan Date: Tue, 12 Aug 2025 16:58:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=95=B0=E6=8D=AE=E5=AD=98?= =?UTF-8?q?=E5=8F=96=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/gui/element/lucky.prefab | 504 +++++++++++++++++- assets/resources/gui/role_controller.prefab | 382 ++++++++++++- .../script/game/common/SingletonModuleComp.ts | 470 +++++++++++++++- assets/script/game/common/config/Mission.ts | 2 + assets/script/game/initialize/Initialize.ts | 42 +- assets/script/game/map/MissionComp.ts | 7 +- assets/script/game/map/MissionHomeComp.ts | 7 + assets/script/game/map/MissionMonComp.ts | 2 +- assets/script/game/map/VictoryComp.ts | 3 +- 9 files changed, 1376 insertions(+), 43 deletions(-) diff --git a/assets/resources/gui/element/lucky.prefab b/assets/resources/gui/element/lucky.prefab index ed09d8b2..b847fab8 100644 --- a/assets/resources/gui/element/lucky.prefab +++ b/assets/resources/gui/element/lucky.prefab @@ -28,19 +28,19 @@ "_active": true, "_components": [ { - "__id__": 60 + "__id__": 80 }, { - "__id__": 62 + "__id__": 82 } ], "_prefab": { - "__id__": 64 + "__id__": 84 }, "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": 228.866, + "y": -411.134, "z": 0 }, "_lrot": { @@ -133,7 +133,7 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 350, + "width": 500, "height": 50 }, "_anchorPoint": { @@ -206,8 +206,8 @@ }, "_alignFlags": 40, "_target": null, - "_left": 185, - "_right": 185, + "_left": 110, + "_right": 110, "_top": 0, "_bottom": 0, "_horizontalCenter": 0, @@ -255,22 +255,25 @@ }, { "__id__": 33 + }, + { + "__id__": 53 } ], "_active": true, "_components": [ { - "__id__": 53 + "__id__": 73 }, { - "__id__": 55 + "__id__": 75 }, { - "__id__": 57 + "__id__": 77 } ], "_prefab": { - "__id__": 59 + "__id__": 79 }, "_lpos": { "__type__": "cc.Vec3", @@ -303,7 +306,7 @@ }, { "__type__": "cc.Node", - "_name": "coins", + "_name": "gold", "_objFlags": 0, "__editorExtras__": {}, "_parent": { @@ -328,7 +331,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": -135, + "x": -210, "y": 0, "z": 0 }, @@ -796,7 +799,7 @@ }, { "__type__": "cc.Node", - "_name": "count", + "_name": "diamond", "_objFlags": 0, "__editorExtras__": {}, "_parent": { @@ -821,7 +824,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": 15, + "x": -60, "y": 0, "z": 0 }, @@ -949,7 +952,7 @@ "a": 255 }, "_spriteFrame": { - "__uuid__": "49c583b3-d566-4c79-9e4c-bd0ca4a4b717@a139a", + "__uuid__": "49c583b3-d566-4c79-9e4c-bd0ca4a4b717@d2cb1", "__expectedType__": "cc.SpriteFrame" }, "_type": 0, @@ -1185,7 +1188,7 @@ "__id__": 48 }, "templateMode": false, - "watchPath": "data.mission_data.refresh_count", + "watchPath": "data.mission_data.diamond", "labelType": "cc.Label", "watchPathArr": [], "_id": "" @@ -1248,6 +1251,460 @@ "targetOverrides": null, "nestedPrefabInstanceRoots": null }, + { + "__type__": "cc.Node", + "_name": "mission", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": { + "__id__": 10 + }, + "_children": [ + { + "__id__": 54 + }, + { + "__id__": 60 + } + ], + "_active": true, + "_components": [ + { + "__id__": 70 + } + ], + "_prefab": { + "__id__": 72 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 90, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_mobility": 0, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "ItemIcon_Ticket_Gold", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": { + "__id__": 53 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 55 + }, + { + "__id__": 57 + } + ], + "_prefab": { + "__id__": 59 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 0.4, + "y": 0.4, + "z": 1 + }, + "_mobility": 0, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 54 + }, + "_enabled": true, + "__prefab": { + "__id__": 56 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 128, + "height": 128 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "0bB3zZ4dRDAqckiAeaH3a8" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 54 + }, + "_enabled": true, + "__prefab": { + "__id__": 58 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "49c583b3-d566-4c79-9e4c-bd0ca4a4b717@b5bcd", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 1, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "283ljlJt1ICabEFFX7+vtD" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "4bEXCSzrhDvIKuKpLUbW2V", + "instance": null, + "targetOverrides": null, + "nestedPrefabInstanceRoots": null + }, + { + "__type__": "cc.Node", + "_name": "num", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": { + "__id__": 53 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 61 + }, + { + "__id__": 63 + }, + { + "__id__": 65 + }, + { + "__id__": 67 + } + ], + "_prefab": { + "__id__": 69 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 5, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_mobility": 0, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 60 + }, + "_enabled": true, + "__prefab": { + "__id__": 62 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 80, + "height": 35 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "db/+ZGLsJBOpreykUIsriR" + }, + { + "__type__": "cc.Label", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 60 + }, + "_enabled": true, + "__prefab": { + "__id__": 64 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_string": "9999", + "_horizontalAlign": 0, + "_verticalAlign": 1, + "_actualFontSize": 30, + "_fontSize": 30, + "_fontFamily": "Arial", + "_lineHeight": 35, + "_overflow": 2, + "_enableWrapText": true, + "_font": null, + "_isSystemFontUsed": true, + "_spacingX": 0, + "_isItalic": false, + "_isBold": true, + "_isUnderline": false, + "_underlineHeight": 2, + "_cacheMode": 0, + "_enableOutline": true, + "_outlineColor": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_outlineWidth": 2, + "_enableShadow": false, + "_shadowColor": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_shadowOffset": { + "__type__": "cc.Vec2", + "x": 2, + "y": 2 + }, + "_shadowBlur": 2, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "33IeCHamJLbZ2z7YvlZ1hl" + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 60 + }, + "_enabled": true, + "__prefab": { + "__id__": 66 + }, + "_alignFlags": 18, + "_target": null, + "_left": -15, + "_right": -15, + "_top": 0, + "_bottom": 0, + "_horizontalCenter": -30, + "_verticalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 80, + "_originalHeight": 0, + "_alignMode": 2, + "_lockFlags": 0, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "3eDcZZ0whHTbStotzvqfOU" + }, + { + "__type__": "545c05XsG9GDJispEGWKvYv", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 60 + }, + "_enabled": true, + "__prefab": { + "__id__": 68 + }, + "templateMode": false, + "watchPath": "data.mission_data.mission", + "labelType": "cc.Label", + "watchPathArr": [], + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "cfPUkHtUhI7Y5+UR0EDVbP" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "afTcUOWMlBNZLOa/fdmAKQ", + "instance": null, + "targetOverrides": null, + "nestedPrefabInstanceRoots": null + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 53 + }, + "_enabled": true, + "__prefab": { + "__id__": 71 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 150, + "height": 50 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "a6y+skfR9JZYlL793MIc3i" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "ffUnmXtAJH9KA/mdbakTgi", + "instance": null, + "targetOverrides": null, + "nestedPrefabInstanceRoots": null + }, { "__type__": "cc.UITransform", "_name": "", @@ -1258,11 +1715,11 @@ }, "_enabled": true, "__prefab": { - "__id__": 54 + "__id__": 74 }, "_contentSize": { "__type__": "cc.Size", - "width": 330, + "width": 480, "height": 100 }, "_anchorPoint": { @@ -1286,7 +1743,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 56 + "__id__": 76 }, "_alignFlags": 16, "_target": null, @@ -1322,7 +1779,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 58 + "__id__": 78 }, "_resizeMode": 1, "_layoutType": 1, @@ -1373,7 +1830,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 61 + "__id__": 81 }, "_contentSize": { "__type__": "cc.Size", @@ -1401,7 +1858,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 63 + "__id__": 83 }, "_alignFlags": 44, "_target": null, @@ -1436,6 +1893,7 @@ "__id__": 0 }, "fileId": "c9POIiGDRD145GjODqam/b", + "instance": null, "targetOverrides": null } ] \ No newline at end of file diff --git a/assets/resources/gui/role_controller.prefab b/assets/resources/gui/role_controller.prefab index c38e9ced..1ec7f44b 100644 --- a/assets/resources/gui/role_controller.prefab +++ b/assets/resources/gui/role_controller.prefab @@ -26,22 +26,25 @@ }, { "__id__": 626 + }, + { + "__id__": 666 } ], "_active": true, "_components": [ { - "__id__": 666 + "__id__": 695 }, { - "__id__": 668 + "__id__": 697 }, { - "__id__": 670 + "__id__": 699 } ], "_prefab": { - "__id__": 672 + "__id__": 701 }, "_lpos": { "__type__": "cc.Vec3", @@ -181,7 +184,7 @@ "_lpos": { "__type__": "cc.Vec3", "x": -306.784, - "y": 1238.567, + "y": 64.12400000000002, "z": 0 }, "_lrot": { @@ -752,7 +755,7 @@ "_target": null, "_left": 3.216000000000008, "_right": 20, - "_top": 11.432999999999993, + "_top": 1185.876, "_bottom": 1069.101, "_horizontalCenter": 0, "_verticalCenter": 0, @@ -15271,6 +15274,360 @@ "targetOverrides": null, "nestedPrefabInstanceRoots": null }, + { + "__type__": "cc.Node", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_prefab": { + "__id__": 667 + }, + "__editorExtras__": {} + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 666 + }, + "asset": { + "__uuid__": "139f14cc-484c-4a8d-bfbf-d03cab9da553", + "__expectedType__": "cc.Prefab" + }, + "fileId": "c9POIiGDRD145GjODqam/b", + "instance": { + "__id__": 668 + }, + "targetOverrides": null + }, + { + "__type__": "cc.PrefabInstance", + "fileId": "736shlg3ZPs5EYj4X0YxTO", + "prefabRootNode": { + "__id__": 1 + }, + "mountedChildren": [], + "mountedComponents": [], + "propertyOverrides": [ + { + "__id__": 669 + }, + { + "__id__": 671 + }, + { + "__id__": 672 + }, + { + "__id__": 673 + }, + { + "__id__": 674 + }, + { + "__id__": 676 + }, + { + "__id__": 678 + }, + { + "__id__": 679 + }, + { + "__id__": 681 + }, + { + "__id__": 682 + }, + { + "__id__": 683 + }, + { + "__id__": 684 + }, + { + "__id__": 686 + }, + { + "__id__": 688 + }, + { + "__id__": 690 + }, + { + "__id__": 691 + }, + { + "__id__": 692 + }, + { + "__id__": 694 + } + ], + "removedComponents": [] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 670 + }, + "propertyPath": [ + "_name" + ], + "value": "lucky" + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "c9POIiGDRD145GjODqam/b" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 670 + }, + "propertyPath": [ + "_lpos" + ], + "value": { + "__type__": "cc.Vec3", + "x": -2.808999999999969, + "y": 1222.74, + "z": 0 + } + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 670 + }, + "propertyPath": [ + "_lrot" + ], + "value": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + } + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 670 + }, + "propertyPath": [ + "_euler" + ], + "value": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + } + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 675 + }, + "propertyPath": [ + "_bottom" + ], + "value": 1187.74 + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "32JLwFj+9NLZacq366ZnCw" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 677 + }, + "propertyPath": [ + "_alignFlags" + ], + "value": 8 + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "34r2ez99xP0oUhE86XdZ2h" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 677 + }, + "propertyPath": [ + "_left" + ], + "value": 20 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 680 + }, + "propertyPath": [ + "_resizeMode" + ], + "value": 1 + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "9eEsWbC6RAU7oHUdbRIR8a" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 675 + }, + "propertyPath": [ + "_left" + ], + "value": -2.8089999999999886 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 675 + }, + "propertyPath": [ + "_right" + ], + "value": 2.8089999999999886 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 675 + }, + "propertyPath": [ + "_alignFlags" + ], + "value": 12 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 685 + }, + "propertyPath": [ + "_lpos" + ], + "value": { + "__type__": "cc.Vec3", + "x": -100, + "y": 0, + "z": 0 + } + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "a1tJISIr5HIY+xwhWaE78W" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 687 + }, + "propertyPath": [ + "_contentSize" + ], + "value": { + "__type__": "cc.Size", + "width": 500, + "height": 50 + } + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "7dO+Y5W0pFK5GhKU+bAO4p" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 689 + }, + "propertyPath": [ + "_alignFlags" + ], + "value": 8 + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "cdgeT8NrhFEpUzHt5Rj+bV" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 689 + }, + "propertyPath": [ + "_left" + ], + "value": 15 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 689 + }, + "propertyPath": [ + "_right" + ], + "value": 210 + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 693 + }, + "propertyPath": [ + "_lpos" + ], + "value": { + "__type__": "cc.Vec3", + "x": -345, + "y": 0, + "z": 0 + } + }, + { + "__type__": "cc.TargetInfo", + "localID": [ + "3bmV0DxQ5OKZHpJ0UZBhln" + ] + }, + { + "__type__": "CCPropertyOverrideInfo", + "targetInfo": { + "__id__": 687 + }, + "propertyPath": [ + "_anchorPoint" + ], + "value": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + } + }, { "__type__": "cc.UITransform", "_name": "GameUI", @@ -15281,7 +15638,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 667 + "__id__": 696 }, "_contentSize": { "__type__": "cc.Size", @@ -15309,7 +15666,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 669 + "__id__": 698 }, "_alignFlags": 45, "_target": null, @@ -15345,7 +15702,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 671 + "__id__": 700 }, "_id": "" }, @@ -15363,6 +15720,11 @@ }, "fileId": "6514ysgfJNtIx/ak03+nce", "instance": null, - "targetOverrides": [] + "targetOverrides": [], + "nestedPrefabInstanceRoots": [ + { + "__id__": 666 + } + ] } ] \ No newline at end of file diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 4a0e9c31..c4a0d6e6 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -3,6 +3,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec import { Initialize } from "../initialize/Initialize"; import { GameMap } from "../map/GameMap"; import { HeroUI, MissionData, VmInfo } from "./config/Mission"; +import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; // import { Role } from "../role/Role"; @@ -19,8 +20,14 @@ export class SingletonModuleComp extends ecs.Comp { play:false, pause:false, in_select:false, - score:888, + in_fight:false, }; + data:any={ + score:0, + mission:1, + gold:100, + diamond:100, + } fight_heros:any={ 0:5001, 1:5005, @@ -33,6 +40,7 @@ export class SingletonModuleComp extends ecs.Comp { 5005:{lv:1}, 5007:{lv:1}, }; + monsters:any = []; sk_info:any = [] monsters_dead:any = [] @@ -55,6 +63,466 @@ export class SingletonModuleComp extends ecs.Comp { delete this.vmdata[key]; } } + + // ==================== 本地存储管理方法 ==================== + + /** + * 初始化默认游戏数据 + */ + initDefaultData() { + // 确保出战英雄有默认值 + if (!this.fight_heros || Object.keys(this.fight_heros).length === 0) { + this.fight_heros = { + 0: 5001, + 1: 5005, + 2: 0, + 3: 0, + 4: 0, + }; + } + + // 确保英雄属性有默认值 + if (!this.heros || Object.keys(this.heros).length === 0) { + this.heros = { + 5001: {lv: 1}, + 5005: {lv: 1}, + 5007: {lv: 1}, + }; + } + + // 确保游戏数据有默认值 + if (!this.data || Object.keys(this.data).length === 0) { + this.data = { + score: 888, + mission: 1, + gold: 100, + diamond: 100, + }; + } + + console.log("[SMC]: 默认数据已初始化 - 出战英雄:", this.fight_heros, "英雄属性:", this.heros, "游戏数据:", this.data); + } + + /** + * 保存游戏数据到本地存储 + */ + saveGameData() { + try { + // 保存出战英雄数据 + const fightHerosJson = JSON.stringify(this.fight_heros); + oops.storage.set("fight_heros", fightHerosJson); + + // 保存英雄属性数据 + const herosJson = JSON.stringify(this.heros); + oops.storage.set("heros", herosJson); + + // 保存游戏数据(金币、钻石等) + const dataJson = JSON.stringify(this.data); + oops.storage.set("game_data", dataJson); + + console.log("[SMC]: 游戏数据已保存 - 出战英雄:", this.fight_heros, "英雄属性:", this.heros, "游戏数据:", this.data); + return true; + } catch (error) { + console.error("[SMC]: 保存游戏数据失败:", error); + return false; + } + } + + /** + * 保存英雄数据到本地存储(兼容旧方法名) + */ + saveHeroData() { + return this.saveGameData(); + } + + /** + * 从本地存储加载游戏数据 + */ + loadGameData() { + console.log("[SMC]: 加载游戏数据") + try { + let hasAnyData = false; + + // 加载出战英雄数据 + const savedFightHeros = oops.storage.get("fight_heros"); + if (savedFightHeros && savedFightHeros !== "") { + const fightHerosData = JSON.parse(savedFightHeros); + this.fight_heros = fightHerosData; + console.log("[SMC]: 从本地加载出战英雄数据:", fightHerosData); + hasAnyData = true; + } else { + console.log("[SMC]: 未找到本地出战英雄数据,使用默认配置"); + } + + // 加载英雄属性数据 + const savedHeros = oops.storage.get("heros"); + if (savedHeros && savedHeros !== "") { + const herosData = JSON.parse(savedHeros); + this.heros = herosData; + console.log("[SMC]: 从本地加载英雄属性数据:", herosData); + hasAnyData = true; + } else { + console.log("[SMC]: 未找到本地英雄属性数据,使用默认配置"); + } + + // 加载游戏数据 + const savedData = oops.storage.get("game_data"); + if (savedData && savedData !== "") { + const gameData = JSON.parse(savedData); + this.data = gameData; + console.log("[SMC]: 从本地加载游戏数据:", gameData); + hasAnyData = true; + } else { + console.log("[SMC]: 未找到本地游戏数据,使用默认配置"); + } + + // 如果没有任何本地数据,说明是首次启动,初始化并保存默认数据 + if (!hasAnyData) { + console.log("[SMC]: 首次启动,初始化默认游戏数据"); + this.initDefaultData(); + this.saveGameData(); + return true; // 首次启动也算成功 + } + + return hasAnyData; + } catch (error) { + console.error("[SMC]: 加载游戏数据失败:", error); + return false; + } + } + + /** + * 从本地存储加载英雄数据(兼容旧方法名) + */ + loadHeroData() { + return this.loadGameData(); + } + + /** + * 设置出战英雄 + * @param position 出战位置 (0-4) + * @param heroId 英雄ID,0表示移除 + * @param autoSave 是否自动保存 (默认true) + */ + setFightHero(position: number, heroId: number, autoSave: boolean = true) { + if (position < 0 || position > 4) { + console.warn("[SMC]: 出战位置无效:", position); + return false; + } + + this.fight_heros[position] = heroId; + console.log(`[SMC]: 设置出战位置${position} -> 英雄${heroId}`); + + if (autoSave) { + this.saveGameData(); + } + return true; + } + + /** + * 获取出战英雄ID + * @param position 出战位置 (0-4) + */ + getFightHero(position: number): number { + if (position < 0 || position > 4) { + console.warn("[SMC]: 出战位置无效:", position); + return 0; + } + return this.fight_heros[position] || 0; + } + + /** + * 获取当前出战英雄列表(不包含空位) + */ + getActiveFightHeros(): number[] { + const activeHeros: number[] = []; + for (let i = 0; i < 5; i++) { + const heroId = this.fight_heros[i]; + if (heroId && heroId > 0) { + activeHeros.push(heroId); + } + } + return activeHeros; + } + + /** + * 设置英雄属性 + * @param heroId 英雄ID + * @param property 属性名 (如: lv, exp等) + * @param value 属性值 + * @param autoSave 是否自动保存 (默认true) + */ + setHeroProperty(heroId: number, property: string, value: any, autoSave: boolean = true) { + if (!this.heros[heroId]) { + this.heros[heroId] = {}; + } + + this.heros[heroId][property] = value; + console.log(`[SMC]: 设置英雄${heroId}的${property} = ${value}`); + + if (autoSave) { + this.saveGameData(); + } + } + + /** + * 获取英雄属性 + * @param heroId 英雄ID + * @param property 属性名 + * @param defaultValue 默认值 + */ + getHeroProperty(heroId: number, property: string, defaultValue: any = null): any { + if (!this.heros[heroId]) { + return defaultValue; + } + return this.heros[heroId][property] !== undefined ? this.heros[heroId][property] : defaultValue; + } + + /** + * 英雄升级 + * @param heroId 英雄ID + * @param levels 升级级数 (默认1级) + * @param autoSave 是否自动保存 (默认true) + */ + levelUpHero(heroId: number, levels: number = 1, autoSave: boolean = true) { + const currentLevel = this.getHeroProperty(heroId, "lv", 1); + const newLevel = currentLevel + levels; + this.setHeroProperty(heroId, "lv", newLevel, autoSave); + console.log(`[SMC]: 英雄${heroId}升级: ${currentLevel} -> ${newLevel}`); + } + + /** + * 获取英雄等级 + * @param heroId 英雄ID + */ + getHeroLevel(heroId: number): number { + return this.getHeroProperty(heroId, "lv", 1); + } + + /** + * 清除所有本地存储数据 + */ + clearAllSaveData() { + try { + oops.storage.remove("fight_heros"); + oops.storage.remove("heros"); + oops.storage.remove("game_data"); + console.log("[SMC]: 已清除所有本地存储数据"); + return true; + } catch (error) { + console.error("[SMC]: 清除存储数据失败:", error); + return false; + } + } + + /** + * 重置英雄数据为默认值 + * @param autoSave 是否自动保存 (默认true) + */ + resetHeroData(autoSave: boolean = true) { + // 重置为默认出战英雄 + this.fight_heros = { + 0: 5001, + 1: 5005, + 2: 0, + 3: 0, + 4: 0, + }; + + // 重置为默认英雄属性 + this.heros = { + 5001: {lv: 1}, + 5005: {lv: 1}, + 5007: {lv: 1}, + }; + + console.log("[SMC]: 英雄数据已重置为默认值"); + + if (autoSave) { + this.saveGameData(); + } + } + + // ==================== 游戏数据管理方法 ==================== + + /** + * 设置游戏数据属性 + * @param property 属性名 (如: score, mission, gold, diamond) + * @param value 属性值 + * @param autoSave 是否自动保存 (默认true) + */ + setGameProperty(property: string, value: any, autoSave: boolean = true) { + this.data[property] = value; + this.vmdata.mission_data[property] = value; + console.log(`[SMC]: 设置游戏数据 ${property} = ${value}`); + + if (autoSave) { + this.saveGameData(); + } + } + + /** + * 获取游戏数据属性 + * @param property 属性名 + * @param defaultValue 默认值 + */ + getGameProperty(property: string, defaultValue: any = null): any { + return this.data[property] !== undefined ? this.data[property] : defaultValue; + } + + /** + * 增加金币 + * @param amount 金币数量 + * @param autoSave 是否自动保存 (默认true) + */ + addGold(amount: number, autoSave: boolean = true) { + const currentGold = this.getGameProperty("gold", 0); + const newGold = Math.max(0, currentGold + amount); + this.setGameProperty("gold", newGold, autoSave); + console.log(`[SMC]: 金币变更: ${currentGold} -> ${newGold} (${amount > 0 ? '+' : ''}${amount})`); + return newGold; + } + + /** + * 消耗金币 + * @param amount 消耗数量 + * @param autoSave 是否自动保存 (默认true) + * @returns 是否成功消耗 + */ + spendGold(amount: number, autoSave: boolean = true): boolean { + const currentGold = this.getGameProperty("gold", 0); + if (currentGold < amount) { + console.warn(`[SMC]: 金币不足,当前: ${currentGold}, 需要: ${amount}`); + return false; + } + + this.addGold(-amount, autoSave); + return true; + } + + /** + * 获取金币数量 + */ + getGold(): number { + return this.getGameProperty("gold", 0); + } + + /** + * 增加钻石 + * @param amount 钻石数量 + * @param autoSave 是否自动保存 (默认true) + */ + addDiamond(amount: number, autoSave: boolean = true) { + const currentDiamond = this.getGameProperty("diamond", 0); + const newDiamond = Math.max(0, currentDiamond + amount); + this.setGameProperty("diamond", newDiamond, autoSave); + console.log(`[SMC]: 钻石变更: ${currentDiamond} -> ${newDiamond} (${amount > 0 ? '+' : ''}${amount})`); + return newDiamond; + } + + /** + * 消耗钻石 + * @param amount 消耗数量 + * @param autoSave 是否自动保存 (默认true) + * @returns 是否成功消耗 + */ + spendDiamond(amount: number, autoSave: boolean = true): boolean { + const currentDiamond = this.getGameProperty("diamond", 0); + if (currentDiamond < amount) { + console.warn(`[SMC]: 钻石不足,当前: ${currentDiamond}, 需要: ${amount}`); + return false; + } + + this.addDiamond(-amount, autoSave); + return true; + } + + /** + * 获取钻石数量 + */ + getDiamond(): number { + return this.getGameProperty("diamond", 0); + } + + /** + * 设置关卡进度 + * @param mission 关卡号 + * @param autoSave 是否自动保存 (默认true) + */ + setMission(mission: number, autoSave: boolean = true) { + const currentMission = this.getGameProperty("mission", 1); + if (mission > currentMission) { + this.setGameProperty("mission", mission, autoSave); + console.log(`[SMC]: 关卡进度更新: ${currentMission} -> ${mission}`); + } + } + + /** + * 获取当前关卡进度 + */ + getMission(): number { + return this.getGameProperty("mission", 1); + } + + /** + * 增加分数 + * @param score 分数 + * @param autoSave 是否自动保存 (默认true) + */ + addScore(score: number, autoSave: boolean = true) { + const currentScore = this.getGameProperty("score", 0); + const newScore = currentScore + score; + this.setGameProperty("score", newScore, autoSave); + console.log(`[SMC]: 分数增加: ${currentScore} -> ${newScore} (+${score})`); + return newScore; + } + + /** + * 获取当前分数 + */ + getScore(): number { + return this.getGameProperty("score", 0); + } + + /** + * 重置游戏数据为默认值 + * @param autoSave 是否自动保存 (默认true) + */ + resetGameData(autoSave: boolean = true) { + this.data = { + score: 888, + mission: 1, + gold: 100, + diamond: 100, + }; + + console.log("[SMC]: 游戏数据已重置为默认值:", this.data); + + if (autoSave) { + this.saveGameData(); + } + } + + /** + * 检查本地存储状态(调试用) + */ + checkLocalStorage() { + const fightHeros = oops.storage.get("fight_heros"); + const heros = oops.storage.get("heros"); + const gameData = oops.storage.get("game_data"); + + console.log("[SMC]: 本地存储状态检查:"); + console.log(" - fight_heros:", fightHeros ? "存在" : "不存在", fightHeros); + console.log(" - heros:", heros ? "存在" : "不存在", heros); + console.log(" - game_data:", gameData ? "存在" : "不存在", gameData); + + return { + hasFightHeros: !!fightHeros, + hasHeros: !!heros, + hasGameData: !!gameData, + isFirstTime: !fightHeros && !heros && !gameData + }; + } } export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp); \ No newline at end of file diff --git a/assets/script/game/common/config/Mission.ts b/assets/script/game/common/config/Mission.ts index de6138fe..0f93e45c 100644 --- a/assets/script/game/common/config/Mission.ts +++ b/assets/script/game/common/config/Mission.ts @@ -90,7 +90,9 @@ export enum FightSet { export const MissionData = { gold:1000,//金币 score:0,//分数 + diamond:0,//钻石 current_wave:1, + mission:1,//关卡 mon_num:0,//怪物数量 wave_time_num:0,//波次时间 in_fight:false, diff --git a/assets/script/game/initialize/Initialize.ts b/assets/script/game/initialize/Initialize.ts index f0553f39..50204804 100644 --- a/assets/script/game/initialize/Initialize.ts +++ b/assets/script/game/initialize/Initialize.ts @@ -11,6 +11,7 @@ import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-fra import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { UIID } from "../common/config/GameUIConfig"; import { LoadingViewComp } from "./view/LoadingViewComp"; +import { smc } from "../common/SingletonModuleComp"; // import {data} from "../data/data"; @@ -46,10 +47,13 @@ export class Initialize extends ecs.Entity { private loadCustom(queue: AsyncQueue) { queue.push(async (next: NextFunction, params: any, args: any) => { // 加载多语言对应字体 - oops.res.load("language/font/" + oops.language.current, next); + oops.res.load("language/font/" + oops.language.current, () => { + // 加载本地英雄数据 + this.loadHeroDataFromLocal(); + next(); + }); //加载精灵配置表 // oops.res.load("config/game/heros", next); - }); } @@ -80,6 +84,40 @@ export class Initialize extends ecs.Entity { }); } + /** + * 从本地存储加载游戏数据 + */ + private loadHeroDataFromLocal() { + // 检查本地存储状态 + const storageStatus = smc.checkLocalStorage(); + + if (storageStatus.isFirstTime) { + console.log("[Initialize]: 检测到首次启动游戏"); + } + + // 使用SingletonModuleComp的加载方法 + // loadGameData方法已经包含了首次启动的处理逻辑 + const success = smc.loadGameData(); + if (success) { + console.log("[Initialize]: 游戏数据加载完成"); + } else { + console.log("[Initialize]: 游戏数据加载失败,使用默认配置"); + // 如果加载失败,初始化默认数据并保存 + smc.initDefaultData(); + smc.saveGameData(); + } + + // 再次检查存储状态,确认数据已保存 + if (storageStatus.isFirstTime) { + const newStatus = smc.checkLocalStorage(); + if (newStatus.hasFightHeros && newStatus.hasHeros && newStatus.hasGameData) { + console.log("[Initialize]: 首次启动数据保存成功"); + } else { + console.warn("[Initialize]: 首次启动数据保存可能失败"); + } + } + } + /** 加载完成进入游戏内容加载界面 */ private onComplete(queue: AsyncQueue) { queue.complete = () => { diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index 0e26f928..de50ad5a 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -34,9 +34,8 @@ export class MissionComp extends CCComp { if(!smc.mission.play||smc.mission.pause){ return } - if(smc.vmdata.mission_data.in_fight){ + if(smc.mission.in_fight){ smc.vmdata.mission_data.fight_time+=dt - } } //奖励发放 @@ -58,7 +57,7 @@ export class MissionComp extends CCComp { } do_mon_dead_thing(){ - smc.vmdata.mission_data.gold+=smc.vmdata.mission_data.add_gold+smc.vmdata.mission_data.buff_add_gold + smc.addGold(1) } do_ad(){ @@ -96,7 +95,7 @@ export class MissionComp extends CCComp { to_fight(){ console.log("[MissionComp] ** 3 ** to_fight") - smc.vmdata.mission_data.in_fight=true + smc.mission.in_fight=true oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪 } diff --git a/assets/script/game/map/MissionHomeComp.ts b/assets/script/game/map/MissionHomeComp.ts index 83d601b0..4bf1fb60 100644 --- a/assets/script/game/map/MissionHomeComp.ts +++ b/assets/script/game/map/MissionHomeComp.ts @@ -29,9 +29,16 @@ export class MissionHomeComp extends CCComp { this.home_active() } home_active(){ + this.uodate_data() this.node.active=true oops.message.dispatchEvent(GameEvent.UpdateHero, {}) } + uodate_data(){ + smc.vmdata.mission_data.mission=smc.data.mission + smc.vmdata.mission_data.score=smc.data.score + smc.vmdata.mission_data.gold=smc.data.gold + smc.vmdata.mission_data.diamond=smc.data.diamond + } diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index d030e18e..a5d887e4 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -101,7 +101,7 @@ export class MissionMonCompComp extends CCComp { // 添加刷怪队列 - 使 this.isPausing = false; this.spawnTimer = 0; - const currentStage = smc.vmdata.mission_data.current_wave; + const currentStage = smc.data.mission; // 使用新的肉鸽关卡配置 const stageType = getStageType(currentStage); const monsterConfigs = getStageMonsterConfigs(currentStage); diff --git a/assets/script/game/map/VictoryComp.ts b/assets/script/game/map/VictoryComp.ts index 503b5269..27e06bff 100644 --- a/assets/script/game/map/VictoryComp.ts +++ b/assets/script/game/map/VictoryComp.ts @@ -26,8 +26,7 @@ export class VictoryComp extends CCComp { this.hide() } fight_end(e:any,val:any){ - this.node.getChildByName("score").getComponent(Label).string=smc.mission.score.toString() - this.node.getChildByName("score_add").getComponent(Label).string=smc.vmdata.mission_data.score.toString() + this.open() } victory_end(){