心愿抽卡优化

back_recharge
duhui 2021-07-15 16:03:04 +08:00
parent 80b1659cb1
commit b2f31798b0
2 changed files with 36 additions and 29 deletions

View File

@ -78,9 +78,10 @@ public class HeroManager extends MongoBase {
private Map<Integer,Integer> randomCountByType = new HashMap<>(); private Map<Integer,Integer> randomCountByType = new HashMap<>();
/** /**
*
* key: value:< key: value: > * key: value:< key: value: >
*/ */
private Map<Integer, Map<Integer,Integer>> randomCountByStar = new HashMap<>(); private Map<Integer, Map<Integer,Integer>> wishCountByStar = new HashMap<>();
public Map<Integer, Integer> getRandomCountByType() { public Map<Integer, Integer> getRandomCountByType() {
return randomCountByType; return randomCountByType;
@ -96,22 +97,22 @@ public class HeroManager extends MongoBase {
updateString("randomCountByType."+type, value); updateString("randomCountByType."+type, value);
} }
public Map<Integer, Map<Integer, Integer>> getRandomCountByStar() { public Map<Integer, Map<Integer, Integer>> getWishCountByStar() {
return randomCountByStar; return wishCountByStar;
} }
public Map<Integer, Integer> getRandomStar(int type) { public Map<Integer, Integer> getWishStar(int type) {
return randomCountByStar.getOrDefault(type,new HashMap<>()); return wishCountByStar.getOrDefault(type,new HashMap<>());
} }
public void setRandomCountByStar(Map<Integer, Map<Integer, Integer>> randomCountByStar) { public void setWishCountByStar(Map<Integer, Map<Integer, Integer>> wishCountByStar) {
this.randomCountByStar = randomCountByStar; this.wishCountByStar = wishCountByStar;
updateString("randomCountByStar", randomCountByStar); updateString("wishCountByStar", wishCountByStar);
} }
public void putRandomStar(int type,Map<Integer,Integer> starMap) { public void putWishStar(int type,Map<Integer,Integer> starMap) {
randomCountByStar.put(type,starMap); wishCountByStar.put(type,starMap);
updateString("randomCountByStar."+type, starMap); updateString("wishCountByStar."+type, starMap);
} }
public void updateRandCount(int type, int count){ public void updateRandCount(int type, int count){

View File

@ -400,15 +400,6 @@ public class HeroLogic{
} }
//记录卡池抽奖次数 //记录卡池抽奖次数
heroManager.putRandomType(type,num+result[1]); heroManager.putRandomType(type,num+result[1]);
// 记录卡池,抽奖星级次数
SCHero scHero = SCHero.getsCHero().get(reward[0]);
if (scHero != null){
// 获取类型抽奖次数
Map<Integer, Integer> randomStar = heroManager.getRandomStar(type);
// 更新次数
randomStar.put(scHero.getStar(),randomStar.getOrDefault(scHero.getStar(),0)+result[1]);
heroManager.putRandomStar(type,randomStar);
}
return result; return result;
} }
@ -428,13 +419,21 @@ public class HeroLogic{
} }
// 非五星英雄 // 非五星英雄
SCHero scHero = SCHero.getsCHero().get(item[0]); SCHero scHero = SCHero.getsCHero().get(item[0]);
if (scHero.getStar() < 5){ if (scHero == null || scHero.getStar() < 5){
return item; return item;
} }
// 更新抽奖次数, 记录卡池
HeroManager heroManager = user.getHeroManager();
// 获取类型抽奖次数
Map<Integer, Integer> randomStar = heroManager.getWishStar(type);
// 更新次数
int num = heroManager.getWishStar(type).getOrDefault(scHero.getStar(), 0)+1;
randomStar.put(scHero.getStar(),num);
heroManager.putWishStar(type,randomStar);
/* ======================= 中不中心愿 ======================= */ /* ======================= 中不中心愿 ======================= */
// 获取钻石抽奖抽中五星的次数 // 获取钻石抽奖抽中五星的次数
int num = user.getHeroManager().getRandomStar(type).getOrDefault(5, 0)+1;
boolean randomBol = (num - 1) % 3 == 0; boolean randomBol = (num - 1) % 3 == 0;
LOGGER.error("*************************************是否中心愿;num:{},random:{}",num, randomBol);
if (!randomBol){ if (!randomBol){
// 不到次数,不走心愿 // 不到次数,不走心愿
return item; return item;
@ -447,18 +446,25 @@ public class HeroLogic{
// 计算权重map // 计算权重map
HashMap<Integer, Integer> map = new HashMap<>(); HashMap<Integer, Integer> map = new HashMap<>();
cardInfoMap.forEach((k,v)->{ cardInfoMap.forEach((k,v)->{
if (v.getStatus() == 0 && v.getHeroTid() != 0){ if (v.getStatus() == 0){
// 英雄格子 if (v.getHeroTid() == 0){
SCHero hero = SCHero.getsCHero().get(v.getHeroTid()); // 空格子
map.put(k,hero.getWeight()); map.put(k,empty);
}else { }else {
// 空格子 // 英雄格子
map.put(k,empty); int heroWeight = Optional.ofNullable(SCHero.getsCHero().get(v.getHeroTid())).map(SCHero::getWeight).orElse(0);
map.put(k,heroWeight);
}
} }
}); });
// 全部抽中
if (map.isEmpty()){
return item;
}
// 随机权重 // 随机权重
int weight = map.values().stream().mapToInt(Integer::intValue).sum(); int weight = map.values().stream().mapToInt(Integer::intValue).sum();
int randomInt = MathUtils.randomInt(weight); int randomInt = MathUtils.randomInt(weight);
LOGGER.error("*************************************心愿抽奖权重,总权重:{},随机值:{},map:{}",weight,randomInt,map.toString());
// 遍历权重 // 遍历权重
for (Map.Entry<Integer, Integer> entry : map.entrySet()) { for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (randomInt <= entry.getValue()){ if (randomInt <= entry.getValue()){