mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-08-11 09:49:11 +00:00
更新升级请求 摸鱼的一天~~~
This commit is contained in:
parent
088e91a32b
commit
4c47969828
@ -2,6 +2,7 @@ import SystemBase from "../../extensions/ngame/assets/ngame/system/SystemBase";
|
|||||||
import { app } from "./App";
|
import { app } from "./App";
|
||||||
import BaseData from "./data/BaseData";
|
import BaseData from "./data/BaseData";
|
||||||
import ChatData from "./data/ChatData";
|
import ChatData from "./data/ChatData";
|
||||||
|
import GOnHookData from "./data/GOnHookData";
|
||||||
import PlayerData from "./data/PlayerData";
|
import PlayerData from "./data/PlayerData";
|
||||||
import PlayerPetData from "./data/PlayerPetData";
|
import PlayerPetData from "./data/PlayerPetData";
|
||||||
import PlayerTacticalData from "./data/PlayerTacticalData";
|
import PlayerTacticalData from "./data/PlayerTacticalData";
|
||||||
@ -18,6 +19,7 @@ export class AppData extends SystemBase{
|
|||||||
ChatData.getIns(), //聊天
|
ChatData.getIns(), //聊天
|
||||||
PlayerTacticalData.getIns(), //阵法
|
PlayerTacticalData.getIns(), //阵法
|
||||||
ResourceData.getIns(), //玩家资源
|
ResourceData.getIns(), //玩家资源
|
||||||
|
GOnHookData.getIns(), //无限模式信息类 (无限模式是游戏基础模式玩法 需要默认信息)
|
||||||
];
|
];
|
||||||
|
|
||||||
async onInit(): Promise<any> {
|
async onInit(): Promise<any> {
|
||||||
|
@ -3,9 +3,18 @@ import { app } from "../App";
|
|||||||
import { PlayerPetOV, RData, RProto } from "./API";
|
import { PlayerPetOV, RData, RProto } from "./API";
|
||||||
import { GActionType } from "./GActionType";
|
import { GActionType } from "./GActionType";
|
||||||
|
|
||||||
|
export interface ModeOnHookOV{
|
||||||
|
|
||||||
|
playerId:number; //玩家Id
|
||||||
|
onHookMap:number; //当前玩家所在的地图(配置表Id)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export const GAPI = {
|
export const GAPI = {
|
||||||
|
|
||||||
/************** 无限模式接口 ********************/
|
/************** 无限模式接口 ********************/
|
||||||
|
//获取模式信息
|
||||||
|
GOnHookInfo : async () => RData(await app.api.get(`/game/mode/onHook/info`)) as ModeOnHookOV,
|
||||||
//生成野怪
|
//生成野怪
|
||||||
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'}),GActionType.GOnHookPets) as GOnHookPets,
|
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'}),GActionType.GOnHookPets) as GOnHookPets,
|
||||||
//捕捉野怪
|
//捕捉野怪
|
||||||
|
15
JisolGameCocos/assets/script/data/GOnHookData.ts
Normal file
15
JisolGameCocos/assets/script/data/GOnHookData.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { GAPI, ModeOnHookOV } from "../consts/GAPI";
|
||||||
|
import BaseData from "./BaseData";
|
||||||
|
|
||||||
|
//无限模式数据类
|
||||||
|
export default class GOnHookData extends BaseData{
|
||||||
|
|
||||||
|
info:ModeOnHookOV;
|
||||||
|
|
||||||
|
async onInit() {
|
||||||
|
this.info = await GAPI.GOnHookInfo();
|
||||||
|
console.log("GOnHookData Info",this.info);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
9
JisolGameCocos/assets/script/data/GOnHookData.ts.meta
Normal file
9
JisolGameCocos/assets/script/data/GOnHookData.ts.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "f5a8c28b-dae6-4393-b922-3fbc5097400d",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit cd18e8d3444e584393b0dca23a1c11e0ab3c691f
|
Subproject commit 87cdbc5b91be3f46c06c6a647ed9cf3525a009eb
|
@ -5,8 +5,9 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.retry.annotation.EnableRetry;
|
||||||
|
|
||||||
|
@EnableRetry
|
||||||
@MapperScan(basePackages = "cn.jisol.game.mapper")
|
@MapperScan(basePackages = "cn.jisol.game.mapper")
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class JGameApplication {
|
public class JGameApplication {
|
||||||
|
@ -18,6 +18,13 @@ public class HTTPExceptionHandler {
|
|||||||
return NewsContext.onMessage("Token 失效",null,LOGIN_TOKEN);
|
return NewsContext.onMessage("Token 失效",null,LOGIN_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//材料不够
|
||||||
|
@ExceptionHandler(value = ResourceNotException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public NewsContext<String> retryExceptionHandler(ResourceNotException e){
|
||||||
|
return NewsContext.onFail("材料不够.");
|
||||||
|
}
|
||||||
|
|
||||||
//并发异常
|
//并发异常
|
||||||
@ExceptionHandler(value = RetryException.class)
|
@ExceptionHandler(value = RetryException.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package cn.jisol.game.controller.exception;
|
||||||
|
|
||||||
|
public class ResourceNotException extends RuntimeException{
|
||||||
|
public ResourceNotException() {
|
||||||
|
}
|
||||||
|
public ResourceNotException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -62,7 +62,6 @@ public class GPlayerPetController {
|
|||||||
@ApiOperation(value = "提升宠物星")
|
@ApiOperation(value = "提升宠物星")
|
||||||
@PostMapping("/up/star")
|
@PostMapping("/up/star")
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(value = RetryException.class)
|
|
||||||
public NewsResource<PlayerPet> onUpStar(@RequestBody PetUpStarOV info, @CurrentPlayer Player player){
|
public NewsResource<PlayerPet> onUpStar(@RequestBody PetUpStarOV info, @CurrentPlayer Player player){
|
||||||
|
|
||||||
//判断参数
|
//判断参数
|
||||||
@ -132,7 +131,6 @@ public class GPlayerPetController {
|
|||||||
@ApiOperation(value = "提升宠物等级")
|
@ApiOperation(value = "提升宠物等级")
|
||||||
@PostMapping("/up/level/{petId}")
|
@PostMapping("/up/level/{petId}")
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(value = RetryException.class)
|
|
||||||
public NewsResource<PlayerPet> onUpLevel(@PathVariable Integer petId, @CurrentPlayer Player player){
|
public NewsResource<PlayerPet> onUpLevel(@PathVariable Integer petId, @CurrentPlayer Player player){
|
||||||
|
|
||||||
//整理刷新数据
|
//整理刷新数据
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.jisol.game.controller.game.mode;
|
package cn.jisol.game.controller.game.mode;
|
||||||
|
|
||||||
|
import cfg.TB.TbGOnHookMaps;
|
||||||
import cfg.TB.TbGRole;
|
import cfg.TB.TbGRole;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
|
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
|
||||||
@ -9,7 +10,9 @@ import cn.jisol.game.data.TD;
|
|||||||
import cn.jisol.game.entity.game.Player;
|
import cn.jisol.game.entity.game.Player;
|
||||||
import cn.jisol.game.entity.game.PlayerPet;
|
import cn.jisol.game.entity.game.PlayerPet;
|
||||||
import cn.jisol.game.entity.game.Resource;
|
import cn.jisol.game.entity.game.Resource;
|
||||||
|
import cn.jisol.game.entity.mode.ModeOnHook;
|
||||||
import cn.jisol.game.proto.GOnHookMessage;
|
import cn.jisol.game.proto.GOnHookMessage;
|
||||||
|
import cn.jisol.game.service.ModeOnHookService;
|
||||||
import cn.jisol.game.service.PlayerPetService;
|
import cn.jisol.game.service.PlayerPetService;
|
||||||
import cn.jisol.game.service.ResourceService;
|
import cn.jisol.game.service.ResourceService;
|
||||||
import cn.jisol.game.vo.news.NewsResource;
|
import cn.jisol.game.vo.news.NewsResource;
|
||||||
@ -22,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.retry.RetryException;
|
import org.springframework.retry.RetryException;
|
||||||
|
import org.springframework.retry.annotation.Retryable;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -40,10 +44,40 @@ public class GOnHookController {
|
|||||||
PlayerPetService playerPetService;
|
PlayerPetService playerPetService;
|
||||||
@Autowired
|
@Autowired
|
||||||
ResourceService resourceService;
|
ResourceService resourceService;
|
||||||
|
@Autowired
|
||||||
|
ModeOnHookService modeOnHookService;
|
||||||
|
|
||||||
//生成的野怪列表
|
//生成的野怪列表
|
||||||
public static Map<Long, Map<String, GOnHookMessage.GOnHookPet>> CREEPS = new HashMap<>();
|
public static Map<Long, Map<String, GOnHookMessage.GOnHookPet>> CREEPS = new HashMap<>();
|
||||||
|
|
||||||
|
//获取玩家模式信息
|
||||||
|
@ApiImplicitParams({})
|
||||||
|
@ApiOperation(value = "生成野怪")
|
||||||
|
@GetMapping("/info")
|
||||||
|
@Retryable(value = RetryException.class)
|
||||||
|
public NewsContext<ModeOnHook> getInfo(@CurrentPlayer Player player){
|
||||||
|
|
||||||
|
ModeOnHook info = modeOnHookService.getById(player.getPlayerId());
|
||||||
|
|
||||||
|
//如果没有信息则初始化默认信息
|
||||||
|
if(Objects.isNull(info)){
|
||||||
|
//获取第一个地图
|
||||||
|
TbGOnHookMaps oneMapInfo = TD.DATA.getTbGOnHookMaps().getDataList().get(0);
|
||||||
|
if(Objects.isNull(oneMapInfo)){
|
||||||
|
return NewsResource.onFail("获取信息失败 没有地图信息");
|
||||||
|
}
|
||||||
|
modeOnHookService.save(ModeOnHook.builder()
|
||||||
|
.playerId(player.getPlayerId())
|
||||||
|
.onHookMap(oneMapInfo.id)
|
||||||
|
.build());
|
||||||
|
//并且重试获取
|
||||||
|
throw new RetryException("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewsContext.onSuccess("获取成功",info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//生成野怪
|
//生成野怪
|
||||||
@ApiImplicitParams({})
|
@ApiImplicitParams({})
|
||||||
@ApiOperation(value = "生成野怪")
|
@ApiOperation(value = "生成野怪")
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package cn.jisol.game.entity.mode;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家 无限模式(OnHook) 信息
|
||||||
|
*/
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@TableName("`mode_on_hook`")
|
||||||
|
public class ModeOnHook {
|
||||||
|
|
||||||
|
@TableId(type = IdType.INPUT)
|
||||||
|
private Long playerId; //玩家Id
|
||||||
|
private Integer onHookMap; //当前玩家所在的地图(配置表Id)
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package cn.jisol.game.mapper;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.game.Player;
|
||||||
|
import cn.jisol.game.entity.mode.ModeOnHook;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface ModeOnHookMapper extends BaseMapper<ModeOnHook> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package cn.jisol.game.service;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.mode.ModeOnHook;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
public interface ModeOnHookService extends IService<ModeOnHook> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.mode.ModeOnHook;
|
||||||
|
import cn.jisol.game.mapper.ModeOnHookMapper;
|
||||||
|
import cn.jisol.game.service.ModeOnHookService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ModeOnHookServiceImpl extends ServiceImpl<ModeOnHookMapper, ModeOnHook> implements ModeOnHookService {
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package cn.jisol.game.service.impl;
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cn.jisol.game.controller.exception.ResourceNotException;
|
||||||
import cn.jisol.game.data.ResourceId;
|
import cn.jisol.game.data.ResourceId;
|
||||||
import cn.jisol.game.entity.game.Player;
|
import cn.jisol.game.entity.game.Player;
|
||||||
import cn.jisol.game.entity.game.Resource;
|
import cn.jisol.game.entity.game.Resource;
|
||||||
import cn.jisol.game.mapper.ResourceMapper;
|
import cn.jisol.game.mapper.ResourceMapper;
|
||||||
import cn.jisol.game.service.ResourceService;
|
import cn.jisol.game.service.ResourceService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.retry.RetryException;
|
import org.springframework.retry.RetryException;
|
||||||
@ -24,53 +26,48 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Retryable(value = RetryException.class)
|
@Retryable(RetryException.class)
|
||||||
public Resource addResourceValue(Long playerId, int type, Long value) {
|
public Resource addResourceValue(Long playerId, int type, Long value) {
|
||||||
|
|
||||||
//获取玩家资源
|
|
||||||
|
LambdaUpdateWrapper<Resource> eq = Wrappers.lambdaUpdate(Resource.class)
|
||||||
|
.eq(Resource::getPlayerId, playerId) //玩家
|
||||||
|
.eq(Resource::getResourceTbId, type);//资源
|
||||||
|
|
||||||
|
if(value < 0) {
|
||||||
|
eq.gt(Resource::getResourceValue,Math.abs(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
//执行SQL
|
||||||
|
boolean update = this.update(
|
||||||
|
eq.setSql("version = version + 1,resource_value = resource_value + " + value)
|
||||||
|
);
|
||||||
|
|
||||||
|
//查询货币数量
|
||||||
Resource res = this.getOne(
|
Resource res = this.getOne(
|
||||||
Wrappers.lambdaQuery(Resource.class)
|
Wrappers.lambdaQuery(Resource.class)
|
||||||
.eq(Resource::getPlayerId, playerId) //玩家
|
.eq(Resource::getPlayerId, playerId) //玩家
|
||||||
.eq(Resource::getResourceTbId, type) //资源
|
.eq(Resource::getResourceTbId, type) //资源
|
||||||
);
|
);
|
||||||
|
|
||||||
//如果没有资源则默认给一个0的资源
|
if(!update){
|
||||||
if(Objects.isNull(res)){
|
if(Objects.isNull(res)){
|
||||||
//创建初始资源
|
//没有资源信息 创建初始资源
|
||||||
res = this.initResource(playerId,type);
|
res = this.initResource(playerId,type);
|
||||||
}
|
//并且重试
|
||||||
|
|
||||||
if(value > 0){
|
|
||||||
|
|
||||||
//如果是累加 则 执行累加sql
|
|
||||||
if(this.update(
|
|
||||||
Wrappers.lambdaUpdate(Resource.class)
|
|
||||||
.eq(Resource::getPlayerId, playerId) //玩家
|
|
||||||
.eq(Resource::getResourceTbId, type) //资源
|
|
||||||
.setSql("version = version + 1,resource_value = resource_value + "+value)
|
|
||||||
)){
|
|
||||||
//添加资源
|
|
||||||
res.setResourceValue(res.getResourceValue() + value);
|
|
||||||
return res;
|
|
||||||
}else{
|
|
||||||
throw new RetryException("");
|
throw new RetryException("");
|
||||||
|
}else{
|
||||||
|
//更新失败 材料不够
|
||||||
|
throw new ResourceNotException("资源不够");
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//添加资源
|
|
||||||
res.setResourceValue(res.getResourceValue() + value);
|
|
||||||
|
|
||||||
if(res.getResourceValue() <= 0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//保存资源 (保存失败重试)
|
|
||||||
if (!this.saveOrUpdate(res)) throw new RetryException("");
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果资源不够则报错
|
||||||
|
if(res.getResourceValue() < 0) throw new ResourceNotException("资源不够");
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化某个资源
|
//初始化某个资源
|
||||||
@ -83,7 +80,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource initResource(Resource resource) {
|
public Resource initResource(Resource resource) {
|
||||||
this.saveOrUpdate(resource);
|
this.save(resource);
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user