parent
e912f389ca
commit
1e11b909fc
|
@ -52,9 +52,6 @@ public class HomeLogic {
|
|||
User user = UserManager.getUser(session.getUid());
|
||||
//xxxx 目前只允许升级一个建筑,多个建筑一键升级需要优化
|
||||
int id = proto.getIdsList().get(0);
|
||||
// 1:普通升级, 2:立即完成 3:取消升级 4:特权加速
|
||||
int type = proto.getType();
|
||||
ArrayList<CommonProto.ArchitectureInfo> list = new ArrayList<>();
|
||||
// 当前时间
|
||||
int now = TimeUtils.nowInt();
|
||||
Map<Integer, SHomeLandLevel> config = STableManager.getConfig(SHomeLandLevel.class);
|
||||
|
@ -67,6 +64,11 @@ public class HomeLogic {
|
|||
if (landLevel == null){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_DEFINE,"浮生门建筑升级,策划表内找不到建筑levelId:"+info.getId());
|
||||
}
|
||||
// 最高等级验证
|
||||
int maxId = config.values().stream().filter(v->v.getPoolID()==landLevel.getPoolID()).mapToInt(SHomeLandLevel::getlevel).max().orElse(0);
|
||||
if (info.getId() == maxId) {
|
||||
throw new ErrorCodeException(ErrorCode.LEVE_MAX,"浮生门建筑升级,建筑等级最高,升级建筑levelId:"+info.getId());
|
||||
}
|
||||
//升级前置条件
|
||||
int[] rule = landLevel.getRule();
|
||||
if (rule != null && rule.length > 1){
|
||||
|
@ -83,68 +85,43 @@ public class HomeLogic {
|
|||
if (info.getUpLvEndTime() != 0 && info.getUpLvEndTime() <= now){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
//普通升级
|
||||
if (type == 1 && info.getUpLvEndTime() == 0){
|
||||
// 最高等级
|
||||
int maxId = config.values().stream().filter(v->v.getPoolID()==landLevel.getPoolID()).mapToInt(SHomeLandLevel::getlevel).max().orElse(0);
|
||||
if (info.getId() == maxId) {
|
||||
throw new ErrorCodeException(ErrorCode.LEVE_MAX,"浮生门建筑升级,建筑等级最高,升级建筑levelId:"+info.getId());
|
||||
}
|
||||
// 需要消耗的道具
|
||||
int[][] items = landLevel.getCost();
|
||||
boolean cost = ItemUtil.itemCost(user, items, BIReason.ARCHITECTURE_UP_LEVEL, 0);
|
||||
if (!cost) {
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH,"浮生门建筑升级,建筑升级要求道具不足,建筑levelId:"+info.getId()+",道具要求:"+Arrays.toString(items));
|
||||
}
|
||||
// 普通升级
|
||||
// 1:普通升级, 2:立即完成 3:取消升级 4:特权加速
|
||||
int type = proto.getType();
|
||||
if (type == 1 || type == 2){
|
||||
// 消耗道具
|
||||
if (info.getUpLvEndTime() == 0){
|
||||
int endTime = landLevel.getTime();
|
||||
info.setUpLvEndTime(now + endTime);
|
||||
}
|
||||
}
|
||||
// 立即完成
|
||||
if (type == 2){
|
||||
// 最高等级
|
||||
int maxId = config.values().stream().filter(v->v.getPoolID()==landLevel.getPoolID()).mapToInt(SHomeLandLevel::getlevel).max().orElse(0);
|
||||
if (info.getId() == maxId) {
|
||||
throw new ErrorCodeException(ErrorCode.LEVE_MAX,"浮生门建筑升级,建筑等级最高,升级建筑levelId:"+info.getId());
|
||||
}
|
||||
boolean ifType = false;
|
||||
int[][] items = landLevel.getCost();
|
||||
// quick up level
|
||||
if (info.getUpLvEndTime() == 0){
|
||||
boolean cost = ItemUtil.checkCostLong(user, items, 1);
|
||||
boolean ifType = false;
|
||||
boolean cost = ItemUtil.checkCostLong(user, landLevel.getCost(), 1);
|
||||
if (!cost) {
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH,"浮生门建筑升级,建筑升级要求道具不足,建筑levelId:"+info.getId()+",道具要求:"+Arrays.toString(items));
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH, "浮生门建筑升级,建筑升级要求道具不足,建筑levelId:"+info.getId());
|
||||
}
|
||||
ifType = true;
|
||||
info.setUpLvEndTime(now + landLevel.getTime());
|
||||
}
|
||||
// 条件: 单位/s 道具id 道具数量
|
||||
int[] intValues = SSpecialConfig.getIntegerArrayValue(SSpecialConfig.HONGMENG_LATTICE_PRICE);
|
||||
// 立即升级消耗的道具
|
||||
int time = Math.max(info.getUpLvEndTime() - now, 0);
|
||||
if (time > 0){
|
||||
// 每一个单位的消耗
|
||||
int oneCost = intValues[0] * intValues[2];
|
||||
// 总消耗数量,向上取整
|
||||
int count = (int) Math.ceil((double) time/oneCost);
|
||||
int[][] cost1 = {{intValues[1], count}};
|
||||
boolean itemCost = ItemUtil.itemCost(user, cost1, BIReason.ARCHITECTURE_IMMEDIATELY_UP_LEVEL, 0);
|
||||
if (!itemCost) {
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH, "浮生门建筑升级,立刻升级失败道具不足,建筑levelId:" + info.getId() + ",道具要求:" + Arrays.toString(cost1));
|
||||
}
|
||||
if (ifType){
|
||||
ItemUtil.itemCost(user, items, BIReason.ARCHITECTURE_UP_LEVEL, 0);
|
||||
// 立即升级消耗妖晶
|
||||
if (type == 2){
|
||||
// 条件: 单位/s 道具id 道具数量
|
||||
int[] intValues = SSpecialConfig.getIntegerArrayValue(SSpecialConfig.HONGMENG_LATTICE_PRICE);
|
||||
// 立即升级消耗的道具
|
||||
int time = Math.max(info.getUpLvEndTime() - now, 0);
|
||||
if (time > 0){
|
||||
// 每一个单位的消耗
|
||||
int oneCost = intValues[0] * intValues[2];
|
||||
// 总消耗数量,向上取整
|
||||
int count = (int) Math.ceil((double) time/oneCost);
|
||||
boolean itemCost = ItemUtil.itemCost(user, new int[][]{{intValues[1], count}}, BIReason.ARCHITECTURE_IMMEDIATELY_UP_LEVEL, 0);
|
||||
if (!itemCost) {
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH, "浮生门建筑升级,立刻升级失败道具不足,建筑levelId:"+info.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemUtil.itemCost(user, landLevel.getCost(), BIReason.ARCHITECTURE_UP_LEVEL, 0);
|
||||
architectureUpLvEnd(user, landLevel.getPoolID(), info);
|
||||
}
|
||||
// 取消升级
|
||||
if (type == 3){
|
||||
info.setUpLvEndTime(0);
|
||||
}
|
||||
// 特权加速
|
||||
if (type == 4 && info.getId() > 0){
|
||||
if (type == 4 && info.getUpLvEndTime() > 0){
|
||||
// 验证特权次数
|
||||
boolean countBol = PlayerLogic.getInstance().checkAndUpdate(user, VipPrivilegeType.HOME_DAY_TIME_NUM, 1);
|
||||
if (!countBol) {
|
||||
|
@ -154,7 +131,6 @@ public class HomeLogic {
|
|||
int time = now + value;
|
||||
// 加速后是否达到升级时间
|
||||
if (time >= info.getUpLvEndTime()){
|
||||
info.setUpLvEndTime(0);
|
||||
architectureUpLvEnd(user, landLevel.getPoolID(), info);
|
||||
}else {
|
||||
info.setUpLvEndTime(time);
|
||||
|
@ -163,6 +139,7 @@ public class HomeLogic {
|
|||
// 最后更新
|
||||
user.getPlayerInfoManager().putArchitectureInfo(landLevel.getPoolID(),info);
|
||||
// 需要更新的建筑信息
|
||||
ArrayList<CommonProto.ArchitectureInfo> list = new ArrayList<>();
|
||||
CommonProto.ArchitectureInfo.Builder infoBuilder = CommonProto.ArchitectureInfo.newBuilder()
|
||||
.setId(info.getId()).setProductionStartTime(info.getProductionStartTime()).setUpLvEndTime(info.getUpLvEndTime());
|
||||
list.add(infoBuilder.build());
|
||||
|
|
Loading…
Reference in New Issue