抽卡修改

back_recharge
lvxinran 2020-06-19 13:33:19 +08:00
parent 1e7bea7b90
commit f8a2ad6a32
4 changed files with 96 additions and 176 deletions

View File

@ -62,7 +62,7 @@ public class CircleGame implements MapGame {
int[] id = MathUtils.randomFromWeightWithTaking(randomArray, 1); int[] id = MathUtils.randomFromWeightWithTaking(randomArray, 1);
//todo 需要告诉前端一个拿到的id //todo 需要告诉前端一个拿到的id
STrialGameConfig config = STrialGameConfig.trialGameConfigMap.get(id[0]); STrialGameConfig config = STrialGameConfig.trialGameConfigMap.get(id[0]);
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{{id[0], config.getMin()}}, BIReason.MAP_EVENET_REWARD); CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{{config.getRewardID(), config.getMin()}}, BIReason.MAP_EVENET_REWARD);
MapInfoProto.MapGameUpdateResponse response = MapInfoProto.MapGameUpdateResponse.newBuilder() MapInfoProto.MapGameUpdateResponse response = MapInfoProto.MapGameUpdateResponse.newBuilder()

View File

@ -11,25 +11,20 @@ import java.util.Map;
public class HeroManager extends MongoBase { public class HeroManager extends MongoBase {
private Map<String, Hero> heroMap; private Map<String, Hero> heroMap= new HashMap<>();
Map<Integer, Integer> totalCount; private Map<Integer, Integer> totalCount= new HashMap<>();
private Map<Integer, Map<Integer, Integer>> randomPoolByType; private Map<Integer, Map<Integer, Integer>> randomPoolByType = new HashMap<>();
private Map<Integer,Integer> mustRandomCount; private Map<Integer,Integer> mustRandomCount= new HashMap<>();
Map<Integer,Integer> heroHandBook; private Map<Integer,Integer> heroHandBook = new HashMap<>();
private int firstTenth; private int firstTenth;
public HeroManager() { public HeroManager() {
heroMap = new HashMap();
totalCount = new HashMap();
heroHandBook = new HashMap<>();
randomPoolByType = new HashMap<>();
mustRandomCount = new HashMap<>();
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
} }

View File

@ -184,6 +184,7 @@ public class HeroLogic{
public void random(ISession session,int type) throws Exception { public void random(ISession session,int type) throws Exception {
long time = System.currentTimeMillis();
int uid = session.getUid(); int uid = session.getUid();
User user = UserManager.getUser(uid); User user = UserManager.getUser(uid);
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type); SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
@ -207,24 +208,12 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN); throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
} }
} }
//筛选卡池
int pooId =0;
if(heroManager!=null&& heroManager.getHeroMap()!=null){ if(heroManager!=null&& heroManager.getHeroMap()!=null){
if(heroManager.getHeroMap().size() + perCount > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getHeroNumlimit()){ if(heroManager.getHeroMap().size() + perCount > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getHeroNumlimit()){
throw new ErrorCodeException(ErrorCode.HERO_MAX); throw new ErrorCodeException(ErrorCode.HERO_MAX);
} }
} }
if(sLotterySetting.getOrderBoxPool()!=null && sLotterySetting.getOrderBoxPool().length>0){
pooId = getOrderBoxPoolId(sLotterySetting);
if(pooId == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("pooId 0"));
}
}
//检验消耗 //检验消耗
boolean allowFree = false; boolean allowFree = false;
int privilege = sLotterySetting.getFreeTimes(); int privilege = sLotterySetting.getFreeTimes();
@ -244,140 +233,109 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH); throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
} }
} }
// else{
// user.getPlayerInfoManager().updateVipPrivilage(privilege, 1); //抽卡必得积分
// } int[][] tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
int[][] tenTimesMustGetItem = new int[perCount][]; //所有获得物品
int[][] resultRandom = new int[perCount+tenTimesMustGetItem.length][];
//进行抽取
int index = 0;
for(int i = 0 ;i<perCount;i++){ for(int i = 0 ;i<perCount;i++){
tenTimesMustGetItem[i] = new int[]{randomOne(user,type),1}; int rewardId = randomOne(user, type);
SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
resultRandom[i] =sLotteryRewardConfig.getReward();
index = i;
}
for(int i = 0;i<tenTimesMustGetItem.length;i++) {
resultRandom[i+index+1] = tenTimesMustGetItem[i];
} }
// if(sLotterySetting.getTenTimesMustGetItem()!=null &&sLotterySetting.getTenTimesMustGetItem().length>0){
// tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
// length+=tenTimesMustGetItem.length;
// }
// int[][] dropHeroAndItem = new int[length][];
// int randCount = 0;
// int poolCount = 0;
// Map<Integer, Integer> totalCountMap = heroManager.getTotalCount();
// Map<Integer, Integer> randomPoolByType = heroManager.getRandomPoolByType();
// if (totalCountMap.containsKey(type)) {
// randCount = totalCountMap.get(type);
// }
// if (randomPoolByType.containsKey(sLotterySetting.getMergePool())) {
// poolCount = randomPoolByType.get(sLotterySetting.getMergePool());
// }
// int totalCount = 0;
// for(Integer count : totalCountMap.values()){
// totalCount+=count;
// }
//
// int j=0;
//// //标记是否触发保底
//// boolean specialTrigger=false;
// for(int i=0;i<perCount;i++){
// randCount++;
// poolCount++;
// int randomPoolId = pooId;
// int specialPoolId = getSpecialPoolByRandcount(sLotterySetting, randCount,poolCount);
// if(specialPoolId == 0){
// if(randomPoolId==0){
// randomPoolId = getPooId(sLotterySetting);
// }
// }else{
// randomPoolId =specialPoolId;
// }
// totalCount++;
// SLotteryRewardConfig sLotteryRewardConfig = randomHeroByPoolId(randomPoolId, totalCount, user.getPlayerInfoManager().getLevel());
// LOGGER.info("the uid={},the type={},the poolId={},reward={},poolCount={}",uid,type,randomPoolId,sLotteryRewardConfig.getId(),poolCount);
// if(sLotteryRewardConfig.getStar() == 1){
// poolCount=0;
// }
// int[] reward =sLotteryRewardConfig.getReward();
// if(reward!=null){
// dropHeroAndItem[j++] = reward;
// }
// }
// heroManager.updateRandPoolTypeCount(sLotterySetting.getMergePool(),poolCount);
//
// //1群英招募 // //1群英招募
HeroInfoProto.HeroRandResponse.Builder builder = HeroInfoProto.HeroRandResponse.newBuilder(); HeroInfoProto.HeroRandResponse.Builder builder = HeroInfoProto.HeroRandResponse.newBuilder();
// if(sLotterySetting.getLotteryType() == 1){ if(sLotterySetting.getLotteryType() == 1){
// Poster.getPoster().dispatchEvent(new HeroRandomEvent(uid,perCount)); Poster.getPoster().dispatchEvent(new HeroRandomEvent(uid,perCount));
// } }
// user.getUserMissionManager().onGameEvent(user,GameEvent.RANDOM_HERO,sLotterySetting.getLotteryType(),perCount); user.getUserMissionManager().onGameEvent(user,GameEvent.RANDOM_HERO,sLotterySetting.getLotteryType(),perCount);
// heroManager.updateRandCount(type,randCount); heroManager.updateRandCount(type,perCount);
// if(tenTimesMustGetItem!=null){ Poster.getPoster().dispatchEvent(new RandomCardEvent(uid,sLotterySetting.getLotteryType(),SSpecialConfig.getIntegerValue(SSpecialConfig.TIME_LIMIT_RECRUITMENT_INTEGRAL)*sLotterySetting.getPerCount(),resultRandom));
// for(int i=0;i<tenTimesMustGetItem.length;i++){ CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, resultRandom,BIReason.HERO_RANDOM);
// dropHeroAndItem[j++] = tenTimesMustGetItem[i];
// }
// }
// Poster.getPoster().dispatchEvent(new RandomCardEvent(uid,sLotterySetting.getLotteryType(),SSpecialConfig.getIntegerValue(SSpecialConfig.TIME_LIMIT_RECRUITMENT_INTEGRAL)*sLotterySetting.getPerCount(),dropHeroAndItem));
CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, tenTimesMustGetItem,BIReason.HERO_RANDOM);
builder.setDrop(drop); builder.setDrop(drop);
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.HERO_RAND_RESPONSE_VALUE, builder.build(), true); MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.HERO_RAND_RESPONSE_VALUE, builder.build(), true);
System.out.println(System.currentTimeMillis()-time);
} }
/**
*
* @param user
* @param type
* @return
* @throws Exception
*/
private int randomOne(User user,int type) throws Exception { private int randomOne(User user,int type) throws Exception {
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type); SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
int mergePool = sLotterySetting.getMergePool(); int mergePool = sLotterySetting.getMergePool();
List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool); List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
HeroManager heroManager = user.getHeroManager(); HeroManager heroManager = user.getHeroManager();
//设置必出计数器
if(specialConfigs!=null&&!specialConfigs.isEmpty()){
if(!heroManager.getRandomPoolByType().containsKey(mergePool)){
heroManager.getRandomPoolByType().put(mergePool,new HashMap<>());
for(SLotterySpecialConfig config:specialConfigs){
heroManager.getRandomPoolByType().get(mergePool).put(config.getDifferentType(),0);
// heroManager.getRandomPoolByType().computeIfAbsent(mergePool,n->new HashMap<>()).put(config.getId(),0);
}
}
}
Map<Integer, Integer> countMap = heroManager.getRandomPoolByType().get(mergePool);
Set<Integer> mustSet = new HashSet<>(); Set<Integer> mustSet = new HashSet<>();
//次数计算 Map<Integer, Map<Integer, Integer>> randomPoolByType = heroManager.getRandomPoolByType();
for(Map.Entry<Integer,Integer> countEntry:countMap.entrySet()){ //设置用户必出计数器
SLotterySpecialConfig config = null; if(specialConfigs!=null&&!specialConfigs.isEmpty()){
if(specialConfigs==null||specialConfigs.isEmpty()){ if(!randomPoolByType.containsKey(mergePool)){
continue; randomPoolByType.put(mergePool,new HashMap<>());
for(SLotterySpecialConfig config:specialConfigs){
randomPoolByType.get(mergePool).put(config.getDifferentType(),0);
}
} }
for(SLotterySpecialConfig everyConfig:specialConfigs){ //保底次数计算
if(everyConfig.getDifferentType()!=countEntry.getKey()){ for(Map.Entry<Integer,Integer> countEntry:randomPoolByType.get(mergePool).entrySet()){
SLotterySpecialConfig config = null;
// if(specialConfigs.isEmpty()){
// continue;
// }
for(SLotterySpecialConfig everyConfig:specialConfigs){
if(everyConfig.getDifferentType()!=countEntry.getKey()){
continue;
}
config = everyConfig;
}
if(config==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
//本次是否触发保底
if(countEntry.getValue()+1<config.getCount()){
continue; continue;
} }
config = everyConfig; //保底触发次数统计
} Map<Integer, Integer> mustRandomCount = heroManager.getMustRandomCount();
if(config==null){ if(mustRandomCount.containsKey(countEntry.getKey())) {
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); //是否已经到了保底触发上限
} if(config.getMin_num()!=0&&mustRandomCount.get(countEntry.getKey())>=config.getMin_num()) {
if(countEntry.getValue()+1<config.getCount()){ continue;
continue; }else{
} mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1);
Map<Integer, Integer> mustRandomCount = heroManager.getMustRandomCount(); }
if(mustRandomCount.containsKey(countEntry.getKey())) {
if(config.getMin_num()!=0&&mustRandomCount.get(countEntry.getKey())>=config.getMin_num()) {
continue;
}else{ }else{
mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1); mustRandomCount.put(countEntry.getKey(),1);
} }
}else{ heroManager.setMustRandomCount(mustRandomCount);
mustRandomCount.put(countEntry.getKey(),1); mustSet.add(countEntry.getKey());
} }
heroManager.setMustRandomCount(mustRandomCount);
mustSet.add(countEntry.getKey());
} }
SLotteryRewardConfig sLotteryRewardConfig; SLotteryRewardConfig sLotteryRewardConfig;
//是否有必出 //是否有必出
if(mustSet.isEmpty()){ if(mustSet.isEmpty()){
sLotteryRewardConfig = randomHeroByPoolId(getPooId(sLotterySetting), 1, user.getPlayerInfoManager().getLevel()); sLotteryRewardConfig = randomHeroByPoolId(getPooId(sLotterySetting), 1, user.getPlayerInfoManager().getLevel());
int star = sLotteryRewardConfig.getStar(); int star = sLotteryRewardConfig.getStar();
for(int key:countMap.keySet()){ for(int key:randomPoolByType.get(mergePool).keySet()){
if(star==key){ if(star==key){
countMap.put(key,0); randomPoolByType.get(mergePool).put(key,0);
}else{ }else{
countMap.put(key,countMap.get(key)+1); int curValue= randomPoolByType.get(mergePool).getOrDefault(key,0);
randomPoolByType.get(mergePool).put(key,curValue+1);
} }
} }
}else{ }else{
//有必出时比较各个优先级,取优先级高的
int maxId = 0; int maxId = 0;
for(int mustId:mustSet){ for(int mustId:mustSet){
maxId = mustId; maxId = mustId;
@ -393,10 +351,10 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
} }
sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel()); sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel());
countMap.put(maxId,0); randomPoolByType.get(mergePool).put(maxId,0);
} }
heroManager.updateRandomPoolByType(mergePool,countMap); heroManager.updateRandomPoolByType(mergePool,randomPoolByType.get(mergePool));
int result = sLotteryRewardConfig.getReward()[0]; int result = sLotteryRewardConfig.getId();
System.out.print(result+"、"); System.out.print(result+"、");
return result; return result;
} }
@ -455,19 +413,19 @@ public class HeroLogic{
return 0; return 0;
} }
public int getOrderBoxPoolId(SLotterySetting sLotterySetting) throws Exception { // public int getOrderBoxPoolId(SLotterySetting sLotterySetting) throws Exception {
int[] orderBoxPool = sLotterySetting.getOrderBoxPool(); // int[] orderBoxPool = sLotterySetting.getOrderBoxPool();
int orderBoxOpenTime = sLotterySetting.getOrderBoxOpenTime(); // int orderBoxOpenTime = sLotterySetting.getOrderBoxOpenTime();
int orderBoxContinue = sLotterySetting.getOrderBoxContinue(); // int orderBoxContinue = sLotterySetting.getOrderBoxContinue();
long now = System.currentTimeMillis(); // long now = System.currentTimeMillis();
ServerConfig serverConfig = GameApplication.serverConfig; // ServerConfig serverConfig = GameApplication.serverConfig;
int diffHours = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60%( (orderBoxOpenTime + orderBoxContinue))); // int diffHours = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60%( (orderBoxOpenTime + orderBoxContinue)));
int diffSeaseon = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60/( (orderBoxOpenTime + orderBoxContinue))); // int diffSeaseon = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60/( (orderBoxOpenTime + orderBoxContinue)));
if(diffHours>=orderBoxOpenTime){ // if(diffHours>=orderBoxOpenTime){
return orderBoxPool[diffSeaseon%orderBoxPool.length]; // return orderBoxPool[diffSeaseon%orderBoxPool.length];
} // }
return 0; // return 0;
} // }

View File

@ -7,19 +7,10 @@ public class SLotterySetting implements BaseConfig {
private int id; private int id;
private int orderBoxOpenTime;
private int orderBoxContinue;
private int orderBoxInterval;
private int[] orderBoxPool;
private int diamondBoxInterval; private int diamondBoxInterval;
private int[][] cost; private int[][] cost;
private int getHerosInterval;
private int[][] diamondBoxContain; private int[][] diamondBoxContain;
@ -33,8 +24,6 @@ public class SLotterySetting implements BaseConfig {
private int mergePool; private int mergePool;
private int[][] tenTimesMustGetBox;
private int activityId; private int activityId;
private int freeTimes; private int freeTimes;
@ -52,22 +41,6 @@ public class SLotterySetting implements BaseConfig {
return id; return id;
} }
public int getOrderBoxOpenTime() {
return orderBoxOpenTime;
}
public int getOrderBoxContinue() {
return orderBoxContinue;
}
public int getOrderBoxInterval() {
return orderBoxInterval;
}
public int[] getOrderBoxPool() {
return orderBoxPool;
}
public int getDiamondBoxInterval() { public int getDiamondBoxInterval() {
return diamondBoxInterval; return diamondBoxInterval;
} }
@ -76,9 +49,6 @@ public class SLotterySetting implements BaseConfig {
return cost; return cost;
} }
public int getGetHerosInterval() {
return getHerosInterval;
}
public int[][] getDiamondBoxContain() { public int[][] getDiamondBoxContain() {
return diamondBoxContain; return diamondBoxContain;
@ -104,9 +74,6 @@ public class SLotterySetting implements BaseConfig {
return mergePool; return mergePool;
} }
public int[][] getTenTimesMustGetBox() {
return tenTimesMustGetBox;
}
public int getActivityId() { public int getActivityId() {
return activityId; return activityId;