心愿抽卡功能优化
parent
07fe5c89ed
commit
80b1659cb1
|
@ -270,7 +270,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
||||||
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
|
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
|
||||||
if (num < value){
|
if (num < value){
|
||||||
// 修改次数
|
// 修改次数
|
||||||
user.getHeroManager().putRandomCount(1,value);
|
user.getHeroManager().putRandomType(1,value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
package com.ljsd.jieling.logic.dao;
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
import com.ljsd.common.mogodb.MongoBase;
|
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.Poster;
|
||||||
import com.ljsd.jieling.logic.activity.event.RemoveHeroEvent;
|
import com.ljsd.jieling.logic.activity.event.RemoveHeroEvent;
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
import com.ljsd.jieling.logic.hero.HongMengAttributeEnum;
|
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 config.SSpecialConfig;
|
||||||
import rpc.protocols.HeroInfoProto;
|
|
||||||
import rpc.protocols.MessageTypeProto;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -83,6 +77,11 @@ public class HeroManager extends MongoBase {
|
||||||
*/
|
*/
|
||||||
private Map<Integer,Integer> randomCountByType = new HashMap<>();
|
private Map<Integer,Integer> randomCountByType = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* key: 招募类型 value:< key: 星级 value: 数量 >
|
||||||
|
*/
|
||||||
|
private Map<Integer, Map<Integer,Integer>> randomCountByStar = new HashMap<>();
|
||||||
|
|
||||||
public Map<Integer, Integer> getRandomCountByType() {
|
public Map<Integer, Integer> getRandomCountByType() {
|
||||||
return randomCountByType;
|
return randomCountByType;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +91,30 @@ public class HeroManager extends MongoBase {
|
||||||
updateString("randomCountByType", randomCountByType);
|
updateString("randomCountByType", randomCountByType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putRandomCount(int type,int value) {
|
public void putRandomType(int type,int value) {
|
||||||
randomCountByType.put(type,value);
|
randomCountByType.put(type,value);
|
||||||
updateString("randomCountByType."+type, value);
|
updateString("randomCountByType."+type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRandCount(int type,int count){
|
public Map<Integer, Map<Integer, Integer>> getRandomCountByStar() {
|
||||||
|
return randomCountByStar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, Integer> getRandomStar(int type) {
|
||||||
|
return randomCountByStar.getOrDefault(type,new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRandomCountByStar(Map<Integer, Map<Integer, Integer>> randomCountByStar) {
|
||||||
|
this.randomCountByStar = randomCountByStar;
|
||||||
|
updateString("randomCountByStar", randomCountByStar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putRandomStar(int type,Map<Integer,Integer> starMap) {
|
||||||
|
randomCountByStar.put(type,starMap);
|
||||||
|
updateString("randomCountByStar."+type, starMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateRandCount(int type, int count){
|
||||||
updateString("totalCount." + type, count);
|
updateString("totalCount." + type, count);
|
||||||
totalCount.put(type,count);
|
totalCount.put(type,count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,19 +383,33 @@ public class HeroLogic{
|
||||||
*/
|
*/
|
||||||
private int[] drawCard(User user, SLotteryRewardConfig sLotteryRewardConfig, SLotterySetting sLotterySetting){
|
private int[] drawCard(User user, SLotteryRewardConfig sLotteryRewardConfig, SLotterySetting sLotterySetting){
|
||||||
HeroManager heroManager = user.getHeroManager();
|
HeroManager heroManager = user.getHeroManager();
|
||||||
// 限制次数
|
// 参数
|
||||||
|
int type = sLotterySetting.getLotteryType();
|
||||||
|
int[] reward = sLotteryRewardConfig.getReward();
|
||||||
|
// 限制满足次数
|
||||||
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
|
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
|
||||||
// 对应卡池抽奖次数
|
// 对应卡池抽奖次数
|
||||||
Integer num = heroManager.getRandomCountByType().getOrDefault(sLotterySetting.getLotteryType(),0);
|
Integer num = heroManager.getRandomCountByType().getOrDefault(type,0);
|
||||||
// 心愿抽卡
|
// 心愿抽卡
|
||||||
int[] result;
|
int[] result;
|
||||||
if (sLotterySetting.getLotteryType() == 1 && num >= value){
|
if (type == 1 && num >= value){
|
||||||
result = wishDrawCardCheck(user,sLotteryRewardConfig.getReward());
|
// 钻石抽卡并且次数满足
|
||||||
|
result = wishDrawCardCheck(user,reward,type);
|
||||||
}else {
|
}else {
|
||||||
result = sLotteryRewardConfig.getReward();
|
result = reward;
|
||||||
}
|
}
|
||||||
//记录次数
|
//记录卡池抽奖次数
|
||||||
heroManager.putRandomCount(sLotterySetting.getLotteryType(),num+1);
|
heroManager.putRandomType(type,num+result[1]);
|
||||||
|
// 记录卡池,抽奖星级次数
|
||||||
|
SCHero scHero = SCHero.getsCHero().get(reward[0]);
|
||||||
|
if (scHero != null){
|
||||||
|
// 获取类型抽奖次数
|
||||||
|
Map<Integer, Integer> randomStar = heroManager.getRandomStar(type);
|
||||||
|
// 更新次数
|
||||||
|
randomStar.put(scHero.getStar(),randomStar.getOrDefault(scHero.getStar(),0)+result[1]);
|
||||||
|
heroManager.putRandomStar(type,randomStar);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +419,7 @@ public class HeroLogic{
|
||||||
* @param item
|
* @param item
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private int[] wishDrawCardCheck(User user,int[] item){
|
private int[] wishDrawCardCheck(User user,int[] item,int type){
|
||||||
// 查找物品
|
// 查找物品
|
||||||
SItem sItem = SItem.getsItemMap().get(item[0]);
|
SItem sItem = SItem.getsItemMap().get(item[0]);
|
||||||
// 非英雄奖励直接返回
|
// 非英雄奖励直接返回
|
||||||
|
@ -417,42 +431,34 @@ public class HeroLogic{
|
||||||
if (scHero.getStar() < 5){
|
if (scHero.getStar() < 5){
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================= 中不中心愿 ======================= */
|
/* ======================= 中不中心愿 ======================= */
|
||||||
// 随机权重
|
// 获取钻石抽奖抽中五星的次数
|
||||||
int totalNum = 10000;
|
int num = user.getHeroManager().getRandomStar(type).getOrDefault(5, 0)+1;
|
||||||
int anInt = MathUtils.randomInt(totalNum);
|
boolean randomBol = (num - 1) % 3 == 0;
|
||||||
// 单个格子权重
|
if (!randomBol){
|
||||||
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.CARDWISHBLOCKRATE);
|
// 不到次数,不走心愿
|
||||||
// 获取玩家现在的心愿格子信息
|
|
||||||
Map<Integer, WishDrawCardInfo> cardInfoMap = user.getHeroManager().getWishDrawCardInfoMap();
|
|
||||||
// 中将权重值
|
|
||||||
int weight = cardInfoMap.size() * value;
|
|
||||||
// 未中奖
|
|
||||||
if (anInt > weight){
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*======================== 中心愿随机奖励 ========================*/
|
/*======================== 中心愿随机奖励 ========================*/
|
||||||
|
// 心愿格子信息
|
||||||
|
HashMap<Integer, WishDrawCardInfo> cardInfoMap = user.getHeroManager().getWishDrawCardInfoMap();
|
||||||
|
// 空格子权重
|
||||||
|
int empty = SSpecialConfig.getIntegerValue(SSpecialConfig.CARDWISHBLOCKRATE);
|
||||||
// 计算权重map
|
// 计算权重map
|
||||||
HashMap<Integer, Integer> map = new HashMap<>();
|
HashMap<Integer, Integer> map = new HashMap<>();
|
||||||
for (Integer key : cardInfoMap.keySet()) {
|
cardInfoMap.forEach((k,v)->{
|
||||||
if (cardInfoMap.get(key).getStatus() == 1){
|
if (v.getStatus() == 0 && v.getHeroTid() != 0){
|
||||||
// 已经抽中得格子去除
|
// 英雄格子
|
||||||
weight-=value;
|
SCHero hero = SCHero.getsCHero().get(v.getHeroTid());
|
||||||
continue;
|
map.put(k,hero.getWeight());
|
||||||
|
}else {
|
||||||
|
// 空格子
|
||||||
|
map.put(k,empty);
|
||||||
}
|
}
|
||||||
map.put(key,value);
|
});
|
||||||
}
|
// 随机权重
|
||||||
|
int weight = map.values().stream().mapToInt(Integer::intValue).sum();
|
||||||
// 全部抽中
|
|
||||||
if (map.isEmpty() || weight == 0){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
int randomInt = MathUtils.randomInt(weight);
|
int randomInt = MathUtils.randomInt(weight);
|
||||||
|
|
||||||
// 遍历权重
|
// 遍历权重
|
||||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||||
if (randomInt <= entry.getValue()){
|
if (randomInt <= entry.getValue()){
|
||||||
|
|
|
@ -60,6 +60,8 @@ public class SCHero implements BaseConfig{
|
||||||
|
|
||||||
private int maxLevel;
|
private int maxLevel;
|
||||||
|
|
||||||
|
private int weight;
|
||||||
|
|
||||||
private Map<Integer,Integer> secondaryFactorMap;
|
private Map<Integer,Integer> secondaryFactorMap;
|
||||||
|
|
||||||
private Map<Integer, List<Integer>> skillListByStar;
|
private Map<Integer, List<Integer>> skillListByStar;
|
||||||
|
@ -348,4 +350,8 @@ public class SCHero implements BaseConfig{
|
||||||
public int getMaxLevel() {
|
public int getMaxLevel() {
|
||||||
return maxLevel;
|
return maxLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue