This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-10 03:56:07 +08:00
parent 9157e123b6
commit 620bcd3e53
36 changed files with 3246 additions and 32 deletions

View File

@@ -8,17 +8,18 @@ import cn.jisol.game.service.PlayerService;
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 org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
* 新手API
*/
@Api(value = "JNGameDemo - API", tags = {"PET - API"})
@RestController
@RequestMapping("/game/player")
@ResponseBody
@@ -28,18 +29,56 @@ public class PlayerController {
PlayerServiceImpl playerService;
//获取玩家信息
@ApiImplicitParams({})
@ApiOperation(value = "获取玩家信息")
@GetMapping("/info")
public NewsContext<Player> getPlayerInfo(@CurrentUser User user){
Player info = playerService.getOne(Wrappers.lambdaQuery(Player.class).eq(Player::getUserId,user.getUserId()));
if (Objects.isNull(info)){
//玩家没有进入过游戏 前往 新手引导
return NewsContext.onMessage("前往新手引导",null, HttpCode.NOT_CREATE_PLAYER_INFO);
}else{
try{
info = Player.builder().userId(user.getUserId()).playerName("冒险者").build();
playerService.saveOrUpdate(info);
}catch (Exception ignored){}
assert playerService != null;
info = playerService.getOne(Wrappers.lambdaQuery(Player.class).eq(Player::getUserId,user.getUserId()));
}
if (info.isNovice()){
return NewsContext.onSuccess("获取成功",info);
}else{
//前往 新手引导
return NewsContext.onMessage("前往新手引导",info, HttpCode.NOT_CREATE_PLAYER_INFO);
}
}
//设置玩家信息
@ApiImplicitParams({})
@ApiOperation(value = "设置玩家信息")
@PostMapping("/info/save")
public NewsContext<Player> savePlayerInfo(@CurrentUser User user,@RequestBody Player player){
//获取玩家信息
Player info = playerService.getOne(Wrappers.lambdaQuery(Player.class).eq(Player::getUserId,user.getUserId()));
//如果没有玩家信息则初始化信息
if (Objects.isNull(info)){
info = Player.builder().userId(user.getUserId()).build();
}
info.setPlayerName(player.getPlayerName());
info.setNovice(player.isNovice());
//保存信息
if(playerService.saveOrUpdate(info)){
return NewsContext.onSuccess("保存成功",info);
}else{
return NewsContext.onFail("保存失败",info);
}
}
}

View File

@@ -1,18 +1,19 @@
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 com.baomidou.mybatisplus.annotation.*;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
@Builder
@Data
@TableName("`player`")
public class Player {
@TableId(type = IdType.AUTO)
private Long playerId; //游戏玩家Id
private String userId; //玩家Id
private Long userId; //玩家Id
private String playerName; //游戏玩家名称
private Long playerCreateTime; //玩家创建时间
private Date playerCreateTime; //玩家创建时间
private boolean isNovice; //玩家是否过了新手引导
}

View File

@@ -6,6 +6,9 @@ spring:
password: sThsBwjfDcaw2wJR
url: jdbc:mysql://kyu.jisol.cn:3306/pet_jisol_cn?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
jackson:
serialization:
write-dates-as-timestamps: true
mybatis-plus:
configuration: