back_recharge
gaojie 2019-05-16 20:21:11 +08:00
commit cdaf854d55
6 changed files with 151 additions and 46 deletions

View File

@ -14,10 +14,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class RedisUtil {
@ -891,6 +888,27 @@ public class RedisUtil {
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){
Map<K,T> result = new HashMap<>();
@ -904,7 +922,7 @@ public class RedisUtil {
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);
for (int i = 0; i < MAX_TRY_TIMES; i++) {
try {

View File

@ -10,7 +10,8 @@ public class AdventureBoss {
private int findUserId; //发现者
private int findTime; //发现时间
private int totalHp;// 总血量
private List<Integer> remainHp; //剩余血量
private int remainHp;
private List<Integer> remainHps; //剩余血量
public AdventureBoss() {
}
@ -20,51 +21,21 @@ public class AdventureBoss {
this.findUserId = findUserId;
this.findTime = findTime;
this.totalHp = totalHp;
this.remainHp = remainHp;
this.remainHp = totalHp;
this.remainHps = remainHp;
this.bossGroupId = bossGroupId;
this.arenaLevel = arenaLevel;
}
public String getBossId() {
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) {
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() {
return bossGroupId;
}
@ -88,4 +59,44 @@ public class AdventureBoss {
public void setArenaLevel(int 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;
}
}

View File

@ -8,6 +8,7 @@ import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.handler.map.MapManager;
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.root.User;
import com.ljsd.jieling.logic.dao.UserManager;
@ -28,6 +29,8 @@ import java.util.*;
public class CombatLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(CombatLogic.class);
public Set<Integer> orderAdventureUids= new HashSet<>();
private CombatLogic(){}
@ -177,6 +180,7 @@ public class CombatLogic {
adventureManager.setFlushBossTime(nowMs + flushBossNextTime *1000);
}
}
orderAdventureUids.add(uid);
builder.setNextBossFlushTime(flushBossNextTime).setBuyTimsPerDay(adventureManager.getBuyTimsPerDay()).setDayChallengeTimes(adventureManager.getDayChallengeTimes());
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();
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 {
@ -426,6 +473,7 @@ public class CombatLogic {
}
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_OWN,"",bossId,0);
}
adventureStateInfo.setBossId(bossId);
adventureStateInfo.setBossGroupId(bossGroupID);
@ -433,6 +481,28 @@ public class CombatLogic {
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 {
AdventureBoss adventureBoss = RedisUtil.getInstence().getMapEntry(RedisKey.ADVENTRUEN_BOSS_INFO, "", bossId, AdventureBoss.class);
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);
int bossGroupId = adventureBoss.getBossGroupId();
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);
Map<Integer, List<CommonProto.FightUnitInfo>> monsterByGroup = MonsterUtil.getMonsterByGroup(bossGroupId,hps);
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){
int hurt = 0;
List<Integer> oldRemainHp = adventureBoss.getRemainHp();
List<Integer> oldRemainHp = adventureBoss.getRemainHps();
int fightResult = checkResult[0];
if(fightResult == 1){
for(Integer hp : oldRemainHp){
@ -535,7 +605,8 @@ public class CombatLogic {
result.add(checkResult[i]);
hurt+=(oldRemainHp.get(i-1)-checkResult[i]);
}
adventureBoss.setRemainHp(result);
adventureBoss.setRemainHp(adventureBoss.getRemainHp() - hurt);
adventureBoss.setRemainHps(result);
return hurt;
}

View File

@ -20,6 +20,7 @@ import com.ljsd.jieling.logic.dao.LevelDifficulty;
import com.ljsd.jieling.logic.dao.PlayerManager;
import com.ljsd.jieling.logic.dao.UserManager;
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.Tea;
import com.ljsd.jieling.netty.handler.GameMessageHandler;
@ -340,6 +341,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
}
GameMessageHandler.currentSessions.remove(session.getUid());
CombatLogic.getInstance().orderAdventureUids.remove(session.getUid());
try {
OnlineUserManager.userOffline(session.getUid());

View File

@ -204,7 +204,6 @@ public class CBean2Proto {
public static CommonProto.AdventureRankItemInfo getAdventureRankItemInfo(int uid, User user, int hurtNum, int rank){
PlayerManager playerInfoManager = user.getPlayerInfoManager();
return CommonProto.AdventureRankItemInfo.newBuilder()
.setUid(uid)
.setLevel(playerInfoManager.getLevel())
.setName(playerInfoManager.getNickName())
.setHurt(hurtNum)

View File

@ -0,0 +1,4 @@
package db;
public class RedisTest {
}