社稷大典功能提交

back_recharge
zhangshanxue 2020-10-25 17:00:45 +08:00
parent 210f4a1529
commit 1d9452992c
5 changed files with 550 additions and 0 deletions

View File

@ -0,0 +1,95 @@
package com.ljsd.jieling.logic;
import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.logic.activity.ActivityLogic;
import com.ljsd.jieling.logic.activity.ActivityType;
import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
import com.ljsd.jieling.logic.activity.IEventHandler;
import com.ljsd.jieling.logic.activity.event.IEvent;
import com.ljsd.jieling.logic.activity.event.MinuteTaskEvent;
import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
import config.SGlobalActivity;
import config.SGodSacrificeSetting;
import manager.STableManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.TimeUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* Description: des
* Author: zsx
* CreateDate: 2020/10/22 10:46
*/
public class GlobleSystemLogic implements IEventHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(GlobleSystemLogic.class);
private GlobleSystemLogic() {
Poster.getPoster().listenEvent(this, MinuteTaskEvent.class);
}
public static GlobleSystemLogic getInstence() {
return GlobleSystemLogic.InnerClass.instance;
}
public GlobalSystemControl getGlobalSystemControl() throws Exception {
GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
if (globalSystemControl == null) {
globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
}
return globalSystemControl;
}
private static class InnerClass {
private static final GlobleSystemLogic instance = new GlobleSystemLogic();
}
@Override
public void onEvent(IEvent event) throws Exception {
if (event instanceof MinuteTaskEvent) {
try {
SGodSacrificeSetting sGodSacrificeSetting = STableManager.getConfig(SGodSacrificeSetting.class).get(1);
if(null==sGodSacrificeSetting){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
List<Integer> list1 = Arrays.stream(sGodSacrificeSetting.getTimePointList()).boxed().collect(Collectors.toList());
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
if(list1.contains(hour)&& minute ==0){
//更新社稷大典
List<SGlobalActivity> activities = SGlobalActivity.sGlobalActivityMapByType.get(ActivityType.SHEJI_ACTIVITY);
int openID=0;
for(SGlobalActivity sGlobalActivity:activities){
if(ActivityLogic.getInstance().checkGlobleActivityOpen(sGlobalActivity.getId())){
openID=sGlobalActivity.getId();
break;
}
}
if(openID!=0){
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
globalSystemControl.getActivityOpenValue().putIfAbsent(openID,(int)(calendar.getTimeInMillis()/1000L));
GlobalSystemControl.save(globalSystemControl);
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Exception::=>{}", e.toString());
}
}
}
}

View File

@ -0,0 +1,329 @@
package com.ljsd.jieling.logic.activity;
import com.ljsd.jieling.core.Lockeys;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
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.CommitSheJiEvent;
import com.ljsd.jieling.logic.activity.event.IEvent;
import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.activity.event.SignInEvent;
import com.ljsd.jieling.logic.dao.GuilidManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.mail.MailLogic;
import com.ljsd.jieling.logic.rank.RankContext;
import com.ljsd.jieling.logic.rank.RankEnum;
import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.thread.ThreadManager;
import com.ljsd.jieling.util.ItemUtil;
import config.*;
import manager.STableManager;
import org.springframework.data.redis.core.ZSetOperations;
import util.TimeUtils;
import java.util.*;
/**
*
*/
class SheJiActivity extends AbstractActivity {
public SheJiActivity(int id) {
super(id);
Poster.getPoster().listenEvent(this, CommitSheJiEvent.class);
}
@Override
public void onActivityStart() throws Exception {
super.onActivityStart();
}
@Override
public void initActivity(User user) throws Exception {
super.initActivity(user);
//初始化移除道具
SGodSacrificeSetting sGodSacrificeSetting = STableManager.getConfig(SGodSacrificeSetting.class).get(1);
if (null != sGodSacrificeSetting) {
if (sGodSacrificeSetting.getItemDelete() == 1) {
int[] activityItems = sGodSacrificeSetting.getActivityItems();
for (int item : activityItems) {
user.getItemManager().removeItem(item);
}
}
}
}
@Override
void updateProgressWithUser(User user, ActivityMission activityMission, int count) {
Map<Integer, ActivityProgressInfo> activityProgressInfoMap = activityMission.getActivityMissionMap();
int progress;
for (Map.Entry<Integer, ActivityProgressInfo> item : activityProgressInfoMap.entrySet()) {
ActivityProgressInfo activityProgressInfo = item.getValue();
//考虑退公会的情况
if (activityProgressInfo.getProgrss() > count) {
break;
}
progress = count;
activityProgressInfo.setProgrss(progress);
activityMission.getActivityMissionMap().put(item.getKey(), activityProgressInfo);
// activityMission.updateProgressInfo(item.getKey(), activityProgressInfo);
}
}
@Override
public void onEvent(IEvent event) throws Exception {
if (!(event instanceof CommitSheJiEvent)) return;
int guildId = ((CommitSheJiEvent) event).getGuild();
if (guildId == 0) {
LOGGER.error("Exception guild id=>{} not exit", guildId);
}
//lock all 会修改公会记录
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
Set<Integer> sendUids = new HashSet<>();
for (Set<Integer> items : guildInfo.getMembers().values()) {
sendUids.addAll(items);
}
Lockeys.getLockeys().lock("guild", sendUids);
for (Integer uid : sendUids) {
User user = UserManager.getUser(uid);
if (null == user) {
LOGGER.error("Exception::user==null,uid=>{}", uid);
continue;
}
update(user, guildInfo.getGuildSheJiScore());
}
AbstractRank guildRank = RankContext.getRankEnum(RankEnum.GUILD_SHEJI_SCORE_RANK.getType());
guildRank.addRank(guildId,String.valueOf(id),guildInfo.getGuildSheJiScore());
if( ((CommitSheJiEvent) event).getScore()!=0){
RankContext.getRankEnum(RankEnum.EXPERT_RANK.getType()).incrementRankScore(((CommitSheJiEvent) event).getCommitUid(), String.valueOf(id), ((CommitSheJiEvent) event).getScore());
}
}
@Override
public void onActivityEnd() throws Exception {
ThreadManager.getScheduledExecutor().execute(this::sendReward);
}
protected void sendReward() {
Thread.currentThread().setName("sendReward-Activity-" + id);
SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id);
if (sGlobalActivity.getOpenRanking() == 0) {
return;
}
Map<Integer, List<SGodSacrificeConfig>> integerListMap = SGodSacrificeConfig.getIntegerListMap().get(1);
if (integerListMap == null) {
return;
}
SGodSacrificeSetting sGodSacrificeSetting = STableManager.getConfig(SGodSacrificeSetting.class).get(1);
InnerResult rewardMap = getRewardMap(2);
Map<Integer, Integer> rank2miss = rewardMap.getRank2miss();
int maxRank = rewardMap.getMaxRamk();
int maxRewardId = rewardMap.getMaxRewardId();
AbstractRank expertRank = RankContext.getRankEnum(RankEnum.EXPERT_RANK.getType());
Set<ZSetOperations.TypedTuple<String>> rankInfo = expertRank.getRankByKey(String.valueOf(id), 0, -1);
int rank = 1;
int nowTime = (int) (TimeUtils.now() / 1000);
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
String value = item.getValue();
int uid = Integer.parseInt(value);
try {
User user = UserManager.getUser(uid, true);
if (null == user) {
continue;
}
int missionId;
Double score = item.getScore();
if(score<sGodSacrificeSetting.getL1Score()){
LOGGER.error("id为{}的玩家,{}活动排行奖励积分不够 不预发奖", uid, id);
return;
}
if (rank2miss.containsKey(rank)) {
if (rank <= 10 && score <2500) {
missionId = 11;
} else {
missionId = rank2miss.get(rank);
}
} else {
if (maxRank == -1) {
missionId = maxRewardId;
} else {
continue;
}
}
//checkAndUpdate value
SGodSacrificeConfig sActivityRankingReward1 = SGodSacrificeConfig.getsGodSacrificeConfigMap().get(missionId);
//sendmail
String title = SErrorCodeEerverConfig.getI18NMessage("personal_activity_reward_title", new Object[]{sGlobalActivity.getSesc()});
String content = SErrorCodeEerverConfig.getI18NMessage("personal_activity_reward_txt", new Object[]{sGlobalActivity.getSesc(), rank++});
String mailReward = ItemUtil.getMailReward(sActivityRankingReward1.getRankingReward());
MailLogic.getInstance().sendMail(uid, title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
} catch (Exception e) {
LOGGER.error("id为{}的玩家,{}活动排行奖励没有发成功", uid, id);
System.out.println(e);
e.printStackTrace();
}
}
sendGuildReward();
}
protected void sendGuildReward() {
SGodSacrificeSetting sGodSacrificeSetting = STableManager.getConfig(SGodSacrificeSetting.class).get(1);
Thread.currentThread().setName("sendGuildReward-Activity-" + id);
SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id);
if (sGlobalActivity.getOpenRanking() == 0) {
return;
}
int nowTime = (int) (TimeUtils.now() / 1000);
InnerResult rewardMap = getRewardMap(2);
Map<Integer, Integer> rank2miss = rewardMap.getRank2miss();
int maxRank = rewardMap.getMaxRamk();
AbstractRank abstractRank = RankContext.getRankEnum(RankEnum.GUILD_SHEJI_SCORE_RANK.getType());
Set<ZSetOperations.TypedTuple<String>> rankByKey = abstractRank.getRankByKey("", 0, -1);
int rankIndex = 1;
for (ZSetOperations.TypedTuple<String> item : rankByKey) {
try {
String guildId = item.getValue();
int guild = Integer.parseInt(guildId);
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guild);
Set<Integer> sendUids = new HashSet<>();
for (Set<Integer> items : guildInfo.getMembers().values()) {
sendUids.addAll(items);
}
for (Integer uid : sendUids) {
try {
User user = UserManager.getUser(uid, true);
if (null == user) {
continue;
}
if (user.getPlayerInfoManager().getCreateTime() + sGodSacrificeSetting.getLifeLimit() * TimeUtils.ONE_DAY - nowTime > 0) {
continue;
}
if (user.getGuildMyInfo().getJoinTime() + sGodSacrificeSetting.getJoinLimit() * TimeUtils.ONE_DAY - nowTime > 0) {
continue;
}
int missionId;
if (rank2miss.containsKey(rankIndex)) {
missionId = rank2miss.get(rankIndex);
} else {
if (maxRank == -1) {
missionId = rewardMap.getMaxRewardId();
} else {
continue;
}
}
//checkAndUpdate value
SGodSacrificeConfig sActivityRankingReward1 = SGodSacrificeConfig.getsGodSacrificeConfigMap().get(missionId);
//sendmail
String title = SErrorCodeEerverConfig.getI18NMessage("guild_activity_reward_title", new Object[]{sGlobalActivity.getSesc()});
String content = SErrorCodeEerverConfig.getI18NMessage("guild_activity_reward_txt", new Object[]{sGlobalActivity.getSesc(), rankIndex++});
String mailReward = ItemUtil.getMailReward(sActivityRankingReward1.getRankingReward());
MailLogic.getInstance().sendMail(uid, title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
} catch (Exception e) {
LOGGER.error("id为{}的玩家,{}活动排行奖励没有发成功", uid, id);
System.out.println(e);
e.printStackTrace();
}
}
} catch (Exception e) {
LOGGER.error("排行奖励没有发成功=>{}", id);
e.printStackTrace();
}
}
}
private InnerResult getRewardMap(int type) {
InnerResult innerResult = new InnerResult();
Map<Integer, Integer> rank2miss = innerResult.getRank2miss();
Map<Integer, List<SGodSacrificeConfig>> integerListMap = SGodSacrificeConfig.getIntegerListMap().get(type);
if (integerListMap == null) {
return innerResult;
}
List<SGodSacrificeConfig> sGodSacrificeConfigs = integerListMap.get(id);
if (null == sGodSacrificeConfigs)
return innerResult;
int maxRank = 0;
int maxRewardId = 0;
for (SGodSacrificeConfig sActivityRankingReward1 : sGodSacrificeConfigs) {
if (sActivityRankingReward1.getMaxRank() == -1) {
maxRank = -1;
maxRewardId = sActivityRankingReward1.getId();
continue;
}
if (maxRank != -1) {
maxRank = Math.max(maxRank, sActivityRankingReward1.getMaxRank());
}
for (Integer rank : getRankSet(sActivityRankingReward1.getMinRank(), sActivityRankingReward1.getMaxRank())) {
rank2miss.put(rank, sActivityRankingReward1.getId());
}
}
innerResult.setMaxRamk(maxRank);
innerResult.setMaxRewardId(maxRewardId);
return innerResult;
}
class InnerResult {
Map<Integer, Integer> rank2miss = new HashMap<>();
int maxRamk;
int maxRewardId;
Map<Integer, Integer> getRank2miss() {
return rank2miss;
}
public void setRank2miss(Map<Integer, Integer> rank2miss) {
this.rank2miss = rank2miss;
}
int getMaxRamk() {
return maxRamk;
}
void setMaxRamk(int maxRamk) {
this.maxRamk = maxRamk;
}
int getMaxRewardId() {
return maxRewardId;
}
void setMaxRewardId(int maxRewardId) {
this.maxRewardId = maxRewardId;
}
}
}

View File

@ -0,0 +1,41 @@
package com.ljsd.jieling.logic.activity.event;
/**
*
*/
public class CommitSheJiEvent implements IEvent{
private int guild;
private int commitUid;
private int score;
public CommitSheJiEvent(int guild, int commitUid, int score) {
this.guild = guild;
this.commitUid = commitUid;
this.score = score;
}
public int getGuild() {
return guild;
}
public void setGuild(int guild) {
this.guild = guild;
}
public int getCommitUid() {
return commitUid;
}
public void setCommitUid(int commitUid) {
this.commitUid = commitUid;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}

View File

@ -0,0 +1,20 @@
package com.ljsd.jieling.logic.activity.event;
/**
*
*/
public class GetSheJiAwardEvent implements IEvent{
private int uid;
public GetSheJiAwardEvent(int uid) {
this.uid = uid;
}
public int getGuild() {
return uid;
}
public void setGuild(int uid) {
this.uid = uid;
}
}

View File

@ -0,0 +1,65 @@
package com.ljsd.jieling.logic.rank.rankImpl;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.logic.dao.GuilidManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import org.springframework.data.redis.core.ZSetOperations;
import java.util.Set;
/**
* @author lvxinran
* @date 2020/8/22
* @discribe
*/
public class GuildSheJiScoreRank extends AbstractRank {
public GuildSheJiScoreRank(int type, String redisKey) {
super(type, redisKey);
}
@Override
public long[] getDataByScore(Double score) {
return new long[]{score.longValue()};
}
@Override
public double getScore(double... data) {
return data[0];
}
protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) {
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(Integer.parseInt(data.getValue()));
CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
.setRank(index)
.setParam1(getParam1(data.getScore()))
.setParam2(getParam2(data.getScore()))
.setParam3(getParam3(data.getScore()));
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
.setUid(guildInfo.getId())
.setUserName(guildInfo.getName())
.setRankInfo(everyRankInfo);
builder.addRanks(everyRank);
}
@Override
protected void getMyInfo(User user, String rkey, PlayerInfoProto.RankResponse.Builder allUserResponse){
int guildId = user.getPlayerInfoManager().getGuildId();
if(guildId==0){
return;
}
int myRank= RedisUtil.getInstence().getZSetreverseRank(redisKey,rkey,Integer.toString(guildId)).intValue();
Double zSetScore = RedisUtil.getInstence().getZSetScore(redisKey, rkey, Integer.toString(guildId));
CommonProto.RankInfo towerRankInfo = CommonProto.RankInfo.newBuilder()
.setRank(myRank)
.setParam1(getParam1(zSetScore))
.setParam2(getParam2(zSetScore)).build();
allUserResponse.setMyRankInfo(towerRankInfo);
}
}