自动发现服务器
parent
5ff27b049c
commit
f5ec857e24
|
@ -181,7 +181,6 @@ public abstract class Creature extends SceneActor{
|
||||||
if(update){
|
if(update){
|
||||||
path.clear();
|
path.clear();
|
||||||
getScene().processEventUpdate(EventType.SCENEACTORE_UPDATE,this.getId());
|
getScene().processEventUpdate(EventType.SCENEACTORE_UPDATE,this.getId());
|
||||||
System.out.println("can not move next" + getId() + " hit the " + sceneActor.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -53,6 +53,11 @@ public class Scene implements Runnable{
|
||||||
private Map<Integer, AnalysisData> analysisDataMap = new HashMap<>();
|
private Map<Integer, AnalysisData> analysisDataMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
public AnalysisData getAnalysisData(int id){
|
||||||
|
return analysisDataMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void randomMineralOfUserDeath(Creature creature,int totalMineal){
|
public void randomMineralOfUserDeath(Creature creature,int totalMineal){
|
||||||
if(totalMineal <=0){
|
if(totalMineal <=0){
|
||||||
return;
|
return;
|
||||||
|
@ -125,18 +130,14 @@ public class Scene implements Runnable{
|
||||||
Integer value = next.getValue();
|
Integer value = next.getValue();
|
||||||
if(tick>value){
|
if(tick>value){
|
||||||
Integer monsterIndex = next.getKey();
|
Integer monsterIndex = next.getKey();
|
||||||
System.out.println("the actor siz=" + sceneActorMap.size());
|
|
||||||
SceneManager.createMonster(this,monsterIndex);
|
SceneManager.createMonster(this,monsterIndex);
|
||||||
processEventUpdate(EventType.SCENEACTORE_UPDATE,monsterIndex);
|
processEventUpdate(EventType.SCENEACTORE_UPDATE,monsterIndex);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
System.out.println("the actor after siz=" + sceneActorMap.size());
|
|
||||||
System.out.println("the monsterid={}" + monsterIndex + "recovery");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void whenMonsterDead(int deadId){
|
public void whenMonsterDead(int deadId){
|
||||||
System.out.println("the monster deadID="+deadId);
|
|
||||||
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
|
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
|
||||||
int[] monsterItem = sBloodyBattleSetting.getMonsterIndexMap().get(deadId);
|
int[] monsterItem = sBloodyBattleSetting.getMonsterIndexMap().get(deadId);
|
||||||
monsterRecoryMap.put(deadId,monsterItem[1]*20 + tick);
|
monsterRecoryMap.put(deadId,monsterItem[1]*20 + tick);
|
||||||
|
@ -159,12 +160,11 @@ public class Scene implements Runnable{
|
||||||
if(msgUpdate || !cacheMsg.isEmpty()){
|
if(msgUpdate || !cacheMsg.isEmpty()){
|
||||||
for(Integer removeId : builder.getRemoveActorIdList()){
|
for(Integer removeId : builder.getRemoveActorIdList()){
|
||||||
sceneActorMap.remove(removeId);
|
sceneActorMap.remove(removeId);
|
||||||
System.out.println("remove the id=------------" + removeId);
|
|
||||||
}
|
}
|
||||||
for(SceneActor sceneActor : sceneActorMap.values()){
|
for(SceneActor sceneActor : sceneActorMap.values()){
|
||||||
if(sceneActor.getType() != ActorType.Npc){
|
if(sceneActor.getType() != ActorType.Npc){
|
||||||
if(willUpdateActors.contains(sceneActor.getId())){
|
if(willUpdateActors.contains(sceneActor.getId())){
|
||||||
builder.addSceneActor(BeanToProto.getSceneActor(sceneActor));
|
builder.addSceneActor(BeanToProto.getSceneActor(this,sceneActor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,6 @@ public class Scene implements Runnable{
|
||||||
*/
|
*/
|
||||||
public void processEventUpdate(EventType eventType,Object parm){
|
public void processEventUpdate(EventType eventType,Object parm){
|
||||||
msgUpdate = true;
|
msgUpdate = true;
|
||||||
System.out.println("the eventType = "+ eventType);
|
|
||||||
switch (eventType){
|
switch (eventType){
|
||||||
case SCENEACTORE_UPDATE:
|
case SCENEACTORE_UPDATE:
|
||||||
willUpdateActors.add((int)parm);
|
willUpdateActors.add((int)parm);
|
||||||
|
@ -215,7 +214,6 @@ public class Scene implements Runnable{
|
||||||
case SCENEACTORE_REMOVE:
|
case SCENEACTORE_REMOVE:
|
||||||
int deadId = (int) parm;
|
int deadId = (int) parm;
|
||||||
builder.addRemoveActorId(deadId);
|
builder.addRemoveActorId(deadId);
|
||||||
System.out.println("remove the scene id is " + deadId);
|
|
||||||
break;
|
break;
|
||||||
case POSMINERAL_REMOVE:
|
case POSMINERAL_REMOVE:
|
||||||
builder.addRemovePosMineralId( (int) parm);
|
builder.addRemovePosMineralId( (int) parm);
|
||||||
|
@ -296,7 +294,6 @@ public class Scene implements Runnable{
|
||||||
needAdd = flushNums;
|
needAdd = flushNums;
|
||||||
}
|
}
|
||||||
SceneManager.createMinear(this,size,needAdd);
|
SceneManager.createMinear(this,size,needAdd);
|
||||||
System.out.println("创建矿....");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -307,7 +304,7 @@ public class Scene implements Runnable{
|
||||||
|
|
||||||
//退出操作
|
//退出操作
|
||||||
public void gameEnd() {
|
public void gameEnd() {
|
||||||
System.out.println("game ending....");
|
LOGGER.info("the roomId={} is gameEnding" ,roomId);
|
||||||
isEnd = true;
|
isEnd = true;
|
||||||
//结算操作
|
//结算操作
|
||||||
List<SortDataBean> sortDataBeans = new ArrayList<>();
|
List<SortDataBean> sortDataBeans = new ArrayList<>();
|
||||||
|
@ -365,7 +362,6 @@ public class Scene implements Runnable{
|
||||||
executorService.submit(new Callable<Integer>() {
|
executorService.submit(new Callable<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer call() throws Exception {
|
public Integer call() throws Exception {
|
||||||
System.out.println("exce com.ljsd.battle...............................");
|
|
||||||
SceneActor attackActor = battleRequest.getAttackActor();
|
SceneActor attackActor = battleRequest.getAttackActor();
|
||||||
SceneActor defActor = battleRequest.getDefActor();
|
SceneActor defActor = battleRequest.getDefActor();
|
||||||
SceneActor temp = null;
|
SceneActor temp = null;
|
||||||
|
@ -395,8 +391,6 @@ public class Scene implements Runnable{
|
||||||
effectBuffer.clearvalues();
|
effectBuffer.clearvalues();
|
||||||
effectBuffer.addEffectValue(checkResult[0]);
|
effectBuffer.addEffectValue(checkResult[0]);
|
||||||
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
|
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
|
||||||
System.out.println(effectBuffer);
|
|
||||||
System.out.println(attackActor.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<Integer, EffectBuffer> defBufferMap = defActor.getBufferMap();
|
Map<Integer, EffectBuffer> defBufferMap = defActor.getBufferMap();
|
||||||
|
@ -405,8 +399,6 @@ public class Scene implements Runnable{
|
||||||
effectBuffer.clearvalues();
|
effectBuffer.clearvalues();
|
||||||
effectBuffer.addEffectValue(checkResult[0]==1?0:1);
|
effectBuffer.addEffectValue(checkResult[0]==1?0:1);
|
||||||
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
|
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
|
||||||
System.out.println(effectBuffer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -165,8 +165,9 @@ public abstract class SceneActor{
|
||||||
// 定位到出生点位置
|
// 定位到出生点位置
|
||||||
this.setPos(SceneManager.selectForPlayerRebirth(scene));
|
this.setPos(SceneManager.selectForPlayerRebirth(scene));
|
||||||
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,id);
|
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,id);
|
||||||
|
if(scene.getSceneActorMap().containsKey(value.getCaster()) &&scene.getSceneActorMap().get(value.getCaster()).getType() == ActorType.Player){
|
||||||
MessageBoxUtils.onGameEvent(AnalysisEventType.BATTLE,scene,new AnalysisSourceData(value.getTarget(),value.getCaster(),effectValue));
|
MessageBoxUtils.onGameEvent(AnalysisEventType.BATTLE,scene,new AnalysisSourceData(value.getTarget(),value.getCaster(),effectValue));
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
Creature creature = (Creature) scene.getSceneActorMap().get(value.getCaster());
|
Creature creature = (Creature) scene.getSceneActorMap().get(value.getCaster());
|
||||||
if(creature.getType() == ActorType.Monster){
|
if(creature.getType() == ActorType.Monster){
|
||||||
|
@ -184,7 +185,7 @@ public abstract class SceneActor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.getType() == ActorType.Player){
|
if(this.getType() == ActorType.Player && creature.getType() == ActorType.Player){
|
||||||
MessageBoxUtils.onGameEvent(AnalysisEventType.BATTLE,scene,new AnalysisSourceData(value.getTarget(),value.getCaster(),effectValue));
|
MessageBoxUtils.onGameEvent(AnalysisEventType.BATTLE,scene,new AnalysisSourceData(value.getTarget(),value.getCaster(),effectValue));
|
||||||
}
|
}
|
||||||
stateType = StateType.MOVEABLE;
|
stateType = StateType.MOVEABLE;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ljsd.battle.room;
|
package com.ljsd.battle.room;
|
||||||
|
|
||||||
import com.ljsd.battle.manager.BattleManager;
|
import com.ljsd.battle.manager.BattleManager;
|
||||||
|
import com.ljsd.battle.statics.AnalysisData;
|
||||||
import com.ljsd.battle.vo.UserBloodySnpInfo;
|
import com.ljsd.battle.vo.UserBloodySnpInfo;
|
||||||
|
|
||||||
import com.ljsd.battle.actor.*;
|
import com.ljsd.battle.actor.*;
|
||||||
|
@ -14,7 +15,7 @@ import java.util.Map;
|
||||||
|
|
||||||
public class BeanToProto {
|
public class BeanToProto {
|
||||||
|
|
||||||
public static CommonProto.SceneActor getSceneActor(SceneActor sceneActor){
|
public static CommonProto.SceneActor getSceneActor(Scene scene,SceneActor sceneActor){
|
||||||
ActorType actorType = sceneActor.getType();
|
ActorType actorType = sceneActor.getType();
|
||||||
CommonProto.SceneActor.Builder builder = CommonProto.SceneActor.newBuilder()
|
CommonProto.SceneActor.Builder builder = CommonProto.SceneActor.newBuilder()
|
||||||
.setId(sceneActor.getId())
|
.setId(sceneActor.getId())
|
||||||
|
@ -22,7 +23,7 @@ public class BeanToProto {
|
||||||
.setType(actorType.getStateCode())
|
.setType(actorType.getStateCode())
|
||||||
.setState(sceneActor.getStateType().getState());
|
.setState(sceneActor.getStateType().getState());
|
||||||
if(actorType != ActorType.Npc){
|
if(actorType != ActorType.Npc){
|
||||||
builder.setCreature(getCreature((Creature)sceneActor));
|
builder.setCreature(getCreature(scene,(Creature)sceneActor));
|
||||||
}
|
}
|
||||||
if(actorType == ActorType.Player){
|
if(actorType == ActorType.Player){
|
||||||
builder.setUserName(BattleManager.bloodMyHeroInfoMap.get(sceneActor.getId()).getName());
|
builder.setUserName(BattleManager.bloodMyHeroInfoMap.get(sceneActor.getId()).getName());
|
||||||
|
@ -30,7 +31,7 @@ public class BeanToProto {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommonProto.Creature getCreature(Creature creature){
|
public static CommonProto.Creature getCreature(Scene scene,Creature creature){
|
||||||
CommonProto.Creature.Builder builder = CommonProto.Creature.newBuilder();
|
CommonProto.Creature.Builder builder = CommonProto.Creature.newBuilder();
|
||||||
if(creature.getType() == ActorType.Player){
|
if(creature.getType() == ActorType.Player){
|
||||||
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(creature.getId());
|
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(creature.getId());
|
||||||
|
@ -43,6 +44,8 @@ public class BeanToProto {
|
||||||
Integer curHp = attribute.get(HeroAttributeEnum.CurHP.getPropertyId());
|
Integer curHp = attribute.get(HeroAttributeEnum.CurHP.getPropertyId());
|
||||||
builder.addHeroInfo(CommonProto.BloodyHeroInfo.newBuilder().setHeroId(heroId).setHeroHp(curHp).setHeroMaxHp(hp).setHeroTid(familyHeroInfo.getTempleteId()));
|
builder.addHeroInfo(CommonProto.BloodyHeroInfo.newBuilder().setHeroId(heroId).setHeroHp(curHp).setHeroMaxHp(hp).setHeroTid(familyHeroInfo.getTempleteId()));
|
||||||
}
|
}
|
||||||
|
AnalysisData analysisData = scene.getAnalysisData(creature.getId());
|
||||||
|
builder.setKillNums(analysisData.getKillNums());
|
||||||
}
|
}
|
||||||
if(creature.getStateType() != StateType.FROZEN){
|
if(creature.getStateType() != StateType.FROZEN){
|
||||||
builder.addAllPath(creature.getPath());
|
builder.addAllPath(creature.getPath());
|
||||||
|
@ -50,7 +53,6 @@ public class BeanToProto {
|
||||||
return builder.setCurHp(creature.getLife().getCurHp())
|
return builder.setCurHp(creature.getLife().getCurHp())
|
||||||
.setMaxHp(creature.getLife().getMaxMp())
|
.setMaxHp(creature.getLife().getMaxMp())
|
||||||
.setSpeed(creature.getSpeed())
|
.setSpeed(creature.getSpeed())
|
||||||
|
|
||||||
.setCamp(creature.getCamp())
|
.setCamp(creature.getCamp())
|
||||||
.setMineral(creature.getMineral())
|
.setMineral(creature.getMineral())
|
||||||
.build();
|
.build();
|
||||||
|
@ -77,7 +79,7 @@ public class BeanToProto {
|
||||||
CommonProto.SceneInfo.Builder builder = CommonProto.SceneInfo.newBuilder().setMapId(scene.getMapId());
|
CommonProto.SceneInfo.Builder builder = CommonProto.SceneInfo.newBuilder().setMapId(scene.getMapId());
|
||||||
Map<Integer, SceneActor> sceneActorMap = scene.getSceneActorMap();
|
Map<Integer, SceneActor> sceneActorMap = scene.getSceneActorMap();
|
||||||
for(SceneActor sceneActor : sceneActorMap.values()){
|
for(SceneActor sceneActor : sceneActorMap.values()){
|
||||||
builder.addSceneActor(getSceneActor(sceneActor));
|
builder.addSceneActor(getSceneActor(scene,sceneActor));
|
||||||
Map<Integer, EffectBuffer> bufferMap = sceneActor.getBufferMap();
|
Map<Integer, EffectBuffer> bufferMap = sceneActor.getBufferMap();
|
||||||
Iterator<Map.Entry<Integer, EffectBuffer>> iterator = bufferMap.entrySet().iterator();
|
Iterator<Map.Entry<Integer, EffectBuffer>> iterator = bufferMap.entrySet().iterator();
|
||||||
while (iterator.hasNext()){
|
while (iterator.hasNext()){
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
|
||||||
|
@ -38,7 +39,41 @@ public class SceneManager {
|
||||||
private static Map<Integer, Scene> sceneMap = new HashMap<>();
|
private static Map<Integer, Scene> sceneMap = new HashMap<>();
|
||||||
private static Map<Integer, Scene> sceneByUidMap = new HashMap<>();
|
private static Map<Integer, Scene> sceneByUidMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static Map<Integer,Long> readyRunTaskMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static ScheduledThreadPoolExecutor scheduledExecutor=new ScheduledThreadPoolExecutor(8); //管理task
|
private static ScheduledThreadPoolExecutor scheduledExecutor=new ScheduledThreadPoolExecutor(8); //管理task
|
||||||
|
static {
|
||||||
|
scheduledExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true){
|
||||||
|
try {
|
||||||
|
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
|
||||||
|
if(sBloodyBattleSetting != null){
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
Iterator<Map.Entry<Integer, Long>> iterator = readyRunTaskMap.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()){
|
||||||
|
Map.Entry<Integer, Long> next = iterator.next();
|
||||||
|
Integer roomId = next.getKey();
|
||||||
|
Long time = next.getValue();
|
||||||
|
if(time - now > sBloodyBattleSetting.getReloadTime() * 1000){
|
||||||
|
iterator.remove();
|
||||||
|
Scene scene = sceneMap.get(roomId);
|
||||||
|
if(scene!=null){
|
||||||
|
startGame(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static BloodyMap bloodyMap;
|
public static BloodyMap bloodyMap;
|
||||||
public static Queue<List<Integer>> possibalePositions = new LinkedBlockingDeque<>();
|
public static Queue<List<Integer>> possibalePositions = new LinkedBlockingDeque<>();
|
||||||
|
@ -397,6 +432,10 @@ public class SceneManager {
|
||||||
|
|
||||||
|
|
||||||
public static void startGame(Scene scene) {
|
public static void startGame(Scene scene) {
|
||||||
|
synchronized (scene){
|
||||||
|
if(scene.getState() == 1){
|
||||||
|
return;
|
||||||
|
}
|
||||||
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
|
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
|
||||||
if(sceneActor.getType()== ActorType.Player){
|
if(sceneActor.getType()== ActorType.Player){
|
||||||
MessageUtil.sendRoomStartGameIndication(sceneActor.getId());
|
MessageUtil.sendRoomStartGameIndication(sceneActor.getId());
|
||||||
|
@ -408,6 +447,8 @@ public class SceneManager {
|
||||||
LOGGER.info("the roomid={},start battle pvp",scene.getRoomId());
|
LOGGER.info("the roomid={},start battle pvp",scene.getRoomId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void whenUserOffline(int uid){
|
public static void whenUserOffline(int uid){
|
||||||
Scene scene = sceneByUidMap.get(uid);
|
Scene scene = sceneByUidMap.get(uid);
|
||||||
|
@ -415,4 +456,24 @@ public class SceneManager {
|
||||||
scene.getSceneActorMap().get(uid).setGameState(StateType.UNREADY_STATE);
|
scene.getSceneActorMap().get(uid).setGameState(StateType.UNREADY_STATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static class ReadySceneTask{
|
||||||
|
private Scene scene;
|
||||||
|
private long startTime;
|
||||||
|
|
||||||
|
public ReadySceneTask(Scene scene, long startTime) {
|
||||||
|
this.scene = scene;
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scene getScene() {
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
|
||||||
}else{
|
}else{
|
||||||
analysisData.fail();
|
analysisData.fail();
|
||||||
}
|
}
|
||||||
|
analysis(scene,analysisData,analysisSourceData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,28 +38,21 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
|
||||||
String targetName = targetBloodySnpInfo.getName();
|
String targetName = targetBloodySnpInfo.getName();
|
||||||
String casterName = casterBloodySnpInfo.getName();
|
String casterName = casterBloodySnpInfo.getName();
|
||||||
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{targetName,casterName}));
|
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{targetName,casterName}));
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(sBloodyMessagesConfig.getType() == AnalysisDataType.CONTINUOUS_KILL_NUMS.getType()){
|
}
|
||||||
|
}
|
||||||
|
if(sBloodyMessagesConfig.getType() == AnalysisDataType.CONTINUOUS_KILL_NUMS.getType() || sBloodyMessagesConfig.getType() == AnalysisDataType.CONTINUOUS_DIED_NUMS.getType()){
|
||||||
if(targetAnalysisData.getContinuousKillNums() == count){
|
if(targetAnalysisData.getContinuousKillNums() == count){
|
||||||
int id = targetAnalysisData.getId();
|
int id = targetAnalysisData.getId();
|
||||||
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
|
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
|
||||||
String name = userBloodySnpInfo.getName();
|
String name = userBloodySnpInfo.getName();
|
||||||
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
|
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(sBloodyMessagesConfig.getType() == AnalysisDataType.CONTINUOUS_DIED_NUMS.getType()){
|
|
||||||
if(targetAnalysisData.getContinuousDeadNums() == count){
|
|
||||||
int id = targetAnalysisData.getId();
|
|
||||||
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
|
|
||||||
String name = userBloodySnpInfo.getName();
|
|
||||||
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sBloodyMessagesConfig.getType() == AnalysisDataType.END_CONTINUOUS_KILL_NUMS.getType()){
|
if(sBloodyMessagesConfig.getType() == AnalysisDataType.END_CONTINUOUS_KILL_NUMS.getType()){
|
||||||
int targetId = analysisSourceData.getTargetId();
|
int targetId = analysisSourceData.getTargetId();
|
||||||
int casterId = analysisSourceData.getCaster();
|
int casterId = analysisSourceData.getCaster();
|
||||||
|
@ -70,20 +64,22 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
|
||||||
String targetName = targetBloodySnpInfo.getName();
|
String targetName = targetBloodySnpInfo.getName();
|
||||||
String casterName = casterBloodySnpInfo.getName();
|
String casterName = casterBloodySnpInfo.getName();
|
||||||
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{targetName,casterName}));
|
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{targetName,casterName}));
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if(sBloodyMessagesConfig.getType() == AnalysisDataType.SEND_TO_DEATH.getType()){
|
if(sBloodyMessagesConfig.getType() == AnalysisDataType.SEND_TO_DEATH.getType()){
|
||||||
if(targetAnalysisData.getContinuousDeadNums() >= count){
|
if(targetAnalysisData.getContinuousDeadNums() >= count){
|
||||||
int id = targetAnalysisData.getId();
|
int id = targetAnalysisData.getId();
|
||||||
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
|
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
|
||||||
String name = userBloodySnpInfo.getName();
|
String name = userBloodySnpInfo.getName();
|
||||||
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
|
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,6 @@ public class MessageUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int indicationIndex = session.getIndicationIndex();
|
int indicationIndex = session.getIndicationIndex();
|
||||||
System.out.println("indicationIndex----"+indicationIndex);
|
|
||||||
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), indicationIndex,result, msgId, generatedMessage);
|
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), indicationIndex,result, msgId, generatedMessage);
|
||||||
if (flush) {
|
if (flush) {
|
||||||
session.writeAndFlush(byteBuf);
|
session.writeAndFlush(byteBuf);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.ljsd;
|
package com.ljsd;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.ljsd.jieling.config.CoreSettings;
|
import com.ljsd.jieling.config.CoreSettings;
|
||||||
|
import com.ljsd.jieling.config.ServerInfo;
|
||||||
|
import com.ljsd.jieling.redis.RedisKey;
|
||||||
import com.ljsd.jieling.redis.RedisUtil;
|
import com.ljsd.jieling.redis.RedisUtil;
|
||||||
import com.ljsd.jieling.thrift.RPCServerTask;
|
import com.ljsd.jieling.thrift.RPCServerTask;
|
||||||
import com.ljsd.jieling.thrift.pool.ThriftPoolUtils;
|
import com.ljsd.jieling.thrift.pool.ThriftPoolUtils;
|
||||||
|
@ -17,6 +20,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class MatchServerApplication {
|
public class MatchServerApplication {
|
||||||
public static int arenId = 0;
|
public static int arenId = 0;
|
||||||
|
private static Gson gson = new Gson();
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication springApplication = new SpringApplication(MatchServerApplication.class);
|
SpringApplication springApplication = new SpringApplication(MatchServerApplication.class);
|
||||||
springApplication.setRegisterShutdownHook(false);
|
springApplication.setRegisterShutdownHook(false);
|
||||||
|
@ -27,5 +31,17 @@ public class MatchServerApplication {
|
||||||
new RPCServerTask(configurableApplicationContext).start();
|
new RPCServerTask(configurableApplicationContext).start();
|
||||||
CoreSettings bean = configurableApplicationContext.getBean(CoreSettings.class);
|
CoreSettings bean = configurableApplicationContext.getBean(CoreSettings.class);
|
||||||
arenId = bean.getArea();
|
arenId = bean.getArea();
|
||||||
|
register(configurableApplicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void register(ConfigurableApplicationContext configurableApplicationContext){
|
||||||
|
CoreSettings coreSettings = configurableApplicationContext.getBean(CoreSettings.class);
|
||||||
|
String ip = coreSettings.getIp();
|
||||||
|
int port = coreSettings.getPort();
|
||||||
|
int area = coreSettings.getArea();
|
||||||
|
String rpcUrl = ip + ":" + port;
|
||||||
|
RedisUtil.getInstence().sadd(RedisKey.MATCH_SERVER_INFO + ":" + area,gson.toJson(rpcUrl));
|
||||||
|
RedisUtil.getInstence().set( RedisKey.MATCH_SIZE + ":" + area,Integer.toString(1));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ public class ServerInfo {
|
||||||
this.rpcUrl = rpcUrl;
|
this.rpcUrl = rpcUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerInfo(String rpcUrl) {
|
||||||
|
this.rpcUrl = rpcUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserSeeUrl() {
|
public String getUserSeeUrl() {
|
||||||
return userSeeUrl;
|
return userSeeUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class BloodyBattleReallyMatchServer implements IMatch{
|
||||||
/**
|
/**
|
||||||
* 每个人需要匹配到的玩家数量
|
* 每个人需要匹配到的玩家数量
|
||||||
*/
|
*/
|
||||||
private static int NEED_MATCH_PLAYER_COUNT = 0;
|
private static int NEED_MATCH_PLAYER_COUNT = 1;
|
||||||
/**
|
/**
|
||||||
* 匹配池
|
* 匹配池
|
||||||
*/
|
*/
|
||||||
|
@ -66,6 +66,7 @@ public class BloodyBattleReallyMatchServer implements IMatch{
|
||||||
LOGGER.info("执行匹配开始");
|
LOGGER.info("执行匹配开始");
|
||||||
try{
|
try{
|
||||||
//先把匹配池中的玩家按分数分布
|
//先把匹配池中的玩家按分数分布
|
||||||
|
NEED_MATCH_PLAYER_COUNT =Integer.parseInt(RedisUtil.getInstence().get(RedisKey.MATCH_SIZE + ":" + MatchServerApplication.arenId).toString());
|
||||||
TreeMap<Integer,HashSet<MatchPoolPlayerInfo>> pointMap = new TreeMap<Integer,HashSet<MatchPoolPlayerInfo>>();
|
TreeMap<Integer,HashSet<MatchPoolPlayerInfo>> pointMap = new TreeMap<Integer,HashSet<MatchPoolPlayerInfo>>();
|
||||||
for (MatchPoolPlayerInfo matchPlayer : playerPool.values()) {
|
for (MatchPoolPlayerInfo matchPlayer : playerPool.values()) {
|
||||||
//在匹配池中是时间太长,直接移除
|
//在匹配池中是时间太长,直接移除
|
||||||
|
|
|
@ -10,5 +10,7 @@ public class RedisKey {
|
||||||
public static final String BLOODY_ROOM_ADDRESS = "BLOODY_ROOM_ADDRESS"; //房间服务器地址信息
|
public static final String BLOODY_ROOM_ADDRESS = "BLOODY_ROOM_ADDRESS"; //房间服务器地址信息
|
||||||
public static final String USER_LOGIN_URL = "USER_LOGIN_URL"; //房间服务器地址信息
|
public static final String USER_LOGIN_URL = "USER_LOGIN_URL"; //房间服务器地址信息
|
||||||
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO"; //房间服务器地址信息
|
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO"; //房间服务器地址信息
|
||||||
|
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO"; //匹配服务器地址信息
|
||||||
|
public static final String MATCH_SIZE = "MATCH_SIZE"; //匹配人数设置
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,16 @@ public class RedisUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean sadd(String key,String member){
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForSet().add(key,member);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ljsd;
|
||||||
|
|
||||||
import com.ljsd.common.mogodb.util.MongoKeys;
|
import com.ljsd.common.mogodb.util.MongoKeys;
|
||||||
import com.ljsd.jieling.config.ServerConfig;
|
import com.ljsd.jieling.config.ServerConfig;
|
||||||
|
import com.ljsd.jieling.config.json.CoreSettings;
|
||||||
import com.ljsd.jieling.config.json.ServerConfiguration;
|
import com.ljsd.jieling.config.json.ServerConfiguration;
|
||||||
import com.ljsd.jieling.config.json.ServerProperties;
|
import com.ljsd.jieling.config.json.ServerProperties;
|
||||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||||
|
@ -66,7 +67,8 @@ public class GameApplication {
|
||||||
ServerConfiguration serverConfiguration = configurableApplicationContext.getBean(ServerConfiguration.class);
|
ServerConfiguration serverConfiguration = configurableApplicationContext.getBean(ServerConfiguration.class);
|
||||||
serverProperties = serverConfiguration.getServerProperties();
|
serverProperties = serverConfiguration.getServerProperties();
|
||||||
serverId = serverProperties.getId();
|
serverId = serverProperties.getId();
|
||||||
areaId = serverProperties.getId();
|
CoreSettings coreSettings = configurableApplicationContext.getBean(CoreSettings.class);
|
||||||
|
GameApplication.areaId = coreSettings.getArea();
|
||||||
LOGGER.info("ServerProperties ->{},coreIp=>{}", serverProperties.toString());
|
LOGGER.info("ServerProperties ->{},coreIp=>{}", serverProperties.toString());
|
||||||
RedisUtil.getInstence().init(configurableApplicationContext);
|
RedisUtil.getInstence().init(configurableApplicationContext);
|
||||||
MongoUtil.getInstence().init(configurableApplicationContext);
|
MongoUtil.getInstence().init(configurableApplicationContext);
|
||||||
|
|
|
@ -85,6 +85,8 @@ public class SBloodyBattleSetting implements BaseConfig {
|
||||||
|
|
||||||
private int[][] scoreConversion;
|
private int[][] scoreConversion;
|
||||||
|
|
||||||
|
private int reloadTime;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
|
@ -292,4 +294,8 @@ public class SBloodyBattleSetting implements BaseConfig {
|
||||||
public int[][] getScoreConversion() {
|
public int[][] getScoreConversion() {
|
||||||
return scoreConversion;
|
return scoreConversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getReloadTime() {
|
||||||
|
return reloadTime;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -166,6 +166,7 @@ public class RedisKey {
|
||||||
public static final String BLOODY_TEAM = "BLOODY_TEAM";
|
public static final String BLOODY_TEAM = "BLOODY_TEAM";
|
||||||
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
|
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
|
||||||
public static final String BLOODY_PERSON_BATTLE_INFO = "BLOODY_PERSON_BATTLE_INFO";
|
public static final String BLOODY_PERSON_BATTLE_INFO = "BLOODY_PERSON_BATTLE_INFO";
|
||||||
|
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO";
|
||||||
|
|
||||||
public static String getKey(String type, String key, boolean withoutServerId) {
|
public static String getKey(String type, String key, boolean withoutServerId) {
|
||||||
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){
|
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){
|
||||||
|
|
|
@ -876,6 +876,26 @@ public class RedisUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getAllSetToList(String key, Class<T> clazz){
|
||||||
|
for(int i=0;i<MAX_TRY_TIMES;i++){
|
||||||
|
try {
|
||||||
|
|
||||||
|
Set<String> members = redisTemplate.opsForSet().members(key);
|
||||||
|
if(members!=null && !members.isEmpty()){
|
||||||
|
List<T> result = new ArrayList<>(members.size());
|
||||||
|
for(String item : members){
|
||||||
|
result.add(gson.fromJson(item,clazz));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TimeUtils.sleep(FAILED_SLEEP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public boolean sremove(String key,String member){
|
public boolean sremove(String key,String member){
|
||||||
try {
|
try {
|
||||||
redisTemplate.opsForSet().remove(key,member);
|
redisTemplate.opsForSet().remove(key,member);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ljsd.jieling.handler.room;
|
package com.ljsd.jieling.handler.room;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.ljsd.GameApplication;
|
||||||
import com.ljsd.jieling.bloody.UserBloodySnpInfo;
|
import com.ljsd.jieling.bloody.UserBloodySnpInfo;
|
||||||
import com.ljsd.jieling.config.SBloodyBattleSetting;
|
import com.ljsd.jieling.config.SBloodyBattleSetting;
|
||||||
import com.ljsd.jieling.core.GlobalsDef;
|
import com.ljsd.jieling.core.GlobalsDef;
|
||||||
|
@ -22,11 +23,13 @@ import com.ljsd.jieling.network.session.ISession;
|
||||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
import com.ljsd.jieling.protocols.RoomProto;
|
import com.ljsd.jieling.protocols.RoomProto;
|
||||||
import com.ljsd.jieling.thrift.pool.ServiceKey;
|
import com.ljsd.jieling.thrift.pool.ServiceKey;
|
||||||
|
import com.ljsd.jieling.util.MathUtils;
|
||||||
import com.ljsd.jieling.util.MessageUtil;
|
import com.ljsd.jieling.util.MessageUtil;
|
||||||
import com.ljsd.jieling.util.StringUtil;
|
import com.ljsd.jieling.util.StringUtil;
|
||||||
import com.ljsd.jieling.util.TimeUtils;
|
import com.ljsd.jieling.util.TimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.mongodb.monitor.ServerInfo;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -73,7 +76,16 @@ public class RoomMatchRequestHandler extends BaseHandler{
|
||||||
User user = UserManager.getUser(iSession.getUid());
|
User user = UserManager.getUser(iSession.getUid());
|
||||||
snapUserFightInfo(user);
|
snapUserFightInfo(user);
|
||||||
RedisUtil.getInstence().set(RedisKey.MATCH_UID_KEY + ":" + uid,gson.toJson("1"));
|
RedisUtil.getInstence().set(RedisKey.MATCH_UID_KEY + ":" + uid,gson.toJson("1"));
|
||||||
String serviceKey =StringUtil.getServiceKey(ServiceKey.RPCMATCH,"60.1.1.215","17900");
|
List<String> matchAddressInfos = RedisUtil.getInstence().getAllSetToList(RedisKey.MATCH_SERVER_INFO + ":" + GameApplication.areaId, String.class);
|
||||||
|
if(matchAddressInfos == null || matchAddressInfos.isEmpty()){
|
||||||
|
LOGGER.error("没有匹配服务器");
|
||||||
|
MessageUtil.sendErrorResponse(iSession,0,responseMsgId,"没有匹配服务器");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String rpcUrl = matchAddressInfos.get(MathUtils.randomInt(matchAddressInfos.size()));
|
||||||
|
String ip = rpcUrl.split(":")[0];
|
||||||
|
String port = rpcUrl.split(":")[1];
|
||||||
|
String serviceKey =StringUtil.getServiceKey(ServiceKey.RPCMATCH,ip,port);
|
||||||
ClientAdapterPo<RPCMatchRequestIFace.Client> rPCClient = null;
|
ClientAdapterPo<RPCMatchRequestIFace.Client> rPCClient = null;
|
||||||
try {
|
try {
|
||||||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||||
|
@ -93,8 +105,8 @@ public class RoomMatchRequestHandler extends BaseHandler{
|
||||||
|
|
||||||
public static void snapUserFightInfo(User mine){
|
public static void snapUserFightInfo(User mine){
|
||||||
//血量处理
|
//血量处理
|
||||||
// int myteamId = GlobalsDef.BLOODY_TEAM;
|
int myteamId = GlobalsDef.BLOODY_TEAM;
|
||||||
int myteamId = 1;
|
|
||||||
mine.getTeamPosManager().setCurTeamPosId(myteamId);
|
mine.getTeamPosManager().setCurTeamPosId(myteamId);
|
||||||
PlayerManager playerInfoManager = mine.getPlayerInfoManager();
|
PlayerManager playerInfoManager = mine.getPlayerInfoManager();
|
||||||
UserBloodySnpInfo userBloodySnpInfo = new UserBloodySnpInfo(mine.getId(),playerInfoManager.getNickName());
|
UserBloodySnpInfo userBloodySnpInfo = new UserBloodySnpInfo(mine.getId(),playerInfoManager.getNickName());
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ljsd.jieling.thread.task;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.ljsd.CoreService;
|
import com.ljsd.CoreService;
|
||||||
|
import com.ljsd.GameApplication;
|
||||||
import com.ljsd.jieling.config.json.CoreSettings;
|
import com.ljsd.jieling.config.json.CoreSettings;
|
||||||
import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
|
import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
|
||||||
import org.apache.thrift.TProcessor;
|
import org.apache.thrift.TProcessor;
|
||||||
|
|
Loading…
Reference in New Issue