资源刷新 以及 出售

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

Binary file not shown.

Binary file not shown.

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();
}
//刷新
@ -87,6 +89,22 @@ export class MainSreepsList extends Component {
}
//野怪出售
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:"出售成功!"});
}
}

@ -1 +1 @@
Subproject commit 1943c6992fd3f7269e7a08b174cdf5e49028c074
Subproject commit be42908eaecd47d952a79d2f1549bd0dd4176765

@ -1 +1 @@
Subproject commit a57971eceadfcc80e06934e75a7dee7469fb10a1
Subproject commit f3c05c98992ccc4c4bc45ca120b3fcaf5ff6af58

View File

@ -0,0 +1,55 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg.TB;
import luban.*;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public final class TbGResource extends AbstractBean {
public TbGResource(JsonObject _buf) {
id = _buf.get("id").getAsInt();
name = _buf.get("name").getAsString();
tig = _buf.get("tig").getAsString();
}
public static TbGResource deserialize(JsonObject _buf) {
return new cfg.TB.TbGResource(_buf);
}
/**
* id
*/
public final int id;
/**
* 资源名称
*/
public final String name;
/**
* 描述
*/
public final String tig;
public static final int __ID__ = 1780642599;
@Override
public int getTypeId() { return __ID__; }
@Override
public String toString() {
return "{ "
+ "(format_field_name __code_style field.name):" + id + ","
+ "(format_field_name __code_style field.name):" + name + ","
+ "(format_field_name __code_style field.name):" + tig + ","
+ "}";
}
}

View File

@ -33,6 +33,8 @@ public final class Tables
public cfg.TbGMap getTbGMap() { return _tbgmap; }
private final cfg.TbGOnHookGlobal _tbgonhookglobal;
public cfg.TbGOnHookGlobal getTbGOnHookGlobal() { return _tbgonhookglobal; }
private final cfg.TbGResource _tbgresource;
public cfg.TbGResource getTbGResource() { return _tbgresource; }
public Tables(IJsonLoader loader) throws java.io.IOException {
_tbgglobal = new cfg.TbGGlobal(loader.load("tbgglobal"));
@ -42,6 +44,7 @@ public final class Tables
_tbgroleskill = new cfg.TbGRoleSkill(loader.load("tbgroleskill"));
_tbgmap = new cfg.TbGMap(loader.load("tbgmap"));
_tbgonhookglobal = new cfg.TbGOnHookGlobal(loader.load("tbgonhookglobal"));
_tbgresource = new cfg.TbGResource(loader.load("tbgresource"));
}
}

View File

@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg;
import luban.*;
import com.google.gson.JsonElement;
public final class TbGResource {
private final java.util.HashMap<Integer, cfg.TB.TbGResource> _dataMap;
private final java.util.ArrayList<cfg.TB.TbGResource> _dataList;
public TbGResource(JsonElement _buf) {
_dataMap = new java.util.HashMap<Integer, cfg.TB.TbGResource>();
_dataList = new java.util.ArrayList<cfg.TB.TbGResource>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
cfg.TB.TbGResource _v;
_v = cfg.TB.TbGResource.deserialize(_e_.getAsJsonObject());
_dataList.add(_v);
_dataMap.put(_v.id, _v);
}
}
public java.util.HashMap<Integer, cfg.TB.TbGResource> getDataMap() { return _dataMap; }
public java.util.ArrayList<cfg.TB.TbGResource> getDataList() { return _dataList; }
public cfg.TB.TbGResource get(int key) { return _dataMap.get(key); }
}

View File

@ -1,10 +1,9 @@
package cn.jisol.game.controller.game;
import cfg.TB.TbGGlobal;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
import cn.jisol.game.data.GlobalIds;
import cn.jisol.game.data.GlobalId;
import cn.jisol.game.data.TD;
import cn.jisol.game.entity.game.Player;
import cn.jisol.game.entity.game.PlayerPet;
@ -17,7 +16,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -38,7 +36,7 @@ public class GNoviceController {
if(Objects.isNull(petId)) return NewsContext.onFail("请选择宠物");
//判断选择的宠物是否在配置表中
TbGGlobal info = TD.DATA.getTbGGlobal().get(GlobalIds.SELECT_PET_ID);
TbGGlobal info = TD.DATA.getTbGGlobal().get(GlobalId.SELECT_PET_ID);
//判断选择的宠物是否在其中
List<Integer> ids = JSONUtil.toList(info.args, Integer.class);
if (!ids.contains(petId)) return NewsContext.onFail("不可选择这个宠物!");

View File

@ -0,0 +1,50 @@
package cn.jisol.game.controller.game;
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
import cn.jisol.game.entity.game.Player;
import cn.jisol.game.entity.game.PlayerTactical;
import cn.jisol.game.entity.game.Resource;
import cn.jisol.game.service.ResourceService;
import cn.jisol.ngame.util.NewsContext;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Wrapper;
import java.util.List;
/**
* 资源
*/
@Api(value = "JNGameDemo - API", tags = {"资源 - API"})
@RestController
@RequestMapping("/game/resource")
@ResponseBody
public class GResourceController {
@Autowired
ResourceService resourceService;
//获取玩家的资源
@ApiImplicitParams({})
@ApiOperation(value = "获取玩家的资源")
@GetMapping("/get")
public NewsContext<List<Resource>> getInfo(@CurrentPlayer Player player){
//获取玩家全部资源列表
List<Resource> list = resourceService.list(
Wrappers.lambdaQuery(Resource.class)
.eq(Resource::getPlayerId, player.getPlayerId())
);
return NewsContext.onSuccess("获取成功",list);
}
}

View File

@ -3,15 +3,19 @@ package cn.jisol.game.controller.game.mode;
import cfg.TB.TbGRole;
import cn.hutool.core.util.RandomUtil;
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
import cn.jisol.game.data.GlobalIds;
import cn.jisol.game.data.GlobalId;
import cn.jisol.game.data.ResourceId;
import cn.jisol.game.data.TD;
import cn.jisol.game.entity.game.Player;
import cn.jisol.game.entity.game.PlayerPet;
import cn.jisol.game.entity.game.Resource;
import cn.jisol.game.proto.GOnHookMessage;
import cn.jisol.game.service.PlayerPetService;
import cn.jisol.game.service.ResourceService;
import cn.jisol.game.vo.news.NewsResource;
import cn.jisol.game.vo.news.ov.ResourceUpdateOV;
import cn.jisol.ngame.util.NewsContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +36,8 @@ public class GOnHookController {
@Autowired
PlayerPetService playerPetService;
@Autowired
ResourceService resourceService;
//生成的野怪列表
public static Map<Long, Map<String, GOnHookMessage.GOnHookPet>> CREEPS = new HashMap<>();
@ -54,7 +60,7 @@ public class GOnHookController {
}
//获取可生成的最大数量
int max = Integer.parseInt(TD.DATA.getTbGOnHookGlobal().get(GlobalIds.MODE_ON_HOOK_SPAWN_NUM).args);
int max = Integer.parseInt(TD.DATA.getTbGOnHookGlobal().get(GlobalId.MODE_ON_HOOK_SPAWN_NUM).args);
//获取配置表全部宠物
ArrayList<TbGRole> tdPets = TD.DATA.getTbGRole().getDataList();
@ -83,8 +89,25 @@ public class GOnHookController {
@ApiImplicitParams({})
@ApiOperation(value = "出售野怪")
@PostMapping("/onSellCreeps/{creepId}")
public NewsContext<Boolean> onSellCreeps(@PathVariable String creepId){
return NewsContext.onSuccess("卖出成功");
public NewsResource<Boolean> onSellCreeps(@PathVariable String creepId, @CurrentPlayer Player player){
//玩家的野怪
Map<String, GOnHookMessage.GOnHookPet> creeps;
//找到野怪删除
if(Objects.isNull(creeps = CREEPS.get(player.getPlayerId()))) return NewsResource.onFail("卖出失败",false);
if(Objects.nonNull(creeps.remove(creepId))){
//增加玩家金币 (默认添加100)
Resource res = resourceService.addResourceValue(player.getPlayerId(), ResourceId.Gold, 100L);
return NewsResource.onSuccess(
"卖出成功",
true,
ResourceUpdateOV.onUpdate(res) //更新金币
);
}else{
return NewsResource.onFail("卖出失败",false);
}
}
//捕捉野怪

View File

@ -1,11 +1,10 @@
package cn.jisol.game.data;
public interface GlobalIds {
public interface GlobalId {
//选择宠物配置表Id
int SELECT_PET_ID = 70001;
//OnHook模式 宠物生成数量
int MODE_ON_HOOK_SPAWN_NUM = 80001;

View File

@ -0,0 +1,14 @@
package cn.jisol.game.data;
public enum ResourceId {
//金币资源
Gold(90001),
;
public int id;
ResourceId(int id) {
this.id = id;
}
}

View File

@ -0,0 +1,23 @@
package cn.jisol.game.entity.game;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder;
import lombok.Data;
/**
* 资源类
*/
@Builder
@Data
@TableName("`resource`")
public class Resource {
@TableId(type = IdType.AUTO)
private Long resourceId; //资源Id
private Long playerId; //玩家Id
private int resourceTbId; //资源配置表Id
private Long resourceValue; //资源数量
}

View File

@ -0,0 +1,11 @@
package cn.jisol.game.mapper;
import cn.jisol.game.entity.game.Player;
import cn.jisol.game.entity.game.Resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Component;
@Component
public interface ResourceMapper extends BaseMapper<Resource> {
}

View File

@ -0,0 +1,17 @@
package cn.jisol.game.service;
import cn.jisol.game.data.ResourceId;
import cn.jisol.game.entity.game.PlayerPet;
import cn.jisol.game.entity.game.Resource;
import com.baomidou.mybatisplus.extension.service.IService;
public interface ResourceService extends IService<Resource> {
//添加某个资源的数量
public Resource addResourceValue(Long playerId, ResourceId type, Long value);
//初始化某个资源
public Resource initResource(Long playerId, ResourceId type);
public Resource initResource(Resource resource);
}

View File

@ -0,0 +1,63 @@
package cn.jisol.game.service.impl;
import cn.jisol.game.data.ResourceId;
import cn.jisol.game.entity.game.Player;
import cn.jisol.game.entity.game.Resource;
import cn.jisol.game.mapper.ResourceMapper;
import cn.jisol.game.service.ResourceService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {
/**
* @param playerId 玩家Id
* @param type 资源类型
* @param value 添加的数量
* @return
*/
@Override
public Resource addResourceValue(Long playerId, ResourceId type, Long value) {
//获取玩家资源
Resource res = this.getOne(
Wrappers.lambdaQuery(Resource.class)
.eq(Resource::getPlayerId, playerId) //玩家
.eq(Resource::getResourceTbId, type.id) //资源
);
//如果没有资源则默认给一个0的资源
if(Objects.isNull(res)){
//创建初始资源
res = this.initResource(playerId,type);
}
//添加资源
res.setResourceValue(res.getResourceValue() + value);
//保存资源
this.saveOrUpdate(res);
return res;
}
//初始化某个资源
@Override
public Resource initResource(Long playerId, ResourceId type) {
Resource resource = Resource.builder().playerId(playerId).resourceTbId(type.id).resourceValue(0L).build();
this.initResource(resource);
return resource;
}
@Override
public Resource initResource(Resource resource) {
this.saveOrUpdate(resource);
return resource;
}
}

View File

@ -0,0 +1,53 @@
package cn.jisol.game.vo.news;
import cn.jisol.game.entity.game.Resource;
import cn.jisol.game.vo.news.ov.ResourceUpdateOV;
import cn.jisol.ngame.util.NewsContext;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.Builder;
import lombok.experimental.SuperBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
//返回带资源更新的消息
@SuperBuilder
@ApiResponses({
@ApiResponse(code = 200,message = "成功"),
@ApiResponse(code = 500,message = "失败"),
})
public class NewsResource<T> extends NewsContext<T> {
//资源刷新
public List<ResourceUpdateOV> resources = new ArrayList<>();
//添加一个刷新资源数据
public void addUpdateResource(Resource resource){
this.resources.add(ResourceUpdateOV.onUpdate(resource));
}
public static <T> NewsResource<T> onSuccess(String msg){
return onMessage(msg,null,NEWS_STATE_SUCCESS,new ArrayList<>());
}
public static <T> NewsResource<T> onSuccess(String msg,T data){
return onMessage(msg,data,NEWS_STATE_SUCCESS,new ArrayList<>());
}
public static <T> NewsResource<T> onSuccess(String msg,T data,ResourceUpdateOV... resource){
return onMessage(msg,data,NEWS_STATE_SUCCESS, Arrays.asList(resource));
}
public static <T> NewsResource<T> onFail(String msg){
return onMessage(msg,null,NEWS_STATE_FAIL,new ArrayList<>());
}
public static <T> NewsResource<T> onFail(String msg, T data){
return onMessage(msg,data,NEWS_STATE_FAIL,new ArrayList<>());
}
public static <T> NewsResource<T> onMessage(String msg, T data, Integer state,List<ResourceUpdateOV> resource){
return (NewsResource<T>) NewsResource.builder().state(state).msg(msg).data(data).resources(resource).build();
}
}

View File

@ -0,0 +1,29 @@
package cn.jisol.game.vo.news.ov;
import cn.jisol.game.entity.game.Resource;
import lombok.Builder;
import lombok.Data;
//资源更新类
@Builder
@Data
public class ResourceUpdateOV {
Resource resource;
//操作
int operation = 0;
//资源更新类型
public interface ResourceUpdateType{
static int UPDATE = 0; //刷新资源数量
static int MINUS = 1; //减少资源数量
static int ADD = 2; //添加资源数量
}
//返回一个刷新的资源更新类
public static ResourceUpdateOV onUpdate(Resource resource){
return ResourceUpdateOV.builder().operation(ResourceUpdateType.UPDATE).resource(resource).build();
}
}

View File

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