抽卡逻辑修改
parent
7c0e200d18
commit
06ba20787b
|
@ -15,7 +15,9 @@ public class HeroManager extends MongoBase {
|
|||
|
||||
Map<Integer, Integer> totalCount;
|
||||
|
||||
Map<Integer, Integer> randomPoolByType;
|
||||
private Map<Integer, Map<Integer, Integer>> randomPoolByType;
|
||||
|
||||
private Map<Integer,Integer> mustRandomCount;
|
||||
|
||||
Map<Integer,Integer> heroHandBook;
|
||||
|
||||
|
@ -27,6 +29,7 @@ public class HeroManager extends MongoBase {
|
|||
totalCount = new HashMap();
|
||||
heroHandBook = new HashMap<>();
|
||||
randomPoolByType = new HashMap<>();
|
||||
mustRandomCount = new HashMap<>();
|
||||
this.setRootCollection(User._COLLECTION_NAME);
|
||||
}
|
||||
|
||||
|
@ -35,9 +38,15 @@ public class HeroManager extends MongoBase {
|
|||
totalCount.put(type,count);
|
||||
}
|
||||
|
||||
public void updateRandPoolTypeCount(int mergePool,int count){
|
||||
updateString("randomPoolByType." + mergePool, count);
|
||||
randomPoolByType.put(mergePool,count);
|
||||
public void updateRandPoolTypeCount(int type,int profession,int count){
|
||||
updateString("randomPoolByType." + type+"."+profession, count);
|
||||
randomPoolByType.get(type).put(profession,count);
|
||||
}
|
||||
|
||||
public void updateRandomPoolByType(int type,Map<Integer,Integer> map){
|
||||
randomPoolByType.put(type,map);
|
||||
updateString("randomPoolByType." + type, map);
|
||||
|
||||
}
|
||||
|
||||
public Map<String, Hero> getItemMap() {
|
||||
|
@ -104,7 +113,16 @@ public class HeroManager extends MongoBase {
|
|||
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getRandomPoolByType() {
|
||||
public Map<Integer, Map<Integer, Integer>> getRandomPoolByType() {
|
||||
return randomPoolByType;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getMustRandomCount() {
|
||||
return mustRandomCount;
|
||||
}
|
||||
|
||||
public void setMustRandomCount(Map<Integer, Integer> mustRandomCount) {
|
||||
this.mustRandomCount = mustRandomCount;
|
||||
updateString("mustRandomCount",mustRandomCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.ljsd.jieling.chat.logic.ChatLogic;
|
|||
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
|
||||
import com.ljsd.jieling.config.clazzStaticCfg.HeroStaticConfig;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.core.SimpleTransaction;
|
||||
import com.ljsd.jieling.core.VipPrivilegeType;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
|
@ -45,6 +43,7 @@ import java.math.BigDecimal;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HeroLogic{
|
||||
|
@ -248,81 +247,158 @@ public class HeroLogic{
|
|||
// else{
|
||||
// user.getPlayerInfoManager().updateVipPrivilage(privilege, 1);
|
||||
// }
|
||||
//额外获取
|
||||
int length = perCount;
|
||||
int[][] tenTimesMustGetItem = null;
|
||||
if(sLotterySetting.getTenTimesMustGetItem()!=null &&sLotterySetting.getTenTimesMustGetItem().length>0){
|
||||
tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
|
||||
length+=tenTimesMustGetItem.length;
|
||||
int[][] tenTimesMustGetItem = new int[perCount][];
|
||||
for(int i = 0 ;i<perCount;i++){
|
||||
tenTimesMustGetItem[i] = new int[]{randomOne(user,type),1};
|
||||
}
|
||||
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群英招募
|
||||
// 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群英招募
|
||||
HeroInfoProto.HeroRandResponse.Builder builder = HeroInfoProto.HeroRandResponse.newBuilder();
|
||||
if(sLotterySetting.getLotteryType() == 1){
|
||||
Poster.getPoster().dispatchEvent(new HeroRandomEvent(uid,perCount));
|
||||
}
|
||||
user.getUserMissionManager().onGameEvent(user,GameEvent.RANDOM_HERO,sLotterySetting.getLotteryType(),perCount);
|
||||
heroManager.updateRandCount(type,randCount);
|
||||
if(tenTimesMustGetItem!=null){
|
||||
for(int i=0;i<tenTimesMustGetItem.length;i++){
|
||||
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, dropHeroAndItem,BIReason.HERO_RANDOM);
|
||||
// if(sLotterySetting.getLotteryType() == 1){
|
||||
// Poster.getPoster().dispatchEvent(new HeroRandomEvent(uid,perCount));
|
||||
// }
|
||||
// user.getUserMissionManager().onGameEvent(user,GameEvent.RANDOM_HERO,sLotterySetting.getLotteryType(),perCount);
|
||||
// heroManager.updateRandCount(type,randCount);
|
||||
// if(tenTimesMustGetItem!=null){
|
||||
// for(int i=0;i<tenTimesMustGetItem.length;i++){
|
||||
// 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);
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.HERO_RAND_RESPONSE_VALUE, builder.build(), true);
|
||||
}
|
||||
private int randomOne(User user,int type) throws Exception {
|
||||
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
|
||||
int mergePool = sLotterySetting.getMergePool();
|
||||
List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
|
||||
HeroManager heroManager = user.getHeroManager();
|
||||
//设置必出计数器
|
||||
if(specialConfigs!=null&&!specialConfigs.isEmpty()){
|
||||
for(SLotterySpecialConfig config:specialConfigs){
|
||||
if(!heroManager.getRandomPoolByType().containsKey(mergePool)){
|
||||
Map<Integer,Integer> map = new HashMap<>();
|
||||
map.put(config.getDifferentType(),0);
|
||||
heroManager.getRandomPoolByType().put(mergePool,new HashMap<>());
|
||||
}
|
||||
// heroManager.getRandomPoolByType().computeIfAbsent(mergePool,n->new HashMap<>()).put(config.getId(),0);
|
||||
}
|
||||
}
|
||||
Map<Integer, Integer> countMap = heroManager.getRandomPoolByType().get(mergePool);
|
||||
Set<Integer> mustSet = new HashSet<>();
|
||||
//次数计算
|
||||
for(Map.Entry<Integer,Integer> countEntry:countMap.entrySet()){
|
||||
SLotterySpecialConfig config = null;
|
||||
if(specialConfigs==null||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;
|
||||
}
|
||||
Map<Integer, Integer> mustRandomCount = heroManager.getMustRandomCount();
|
||||
if(mustRandomCount.containsKey(countEntry.getKey())) {
|
||||
if(mustRandomCount.get(countEntry.getKey())>=config.getMin_num()) {
|
||||
continue;
|
||||
}else{
|
||||
mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1);
|
||||
}
|
||||
}else{
|
||||
mustRandomCount.put(countEntry.getKey(),1);
|
||||
}
|
||||
heroManager.setMustRandomCount(mustRandomCount);
|
||||
mustSet.add(countEntry.getKey());
|
||||
}
|
||||
|
||||
SLotteryRewardConfig sLotteryRewardConfig;
|
||||
//是否有必出
|
||||
if(mustSet.isEmpty()){
|
||||
sLotteryRewardConfig = randomHeroByPoolId(getPooId(sLotterySetting), 1, user.getPlayerInfoManager().getLevel());
|
||||
int star = sLotteryRewardConfig.getStar();
|
||||
for(int key:countMap.keySet()){
|
||||
if(star==key){
|
||||
countMap.put(key,0);
|
||||
}else{
|
||||
countMap.put(key,countMap.get(key)+1);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
int maxId = 0;
|
||||
for(int mustId:mustSet){
|
||||
maxId = mustId;
|
||||
}
|
||||
|
||||
sLotteryRewardConfig = randomHeroByPoolId(STableManager.getConfig(SLotterySpecialConfig.class).get(maxId).getpool_id(), 1, user.getPlayerInfoManager().getLevel());
|
||||
countMap.put(maxId,0);
|
||||
}
|
||||
heroManager.updateRandomPoolByType(mergePool,countMap);
|
||||
int result = sLotteryRewardConfig.getReward()[0];
|
||||
System.out.print(result+"、");
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getSpecialPoolByRandcount(SLotterySetting sLotterySetting, int randCount,int poolCount) {
|
||||
int id = sLotterySetting.getId();
|
||||
List<SLotterySpecialConfig> list = SLotterySpecialConfig.getLotterySpecialConfigListByType(1,id);
|
||||
List<SLotterySpecialConfig> list = SLotterySpecialConfig.getLotterySpecialConfigListByType(id);
|
||||
|
||||
if (list == null) {
|
||||
list = SLotterySpecialConfig.getLotterySpecialConfigListByType(2,sLotterySetting.getMergePool());
|
||||
list = SLotterySpecialConfig.getLotterySpecialConfigListByType(sLotterySetting.getMergePool());
|
||||
if(list == null){
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -26,32 +26,33 @@ public class SLotterySpecialConfig implements BaseConfig {
|
|||
private int pool_id;
|
||||
|
||||
|
||||
private static Map<Integer, Map<Integer,List<SLotterySpecialConfig>>> lotterySpecialConfigMap;
|
||||
private static Map<Integer, List<SLotterySpecialConfig>> lotterySpecialConfigMap;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Map<Integer, SLotterySpecialConfig> config = STableManager.getConfig(SLotterySpecialConfig.class);
|
||||
Map<Integer, Map<Integer,List<SLotterySpecialConfig>>> lotterySpecialConfigMapTmp = new HashMap<>();
|
||||
Map<Integer, List<SLotterySpecialConfig>> lotterySpecialConfigMapTmp = new HashMap<>();
|
||||
for(SLotterySpecialConfig sLotterySpecialConfig : config.values()){
|
||||
int differentType = sLotterySpecialConfig.getDifferentType();
|
||||
if(!lotterySpecialConfigMapTmp.containsKey(differentType)){
|
||||
lotterySpecialConfigMapTmp.put(differentType,new HashMap<>());
|
||||
}
|
||||
int type = sLotterySpecialConfig.getType();
|
||||
if(!lotterySpecialConfigMapTmp.get(differentType).containsKey(type)){
|
||||
lotterySpecialConfigMapTmp.get(differentType).put(type,new ArrayList<>());
|
||||
}
|
||||
lotterySpecialConfigMapTmp.get(differentType).get(type).add(sLotterySpecialConfig);
|
||||
// int differentType = sLotterySpecialConfig.getDifferentType();
|
||||
// if(!lotterySpecialConfigMapTmp.containsKey(differentType)){
|
||||
// lotterySpecialConfigMapTmp.put(differentType,new HashMap<>());
|
||||
// }
|
||||
// int type = sLotterySpecialConfig.getType();
|
||||
// if(!lotterySpecialConfigMapTmp.get(differentType).containsKey(type)){
|
||||
// lotterySpecialConfigMapTmp.get(differentType).put(type,new ArrayList<>());
|
||||
// }
|
||||
// lotterySpecialConfigMapTmp.get(differentType).get(type).add(sLotterySpecialConfig);
|
||||
lotterySpecialConfigMapTmp.computeIfAbsent(sLotterySpecialConfig.getType(),n->new ArrayList<>()).add(sLotterySpecialConfig);
|
||||
}
|
||||
lotterySpecialConfigMap = lotterySpecialConfigMapTmp;
|
||||
}
|
||||
|
||||
public static List<SLotterySpecialConfig> getLotterySpecialConfigListByType(int differentType,int type) {
|
||||
if(!lotterySpecialConfigMap.containsKey(differentType)){
|
||||
public static List<SLotterySpecialConfig> getLotterySpecialConfigListByType(int type) {
|
||||
if(!lotterySpecialConfigMap.containsKey(type)){
|
||||
return null;
|
||||
}
|
||||
return lotterySpecialConfigMap.get(differentType).get(type);
|
||||
return lotterySpecialConfigMap.get(type);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
Loading…
Reference in New Issue