资源刷新 以及 出售

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-20 03:47:00 +08:00
parent cb64a6c25f
commit 98b7a52b45
41 changed files with 1483 additions and 263 deletions

View File

@@ -147,7 +147,7 @@
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 6,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,

View File

@@ -144,7 +144,7 @@
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_clearFlags": 6,
"_rect": {
"__type__": "cc.Rect",
"x": 0,

View File

@@ -309,6 +309,39 @@ export class TbGOnHookGlobal {
}
export namespace TB {
export class TbGResource {
constructor(_json_: any) {
if (_json_.id === undefined) { throw new Error() }
this.id = _json_.id
if (_json_.name === undefined) { throw new Error() }
this.name = _json_.name
if (_json_.tig === undefined) { throw new Error() }
this.tig = _json_.tig
}
/**
* id
*/
readonly id: number
/**
* 资源名称
*/
readonly name: string
/**
* 描述
*/
readonly tig: string
resolve(tables:Tables)
{
}
}
}
export class TbGGlobal{
@@ -535,6 +568,38 @@ export class TbGOnHookGlobal{
export class TbGResource{
private _dataMap: Map<number, TB.TbGResource>
private _dataList: TB.TbGResource[]
constructor(_json_: any) {
this._dataMap = new Map<number, TB.TbGResource>()
this._dataList = []
for(var _json2_ of _json_) {
let _v: TB.TbGResource
_v = new TB.TbGResource(_json2_)
this._dataList.push(_v)
this._dataMap.set(_v.id, _v)
}
}
getDataMap(): Map<number, TB.TbGResource> { return this._dataMap; }
getDataList(): TB.TbGResource[] { return this._dataList; }
get(key: number): TB.TbGResource | undefined { return this._dataMap.get(key); }
resolve(tables:Tables)
{
for(let data of this._dataList)
{
data.resolve(tables)
}
}
}
type JsonLoader = (file: string) => any
export class Tables {
@@ -552,6 +617,8 @@ export class Tables {
get TbGMap(): TbGMap { return this._TbGMap;}
private _TbGOnHookGlobal: TbGOnHookGlobal
get TbGOnHookGlobal(): TbGOnHookGlobal { return this._TbGOnHookGlobal;}
private _TbGResource: TbGResource
get TbGResource(): TbGResource { return this._TbGResource;}
constructor(loader: JsonLoader) {
this._TbGGlobal = new TbGGlobal(loader('tbgglobal'))
@@ -561,6 +628,7 @@ export class Tables {
this._TbGRoleSkill = new TbGRoleSkill(loader('tbgroleskill'))
this._TbGMap = new TbGMap(loader('tbgmap'))
this._TbGOnHookGlobal = new TbGOnHookGlobal(loader('tbgonhookglobal'))
this._TbGResource = new TbGResource(loader('tbgresource'))
this._TbGGlobal.resolve(this)
this._TbGRole.resolve(this)
@@ -569,5 +637,6 @@ export class Tables {
this._TbGRoleSkill.resolve(this)
this._TbGMap.resolve(this)
this._TbGOnHookGlobal.resolve(this)
this._TbGResource.resolve(this)
}
}

View File

@@ -0,0 +1,7 @@
[
{
"id": 90001,
"name": "金币",
"tig": "金币 (目前叫做金币 名称还没有定) 游戏的基础资源 用于升级宠物"
}
]

View File

@@ -0,0 +1,11 @@
{
"ver": "2.0.1",
"importer": "json",
"imported": true,
"uuid": "97d4ae8c-12df-45cd-8629-87e18f6e8ddf",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -31,20 +31,20 @@
"_active": true,
"_components": [
{
"__id__": 67
"__id__": 68
},
{
"__id__": 69
"__id__": 70
},
{
"__id__": 71
"__id__": 72
},
{
"__id__": 73
"__id__": 74
}
],
"_prefab": {
"__id__": 75
"__id__": 76
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1109,11 +1109,11 @@
"__id__": 62
},
{
"__id__": 64
"__id__": 65
}
],
"_prefab": {
"__id__": 66
"__id__": 67
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1394,7 +1394,11 @@
"__prefab": {
"__id__": 63
},
"clickEvents": [],
"clickEvents": [
{
"__id__": 64
}
],
"_interactable": true,
"_transition": 3,
"_normalColor": {
@@ -1440,6 +1444,16 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "46kCHG8yRJL65tBER5eoyC"
},
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 1
},
"component": "",
"_componentId": "fe2adMH7MZF5KXgR4KwvwJX",
"handler": "onClickSell",
"customEventData": ""
},
{
"__type__": "cc.Widget",
"_name": "",
@@ -1450,7 +1464,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 65
"__id__": 66
},
"_alignFlags": 37,
"_target": null,
@@ -1499,7 +1513,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 68
"__id__": 69
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1527,7 +1541,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 70
"__id__": 71
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -1572,7 +1586,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 72
"__id__": 73
},
"_alignFlags": 40,
"_target": null,
@@ -1608,7 +1622,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 74
"__id__": 75
},
"views": {
"__id__": 46

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "984854ce-ea02-4a29-9a85-ae0d93f322d0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,341 @@
[
{
"__type__": "cc.Prefab",
"_name": "玩家资源显示",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "玩家资源显示",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [
{
"__id__": 10
},
{
"__id__": 12
},
{
"__id__": 14
}
],
"_prefab": {
"__id__": 16
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -46.486,
"y": 520.668,
"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": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Label",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 9
},
"_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": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 4
},
"_contentSize": {
"__type__": "cc.Size",
"width": 17.34765625,
"height": 54.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7aYBKLDBBBb6gSDGMjRc7V"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 6
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_string": "0",
"_horizontalAlign": 1,
"_verticalAlign": 1,
"_actualFontSize": 24,
"_fontSize": 24,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 0,
"_enableWrapText": true,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": true,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "ca5SxOX1lI6KJW85+4yzjd"
},
{
"__type__": "cc.LabelOutline",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_width": 2,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "3eNlsJF9tNXZmkwP9l76/E"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "e0KCY2i/BDFrz3/8Kl7xXv",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"_contentSize": {
"__type__": "cc.Size",
"width": 120,
"height": 60
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "31Y91EbyVPvqbf1yXWW3mP"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 13
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 235,
"g": 235,
"b": 235,
"a": 255
},
"_spriteFrame": {
"__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "829ZRhv3JLKq0wDBYUk3xR"
},
{
"__type__": "dd6ff3gNGFAzKeTlGPK1jnx",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 15
},
"type": 90001,
"show": {
"__id__": 5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "22Ciflh0NO/ZUfdrKoAktL"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "7ehoARooRAIIfX4ttdeppc",
"instance": null,
"targetOverrides": null
}
]

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.49",
"importer": "prefab",
"imported": true,
"uuid": "f9a7b5b8-0c1a-4b0c-a6c7-bbf2e077442a",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "玩家资源显示"
}
}

View File

@@ -25,12 +25,12 @@ import { StorageData, StorageEnum } from "./consts/GData";
import { JAPI, JAPIConfig } from "../../extensions/ngame/assets/ngame/util/JAPI";
import { AppData } from "./AppData";
// let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket`
let APIPath = `http://localhost:8080`
let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `http://192.168.0.123:8080`
// let WsPath = `ws://192.168.0.123:8080/websocket`
let APIPath = `https://api.pet.jisol.cn`
let WsPath = `wss://api.pet.jisol.cn/websocket`
// let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket`
//重写UI
class JNGLayer extends JNLayer{

View File

@@ -5,6 +5,7 @@ import ChatData from "./data/ChatData";
import PlayerData from "./data/PlayerData";
import PlayerPetData from "./data/PlayerPetData";
import PlayerTacticalData from "./data/PlayerTacticalData";
import ResourceData from "./data/ResourceData";
//数据类 (用于初始化游戏信息)
export class AppData extends SystemBase{
@@ -16,6 +17,7 @@ export class AppData extends SystemBase{
PlayerPetData.getIns(), //玩家宠物信息
ChatData.getIns(), //聊天
PlayerTacticalData.getIns(), //阵法
ResourceData.getIns(), //玩家资源
];
async onInit(): Promise<any> {

View File

@@ -326,17 +326,25 @@ export default class GOnHookMode extends GBaseMode<{}>{
//获取敌人
let roles = this.getOnesRoleAlive(enumyOnes);
//返回敌人
//获取我在第几排
let playerXY = player.tactical.getXY(player.tacticalIndex);
//通过排数获取最近的敌人
let sort = roles.sort((enumy1,enumy2) => {
let enumy1XY = enumy1.tactical.getXY(enumy1.tacticalIndex);
let enumy2XY = enumy2.tactical.getXY(enumy2.tacticalIndex);
return Math.abs((playerXY.y * 1000) - (enumy1XY.y * 1000)) + Math.abs((playerXY.x - enumy1XY.x)) -
Math.abs((playerXY.y * 1000) - (enumy2XY.y * 1000)) + Math.abs((playerXY.x - enumy2XY.x))
});
return sort[0]
//通过距离获取最近的敌人
if(roles[0]){
let len = Math.abs(Vec2.distance(player.v2World,roles[0].v2World));
let enumy = roles[0];
for (let index = 0; index < roles.length; index++) {
const role = roles[index];
let tLen;
if(tLen = Math.abs(Vec2.distance(player.v2World,role.v2World)) < len){
enumy = role;
len = tLen;
}
}
return enumy;
}else{
return null;
}
}

View File

@@ -1,9 +1,17 @@
import { app } from "../App";
import ResourceData from "../data/ResourceData";
import { GUI } from "../ui/UIConfig";
//接受到JSON消息
export const RData = (data:any,isTips:boolean = true) => {
if(data.data.state == 200){
//如果有 Resource 字段 表示要刷新资源
if(data.data['resources']){
//刷新资源
data.data['resources'].forEach(res => {
ResourceData.getIns().onUpdateOV(res.operation,res.resource);
})
}
return data.data.data;
}else{
//弹出提示
@@ -68,6 +76,13 @@ export interface PlayerTacticalOV{
playerId:number, //玩家Id
tacticalData:string, //阵法数据
}
//玩家资源
export interface ResourceOV{
resourceId:number; //资源Id
playerId:number; //玩家Id
resourceTbId:number; //资源配置表Id
resourceValue:number; //资源数量
}
export const API = {
@@ -86,5 +101,9 @@ export const API = {
/********** 阵法接口 ******************/
GetPlayerTactical: async () => RData(await app.api.get(`/game/tactical/get`),false) as PlayerTacticalOV, //获取玩家阵法
SetPlayerTactical: async (data:PlayerTacticalOV) => RData(await app.api.post(`/game/tactical/set`,data),false) as PlayerTacticalOV, //更新玩家阵法
/********** 资源接口 ******************/
GetPlayerResource: async () => RData(await app.api.get(`/game/resource/get`),false) as ResourceOV[], //获取玩家资源
}

View File

@@ -10,5 +10,7 @@ export const GAPI = {
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'}),GActionType.GOnHookPets) as GOnHookPets,
//捕捉野怪
GOnHookCatchCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onCatchCreeps/${creepId}`)) as PlayerPetOV,
//出售野怪
GOnHookSellCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onSellCreeps/${creepId}`)),
}

View 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)
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7d3c75f4-37fd-4009-baab-1fcc2430b739",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -74,7 +74,7 @@ export default class GOnHookManager extends Singleton{
let index;
if((index = this.killSreeps.indexOf(creeps)) < 0){
app.layer.Open(GUI.Tips,{text:"不可捕捉该宠物"});
app.layer.Open(GUI.Tips,{text:"不可捕捉该野怪"});
return false;
}
@@ -95,6 +95,25 @@ export default class GOnHookManager extends Singleton{
}
//出售野怪
async onSellCreeps(creeps:GOnHookPet):Promise<boolean>{
let index;
if((index = this.killSreeps.indexOf(creeps)) < 0){
app.layer.Open(GUI.Tips,{text:"不可出售当前野怪"});
return false;
}
//删除
this.killSreeps.splice(index,1);
//通知添加野怪被删除
app.event.emit(GOnHookManagerEvent.DEL_KILL_SREEP,creeps);
return await GAPI.GOnHookSellCreeps(creeps.key);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a2e6e211-4b26-493c-85ba-38c5a9f2c614",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,43 @@
import { Label } from 'cc';
import { _decorator, Component, Node } from 'cc';
import ResourceData, { ResourceEvent, ResourceType } from '../../../data/ResourceData';
import { Enum } from 'cc';
import { app } from '../../../App';
const { ccclass, property } = _decorator;
@ccclass('PlayerResourceShow')
export class PlayerResourceShow extends Component {
//显示的资源
@property({type:Enum(ResourceType)})
type:ResourceType = ResourceType.Gold;
//显示文本
@property(Label)
show:Label;
protected onLoad(): void {
//更新
this.onUpdateView();
//监听
app.event.on(ResourceEvent.UPDATE,this.onUpdateView,this);
}
protected onDestroy(): void {
app.event.off(ResourceEvent.UPDATE,this.onUpdateView,this);
}
//刷新
onUpdateView(){
//更新资源数量
this.show.string = `${ResourceData.getIns().getValue(this.type)}`;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "dd6ffde0-3461-40cc-a793-9463cad639f1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -41,11 +41,13 @@ export class MainSreepsList extends Component {
//添加野怪
onAddSreep(sreep:GOnHookPet){
this.views.addData(sreep);
this.onUpdateView();
}
//删除野怪
onDelSreep(sreep:GOnHookPet){
this.views.delData(sreep);
this.onUpdateView();
}
//刷新
@@ -86,6 +88,22 @@ export class MainSreepsList extends Component {
app.layer.Open(GUI.Tips,{text:"捕捉成功!"});
}
//野怪出售
async onClickSell(){
//获取选中的野怪
let item = this.views.getItems<MainSreepsIcon>()[this.index];
if(!item){
app.layer.Open(GUI.Tips,{text:"请选择需要出售的宠物"});
return;
}
if(await GOnHookManager.getIns().onSellCreeps(item.data))
app.layer.Open(GUI.Tips,{text:"出售成功!"});
}
}