全民福利
parent
2df133f4d2
commit
add9233993
|
@ -443,6 +443,9 @@ public class RedisKey {
|
|||
// 御剑飞行时间锁
|
||||
public static final String RIDING_SWARD_TIME_LOCK = "RIDING_SWARD_TIME_LOCK";
|
||||
|
||||
//全民福利购买礼包次数
|
||||
public static final String ALL_PEOPLE_WELFARE_BUY_COUNT = "ALL_PEOPLE_WELFARE_BUY_COUNT";
|
||||
|
||||
public static Set<String> newAreaCacChe = new HashSet<>();//进程排行 合区统一
|
||||
|
||||
public static Set<String> rankCacChe = new HashSet<>();
|
||||
|
|
|
@ -136,4 +136,6 @@ public interface ActivityType {
|
|||
int WHOLE_LIFE_CARD = 99;//终生卡
|
||||
|
||||
int WEEK_CARD = 102;//月卡
|
||||
|
||||
int ALL_PEOPLE_WELFARE = 105;//全民福利
|
||||
}
|
||||
|
|
|
@ -110,8 +110,9 @@ public enum ActivityTypeEnum {
|
|||
DONGHAI_XUNXIAN_ACTIVITY(ActivityType.DonghaiXunxian,DonghaiXunxianActivity::new),//东海寻仙
|
||||
WHOEL_LIFE_ACTIVITY(ActivityType.WHOLE_LIFE_CARD,WholeLifeActivity::new),//东海寻仙
|
||||
ENCHANTER_STORE(ActivityType.ENCHANTER_STORE,DefaultEmptyActivity::new),//寻仙商城
|
||||
|
||||
WEEK_CARD(ActivityType.WEEK_CARD,WeekCardActivity::new),//月卡
|
||||
// bt
|
||||
ALL_PEOPLE_WELFARE(ActivityType.ALL_PEOPLE_WELFARE,AllPeopleWelfareActivity::new),//全民福利
|
||||
;
|
||||
|
||||
private int type;
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
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.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.SuperBoxEvent;
|
||||
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.SUniversalWelfareConfig;
|
||||
import manager.STableManager;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hj
|
||||
* 全民福利活动-bt版
|
||||
* 2022-9-6
|
||||
*/
|
||||
public class AllPeopleWelfareActivity extends AbstractActivity {
|
||||
|
||||
AllPeopleWelfareActivity(int id) {
|
||||
super(id);
|
||||
Poster.getPoster().listenEvent(this, SuperBoxEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initActivity(User user) throws Exception {
|
||||
// 活动信息初始化
|
||||
ActivityMission mission = new ActivityMission();
|
||||
ActivityLogic.getInstance().initOtherMission(mission, new ArrayList<>());
|
||||
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||
LOGGER.info("全民福利活动-bt版...uid={},activityId={}",user.getId(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
// 类型验证
|
||||
if (!(event instanceof SuperBoxEvent)) {
|
||||
return;
|
||||
}
|
||||
// 获取信息
|
||||
SuperBoxEvent event1 = (SuperBoxEvent) event;
|
||||
User user = UserManager.getUser(event1.getUserId());
|
||||
// 活动数据处理
|
||||
updateValue(event1.getGiftId());
|
||||
// 状态推送
|
||||
sendActivityProgress(user, user.getActivityManager().getActivityMissionMap().get(id), null);
|
||||
}
|
||||
|
||||
public static int getValue(){
|
||||
return (int)Optional.ofNullable(RedisUtil.getInstence().get(RedisKey.ALL_PEOPLE_WELFARE_BUY_COUNT)).orElse(0);
|
||||
}
|
||||
|
||||
public static void addValue(int count){
|
||||
int value = getValue()+count;
|
||||
RedisUtil.getInstence().set(RedisKey.ALL_PEOPLE_WELFARE_BUY_COUNT,String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数
|
||||
* @param giftId
|
||||
*/
|
||||
private void updateValue(int giftId){
|
||||
List<Integer> giftList = SUniversalWelfareConfig.getGiftList();
|
||||
// 验证礼包id
|
||||
if (giftList.contains(giftId)){
|
||||
addValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonProto.ActivityInfo.MissionInfo> getAllMissInfo(User user,ActivityMission activityMission, Set<Integer> filter) {
|
||||
if (activityMission == null){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// 库里存储的活动档位信息
|
||||
Map<Integer, ActivityProgressInfo> progressInfoMap = activityMission.getActivityMissionMap();
|
||||
// 策划表的配置
|
||||
Map<Integer, SUniversalWelfareConfig> config = STableManager.getConfig(SUniversalWelfareConfig.class);
|
||||
// 返回对象
|
||||
List<CommonProto.ActivityInfo.MissionInfo> missionInfos = new ArrayList<>(config.size());
|
||||
int value = getValue();
|
||||
for (Map.Entry<Integer, SUniversalWelfareConfig> entry : config.entrySet()) {
|
||||
// 参数初始化
|
||||
int missionId = entry.getKey();
|
||||
int state = getState(progressInfoMap.get(missionId));
|
||||
// 封装proto并返回
|
||||
CommonProto.ActivityInfo.MissionInfo build = CommonProto.ActivityInfo.MissionInfo.newBuilder()
|
||||
.setMissionId(missionId)
|
||||
.setProgress(value)
|
||||
.setState(state)
|
||||
.build();
|
||||
missionInfos.add(build);
|
||||
}
|
||||
return missionInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态
|
||||
* @param progressInfo
|
||||
* @return
|
||||
*/
|
||||
private int getState(ActivityProgressInfo progressInfo){
|
||||
int state = 0;
|
||||
if (progressInfo != null && progressInfo.getState() == ActivityType.HAD_TAKED){
|
||||
state = ActivityType.HAD_TAKED;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取奖励
|
||||
* @param session
|
||||
* @param missionId
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean takeReward(ISession session, int missionId) throws Exception {
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
// activity check
|
||||
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||
if (mission == null){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"活动信息不存在:"+id);
|
||||
}
|
||||
SUniversalWelfareConfig welfareConfig = STableManager.getConfig(SUniversalWelfareConfig.class).get(missionId);
|
||||
if (welfareConfig == null){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"领取挡位不存在,活动id ==> 挡位id:"+id+"==>"+missionId);
|
||||
}
|
||||
ActivityProgressInfo progressInfo = mission.getActivityMissionMap().get(missionId);
|
||||
if (progressInfo != null && progressInfo.getState() == ActivityType.HAD_TAKED){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"档位已领取,活动id ==> 挡位id:"+id+"==>"+missionId);
|
||||
}
|
||||
int value = getValue();
|
||||
if (value < welfareConfig.getPeolple()){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"条件不满足,活动id ==> 挡位id ==> 当前数量:"+id+"==>"+missionId+"==>"+value);
|
||||
}
|
||||
// reward
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, welfareConfig.getType(), BIReason.TAKE_ACTIVITY_REWARD);
|
||||
// 更新数据库
|
||||
ActivityProgressInfo info = new ActivityProgressInfo();
|
||||
info.setState(ActivityType.HAD_TAKED);
|
||||
mission.getActivityMissionMap().put(missionId,info);
|
||||
|
||||
PlayerInfoProto.TakeActivityRewardResponse build = PlayerInfoProto.TakeActivityRewardResponse.newBuilder().setDrop(drop).build();
|
||||
MessageUtil.sendMessage(session, 1, rewardResponseValue, build, true);
|
||||
// 状态推送
|
||||
sendActivityProgress(session, mission, null);
|
||||
// 打点上报
|
||||
reportTakeActivityReward(user,welfareConfig.getType(),missionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.ljsd.jieling.logic.activity.event;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/5/26 11:05
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Table(name ="UniversalWelfareConfig")
|
||||
public class SUniversalWelfareConfig implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int peolple;
|
||||
|
||||
private int[][] type;
|
||||
|
||||
private int rechargeCom;
|
||||
|
||||
private static List<Integer> giftList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Map<Integer, SUniversalWelfareConfig> config = STableManager.getConfig(SUniversalWelfareConfig.class);
|
||||
List<Integer> list = config.values().stream().map(SUniversalWelfareConfig::getRechargeCom).collect(Collectors.toList());
|
||||
giftList.clear();
|
||||
giftList = list;
|
||||
}
|
||||
|
||||
public static List<Integer> getGiftList() {
|
||||
return giftList;
|
||||
}
|
||||
|
||||
public int getid() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getPeolple() {
|
||||
return peolple;
|
||||
}
|
||||
|
||||
public int[][] getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getRechargeCom() {
|
||||
return rechargeCom;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue