公会战提交

lvxinran 2019-08-31 06:24:15 +08:00
parent e38fb0f41d
commit 9c6f7c277b
10 changed files with 397 additions and 49 deletions

View File

@ -23,7 +23,7 @@ public class SGuildLevelConfig implements BaseConfig {
public static Map<Integer,SGuildLevelConfig> sGuildLevelConfigMap;
@Override
public void init() throws Exception {
sGuildLevelConfigMap = STableManager.getConfig(SGuildLevelConfig.class);
}

View File

@ -18,10 +18,11 @@ public class SGuildScoreConfig implements BaseConfig {
private int[][] starExp;
@Override
public static Map<Integer,SGuildScoreConfig> sGuildScoreConfigMap;
@Override
public void init() throws Exception {
sGuildScoreConfigMap = STableManager.getConfig(SGuildScoreConfig.class);
}

View File

@ -129,4 +129,24 @@ public class SGuildSetting implements BaseConfig {
public int[][] getBuildingBuff() {
return buildingBuff;
}
public float getDefendScore() {
return defendScore;
}
public float getForceScore() {
return forceScore;
}
public float getLoseScore() {
return loseScore;
}
public float getWinScore() {
return winScore;
}
public float getExpansionScore() {
return expansionScore;
}
}

View File

@ -116,17 +116,21 @@ public class RedisKey {
public static final String FAMILY_ID = "FAMILY_ID";
public static final String FAMILY_FIGHT = "FAMILY_FIGHT" ;
public static final String FAMILY_ATTACK_RECORD = "FAMILY_ATTACK_RECORD";
public static final String FAMILY_ATTACK_BLOOD = "FAMILY_ATTACK_BLOOD";
public static final String FAMILY_FIGHT_RANK = "FAMILY_FIGHT_RANK";
public static final String FAMILY_FIGHT_MATCHING_RANK ="FAMILY_FIGHT_MATCHING_RANK";
//公会战进攻获得星数排行榜
public static final String FAMILY_FIGHT_STAR_RANK = "FAMILY_FIGHT_STAR_RANK";
//公会战击破建筑星数
public static final String FAMILY_FIGHT_EXTRA_STAR = "FAMILY_FIGHT_EXTRA_STAR";
//公会战公会统计
public static final String FAMILY_FIGHT_CAL_STAR = "FAMILY_FIGHT_CAL_STAR";
//公会战buff缓存
public static final String FAMILY_FIGHT_BUFF = "FAMILY_FIGHT_BUFF";
//公会战进攻次数缓存
public static final String FAMILY_FIGHT_ATTACK_COUNT = "FAMILY_FIGHT_ATTACK_COUNT";
//公会总星数
public static final String FAMILY_FIGHT_TOTAL_STAR = "FAMILY_FIGHT_TOTAL_STAR";
//给用户发送邮件
public static final String READY_TO_USER_MAIL = "READY_TO_USER_MAIL";
//把用户踢下线

View File

@ -19,6 +19,7 @@ public class FamilyChangeJoinHandler extends BaseHandler {
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] bytes = netData.parseClientProtoNetData();
Family.FamilyChangeJoinTypeRequest familyChangeJoinTypeRequest = Family.FamilyChangeJoinTypeRequest.parseFrom(bytes);
GuildLogic.changeJoinType(iSession,familyChangeJoinTypeRequest.getType());
GuildLogic.changeJoinType(iSession,familyChangeJoinTypeRequest.getType(),familyChangeJoinTypeRequest.getIntoLevel());
}
}

View File

@ -0,0 +1,21 @@
package com.ljsd.jieling.handler.family;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.family.GuildFightLogic;
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;
@Component
public class FamilyFightAttackBloodHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.FAMILY_ATTACK_BLOOD_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
GuildFightLogic.getAttackHeroBlood(iSession, MessageTypeProto.MessageType.FAMILY_ATTACK_BLOOD_RESPONSE);
}
}

View File

@ -39,8 +39,12 @@ public class GuildInfo extends MongoBase {
private Map<Integer,Integer> fightResult = new HashMap<>();
private int continueCount;//连胜连败场数:负数为连败场次、正数为连胜场次
private int icon;
private int intoLevel;
public GuildInfo() {
setRootCollection(_COLLECTION_NAME);
}
@ -128,6 +132,10 @@ public class GuildInfo extends MongoBase {
public int getLevel() {
return level;
}
public void updateLevel(int level){
updateString("level",level);
this.level = level;
}
public int getExp() {
return exp;
@ -147,9 +155,12 @@ public class GuildInfo extends MongoBase {
}
public void removeDefendInfo(int uid){
defendInfo.remove(uid);
removeString(getMongoKey()+".defendInfo."+uid);
removeString("defendInfo."+uid);
}
public void removeAllDefendInfo(){
defendInfo = new HashMap<>();
updateString("defendInfo",new HashMap<>());
}
public int getIcon() {
return icon;
}
@ -164,5 +175,25 @@ public class GuildInfo extends MongoBase {
fightResult.put(type,value);
updateString("fightResult."+type,value);
}
public void updateExp(int exp){
updateString("exp",exp);
this.exp = exp;
}
public void updateContinueCount(int count){
updateString("continueCount",count);
this.continueCount = count;
}
public int getContinueCount() {
return continueCount;
}
public int getIntoLevel() {
return intoLevel;
}
public void updateIntoLevel(int intoLevel){
this.intoLevel = intoLevel;
updateString("intoLevel",intoLevel);
}
}

View File

@ -1,8 +1,11 @@
package com.ljsd.jieling.logic.family;
import com.google.gson.Gson;
import com.ljsd.jieling.config.SArenaSetting;
import com.ljsd.jieling.config.SGuildLevelConfig;
import com.ljsd.jieling.config.SGuildScoreConfig;
import com.ljsd.jieling.config.SGuildSetting;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.family.FamilyRound;
@ -28,7 +31,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.ZSetOperations;
import java.net.UnknownHostException;
import java.util.*;
import java.util.stream.Collectors;
public class GuildFightLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(GuildFightLogic.class);
@ -38,6 +43,7 @@ public class GuildFightLogic {
private static int status;
private static boolean startMatching;
static{
int hour = TimeUtils.getHourOfDay();
switch (hour){
@ -61,6 +67,13 @@ public class GuildFightLogic {
break;
}
}
public static int getStatus() {
return status;
}
public static void setStatus(int status) {
GuildFightLogic.status = status;
}
/**
*
*
@ -74,9 +87,11 @@ public class GuildFightLogic {
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(gid);
Map<Integer, Integer> defendInfo = guildInfo.getDefendInfo();
Family.FamilyDefendViewResponse.Builder response = Family.FamilyDefendViewResponse.newBuilder();
SGuildSetting guildSetting = SGuildSetting.sGuildSetting;
for (Map.Entry<Integer, Integer> entry : defendInfo.entrySet()) {
int memberType = GuildLogic.getMemberType(entry.getKey(), guildInfo.getMembers());
Family.FamilyDefendInfo.Builder defend = Family.FamilyDefendInfo.newBuilder();
defend.setStarCount(5);
defend.setStarCount(guildSetting.getStarNum()[memberType-1]);
defend.setUid(entry.getKey());
defend.setBuildId(entry.getValue());
defend.setCurForce(HeroLogic.getInstance().calTeamTotalForce(UserManager.getUser(entry.getKey()), 501, false));
@ -227,26 +242,33 @@ public class GuildFightLogic {
}
RedisUtil redisUtil = RedisUtil.getInstence();
String key = RedisKey.getKey(RedisKey.FAMILY_FIGHT_RANK, "", false);
Set<String> rank = redisUtil.getZset(key, 0, redisUtil.getZsetSize(key));
SGuildSetting guildSetting = SGuildSetting.sGuildSetting;
for (Integer gid : guildIds) {
Map<Integer, SGuildLevelConfig> configMap = SGuildLevelConfig.sGuildLevelConfigMap;
//匹配处理
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(gid);
int guildTotalExp = guildInfo.getExp();
for(int i = 1 ; i <guildInfo.getLevel();i++){
guildTotalExp = configMap.get(i).getExp();
int totalForce = 0;
for(Map.Entry<Integer, Set<Integer>> entry:guildInfo.getMembers().entrySet()){
for(Integer uid:entry.getValue()){
int maxForce = UserManager.getUser(uid).getPlayerInfoManager().getMaxForce();
totalForce+=maxForce;
}
}
if (guildInfo.getDefendInfo() != null && guildInfo.getDefendInfo().size() > 0) {
int loseWinScore = guildInfo.getContinueCount();
if(guildInfo.getContinueCount()<0){
loseWinScore *= guildSetting.getLoseScore();
}else{
loseWinScore *= guildSetting.getWinScore();
}
float guildTotalScore =totalForce*guildSetting.getForceScore()+guildInfo.getDefendInfo().size()*guildSetting.getDefendScore()+loseWinScore;
String matchingKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK, "", false);
int random = MathUtils.randomInt(30);
if (!rank.contains(gid.toString())) {
redisUtil.zsetAddOne(key, gid.toString(), guildTotalExp);
redisUtil.zsetAddOne(matchingKey, gid.toString(), guildTotalExp + random);
} else {
Double zSetScore = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_RANK, "", gid.toString());
redisUtil.zsetAddOne(matchingKey, gid.toString(), zSetScore + random);
}
redisUtil.zsetAddOne(key, gid.toString(), guildTotalScore);
Double zSetScore = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_RANK, "", gid.toString());
redisUtil.zsetAddOne(matchingKey, gid.toString(), zSetScore + random);
}
Map<Integer, Integer> defendInfo = guildInfo.getDefendInfo();
if (defendInfo == null || defendInfo.size() < 1) {
@ -263,6 +285,7 @@ public class GuildFightLogic {
int[] resultBuff= MathUtils.randomFromWeightWithTaking(randomBuff,buff[0]);
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_BUFF,gid.toString(),String.valueOf(i+1),resultBuff);
}
int familyTotalStar = 0;
//血量记录处理,星级记录处理
for (Map.Entry<Integer, Integer> entry : defendInfo.entrySet()) {
User user = UserManager.getUser(entry.getKey());
@ -290,7 +313,13 @@ public class GuildFightLogic {
fightInfo.setBuildId(entry.getValue());
fightInfo.setStarCount(guildSetting.getStarNum()[memberType-1]);
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(guildInfo.getId()), String.valueOf(entry.getKey()), fightInfo);
familyTotalStar+=fightInfo.getStarCount();
}
for(Integer star:guildSetting.getStarNum()){
familyTotalStar+=star;
}
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_TOTAL_STAR,"",String.valueOf(gid),familyTotalStar);
}
for (Integer gid : guildIds) {
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(gid);
@ -314,6 +343,9 @@ public class GuildFightLogic {
private static int getEnemyFamily(int myFamilyId) {
RedisUtil redisUtil = RedisUtil.getInstence();
Long matchingRank = redisUtil.getZSetreverseRank(RedisKey.FAMILY_FIGHT_MATCHING_RANK, "", String.valueOf(myFamilyId));
if(matchingRank==-1){
return -1;
}
int enmeyFamilyId;
long rank;
if (matchingRank % 2 == 1) {
@ -350,7 +382,6 @@ public class GuildFightLogic {
int defendBuildId = GuilidManager.guildInfoMap.get(defendGuildId).getDefendInfo().get(defendUid);
FamilyFightInfo defendInfo = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(defendGuildId), String.valueOf(userDefend.getId()), FamilyFightInfo.class);
Map<String, FamilyHeroInfo> heroAttribute = defendInfo.getHeroAttribute();
int seed = (int) (System.currentTimeMillis() / 1000);
List<CommonProto.FightUnitInfo> heroDefendFightInfos = new ArrayList<>();
for (Map.Entry<String, FamilyHeroInfo> entry : heroAttribute.entrySet()) {
Hero hero = userDefend.getHeroManager().getHero(entry.getKey());
@ -374,10 +405,51 @@ public class GuildFightLogic {
.addAllFightUnitList(heroDefendFightInfos)
.setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(userDefend, 1))
.build();
CommonProto.FightTeamInfo fightAttackTeamInfo = BehaviorUtil.getFightTeamInfo(userAttack, 502, true);
//攻击者血量处理
CommonProto.FightTeamInfo fightAttackTeamInfo = null;
List<CommonProto.FightUnitInfo> heroAttackFightInfos = new ArrayList<>();
Map<String, String> attackBloodMap = redisUtil.getMapValues(RedisKey.FAMILY_ATTACK_BLOOD, String.valueOf(userAttack.getId()), String.class, String.class);
List<TeamPosHeroInfo> teamAttack = userAttack.getTeamPosManager().getTeamPosForHero().get(502);
if(attackBloodMap!=null&&attackBloodMap.size()>0){
for(TeamPosHeroInfo teamHero: teamAttack){
for(Map.Entry<String,String> blood:attackBloodMap.entrySet()){
if(teamHero.getHeroId().equals(blood.getKey())){
Hero hero = userAttack.getHeroManager().getHero(teamHero.getHeroId());
if (hero == null) {
continue;
}
StringBuilder skillSb = new StringBuilder();
StringBuilder propertySb = new StringBuilder();
String heroSkill = HeroLogic.getInstance().getHeroSkills(userDefend, hero, skillSb).toString();
Map<Integer, Integer> heroAttributeMap = HeroLogic.getInstance().calHeroNotBufferAttribute(userAttack, hero, false, 502);
heroAttributeMap.put(HeroAttributeEnum.CurHP.getPropertyId(),heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())-Integer.parseInt(blood.getValue())*heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())/100);
String property = HeroLogic.getInstance().getHeroPropertyBuilder(propertySb, hero, heroAttributeMap).toString();
CommonProto.FightUnitInfo heroFightInfo = CommonProto.FightUnitInfo
.newBuilder()
.setUnitId(Integer.toString(hero.getTemplateId()))
.setUnitSkillIds(heroSkill.substring(0, heroSkill.length() - 1))
.setProperty(property.substring(0, property.length() - 1))
.build();
heroAttackFightInfos.add(heroFightInfo);
}
}
}
CommonProto.FightTeamInfo.Builder fightAttackTeamInfoBuilder = CommonProto.FightTeamInfo.newBuilder().addAllFightUnitList(heroAttackFightInfos)
.setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(userAttack, 1));
fightAttackTeamInfo = fightAttackTeamInfoBuilder.build();
}else{
fightAttackTeamInfo = BehaviorUtil.getFightTeamInfo(userAttack,502,true);
}
LuaValue getFightData = FightDataUtil.getFinalPlayerFightData(fightAttackTeamInfo, fightDefendTeamInfo);
LuaValue getOptionData = FightDataUtil.getOptionData("");
int seed = (int) (System.currentTimeMillis() / 1000);
CommonProto.FightData fightData = CommonProto.FightData.newBuilder()
.setFightMaxTime(SArenaSetting.getSArenaSetting().getMostTime())
.setFightSeed(seed)
.setHeroFightInfos(fightAttackTeamInfo)
.addMonsterList(fightDefendTeamInfo)
.build();
int[] fightResult = CheckFight.getInstance().checkFight(seed, 1000, getFightData, getOptionData);
for (int i = 0; i < fightResult.length; i++) {
System.out.println(fightResult[i]);
@ -404,21 +476,33 @@ public class GuildFightLogic {
//获得星数
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);
int indexAttack =2;
for(TeamPosHeroInfo attack:teamAttack){
Hero hero = userAttack.getHeroManager().getHeroMap().get(attack.getHeroId());
Map<Integer, Integer> integerIntegerMap = HeroLogic.getInstance().calHeroNotBufferAttribute(userAttack, hero, false, 502);
int bloodLess = ((integerIntegerMap.get(HeroAttributeEnum.Hp.getPropertyId())-fightResult[indexAttack])) *100/ integerIntegerMap.get(HeroAttributeEnum.Hp.getPropertyId());
redisUtil.putMapEntry(RedisKey.FAMILY_ATTACK_BLOOD,String.valueOf(userAttack.getId()),attack.getHeroId(),bloodLess);
indexAttack++;
}
}else{
int memberType = GuildLogic.getMemberType(defendUid, GuilidManager.guildInfoMap.get(defendGuildId).getMembers());
int maxStar = SGuildSetting.sGuildSetting.getStarNum()[memberType];
int maxStar = SGuildSetting.sGuildSetting.getStarNum()[memberType-1];
int lessStar = maxStar - dieCount*maxStar/5;
//倍数k(maxStar/5)
getStar = defendInfo.getStarCount()-lessStar;
defendInfo.setStarCount(lessStar);
for(TeamPosHeroInfo attack:teamAttack){
redisUtil.putMapEntry(RedisKey.FAMILY_ATTACK_BLOOD,String.valueOf(userAttack.getId()),attack.getHeroId(),100);
}
}
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(defendGuildId), String.valueOf(userDefend.getId()), defendInfo);
//发送indication
Family.DefeatResponse fightResponse = Family.DefeatResponse.newBuilder().setUid(defendUid).setTeamLostStar(getStar).build();
GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(userDefend.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_DEFEATE_INDICATION,fightResponse);
GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(userAttack.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_DEFEATE_INDICATION,fightResponse);
//获得星数处理
int attackGuildId = userAttack.getPlayerInfoManager().getGuildId();
String attackRankKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), false);
@ -433,7 +517,7 @@ public class GuildFightLogic {
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();
Family.FamilyFightAttackResponse response = Family.FamilyFightAttackResponse.newBuilder().setResult(fightResult[0]).setStarCount(getStar).setData(fightData).build();
MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
}
@ -518,14 +602,14 @@ public class GuildFightLogic {
LOGGER.info("阶段变为进攻");
} else if (status == 3 && hour == FamilyRound.FAMILY_FIGHT_ATTACK_END) {
accountFamilyFightResult();
MongoUtil.getLjsdMongoTemplate().lastUpdate();
status = 4;
LOGGER.info("阶段变为结算");
} else if (status == 4 && hour == FamilyRound.FAMILY_FIGHT_END) {
status = 0;
LOGGER.info("阶段变为等待");
} else if (hour > FamilyRound.FAMILY_FIGHT_END || hour < FamilyRound.FAMILY_FIGHT_START) {
} else if (hour >= FamilyRound.FAMILY_FIGHT_END || hour < FamilyRound.FAMILY_FIGHT_START) {
status = 0;
removeMatchingInfo();
startMatching = true;
@ -542,7 +626,8 @@ public class GuildFightLogic {
String matchingKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false);
//攻击次数信息
String attackCountKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_ATTACK_COUNT, "", false);
//额外星数信息
String extraStar = RedisKey.getKey(RedisKey.FAMILY_FIGHT_EXTRA_STAR,"",false);
Set<String> matchingRank = redisUtil.getZset(matchingKey, 0, redisUtil.getZsetSize(matchingKey));
for(String index:matchingRank){
Map<Integer, FamilyFightInfo> fightDefend = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT, index, Integer.class, FamilyFightInfo.class);
@ -563,8 +648,24 @@ public class GuildFightLogic {
//删除buff信息
redisUtil.removeMapEntrys(RedisKey.FAMILY_FIGHT_BUFF,index,String.valueOf(i));
}
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(Integer.parseInt(index));
//删除进攻血量信息
for(Map.Entry<Integer,Set<Integer>> entry:guildInfo.getMembers().entrySet()){
for(Integer attackId:entry.getValue()){
String key = RedisKey.getKey(RedisKey.FAMILY_ATTACK_BLOOD, String.valueOf(attackId), false);
if(redisUtil.hasKey(key)){
redisUtil.del(key);
}
}
}
//清除额外星数信息
// redisUtil.removeMapEntrys(RedisKey.FAMILY_FIGHT_EXTRA_STAR,"");
//清除布防信息
// GuilidManager.guildInfoMap.get(index).removeAllDefendInfo();
}
redisUtil.del(matchingKey,attackCountKey);
redisUtil.del(matchingKey,attackCountKey,extraStar);
// 删除匹配信息
// redisUtil.removeZSetRangeByRank(matchingKey,0,redisUtil.getZsetSize(matchingKey));
@ -572,13 +673,99 @@ public class GuildFightLogic {
/**
* (Redismongo)
*/
public void accountFamilyFightResult() {
public static void accountFamilyFightResult() throws Exception {
RedisUtil redisUtil = RedisUtil.getInstence();
String key = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false);
int size = redisUtil.getZsetSize(key);
}
Set<String> matchingRank = redisUtil.getZset(key, 0, redisUtil.getZsetSize(key));
int[] buildingStar = SGuildSetting.sGuildSetting.getBuildingStar();
for(String str:matchingRank){
int[] buildStar = new int[3];
int enemyFamily = getEnemyFamily(Integer.parseInt(str));
if(enemyFamily==-1){
continue;
}
LOGGER.info("{}公会结算",str);
Map<Integer, Integer> enemyDefendInfo = GuilidManager.guildInfoMap.get(enemyFamily).getDefendInfo();
for(Map.Entry<Integer, Integer> defend:enemyDefendInfo.entrySet()){
FamilyFightInfo mapEntry = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(enemyFamily), String.valueOf(defend.getKey()), FamilyFightInfo.class);
if(mapEntry!=null){
buildStar[defend.getValue()-1] = buildStar[defend.getValue()-1]+mapEntry.getStarCount();
}
}
for(int i = 0 ; i < buildStar.length;i++){
if(buildStar[i]==0){
buildStar[i] = buildingStar[i];
LOGGER.info("结算额外星数{}",buildStar[i]);
continue;
}else{
buildStar[i] = 0;
LOGGER.info("结算额外星数{}",buildStar[i]);
continue;
}
}
redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_EXTRA_STAR,"",str,buildStar);
}
Map<Integer, SGuildLevelConfig> levelConfigMap = SGuildLevelConfig.sGuildLevelConfigMap;
Map<Integer, SGuildScoreConfig> sGuildScoreConfigMap = SGuildScoreConfig.sGuildScoreConfigMap;
Map<String, Integer> totalStarMap = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_TOTAL_STAR, "", String.class, Integer.class);
for(String str:matchingRank) {
int enemyFamily = getEnemyFamily(Integer.parseInt(str));
if(enemyFamily==-1){
continue;
}
int getStar = getTotalStar(Integer.parseInt(str));
int loseStar = getTotalStar(enemyFamily);
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(Integer.parseInt(str));
LOGGER.info("公会{}获得星数:{},失去星数{}",str,getStar,loseStar);
//战绩结算
int getExp = 0;
Double rank = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_RANK, "", str);
for(Map.Entry<Integer, SGuildScoreConfig> entry:sGuildScoreConfigMap.entrySet()){
if(rank<entry.getValue().getScoreMin()||rank>entry.getValue().getScoreMax()){
continue;
}
int[] resultExp = entry.getValue().getResultExp();
//胜负判断
if(getStar>loseStar){
getExp+=resultExp[0];
guildInfo.updateResult(1,guildInfo.getResult(1)+1);
if(guildInfo.getContinueCount()<0){
guildInfo.updateContinueCount(1);
}else{
guildInfo.updateContinueCount(guildInfo.getContinueCount()+1);
}
}else if(getStar ==loseStar){
getExp+=resultExp[1];
guildInfo.updateResult(2,guildInfo.getResult(2)+1);
guildInfo.updateContinueCount(0);
}else{
getExp+=resultExp[2];
guildInfo.updateResult(3,guildInfo.getResult(3)+1);
if(guildInfo.getContinueCount()<0){
guildInfo.updateContinueCount(guildInfo.getContinueCount()-1);
}else{
guildInfo.updateContinueCount(-1);
}
}
//星数判断
for(int i = 0 ;i<entry.getValue().getStarExp().length;i++){
if(getStar*100/totalStarMap.get(String.valueOf(enemyFamily))>entry.getValue().getStarExp()[i][0]){
getExp+=entry.getValue().getStarExp()[i][0];
}else{
break;
}
}
break;
}
if(guildInfo.getExp()+getExp>=levelConfigMap.get(guildInfo.getLevel()).getExp()){
guildInfo.updateExp(guildInfo.getExp()+getExp-levelConfigMap.get(guildInfo.getLevel()).getExp());
guildInfo.updateLevel(guildInfo.getLevel()+getExp);
}else{
guildInfo.updateExp(guildInfo.getExp()+getExp);
}
}
MongoUtil.getLjsdMongoTemplate().lastUpdate();
}
/**
*
@ -601,7 +788,7 @@ public class GuildFightLogic {
PlayerManager playerInfoManager = UserManager.getUser(uid).getPlayerInfoManager();
Family.PersonalFightResult.Builder fightResult = Family.PersonalFightResult.newBuilder()
.setRank(rank)
.setAttackCount(2)
.setAttackCount(RedisUtil.getInstence().getMapEntry(RedisKey.FAMILY_FIGHT_ATTACK_COUNT,"",String.valueOf(uid),Integer.class))
.setUid(uid)
.setHead(1)
.setHeadFrame(playerInfoManager.getHeadFrame())
@ -618,20 +805,88 @@ public class GuildFightLogic {
*
*/
public static void guildFightResult(ISession session,MessageTypeProto.MessageType messageType) throws Exception {
RedisUtil redisUtil = RedisUtil.getInstence();
int guildId=UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId();
int enemyFamily = getEnemyFamily(guildId);
Family.GuildFightResultResponse.Builder response = Family.GuildFightResultResponse.newBuilder();
response.setGetExp(10);
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
if(enemyFamily==-1){
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
return;
}
int winStar = getTotalStar(guildId);
int defeatStar = getTotalStar(enemyFamily);
if(winStar<defeatStar){
response.setGetExp(1);
}else if(winStar==defeatStar){
response.setGetExp(10);
}else{
response.setGetExp(100);
}
response.setCurExp(guildInfo.getExp());
response.setLevel(guildInfo.getLevel());
//获取星星
Map<Integer, Integer> mapValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(guildId), Integer.class, Integer.class);
Map<Integer, Integer> mapValues = redisUtil.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);
Map<Integer, Integer> mapEnemyValues = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(enemyFamily), Integer.class, Integer.class);
response.addStar(mapValues.get(1)==null?0:mapValues.get(1));
response.addStar(mapValues.get(2)==null?0:mapValues.get(2));
response.addStar(mapValues.get(3)==null?0:mapValues.get(3));
response.addStar(mapEnemyValues.get(1)==null?0:mapValues.get(1));
response.addStar(mapEnemyValues.get(2)==null?0:mapValues.get(2));
response.addStar(mapEnemyValues.get(3)==null?0:mapValues.get(3));
response.addStar(mapEnemyValues.get(1)==null?0:mapEnemyValues.get(1));
response.addStar(mapEnemyValues.get(2)==null?0:mapEnemyValues.get(2));
response.addStar(mapEnemyValues.get(3)==null?0:mapEnemyValues.get(3));
int[] buildStar = new int[6];
int[] getStar= redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_EXTRA_STAR, "", String.valueOf(guildId), int[].class);
int[] loseStar = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_EXTRA_STAR, "", String.valueOf(enemyFamily), int[].class);
for(int i = 0 ; i<buildStar.length;i++){
if(i<3){
if(getStar!=null){
buildStar[i] = getStar[i];
}
}else{
if(loseStar!=null){
buildStar[i] = loseStar[i-3];
}
}
}
List<Integer> list = Arrays.stream(buildStar).boxed().collect(Collectors.toList());
response.addAllExtraStar(list);
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
/**
*
*
*/
public static void getAttackHeroBlood(ISession session, MessageTypeProto.MessageType messageType){
Family.GetAttackHeroBloodResponse.Builder response = Family.GetAttackHeroBloodResponse.newBuilder();
Map<String, String> bloodValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_ATTACK_BLOOD, String.valueOf(session.getUid()), String.class, String.class);
if(bloodValues!=null&&bloodValues.size()>0){
for(Map.Entry<String, String> blood:bloodValues.entrySet()){
CommonProto.HeroBloodInfo heroBloodInfo = CommonProto.HeroBloodInfo.newBuilder().setHeroId(blood.getKey()).setLostBlood(Integer.parseInt(blood.getValue())).build();
response.addBlood(heroBloodInfo);
}
}
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
private static int getTotalStar(int gid){
RedisUtil redisUtil = RedisUtil.getInstence();
int totalStar = 0;
Map<Integer, int[]> extraStar = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_EXTRA_STAR, "", Integer.class, int[].class);
Map<Integer, Integer> getStar = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(gid), Integer.class, Integer.class);
for(Map.Entry<Integer, Integer> entry:getStar.entrySet()){
totalStar+= entry.getValue();
}
int[] buildExtra = extraStar.get(gid);
for(int i = 0 ;i <buildExtra.length;i++){
totalStar+=buildExtra[i];
}
return totalStar;
}
}

View File

@ -215,6 +215,10 @@ public class GuildLogic {
MessageUtil.sendErrorResponse(session,0,msgId,"公会不存在");
return;
}
if(user.getPlayerInfoManager().getLevel()<guildInfo.getIntoLevel()){
MessageUtil.sendErrorResponse(session,0,msgId,"等级不足");
return;
}
//todo 判读人数是否已达上限
boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid), 500);
if(!isSuccess){
@ -395,9 +399,9 @@ public class GuildLogic {
if(!isSuccess){
return;
}
User targetUser = UserManager.getUser(applyId);
try {
guildInfo.addMembers(GlobalsDef.MEMBER,applyId);
User targetUser = UserManager.getUser(applyId);
targetUser.getPlayerInfoManager().setGuildId(guildInfo.getId());
GuilidManager.removeMineApplyGuildInfos(guildInfo.getId(),applyId);
GuilidManager.removeOneApplyGuildInfos(guildInfo.getId(),applyId);
@ -407,7 +411,10 @@ public class GuildLogic {
RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN,Integer.toString(applyId), Integer.toString(applyId));
}
if(isApply){
sendFamilyJoinIndication(applyId,guildInfo);
Family.FamilyJoinIndicaion.Builder builder = Family.FamilyJoinIndicaion.newBuilder();
Family.FamilyJoinIndicaion build = builder.setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(targetUser, GlobalsDef.MEMBER)).build();
sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_JOIN_INDICATION,build);
}
}
@ -520,6 +527,9 @@ public class GuildLogic {
MessageUtil.sendErrorResponse(session,0,msgId,"已操作过了");
return;
}
if(GuildFightLogic.getStatus()!=0){
MessageUtil.sendErrorResponse(session,0,msgId,"公会战期间不允许解散工会");
}
//解散公会
if(type == 1){
guildInfo.setLevelTime((int)(System.currentTimeMillis()/1000));
@ -576,7 +586,7 @@ public class GuildLogic {
* @param joinType
* @throws Exception
*/
public static void changeJoinType(ISession session,int joinType) throws Exception {
public static void changeJoinType(ISession session,int joinType,int joinLevel) throws Exception {
int msgId = MessageTypeProto.MessageType.FAMILY_CHANGE_JOIN_TYPE_RESPONSE_VALUE;
if(joinType<=0 || joinType>3){
MessageUtil.sendErrorResponse(session,0,msgId,"参数错误");
@ -595,6 +605,7 @@ public class GuildLogic {
MessageUtil.sendErrorResponse(session,0,msgId,"无权操作");
return;
}
guildInfo.updateIntoLevel(joinLevel);
guildInfo.setJoinType(joinType);
sendFamilyBaseUpdateIndication(guildInfo);
MessageUtil.sendMessage(session,1,msgId,null,true);
@ -665,6 +676,9 @@ public class GuildLogic {
MessageUtil.sendErrorResponse(session,0,msgId,"会长不能退出公会");
return;
}
if(guildInfo.getDefendInfo().containsKey((uid))){
guildInfo.removeDefendInfo(uid);
}
guildInfo.removeMember(uidType,uid);
user.getPlayerInfoManager().setGuildId(0);
user.getGuildMyInfo().clearOfLevelGuild();

View File

@ -359,6 +359,7 @@ public class CBean2Proto {
.setTotalNum(guildInfo.getTotalMembers())
.setIcon(guildInfo.getIcon())
.setFightResult(familyContribute)
.setPlayerIntoLevel(guildInfo.getIntoLevel())
.build();
}