mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 10:16:14 +00:00
提交
This commit is contained in:
@@ -19,6 +19,7 @@ public final class TbGResource extends AbstractBean {
|
||||
id = _buf.get("id").getAsInt();
|
||||
name = _buf.get("name").getAsString();
|
||||
tig = _buf.get("tig").getAsString();
|
||||
args = _buf.get("args").getAsString();
|
||||
}
|
||||
|
||||
public static TbGResource deserialize(JsonObject _buf) {
|
||||
@@ -37,6 +38,10 @@ public final class TbGResource extends AbstractBean {
|
||||
* 描述
|
||||
*/
|
||||
public final String tig;
|
||||
/**
|
||||
* 额外参数
|
||||
*/
|
||||
public final String args;
|
||||
|
||||
public static final int __ID__ = 1780642599;
|
||||
|
||||
@@ -49,6 +54,7 @@ public final class TbGResource extends AbstractBean {
|
||||
+ "(format_field_name __code_style field.name):" + id + ","
|
||||
+ "(format_field_name __code_style field.name):" + name + ","
|
||||
+ "(format_field_name __code_style field.name):" + tig + ","
|
||||
+ "(format_field_name __code_style field.name):" + args + ","
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
package cn.jisol.game.controller.exception;
|
||||
|
||||
public class GeneralException extends RuntimeException{
|
||||
public GeneralException() {
|
||||
}
|
||||
public GeneralException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@@ -32,6 +32,12 @@ public class HTTPExceptionHandler {
|
||||
return NewsContext.onFail("服务器忙碌啦~ 一会再试试.");
|
||||
}
|
||||
|
||||
//通用错误
|
||||
@ExceptionHandler(value = GeneralException.class)
|
||||
@ResponseBody
|
||||
public NewsContext<String> generalHandler(Exception e){
|
||||
return NewsContext.onFail(e.getMessage());
|
||||
}
|
||||
//全局异常
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
|
@@ -6,7 +6,6 @@ import cfg.TB.TbGRoleEquipType;
|
||||
import cfg.TbGEntity.TAttributeValue;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
|
||||
import cn.jisol.game.controller.exception.ResourceNotException;
|
||||
import cn.jisol.game.data.ResourceId;
|
||||
import cn.jisol.game.data.TD;
|
||||
import cn.jisol.game.entity.data.GAttribute;
|
||||
@@ -16,20 +15,21 @@ import cn.jisol.game.service.PetEquipService;
|
||||
import cn.jisol.game.service.PlayerPetService;
|
||||
import cn.jisol.game.service.ResourceService;
|
||||
import cn.jisol.game.util.GRandomUtil;
|
||||
import cn.jisol.game.vo.news.NewsResource;
|
||||
import cn.jisol.game.vo.news.ov.ResourceUpdateOV;
|
||||
import cn.jisol.game.vo.pet.equip.EquipForgingBenchOV;
|
||||
import cn.jisol.game.vo.pet.equip.PetEquipForgingOV;
|
||||
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.retry.RetryException;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public class GPlayerEquipController {
|
||||
@ApiOperation(value = "锻造装备(扣除玩家锻造石 打造一件装备)")
|
||||
@GetMapping("/forging")
|
||||
@Transactional
|
||||
public NewsContext<PetEquip> forging(@CurrentPlayer Player player){
|
||||
public NewsContext<PetEquipForgingOV> forging(@CurrentPlayer Player player){
|
||||
|
||||
//扣除一个锻造石
|
||||
resourceService.addResourceValue(player.getPlayerId(), ResourceId.ForgedStones.id, -1L);
|
||||
@@ -63,6 +63,8 @@ public class GPlayerEquipController {
|
||||
//获取锻造台
|
||||
EquipForgingBenchOV forgingInfo = this.forgingInfo(player).data;
|
||||
|
||||
if(Objects.isNull(forgingInfo.getForgingPetId())) return NewsContext.onFail("请设置锻造宠");
|
||||
|
||||
//随机取一个部位
|
||||
TbGRoleEquipType position = GRandomUtil.randomArray(TD.DATA.getTbGRoleEquipType().getDataList());
|
||||
|
||||
@@ -77,7 +79,7 @@ public class GPlayerEquipController {
|
||||
//随机取一个装备
|
||||
TbGRoleEquip equipInfo = GRandomUtil.randomArray(equips);
|
||||
|
||||
//封装
|
||||
//封装装备
|
||||
PetEquip equip = new PetEquip();
|
||||
equip.setEquipCfgId(equipInfo.id);
|
||||
equip.setEquipPlayerId(player.getPlayerId());
|
||||
@@ -106,9 +108,13 @@ public class GPlayerEquipController {
|
||||
equip.setEquipHighAttributes(new ArrayList<>());
|
||||
}
|
||||
|
||||
petEquipService.save(equip);
|
||||
//宠物锻造经验+1
|
||||
forgingInfo.addForgingPetLevel(1);
|
||||
|
||||
return NewsContext.onSuccess("锻造成功",petEquipService.getById(equip.getEquipId()));
|
||||
petEquipService.save(equip);
|
||||
equipForgingBenchService.saveOrUpdate(forgingInfo);
|
||||
|
||||
return NewsContext.onSuccess("锻造成功", PetEquipForgingOV.builder().equip(equip).info(forgingInfo).build());
|
||||
|
||||
}
|
||||
|
||||
@@ -137,7 +143,7 @@ public class GPlayerEquipController {
|
||||
try{
|
||||
info = EquipForgingBench.builder().playerId(player.getPlayerId())
|
||||
.forgingQuality(TD.DATA.getTbGRoleEquipQuality().getDataList().get(0).id)
|
||||
.forgingExp(0).build();
|
||||
.build();
|
||||
equipForgingBenchService.saveOrUpdate(info);
|
||||
}catch (Exception ignored){}
|
||||
assert equipForgingBenchService != null;
|
||||
@@ -204,10 +210,52 @@ public class GPlayerEquipController {
|
||||
|
||||
//升级锻造台
|
||||
@ApiImplicitParams({})
|
||||
@ApiOperation(value = "锻造台升级")
|
||||
@ApiOperation(value = "锻造台品质升级")
|
||||
@PostMapping("/forging/up")
|
||||
public NewsContext<EquipForgingBenchOV> wear(@CurrentPlayer Player player){
|
||||
return NewsContext.onFail("升级成功");
|
||||
public NewsResource<EquipForgingBenchOV> wear(@CurrentPlayer Player player){
|
||||
EquipForgingBenchOV info = this.forgingInfo(player).data;
|
||||
|
||||
if(info.getForgingUpTimeExcess() > 0) return NewsResource.onFail("正在升级",info);
|
||||
|
||||
//下一个等级
|
||||
int nextLevel = info.getForgingQuality() + 1;
|
||||
TbGRoleEquipQuality currentForgingInfo = TD.DATA.getTbGRoleEquipQuality().get(info.getForgingQuality());
|
||||
TbGRoleEquipQuality nextForgingInfo = TD.DATA.getTbGRoleEquipQuality().get(nextLevel);
|
||||
if(Objects.isNull(nextForgingInfo)) return NewsResource.onFail("已满级");
|
||||
|
||||
//扣除材料
|
||||
ArrayList<ResourceUpdateOV> resources = new ArrayList<>(resourceService.deduct(player,nextForgingInfo.materials));
|
||||
|
||||
info.setForgingQuality(nextLevel);
|
||||
//保存升级结束时间
|
||||
info.setForgingUpTime((new Date()).getTime() + currentForgingInfo.upTime * 1000L);
|
||||
|
||||
equipForgingBenchService.saveOrUpdate(info);
|
||||
|
||||
return NewsResource.onSuccess("升级成功",info,resources.toArray(new ResourceUpdateOV[0]));
|
||||
}
|
||||
|
||||
//使用加速卷
|
||||
@ApiImplicitParams({})
|
||||
@ApiOperation(value = "锻造台加速")
|
||||
@PostMapping("/use/speed/{resType}")
|
||||
@Transactional
|
||||
public NewsResource<EquipForgingBenchOV> useSpeed(@CurrentPlayer Player player, @PathVariable Integer resType){
|
||||
EquipForgingBenchOV info = this.forgingInfo(player).data;
|
||||
|
||||
if(Objects.isNull(resType)) return NewsResource.onFail("请选择需要使用的加速卷",info);
|
||||
if(info.getForgingUpTimeExcess() <= 0) return NewsResource.onFail("锻造台已升级成功",info);
|
||||
|
||||
//扣除资源
|
||||
ArrayList<ResourceUpdateOV> resources = new ArrayList<ResourceUpdateOV>(){{add(resourceService.deductSpeedUp(player,resType));}};
|
||||
|
||||
//减少时间
|
||||
info.setForgingUpTime(info.getForgingUpTime() - resourceService.timeSpeedUp(resType));
|
||||
|
||||
if(!equipForgingBenchService.updateById(info)) throw new RetryException("");;
|
||||
|
||||
return NewsResource.onSuccess("使用成功",info,resources.toArray(new ResourceUpdateOV[0]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -131,8 +131,6 @@ public class GPlayerPetController {
|
||||
@Transactional
|
||||
public NewsResource<PlayerPet> onUpLevel(@PathVariable Integer petId, @CurrentPlayer Player player){
|
||||
|
||||
//整理刷新数据
|
||||
ArrayList<ResourceUpdateOV> resources = new ArrayList<>();
|
||||
|
||||
//获取需要升级的宠物
|
||||
PlayerPet pet = playerPetService.getById(petId);
|
||||
@@ -148,18 +146,8 @@ public class GPlayerPetController {
|
||||
if(pet.getPetStar() * 10 <= pet.getPetLevel()){
|
||||
return NewsResource.onFail("突破星级 可升级");
|
||||
}
|
||||
|
||||
//扣除玩家材料
|
||||
for (int i = 0; i < resource.materials.length; i++) {
|
||||
TResource res = resource.materials[i];
|
||||
Resource data = resourceService.addResourceValue(player.getPlayerId(), res.id, -((long) res.value));
|
||||
if (Objects.isNull(data)){
|
||||
return NewsResource.onFail("材料不够");
|
||||
}else{
|
||||
//刷新资源
|
||||
resources.add(ResourceUpdateOV.onUpdate(data)); //刷新资源
|
||||
}
|
||||
}
|
||||
ArrayList<ResourceUpdateOV> resources = new ArrayList<>(resourceService.deduct(player, resource.materials));
|
||||
|
||||
//升级
|
||||
pet.setPetLevel(pet.getPetLevel() + 1);
|
||||
|
@@ -6,6 +6,8 @@ public enum ResourceId {
|
||||
Gold(90001),
|
||||
//锻造石
|
||||
ForgedStones(90002),
|
||||
//加速卷
|
||||
SpeedUp(90003),
|
||||
;
|
||||
|
||||
public int id;
|
||||
|
@@ -2,37 +2,65 @@ package cn.jisol.game.entity.table;
|
||||
|
||||
import cfg.TB.TbGRoleEquipLevel;
|
||||
import cn.jisol.game.data.TD;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.jisol.game.entity.data.GAttribute;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@TableName("`equip_forging_bench`")
|
||||
@TableName(value = "`equip_forging_bench`",autoResultMap = true)
|
||||
public class EquipForgingBench {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer forgingId; //锻造台Id
|
||||
private Long playerId; //锻造台所属的玩家Id
|
||||
private Integer forgingExp; //锻造等级经验
|
||||
private Integer forgingQuality; //锻造品质等级
|
||||
private Integer forgingPetId; //当前占用宠物Id
|
||||
private Long forgingUpTime; //升级结束时间(服务器)
|
||||
|
||||
@Version
|
||||
private Integer version;
|
||||
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
private Map<String,Integer> forgingPetLevels; //锻造宠等级信息{宠物Id:宠物经验}
|
||||
|
||||
public Map<String, Integer> getForgingPetLevels() {
|
||||
if(Objects.isNull(forgingPetLevels))
|
||||
return this.forgingPetLevels = new HashMap<>();
|
||||
return forgingPetLevels;
|
||||
}
|
||||
|
||||
//获取锻造等级
|
||||
public Integer getForgingLevel() {
|
||||
List<TbGRoleEquipLevel> collect = TD.DATA.getTbGRoleEquipLevel().getDataList().stream().filter(info -> info.exp <= this.forgingExp).collect(Collectors.toList());
|
||||
List<TbGRoleEquipLevel> collect = TD.DATA.getTbGRoleEquipLevel().getDataList().stream().filter(info -> info.exp <= this.getForgingPetLevels().getOrDefault(this.getForgingPetId().toString(),0)).collect(Collectors.toList());
|
||||
return collect.get(collect.size() - 1).id;
|
||||
}
|
||||
|
||||
public Integer getForgingPetId(){
|
||||
if(Objects.isNull(this.forgingPetId))
|
||||
return 0;
|
||||
return this.forgingPetId;
|
||||
}
|
||||
|
||||
//提升指定宠物锻造经验
|
||||
public boolean addForgingPetLevel(Integer exp) {
|
||||
Integer petId = this.forgingPetId;
|
||||
if (Objects.isNull(petId)) return false;
|
||||
Integer level = this.getForgingPetLevels().get(petId.toString());
|
||||
if(Objects.isNull(level)) level = 0;
|
||||
level += 1;
|
||||
this.getForgingPetLevels().put(petId.toString(),level);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,12 @@
|
||||
package cn.jisol.game.service;
|
||||
|
||||
import cn.jisol.game.entity.table.Player;
|
||||
import cn.jisol.game.entity.table.Resource;
|
||||
import cn.jisol.game.vo.news.ov.ResourceUpdateOV;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ResourceService extends IService<Resource> {
|
||||
|
||||
//添加某个资源的数量
|
||||
@@ -12,4 +16,15 @@ public interface ResourceService extends IService<Resource> {
|
||||
public Resource initResource(Long playerId, int type, Long value);
|
||||
public Resource initResource(Resource resource);
|
||||
|
||||
//扣除玩家材料
|
||||
public ArrayList<ResourceUpdateOV> deduct(Player player, cfg.TbGEntity.TResource[] materials);
|
||||
|
||||
//扣除通用加速卷
|
||||
public ResourceUpdateOV deductSpeedUp(Player player, int type);
|
||||
|
||||
//返回通用加速卷 减少的时间(ms)
|
||||
public long timeSpeedUp(int type);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,26 @@
|
||||
package cn.jisol.game.service.impl;
|
||||
|
||||
import cfg.TbGEntity.TResource;
|
||||
import cn.jisol.game.controller.exception.GeneralException;
|
||||
import cn.jisol.game.controller.exception.ResourceInitException;
|
||||
import cn.jisol.game.controller.exception.ResourceNotException;
|
||||
import cn.jisol.game.data.ResourceId;
|
||||
import cn.jisol.game.data.TD;
|
||||
import cn.jisol.game.entity.table.Player;
|
||||
import cn.jisol.game.entity.table.Resource;
|
||||
import cn.jisol.game.mapper.ResourceMapper;
|
||||
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.spring.SpringBeanUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.retry.RetryException;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@@ -92,5 +97,37 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ResourceUpdateOV> deduct(Player player, TResource[] materials) {
|
||||
|
||||
ArrayList<ResourceUpdateOV> list = new ArrayList<>();
|
||||
|
||||
for (TResource res : materials) {
|
||||
Resource data = this.addResourceValue(player.getPlayerId(), res.id, -((long) res.value));
|
||||
if (Objects.isNull(data)) {
|
||||
throw new ResourceNotException("资源不够");
|
||||
} else {
|
||||
//刷新资源
|
||||
list.add(ResourceUpdateOV.onUpdate(data)); //刷新资源
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceUpdateOV deductSpeedUp(Player player, int type) {
|
||||
if(!(Arrays.asList(ResourceId.SpeedUp.id).contains(type))) throw new GeneralException("资源错误");
|
||||
//扣除资源
|
||||
return ResourceUpdateOV.onUpdate(this.addResourceValue(player.getPlayerId(), type, -1L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long timeSpeedUp(int type) {
|
||||
if(!(Arrays.asList(ResourceId.SpeedUp.id).contains(type))) throw new GeneralException("资源错误");
|
||||
return Integer.parseInt(TD.DATA.getTbGResource().get(type).args) * 1000L;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -8,8 +8,7 @@ import java.util.Date;
|
||||
public class EquipForgingBenchOV extends EquipForgingBench {
|
||||
|
||||
//获取当前品质等级
|
||||
@Override
|
||||
public Integer getForgingQuality() {
|
||||
public Integer getCurrentForgingQuality() {
|
||||
if(this.getForgingUpTimeExcess() > 0){
|
||||
return super.getForgingQuality() - 1;
|
||||
}else{
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package cn.jisol.game.vo.pet.equip;
|
||||
|
||||
import cn.jisol.game.entity.table.EquipForgingBench;
|
||||
import cn.jisol.game.entity.table.PetEquip;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class PetEquipForgingOV {
|
||||
private EquipForgingBench info;
|
||||
private PetEquip equip;
|
||||
}
|
@@ -2,11 +2,19 @@
|
||||
{
|
||||
"id": 90001,
|
||||
"name": "金币",
|
||||
"tig": "金币 (目前叫做金币 名称还没有定) 游戏的基础资源 用于升级宠物"
|
||||
"tig": "金币 (目前叫做金币 名称还没有定) 游戏的基础资源 用于升级宠物",
|
||||
"args": ""
|
||||
},
|
||||
{
|
||||
"id": 90002,
|
||||
"name": "锻造石",
|
||||
"tig": "锻造石 可以锻造装备的石头"
|
||||
"tig": "锻造石 可以锻造装备的石头",
|
||||
"args": ""
|
||||
},
|
||||
{
|
||||
"id": 90003,
|
||||
"name": "通用加速卷",
|
||||
"tig": "加速卷 用来加速一切需要时间的东西 减少冷却:60s",
|
||||
"args": "60"
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user