十绝阵 奖励相关

back_recharge
lvxinran 2020-05-11 10:09:38 +08:00
parent 632af72234
commit dd799829db
6 changed files with 243 additions and 47 deletions

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.family.deathPath;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.family.DeathPathLogic;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.Family;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/5/11
* @discribe
*/
@Component
public class DeathPathDoRewardHandler extends BaseHandler<Family.DoRewardDeathPathRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.DEATH_PATH_DO_REWARD_REQUEST;
}
@Override
public void processWithProto(ISession iSession, Family.DoRewardDeathPathRequest proto) throws Exception {
DeathPathLogic.getInstance().getDeathPathReward(iSession,proto.getPosition(), MessageTypeProto.MessageType.DEATH_PATH_DO_REWARD_RESPONSE);
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.family.deathPath;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.family.DeathPathLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/5/11
* @discribe
*/
@Component
public class GetDeathPathAllRewardInfoHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.DEATH_PATH_GET_ALL_REWARD_INFO_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
DeathPathLogic.getInstance().getAllRewardInfo(iSession,MessageTypeProto.MessageType.DEATH_PATH_GET_ALL_REWARD_INFO_RESPONSE);
}
}

View File

@ -0,0 +1,22 @@
package com.ljsd.jieling.logic.family;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/5/9
* @discribe
*/
public class DeathChallengeCount {
private Map<Integer,DeathReward> userReward = new HashMap<>();
public Map<Integer, DeathReward> getUserReward() {
return userReward;
}
public void setUserReward(int uid,DeathReward reward) {
userReward.put(uid,reward);
}
}

View File

@ -4,8 +4,10 @@ import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
import com.ljsd.jieling.core.GlobalsDef;
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.logic.dao.GuildMyInfo;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.GuilidManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
@ -87,41 +89,48 @@ public class DeathPathLogic {
continue;
}
result = true;
break;
}
}else if(guildWarOpenTime[0]==1){
result = true;
}else{
return;
}
if(result&&isOpen()){
if(taskExecutor==null){
taskExecutor = new DeathPathExecutor(tasks);
taskExecutor.start();
}
status = 1;
}else {
status = 0;
if(result) {
Runnable runnable = this::isOpen;
runnable.run();
}
}
private boolean isOpen(){
private void isOpen(){
int hourOfDay = TimeUtils.getHourOfDay();
Calendar calendar = Calendar.getInstance();
int minute = calendar.get(Calendar.MINUTE);
if(hourOfDay<=guildWarTime[0][0]&&minute<guildWarTime[0][1]){
if(overTime!=0)
overTime=0;
return false;
int tempTime = hourOfDay*100+minute;
int currStatus = 0;
for(int i = 0;i<guildWarTime.length-1;i++){
int tempSmall = guildWarTime[i][0]*100+guildWarTime[i][1];
int tempBig = guildWarTime[i+1][0]*100+guildWarTime[i+1][1];
if(tempTime>=tempSmall&&tempTime<tempBig){
currStatus = i+1;
break;
}
}
if(hourOfDay>=guildWarTime[1][0]&&minute>guildWarTime[1][1]){
if(overTime!=0)
overTime=0;
return false;
if(currStatus!=status){
status = currStatus;
overTime = (int)(TimeUtils.getAppointTime(guildWarTime[status][0],guildWarTime[status][1])/1000);
if(status==1){
if (taskExecutor == null) {
taskExecutor = new DeathPathExecutor(tasks);
taskExecutor.start();
}
}
//阶段信息改变发送推送
for(Map.Entry<Integer, ISession> sessionEntry:OnlineUserManager.sessionMap.entrySet()) {
Family.DeathPathStatusChangeIndication indication = Family.DeathPathStatusChangeIndication.newBuilder().setStatus(status).build();
MessageUtil.sendIndicationMessage(sessionEntry.getValue(),1, MessageTypeProto.MessageType.DEATH_PATH_STATUS_CHANGE_INDICATION.getNumber(),indication,true);
}
}
if(overTime==0){
overTime = (int)(TimeUtils.getAppointTime(guildWarTime[1][0],guildWarTime[1][1])/1000);
}
return true;
}
/**
@ -169,6 +178,9 @@ public class DeathPathLogic {
* @param messageType
*/
public void challenge(ISession session, int pathId, MessageTypeProto.MessageType messageType) throws Exception {
if(status!=1){
throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
}
int uid = session.getUid();
User user = UserManager.getUser(uid);
int guildId = user.getPlayerInfoManager().getGuildId();
@ -217,9 +229,20 @@ public class DeathPathLogic {
}
}
}
public void taskDoExecute(DeathPathTask task){
private void taskDoExecute(DeathPathTask task){
//公会总进攻次数
DeathChallengeCount countInfo = RedisUtil.getInstence().get(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(task.getGuildId()), DeathChallengeCount.class);
if (countInfo==null){
countInfo = new DeathChallengeCount();
countInfo.setUserReward(task.getUid(),null);
RedisUtil.getInstence().set(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(task.getGuildId()),countInfo);
}else if(!countInfo.getUserReward().containsKey(task.getUid())) {
countInfo.setUserReward(task.getUid(),null);
RedisUtil.getInstence().set(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(task.getGuildId()), countInfo);
}
//操作每个关的公会数据
task.setDamage(2000000000);
task.setDamage(task.getDamage());
AbstractRank guildRank = RankContext.getRankEnum(RankEnum.DEATH_PATH_EVERY_GUILD_RANK.getType());
AbstractRank personRank = RankContext.getRankEnum(RankEnum.DEATH_PATH_EVERY_PERSON_RANK.getType());
@ -237,22 +260,11 @@ public class DeathPathLogic {
if(!iterator.hasNext()){
guildTotalRank.addRank(task.getGuildId(),"",task.getDamage(),1);
//操作每个关的个人数据
if(personRank.getScoreById(task.getUid(),String.valueOf(task.getPathId()))==-1){
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage(),1);
}else{
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage());
}
personRank.addRank(task.getUid(),String.valueOf(task.getPathId()),task.getDamage());
doRankAdd(personRank,guildRank,task);
}else{
ZSetOperations.TypedTuple<String> next = iterator.next();
firstGuildId = Integer.valueOf(next.getValue());
//判断改阵排行榜中是否有我打过的信息,没有加个人数
if(personRank.getScoreById(task.getUid(),String.valueOf(task.getPathId()))==-1){
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage(),1);
}else{
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage());
}
personRank.addRank(task.getUid(),String.valueOf(task.getPathId()),task.getDamage());
doRankAdd(personRank,guildRank,task);
Set<ZSetOperations.TypedTuple<String>> currScores = RedisUtil.getInstence().getZsetreverseRangeWithScores(guildRank.getRedisKey(), String.valueOf(task.getPathId()), 0, 0);
Iterator<ZSetOperations.TypedTuple<String>> currIterator = currScores.iterator();
ZSetOperations.TypedTuple<String> currNext = currIterator.next();
@ -266,5 +278,69 @@ public class DeathPathLogic {
}
}
//判断改阵排行榜中是否有我打过的信息,没有加个人数
private void doRankAdd(AbstractRank personRank,AbstractRank guildRank ,DeathPathTask task){
if(personRank.getScoreById(task.getUid(),String.valueOf(task.getPathId()))==-1){
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage(),1);
}else{
guildRank.addRank(task.getGuildId(),String.valueOf(task.getPathId()),task.getDamage());
}
personRank.addRank(task.getUid(),String.valueOf(task.getPathId()),task.getDamage());
}
}
/**
*
* @param session
* @param messageType
*/
public void getAllRewardInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
DeathChallengeCount countInfo = RedisUtil.getInstence().get(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(user.getPlayerInfoManager().getGuildId()), DeathChallengeCount.class);
Map<Integer, DeathReward> userReward = countInfo.getUserReward();
Family.GetAllDeathPathRewardInfoResponse.Builder response = Family.GetAllDeathPathRewardInfoResponse.newBuilder();
for(Map.Entry<Integer, DeathReward> entry:userReward.entrySet()){
DeathReward value = entry.getValue();
Family.RewardInfo info = Family.RewardInfo.newBuilder().setUid(entry.getKey()).setItemCount(value.getItemCount()).setItemId(value.getItemId()).setPosition(value.getPosition()).build();
response.addInfo(info);
}
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
/**
*
* @param session
* @param messageType
* @throws Exception
*/
public void getDeathPathReward(ISession session,int position, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
int[] reward = new int[]{4,10};
int guildId = user.getPlayerInfoManager().getGuildId();
DeathChallengeCount countInfo = RedisUtil.getInstence().get(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(guildId), DeathChallengeCount.class);
if (countInfo==null||!countInfo.getUserReward().containsKey(uid)){
//您所在的公会或您没有达到领奖条件
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
if(countInfo.getUserReward().get(uid)!=null){
//您已领取过奖励
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
countInfo = new DeathChallengeCount();
countInfo.setUserReward(uid,new DeathReward(reward[0],reward[1],position));
RedisUtil.getInstence().set(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(guildId),countInfo);
ItemUtil.drop(user,new int[][]{reward},BIReason.DEATH_PAHT_RANDOM_REWARD);
Family.RewardInfo info = Family.RewardInfo.newBuilder().setUid(uid).setItemCount(reward[1]).setItemId(reward[0]).setPosition(position).build();
GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(guildId), MessageTypeProto.MessageType.DEATH_PATH_DO_REWARD_INDICATION,info);
MessageUtil.sendMessage(session,1,messageType.getNumber(),null,true);
}
}

View File

@ -0,0 +1,43 @@
package com.ljsd.jieling.logic.family;
/**
* @author lvxinran
* @date 2020/5/9
* @discribe
*/
public class DeathReward {
private int itemId;
private int itemCount ;
private int position;
public int getItemId() {
return itemId;
}
public void setItemId(int itemId) {
this.itemId = itemId;
}
public int getItemCount() {
return itemCount;
}
public void setItemCount(int itemCount) {
this.itemCount = itemCount;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public DeathReward(int itemId, int itemCount, int position) {
this.itemId = itemId;
this.itemCount = itemCount;
this.position = position;
}
}

View File

@ -1,10 +1,11 @@
package com.ljsd.jieling.logic.rank.rankImpl;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
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.family.DeathChallengeCount;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import org.springframework.data.redis.core.ZSetOperations;
@ -37,14 +38,14 @@ public class DeathPathTotalGuildRank extends AbstractRank{
return decimal.doubleValue();
}
protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
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()));
protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(Integer.parseInt(data.getValue()));
DeathChallengeCount countInfo = RedisUtil.getInstence().get(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(guildInfo.getId()), DeathChallengeCount.class);
CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
.setRank(index)
.setParam1(getParam1(data.getScore()))
.setParam2(getParam2(data.getScore()))
.setParam3(countInfo==null?0:countInfo.getUserReward().size());
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
.setUid(guildInfo.getId())
.setGuildName(guildInfo.getName())
@ -55,12 +56,14 @@ public class DeathPathTotalGuildRank extends AbstractRank{
@Override
protected void getMyInfo(User user, String rkey, PlayerInfoProto.RankResponse.Builder allUserResponse) {
int guildId = user.getPlayerInfoManager().getGuildId();
DeathChallengeCount countInfo = RedisUtil.getInstence().get(RedisKey.DEATH_PAHT_TOTAL_CHALLENGE_COUNT, String.valueOf(guildId), DeathChallengeCount.class);
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();
.setParam2(getParam2(zSetScore))
.setParam3(countInfo==null?0:countInfo.getUserReward().size()).build();
allUserResponse.setMyRankInfo(towerRankInfo);
}