抽卡计次修改

back_recharge
lvxinran 2021-01-28 16:41:54 +08:00
parent 2fb09e6844
commit 50824acdd9
2 changed files with 15 additions and 216 deletions

View File

@ -552,7 +552,21 @@ public class HeroLogic{
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel());
randomPoolByType.get(mergePool).put(maxId,0);
if(mustSet.size() > 1){
//如果同时触发多个 把所有的计数清零
for(int mustId:mustSet){
randomPoolByType.get(mergePool).put(mustId,0);
}
}else{
//如果只触发一个仍把其他的计数加1
for (int key : randomPoolByType.get(mergePool).keySet()) {
if(maxId != key){
int curValue = randomPoolByType.get(mergePool).getOrDefault(key, 0);
randomPoolByType.get(mergePool).put(key, curValue + 1);
}
}
randomPoolByType.get(mergePool).put(maxId,0);
}
}
heroManager.updateRandomPoolByType(mergePool,randomPoolByType.get(mergePool));
int result = sLotteryRewardConfig.getId();

View File

@ -235,124 +235,6 @@ 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);
if (sLotterySetting == null) {
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
}
int perCount = sLotterySetting.getPerCount();
int maxTimes = sLotterySetting.getMaxTimes();
if(maxTimes!=0 && !PlayerLogic.getInstance().checkAndUpdate(user,maxTimes, perCount)){
throw new ErrorCodeException("已抽取今日最大次数");
}
HeroManager heroManager = user.getHeroManager();
if(type==11&&heroManager.getFirstTenth()==0){
heroManager.updateFirstTenth();
}
if(sLotterySetting.getLotteryType()==3){
//活动抽卡校验
if(!user.getActivityManager().getActivityMissionMap().containsKey(sLotterySetting.getActivityId())){
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
}
SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(sLotterySetting.getActivityId());
long endTimeLong = ToolsUtil.getEndTimeLong(activity.getStartTimeLong(), activity.getEndTimeLong(), activity.getTime(), user.getPlayerInfoManager().getCreateTime(), activity.getGapTime());
if(endTimeLong!=0&&TimeUtils.now()>endTimeLong){
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
}
}
if(heroManager!=null&& heroManager.getHeroMap()!=null){
if(heroManager.getHeroMap().size() + perCount > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getHeroNumlimit()){
throw new ErrorCodeException(ErrorCode.HERO_MAX);
}
}
//检验消耗
boolean allowFree = false;
int[] costAmount = new int[1];
int privilege = sLotterySetting.getFreeTimes();
if(privilege!=0){
allowFree = PlayerLogic.getInstance().checkAndUpdate(user,privilege, perCount);
}
if(!allowFree){
boolean enoughCost = false;
for (int[] cost:sLotterySetting.getCostItem()){
int[] costItem = new int[cost.length];
for(int i= 0; i <cost.length;i++){
costItem[i] = cost[i];
}
int[][] costItems = new int[][]{costItem};
if(costItems[0][0]==Global.GEM){
//每日妖精抽取次数
if(sLotterySetting.getMoneyTimes()!=0 && !PlayerLogic.getInstance().checkAndUpdate(user,sLotterySetting.getMoneyTimes(), perCount)){
throw new ErrorCodeException("已抽取今日最大次数");
}
//检测是否有折扣
if(sLotterySetting.getDiscountTimes()!=0){
List<SPrivilegeTypeConfig> missingType = SPrivilegeTypeConfig.privilegeByType.get(sLotterySetting.getDiscountTimes());
Arrays.stream(costItems).forEach(n->{
for(SPrivilegeTypeConfig config:missingType){
if(user.getPlayerInfoManager().containPrivilageId(config.getId())){
n[1] =(int)(n[1]/10000d*(10000+config.getCondition()[0][1]));
}
}
}
);
}
}
enoughCost = ItemUtil.itemCost(user, costItems,BIReason.RANDOM_HERO_CONSUME,type);
if(enoughCost){
costAmount = cost;
break;
}
}
if(!enoughCost){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
}
//抽卡必得积分
int[][] tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
//所有获得物品
int[][] resultRandom = new int[perCount+tenTimesMustGetItem.length][];
//进行抽取
int index = 0;
for(int i = 0 ;i<perCount;i++){
int rewardId = randomOne(user, type);
SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
resultRandom[i] =sLotteryRewardConfig.getReward();
index = i;
}
//上报抽卡
reportRandom(user,sLotterySetting,resultRandom,costAmount);
for(int i = 0;i<tenTimesMustGetItem.length;i++) {
resultRandom[i+index+1] = tenTimesMustGetItem[i];
}
//是否需要根据活动替换所得物品
if(sLotterySetting.getLotteryType()==10){
changeRandomItem(user,sLotterySetting.getActivityId(),resultRandom);
}
Poster.getPoster().dispatchEvent(new RandomCardEvent(user.getId(),sLotterySetting.getActivityId(),heroManager.getRandomPoolByType().get(sLotterySetting.getMergePool()),sLotterySetting.getPerCount()));
// //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,perCount);
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);
}
private void changeRandomItem(User user,int activityId,int[][] random){
ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(activityId);
if(activityMission==null||activityMission.getActivityMissionMap().get(0)==null){
@ -452,104 +334,7 @@ public class HeroLogic {
}
/**
*
* @param user
* @param type
* @return
* @throws Exception
*/
public static 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();
Set<Integer> mustSet = new HashSet<>();
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(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;
}
//保底触发次数统计
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(),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();
if(randomPoolByType.get(mergePool)!=null) {
for (int key : randomPoolByType.get(mergePool).keySet()) {
if (star == key) {
randomPoolByType.get(mergePool).put(key, 0);
} else {
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>maxId?mustId:maxId;
}
LOGGER.info("randomOne uid=>{} 触发必出=>{}", user.getId(), maxId);
SLotterySpecialConfig onConfig = null;
for(SLotterySpecialConfig everyConfig:specialConfigs){
if(everyConfig.getDifferentType()!=maxId){
continue;
}
onConfig = everyConfig;
}
if(onConfig==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel());
randomPoolByType.get(mergePool).put(maxId,0);
}
heroManager.updateRandomPoolByType(mergePool,randomPoolByType.get(mergePool));
int result = sLotteryRewardConfig.getId();
return result;
}
private int getSpecialPoolByRandcount(SLotterySetting sLotterySetting, int randCount,int poolCount) {
int id = sLotterySetting.getId();