工坊升级材料方式

back_recharge
lvxinran 2019-06-18 15:45:12 +08:00
parent 5f2d97cd7a
commit 396c8be30c
4 changed files with 57 additions and 96 deletions

View File

@ -12,10 +12,14 @@ public class SWorkShopSetting implements BaseConfig {
private int id;
private int exp;
private int[][] exp;
private int[] promote;
private int technologyLevel;
private int[] unravelItem;
private int foodExp;
private float addNum;
@ -28,10 +32,7 @@ public class SWorkShopSetting implements BaseConfig {
private int cookTotalWeight;
private static int maxExp;
private static int maxCookExp;
private static int maxLevel;
private static Map<Integer,SWorkShopSetting> sWorkShopSettingMap;
@ -40,8 +41,7 @@ public class SWorkShopSetting implements BaseConfig {
public void init() throws Exception {
Map<Integer, SWorkShopSetting> sWorkShopSettingMapTmp = sWorkShopSettingMap = STableManager.getConfig(SWorkShopSetting.class);
Map<Integer,Integer> promoteMapTmp = new HashMap<>();
int maxExpTmp = 0;
int maxCookExpTmp = 0;
int maxLevel = 0;
for(SWorkShopSetting sWorkShopSetting : sWorkShopSettingMapTmp.values()){
Map<Integer,Integer> promoteMapTmptm = new HashMap<>(promoteMapTmp);
int[] promote = sWorkShopSetting.getPromote();
@ -51,8 +51,7 @@ public class SWorkShopSetting implements BaseConfig {
promoteMapTmptm.put(promote[0],promote[1]);
sWorkShopSetting.setPromoteMap(promoteMapTmptm);
}
maxExpTmp = MathUtils.getMaxNum(maxExpTmp,sWorkShopSetting.getExp());
maxCookExpTmp=MathUtils.getMaxNum(maxExpTmp,sWorkShopSetting.getFoodExp());
maxLevel = MathUtils.getMaxNum(maxLevel,sWorkShopSetting.getId());
int[][] poolWeight = sWorkShopSetting.getPoolRate();
if(poolWeight!=null && poolWeight.length>0){
int totalWeight = 0;
@ -64,27 +63,22 @@ public class SWorkShopSetting implements BaseConfig {
}
sWorkShopSettingMap = sWorkShopSettingMapTmp;
maxExp = maxExpTmp;
maxCookExp = maxCookExpTmp;
this.maxLevel = maxLevel;
}
public static int getMaxExp() {
return maxExp;
public static int getMaxLevel() {
return maxLevel;
}
public static int getMaxCookExp() {
return maxCookExp;
}
public static SWorkShopSetting getsWorkShopSettingByLevel(int levle) {
return sWorkShopSettingMap.get(levle);
public static SWorkShopSetting getsWorkShopSettingByLevel(int level) {
return sWorkShopSettingMap.get(level);
}
public int getId() {
return id;
}
public int getExp() {
public int[][] getExp() {
return exp;
}
@ -100,18 +94,10 @@ public class SWorkShopSetting implements BaseConfig {
this.promoteMap = promoteMap;
}
public void setExp(int exp) {
public void setExp(int[][] exp) {
this.exp = exp;
}
public int getFoodExp() {
return foodExp;
}
public float getAddNum() {
return addNum;
}
public int[][] getPoolRate() {
return poolRate;
}

View File

@ -0,0 +1,21 @@
package com.ljsd.jieling.handler.workshop;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.item.WorkShopLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
@Component
public class WorkShopLevelUpHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.WORKSHOP_LEVELUP_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
WorkShopLogic.getInstance().workShopLevelUp(iSession);
}
}

View File

@ -38,62 +38,6 @@ public class WorkShopController extends MongoBase {
updateString("openBlueStateMap." + type, openBlueStateMap.get(type));
}
public void addWorkShopExp(User user,int addExp) throws Exception {
int maxExp = SWorkShopSetting.getMaxExp();
if(this.workShopExp >= maxExp){
return;
}
SWorkShopSetting sWorkShopSetting = SWorkShopSetting.getsWorkShopSettingByLevel(this.workShopLevel + 1);
int needLevelExp;
if (sWorkShopSetting == null) {
needLevelExp = maxExp;
} else {
needLevelExp = sWorkShopSetting.getExp();
}
int curExp = MathUtils.setBetweenWithMax(this.workShopExp + addExp, 0, maxExp);
int oldLevel = this.workShopLevel;
while(curExp>=needLevelExp && curExp <= maxExp){
setWorkShopLevel(this.workShopLevel+1);
sWorkShopSetting = SWorkShopSetting.getsWorkShopSettingByLevel(this.workShopLevel + 1);
if(null == sWorkShopSetting){
needLevelExp = Integer.MAX_VALUE;
continue;
}
needLevelExp = sWorkShopSetting.getExp();
}
if(this.workShopLevel>oldLevel){
user.getUserMissionManager().onGameEvent(user,GameEvent.WORKSHOP_LEVELUP,oldLevel,this.workShopLevel);
}
setWorkShopExp(curExp);
}
public void addCookExp(int addExp) throws Exception {
int maxExp = SWorkShopSetting.getMaxCookExp();
if(this.cookExp >= maxExp){
return;
}
SWorkShopSetting sWorkShopSetting = SWorkShopSetting.getsWorkShopSettingByLevel(this.cookLevel + 1);
int needLevelExp;
if (sWorkShopSetting == null) {
needLevelExp = maxExp;
} else {
needLevelExp = sWorkShopSetting.getExp();
}
int curExp = MathUtils.setBetweenWithMax(this.cookExp + addExp, 0, maxExp);
while(curExp>=needLevelExp && curExp <= maxExp){
setWorkShopLevel(this.cookLevel+1);
sWorkShopSetting = SWorkShopSetting.getsWorkShopSettingByLevel(this.cookLevel + 1);
if(null == sWorkShopSetting || sWorkShopSetting.getExp() == 0){
needLevelExp = Integer.MAX_VALUE;
continue;
}
needLevelExp = sWorkShopSetting.getExp();
}
setWorkShopExp(curExp);
}
public int getWorkShopLevel() {
return workShopLevel;
}

View File

@ -105,9 +105,7 @@ public class WorkShopLogic {
totalFailExp+=failExp;
}
CommonProto.Drop.Builder dropThing = ItemUtil.drop(user, drop,BIReason.WORKSHOP_MAKEFOOD);
if(totalFailExp>0){
user.getWorkShopController().addCookExp(totalFailExp);
}
CommonProto.WorkShopBaseInfo workShopBaseInfo = CommonProto.WorkShopBaseInfo.newBuilder().setType(GlobalsDef.COOK_SHOP_TYPE).setLevle(workShopController.getCookLevel()).setExp(workShopController.getCookExp()).build();
PlayerInfoProto.CookFoodResponse build = PlayerInfoProto.CookFoodResponse.newBuilder().setWorkShopBaseInfo(workShopBaseInfo).setDrop(dropThing).build();
@ -245,11 +243,7 @@ public class WorkShopLogic {
//熟练度提升
int type = sWorkShopFoundationConfig.getType();
int addExp = sWorkShopFoundationConfig.getExp()*nums;
if(type == GlobalsDef.WORK_SHOP_TYPE){
user.getWorkShopController().addWorkShopExp(user,addExp);
}else if( type == GlobalsDef.COOK_SHOP_TYPE){
user.getWorkShopController().addCookExp(addExp);
}
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.WORKSHOP_FOUNDATION_RESPONSE_VALUE,null,true);
}
@ -309,10 +303,8 @@ public class WorkShopLogic {
user.getEquipManager().addEquip(user,equip);
dropBuilder.addEquipId(CBean2Proto.getEquipProto(equip));
}
user.getWorkShopController().addWorkShopExp(user,addExp);
user.getUserMissionManager().onGameEvent(user, GameEvent.WORKSHOP_CREATE_EQUIP,nums);
}else if( type == GlobalsDef.COOK_SHOP_TYPE){
user.getWorkShopController().addCookExp(addExp);
Map<Integer,Integer> items = new HashMap<>();
items.put(equipTid,SMysteryFoodSetting.getsMysteryFoodSetting().getFoodNum()*nums);
ItemUtil.addItem(user,items,dropBuilder,BIReason.WORKSHOP_CREATEQUIP);
@ -343,7 +335,6 @@ public class WorkShopLogic {
clone.rebuildEquip(user.getWorkShopController().getWorkShopLevel());
equipManager.setUnDetermined(clone);
int addExp = sWorkShopRebuildConfig.getExp();
user.getWorkShopController().addWorkShopExp(user,addExp);
PlayerInfoProto.WorkShopRebuildRespoonse build = PlayerInfoProto.WorkShopRebuildRespoonse.newBuilder().setEquip(CBean2Proto.getEquipProto(clone)).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.WORKSHOP_REBUILD_RESPONSE_VALUE,build,true);
}
@ -409,4 +400,23 @@ public class WorkShopLogic {
}
return "";
}
public void workShopLevelUp(ISession session)throws Exception{
int uid = session.getUid();
User user = UserManager.getUser(uid);
WorkShopController controller = user.getWorkShopController();
int currLevel = controller.getWorkShopLevel();
SWorkShopSetting shopSetting = SWorkShopSetting.getsWorkShopSettingByLevel(currLevel);
int[][] itemInfo = shopSetting.getExp();
if(currLevel>=SWorkShopSetting.getMaxLevel()){
MessageUtil.sendErrorResponse(session,0,MessageTypeProto.MessageType.WORKSHOP_LEVELUP_RESPONSE_VALUE,"已满级");
return;
}
boolean costResult = ItemUtil.itemCost(user,itemInfo,1,1);
if(costResult){
controller.setWorkShopLevel(currLevel+1);
MessageUtil.sendMessage(uid,1,MessageTypeProto.MessageType.WORKSHOP_LEVELUP_RESPONSE_VALUE,null,true);
}else{
MessageUtil.sendErrorResponse(session,0,MessageTypeProto.MessageType.WORKSHOP_LEVELUP_RESPONSE_VALUE,"道具不足");
}
}
}