Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
cdaf854d55
|
@ -14,10 +14,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.data.redis.core.ZSetOperations;
|
import org.springframework.data.redis.core.ZSetOperations;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class RedisUtil {
|
public class RedisUtil {
|
||||||
|
@ -891,6 +888,27 @@ public class RedisUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getMapEntrys(String type, String key, Collection<Object> mapKeys, Class<T> valueClazz){
|
||||||
|
String rkey = getKey(type, key);
|
||||||
|
List<T> result = new ArrayList<>();
|
||||||
|
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||||
|
try {
|
||||||
|
List<Object> objects = redisTemplate.opsForHash().multiGet(rkey, mapKeys);
|
||||||
|
if(objects!=null &&!objects.isEmpty()){
|
||||||
|
for(Object o : objects){
|
||||||
|
if(o!=null){
|
||||||
|
result.add(gson.fromJson(o.toString(),valueClazz));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TimeUtils.sleep(FAILED_SLEEP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public <K,T> Map<K,T> getMapValues(String type,String key,Class<K> keyClazz,Class<T> valueClazz){
|
public <K,T> Map<K,T> getMapValues(String type,String key,Class<K> keyClazz,Class<T> valueClazz){
|
||||||
Map<K,T> result = new HashMap<>();
|
Map<K,T> result = new HashMap<>();
|
||||||
|
@ -904,7 +922,7 @@ public class RedisUtil {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMapEntrys(String type, String key, String... mapKeys){
|
public void removeMapEntrys(String type, String key, Object... mapKeys){
|
||||||
String rkey = getKey(type, key);
|
String rkey = getKey(type, key);
|
||||||
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,7 +10,8 @@ public class AdventureBoss {
|
||||||
private int findUserId; //发现者
|
private int findUserId; //发现者
|
||||||
private int findTime; //发现时间
|
private int findTime; //发现时间
|
||||||
private int totalHp;// 总血量
|
private int totalHp;// 总血量
|
||||||
private List<Integer> remainHp; //剩余血量
|
private int remainHp;
|
||||||
|
private List<Integer> remainHps; //剩余血量
|
||||||
|
|
||||||
public AdventureBoss() {
|
public AdventureBoss() {
|
||||||
}
|
}
|
||||||
|
@ -20,51 +21,21 @@ public class AdventureBoss {
|
||||||
this.findUserId = findUserId;
|
this.findUserId = findUserId;
|
||||||
this.findTime = findTime;
|
this.findTime = findTime;
|
||||||
this.totalHp = totalHp;
|
this.totalHp = totalHp;
|
||||||
this.remainHp = remainHp;
|
this.remainHp = totalHp;
|
||||||
|
this.remainHps = remainHp;
|
||||||
this.bossGroupId = bossGroupId;
|
this.bossGroupId = bossGroupId;
|
||||||
this.arenaLevel = arenaLevel;
|
this.arenaLevel = arenaLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getBossId() {
|
public String getBossId() {
|
||||||
return bossId;
|
return bossId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFindUserId() {
|
|
||||||
return findUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFindTime() {
|
|
||||||
return findTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalHp() {
|
|
||||||
return totalHp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getRemainHp() {
|
|
||||||
return remainHp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBossId(String bossId) {
|
public void setBossId(String bossId) {
|
||||||
this.bossId = bossId;
|
this.bossId = bossId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFindUserId(int findUserId) {
|
|
||||||
this.findUserId = findUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFindTime(int findTime) {
|
|
||||||
this.findTime = findTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalHp(int totalHp) {
|
|
||||||
this.totalHp = totalHp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemainHp(List<Integer> remainHp) {
|
|
||||||
this.remainHp = remainHp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBossGroupId() {
|
public int getBossGroupId() {
|
||||||
return bossGroupId;
|
return bossGroupId;
|
||||||
}
|
}
|
||||||
|
@ -88,4 +59,44 @@ public class AdventureBoss {
|
||||||
public void setArenaLevel(int arenaLevel) {
|
public void setArenaLevel(int arenaLevel) {
|
||||||
this.arenaLevel = arenaLevel;
|
this.arenaLevel = arenaLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getFindUserId() {
|
||||||
|
return findUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFindUserId(int findUserId) {
|
||||||
|
this.findUserId = findUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFindTime() {
|
||||||
|
return findTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFindTime(int findTime) {
|
||||||
|
this.findTime = findTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalHp() {
|
||||||
|
return totalHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalHp(int totalHp) {
|
||||||
|
this.totalHp = totalHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemainHp() {
|
||||||
|
return remainHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemainHp(int remainHp) {
|
||||||
|
this.remainHp = remainHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getRemainHps() {
|
||||||
|
return remainHps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemainHps(List<Integer> remainHps) {
|
||||||
|
this.remainHps = remainHps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.ljsd.jieling.db.redis.RedisUtil;
|
||||||
import com.ljsd.jieling.globals.Global;
|
import com.ljsd.jieling.globals.Global;
|
||||||
import com.ljsd.jieling.handler.map.MapManager;
|
import com.ljsd.jieling.handler.map.MapManager;
|
||||||
import com.ljsd.jieling.handler.map.behavior.BehaviorUtil;
|
import com.ljsd.jieling.handler.map.behavior.BehaviorUtil;
|
||||||
|
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||||
import com.ljsd.jieling.logic.dao.*;
|
import com.ljsd.jieling.logic.dao.*;
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
@ -28,6 +29,8 @@ import java.util.*;
|
||||||
public class CombatLogic {
|
public class CombatLogic {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CombatLogic.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CombatLogic.class);
|
||||||
|
|
||||||
|
public Set<Integer> orderAdventureUids= new HashSet<>();
|
||||||
|
|
||||||
private CombatLogic(){}
|
private CombatLogic(){}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,6 +180,7 @@ public class CombatLogic {
|
||||||
adventureManager.setFlushBossTime(nowMs + flushBossNextTime *1000);
|
adventureManager.setFlushBossTime(nowMs + flushBossNextTime *1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
orderAdventureUids.add(uid);
|
||||||
builder.setNextBossFlushTime(flushBossNextTime).setBuyTimsPerDay(adventureManager.getBuyTimsPerDay()).setDayChallengeTimes(adventureManager.getDayChallengeTimes());
|
builder.setNextBossFlushTime(flushBossNextTime).setBuyTimsPerDay(adventureManager.getBuyTimsPerDay()).setDayChallengeTimes(adventureManager.getDayChallengeTimes());
|
||||||
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ADVENTURE_INFO_RESPONSE_VALUE,builder.build(),true);
|
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ADVENTURE_INFO_RESPONSE_VALUE,builder.build(),true);
|
||||||
}
|
}
|
||||||
|
@ -384,11 +388,54 @@ public class CombatLogic {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getInvasionBoss(ISession session){
|
public void getInvasionBoss(ISession session) throws Exception {
|
||||||
int uid = session.getUid();
|
int uid = session.getUid();
|
||||||
Map<String, Integer> mapValues = RedisUtil.getInstence().getMapValues(RedisKey.ADVENTRUEN_BOSS_OWN, Integer.toString(uid), String.class, Integer.class);
|
|
||||||
|
|
||||||
|
|
||||||
|
FightInfoProto.AdventureBossInfoResponse.Builder builder = FightInfoProto.AdventureBossInfoResponse.newBuilder();
|
||||||
|
Map<String, Integer> myHurtInfo = RedisUtil.getInstence().getMapValues(RedisKey.ADVENTRUEN_BOSS_OWN, Integer.toString(uid), String.class, Integer.class);
|
||||||
|
int now = (int)(TimeUtils.now()/1000);
|
||||||
|
if(myHurtInfo!=null&&!myHurtInfo.isEmpty()){
|
||||||
|
List<Object> kes = new ArrayList<>(myHurtInfo.keySet());
|
||||||
|
List<AdventureBoss> adventureBosseInfo = RedisUtil.getInstence().getMapEntrys(RedisKey.ADVENTRUEN_BOSS_INFO, "", kes, AdventureBoss.class);
|
||||||
|
List<String> removeAdventureBosseInfo = new ArrayList<>();
|
||||||
|
for(AdventureBoss adventureBoss : adventureBosseInfo){
|
||||||
|
if(adventureBoss == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String bossId = adventureBoss.getBossId();
|
||||||
|
int arenaId = adventureBoss.getArenaId();
|
||||||
|
int findTime = adventureBoss.getFindTime();
|
||||||
|
SAdventureConfig sAdventureConfig = SAdventureConfig.getConfig().get(arenaId);
|
||||||
|
int invasionBossHolding = sAdventureConfig.getInvasionBossHolding();
|
||||||
|
int remainTime = invasionBossHolding - ( now - findTime);
|
||||||
|
int findUserId = adventureBoss.getFindUserId();
|
||||||
|
if(remainTime<0){
|
||||||
|
removeAdventureBosseInfo.add(bossId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
User findUsser = UserManager.getUser(findUserId);
|
||||||
|
builder.addAdventureBossInfo(CommonProto.AdventureBossInfo.newBuilder()
|
||||||
|
.setArenaId(adventureBoss.getArenaId())
|
||||||
|
.setFindUid(adventureBoss.getFindUserId())
|
||||||
|
.setFindName(findUsser.getPlayerInfoManager().getNickName())
|
||||||
|
.setBossId(bossId)
|
||||||
|
.setBossGroupId(adventureBoss.getBossGroupId())
|
||||||
|
.setMyHurt(myHurtInfo.get(bossId))
|
||||||
|
.setRemainTime(remainTime)
|
||||||
|
.setTotalHp(adventureBoss.getTotalHp())
|
||||||
|
.setBossRemainlHp(adventureBoss.getRemainHp())
|
||||||
|
.build());
|
||||||
|
myHurtInfo.remove(bossId);
|
||||||
|
}
|
||||||
|
if(!myHurtInfo.isEmpty()){
|
||||||
|
RedisUtil.getInstence().removeMapEntrys(RedisKey.ADVENTRUEN_BOSS_OWN,"",myHurtInfo.keySet().toArray());
|
||||||
|
}
|
||||||
|
if(!removeAdventureBosseInfo.isEmpty()){
|
||||||
|
RedisUtil.getInstence().removeMapEntrys(RedisKey.ADVENTRUEN_BOSS_INFO,"",removeAdventureBosseInfo.toArray());
|
||||||
|
RedisUtil.getInstence().removeMapEntrys(RedisKey.ADVENTRUEN_BOSS_OWN,"",removeAdventureBosseInfo.toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ADVENTURE_BOSSHURT_RESPONSE_VALUE,builder.build(),true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int randomInvasionBoss(int uid,int arenaID) throws Exception {
|
public int randomInvasionBoss(int uid,int arenaID) throws Exception {
|
||||||
|
@ -426,6 +473,7 @@ public class CombatLogic {
|
||||||
}
|
}
|
||||||
AdventureBoss adventureBoss = new AdventureBoss(bossId,bossGroupID,arenaID,levle,uid,now,totalHp,hps);
|
AdventureBoss adventureBoss = new AdventureBoss(bossId,bossGroupID,arenaID,levle,uid,now,totalHp,hps);
|
||||||
RedisUtil.getInstence().putMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO,"",bossId,adventureBoss);
|
RedisUtil.getInstence().putMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO,"",bossId,adventureBoss);
|
||||||
|
RedisUtil.getInstence().putMapEntry(RedisKey.ADVENTRUEN_BOSS_OWN,"",bossId,0);
|
||||||
}
|
}
|
||||||
adventureStateInfo.setBossId(bossId);
|
adventureStateInfo.setBossId(bossId);
|
||||||
adventureStateInfo.setBossGroupId(bossGroupID);
|
adventureStateInfo.setBossGroupId(bossGroupID);
|
||||||
|
@ -433,6 +481,28 @@ public class CombatLogic {
|
||||||
return bossGroupID;
|
return bossGroupID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void broadAdventureBoss(AdventureBoss adventureBoss,String findUserName){
|
||||||
|
int now = (int)(TimeUtils.now()/1000);
|
||||||
|
int arenaId = adventureBoss.getArenaId();
|
||||||
|
SAdventureConfig sAdventureConfig = SAdventureConfig.getConfig().get(arenaId);
|
||||||
|
CommonProto.AdventureBossSimpleInfo build = CommonProto.AdventureBossSimpleInfo.newBuilder()
|
||||||
|
.setArenaId(arenaId)
|
||||||
|
.setBossId(adventureBoss.getBossId())
|
||||||
|
.setBossGroupId(adventureBoss.getBossGroupId())
|
||||||
|
.setRemainTime(sAdventureConfig.getInvasionBossHolding())
|
||||||
|
.setFindUserName(findUserName)
|
||||||
|
.build();
|
||||||
|
FightInfoProto.AdventureBossFindIndication adventureBossFindIndication = FightInfoProto.AdventureBossFindIndication.newBuilder().setAdventureBossSimpleInfo(build).build();
|
||||||
|
|
||||||
|
for(Integer uid:orderAdventureUids){
|
||||||
|
ISession sessionByUid = OnlineUserManager.getSessionByUid(uid);
|
||||||
|
if(sessionByUid!=null){
|
||||||
|
MessageUtil.sendMessage(sessionByUid,1, MessageTypeProto.MessageType.ADVENTURE_BOSS_FIND_INDICATION_VALUE,adventureBossFindIndication,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void shareAdventureBoss(ISession session,String bossId) throws Exception {
|
public void shareAdventureBoss(ISession session,String bossId) throws Exception {
|
||||||
AdventureBoss adventureBoss = RedisUtil.getInstence().getMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO, "", bossId, AdventureBoss.class);
|
AdventureBoss adventureBoss = RedisUtil.getInstence().getMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO, "", bossId, AdventureBoss.class);
|
||||||
if(adventureBoss == null || adventureBoss.getFindUserId() !=session.getUid()){
|
if(adventureBoss == null || adventureBoss.getFindUserId() !=session.getUid()){
|
||||||
|
@ -460,7 +530,7 @@ public class CombatLogic {
|
||||||
AdventureBoss adventureBoss = RedisUtil.getInstence().getMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO, "", bossId, AdventureBoss.class);
|
AdventureBoss adventureBoss = RedisUtil.getInstence().getMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO, "", bossId, AdventureBoss.class);
|
||||||
int bossGroupId = adventureBoss.getBossGroupId();
|
int bossGroupId = adventureBoss.getBossGroupId();
|
||||||
Map<Integer,List<Integer>> hps = new HashMap<>(1);
|
Map<Integer,List<Integer>> hps = new HashMap<>(1);
|
||||||
hps.put(0,adventureBoss.getRemainHp());
|
hps.put(0,adventureBoss.getRemainHps());
|
||||||
CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(user, teamId,true);
|
CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(user, teamId,true);
|
||||||
Map<Integer, List<CommonProto.FightUnitInfo>> monsterByGroup = MonsterUtil.getMonsterByGroup(bossGroupId,hps);
|
Map<Integer, List<CommonProto.FightUnitInfo>> monsterByGroup = MonsterUtil.getMonsterByGroup(bossGroupId,hps);
|
||||||
List<CommonProto.FightTeamInfo> monsterGroupList = BehaviorUtil.getFightTeamInfos(bossGroupId,monsterByGroup, Global.MONSTER_1);
|
List<CommonProto.FightTeamInfo> monsterGroupList = BehaviorUtil.getFightTeamInfos(bossGroupId,monsterByGroup, Global.MONSTER_1);
|
||||||
|
@ -522,7 +592,7 @@ public class CombatLogic {
|
||||||
|
|
||||||
public int updateBossAndGetHurtForFight(int[] checkResult,AdventureBoss adventureBoss){
|
public int updateBossAndGetHurtForFight(int[] checkResult,AdventureBoss adventureBoss){
|
||||||
int hurt = 0;
|
int hurt = 0;
|
||||||
List<Integer> oldRemainHp = adventureBoss.getRemainHp();
|
List<Integer> oldRemainHp = adventureBoss.getRemainHps();
|
||||||
int fightResult = checkResult[0];
|
int fightResult = checkResult[0];
|
||||||
if(fightResult == 1){
|
if(fightResult == 1){
|
||||||
for(Integer hp : oldRemainHp){
|
for(Integer hp : oldRemainHp){
|
||||||
|
@ -535,7 +605,8 @@ public class CombatLogic {
|
||||||
result.add(checkResult[i]);
|
result.add(checkResult[i]);
|
||||||
hurt+=(oldRemainHp.get(i-1)-checkResult[i]);
|
hurt+=(oldRemainHp.get(i-1)-checkResult[i]);
|
||||||
}
|
}
|
||||||
adventureBoss.setRemainHp(result);
|
adventureBoss.setRemainHp(adventureBoss.getRemainHp() - hurt);
|
||||||
|
adventureBoss.setRemainHps(result);
|
||||||
return hurt;
|
return hurt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.ljsd.jieling.logic.dao.LevelDifficulty;
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
|
import com.ljsd.jieling.logic.fight.CombatLogic;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||||
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
||||||
|
@ -340,6 +341,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMessageHandler.currentSessions.remove(session.getUid());
|
GameMessageHandler.currentSessions.remove(session.getUid());
|
||||||
|
CombatLogic.getInstance().orderAdventureUids.remove(session.getUid());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OnlineUserManager.userOffline(session.getUid());
|
OnlineUserManager.userOffline(session.getUid());
|
||||||
|
|
|
@ -204,7 +204,6 @@ public class CBean2Proto {
|
||||||
public static CommonProto.AdventureRankItemInfo getAdventureRankItemInfo(int uid, User user, int hurtNum, int rank){
|
public static CommonProto.AdventureRankItemInfo getAdventureRankItemInfo(int uid, User user, int hurtNum, int rank){
|
||||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||||
return CommonProto.AdventureRankItemInfo.newBuilder()
|
return CommonProto.AdventureRankItemInfo.newBuilder()
|
||||||
.setUid(uid)
|
|
||||||
.setLevel(playerInfoManager.getLevel())
|
.setLevel(playerInfoManager.getLevel())
|
||||||
.setName(playerInfoManager.getNickName())
|
.setName(playerInfoManager.getNickName())
|
||||||
.setHurt(hurtNum)
|
.setHurt(hurtNum)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package db;
|
||||||
|
|
||||||
|
public class RedisTest {
|
||||||
|
}
|
Loading…
Reference in New Issue