mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
资源刷新 以及 出售
This commit is contained in:
57
JisolGameCocos/assets/script/data/ResourceData.ts
Normal file
57
JisolGameCocos/assets/script/data/ResourceData.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
9
JisolGameCocos/assets/script/data/ResourceData.ts.meta
Normal file
9
JisolGameCocos/assets/script/data/ResourceData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7d3c75f4-37fd-4009-baab-1fcc2430b739",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user