心愿抽卡功能提交
parent
24c3c32bb6
commit
a18cdcf1e5
|
@ -3,7 +3,9 @@ package com.ljsd.jieling.tools;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
|
@ -90,7 +92,30 @@ public class Utils {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -73,6 +73,31 @@ 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);
|
||||
totalCount.put(type,count);
|
||||
|
@ -349,7 +374,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;
|
||||
}
|
||||
}
|
|
@ -37,8 +37,10 @@ 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 javafx.geometry.VPos;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -240,7 +242,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);
|
||||
|
@ -327,7 +328,17 @@ public class HeroLogic{
|
|||
for(int i = 0 ;i<perCount;i++){
|
||||
int rewardId = randomOne(user, type);
|
||||
SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
|
||||
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++);
|
||||
index = i;
|
||||
}
|
||||
//上报抽卡
|
||||
|
@ -362,7 +373,126 @@ public class HeroLogic{
|
|||
// System.out.println(System.currentTimeMillis()-time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 心愿抽卡校验
|
||||
* @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;
|
||||
}
|
||||
// 随机权重
|
||||
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);
|
||||
|
|
|
@ -862,4 +862,22 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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