心愿抽奖重新提交
parent
2514e19137
commit
afa3958566
|
@ -3,6 +3,7 @@ package com.ljsd.jieling.tools;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -89,8 +90,30 @@ public class Utils {
|
|||
String randStr = String.valueOf(stringBuffer);
|
||||
return randStr;
|
||||
}
|
||||
/**
|
||||
* 对象拷贝 只要实现了Serializable接口都可以
|
||||
* @param obj
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T extends Serializable> T clone(T obj) {
|
||||
T cloneObj = null;
|
||||
try {
|
||||
// 写入字节流
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ObjectOutputStream obs = new ObjectOutputStream(out);
|
||||
obs.writeObject(obj);
|
||||
obs.close();
|
||||
|
||||
|
||||
|
||||
|
||||
// 分配内存,写入原始对象,生成新对象
|
||||
ByteArrayInputStream ios = new ByteArrayInputStream(out.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(ios);
|
||||
// 返回生成的新对象
|
||||
cloneObj = (T) ois.readObject();
|
||||
ois.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cloneObj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,6 +218,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
.addAllSealList(CBean2Proto.getPurpleMansionSealInfo(user))
|
||||
.setDailyredpack(playerInfoManager.getDailyWelfareRedPacket())
|
||||
.setRandomCount(randomCount)
|
||||
.addAllDrawTimes(CBean2Proto.getRandomTypeNums(user))
|
||||
.build();
|
||||
ReportUtil.onReportEvent(user, ReportEventEnum.APP_LOGIN.getType());
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.ljsd.jieling.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.util.CBean2Proto;
|
||||
import org.springframework.stereotype.Component;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.HeroInfoProto;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/6/29 14:38
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class GetWishDrawCardInfoHandler extends BaseHandler<HeroInfoProto.choiceWishHeroRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.choiceWishHeroRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(int uid, HeroInfoProto.choiceWishHeroRequest proto) throws Exception {
|
||||
// 用户信息
|
||||
User user = UserManager.getUser(uid);
|
||||
if (user == null) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
if (proto != null && proto.getInfoListCount() > 0){
|
||||
HeroLogic.getInstance().updateWishDrawCardInfo(user,proto.getInfoListList());
|
||||
}
|
||||
|
||||
// 返回
|
||||
List<CommonProto.wishDrawCardInfo> wishCard = CBean2Proto.getWishCard(user);
|
||||
return HeroInfoProto.choiceWishHeroResponse.newBuilder().addAllInfoList(wishCard).build();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import com.ljsd.jieling.logic.activity.RemoveEventHeroHandler;
|
|||
import com.ljsd.jieling.logic.activity.UserLevelEventHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.SuperBoxEvent;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.logic.redpacket.WelfareRedPackSendHandler;
|
||||
import com.ljsd.jieling.logic.activity.eventhandler.ActivityStateChangeHandler;
|
||||
import com.ljsd.jieling.logic.activity.eventhandler.BuyGoodsDirectHandler;
|
||||
|
@ -378,13 +379,13 @@ public class GlobalDataManaager implements IManager {
|
|||
}
|
||||
//刷新膜拜信息
|
||||
user.getPlayerInfoManager().setProudInfo(new HashSet<>());
|
||||
|
||||
// 道具刷新
|
||||
BuyGoodsNewLogic.refreshWelfareState(user);
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.LOGIN_GAME,0);
|
||||
|
||||
// 惊喜礼盒,事件推送
|
||||
Poster.getPoster().dispatchEvent(new SuperBoxEvent(user.getId(),-1));
|
||||
// 心愿格子信息刷新
|
||||
HeroLogic.getInstance().resetWishDrawCardInfoMap(user);
|
||||
}
|
||||
user.getPlayerInfoManager().setLoginTime(TimeUtils.now());
|
||||
}
|
||||
|
|
|
@ -72,9 +72,33 @@ public class HeroManager extends MongoBase {
|
|||
* 紫府神印
|
||||
*/
|
||||
private Map<Integer,PurpleMansionSeal> purpleMansionSeal = new HashMap<>();
|
||||
/**
|
||||
* 心愿抽卡
|
||||
*/
|
||||
private HashMap<Integer,WishDrawCardInfo> wishDrawCardInfoMap = new HashMap<>(3);
|
||||
|
||||
/**
|
||||
* 抽奖次数记录
|
||||
* key: 招募类型 value: 次数
|
||||
*/
|
||||
private Map<Integer,Integer> randomCountByType = new HashMap<>();
|
||||
|
||||
public Map<Integer, Integer> getRandomCountByType() {
|
||||
return randomCountByType;
|
||||
}
|
||||
|
||||
public void setRandomCountByType(Map<Integer, Integer> randomCountByType) {
|
||||
this.randomCountByType = randomCountByType;
|
||||
updateString("randomCountByType", randomCountByType);
|
||||
}
|
||||
|
||||
public void putRandomCount(int type,int value) {
|
||||
randomCountByType.put(type,value);
|
||||
updateString("randomCountByType."+type, value);
|
||||
}
|
||||
|
||||
public void updateRandCount(int type,int count){
|
||||
updateString("totalCount." + type, count);
|
||||
updateString("totalCount." + type, count);
|
||||
totalCount.put(type,count);
|
||||
}
|
||||
|
||||
|
@ -349,7 +373,34 @@ public class HeroManager extends MongoBase {
|
|||
public void setTaSuiLingXiaoRankForce(int taSuiLingXiaoRankForce) {
|
||||
this.taSuiLingXiaoRankForce = taSuiLingXiaoRankForce;
|
||||
updateString("taSuiLingXiaoRankForce", taSuiLingXiaoRankForce);
|
||||
}
|
||||
|
||||
public HashMap<Integer, WishDrawCardInfo> getWishDrawCardInfoMap() {
|
||||
if (wishDrawCardInfoMap.isEmpty()){
|
||||
initWishDrawCardInfoMap();
|
||||
}
|
||||
return wishDrawCardInfoMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化心愿格子信息
|
||||
*/
|
||||
private void initWishDrawCardInfoMap(){
|
||||
for (int i = 1; i < 4; i++) {
|
||||
wishDrawCardInfoMap.put(i,new WishDrawCardInfo(i,0,0));
|
||||
}
|
||||
updateString("wishDrawCardInfoMap", wishDrawCardInfoMap);
|
||||
}
|
||||
|
||||
public void setWishDrawCardInfoMap(HashMap<Integer, WishDrawCardInfo> wishDrawCardInfoMap) {
|
||||
this.wishDrawCardInfoMap = wishDrawCardInfoMap;
|
||||
updateString("wishDrawCardInfoMap", wishDrawCardInfoMap);
|
||||
}
|
||||
|
||||
public void putWishDrawCardInfoMap(WishDrawCardInfo wishDrawCardInfo) {
|
||||
int key = wishDrawCardInfo.getId();
|
||||
wishDrawCardInfoMap.put(key,wishDrawCardInfo);
|
||||
updateString("wishDrawCardInfoMap." + key, wishDrawCardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/6/29 11:11
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class WishDrawCardInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int id;
|
||||
private int heroTid;
|
||||
private int status;
|
||||
|
||||
public WishDrawCardInfo(int id, int heroTid, int status) {
|
||||
this.id = id;
|
||||
this.heroTid = heroTid;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getHeroTid() {
|
||||
return heroTid;
|
||||
}
|
||||
|
||||
public void setHeroTid(int heroTid) {
|
||||
this.heroTid = heroTid;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
|
|||
import com.ljsd.jieling.logic.store.newRechargeInfo.PushRechargeType;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.tools.Utils;
|
||||
import com.ljsd.jieling.util.*;
|
||||
import config.*;
|
||||
import manager.STableManager;
|
||||
|
@ -328,7 +329,17 @@ public class HeroLogic{
|
|||
for(int i = 0 ;i<perCount;i++){
|
||||
int rewardId = randomOne(user, type);
|
||||
SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
|
||||
resultRandom[i] =sLotteryRewardConfig.getReward();
|
||||
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.UNLOCKCARDWISH);
|
||||
// 对应卡池抽奖次数
|
||||
Integer num = heroManager.getRandomCountByType().getOrDefault(sLotterySetting.getLotteryType(),0);
|
||||
// 心愿抽卡
|
||||
if (sLotterySetting.getLotteryType() == 1 && num >= value){
|
||||
resultRandom[i] = wishDrawCardCheck(user,sLotteryRewardConfig.getReward());
|
||||
}else {
|
||||
resultRandom[i] = sLotteryRewardConfig.getReward();
|
||||
}
|
||||
//记录次数
|
||||
heroManager.putRandomCount(sLotterySetting.getLotteryType(),num+1);
|
||||
index = i;
|
||||
}
|
||||
//上报抽卡
|
||||
|
@ -359,8 +370,8 @@ public class HeroLogic{
|
|||
fiveStarPushByRandom(user,resultRandom);
|
||||
fiveStarPokemonPushByRandom(user,resultRandom);
|
||||
builder.setDrop(drop);
|
||||
builder.addAllDrawTimes(CBean2Proto.getRandomTypeNums(user));
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.HERO_RAND_RESPONSE_VALUE, builder.build(), true);
|
||||
// System.out.println(System.currentTimeMillis()-time);
|
||||
|
||||
if(sLotterySetting.getLotteryType() == GlobalsDef.RANDOM_LOTTERY_TYPE && !user.getPlayerInfoManager().isHasRandomLotteryType()&sLotterySetting.getPerCount()!=1){
|
||||
//首次神将召唤 10连抽 给个攻略邮件
|
||||
|
@ -371,7 +382,131 @@ public class HeroLogic{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 心愿抽卡校验
|
||||
* @param user
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
private int[] wishDrawCardCheck(User user,int[] item){
|
||||
// 查找物品
|
||||
SItem sItem = SItem.getsItemMap().get(item[0]);
|
||||
// 非英雄奖励直接返回
|
||||
if (sItem.getItemType() != GlobalItemType.CARD){
|
||||
return item;
|
||||
}
|
||||
// 非五星英雄
|
||||
SCHero scHero = SCHero.getsCHero().get(item[0]);
|
||||
if (scHero.getStar() < 5){
|
||||
return item;
|
||||
}
|
||||
// 随机权重
|
||||
int totalNum = 10000;
|
||||
int anInt = MathUtils.randomInt(totalNum);
|
||||
// 单个格子权重
|
||||
int value = SSpecialConfig.getIntegerValue(SSpecialConfig.CARDWISHBLOCKRATE);
|
||||
// 获取玩家现在的心愿格子信息
|
||||
Map<Integer, WishDrawCardInfo> cardInfoMap = user.getHeroManager().getWishDrawCardInfoMap();
|
||||
|
||||
// 计算权重map
|
||||
HashMap<Integer, Integer> map = new HashMap<>(4);
|
||||
for (int i = 0; i < cardInfoMap.size(); i++) {
|
||||
map.put(i+1,value);
|
||||
}
|
||||
int sum = map.values().stream().mapToInt(Integer::intValue).sum();
|
||||
map.put(map.size()+1,totalNum-sum);
|
||||
|
||||
// 遍历权重
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
if (anInt <= entry.getValue()){
|
||||
// 读取格子信息
|
||||
WishDrawCardInfo cardInfo = cardInfoMap.get(entry.getKey());
|
||||
// null表示未中心愿, 该格子已锁定, 是空格子
|
||||
if (cardInfo == null || cardInfo.getStatus() == 1 || cardInfo.getHeroTid() == 0){
|
||||
return item;
|
||||
}
|
||||
// new int[]
|
||||
int[] result = new int[2];
|
||||
// 赋值物品id和数量
|
||||
result[0] = cardInfo.getHeroTid();
|
||||
result[1] = item[1];
|
||||
// 修改格子信息,入库
|
||||
cardInfo.setStatus(1);
|
||||
user.getHeroManager().putWishDrawCardInfoMap(cardInfo);
|
||||
// 消息推送
|
||||
sendWishCardIndication(user);
|
||||
return result;
|
||||
}
|
||||
// 权重递减
|
||||
anInt-=entry.getValue();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送心愿格子信息到客户端
|
||||
* @param user
|
||||
*/
|
||||
private void sendWishCardIndication(User user){
|
||||
List<CommonProto.wishDrawCardInfo> wishCard = CBean2Proto.getWishCard(user);
|
||||
HeroInfoProto.wishDrawCardIndication.Builder list = HeroInfoProto.wishDrawCardIndication.newBuilder().addAllInfoList(wishCard);
|
||||
MessageUtil.sendIndicationMessage(user.getId(),list.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置心愿格子信息
|
||||
*/
|
||||
public void resetWishDrawCardInfoMap(User user){
|
||||
// 重置状态
|
||||
HashMap<Integer, WishDrawCardInfo> map = user.getHeroManager().getWishDrawCardInfoMap();
|
||||
map.values().forEach(v->v.setStatus(0));
|
||||
user.getHeroManager().setWishDrawCardInfoMap(map);
|
||||
// 推送消息
|
||||
sendWishCardIndication(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改英雄格子
|
||||
* @param user
|
||||
* @param list
|
||||
* @throws ErrorCodeException
|
||||
*/
|
||||
public void updateWishDrawCardInfo(User user, List<CommonProto.wishDrawCardInfo> list) throws ErrorCodeException {
|
||||
HashMap<Integer, WishDrawCardInfo> map = Utils.clone(user.getHeroManager().getWishDrawCardInfoMap());
|
||||
// 遍历
|
||||
for (CommonProto.wishDrawCardInfo v : list) {
|
||||
WishDrawCardInfo cardInfo = map.get(v.getId());
|
||||
// 英雄未锁定
|
||||
if (cardInfo != null && cardInfo.getStatus() == 0){
|
||||
// 替换英雄
|
||||
cardInfo.setHeroTid(v.getHeroTid());
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已选择英雄的类型set集合
|
||||
Set<Integer> race = new HashSet<>();
|
||||
map.values().forEach(v->{
|
||||
if (v.getHeroTid() != 0){
|
||||
SCHero scHero = SCHero.getsCHero().get(v.getHeroTid());
|
||||
race.add(scHero.getPropertyName());
|
||||
}
|
||||
});
|
||||
|
||||
// 去除空格子后队列的长度
|
||||
List<WishDrawCardInfo> infos = new ArrayList<>(map.values());
|
||||
infos.removeIf(v->v.getHeroTid() == 0);
|
||||
|
||||
// 类型唯一, 如果长度不一致代表有重复类型英雄
|
||||
if (race.size() != infos.size()){
|
||||
throw new ErrorCodeException("有重复类型英雄,替换失败");
|
||||
}
|
||||
// 入库
|
||||
else {
|
||||
user.getHeroManager().setWishDrawCardInfoMap(map);
|
||||
}
|
||||
// 推送消息
|
||||
sendWishCardIndication(user);
|
||||
}
|
||||
|
||||
private void changeRandomItem(User user,int activityId,int[][] random){
|
||||
ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(activityId);
|
||||
|
|
|
@ -864,4 +864,37 @@ public class CBean2Proto {
|
|||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取心愿格子信息
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static List<CommonProto.wishDrawCardInfo> getWishCard(User user){
|
||||
List<CommonProto.wishDrawCardInfo> list = new ArrayList<>();
|
||||
user.getHeroManager().getWishDrawCardInfoMap().values().forEach(v->{
|
||||
CommonProto.wishDrawCardInfo builder = CommonProto.wishDrawCardInfo.newBuilder()
|
||||
.setId(v.getId())
|
||||
.setHeroTid(v.getHeroTid())
|
||||
.setStatus(v.getStatus())
|
||||
.build();
|
||||
list.add(builder);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型抽卡总次数
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static List<CommonProto.randomTypeNum> getRandomTypeNums(User user){
|
||||
List<CommonProto.randomTypeNum> list = new ArrayList<>();
|
||||
Map<Integer, Integer> countByType = user.getHeroManager().getRandomCountByType();
|
||||
for (Map.Entry<Integer, Integer> entry : countByType.entrySet()) {
|
||||
CommonProto.randomTypeNum.Builder builder = CommonProto.randomTypeNum.newBuilder().setType(entry.getKey()).setNum(entry.getValue());
|
||||
list.add(builder.build());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,9 @@ public class SSpecialConfig implements BaseConfig {
|
|||
public static final String YIJIANGOUMAI = "YiJianGouMai";//一件购买
|
||||
public static final String WELFAREREDPACKET_LIMIT = "RedPackMaxGainNum";//每日领取红包数量上限
|
||||
public static final String SWEEP_ONEKEY = "floodprivilegeid";//一键扫荡
|
||||
|
||||
public static final String CARDWISHBLOCKRATE = "CardWishBlockRate";//钻石抽卡心愿单格子命中万分比
|
||||
public static final String UNLOCKCARDWISH = "UnlockCardWish";//解锁钻石心愿抽卡所需要的抽卡次数
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue