心愿抽奖初版,未联调
parent
3811d59299
commit
d1a2849a56
|
@ -333,4 +333,6 @@ public interface BIReason {
|
|||
int UP_PRACTICE_LEVEL = 1100;//修行升级
|
||||
int SVIP_LEVEL_REWARD = 1101;//特权升级等级奖励
|
||||
|
||||
int CHOICE_DRAW_CARD = 1102;//心愿抽奖
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.ljsd.jieling.handler.activity;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import org.springframework.stereotype.Component;
|
||||
import rpc.protocols.ActivityProto;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/5/24 18:11
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class ChoiceDrawCardHandler extends BaseHandler<ActivityProto.choiceDrawCardRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.choiceDrawCardRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, ActivityProto.choiceDrawCardRequest proto) throws Exception {
|
||||
// 用户信息
|
||||
User user = UserManager.getUser(iSession.getUid());
|
||||
if (user == null) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
int activityId = proto.getActivityId();
|
||||
int type = proto.getType();
|
||||
|
||||
ActivityLogic.getInstance().choiceDrawCard(user,activityId,type);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.ljsd.jieling.handler.activity;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.logic.activity.AbstractActivity;
|
||||
import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import config.SWishActivityUp;
|
||||
import rpc.protocols.ActivityProto;
|
||||
import rpc.protocols.Family;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/5/24 17:04
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ChoiceHeroRewardHandler extends BaseHandler<ActivityProto.choiceHeroRewardRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.choiceHeroRewardRequest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, ActivityProto.choiceHeroRewardRequest proto) throws Exception {
|
||||
// 用户信息
|
||||
User user = UserManager.getUser(iSession.getUid());
|
||||
if (user == null) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
|
||||
int activityId = proto.getActivityId();
|
||||
int rewardId = proto.getRewardId();
|
||||
|
||||
// 验证所选奖励是否正确
|
||||
int[][] upList = SWishActivityUp.map.get(activityId).getUpList();
|
||||
boolean result = false;
|
||||
for (int[] incs : upList) {
|
||||
if (incs[0] == rewardId){
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result){
|
||||
throw new ErrorCodeException("英雄id错误,不在本期活动");
|
||||
}
|
||||
|
||||
// 修改默认英雄id
|
||||
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(activityId);
|
||||
mission.setChoiceRewardId(rewardId);
|
||||
|
||||
ActivityProto.choiceHeroRewardResponse builder = ActivityProto.choiceHeroRewardResponse.newBuilder().build();
|
||||
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.choiceHeroRewardResponse_VALUE,builder,true);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,10 @@ public final class ActivityMission extends MongoBase {
|
|||
private int openType;
|
||||
private int v;
|
||||
private long creatTime;
|
||||
/**
|
||||
* 心愿抽奖专用,选择得奖励id
|
||||
*/
|
||||
private int choiceRewardId;
|
||||
|
||||
public ActivityMission() {
|
||||
}
|
||||
|
@ -30,6 +34,7 @@ public final class ActivityMission extends MongoBase {
|
|||
this.openType = _o_.openType;
|
||||
this.v = _o_.v;
|
||||
this.creatTime = _o_.creatTime;
|
||||
this.choiceRewardId = _o_.choiceRewardId;
|
||||
}
|
||||
|
||||
public Map<Integer, com.ljsd.jieling.jbean.ActivityProgressInfo> getActivityMissionMap() {
|
||||
|
@ -74,6 +79,14 @@ public final class ActivityMission extends MongoBase {
|
|||
this.creatTime = creatTime;
|
||||
}
|
||||
|
||||
public int getChoiceRewardId() {
|
||||
return choiceRewardId;
|
||||
}
|
||||
|
||||
public void setChoiceRewardId(int choiceRewardId) {
|
||||
this.choiceRewardId = choiceRewardId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder _sb_ = new StringBuilder(super.toString());
|
||||
|
@ -83,6 +96,7 @@ public final class ActivityMission extends MongoBase {
|
|||
_sb_.append(this.openType).append(",");
|
||||
_sb_.append(this.v).append(",");
|
||||
_sb_.append(this.creatTime).append(",");
|
||||
_sb_.append(this.choiceRewardId).append(",");
|
||||
_sb_.append(")");
|
||||
return _sb_.toString();
|
||||
}
|
||||
|
|
|
@ -530,7 +530,16 @@ public class ActivityLogic implements IEventHandler{
|
|||
continue;
|
||||
}
|
||||
List<CommonProto.ActivityInfo.MissionInfo> missionInfos =abstractActivity.getAllMissInfo(activityMission);
|
||||
activityInfoList.add(CommonProto.ActivityInfo.newBuilder().setActivityId(activityId).addAllMission(missionInfos).setStartTime(startTime).setEndTime(endTime).setValue(activityMission.getV()).setReallyOpen(activityMission.getOpenType()).build());
|
||||
CommonProto.ActivityInfo build = CommonProto.ActivityInfo.newBuilder()
|
||||
.setActivityId(activityId)
|
||||
.addAllMission(missionInfos)
|
||||
.setStartTime(startTime)
|
||||
.setEndTime(endTime)
|
||||
.setValue(activityMission.getV())
|
||||
.setReallyOpen(activityMission.getOpenType())
|
||||
.setChoiceRewardId(activityMission.getChoiceRewardId())
|
||||
.build();
|
||||
activityInfoList.add(build);
|
||||
}
|
||||
return activityInfoList;
|
||||
}
|
||||
|
@ -1508,4 +1517,139 @@ public class ActivityLogic implements IEventHandler{
|
|||
result[1] = endTime;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 心愿抽奖
|
||||
* @param user
|
||||
* @param activityId
|
||||
* @param type
|
||||
* @throws Exception
|
||||
*/
|
||||
public void choiceDrawCard(User user,int activityId,int type) throws Exception {
|
||||
ActivityProto.choiceDrawCardResponse.Builder build = ActivityProto.choiceDrawCardResponse.newBuilder();
|
||||
SWishActivitySetting setting = STableManager.getConfig(SWishActivitySetting.class).get(0);
|
||||
// 抽奖上限
|
||||
boolean check1 = PlayerLogic.getInstance().check(user, setting.getMaxTimes(), 1);
|
||||
if (!check1){
|
||||
throw new ErrorCodeException("今日抽奖次数已达上限");
|
||||
}
|
||||
CommonProto.Drop.Builder drop;
|
||||
// 抽奖次数
|
||||
int num = type == 1?1:10;
|
||||
// 单抽
|
||||
if (num == 1){
|
||||
// 验证免费特权
|
||||
boolean check = PlayerLogic.getInstance().checkAndUpdate(user, setting.getFreeTimes(), num);
|
||||
if (check){
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
// 发送奖励
|
||||
build.setDrop(drop);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceHeroRewardResponse_VALUE,build.build(),true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 十连抽还是单抽消耗物品获取
|
||||
int[][] item = type == 1?setting.getCostItemMul():setting.getCostItemSingle();
|
||||
HashMap<Integer, Integer> map = new HashMap<>(1);
|
||||
map.put(item[0][0],item[0][1]);
|
||||
// 验证消耗
|
||||
boolean itemCost = ItemUtil.itemCost(user, map, BIReason.CHOICE_DRAW_CARD, 0);
|
||||
// 道具抽奖
|
||||
if (itemCost){
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
}
|
||||
// 妖晶抽奖
|
||||
else {
|
||||
// 验证妖晶购买特权
|
||||
boolean check = PlayerLogic.getInstance().check(user, setting.getDiamondMaxTimes(), num);
|
||||
if (!check){
|
||||
throw new ErrorCodeException(ErrorCode.REFRESH_WHEL_TIME_NOT);
|
||||
}
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
}
|
||||
// 返回奖励信息
|
||||
build.setDrop(drop);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceHeroRewardResponse_VALUE,build.build(),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 心愿 获取奖励
|
||||
* @param user
|
||||
* @param activityId
|
||||
* @param num
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private CommonProto.Drop.Builder getDrawReward(User user,int activityId,int num) throws Exception {
|
||||
// 奖励信息
|
||||
int[][] reward = new int[num][];
|
||||
// 活动信息
|
||||
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(activityId);
|
||||
// 累计得抽奖次数
|
||||
int count = mission.getV();
|
||||
// up奖励id
|
||||
int upRewardId = mission.getChoiceRewardId();
|
||||
|
||||
// 排序权重map
|
||||
Map<Integer, Integer> weight = new TreeMap<>(SWishActivityPool.weight);
|
||||
// 常驻卡池
|
||||
Map<Integer, SWishActivityPool> poolMap = SWishActivityPool.map;
|
||||
// 根据活动获取本期得全部up信息
|
||||
Map<Integer, int[]> up = SWishActivityUp.upMap.get(activityId);
|
||||
// 根据玩家选取得up奖励id获取详细信息
|
||||
int[] incs = up.get(upRewardId);
|
||||
// 讲up奖励id得权重加入到整个卡池权重中
|
||||
weight.put(weight.size(),incs[2]);
|
||||
// 计算总权重
|
||||
int totalWeight = weight.values().stream().mapToInt(Integer::intValue).sum();
|
||||
|
||||
int i = 0;
|
||||
// 根据抽奖次数循环
|
||||
while (i < num){
|
||||
// 默认计数器
|
||||
i++;
|
||||
// 已抽奖次数+1
|
||||
count++;
|
||||
// 随机数
|
||||
int randomInt = MathUtils.randomInt(totalWeight);
|
||||
// up奖励信息
|
||||
int[] result = new int[]{incs[0],incs[1]};
|
||||
|
||||
// 抽奖次数达到必出up次数
|
||||
if (count >= incs[3]){
|
||||
// 次数归0
|
||||
count = 0;
|
||||
// 添加奖励
|
||||
reward[i] = result;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 权重循环
|
||||
for (Map.Entry<Integer, Integer> entry : weight.entrySet()) {
|
||||
// 随机值小于等于当前次数权重,证明抽到了
|
||||
if (randomInt <= entry.getValue()){
|
||||
// 根据id获取奖池信息
|
||||
SWishActivityPool pool = poolMap.get(entry.getKey());
|
||||
// null意味着是up奖励
|
||||
if (pool == null){
|
||||
count = 0;
|
||||
reward[i] = result;
|
||||
}
|
||||
// 非up奖励
|
||||
else {
|
||||
reward[i] = pool.getItemId();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 未抽到, 减去当前次数权重
|
||||
randomInt -= entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新抽奖次数和up奖励id
|
||||
mission.setV(count);
|
||||
// 返回奖励信息
|
||||
return ItemUtil.dropPer(user, reward, BIReason.CHOICE_DRAW_CARD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public interface ActivityType {
|
|||
int JADE_DYNASTY_MISSION = 20000;//破阵诛仙任务
|
||||
int JADE_DYNASTY_SHOP = 20001;//破阵诛仙限时商市
|
||||
int JADE_DYNASTY_RARE_SHOP = 20002;//破阵诛仙珍奇宝阁
|
||||
int CHOICE_DRAW_CRAD = 20003;//心愿抽奖(选择抽卡)
|
||||
int ITEMS_STORE= 6000;//百宝商会
|
||||
int TRIAL_EXPERT = 70;//幻境达人
|
||||
int SHEJI_ACTIVITY = 60;//社稷大典
|
||||
|
|
|
@ -71,7 +71,7 @@ public enum ActivityTypeEnum {
|
|||
LUCKY_GET(ActivityType.LUCKY_GET,LuckyGetActivity::new),
|
||||
EQUIP_UPLEVEL(ActivityType.EQUIP_UPLEVEL,EquipUpLevelActivity::new),
|
||||
TA_SUI_LING_XIAO(ActivityType.TA_SUI_LING_XIAO,TaSuiLingXiaoActivity::new),
|
||||
|
||||
CHOICE_DRAW_CRAD(ActivityType.CHOICE_DRAW_CRAD,ChoiceDrawCardActivity::new),
|
||||
|
||||
;
|
||||
private int type;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import config.SWishActivityUp;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author hj
|
||||
* 心愿抽奖活动
|
||||
*/
|
||||
public class ChoiceDrawCardActivity extends AbstractActivity {
|
||||
|
||||
ChoiceDrawCardActivity(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initActivity(User user) throws Exception {
|
||||
ActivityMission mission = new ActivityMission();
|
||||
ActivityLogic.getInstance().initOtherMission(mission, new ArrayList<>());
|
||||
mission.setChoiceRewardId(SWishActivityUp.defaultMap.get(id));
|
||||
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||
LOGGER.info("心愿抽卡初始化..."+id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@Table(name ="WishActivityPool")
|
||||
public class SWishActivityPool implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int[] itemId;
|
||||
|
||||
private int getRate;
|
||||
|
||||
public static Map<Integer,Integer> weight = new TreeMap<>();
|
||||
|
||||
public static Map<Integer,SWishActivityPool> map = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Map<Integer, SWishActivityPool> config = STableManager.getConfig(SWishActivityPool.class);
|
||||
config.values().forEach(v->{
|
||||
map.put(v.getId(),v);
|
||||
weight.put(v.getId(),v.getGetRate());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int[] getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public int getGetRate() {
|
||||
return getRate;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name ="WishActivitySetting")
|
||||
public class SWishActivitySetting implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int[][] costItemSingle;
|
||||
|
||||
private int[][] costItemMul;
|
||||
|
||||
private int freeTimes;
|
||||
|
||||
private int maxTimes;
|
||||
|
||||
private int diamondMaxTimes;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int[][] getCostItemSingle() {
|
||||
return costItemSingle;
|
||||
}
|
||||
|
||||
public int[][] getCostItemMul() {
|
||||
return costItemMul;
|
||||
}
|
||||
|
||||
public int getFreeTimes() {
|
||||
return freeTimes;
|
||||
}
|
||||
|
||||
public int getMaxTimes() {
|
||||
return maxTimes;
|
||||
}
|
||||
|
||||
public int getDiamondMaxTimes() {
|
||||
return diamondMaxTimes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name ="WishActivityUp")
|
||||
public class SWishActivityUp implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int activityId;
|
||||
|
||||
private int[][] upList;
|
||||
|
||||
/**
|
||||
* 每期活动
|
||||
* key: 活动id value: SWishActivityUp对象
|
||||
*/
|
||||
public static Map<Integer,SWishActivityUp> map = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 每期得up
|
||||
* key: 活动id value->map: key: upList[0][0](道具id) value: upList[0](道具详情)
|
||||
*/
|
||||
public static Map<Integer,Map<Integer,int[]>> upMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 默认up
|
||||
* key: 活动id value: 默认up奖励id
|
||||
*/
|
||||
public static Map<Integer, Integer> defaultMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Map<Integer, SWishActivityUp> config = STableManager.getConfig(SWishActivityUp.class);
|
||||
config.values().forEach(v->{
|
||||
// 每期活动
|
||||
map.put(v.getActivityId(),v);
|
||||
// 每期全部up
|
||||
HashMap<Integer, int[]> map1 = new HashMap<>(v.getUpList().length);
|
||||
for (int[] ints : v.getUpList()) {
|
||||
map1.put(ints[0],ints);
|
||||
}
|
||||
upMap.put(v.getActivityId(),map1);
|
||||
// 每期up默认奖励id
|
||||
defaultMap.put(v.getActivityId(),v.getUpList()[0][0]);
|
||||
});
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public int[][] getUpList() {
|
||||
return upList;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue