mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
58 lines
1.1 KiB
TypeScript
58 lines
1.1 KiB
TypeScript
import { app } from "../App";
|
|
import { API, ResourceOV } from "../consts/API";
|
|
import BaseData from "./BaseData";
|
|
|
|
export enum ResourceEvent{
|
|
UPDATE = "ResourceEvent_UPDATE", //刷新资源
|
|
}
|
|
|
|
//资源类型
|
|
export enum ResourceType{
|
|
Gold = 90001, //金币
|
|
}
|
|
|
|
//玩家资源数据
|
|
export default class ResourceData extends BaseData{
|
|
|
|
//资源数据 {资源Id:资源数量}
|
|
data:{[key:number]:number} = {};
|
|
|
|
//初始化
|
|
async onInit() {
|
|
await this.onUpdateResource();
|
|
}
|
|
|
|
//更新玩家资源
|
|
async onUpdateResource(){
|
|
|
|
//请求资源
|
|
let res = await API.GetPlayerResource();
|
|
|
|
//保存资源数量
|
|
res.forEach(data => {
|
|
this.data[data.resourceTbId] = data.resourceValue;
|
|
})
|
|
|
|
}
|
|
|
|
//获取指定资源的数量
|
|
getValue(type:ResourceType){
|
|
return this.data[type] || 0;
|
|
}
|
|
|
|
//刷新返回资源
|
|
onUpdateOV(operation:number,resource:ResourceOV){
|
|
|
|
if(operation == 0){
|
|
//更新资源
|
|
this.data[resource.resourceTbId] = resource.resourceValue;
|
|
}
|
|
|
|
app.event.emit(ResourceEvent.UPDATE)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|