活动提交
parent
5c1946e7f7
commit
5d1ff52c3d
|
|
@ -1176,6 +1176,9 @@ public class TimeUtils {
|
|||
return !isSameDay(lastTime - (long) (hour) * 3600 * 1000, now() - (long) (hour) * 3600 * 1000);
|
||||
}
|
||||
|
||||
public static boolean isOverTimeNow(int hour, long lastTime) {
|
||||
return !isSameDay(lastTime - (long) (hour) * 3600, now() - (long) (hour) * 3600);
|
||||
}
|
||||
|
||||
// 距离下周几(周日为 1 周一为 2 ...) 零点时间
|
||||
public static long getFirstDayOfWeek(int firstDayOfWeek) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import com.ljsd.jieling.handler.map.MapLogic;
|
|||
import com.ljsd.jieling.handler.map.MapManager;
|
||||
import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.UserOnlineEvent;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
|
|
@ -67,6 +69,8 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
ActivityLogic.getInstance().flushForLogin(user,iSession);
|
||||
GlobalDataManaager.checkNeedReFlush(iSession,user,null);
|
||||
|
||||
Poster.getPoster().dispatchEvent(new UserOnlineEvent(userId));
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.LOGIN_GAME,0);
|
||||
playerInfoManager.setLoginTime(TimeUtils.now());
|
||||
Map<Integer, Integer> guidePoints = playerInfoManager.getGuidePoints();
|
||||
|
|
|
|||
|
|
@ -217,10 +217,7 @@ public class ActivityLogic implements IEventHandler{
|
|||
}
|
||||
ActivityMission activityMission = new ActivityMission();
|
||||
|
||||
boolean b = initMissionInfo(activityMission,activityId);
|
||||
if (!b) {
|
||||
return false;
|
||||
}
|
||||
initMissionInfo(activityMission,activityId);
|
||||
// activityMission.init(getRootId(), getMongoKey() + ".activityMissionMap." + activityId);
|
||||
//自动初始化
|
||||
map.put(activityId, activityMission);
|
||||
|
|
@ -228,9 +225,9 @@ public class ActivityLogic implements IEventHandler{
|
|||
}
|
||||
|
||||
|
||||
public boolean initMissionInfo(ActivityMission activityMission,int activityId){
|
||||
public void initMissionInfo(ActivityMission activityMission,int activityId){
|
||||
List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(activityId);
|
||||
if(sActivityRewardConfigs == null){return false;}
|
||||
if(sActivityRewardConfigs == null){return;}
|
||||
for(SActivityRewardConfig sActivityRewardConfig : sActivityRewardConfigs){
|
||||
ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
|
||||
activityProgressInfo.setProgrss(ActivityLogic.getInstance().getInitActivityMissionProgress(activityId));
|
||||
|
|
@ -244,7 +241,6 @@ public class ActivityLogic implements IEventHandler{
|
|||
}
|
||||
activityMission.setActivityState(ActivityType.OPEN_STATE);
|
||||
activityMission.setV(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void initOtherMission(ActivityMission activityMission,List<Integer> missionIds){
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ public interface ActivityType {
|
|||
|
||||
int LEVEL_EXPERT = 52; //进阶达人
|
||||
|
||||
int BUY_GOLD = 53; //购买金币 点石成金
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ public enum ActivityTypeEnum {
|
|||
LUCKWHEEL_EXPERT(ActivityType.LUCKWHEEL_EXPERT,LuckWheelExpectRankActivity::new),
|
||||
HERORANDOM_EXPERT(ActivityType.HERORANDOM_EXPERT,HeroRandomExpectRankActivity::new),
|
||||
SECURTBOX_EXPERT(ActivityType.SECURTBOX_EXPERT,SecurtBoxExpectRankActivity::new),
|
||||
FIND_FAIRY_FESTIVAL(ActivityType.FIND_FAIRY_FESTIVAL,RechargeSumActivity::new)
|
||||
|
||||
FIND_FAIRY_FESTIVAL(ActivityType.FIND_FAIRY_FESTIVAL,RechargeSumActivity::new),
|
||||
BUY_GOLD(ActivityType.BUY_GOLD,BuyGoldActivity::new)
|
||||
;
|
||||
private int type;
|
||||
private Function<Integer, AbstractActivity> toActivityFunction;
|
||||
|
|
@ -56,6 +56,8 @@ public enum ActivityTypeEnum {
|
|||
for (ActivityTypeEnum item:ActivityTypeEnum.values()) {
|
||||
activityEnumMap.put(item.getType(),item);
|
||||
}
|
||||
//提前注册
|
||||
SGlobalActivity.getsGlobalActivityMap().forEach((integer, sGlobalActivity) -> getActicityType(integer));
|
||||
}
|
||||
|
||||
ActivityTypeEnum(int type, Function<Integer, AbstractActivity> toActivityFunction) {
|
||||
|
|
@ -72,6 +74,7 @@ public enum ActivityTypeEnum {
|
|||
return abstractActivity;
|
||||
}
|
||||
|
||||
//相同类型不同活动id需要处理处理多次事件
|
||||
public static AbstractActivity getActicityType(int id) {
|
||||
SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id);
|
||||
// for (ActivityTypeEnum activityType:ActivityTypeEnum.values()) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.activity.event.HourTaskEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.UserOnlineEvent;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import config.SGlobalActivity;
|
||||
import config.SPrivilegeTypeConfig;
|
||||
import config.SSpecialConfig;
|
||||
import manager.STableManager;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
class BuyGoldActivity extends AbstractActivity {
|
||||
|
||||
public BuyGoldActivity(int id) {
|
||||
super(id);
|
||||
Poster.getPoster().listenEvent(this, UserOnlineEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initActivity(User user) throws Exception {
|
||||
super.initActivity(user);
|
||||
SGlobalActivity sGlobalActivity = STableManager.getConfig(SGlobalActivity.class).get(id);
|
||||
int time = (int) (sGlobalActivity.getEndTimeLong() / 1000);
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
List<Integer> listValue = SSpecialConfig.getListValue(SSpecialConfig.Gold_touch);
|
||||
listValue.forEach(type -> SPrivilegeTypeConfig.privilegeByType.get(type).forEach(sPrivilegeTypeConfig -> {
|
||||
int innerId = sPrivilegeTypeConfig.getId();
|
||||
ids.add(innerId);
|
||||
if (!user.getPlayerInfoManager().containPrivilageId(innerId))
|
||||
user.getPlayerInfoManager().addVipByTime(innerId, time);
|
||||
}));
|
||||
notifyClient(user, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
super.onEvent(event);
|
||||
|
||||
List<Integer> list = SSpecialConfig.getListValue(SSpecialConfig.Gold_touch_refresh);
|
||||
if (event instanceof HourTaskEvent) {
|
||||
if (list.contains(((HourTaskEvent) event).getHour())) {
|
||||
InnerMessageUtil.broadcastWithRandom(user -> {
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
setUpTime(user);
|
||||
}, new ArrayList<>(OnlineUserManager.sessionMap.keySet()), 120);
|
||||
|
||||
}
|
||||
}
|
||||
if (event instanceof UserOnlineEvent) {
|
||||
User user = UserManager.getUser(((UserOnlineEvent) event).getUid());
|
||||
ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||
if (null == activityMission) {
|
||||
return;
|
||||
}
|
||||
boolean needRefresh = false;
|
||||
for (Integer aList : list) {
|
||||
if (TimeUtils.isOverAppointRefreshTime(System.currentTimeMillis(), activityMission.getV() * 1000L, aList)) {
|
||||
needRefresh = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needRefresh) {
|
||||
setUpTime(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpTime(User user) {
|
||||
|
||||
ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||
if (null == activityMission) {
|
||||
return;
|
||||
}
|
||||
//sendclient
|
||||
activityMission.setV((int) (System.currentTimeMillis()/1000));
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
List<Integer> listValue = SSpecialConfig.getListValue(SSpecialConfig.Gold_touch);
|
||||
listValue.forEach(type -> SPrivilegeTypeConfig.privilegeByType.get(type).forEach(sPrivilegeTypeConfig -> {
|
||||
ids.add(sPrivilegeTypeConfig.getId());
|
||||
user.getPlayerInfoManager().refreshVipByType(sPrivilegeTypeConfig.getId());
|
||||
}));
|
||||
notifyClient(user, ids);
|
||||
}
|
||||
|
||||
|
||||
private void notifyClient(User user, Set<Integer> ids) {
|
||||
PlayerInfoProto.PrivilegeIndication.Builder indication = PlayerInfoProto.PrivilegeIndication.newBuilder();
|
||||
Set<CommonProto.Privilege> privilege = PlayerLogic.getInstance().getPrivilege(user, ids);
|
||||
indication.addAllInfos(privilege);
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(user.getId());
|
||||
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.PRIVILLEGE_ADD_INDICATION_VALUE, indication.build(), true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.ljsd.jieling.logic.activity.event;
|
||||
|
||||
public class HourTaskEvent implements IEvent {
|
||||
|
||||
int hour;
|
||||
|
||||
public HourTaskEvent(int hour) {
|
||||
this.hour = hour;
|
||||
}
|
||||
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 简单的活动消息处理 目的 解耦逻辑
|
||||
|
|
@ -27,7 +28,14 @@ public class Poster {
|
|||
private Poster() {
|
||||
}
|
||||
|
||||
private Map<Class<? extends IEvent>, Set<IEventHandler>> listenMap = new HashMap<>();
|
||||
/**
|
||||
* hashmap风险 多线程操作 数据有丢失风险
|
||||
* to fix zsx 20.04.28 并发方案有两个
|
||||
* 1 直接用ConcurrntHashMap
|
||||
* 2 清晰的模块化处理 监听过程由且只能由主线程监听 之后再由模块去事件分发 但是后续分发只能遍历逻辑
|
||||
*
|
||||
*/
|
||||
private Map<Class<? extends IEvent>, Set<IEventHandler>> listenMap = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<IEventHandler> getListeners(IEvent e) {
|
||||
return listenMap.get(e.getClass());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.ljsd.jieling.logic.activity.event;
|
||||
|
||||
public class UserOnlineEvent implements IEvent {
|
||||
|
||||
int uid;
|
||||
|
||||
public UserOnlineEvent(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
}
|
||||
|
|
@ -383,6 +383,11 @@ public class PlayerManager extends MongoBase {
|
|||
this.vipInfo.put(privilageId,vipInfo);
|
||||
}
|
||||
|
||||
public boolean containPrivilageId(int privilageId) {
|
||||
return this.vipInfo.containsKey(privilageId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 刷新整个类型的次数
|
||||
* @param privilegeType
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.ljsd.jieling.ktbeans.sendbeans.KTAppOnline;
|
|||
import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.activity.event.HourTaskEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.MinuteTaskEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
|
|
@ -65,6 +66,7 @@ public class MinuteTask extends Thread {
|
|||
everyZeroTask();
|
||||
everyFiveTask();
|
||||
everyMondyFiveClockTask();
|
||||
everyHourTask();
|
||||
fiveMinuteOnlineSend();
|
||||
CheckFight.getInstance().luaHotFix();
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
|
|
@ -100,6 +102,18 @@ public class MinuteTask extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
//每日凌晨执行
|
||||
public void everyHourTask() throws Exception {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
if(minute ==0){
|
||||
LOGGER.info("everyHourTask start ...");
|
||||
Poster.getPoster().dispatchEvent(new HourTaskEvent(hour));
|
||||
LOGGER.info("everyHourTask end ...");
|
||||
}
|
||||
}
|
||||
|
||||
//每日凌晨执行
|
||||
public void everyZeroTask() throws Exception {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
|
|
|||
|
|
@ -13,56 +13,23 @@ import java.util.concurrent.TimeUnit;
|
|||
public class InnerMessageUtil {
|
||||
|
||||
public static void sendTo(User user, AyyncWorker ayyncWorker) {
|
||||
ProtocolsManager instance = ProtocolsManager.getInstance();
|
||||
HandlerLogicThread handlerThread = instance.handlerThreads[user.getId() % instance.HANDLER_THREAD_NUM];
|
||||
HandlerLogicThread handlerThread = ProtocolsManager.handlerThreads[user.getId() % ProtocolsManager.HANDLER_THREAD_NUM];
|
||||
handlerThread.addAyyncWorker(ayyncWorker);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知所有在线玩家 随机时间 /s
|
||||
* @param sendId 通知的玩家
|
||||
* @param timeBound 时间区间内随机执行点 针对cpu密集型的业务缓解服务器压力
|
||||
* tofix zsx 2020.04.28
|
||||
*/
|
||||
public static void broadcastWithRandom(AyncWorkerRunnable ayncWorkerRunnable, List<Integer> sendId, int timeBound) throws InterruptedException {
|
||||
|
||||
//
|
||||
// ThreadManager.getScheduledExecutor().schedule(() -> {
|
||||
// try {
|
||||
// int lastUid=0;
|
||||
// for (Integer id : sendId) {
|
||||
// User userInMem = UserManager.getUserInMem(id);
|
||||
// if(userInMem == null){
|
||||
// continue;
|
||||
// }
|
||||
// ProtocolsManager instance = ProtocolsManager.getInstance();
|
||||
// if(lastUid!=0){
|
||||
// HandlerLogicThread handlerThread = instance.handlerThreads[lastUid % instance.HANDLER_THREAD_NUM];
|
||||
// int retryTimes = 30;
|
||||
// while ( !handlerThread.ayyncWorkerConcurrentLinkedQueue.isEmpty()){
|
||||
// Thread.sleep(50);
|
||||
// retryTimes--;
|
||||
// if(retryTimes<0){
|
||||
// System.out.println("fail fail ---------------------->>>>>fail..");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// Thread.sleep(50);
|
||||
// }
|
||||
// HandlerLogicThread handlerThread = instance.handlerThreads[id % instance.HANDLER_THREAD_NUM];
|
||||
// ayyncWorker.setTask(true);
|
||||
// ayyncWorker.setUser(userInMem);
|
||||
// handlerThread.addAyyncWorker(ayyncWorker);
|
||||
// lastUid =id;
|
||||
// }
|
||||
// }catch (Exception e){}
|
||||
// }, 1, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
public static void broadcastWithRandom(AyncWorkerRunnable ayncWorkerRunnable, List<Integer> sendId, int timeBound) {
|
||||
|
||||
for (Integer id : sendId) {
|
||||
ThreadManager.getScheduledExecutor().schedule(new InnerTask(id){
|
||||
@Override
|
||||
public void run() {
|
||||
ProtocolsManager instance = ProtocolsManager.getInstance();
|
||||
HandlerLogicThread handlerThread = instance.handlerThreads[getUid() % instance.HANDLER_THREAD_NUM];
|
||||
HandlerLogicThread handlerThread = ProtocolsManager.handlerThreads[getUid() % ProtocolsManager.HANDLER_THREAD_NUM];
|
||||
User userInMem = UserManager.getUserInMem(getUid());
|
||||
if(userInMem == null){
|
||||
return;
|
||||
|
|
@ -81,7 +48,7 @@ public class InnerMessageUtil {
|
|||
static abstract class InnerTask implements Runnable{
|
||||
int uid;
|
||||
|
||||
public InnerTask(int uid) {
|
||||
InnerTask(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1121,7 +1121,7 @@ public class ItemUtil {
|
|||
heroManager.addHero(hero);
|
||||
heroList.add(CBean2Proto.getHero(hero));
|
||||
SCHero scHero = SCHero.getsCHero().get(hero.getTemplateId());
|
||||
if (scHero.getNatural() >= SSpecialConfig.getIntegerValue(SSpecialConfig.lamp_lottery_content_parm)) {
|
||||
if (scHero.getStar() >= SSpecialConfig.getIntegerValue(SSpecialConfig.lamp_lottery_content_parm)) { //策划资质改成星级
|
||||
String message = SErrorCodeEerverConfig.getI18NMessage("lamp_lottery_content", new Object[]{playerInfoManager.getNickName(), scHero.getNatural(), scHero.getReadingName()});
|
||||
if (!message.isEmpty()){
|
||||
ChatLogic.getInstance().sendSysChatMessage(message,Global.LUCKY_LUCK,hero.getTemplateId(),0,0,0,0,0);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import manager.STableManager;
|
|||
import manager.Table;
|
||||
import util.StringUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
|
@ -56,6 +58,8 @@ public class SSpecialConfig implements BaseConfig {
|
|||
public static final String HERO_SACRIFICE_PERCENT = "hero_sacrifice_percent";//献祭返还材料比例 实际百分比为填写数值/10000
|
||||
public static final String HERO_RESOLVE_LICENCE = "hero_resolve_licence";//分解英雄时,处于编队中会有提示
|
||||
public static final String Sign_Location = "Sign_Location";//魂印位置开启条件(玩家等级)
|
||||
public static final String Gold_touch = "Gold_touch";//三个点金对应vip
|
||||
public static final String Gold_touch_refresh = "Gold_touch_refresh";//点金刷新时间
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
|
|
@ -91,6 +95,15 @@ public class SSpecialConfig implements BaseConfig {
|
|||
}
|
||||
return arrayNum;
|
||||
}
|
||||
public static List<Integer> getListValue(String key) {
|
||||
List<Integer> list = new LinkedList<>();
|
||||
String value = enumers.get(key);
|
||||
String[] array = value.split("\\#");
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
list.add(Integer.parseInt(array[i]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static int[][] getTwiceArrayValue(String key) {
|
||||
String value = enumers.get(key);
|
||||
|
|
|
|||
Loading…
Reference in New Issue