|
|
|
@ -34,6 +34,29 @@ public class GuildFightLogic {
|
|
|
|
|
private static int status;
|
|
|
|
|
private static boolean startMatching;
|
|
|
|
|
|
|
|
|
|
static{
|
|
|
|
|
int hour = TimeUtils.getHourOfDay();
|
|
|
|
|
switch (hour){
|
|
|
|
|
case FamilyRound.FAMILY_FIGHT_START:
|
|
|
|
|
status = 1;
|
|
|
|
|
break;
|
|
|
|
|
case FamilyRound.FAMILY_FIGHT_DEFEND_END:
|
|
|
|
|
status = 2;
|
|
|
|
|
break;
|
|
|
|
|
case FamilyRound.FAMILY_FIGHT_MATCHING_END:
|
|
|
|
|
status =3;
|
|
|
|
|
break;
|
|
|
|
|
case FamilyRound.FAMILY_FIGHT_ATTACK_END:
|
|
|
|
|
status = 4;
|
|
|
|
|
break;
|
|
|
|
|
case FamilyRound.FAMILY_FIGHT_END:
|
|
|
|
|
status = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
status = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 查看工会布防信息
|
|
|
|
|
*
|
|
|
|
@ -67,6 +90,7 @@ public class GuildFightLogic {
|
|
|
|
|
* @param messageType
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public static void viewDefendDetailInfo(ISession session, int uid, MessageTypeProto.MessageType messageType) throws Exception {
|
|
|
|
|
User user = UserManager.getUser(uid);
|
|
|
|
|
int guildId = user.getPlayerInfoManager().getGuildId();
|
|
|
|
@ -74,14 +98,21 @@ public class GuildFightLogic {
|
|
|
|
|
TeamPosManager teamPosManager = user.getTeamPosManager();
|
|
|
|
|
CommonProto.Team.Builder team = CommonProto.Team.newBuilder();
|
|
|
|
|
CommonProto.TeamOneTeamInfo.Builder oneInfo = CommonProto.TeamOneTeamInfo.newBuilder();
|
|
|
|
|
for(Map.Entry<String, FamilyHeroInfo> entry:fightInfo.getHeroAttribute().entrySet()){
|
|
|
|
|
int templateId = entry.getValue().getTempleteId();
|
|
|
|
|
team.addHeroTid(templateId);
|
|
|
|
|
Map<Integer, Integer> attribute = entry.getValue().getAttribute();
|
|
|
|
|
if(status==3){
|
|
|
|
|
int remainHp = attribute.get(HeroAttributeEnum.CurHP.getPropertyId())*100/attribute.get(HeroAttributeEnum.Hp.getPropertyId());
|
|
|
|
|
LOGGER.info("血量为百分之{}",remainHp);
|
|
|
|
|
oneInfo.addRemainHp(remainHp);
|
|
|
|
|
if(fightInfo!=null){
|
|
|
|
|
for(Map.Entry<String, FamilyHeroInfo> entry:fightInfo.getHeroAttribute().entrySet()){
|
|
|
|
|
int templateId = entry.getValue().getTempleteId();
|
|
|
|
|
team.addHeroTid(templateId);
|
|
|
|
|
Map<Integer, Integer> attribute = entry.getValue().getAttribute();
|
|
|
|
|
if(status==3){
|
|
|
|
|
int remainHp = attribute.get(HeroAttributeEnum.CurHP.getPropertyId())*100/attribute.get(HeroAttributeEnum.Hp.getPropertyId());
|
|
|
|
|
LOGGER.info("血量为百分之{}",remainHp);
|
|
|
|
|
oneInfo.addRemainHp(remainHp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
List<TeamPosHeroInfo> teamPosHeroInfos = teamPosManager.getTeamPosForHero().get(501);
|
|
|
|
|
for(TeamPosHeroInfo heroInfo:teamPosHeroInfos){
|
|
|
|
|
team.addHeroTid(user.getHeroManager().getHero(heroInfo.getHeroId()).getTemplateId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oneInfo.setTeam(team);
|
|
|
|
@ -128,6 +159,7 @@ public class GuildFightLogic {
|
|
|
|
|
private static Family.FamilyFightInfo familyFightDetailInfo(int guildId) throws Exception {
|
|
|
|
|
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
|
|
|
|
|
Map<Integer, Integer> defendInfo = guildInfo.getDefendInfo();
|
|
|
|
|
Map<Integer, FamilyFightInfo> fightValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_FIGHT, String.valueOf(guildId), Integer.class, FamilyFightInfo.class);
|
|
|
|
|
Family.FamilyFightInfo.Builder fightInfo = Family.FamilyFightInfo.newBuilder();
|
|
|
|
|
fightInfo.setGid(guildId);
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
@ -139,13 +171,13 @@ public class GuildFightLogic {
|
|
|
|
|
for (Map.Entry<Integer, Integer> entry : defendInfo.entrySet()) {
|
|
|
|
|
Family.FamilyFightPlayerInfo.Builder playerInfo = Family.FamilyFightPlayerInfo.newBuilder();
|
|
|
|
|
playerInfo.setBuildId(entry.getValue());
|
|
|
|
|
playerInfo.setStarCount(5);
|
|
|
|
|
playerInfo.setStarCount(fightValues.get(entry.getKey()).getStarCount());
|
|
|
|
|
PlayerManager playerManager = UserManager.getUser(entry.getKey()).getPlayerInfoManager();
|
|
|
|
|
Family.FamilyUserInfo.Builder userInfo = Family.FamilyUserInfo.newBuilder()
|
|
|
|
|
.setRoleUid(entry.getKey())
|
|
|
|
|
.setUserName(playerManager.getNickName())
|
|
|
|
|
.setUserLevel(playerManager.getLevel())
|
|
|
|
|
.setPosition(2)
|
|
|
|
|
.setPosition(GuildLogic.getMemberType(entry.getKey(),GuilidManager.guildInfoMap.get(guildId).getMembers()))
|
|
|
|
|
.setSoulForce(HeroLogic.getInstance().calTeamTotalForce(UserManager.getUser(entry.getKey()), 501, false))
|
|
|
|
|
.setHead(playerManager.getHead())
|
|
|
|
|
.setFrame(playerManager.getHeadFrame())
|
|
|
|
@ -224,6 +256,7 @@ public class GuildFightLogic {
|
|
|
|
|
heroAllAttribute.put(heroInfo.getHeroId(), new FamilyHeroInfo(hero.getTemplateId(), hero.getLevel(), heroAttributeMap));
|
|
|
|
|
}
|
|
|
|
|
fightInfo.setHeroAttribute(heroAllAttribute);
|
|
|
|
|
fightInfo.setBuildId(entry.getValue());
|
|
|
|
|
fightInfo.setStarCount(guildSetting.getStarNum()[memberType-1]);
|
|
|
|
|
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(guildInfo.getId()), String.valueOf(entry.getKey()), fightInfo);
|
|
|
|
|
}
|
|
|
|
@ -277,8 +310,11 @@ public class GuildFightLogic {
|
|
|
|
|
*/
|
|
|
|
|
public static void familyFightResult(ISession session, int defendUid, MessageTypeProto.MessageType messageType) throws Exception {
|
|
|
|
|
User userAttack = UserManager.getUser(session.getUid());
|
|
|
|
|
//战斗次数
|
|
|
|
|
userAttack.getGuildMyInfo().updateAttackCount(userAttack.getGuildMyInfo().getAttackCount()+1);
|
|
|
|
|
User userDefend = UserManager.getUser(defendUid);
|
|
|
|
|
int defendGuildId = userDefend.getPlayerInfoManager().getGuildId();
|
|
|
|
|
int defendBuildId = GuilidManager.guildInfoMap.get(defendGuildId).getDefendInfo().get(defendUid);
|
|
|
|
|
RedisUtil redisUtil = RedisUtil.getInstence();
|
|
|
|
|
FamilyFightInfo defendInfo = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(defendGuildId), String.valueOf(userDefend.getId()), FamilyFightInfo.class);
|
|
|
|
|
Map<String, FamilyHeroInfo> heroAttribute = defendInfo.getHeroAttribute();
|
|
|
|
@ -315,31 +351,54 @@ public class GuildFightLogic {
|
|
|
|
|
System.out.println(fightResult[i]);
|
|
|
|
|
}
|
|
|
|
|
int index = 2;
|
|
|
|
|
int dieCount = 0;
|
|
|
|
|
// 战斗之后数据处理
|
|
|
|
|
for (Map.Entry<String, FamilyHeroInfo> entry : heroAttribute.entrySet()) {
|
|
|
|
|
FamilyHeroInfo value = entry.getValue();
|
|
|
|
|
Map<Integer, Integer> attribute = value.getAttribute();
|
|
|
|
|
if(fightResult[0]==0) {
|
|
|
|
|
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), fightResult[index]);
|
|
|
|
|
}else{
|
|
|
|
|
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), 0);
|
|
|
|
|
for (Map.Entry<String, FamilyHeroInfo> entry : heroAttribute.entrySet()) {
|
|
|
|
|
FamilyHeroInfo value = entry.getValue();
|
|
|
|
|
Map<Integer, Integer> attribute = value.getAttribute();
|
|
|
|
|
if(fightResult[0]==0) {
|
|
|
|
|
if(fightResult[index]==0){
|
|
|
|
|
dieCount++;
|
|
|
|
|
}
|
|
|
|
|
value.setAttribute(attribute);
|
|
|
|
|
index++;
|
|
|
|
|
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), fightResult[index]);
|
|
|
|
|
}else{
|
|
|
|
|
dieCount = 5;
|
|
|
|
|
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value.setAttribute(attribute);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
defendInfo.setHeroAttribute(heroAttribute);
|
|
|
|
|
if (fightResult[0] == 0) {
|
|
|
|
|
defendInfo.setStarCount(defendInfo.getStarCount() - 1);
|
|
|
|
|
//获得星数
|
|
|
|
|
int getStar;
|
|
|
|
|
if (fightResult[0] == 1) {
|
|
|
|
|
//发送indication
|
|
|
|
|
Family.DefeatResponse response = Family.DefeatResponse.newBuilder().setUid(defendUid).build();
|
|
|
|
|
GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(userDefend.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_DEFEATE_INDICATION,response);
|
|
|
|
|
GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(userAttack.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_DEFEATE_INDICATION,response);
|
|
|
|
|
getStar = defendInfo.getStarCount();
|
|
|
|
|
defendInfo.setStarCount(0);
|
|
|
|
|
}else{
|
|
|
|
|
int memberType = GuildLogic.getMemberType(defendUid, GuilidManager.guildInfoMap.get(defendGuildId).getMembers());
|
|
|
|
|
int maxStar = SGuildSetting.sGuildSetting.getStarNum()[memberType];
|
|
|
|
|
int lessStar = maxStar - dieCount*maxStar/5;
|
|
|
|
|
//倍数k(maxStar/5)
|
|
|
|
|
getStar = defendInfo.getStarCount()-lessStar;
|
|
|
|
|
defendInfo.setStarCount(lessStar);
|
|
|
|
|
}
|
|
|
|
|
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(defendGuildId), String.valueOf(userDefend.getId()), defendInfo);
|
|
|
|
|
//获得星数处理
|
|
|
|
|
int attackGuildId = userAttack.getPlayerInfoManager().getGuildId();
|
|
|
|
|
String attackRankKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), false);
|
|
|
|
|
Double starCount = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), String.valueOf(userAttack.getId()));
|
|
|
|
|
redisUtil.zsetAddOne(attackRankKey,String.valueOf(userAttack.getId()),starCount+1);
|
|
|
|
|
Family.FamilyFightAttackResponse response = Family.FamilyFightAttackResponse.newBuilder().setResult(fightResult[0]).setStarCount(1).build();
|
|
|
|
|
redisUtil.zsetAddOne(attackRankKey,String.valueOf(userAttack.getId()),starCount+getStar);
|
|
|
|
|
//建筑星数
|
|
|
|
|
Integer haveGotStar = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(attackGuildId), String.valueOf(defendBuildId), int.class);
|
|
|
|
|
if(haveGotStar==null){
|
|
|
|
|
haveGotStar = 0;
|
|
|
|
|
}
|
|
|
|
|
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_CAL_STAR,String.valueOf(attackGuildId),String.valueOf(defendBuildId),haveGotStar+getStar);
|
|
|
|
|
Family.FamilyFightAttackResponse response = Family.FamilyFightAttackResponse.newBuilder().setResult(fightResult[0]).setStarCount(getStar).build();
|
|
|
|
|
MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -381,6 +440,7 @@ public class GuildFightLogic {
|
|
|
|
|
.setStartTime(startFightTime)
|
|
|
|
|
.setRoundStartTime(roundStartTime)
|
|
|
|
|
.setRoundEndTime(roundEndTime)
|
|
|
|
|
.setAttackCount(UserManager.getUser(session.getUid()).getGuildMyInfo().getAttackCount())
|
|
|
|
|
.setJoinType(1);
|
|
|
|
|
if (enemyFamily != -1) {
|
|
|
|
|
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(enemyFamily);
|
|
|
|
@ -432,13 +492,37 @@ public class GuildFightLogic {
|
|
|
|
|
*/
|
|
|
|
|
private static void removeMatchingInfo(){
|
|
|
|
|
RedisUtil redisUtil = RedisUtil.getInstence();
|
|
|
|
|
String key = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false);
|
|
|
|
|
redisUtil.removeZSetRangeByRank(key,0,redisUtil.getZsetSize(key));
|
|
|
|
|
String matchingKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false);
|
|
|
|
|
Map<Integer, Integer> matchingValues = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_MATCHING_RANK, "", Integer.class, Integer.class);
|
|
|
|
|
for(Map.Entry<Integer, Integer> entry:matchingValues.entrySet()){
|
|
|
|
|
Map<Integer, FamilyFightInfo> fightDefend = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT, entry.getKey().toString(), Integer.class, FamilyFightInfo.class);
|
|
|
|
|
for (Map.Entry<Integer, FamilyFightInfo> defendEntry:fightDefend.entrySet()){
|
|
|
|
|
//删除布防信息
|
|
|
|
|
redisUtil.removeMapEntrys(RedisKey.FAMILY_FIGHT,entry.getKey().toString(),defendEntry.getKey());
|
|
|
|
|
//删除公会结算
|
|
|
|
|
String starRankKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(entry.getKey()), false);
|
|
|
|
|
redisUtil.removeZSetRangeByRank(starRankKey,0,redisUtil.getZsetSize(starRankKey));
|
|
|
|
|
}
|
|
|
|
|
for(int i = 1;i<=3;i++){
|
|
|
|
|
//删除获得星数信息
|
|
|
|
|
if(redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_CAL_STAR,String.valueOf(entry.getKey()),String.valueOf(i),Integer.class)!=null){
|
|
|
|
|
redisUtil.removeMapEntrys(RedisKey.FAMILY_FIGHT_CAL_STAR,String.valueOf(entry.getKey()),i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//删除匹配信息
|
|
|
|
|
redisUtil.removeZSetRangeByRank(matchingKey,0,redisUtil.getZsetSize(matchingKey));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 公会战结算
|
|
|
|
|
*/
|
|
|
|
|
public void accountFamilyFightResult() {
|
|
|
|
|
RedisUtil redisUtil = RedisUtil.getInstence();
|
|
|
|
|
String key = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false);
|
|
|
|
|
|
|
|
|
|
int size = redisUtil.getZsetSize(key);
|
|
|
|
|
Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores = redisUtil.getZsetreverseRangeWithScores(RedisKey.FAMILY_FIGHT_MATCHING_RANK, "", 0, size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -448,8 +532,11 @@ public class GuildFightLogic {
|
|
|
|
|
* @param messageType
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static void personalFightResult(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
|
|
|
|
|
public static void personalFightResult(ISession session,int type, MessageTypeProto.MessageType messageType) throws Exception {
|
|
|
|
|
int guildId = UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId();
|
|
|
|
|
if(type==1){
|
|
|
|
|
guildId = getEnemyFamily(guildId);
|
|
|
|
|
}
|
|
|
|
|
Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(guildId), 0, 20);
|
|
|
|
|
Iterator<ZSetOperations.TypedTuple<String>> it = zsetreverseRangeWithScores.iterator();
|
|
|
|
|
int rank = 1;
|
|
|
|
@ -464,7 +551,7 @@ public class GuildFightLogic {
|
|
|
|
|
.setUid(uid)
|
|
|
|
|
.setHead(1)
|
|
|
|
|
.setHeadFrame(playerInfoManager.getHeadFrame())
|
|
|
|
|
.setPosition(1)
|
|
|
|
|
.setPosition(GuildLogic.getMemberType(Integer.parseInt(personal.getValue()),GuilidManager.guildInfoMap.get(playerInfoManager.getGuildId()).getMembers()))
|
|
|
|
|
.setName(playerInfoManager.getNickName())
|
|
|
|
|
.setStarCount(personal.getScore().intValue());
|
|
|
|
|
response.addResult(fightResult.build());
|
|
|
|
@ -472,4 +559,25 @@ public class GuildFightLogic {
|
|
|
|
|
}
|
|
|
|
|
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 工会总战绩
|
|
|
|
|
*/
|
|
|
|
|
public static void guildFightResult(ISession session,MessageTypeProto.MessageType messageType) throws Exception {
|
|
|
|
|
int guildId=UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId();
|
|
|
|
|
int enemyFamily = getEnemyFamily(guildId);
|
|
|
|
|
Family.GuildFightResultResponse.Builder response = Family.GuildFightResultResponse.newBuilder();
|
|
|
|
|
response.setGetExp(10);
|
|
|
|
|
//获取星星
|
|
|
|
|
Map<Integer, Integer> mapValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(guildId), Integer.class, Integer.class);
|
|
|
|
|
//失去星星
|
|
|
|
|
Map<Integer, Integer> mapEnemyValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(enemyFamily), Integer.class, Integer.class);
|
|
|
|
|
response.addGetStar(mapValues.get(1)==null?0:mapValues.get(1));
|
|
|
|
|
response.addGetStar(mapValues.get(2)==null?0:mapValues.get(2));
|
|
|
|
|
response.addGetStar(mapValues.get(3)==null?0:mapValues.get(3));
|
|
|
|
|
response.addLoseStar(mapEnemyValues.get(1)==null?0:mapValues.get(1));
|
|
|
|
|
response.addLoseStar(mapEnemyValues.get(2)==null?0:mapValues.get(2));
|
|
|
|
|
response.addLoseStar(mapEnemyValues.get(3)==null?0:mapValues.get(3));
|
|
|
|
|
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|