初始版本可以去申请电子版权和软著了

This commit is contained in:
2025-08-21 13:54:28 +08:00
parent 0a654d130a
commit 1b56cb7a8c
12 changed files with 1816 additions and 185 deletions

View File

@@ -96,6 +96,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 更新出战英雄配置异常:`, error);
smc.error()
return false;
}
}
@@ -122,6 +123,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 重置出战英雄配置异常:`, error);
smc.error()
return false;
}
}
@@ -151,6 +153,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 添加英雄异常:`, error);
smc.error()
return false;
}
}
@@ -178,6 +181,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 更新英雄异常:`, error);
smc.error()
return false;
}
}
@@ -206,6 +210,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 设置英雄属性异常:`, error);
smc.error()
return false;
}
}
@@ -216,11 +221,11 @@ export class GameDataSyncManager {
* @param levels 升级级数默认1级
* @returns 是否成功
*/
async levelUpHero(heroId: number, exp:number,gold:number,levels: number = 1,): Promise<boolean> {
async levelUpHero(heroId: number,levels: number = 1,): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 英雄升级 ID:${heroId}, 级数:${levels}`);
const result = await WxCloudApi.levelUpHero(heroId, exp,gold,levels);
const result = await WxCloudApi.levelUpHero(heroId,levels);
if (result.result.code === 200) {
// 远程修改成功,同步本地数据
@@ -233,6 +238,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 英雄升级异常:`, error);
smc.error()
return false;
}
}
@@ -260,6 +266,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 增加道具异常:`, error);
smc.error()
return false;
}
}
@@ -289,6 +296,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 消耗道具异常:`, error);
smc.error()
return false;
}
}
@@ -318,6 +326,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 增加天赋点异常:`, error);
smc.error()
return false;
}
}
@@ -345,6 +354,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 消耗天赋点异常:`, error);
smc.error()
return false;
}
}
@@ -372,6 +382,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 增加装备异常:`, error);
smc.error()
return false;
}
}
@@ -399,10 +410,12 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 消耗装备异常:`, error);
smc.error()
return false;
}
}
async addGameProperty(property: string, value: any): Promise<boolean> {
try {
@@ -417,11 +430,12 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 增加游戏数据异常:`, error);
smc.error()
return false;
}
}
async spendGameProperty(property: string, value: any): Promise<boolean> {
async spendGameProperty(property: string|Record<string, number>, value: any = undefined ): Promise<boolean> {
try {
console.log(`[GameDataSyncManager]: 消耗游戏数据 ${property} = ${value}`);
const result = await WxCloudApi.spendGameDataField(property, value);
@@ -431,6 +445,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 消耗游戏数据异常:`, error);
smc.error()
return false;
}
}
@@ -463,6 +478,7 @@ export class GameDataSyncManager {
}
} catch (error) {
console.error(`[GameDataSyncManager]: 加载云端数据异常:`, error);
smc.error()
return false;
}
}

View File

@@ -9,6 +9,8 @@ import { gameDataSyncManager } from "./GameDataSyncManager";
import { GameSet } from "./config/BoxSet";
import { Test } from "./Test";
import { GameEvent } from "./config/GameEvent";
import { Items } from "./config/Items";
import { HeroInfo } from "./config/heroSet";
// import { Role } from "../role/Role";
@@ -94,6 +96,8 @@ export class SingletonModuleComp extends ecs.Comp {
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
}
//调试用
syncDataFromLocal(){
if(this.isWxClient()) return
@@ -101,6 +105,18 @@ export class SingletonModuleComp extends ecs.Comp {
this.gameDataSyncManager.overrideLocalDataWithRemote(loginResult, "本地调试");
}
addHero(hero_uuid:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.addHero(hero_uuid)){
this.heros[hero_uuid]={ uuid:hero_uuid, lv:1, }
return true
}
return false
}
this.heros[hero_uuid]={ uuid:hero_uuid, lv:1, }
return true
}
setFightHero(position:number,heroId:number,autoSave:boolean=true){
this.fight_heros[position] = heroId;
if(this.isWxClient()){
@@ -121,9 +137,11 @@ export class SingletonModuleComp extends ecs.Comp {
}
return heros_uuid
}
levelUpHero(heroId:number,exp:number,gold:number){
levelUpHero(heroId:number){
if(this.isWxClient()){
let result=this.gameDataSyncManager.levelUpHero(heroId,exp,gold);
let result=this.gameDataSyncManager.levelUpHero(heroId);
if(result){
this.heros[heroId].lv++;
return true
@@ -136,98 +154,112 @@ export class SingletonModuleComp extends ecs.Comp {
}
}
// ==================== 统一的数据操作接口 ====================
/**
* 增加游戏数据属性(统一接口)
* @param property 属性名
* property list:
* ***gold:金币
* ***diamond:钻石
* ***meat:肉
* ***exp:经验
* ***score:分数
* ***mission:关卡
* @param value 增加的值
* @param autoSave 是否自动保存 (默认true)
* @returns 操作结果
*/
error(){
oops.gui.toast("数据处理异常,请重试或重新登录")
}
addExp(exp:number,autoSave:boolean=true){
this.data.exp+=exp
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("exp",exp)
if(this.gameDataSyncManager.addGameProperty("exp",exp)){
this.data.exp+=exp
return true
}
return false
}
this.data.exp+=exp
return true
}
addGold(gold:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.addGameProperty("gold",gold)){
this.data.gold+=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
return true
}
this.error()
return false
}
this.data.gold+=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("gold",gold)
}
return true
}
addDiamond(diamond:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.addGameProperty("diamond",diamond)){
this.data.diamond+=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
return true
}
return false
}
this.data.diamond+=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("diamond",diamond)
}
return true
}
addMission(mission:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.addGameProperty("mission",mission)){
this.data.mission+=mission
oops.message.dispatchEvent(GameEvent.MISSION_UPDATE)
return true
}
return false
}
this.data.mission+=mission
oops.message.dispatchEvent(GameEvent.MISSION_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.addGameProperty("mission",mission)
}
return true
}
spendExp(exp:number,autoSave:boolean=true){
this.data.exp-=exp
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("exp",exp)
if(this.gameDataSyncManager.spendGameProperty("exp",exp)){
this.data.exp-=exp
return true
}
return false
}
this.data.exp-=exp
return true
}
spendGold(gold:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.spendGameProperty("gold",gold)){
this.data.gold-=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
return true
}
return false
}
this.data.gold-=gold
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("gold",gold)
}
return true
}
spendDiamond(diamond:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.spendGameProperty("diamond",diamond)){
this.data.diamond-=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
return true
}
return false
}
this.data.diamond-=diamond
oops.message.dispatchEvent(GameEvent.DIAMOND_UPDATE)
if(this.isWxClient()){
this.gameDataSyncManager.spendGameProperty("diamond",diamond)
}
return true
}
/**
* 消耗游戏数据属性(统一接口)
* - 支持单个字段spendGameProperty('gold', 10)
* - 支持多个字段spendGameProperty({ gold: 10, exp: 5 })
* 只有当所有字段都满足扣除条件时,才会一次性扣减
* @param property 属性名或属性映射
* @param value 消耗的值(当 property 为字符串时有效)
* @param autoSave 是否自动保存 (默认true)
* @returns 是否成功消耗
* 处理多个字段spendGameProperty({ gold: 10, exp: 5 })
*/
async spendGameProperty(property: string | Record<string, number>, value: any = undefined, autoSave: boolean = true): Promise<boolean> {
// 单字段扣除
if (typeof property === 'string') {
const currentValue = this.data[property] || 0;
if (currentValue < value) {
console.warn(`[SMC]: ${property} 不足,当前: ${currentValue}, 需要: ${value}`);
return false;
async spendGameProperty(property: Record<string, number>, autoSave: boolean = true): Promise<boolean> {
if(this.isWxClient()){
if(this.gameDataSyncManager.spendGameProperty(property)){
return true
}
const newValue = currentValue - value;
this.data[property] = newValue;
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
return true;
return false
}
// 多字段扣除(原子性:全部满足才扣)
const deductions = property as Record<string, number>;
// 1) 校验是否全部满足
@@ -237,10 +269,10 @@ export class SingletonModuleComp extends ecs.Comp {
const current = this.data[key] || 0;
if (current < need) {
console.warn(`[SMC]: ${key} 不足,当前: ${current}, 需要: ${need}`);
oops.gui.toast(`${key} 不足,当前: ${current}, 需要: ${need}`)
return false;
}
}
// 2) 统一扣减
for (const key in deductions) {
if (!Object.prototype.hasOwnProperty.call(deductions, key)) continue;
@@ -250,18 +282,32 @@ export class SingletonModuleComp extends ecs.Comp {
this.data[key] = next;
console.log(`[SMC]: 消耗游戏数据 ${key} = ${need}, 当前值: ${next}`);
}
return true;
}
addItem(item_uuid:number,count:number,autoSave:boolean=true){
if(this.isWxClient()){
this.gameDataSyncManager.addItem(item_uuid,count);
}
else{
this.items[item_uuid] = (this.items[item_uuid] || 0) + count;
if(this.gameDataSyncManager.addItem(item_uuid,count)){
this.items[item_uuid] = (this.items[item_uuid] || 0) + count;
return true
}
return false
}
this.items[item_uuid] = (this.items[item_uuid] || 0) + count;
return true
}
spendItem(item_uuid:number,count:number,autoSave:boolean=true){
if(this.isWxClient()){
if(this.gameDataSyncManager.consumeItem(item_uuid,count)){
this.items[item_uuid] = (this.items[item_uuid] || 0) - count;
return true
}
return false
}
this.items[item_uuid] = (this.items[item_uuid] || 0) - count;
return true
}
}

View File

@@ -1,6 +1,7 @@
import { v3 } from "cc"
import { FacSet, QualitySet } from "./BoxSet"
import { smc } from "../SingletonModuleComp"
import { Items } from "./Items"
/**
* kind 1:烈焰 2:寒冰 3:自然 4:暗影 5:神圣
**/
@@ -30,7 +31,19 @@ export enum HType {
remote = 1,
mage = 2,
}
/**
* 解锁英雄所需物品
* 绿色:铜钥匙*100 item:1006 num:100
* 蓝色:银钥匙*200 item:1007 num:200
* 紫色:金钥匙*100 item:1008 num:100
* 橙色:金钥匙*100 item:1009 num:100
*/
export const unlockHeroCost={
[QualitySet.GREEN]:{i_uuid:Items[1006].uuid,num:100},
[QualitySet.BLUE]:{i_uuid:Items[1006].uuid,num:200},
[QualitySet.PURPLE]:{i_uuid:Items[1007].uuid,num:100},
[QualitySet.ORANGE]:{i_uuid:Items[1008].uuid,num:100},
}
//fac:FacSet.HERO
export const getHeroList = (quality:number=0)=>{
const filteredHeros = Object.values(HeroInfo).filter(item=>{