初始版本可以去申请电子版权和软著了
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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=>{
|
||||
|
||||
@@ -98,8 +98,16 @@ export class GoodsComp extends Component {
|
||||
}else if(this.goodsData.c_type==CType.FREE){
|
||||
this.do_free()
|
||||
}else if(this.goodsData.c_type==CType.DIAMOND){
|
||||
if(smc.data.diamond<this.goodsData.cast){
|
||||
oops.gui.toast("钻石不足")
|
||||
return
|
||||
}
|
||||
this.do_diamond_cast()
|
||||
}else if(this.goodsData.c_type==CType.GOLD){
|
||||
if(smc.data.gold<this.goodsData.cast){
|
||||
oops.gui.toast("金币不足")
|
||||
return
|
||||
}
|
||||
this.do_gold_cast()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,18 @@ export class HCardUICom extends Component {
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
to_update_hero(){
|
||||
this.update_data(this.h_uuid,{type:this.type})
|
||||
to_update_hero(event:any,args:any){
|
||||
if(args.uuid==this.h_uuid){
|
||||
console.log("[HCardUICom]:是我诶:",HeroInfo[args.uuid].name+args.uuid)
|
||||
this.update_data(args.uuid,{type:this.type})
|
||||
}
|
||||
}
|
||||
update_data(uuid:number,args:any){
|
||||
this.type=args.type
|
||||
if(args.slot) this.slot=args.slot
|
||||
console.log("[HCardUICom]:update_data",uuid,this.type,this.slot,args)
|
||||
this.h_uuid=uuid
|
||||
this.node.getChildByName("in_fight").active=this.check_in_fight(uuid)
|
||||
this.node.getChildByName("in_fight").active=this.check_in_fight()
|
||||
let hero_data = HeroInfo[uuid]
|
||||
let hero= this.node.getChildByName("hero")
|
||||
let anm_path=hero_data.path
|
||||
@@ -69,7 +72,7 @@ export class HCardUICom extends Component {
|
||||
break
|
||||
case HeroConSet.SELECT:
|
||||
if(oops.gui.has(UIID.HeroSelect)) {
|
||||
this.check_in_slot(this.h_uuid)
|
||||
this.check_in_slot()
|
||||
smc.setFightHero(this.slot,this.h_uuid,true)
|
||||
oops.message.dispatchEvent(GameEvent.UpdateFightHero)
|
||||
oops.gui.remove(UIID.HeroSelect)
|
||||
@@ -77,18 +80,18 @@ export class HCardUICom extends Component {
|
||||
break
|
||||
}
|
||||
}
|
||||
check_in_slot(uuid:number){ //如果英雄在出战位,则移除久的出战位
|
||||
check_in_slot(){ //如果英雄在出战位,则移除久的出战位
|
||||
let heros=smc.fight_heros
|
||||
for(let i=0;i<GameSet.HERO_NUM;i++){
|
||||
if(heros[i]==uuid) {
|
||||
if(heros[i]==this.h_uuid) {
|
||||
smc.setFightHero(i,0,true)
|
||||
}
|
||||
}
|
||||
}
|
||||
check_in_fight(uuid:number){
|
||||
check_in_fight(){
|
||||
let heros=smc.fight_heros
|
||||
for(let i=0;i<GameSet.HERO_NUM;i++){
|
||||
if(heros[i]==uuid) return true
|
||||
if(heros[i]==this.h_uuid) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { _decorator, Animation, AnimationClip, Component, Label, Node, resources } from 'cc';
|
||||
import { _decorator, Animation, AnimationClip, Component, Label, Node, resources, Sprite, SpriteFrame } from 'cc';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { UIID } from '../common/config/GameUIConfig';
|
||||
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType } from '../common/config/heroSet';
|
||||
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType, unlockHeroCost } from '../common/config/heroSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { NumberFormatter } from '../common/config/BoxSet';
|
||||
import { Items } from '../common/config/Items';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('HInfoComp')
|
||||
@@ -22,22 +23,21 @@ export class HInfoComp extends Component {
|
||||
|
||||
}
|
||||
update_data(uuid:number){
|
||||
console.log("[HInfoComp]:update_data",uuid)
|
||||
console.log("[HCardUICom]:update_data",uuid)
|
||||
|
||||
this.h_uuid=uuid
|
||||
let hero_data = HeroInfo[uuid]
|
||||
let hero= this.node.getChildByName("hero")
|
||||
console.log("[HInfoComp]:update_data",uuid,hero_data,this.node)
|
||||
let lv=smc.heros[uuid]?.lv??1
|
||||
let anm_path=hero_data.path
|
||||
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
|
||||
hero.getComponent(Animation).addClip(clip);
|
||||
hero.getComponent(Animation).play("idle");
|
||||
this.node.getChildByName("hero").getComponent(Animation).addClip(clip);
|
||||
this.node.getChildByName("hero").getComponent(Animation).play("idle");
|
||||
});
|
||||
this.node.getChildByName("name").getComponent(Label).string=hero_data.name
|
||||
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=lv.toString()
|
||||
this.node.getChildByName("skills").getChildByName("list2").getChildByName("luck").active= lv <5
|
||||
this.node.getChildByName("skills").getChildByName("list3").getChildByName("luck").active= lv <10
|
||||
this.node.getChildByName("skills").getChildByName("list4").getChildByName("luck").active= lv <15
|
||||
this.node.getChildByName("skills").getChildByName("list2").getChildByName("lock").active= lv <5
|
||||
this.node.getChildByName("skills").getChildByName("list3").getChildByName("lock").active= lv <10
|
||||
this.node.getChildByName("skills").getChildByName("list4").getChildByName("lock").active= lv <15
|
||||
let {hp,ap,def}=getHeroStatsByLevel(uuid,lv)
|
||||
this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=hp.toString()
|
||||
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=ap.toString()
|
||||
@@ -48,7 +48,7 @@ export class HInfoComp extends Component {
|
||||
this.node.getChildByName("type").getChildByName("w").active=hero_data.type==HType.warrior
|
||||
this.node.getChildByName("type").getChildByName("r").active=hero_data.type==HType.remote
|
||||
this.node.getChildByName("type").getChildByName("m").active=hero_data.type==HType.mage
|
||||
this.show_luck(smc.heros[uuid]?.lv??0)
|
||||
this.show_lock(smc.heros[uuid]?.lv??0)
|
||||
}
|
||||
updata_need(experience:number,gold:number){
|
||||
let need_node=this.node.getChildByName("upNeed").getChildByName("need")
|
||||
@@ -57,29 +57,62 @@ export class HInfoComp extends Component {
|
||||
need_node.getChildByName("exp").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.exp)
|
||||
need_node.getChildByName("gold").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.gold)
|
||||
}
|
||||
show_luck(lv:number){
|
||||
show_lock(lv:number){
|
||||
this.node.getChildByName("upBtn").active=lv > 0
|
||||
this.node.getChildByName("upNeed").active=lv > 0
|
||||
this.node.getChildByName("luck").active=lv == 0
|
||||
this.node.getChildByName("lock").active=lv == 0
|
||||
this.node.getChildByName("unLock").active=lv == 0
|
||||
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
||||
console.log("[HInfoComp]:show_lock item:item_uuid:hero_uuid:hero_data",Items[need_item.i_uuid],need_item.i_uuid,this.h_uuid,HeroInfo[this.h_uuid])
|
||||
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("has").getComponent(Label).string=smc.items[need_item.i_uuid]??0
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(need_item.num)
|
||||
let path="gui/items/"+Items[need_item.i_uuid].path
|
||||
resources.load(path,SpriteFrame, (err, clip) => {
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("icon").getComponent(Sprite).spriteFrame=clip
|
||||
});
|
||||
this.node.getChildByName("unLockNeed").active=lv == 0
|
||||
}
|
||||
uplockhero(){
|
||||
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
||||
if(!smc.items[need_item.i_uuid]||smc.items[need_item.i_uuid]<need_item.num){
|
||||
oops.gui.toast("["+Items[need_item.i_uuid].name+"]数量不足")
|
||||
return
|
||||
}
|
||||
if(!smc.spendItem(need_item.i_uuid,need_item.num)){
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
if(!smc.addHero(this.h_uuid)){
|
||||
smc.addItem(need_item.i_uuid,need_item.num,false)
|
||||
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >解锁失败")
|
||||
return
|
||||
}
|
||||
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >解锁成功")
|
||||
this.update_data(this.h_uuid)
|
||||
oops.message.dispatchEvent(GameEvent.UpdateHero, {uuid:this.h_uuid})
|
||||
}
|
||||
uplevel(){
|
||||
let lv=smc.heros[this.h_uuid].lv
|
||||
let {experience,gold}=getUpgradeResources(lv)
|
||||
if(smc.data.exp<=experience||smc.data.gold<=gold){
|
||||
if(smc.data.exp<experience||smc.data.gold<gold){
|
||||
oops.gui.toast("经验或金币不足")
|
||||
return
|
||||
}
|
||||
smc.spendGameProperty({exp:experience,gold:gold},false)
|
||||
let result=smc.levelUpHero(this.h_uuid,experience,gold)
|
||||
if(!result){
|
||||
smc.addExp(experience,false)
|
||||
smc.addGold(gold,false)
|
||||
oops.gui.toast("网络出错了,升级失败,请重试")
|
||||
if(!smc.spendGameProperty({exp:experience,gold:gold},false)){
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
if(!smc.levelUpHero(this.h_uuid)){
|
||||
smc.addExp(experience,false)
|
||||
smc.addGold(gold,false)
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
|
||||
this.update_data(this.h_uuid)
|
||||
oops.message.dispatchEvent(GameEvent.UpdateHero, {})
|
||||
oops.gui.toast(`英雄< ${HeroInfo[this.h_uuid].name} >升级成功`)
|
||||
oops.message.dispatchEvent(GameEvent.UpdateHero, {uuid:this.h_uuid})
|
||||
|
||||
}
|
||||
next_hero(){
|
||||
let heros=getHeroList()
|
||||
|
||||
@@ -446,3 +446,4 @@ export class GameDataManager {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -224,8 +224,8 @@ export class WxCloudApi{
|
||||
* @param amount 消耗的数量
|
||||
* @return Promise<CloudCallFunctionResult<CloudReturnType<{field: string, old_value: number, new_value: number, change: number}>>>
|
||||
*/
|
||||
public static async spendGameDataField(field:string, amount: number): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
field: string,
|
||||
public static async spendGameDataField(field:string|Record<string, number>, amount: number): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
field: string|Record<string, number>,
|
||||
old_value: number,
|
||||
new_value: number,
|
||||
change: number
|
||||
@@ -529,7 +529,7 @@ export class WxCloudApi{
|
||||
* @param levels 升级级数(默认1级)
|
||||
* @return Promise<CloudCallFunctionResult<CloudReturnType<{hero_id: number, property: string, old_value: number, new_value: number}>>>
|
||||
*/
|
||||
public static async levelUpHero(heroId: number, exp:number,gold:number,levels: number = 1): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
public static async levelUpHero(heroId: number,levels: number = 1): Promise<CloudCallFunctionResult<CloudReturnType<{
|
||||
hero_id: number,
|
||||
property: string,
|
||||
old_value: number,
|
||||
@@ -540,8 +540,6 @@ export class WxCloudApi{
|
||||
data: {
|
||||
cmd: "hero_levelup",
|
||||
hero_id: heroId,
|
||||
exp: exp,
|
||||
gold:gold,
|
||||
levels: levels
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user