2023-11-08 02:32:54 +08:00
|
|
|
import { app } from "../App";
|
2023-11-27 02:10:42 +08:00
|
|
|
import PlayerPetData from "../data/PlayerPetData";
|
2023-11-20 03:47:00 +08:00
|
|
|
import ResourceData from "../data/ResourceData";
|
2023-11-08 02:32:54 +08:00
|
|
|
import { GUI } from "../ui/UIConfig";
|
|
|
|
|
2023-11-17 18:29:39 +08:00
|
|
|
//接受到JSON消息
|
|
|
|
export const RData = (data:any,isTips:boolean = true) => {
|
2023-11-08 02:32:54 +08:00
|
|
|
if(data.data.state == 200){
|
2023-11-20 03:47:00 +08:00
|
|
|
//如果有 Resource 字段 表示要刷新资源
|
|
|
|
if(data.data['resources']){
|
|
|
|
//刷新资源
|
|
|
|
data.data['resources'].forEach(res => {
|
2023-11-27 02:10:42 +08:00
|
|
|
ResourceData.getIns().onUpdateOV(res.operation,res.resource); //刷新资源
|
|
|
|
PlayerPetData.getIns().onUpdateOV(res.operation,res.pet); //刷新宠物
|
2023-11-20 03:47:00 +08:00
|
|
|
})
|
|
|
|
}
|
2023-11-08 02:32:54 +08:00
|
|
|
return data.data.data;
|
|
|
|
}else{
|
|
|
|
//弹出提示
|
2023-11-10 03:56:07 +08:00
|
|
|
if(isTips){
|
|
|
|
app.layer.Open(GUI.Tips,{text:data.data.msg});
|
|
|
|
}
|
|
|
|
return data.data.data;
|
2023-11-08 02:32:54 +08:00
|
|
|
}
|
|
|
|
}
|
2023-11-17 18:29:39 +08:00
|
|
|
//接受到Protobuf
|
|
|
|
export const RProto = (data:any,type:string) => {
|
|
|
|
|
|
|
|
try{
|
|
|
|
return app.proto
|
|
|
|
.getType(type)
|
|
|
|
.decode(new Uint8Array(data.data)) as any;;
|
|
|
|
}catch{
|
|
|
|
app.layer.Open(GUI.Tips,{text:"Protobuf 解析失败"});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-11-08 02:32:54 +08:00
|
|
|
|
2023-11-15 18:38:00 +08:00
|
|
|
/************** 请求类 *******************/
|
2023-11-09 04:22:04 +08:00
|
|
|
export interface NewsContext{
|
|
|
|
state:number,
|
|
|
|
msg:string,
|
|
|
|
data:any,
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
//玩家登录返回
|
|
|
|
export interface UserLoginVO{
|
|
|
|
token:string, //token
|
|
|
|
user:UserVO, //玩家信息
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************** 实体类 **************************/
|
|
|
|
|
|
|
|
//玩家信息
|
2023-11-08 02:32:54 +08:00
|
|
|
export interface UserVO{
|
|
|
|
userId:number, //玩家Id
|
|
|
|
userName:string, //玩家名称
|
|
|
|
userPass:string, //玩家密码
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
//游戏玩家信息
|
2023-11-10 03:56:07 +08:00
|
|
|
export interface PlayerInfoOV{
|
|
|
|
playerId:number, //玩家Id
|
|
|
|
userId: number, //用户Id
|
|
|
|
playerName:string, //玩家名
|
|
|
|
playerCreateTime:number, //玩家创建时间
|
|
|
|
novice: false, //是否过引导
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
//玩家宠物信息
|
2023-11-13 02:37:29 +08:00
|
|
|
export interface PlayerPetOV{
|
|
|
|
petId:number, //宠物唯一Id
|
|
|
|
petPlayerId:number; //宠物的玩家Id
|
|
|
|
petTbId:number; //宠物配置表Id
|
|
|
|
petGrade:number; //宠物等级
|
2023-11-26 03:06:23 +08:00
|
|
|
petStar:number; //宠物星级
|
|
|
|
petStarExp:number; //宠物星级经验
|
2023-11-13 02:37:29 +08:00
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
//玩家阵法信息
|
|
|
|
export interface PlayerTacticalOV{
|
|
|
|
playerId:number, //玩家Id
|
|
|
|
tacticalData:string, //阵法数据
|
|
|
|
}
|
2023-11-20 03:47:00 +08:00
|
|
|
//玩家资源
|
|
|
|
export interface ResourceOV{
|
|
|
|
resourceId:number; //资源Id
|
|
|
|
playerId:number; //玩家Id
|
|
|
|
resourceTbId:number; //资源配置表Id
|
|
|
|
resourceValue:number; //资源数量
|
|
|
|
}
|
2023-11-08 02:32:54 +08:00
|
|
|
|
|
|
|
export const API = {
|
|
|
|
|
2023-11-10 03:56:07 +08:00
|
|
|
UserRegister : async () => RData(await app.api.post(`/user/register`)) as UserVO, //玩家注册
|
|
|
|
UserLogin : async (account:string,password:string) => RData(await app.api.post(`/user/login`,{userId:account,userPass:password})) as UserLoginVO, //玩家登录
|
2023-11-13 02:37:29 +08:00
|
|
|
GetPlayerInfo : async () => RData(await app.api.get(`/game/player/info`),false) as PlayerInfoOV, //获取玩家信息
|
2023-11-10 03:56:07 +08:00
|
|
|
|
|
|
|
/********** 新手引导接口 *****************/
|
|
|
|
SavePlayerInfo : async (playerName:string,novice:boolean = true) => (await app.api.post(`/game/player/info/save`,{playerName,novice})).data as NewsContext, //保存玩家信息
|
2023-11-13 02:37:29 +08:00
|
|
|
SelectNovicePet: async (petId:number) => RData(await app.api.post(`/game/novice/select/${petId}`),true), //选择新手引导宠物
|
|
|
|
|
2023-11-08 02:32:54 +08:00
|
|
|
|
2023-11-13 02:37:29 +08:00
|
|
|
/********** 宠物接口 ******************/
|
2023-11-26 03:06:23 +08:00
|
|
|
GetPlayerPets: async () => RData(await app.api.get(`/game/pet/list`),false) as PlayerPetOV[], //获取玩家全部宠物
|
|
|
|
//petId 需合成的Id pets 被合成的Id列表
|
|
|
|
PetUpStar: async (petId:number,pets:number[]) => RData(await app.api.post(`/game/pet/up/star`,{petId,pets}),true) as PlayerPetOV, //提升宠物星
|
2023-11-15 18:38:00 +08:00
|
|
|
|
|
|
|
/********** 阵法接口 ******************/
|
|
|
|
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, //更新玩家阵法
|
2023-11-20 03:47:00 +08:00
|
|
|
|
|
|
|
/********** 资源接口 ******************/
|
|
|
|
GetPlayerResource: async () => RData(await app.api.get(`/game/resource/get`),false) as ResourceOV[], //获取玩家资源
|
|
|
|
|
2023-11-08 02:32:54 +08:00
|
|
|
}
|
|
|
|
|