Merge branch 'master_test_gn' of http://60.1.1.230/backend/jieling_server into master_test_gn
commit
9193d8b6da
|
@ -13,6 +13,8 @@ import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||||
import com.ljsd.jieling.logic.activity.FightMainEventHandler;
|
import com.ljsd.jieling.logic.activity.FightMainEventHandler;
|
||||||
import com.ljsd.jieling.logic.activity.RemoveEventHeroHandler;
|
import com.ljsd.jieling.logic.activity.RemoveEventHeroHandler;
|
||||||
import com.ljsd.jieling.logic.activity.UserLevelEventHandler;
|
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.redpacket.WelfareRedPackSendHandler;
|
import com.ljsd.jieling.logic.redpacket.WelfareRedPackSendHandler;
|
||||||
import com.ljsd.jieling.logic.activity.eventhandler.ActivityStateChangeHandler;
|
import com.ljsd.jieling.logic.activity.eventhandler.ActivityStateChangeHandler;
|
||||||
import com.ljsd.jieling.logic.activity.eventhandler.BuyGoodsDirectHandler;
|
import com.ljsd.jieling.logic.activity.eventhandler.BuyGoodsDirectHandler;
|
||||||
|
@ -380,6 +382,9 @@ public class GlobalDataManaager implements IManager {
|
||||||
// 道具刷新
|
// 道具刷新
|
||||||
BuyGoodsNewLogic.refreshWelfareState(user);
|
BuyGoodsNewLogic.refreshWelfareState(user);
|
||||||
user.getUserMissionManager().onGameEvent(user, GameEvent.LOGIN_GAME,0);
|
user.getUserMissionManager().onGameEvent(user, GameEvent.LOGIN_GAME,0);
|
||||||
|
|
||||||
|
// 惊喜礼盒,事件推送
|
||||||
|
Poster.getPoster().dispatchEvent(new SuperBoxEvent(user.getId(),-1));
|
||||||
}
|
}
|
||||||
user.getPlayerInfoManager().setLoginTime(TimeUtils.now());
|
user.getPlayerInfoManager().setLoginTime(TimeUtils.now());
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,5 +94,6 @@ public interface ActivityType {
|
||||||
int DEMON_TREASURE = 36;//降妖夺宝
|
int DEMON_TREASURE = 36;//降妖夺宝
|
||||||
int NEW_GENERAL_ATTACK = 200;//新将来袭
|
int NEW_GENERAL_ATTACK = 200;//新将来袭
|
||||||
|
|
||||||
|
int SUPER_BOX = 69;//惊喜礼盒
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ public enum ActivityTypeEnum {
|
||||||
EQUIP_UPLEVEL(ActivityType.EQUIP_UPLEVEL,EquipUpLevelActivity::new),
|
EQUIP_UPLEVEL(ActivityType.EQUIP_UPLEVEL,EquipUpLevelActivity::new),
|
||||||
TA_SUI_LING_XIAO(ActivityType.TA_SUI_LING_XIAO,TaSuiLingXiaoActivity::new),
|
TA_SUI_LING_XIAO(ActivityType.TA_SUI_LING_XIAO,TaSuiLingXiaoActivity::new),
|
||||||
CHOICE_DRAW_CRAD(ActivityType.CHOICE_DRAW_CRAD,ChoiceDrawCardActivity::new),
|
CHOICE_DRAW_CRAD(ActivityType.CHOICE_DRAW_CRAD,ChoiceDrawCardActivity::new),
|
||||||
|
SUPER_BOX(ActivityType.SUPER_BOX,SuperBoxActivity::new),
|
||||||
|
|
||||||
;
|
;
|
||||||
private int type;
|
private int type;
|
||||||
|
|
|
@ -0,0 +1,257 @@
|
||||||
|
package com.ljsd.jieling.logic.activity;
|
||||||
|
|
||||||
|
import com.ljsd.GameApplication;
|
||||||
|
import com.ljsd.jieling.globals.Global;
|
||||||
|
import com.ljsd.jieling.jbean.ActivityMission;
|
||||||
|
import com.ljsd.jieling.jbean.ActivityProgressInfo;
|
||||||
|
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||||
|
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.ServerConfig;
|
||||||
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
|
import config.SGlobalActivity;
|
||||||
|
import config.SSurpriseBox;
|
||||||
|
import manager.STableManager;
|
||||||
|
import util.TimeUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hj
|
||||||
|
* 惊喜礼盒活动
|
||||||
|
*
|
||||||
|
* 礼盒状态:
|
||||||
|
* 已解锁可购买 1
|
||||||
|
* 已解锁不可购买 2
|
||||||
|
* 未解锁可见可预览 3
|
||||||
|
* 未解锁可见不可预览 4
|
||||||
|
* 未解锁不可见 5
|
||||||
|
* 已购买 6
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
|
public class SuperBoxActivity extends AbstractActivity {
|
||||||
|
|
||||||
|
SuperBoxActivity(int id) {
|
||||||
|
super(id);
|
||||||
|
Poster.getPoster().listenEvent(this, SuperBoxEvent.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initActivity(User user) throws Exception {
|
||||||
|
ActivityMission mission = new ActivityMission();
|
||||||
|
// 读表获取阶段奖励信息
|
||||||
|
Map<Integer, SSurpriseBox> boxMap = SSurpriseBox.map.getOrDefault(id,new HashMap<>());
|
||||||
|
if (boxMap.isEmpty()){
|
||||||
|
LOGGER.error("惊喜礼盒初始化失败,活动id:"+id);
|
||||||
|
}
|
||||||
|
List<Integer> list = boxMap.values().stream().mapToInt(SSurpriseBox::getId).boxed().collect(Collectors.toList());
|
||||||
|
// 初始化阶段奖励
|
||||||
|
ActivityLogic.getInstance().initOtherMission(mission, list);
|
||||||
|
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||||
|
// 修改状态
|
||||||
|
updateState(user);
|
||||||
|
LOGGER.info("惊喜礼盒初始化..."+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(IEvent event) throws Exception {
|
||||||
|
// 类型验证
|
||||||
|
if (!(event instanceof SuperBoxEvent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 获取信息
|
||||||
|
SuperBoxEvent event1 = (SuperBoxEvent) event;
|
||||||
|
User user = UserManager.getUser(event1.getUserId());
|
||||||
|
// 礼包处理
|
||||||
|
giftHandle(user, event1.getGiftId());
|
||||||
|
// 状态刷新
|
||||||
|
updateState(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 礼包处理
|
||||||
|
* @param user
|
||||||
|
* @param giftId
|
||||||
|
* @param missionMap
|
||||||
|
*/
|
||||||
|
private void giftHandle(User user, int giftId){
|
||||||
|
if (giftId == -1){
|
||||||
|
// 非礼包处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, ActivityProgressInfo> missionMap = user.getActivityManager().getActivityMissionMap().get(id).getActivityMissionMap();
|
||||||
|
Collection<SSurpriseBox> boxes = SSurpriseBox.map.getOrDefault(id, new HashMap<>(0)).values();
|
||||||
|
|
||||||
|
for (SSurpriseBox box : boxes) {
|
||||||
|
if (box.getPackId() == giftId){
|
||||||
|
// 当前礼包状态处理
|
||||||
|
ActivityProgressInfo current = missionMap.get(box.getId());
|
||||||
|
if (current != null){
|
||||||
|
current.setState(ActivityType.HAD_TAKED);
|
||||||
|
current.setProgrss(8);
|
||||||
|
missionMap.put(box.getId(),current);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态
|
||||||
|
* 次数代码非必要不要进行修改,包含N多的嵌套if
|
||||||
|
* 不要问我为啥写的这么恶心,因为我自己也不知怎么写出来的
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
private void updateState(User user){
|
||||||
|
long now = TimeUtils.now();
|
||||||
|
long start = getSrartTime();
|
||||||
|
long end = getEndTime();
|
||||||
|
// 验证活动是否开启
|
||||||
|
if (now < start || now > end){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||||
|
// 计算过去了几天
|
||||||
|
int days = TimeUtils.getSoFarWentDays(start, now);
|
||||||
|
mission.setV(days);
|
||||||
|
// mission 单个礼包
|
||||||
|
Map<Integer, ActivityProgressInfo> missionMap = mission.getActivityMissionMap();
|
||||||
|
Map<Integer, SSurpriseBox> boxMap = SSurpriseBox.map.get(id);
|
||||||
|
// 极为恶心的循环,包含超多的if-else
|
||||||
|
for (Map.Entry<Integer, ActivityProgressInfo> entry : missionMap.entrySet()) {
|
||||||
|
int k = entry.getKey();
|
||||||
|
ActivityProgressInfo v = entry.getValue();
|
||||||
|
int progrss = v.getProgrss();
|
||||||
|
// 是否已购买
|
||||||
|
if (progrss == 8){
|
||||||
|
// 已购买
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSurpriseBox box = boxMap.get(k);
|
||||||
|
// 未购买, 是否解锁
|
||||||
|
if (days >= box.getUnlockDay()){
|
||||||
|
// 已解锁, 可买天数
|
||||||
|
if (days >= box.getBuyDay()){
|
||||||
|
// 可买, 是否购买前置礼包
|
||||||
|
if (checkBuyAgo(user,box.getId())){
|
||||||
|
// 已购买前置. 是否需要特权, 是否激活特权
|
||||||
|
progrss = checkRule(user,box.getRule())?1:4;
|
||||||
|
}else {
|
||||||
|
// 未购买前置
|
||||||
|
progrss = 3;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
// 不可买
|
||||||
|
progrss = 2;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
// 未解锁, 是否可见
|
||||||
|
if (days >= box.getVisibleDay()){
|
||||||
|
// 可见, 是否可预览
|
||||||
|
progrss = days >= box.getViewDay()?6:7;
|
||||||
|
}else {
|
||||||
|
// 不可见
|
||||||
|
progrss = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.setProgrss(progrss);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 客户端推送
|
||||||
|
ISession session = OnlineUserManager.getSessionByUid(user.getId());
|
||||||
|
sendActivityProgress(session, mission, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long getSrartTime(){
|
||||||
|
long startTime = 0;
|
||||||
|
SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(id);
|
||||||
|
// 绝对时间
|
||||||
|
if (activity.getType() == ActivityType.OPEN_TYPE_TIME){
|
||||||
|
startTime = activity.getStartTimeLong();
|
||||||
|
}
|
||||||
|
// 开服时间
|
||||||
|
else if (activity.getType() == ActivityType.OPEN_TYPE_SERVER) {
|
||||||
|
String openTime = GameApplication.serverConfig.getOpenTime();
|
||||||
|
startTime = TimeUtils.stringToTimeLong2(openTime);
|
||||||
|
}
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long getEndTime(){
|
||||||
|
long endTime = 0;
|
||||||
|
SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(id);
|
||||||
|
// 绝对时间
|
||||||
|
if (activity.getType() == ActivityType.OPEN_TYPE_TIME){
|
||||||
|
endTime = activity.getEndTimeLong();
|
||||||
|
}
|
||||||
|
// 开服时间
|
||||||
|
else if (activity.getType() == ActivityType.OPEN_TYPE_SERVER) {
|
||||||
|
String openTime = GameApplication.serverConfig.getOpenTime();
|
||||||
|
long timeLong2 = TimeUtils.stringToTimeLong2(openTime);
|
||||||
|
endTime = timeLong2 + activity.getEndTimeLong() * 1000;
|
||||||
|
}
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证前置礼包购买状态
|
||||||
|
* @param user
|
||||||
|
* @param boxId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean checkBuyAgo(User user, int boxId){
|
||||||
|
boolean result = true;
|
||||||
|
// 获取消息
|
||||||
|
Map<Integer, ActivityProgressInfo> missionMap = user.getActivityManager().getActivityMissionMap().get(id).getActivityMissionMap();
|
||||||
|
SSurpriseBox box = STableManager.getConfig(SSurpriseBox.class).get(boxId);
|
||||||
|
// 非空
|
||||||
|
if (!missionMap.isEmpty() && box != null){
|
||||||
|
// 前置礼包状态验证
|
||||||
|
ActivityProgressInfo info = missionMap.get(box.getLimitPackFId());
|
||||||
|
// info为null代表没有前置条件, state==2代表已买过
|
||||||
|
if (info != null && info.getState() == ActivityType.WILL_TAKE){
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测特殊权限
|
||||||
|
* 0走默认 true
|
||||||
|
* @param user
|
||||||
|
* @param ruleId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean checkRule(User user, int ruleId){
|
||||||
|
boolean result = true;
|
||||||
|
switch (ruleId){
|
||||||
|
case 1:
|
||||||
|
// 普通月卡
|
||||||
|
result = user.getPlayerInfoManager().getMonthCard().get(Global.MONTHCARDID) != null;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// 高级月卡
|
||||||
|
result = user.getPlayerInfoManager().getMonthCard().get(Global.LMONTHCARDID) != null;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.ljsd.jieling.logic.activity.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author hj
|
||||||
|
* @Date 2021/5/26 11:05
|
||||||
|
* @Description:
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
public class SuperBoxEvent implements IEvent {
|
||||||
|
|
||||||
|
private int userId;
|
||||||
|
private int giftId = -1;//礼包id
|
||||||
|
|
||||||
|
public SuperBoxEvent(int userId, int giftId) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.giftId = giftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(int userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGiftId() {
|
||||||
|
return giftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGiftId(int giftId) {
|
||||||
|
this.giftId = giftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,10 +16,7 @@ import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||||
import com.ljsd.jieling.logic.activity.ActivityType;
|
import com.ljsd.jieling.logic.activity.ActivityType;
|
||||||
import com.ljsd.jieling.logic.activity.event.BuyGoodsDirectEvent;
|
import com.ljsd.jieling.logic.activity.event.*;
|
||||||
import com.ljsd.jieling.logic.activity.event.NewWelfareEvent;
|
|
||||||
import com.ljsd.jieling.logic.activity.event.NewWelfareTypeEnum;
|
|
||||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.RechargeInfo;
|
import com.ljsd.jieling.logic.dao.RechargeInfo;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
@ -221,6 +218,9 @@ public class BuyGoodsNewLogic {
|
||||||
//活动
|
//活动
|
||||||
user.getPlayerInfoManager().setRechargedaily(user.getPlayerInfoManager().getRechargedaily()+price);
|
user.getPlayerInfoManager().setRechargedaily(user.getPlayerInfoManager().getRechargedaily()+price);
|
||||||
changeActivity(user,price,info);
|
changeActivity(user,price,info);
|
||||||
|
|
||||||
|
// 惊喜礼盒,事件推送
|
||||||
|
Poster.getPoster().dispatchEvent(new SuperBoxEvent(user.getId(),config.getId()));
|
||||||
}
|
}
|
||||||
if(!info.getIsFirst()){
|
if(!info.getIsFirst()){
|
||||||
info.setIsFirst(true);
|
info.setIsFirst(true);
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
package config;
|
||||||
|
|
||||||
|
import manager.STableManager;
|
||||||
|
import manager.Table;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Table(name ="SurpriseBox")
|
||||||
|
public class SSurpriseBox implements BaseConfig {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private int activityId;
|
||||||
|
|
||||||
|
private int packId;
|
||||||
|
|
||||||
|
private int unlockDay;
|
||||||
|
|
||||||
|
private int visibleDay;
|
||||||
|
|
||||||
|
private int viewDay;
|
||||||
|
|
||||||
|
private int buyDay;
|
||||||
|
|
||||||
|
private int limitPackFId;
|
||||||
|
|
||||||
|
private int limitPackBId;
|
||||||
|
|
||||||
|
private int rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* key: 活动id value: 对象list
|
||||||
|
*/
|
||||||
|
public static Map<Integer, Map<Integer,SSurpriseBox>> map = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
Map<Integer, SSurpriseBox> config = STableManager.getConfig(SSurpriseBox.class);
|
||||||
|
config.values().forEach(v->{
|
||||||
|
Map<Integer, SSurpriseBox> boxMap = map.getOrDefault(v.getActivityId(), new HashMap<>());
|
||||||
|
boxMap.put(v.getId(),v);
|
||||||
|
map.put(v.getActivityId(),boxMap);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActivityId() {
|
||||||
|
return activityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPackId() {
|
||||||
|
return packId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVisibleDay() {
|
||||||
|
return visibleDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBuyDay() {
|
||||||
|
return buyDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimitPackFId() {
|
||||||
|
return limitPackFId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimitPackBId() {
|
||||||
|
return limitPackBId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRule() {
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUnlockDay() {
|
||||||
|
return unlockDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getViewDay() {
|
||||||
|
return viewDay;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue