back_recharge
zhangshanxue 2020-06-19 14:06:11 +08:00
commit a10139ed30
6 changed files with 99 additions and 177 deletions

View File

@ -62,7 +62,7 @@ public class CircleGame implements MapGame {
int[] id = MathUtils.randomFromWeightWithTaking(randomArray, 1);
//todo 需要告诉前端一个拿到的id
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()

View File

@ -11,25 +11,20 @@ import java.util.Map;
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;
public HeroManager() {
heroMap = new HashMap();
totalCount = new HashMap();
heroHandBook = new HashMap<>();
randomPoolByType = new HashMap<>();
mustRandomCount = new HashMap<>();
this.setRootCollection(User._COLLECTION_NAME);
}

View File

@ -598,7 +598,8 @@ public class GuildFightLogic {
* @throws Exception
*/
public static void familyFightStatus() throws Exception {
if(!GameApplication.serverProperties.isGuildFight()){
int isOpen = SSpecialConfig.getIntegerValue(SSpecialConfig.GUILD_WAR_ISOPEN);
if(isOpen==0){
return;
}
if (status == 2 && startMatching) {

View File

@ -184,6 +184,7 @@ public class HeroLogic{
public void random(ISession session,int type) throws Exception {
long time = System.currentTimeMillis();
int uid = session.getUid();
User user = UserManager.getUser(uid);
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
@ -207,24 +208,12 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
}
}
//筛选卡池
int pooId =0;
if(heroManager!=null&& heroManager.getHeroMap()!=null){
if(heroManager.getHeroMap().size() + perCount > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getHeroNumlimit()){
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;
int privilege = sLotterySetting.getFreeTimes();
@ -244,140 +233,109 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
}
// else{
// user.getPlayerInfoManager().updateVipPrivilage(privilege, 1);
// }
int[][] tenTimesMustGetItem = new int[perCount][];
//抽卡必得积分
int[][] tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
//所有获得物品
int[][] resultRandom = new int[perCount+tenTimesMustGetItem.length][];
//进行抽取
int index = 0;
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群英招募
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, tenTimesMustGetItem,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,perCount);
Poster.getPoster().dispatchEvent(new RandomCardEvent(uid,sLotterySetting.getLotteryType(),SSpecialConfig.getIntegerValue(SSpecialConfig.TIME_LIMIT_RECRUITMENT_INTEGRAL)*sLotterySetting.getPerCount(),resultRandom));
CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, resultRandom,BIReason.HERO_RANDOM);
builder.setDrop(drop);
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 {
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()){
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<>();
//次数计算
for(Map.Entry<Integer,Integer> countEntry:countMap.entrySet()){
SLotterySpecialConfig config = null;
if(specialConfigs==null||specialConfigs.isEmpty()){
continue;
Map<Integer, Map<Integer, Integer>> randomPoolByType = heroManager.getRandomPoolByType();
//设置用户必出计数器
if(specialConfigs!=null&&!specialConfigs.isEmpty()){
if(!randomPoolByType.containsKey(mergePool)){
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;
}
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(config.getMin_num()!=0&&mustRandomCount.get(countEntry.getKey())>=config.getMin_num()) {
continue;
//保底触发次数统计
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{
mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1);
}
}else{
mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1);
mustRandomCount.put(countEntry.getKey(),1);
}
}else{
mustRandomCount.put(countEntry.getKey(),1);
heroManager.setMustRandomCount(mustRandomCount);
mustSet.add(countEntry.getKey());
}
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()){
for(int key:randomPoolByType.get(mergePool).keySet()){
if(star==key){
countMap.put(key,0);
randomPoolByType.get(mergePool).put(key,0);
}else{
countMap.put(key,countMap.get(key)+1);
int curValue= randomPoolByType.get(mergePool).getOrDefault(key,0);
randomPoolByType.get(mergePool).put(key,curValue+1);
}
}
}else{
//有必出时比较各个优先级,取优先级高的
int maxId = 0;
for(int mustId:mustSet){
maxId = mustId;
@ -393,10 +351,10 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel());
countMap.put(maxId,0);
randomPoolByType.get(mergePool).put(maxId,0);
}
heroManager.updateRandomPoolByType(mergePool,countMap);
int result = sLotteryRewardConfig.getReward()[0];
heroManager.updateRandomPoolByType(mergePool,randomPoolByType.get(mergePool));
int result = sLotteryRewardConfig.getId();
System.out.print(result+"、");
return result;
}
@ -455,19 +413,19 @@ public class HeroLogic{
return 0;
}
public int getOrderBoxPoolId(SLotterySetting sLotterySetting) throws Exception {
int[] orderBoxPool = sLotterySetting.getOrderBoxPool();
int orderBoxOpenTime = sLotterySetting.getOrderBoxOpenTime();
int orderBoxContinue = sLotterySetting.getOrderBoxContinue();
long now = System.currentTimeMillis();
ServerConfig serverConfig = GameApplication.serverConfig;
int diffHours = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60%( (orderBoxOpenTime + orderBoxContinue)));
int diffSeaseon = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60/( (orderBoxOpenTime + orderBoxContinue)));
if(diffHours>=orderBoxOpenTime){
return orderBoxPool[diffSeaseon%orderBoxPool.length];
}
return 0;
}
// public int getOrderBoxPoolId(SLotterySetting sLotterySetting) throws Exception {
// int[] orderBoxPool = sLotterySetting.getOrderBoxPool();
// int orderBoxOpenTime = sLotterySetting.getOrderBoxOpenTime();
// int orderBoxContinue = sLotterySetting.getOrderBoxContinue();
// long now = System.currentTimeMillis();
// ServerConfig serverConfig = GameApplication.serverConfig;
// int diffHours = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60%( (orderBoxOpenTime + orderBoxContinue)));
// int diffSeaseon = (int)((now - serverConfig.getCacheOpenTime())/1000/60/60/( (orderBoxOpenTime + orderBoxContinue)));
// if(diffHours>=orderBoxOpenTime){
// return orderBoxPool[diffSeaseon%orderBoxPool.length];
// }
// return 0;
// }

View File

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

View File

@ -65,6 +65,7 @@ public class SSpecialConfig implements BaseConfig {
public static final String EXPEDITION_REBORN = "expedition_reborn";// 大闹天宫复活道具id
public static final String REWARD_OF_WORSHIP = "reward_of_worship";//膜拜获得金币奖励
public static final String DISCOUNT_LEVEL= "discount_level";//限时折扣推送等级#推送间隔等级
public static final String GUILD_WAR_ISOPEN = "Guild_war_isopen";//老公会战是否开启
@Override
public void init() throws Exception {