心愿抽卡优化
parent
80b1659cb1
commit
b2f31798b0
|
@ -78,9 +78,10 @@ public class HeroManager extends MongoBase {
|
|||
private Map<Integer,Integer> randomCountByType = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 心愿专用
|
||||
* 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() {
|
||||
return randomCountByType;
|
||||
|
@ -96,22 +97,22 @@ public class HeroManager extends MongoBase {
|
|||
updateString("randomCountByType."+type, value);
|
||||
}
|
||||
|
||||
public Map<Integer, Map<Integer, Integer>> getRandomCountByStar() {
|
||||
return randomCountByStar;
|
||||
public Map<Integer, Map<Integer, Integer>> getWishCountByStar() {
|
||||
return wishCountByStar;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getRandomStar(int type) {
|
||||
return randomCountByStar.getOrDefault(type,new HashMap<>());
|
||||
public Map<Integer, Integer> getWishStar(int type) {
|
||||
return wishCountByStar.getOrDefault(type,new HashMap<>());
|
||||
}
|
||||
|
||||
public void setRandomCountByStar(Map<Integer, Map<Integer, Integer>> randomCountByStar) {
|
||||
this.randomCountByStar = randomCountByStar;
|
||||
updateString("randomCountByStar", randomCountByStar);
|
||||
public void setWishCountByStar(Map<Integer, Map<Integer, Integer>> wishCountByStar) {
|
||||
this.wishCountByStar = wishCountByStar;
|
||||
updateString("wishCountByStar", wishCountByStar);
|
||||
}
|
||||
|
||||
public void putRandomStar(int type,Map<Integer,Integer> starMap) {
|
||||
randomCountByStar.put(type,starMap);
|
||||
updateString("randomCountByStar."+type, starMap);
|
||||
public void putWishStar(int type,Map<Integer,Integer> starMap) {
|
||||
wishCountByStar.put(type,starMap);
|
||||
updateString("wishCountByStar."+type, starMap);
|
||||
}
|
||||
|
||||
public void updateRandCount(int type, int count){
|
||||
|
|
|
@ -400,15 +400,6 @@ public class HeroLogic{
|
|||
}
|
||||
//记录卡池抽奖次数
|
||||
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;
|
||||
}
|
||||
|
@ -428,13 +419,21 @@ public class HeroLogic{
|
|||
}
|
||||
// 非五星英雄
|
||||
SCHero scHero = SCHero.getsCHero().get(item[0]);
|
||||
if (scHero.getStar() < 5){
|
||||
if (scHero == null || scHero.getStar() < 5){
|
||||
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;
|
||||
LOGGER.error("*************************************是否中心愿;num:{},random:{}",num, randomBol);
|
||||
if (!randomBol){
|
||||
// 不到次数,不走心愿
|
||||
return item;
|
||||
|
@ -447,18 +446,25 @@ public class HeroLogic{
|
|||
// 计算权重map
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
cardInfoMap.forEach((k,v)->{
|
||||
if (v.getStatus() == 0 && v.getHeroTid() != 0){
|
||||
// 英雄格子
|
||||
SCHero hero = SCHero.getsCHero().get(v.getHeroTid());
|
||||
map.put(k,hero.getWeight());
|
||||
}else {
|
||||
// 空格子
|
||||
map.put(k,empty);
|
||||
if (v.getStatus() == 0){
|
||||
if (v.getHeroTid() == 0){
|
||||
// 空格子
|
||||
map.put(k,empty);
|
||||
}else {
|
||||
// 英雄格子
|
||||
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 randomInt = MathUtils.randomInt(weight);
|
||||
LOGGER.error("*************************************心愿抽奖权重,总权重:{},随机值:{},map:{}",weight,randomInt,map.toString());
|
||||
// 遍历权重
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
if (randomInt <= entry.getValue()){
|
||||
|
|
Loading…
Reference in New Issue