Merge branch 'dh_dev_wishDrawCard' into master_test_gn

back_recharge
duhui 2021-07-15 16:33:54 +08:00
commit 5c69363203
4 changed files with 79 additions and 43 deletions

View File

@ -272,7 +272,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
if (num < value){
// 修改次数
user.getHeroManager().putRandomCount(1,value);
user.getHeroManager().putRandomType(1,value);
}
}
}

View File

@ -1,17 +1,11 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.activity.event.RemoveHeroEvent;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HongMengAttributeEnum;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.MessageUtil;
import config.SSpecialConfig;
import rpc.protocols.HeroInfoProto;
import rpc.protocols.MessageTypeProto;
import java.util.*;
@ -83,6 +77,12 @@ public class HeroManager extends MongoBase {
*/
private Map<Integer,Integer> randomCountByType = new HashMap<>();
/**
*
* key: value:< key: value: >
*/
private Map<Integer, Map<Integer,Integer>> wishCountByStar = new HashMap<>();
public Map<Integer, Integer> getRandomCountByType() {
return randomCountByType;
}
@ -92,12 +92,30 @@ public class HeroManager extends MongoBase {
updateString("randomCountByType", randomCountByType);
}
public void putRandomCount(int type,int value) {
public void putRandomType(int type,int value) {
randomCountByType.put(type,value);
updateString("randomCountByType."+type, value);
}
public void updateRandCount(int type,int count){
public Map<Integer, Map<Integer, Integer>> getWishCountByStar() {
return wishCountByStar;
}
public Map<Integer, Integer> getWishStar(int type) {
return wishCountByStar.getOrDefault(type,new HashMap<>());
}
public void setWishCountByStar(Map<Integer, Map<Integer, Integer>> wishCountByStar) {
this.wishCountByStar = wishCountByStar;
updateString("wishCountByStar", wishCountByStar);
}
public void putWishStar(int type,Map<Integer,Integer> starMap) {
wishCountByStar.put(type,starMap);
updateString("wishCountByStar."+type, starMap);
}
public void updateRandCount(int type, int count){
updateString("totalCount." + type, count);
totalCount.put(type,count);
}

View File

@ -383,19 +383,24 @@ public class HeroLogic{
*/
private int[] drawCard(User user, SLotteryRewardConfig sLotteryRewardConfig, SLotterySetting sLotterySetting){
HeroManager heroManager = user.getHeroManager();
// 限制次数
// 参数
int type = sLotterySetting.getLotteryType();
int[] reward = sLotteryRewardConfig.getReward();
// 限制满足次数
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
// 对应卡池抽奖次数
Integer num = heroManager.getRandomCountByType().getOrDefault(sLotterySetting.getLotteryType(),0);
Integer num = heroManager.getRandomCountByType().getOrDefault(type,0);
// 心愿抽卡
int[] result;
if (sLotterySetting.getLotteryType() == 1 && num >= value){
result = wishDrawCardCheck(user,sLotteryRewardConfig.getReward());
if (type == 1 && num >= value){
// 钻石抽卡并且次数满足
result = wishDrawCardCheck(user,reward,type);
}else {
result = sLotteryRewardConfig.getReward();
result = reward;
}
//记录次数
heroManager.putRandomCount(sLotterySetting.getLotteryType(),num+1);
//记录卡池抽奖次数
heroManager.putRandomType(type,num+result[1]);
return result;
}
@ -405,7 +410,7 @@ public class HeroLogic{
* @param item
* @return
*/
private int[] wishDrawCardCheck(User user,int[] item){
private int[] wishDrawCardCheck(User user,int[] item,int type){
// 查找物品
SItem sItem = SItem.getsItemMap().get(item[0]);
// 非英雄奖励直接返回
@ -414,45 +419,52 @@ 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 totalNum = 10000;
int anInt = MathUtils.randomInt(totalNum);
// 单个格子权重
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.CARDWISHBLOCKRATE);
// 获取玩家现在的心愿格子信息
Map<Integer, WishDrawCardInfo> cardInfoMap = user.getHeroManager().getWishDrawCardInfoMap();
// 中将权重值
int weight = cardInfoMap.size() * value;
// 未中奖
if (anInt > weight){
// 获取钻石抽奖抽中五星的次数
boolean randomBol = (num - 1) % 3 == 0;
LOGGER.error("*************************************是否中心愿;num:{},random:{}",num, randomBol);
if (!randomBol){
// 不到次数,不走心愿
return item;
}
/*======================== 中心愿随机奖励 ========================*/
// 心愿格子信息
HashMap<Integer, WishDrawCardInfo> cardInfoMap = user.getHeroManager().getWishDrawCardInfoMap();
// 空格子权重
int empty = SSpecialConfig.getIntegerValue(SSpecialConfig.CARDWISHBLOCKRATE);
// 计算权重map
HashMap<Integer, Integer> map = new HashMap<>();
for (Integer key : cardInfoMap.keySet()) {
if (cardInfoMap.get(key).getStatus() == 1){
// 已经抽中得格子去除
weight-=value;
continue;
cardInfoMap.forEach((k,v)->{
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);
}
}
map.put(key,value);
}
});
// 全部抽中
if (map.isEmpty() || weight == 0){
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()){

View File

@ -60,6 +60,8 @@ public class SCHero implements BaseConfig{
private int maxLevel;
private int weight;
private Map<Integer,Integer> secondaryFactorMap;
private Map<Integer, List<Integer>> skillListByStar;
@ -348,4 +350,8 @@ public class SCHero implements BaseConfig{
public int getMaxLevel() {
return maxLevel;
}
public int getWeight() {
return weight;
}
}