心愿抽奖,后端自测完成
parent
d1a2849a56
commit
ab885c392a
|
@ -11,6 +11,7 @@ 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 org.springframework.stereotype.Component;
|
||||
import rpc.protocols.ActivityProto;
|
||||
import rpc.protocols.Family;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
@ -25,6 +26,7 @@ import java.util.stream.Collectors;
|
|||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class ChoiceHeroRewardHandler extends BaseHandler<ActivityProto.choiceHeroRewardRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
|
@ -39,12 +41,12 @@ public class ChoiceHeroRewardHandler extends BaseHandler<ActivityProto.choiceHer
|
|||
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){
|
||||
|
|
|
@ -85,6 +85,7 @@ public final class ActivityMission extends MongoBase {
|
|||
|
||||
public void setChoiceRewardId(int choiceRewardId) {
|
||||
this.choiceRewardId = choiceRewardId;
|
||||
updateString("choiceRewardId",choiceRewardId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1526,51 +1526,68 @@ public class ActivityLogic implements IEventHandler{
|
|||
* @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;
|
||||
SWishActivitySetting setting = STableManager.getConfig(SWishActivitySetting.class).get(1);
|
||||
// 抽奖次数
|
||||
int num = type == 1?1:10;
|
||||
// 抽奖上限
|
||||
boolean check1 = PlayerLogic.getInstance().check(user, setting.getMaxTimes(), num);
|
||||
if (!check1){
|
||||
throw new ErrorCodeException(ErrorCode.REFRESH_WHEL_TIME_NOT, "抽奖次数不足");
|
||||
}
|
||||
CommonProto.Drop.Builder drop;
|
||||
// 单抽
|
||||
if (num == 1){
|
||||
// 验证免费特权
|
||||
boolean check = PlayerLogic.getInstance().checkAndUpdate(user, setting.getFreeTimes(), num);
|
||||
if (check){
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
drop = getDrawReward(user, activityId, num);
|
||||
// 发送奖励
|
||||
build.setDrop(drop);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceHeroRewardResponse_VALUE,build.build(),true);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceDrawCardResponse_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);
|
||||
// 验证道具消耗
|
||||
int[][] cost = new int[][]{{item[0][0],item[0][1]}};
|
||||
boolean itemCost = ItemUtil.itemCost(user, cost, BIReason.CHOICE_DRAW_CARD, 0);
|
||||
// 道具抽奖
|
||||
if (itemCost){
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
drop = getDrawReward(user, activityId, num);
|
||||
}
|
||||
// 妖晶抽奖
|
||||
else {
|
||||
// 验证妖晶购买特权
|
||||
boolean check = PlayerLogic.getInstance().check(user, setting.getDiamondMaxTimes(), num);
|
||||
if (!check){
|
||||
throw new ErrorCodeException(ErrorCode.REFRESH_WHEL_TIME_NOT);
|
||||
throw new ErrorCodeException(ErrorCode.REFRESH_WHEL_TIME_NOT,"妖晶抽奖次数不足");
|
||||
}
|
||||
drop = getDrawReward(user, activityId, type);
|
||||
|
||||
// 验证妖晶消耗
|
||||
int[][] cost2 = new int[][]{{item[1][0],item[1][1]}};
|
||||
boolean itemCost2 = ItemUtil.itemCost(user, cost2, BIReason.CHOICE_DRAW_CARD, 0);
|
||||
if (!itemCost2){
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
//特权次数消耗
|
||||
PlayerLogic.getInstance().checkAndUpdate(user, setting.getDiamondMaxTimes(), num);
|
||||
drop = getDrawReward(user, activityId, num);
|
||||
}
|
||||
|
||||
// 特权消耗
|
||||
PlayerLogic.getInstance().checkAndUpdate(user, setting.getMaxTimes(), num);
|
||||
|
||||
// 事件分发
|
||||
Poster.getPoster().dispatchEvent(new ChoiceDrawCardEvent(user.getId(),activityId,num));
|
||||
|
||||
// 返回奖励信息
|
||||
build.setDrop(drop);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceHeroRewardResponse_VALUE,build.build(),true);
|
||||
MessageUtil.sendMessage(user.getId(),1, MessageTypeProto.MessageType.choiceDrawCardResponse_VALUE,build.build(),true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1607,8 +1624,6 @@ public class ActivityLogic implements IEventHandler{
|
|||
int i = 0;
|
||||
// 根据抽奖次数循环
|
||||
while (i < num){
|
||||
// 默认计数器
|
||||
i++;
|
||||
// 已抽奖次数+1
|
||||
count++;
|
||||
// 随机数
|
||||
|
@ -1621,7 +1636,7 @@ public class ActivityLogic implements IEventHandler{
|
|||
// 次数归0
|
||||
count = 0;
|
||||
// 添加奖励
|
||||
reward[i] = result;
|
||||
reward[i++] = result;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1634,11 +1649,11 @@ public class ActivityLogic implements IEventHandler{
|
|||
// null意味着是up奖励
|
||||
if (pool == null){
|
||||
count = 0;
|
||||
reward[i] = result;
|
||||
reward[i++] = result;
|
||||
}
|
||||
// 非up奖励
|
||||
else {
|
||||
reward[i] = pool.getItemId();
|
||||
reward[i++] = pool.getItemId();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,126 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.globals.BIReason;
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.jbean.ActivityProgressInfo;
|
||||
import com.ljsd.jieling.logic.activity.event.ChoiceDrawCardEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
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.ItemUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import config.SActivityRewardConfig;
|
||||
import config.SWishActivityUp;
|
||||
import java.util.ArrayList;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author hj
|
||||
* 心愿抽奖活动
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public class ChoiceDrawCardActivity extends AbstractActivity {
|
||||
|
||||
ChoiceDrawCardActivity(int id) {
|
||||
super(id);
|
||||
Poster.getPoster().listenEvent(this, ChoiceDrawCardEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initActivity(User user) throws Exception {
|
||||
ActivityMission mission = new ActivityMission();
|
||||
ActivityLogic.getInstance().initOtherMission(mission, new ArrayList<>());
|
||||
// 读表获取阶段奖励信息
|
||||
List<SActivityRewardConfig> configs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(id);
|
||||
List<Integer> list = configs.stream().mapToInt(SActivityRewardConfig::getId).boxed().collect(Collectors.toList());
|
||||
// 初始化阶段奖励
|
||||
ActivityLogic.getInstance().initOtherMission(mission, list);
|
||||
// 添加默认选择奖励
|
||||
mission.setChoiceRewardId(SWishActivityUp.defaultMap.get(id));
|
||||
|
||||
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||
LOGGER.info("心愿抽卡初始化..."+id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
// 类型验证
|
||||
if (!(event instanceof ChoiceDrawCardEvent)) {
|
||||
return;
|
||||
}
|
||||
// 获取信息
|
||||
ChoiceDrawCardEvent drawCardEvent = (ChoiceDrawCardEvent) event;
|
||||
// 用户
|
||||
int userId = drawCardEvent.getUserId();
|
||||
User user = UserManager.getUser(userId);
|
||||
// 更新进度
|
||||
update(user,drawCardEvent.getNum());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeReward(ISession session, int missionId) throws Exception {
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
//checkAndUpdate cfg
|
||||
SActivityRewardConfig config = SActivityRewardConfig.getsActivityRewardConfigByMissionId(missionId);
|
||||
if (config == null || config.getActivityId() != id) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL,"功能不存在:"+missionId);
|
||||
}
|
||||
// acitvityinfo check
|
||||
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||
if (mission == null){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE,"数据错误");
|
||||
}
|
||||
if (mission.getActivityState() != ActivityType.OPEN_STATE || mission.getOpenType() == 0) {
|
||||
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN,"活动未开启");
|
||||
}
|
||||
ActivityProgressInfo progressInfo = mission.getActivityMissionMap().get(missionId);
|
||||
if (progressInfo == null || progressInfo.getState() == ActivityType.HAD_TAKED) {
|
||||
throw new ErrorCodeException(ErrorCode.newDefineCode("活动奖励已经领取"));
|
||||
}
|
||||
// 验证领取条件值
|
||||
if (!takeRewardsProcess(session,config,progressInfo)) {
|
||||
LOGGER.error("the uid={} the misionId={},the missionProgress={},the require is={} ", session.getUid(), config.getId(), progressInfo.getProgrss(), config.getValues());
|
||||
throw new ErrorCodeException(ErrorCode.newDefineCode("未达到领取条件"));
|
||||
}
|
||||
// 验证配置表
|
||||
int[] incs = SWishActivityUp.rewardMap.get(id).get(mission.getChoiceRewardId());
|
||||
if (incs == null){
|
||||
throw new ErrorCodeException(ErrorCode.newDefineCode("数据错误"));
|
||||
}
|
||||
// 更改任务状态
|
||||
checkAndSetProgress(mission,progressInfo,missionId);
|
||||
//up miss
|
||||
int[][] reward = getReward(config.getReward(),incs[config.getSort()-1]);
|
||||
// reward
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, reward, BIReason.TAKE_ACTIVITY_REWARD);
|
||||
PlayerInfoProto.TakeActivityRewardResponse build = PlayerInfoProto.TakeActivityRewardResponse.newBuilder().setDrop(drop).build();
|
||||
MessageUtil.sendMessage(session, 1, rewardResponseValue, build, true);
|
||||
// 状态推送
|
||||
sendActivityProgress(session, mission, null);
|
||||
// 打点上报
|
||||
reportTakeActivityReward(user,reward,missionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊处理奖励
|
||||
* @param reward 默认奖励配置
|
||||
* @param replace 替换得奖励配置
|
||||
* @return
|
||||
*/
|
||||
private int[][] getReward(int[][] reward, int rewardId){
|
||||
int[][] result = new int[reward.length][2];
|
||||
for (int i = 0; i < reward.length; i++) {
|
||||
result[i][0] = rewardId;
|
||||
result[i][1] = reward[i][1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.ljsd.jieling.logic.activity.event;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/5/26 11:05
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ChoiceDrawCardEvent implements IEvent {
|
||||
|
||||
private int userId;
|
||||
private int activityId;
|
||||
private int num;
|
||||
|
||||
public ChoiceDrawCardEvent(int userId, int activityId, int num) {
|
||||
this.userId = userId;
|
||||
this.activityId = activityId;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public void setActivityId(int activityId) {
|
||||
this.activityId = activityId;
|
||||
}
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(int num) {
|
||||
this.num = num;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ public class SActivityRewardConfig implements BaseConfig {
|
|||
|
||||
private int[][] reward;
|
||||
|
||||
private int sort;
|
||||
|
||||
private static Map<Integer, SActivityRewardConfig> sActivityRewardConfigMap;
|
||||
|
||||
private static Map<Integer, List<SActivityRewardConfig>> sActivityRewardConfigListMap;
|
||||
|
@ -64,5 +66,7 @@ public class SActivityRewardConfig implements BaseConfig {
|
|||
return reward;
|
||||
}
|
||||
|
||||
|
||||
public int getSort() {
|
||||
return sort;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ public class SWishActivityUp implements BaseConfig {
|
|||
|
||||
private int[][] upList;
|
||||
|
||||
private int[][] rewardList;
|
||||
|
||||
/**
|
||||
* 每期活动
|
||||
* key: 活动id value: SWishActivityUp对象
|
||||
|
@ -27,6 +29,12 @@ public class SWishActivityUp implements BaseConfig {
|
|||
*/
|
||||
public static Map<Integer,Map<Integer,int[]>> upMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 每期得reward
|
||||
* key: 活动id value->map: key: upList[0][0](道具id) value: rewardList[0](奖励详情)
|
||||
*/
|
||||
public static Map<Integer,Map<Integer,int[]>> rewardMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 默认up
|
||||
* key: 活动id value: 默认up奖励id
|
||||
|
@ -39,14 +47,22 @@ public class SWishActivityUp implements BaseConfig {
|
|||
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]);
|
||||
|
||||
// 每期全部up
|
||||
HashMap<Integer, int[]> map1 = new HashMap<>(v.getUpList().length);
|
||||
// 每期得奖励
|
||||
HashMap<Integer, int[]> map2 = new HashMap<>(v.getRewardList().length);
|
||||
|
||||
for (int i = 0; i < v.getUpList().length; i++) {
|
||||
map1.put(v.getUpList()[i][0],v.getUpList()[i]);
|
||||
map2.put(v.getUpList()[i][0],v.getRewardList()[i]);
|
||||
}
|
||||
|
||||
upMap.put(v.getActivityId(),map1);
|
||||
rewardMap.put(v.getActivityId(),map2);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -62,5 +78,7 @@ public class SWishActivityUp implements BaseConfig {
|
|||
return upList;
|
||||
}
|
||||
|
||||
|
||||
public int[][] getRewardList() {
|
||||
return rewardList;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue