山河社稷图优化

back_recharge
xuexinpeng 2021-06-11 18:30:14 +08:00
parent 880d92bed4
commit 1224f67b7b
4 changed files with 56 additions and 8 deletions

View File

@ -16,7 +16,7 @@ public class HardStageManager extends MongoBase {
private int curChapter;
private int curNode;
private Map<Integer, HardStageChapter> chapterMap;//山河玩家信息
private Map<Integer, HardStageChapter> chapterMap = new HashMap<>();//山河玩家信息
private List<Integer> noOpenId = Lists.newArrayList();//因等级限制未开的关卡
@ -25,7 +25,7 @@ public class HardStageManager extends MongoBase {
}
public Map<Integer, HardStageChapter> getChapterMap(User user) throws Exception {
if (null == chapterMap) {
if (null == chapterMap || chapterMap.size() <1) {
Map<Integer, HardStageChapter> map = initChapterMap(user);
setChapterMap(map);
}
@ -48,7 +48,7 @@ public class HardStageManager extends MongoBase {
chapter.addNodeList(node);
//setCurNode(node.getId());
map.put(chapter.getChapterId(), chapter);
setCurChapter(chapter.getChapterId());
//setCurChapter(chapter.getChapterId());
updateString("chapterMap." + chapter.getChapterId(), chapter);
return map;
}
@ -77,7 +77,7 @@ public class HardStageManager extends MongoBase {
chapter.updateRewardMap();
});
}
setCurChapter(chapterId);
//setCurChapter(chapterId);
updateString("chapterMap." + chapter.getChapterId(), chapter);
return chapter;
}

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.logic.dao.root;
import com.ljsd.jieling.db.mongo.MongoKey;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.jbean.ActivityManager;
import com.ljsd.jieling.logic.dao.*;
@ -213,10 +214,19 @@ public class User {
return expeditionManager;
}
public HardStageManager getHardStageManager() {
public HardStageManager getHardStageManager(){
if(null ==hardStageManager){
this.hardStageManager = new HardStageManager();
this.hardStageManager.init(id,MongoKey.hardStageManager);
}else{
if(this.hardStageManager.getMongoKey()== null || this.hardStageManager.getMongoKey() == ""){
this.hardStageManager.init(id,MongoKey.hardStageManager);
try {
MongoUtil.getInstence().getMyMongoTemplate().save(id,this);
}catch (Exception e){
e.printStackTrace();
}
}
}
return hardStageManager;
}

View File

@ -37,6 +37,10 @@ public class HardStageChapter extends MongoBase {
return stars;
}
public void setStars(int stars) {
this.stars = stars;
}
public void addStars(int stars) {
this.stars += stars;
//updateString("stars", this.stars);

View File

@ -45,9 +45,12 @@ public class HardStageLogic {
public static CommonProto.HardStageInfo.Builder getInfo(User user) throws Exception {
Map<Integer, HardStageChapter> map = user.getHardStageManager().getChapterMap(user);
CommonProto.HardStageInfo.Builder builder = CommonProto.HardStageInfo.newBuilder();
int needSaveChapterId = 0;
int needSaveStarNum = 0;
for (Map.Entry<Integer, HardStageChapter> entry : map.entrySet()) {
//章节信息
CommonProto.HardStageChapter.Builder chapterBuilder = CommonProto.HardStageChapter.newBuilder();
int starNums =0;//章节星星数检测 章节星星总数和所有小节的星星累加的总数 比较
for (HardStageNode node : entry.getValue().getNodeList()) {
CommonProto.HardStageNode.Builder nodeBuilder = CommonProto.HardStageNode.newBuilder();
nodeBuilder.setNodeId(node.getId());
@ -56,9 +59,20 @@ public class HardStageLogic {
nodeBuilder.setIsFirst(node.isFirst());
nodeBuilder.setIsPass(node.isHasPass());
chapterBuilder.addNode(nodeBuilder);
if(node.getType() == 1){
starNums +=checkStarNum(reformatBinary(node.getState()));
}
}
if(starNums != entry.getValue().getStars() ){
//数量不一致 以starNums为准
chapterBuilder.setStars(starNums);
needSaveChapterId = entry.getKey();
needSaveStarNum = starNums;
}else {
chapterBuilder.setStars(entry.getValue().getStars());
}
chapterBuilder.setChapterId(entry.getKey());
chapterBuilder.setStars(entry.getValue().getStars());
for (Map.Entry<Integer, Boolean> entry1 : entry.getValue().getRewardMap().entrySet()) {
CommonProto.HardStageChapterReward.Builder rewardBuilder = CommonProto.HardStageChapterReward.newBuilder();
rewardBuilder.setId(entry1.getKey());
@ -67,6 +81,12 @@ public class HardStageLogic {
}
builder.addChapter(chapterBuilder);
}
//容错
if(needSaveChapterId!=0 ){
map.get(needSaveChapterId).setStars(needSaveStarNum);
user.getHardStageManager().updateString("chapterMap." + needSaveChapterId, map.get(needSaveChapterId));
}
return builder;
}
@ -313,9 +333,9 @@ public class HardStageLogic {
List<Integer> noOpenId = user.getHardStageManager().getNoOpenId();
List<Integer> needDel = Lists.newArrayList();
for (int id:noOpenId) {
if (curNodeId == 0 && chapterId == 0) {
/*if (curNodeId == 0 && chapterId == 0) {
user.getHardStageManager().getChapterMap(user);
}
}*/
SHardStage nodeConfig = SHardStage.getConfigMap().get(id);
if(nodeConfig != null){
boolean openSuccess = user.getHardStageManager().openNewNode(level,nodeConfig);
@ -354,6 +374,20 @@ public class HardStageLogic {
return sb;
}
/**
*
*/
public static int checkStarNum(StringBuffer charString) throws Exception{
int num=0;
char[] chars = charString.toString().toCharArray();
for(int i = 0; i < chars.length; i++) {
if(chars[i]=='1') {
num++;
}
}
return num;
}
/**
*
*/