mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
提交新手引导
This commit is contained in:
Submodule JisolGameServer/JNGame updated: f3a45363ca...fe5330b622
55
JisolGameServer/Main/src/main/java/cfg/TB/TbGGlobal.java
Normal file
55
JisolGameServer/Main/src/main/java/cfg/TB/TbGGlobal.java
Normal 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 TbGGlobal extends AbstractBean {
|
||||
public TbGGlobal(JsonObject _buf) {
|
||||
id = _buf.get("id").getAsInt();
|
||||
args = _buf.get("args").getAsString();
|
||||
tig = _buf.get("tig").getAsString();
|
||||
}
|
||||
|
||||
public static TbGGlobal deserialize(JsonObject _buf) {
|
||||
return new cfg.TB.TbGGlobal(_buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
public final int id;
|
||||
/**
|
||||
* 全局表参数
|
||||
*/
|
||||
public final String args;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
public final String tig;
|
||||
|
||||
public static final int __ID__ = 1682089212;
|
||||
|
||||
@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):" + args + ","
|
||||
+ "(format_field_name __code_style field.name):" + tig + ","
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
@@ -19,23 +19,26 @@ public final class Tables
|
||||
JsonElement load(String file) throws java.io.IOException;
|
||||
}
|
||||
|
||||
private final cfg.TbGGlobal _tbgglobal;
|
||||
public cfg.TbGGlobal getTbGGlobal() { return _tbgglobal; }
|
||||
private final cfg.TbGRole _tbgrole;
|
||||
public cfg.TbGRole getTbGRole() { return _tbgrole; }
|
||||
private final cfg.TbGMap _tbgmap;
|
||||
public cfg.TbGMap getTbGMap() { return _tbgmap; }
|
||||
private final cfg.TbGRoleAttack _tbgroleattack;
|
||||
public cfg.TbGRoleAttack getTbGRoleAttack() { return _tbgroleattack; }
|
||||
private final cfg.TbGRoleBattleRes _tbgrolebattleres;
|
||||
public cfg.TbGRoleBattleRes getTbGRoleBattleRes() { return _tbgrolebattleres; }
|
||||
private final cfg.TbGRoleSkill _tbgroleskill;
|
||||
public cfg.TbGRoleSkill getTbGRoleSkill() { return _tbgroleskill; }
|
||||
private final cfg.TbGMap _tbgmap;
|
||||
public cfg.TbGMap getTbGMap() { return _tbgmap; }
|
||||
|
||||
public Tables(IJsonLoader loader) throws java.io.IOException {
|
||||
_tbgglobal = new cfg.TbGGlobal(loader.load("tbgglobal"));
|
||||
_tbgrole = new cfg.TbGRole(loader.load("tbgrole"));
|
||||
_tbgmap = new cfg.TbGMap(loader.load("tbgmap"));
|
||||
_tbgroleattack = new cfg.TbGRoleAttack(loader.load("tbgroleattack"));
|
||||
_tbgrolebattleres = new cfg.TbGRoleBattleRes(loader.load("tbgrolebattleres"));
|
||||
_tbgroleskill = new cfg.TbGRoleSkill(loader.load("tbgroleskill"));
|
||||
_tbgmap = new cfg.TbGMap(loader.load("tbgmap"));
|
||||
}
|
||||
}
|
||||
|
||||
|
37
JisolGameServer/Main/src/main/java/cfg/TbGGlobal.java
Normal file
37
JisolGameServer/Main/src/main/java/cfg/TbGGlobal.java
Normal 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 TbGGlobal {
|
||||
private final java.util.HashMap<Integer, cfg.TB.TbGGlobal> _dataMap;
|
||||
private final java.util.ArrayList<cfg.TB.TbGGlobal> _dataList;
|
||||
|
||||
public TbGGlobal(JsonElement _buf) {
|
||||
_dataMap = new java.util.HashMap<Integer, cfg.TB.TbGGlobal>();
|
||||
_dataList = new java.util.ArrayList<cfg.TB.TbGGlobal>();
|
||||
|
||||
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
|
||||
cfg.TB.TbGGlobal _v;
|
||||
_v = cfg.TB.TbGGlobal.deserialize(_e_.getAsJsonObject());
|
||||
_dataList.add(_v);
|
||||
_dataMap.put(_v.id, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.HashMap<Integer, cfg.TB.TbGGlobal> getDataMap() { return _dataMap; }
|
||||
public java.util.ArrayList<cfg.TB.TbGGlobal> getDataList() { return _dataList; }
|
||||
|
||||
public cfg.TB.TbGGlobal get(int key) { return _dataMap.get(key); }
|
||||
|
||||
}
|
@@ -1,7 +1,10 @@
|
||||
package cn.jisol.game.config;
|
||||
|
||||
import cn.jisol.game.controller.argsresolver.PlayerMethodArgumentResolver;
|
||||
import cn.jisol.game.controller.argsresolver.UserMethodArgumentResolver;
|
||||
import cn.jisol.game.controller.game.GPlayerController;
|
||||
import cn.jisol.game.interceptor.LoginInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
@@ -12,6 +15,9 @@ import java.util.List;
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
GPlayerController playerController;
|
||||
|
||||
/**
|
||||
* 添加登录拦截器
|
||||
* @param registry
|
||||
@@ -26,5 +32,6 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||
WebMvcConfigurer.super.addArgumentResolvers(resolvers);
|
||||
resolvers.add(new UserMethodArgumentResolver());
|
||||
resolvers.add(new PlayerMethodArgumentResolver(this.playerController));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package cn.jisol.game.controller.argsresolver;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface CurrentPlayer {
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package cn.jisol.game.controller.argsresolver;
|
||||
|
||||
import cn.jisol.game.controller.exception.PlayerException;
|
||||
import cn.jisol.game.controller.exception.TokenException;
|
||||
import cn.jisol.game.controller.game.GPlayerController;
|
||||
import cn.jisol.game.data.Cache;
|
||||
import cn.jisol.game.entity.User;
|
||||
import cn.jisol.game.entity.game.Player;
|
||||
import cn.jisol.game.service.impl.PlayerServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class PlayerMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
GPlayerController playerController;
|
||||
|
||||
public PlayerMethodArgumentResolver(GPlayerController playerController) {
|
||||
this.playerController = playerController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
if (parameter.hasParameterAnnotation(CurrentPlayer.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
|
||||
|
||||
//获取Token
|
||||
String token = nativeWebRequest.getHeader(Cache.KEY_TOKEN);
|
||||
User user;
|
||||
Player player;
|
||||
if(Objects.isNull(token) || Objects.isNull(user = Cache.TOKEN.get(token))){
|
||||
//抛出Token异常
|
||||
throw new TokenException();
|
||||
}
|
||||
//获取Player
|
||||
if(Objects.isNull(player = Cache.PLAYER.get(user.getUserId()))){
|
||||
//如果没有数据则向数据库获取
|
||||
player = playerController.getPlayerInfo(user).data;
|
||||
|
||||
if(Objects.isNull(player)){
|
||||
//抛出Token异常
|
||||
throw new TokenException();
|
||||
}else{
|
||||
Cache.PLAYER.put(user.getUserId(),player);
|
||||
}
|
||||
}
|
||||
|
||||
return player;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
package cn.jisol.game.controller.exception;
|
||||
|
||||
public class PlayerException extends Exception{
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
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.TD;
|
||||
import cn.jisol.game.entity.game.Player;
|
||||
import cn.jisol.game.entity.game.PlayerPet;
|
||||
import cn.jisol.game.service.PlayerPetService;
|
||||
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.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Api(value = "JNGameDemo - API", tags = {"新手引导 - API"})
|
||||
@RestController
|
||||
@RequestMapping("/game/novice")
|
||||
@ResponseBody
|
||||
public class GNoviceController {
|
||||
|
||||
@Autowired
|
||||
PlayerPetService playerPetService;
|
||||
|
||||
//选择宠物(前提是玩家没有宠物)
|
||||
@ApiImplicitParams({})
|
||||
@ApiOperation(value = "选择宠物(前提是玩家没有宠物)")
|
||||
@PostMapping("/select/{petId}")
|
||||
public NewsContext<PlayerPet> select(@CurrentPlayer Player player,@PathVariable Integer petId){
|
||||
|
||||
if(Objects.isNull(petId)) return NewsContext.onFail("请选择宠物");
|
||||
//判断选择的宠物是否在配置表中
|
||||
TbGGlobal info = TD.DATA.getTbGGlobal().get(GlobalIds.SELECT_PET_ID);
|
||||
//判断选择的宠物是否在其中
|
||||
List<Integer> ids = JSONUtil.toList(info.args, Integer.class);
|
||||
if (!ids.contains(petId)) return NewsContext.onFail("不可选择这个宠物!");
|
||||
|
||||
//宠物数量
|
||||
long petCount = playerPetService.count(
|
||||
Wrappers.lambdaQuery(PlayerPet.class).eq(PlayerPet::getPetPlayerId,player.getPlayerId())
|
||||
);
|
||||
|
||||
if(petCount > 0){
|
||||
//玩家已经有宠物了
|
||||
return NewsContext.onFail("你已经有宠物了!");
|
||||
}else{
|
||||
//选择宠物
|
||||
if (playerPetService.save(PlayerPet.builder().petPlayerId(player.getPlayerId()).petTbId(petId).petGrade(0).build())){
|
||||
return NewsContext.onSuccess("选择宠物成功");
|
||||
}else{
|
||||
return NewsContext.onSuccess("选择宠物失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -12,18 +12,19 @@ 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.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 新手API
|
||||
* 玩家
|
||||
*/
|
||||
@Api(value = "JNGameDemo - API", tags = {"PET - API"})
|
||||
@RestController
|
||||
@RequestMapping("/game/player")
|
||||
@ResponseBody
|
||||
public class PlayerController {
|
||||
public class GPlayerController {
|
||||
|
||||
@Autowired
|
||||
PlayerServiceImpl playerService;
|
@@ -0,0 +1,49 @@
|
||||
package cn.jisol.game.controller.game;
|
||||
|
||||
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
|
||||
import cn.jisol.game.controller.argsresolver.CurrentUser;
|
||||
import cn.jisol.game.entity.User;
|
||||
import cn.jisol.game.entity.game.Player;
|
||||
import cn.jisol.game.entity.game.PlayerPet;
|
||||
import cn.jisol.game.service.PlayerPetService;
|
||||
import cn.jisol.game.service.impl.PlayerServiceImpl;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 玩家
|
||||
*/
|
||||
@Api(value = "JNGameDemo - API", tags = {"PET - API"})
|
||||
@RestController
|
||||
@RequestMapping("/game/pet")
|
||||
@ResponseBody
|
||||
public class GPlayerPetController {
|
||||
|
||||
@Autowired
|
||||
PlayerPetService playerPetService;
|
||||
|
||||
//获取玩家宠物列表
|
||||
@ApiImplicitParams({})
|
||||
@ApiOperation(value = "获取玩家宠物列表")
|
||||
@GetMapping("/list")
|
||||
public NewsContext<List<PlayerPet>> getPetList(@CurrentPlayer Player player){
|
||||
|
||||
return NewsContext.onSuccess("获取成功",
|
||||
playerPetService.list(
|
||||
Wrappers.lambdaQuery(PlayerPet.class).eq(PlayerPet::getPetPlayerId,player.getPlayerId())
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package cn.jisol.game.data;
|
||||
|
||||
import cn.jisol.game.entity.User;
|
||||
import cn.jisol.game.entity.game.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -11,6 +12,7 @@ import java.util.Map;
|
||||
public class Cache {
|
||||
|
||||
public static String KEY_TOKEN = "Token";
|
||||
public static Map<String, User> TOKEN = new HashMap<>();
|
||||
public static Map<String, User> TOKEN = new HashMap<>(); //Token
|
||||
public static Map<Long, Player> PLAYER = new HashMap<>(); //玩家
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package cn.jisol.game.data;
|
||||
|
||||
public interface GlobalIds {
|
||||
|
||||
//选择宠物配置表Id
|
||||
int SELECT_PET_ID = 70001;
|
||||
|
||||
}
|
@@ -15,6 +15,7 @@ import lombok.Data;
|
||||
public class PlayerPet {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long petId; //宠物唯一Id
|
||||
private String petTbId; //宠物配置表Id
|
||||
private String petGrade; //宠物等级
|
||||
private Long petPlayerId; //宠物的玩家Id
|
||||
private Integer petTbId; //宠物配置表Id
|
||||
private Integer petGrade; //宠物等级
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package cn.jisol.game.mapper;
|
||||
|
||||
import cn.jisol.game.entity.game.PlayerPet;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public interface PlayerPetMapper extends BaseMapper<PlayerPet> {
|
||||
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package cn.jisol.game.service;
|
||||
|
||||
import cn.jisol.game.entity.game.PlayerPet;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface PlayerPetService extends IService<PlayerPet> {
|
||||
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package cn.jisol.game.service.impl;
|
||||
|
||||
import cn.jisol.game.entity.game.Player;
|
||||
import cn.jisol.game.entity.game.PlayerPet;
|
||||
import cn.jisol.game.mapper.PlayerMapper;
|
||||
import cn.jisol.game.mapper.PlayerPetMapper;
|
||||
import cn.jisol.game.service.PlayerPetService;
|
||||
import cn.jisol.game.service.PlayerService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PlayerPetServiceImpl extends ServiceImpl<PlayerPetMapper, PlayerPet> implements PlayerPetService {
|
||||
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"id": 70001,
|
||||
"args": "[10004,10001,10002]",
|
||||
"tig": "新手引导选择宠物[妙蛙种子,小石头,疯狂石头]"
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user