lvxinran 2019-09-11 22:21:06 +08:00
commit acbbc8ee4f
35 changed files with 6546 additions and 2173 deletions

View File

@ -5,6 +5,9 @@ package com.ljsd.battle.actor;
import com.ljsd.battle.BattleRequest;
import com.ljsd.battle.room.SceneManager;
import com.ljsd.battle.statics.AnalysisEventType;
import com.ljsd.battle.statics.AnalysisSourceData;
import com.ljsd.battle.statics.MessageBoxUtils;
import com.ljsd.jieling.config.SChallengeMapConfig;
import com.ljsd.jieling.util.CellUtil;
@ -47,6 +50,7 @@ public abstract class Creature extends SceneActor{
public void costMineral(int mineral) {
this.mineral -= mineral;
MessageBoxUtils.onGameEvent(AnalysisEventType.DIGGER_NUMS,getScene(),new AnalysisSourceData(this.getId(),-1,mineral));
}
public void tick(){
@ -55,6 +59,7 @@ public abstract class Creature extends SceneActor{
public void addMineral(int mineral) {
this.mineral += mineral;
MessageBoxUtils.onGameEvent(AnalysisEventType.DIGGER_NUMS,getScene(),new AnalysisSourceData(this.getId(),1,this.mineral));
}
public void exec(int tyep, Object parm){
@ -181,7 +186,6 @@ public abstract class Creature extends SceneActor{
if(update){
path.clear();
getScene().processEventUpdate(EventType.SCENEACTORE_UPDATE,this.getId());
System.out.println("can not move next" + getId() + " hit the " + sceneActor.getId());
}
return false;

View File

@ -20,6 +20,8 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.SceneFight;
import com.ljsd.network.session.ISession;
import com.ljsd.network.session.OnlineUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
@ -27,7 +29,7 @@ import java.util.concurrent.*;
public class Scene implements Runnable{
private static final Logger LOGGER = LoggerFactory.getLogger(Scene.class);
private List<FutureResult> futureList = new ArrayList<>();
public static ExecutorService executorService = Executors.newFixedThreadPool(32);
private int roomId;
@ -51,6 +53,11 @@ public class Scene implements Runnable{
private Map<Integer, AnalysisData> analysisDataMap = new HashMap<>();
public AnalysisData getAnalysisData(int id){
return analysisDataMap.get(id);
}
public void randomMineralOfUserDeath(Creature creature,int totalMineal){
if(totalMineal <=0){
return;
@ -115,6 +122,16 @@ public class Scene implements Runnable{
private List<String> cacheMsg = new ArrayList<>(2);
private int quickEnd = -1; //快速结束时间
private int quickPlayId = 0;//快速结束玩家uid
private Set<Integer> possibaleQuickUids = new HashSet<>();
public void addQuickPossibalePlays(int quickPlayId){
possibaleQuickUids.add(quickPlayId);
}
public void monsterReflush(){
Iterator<Map.Entry<Integer, Integer>> iterator = monsterRecoryMap.entrySet().iterator();
@ -123,18 +140,14 @@ public class Scene implements Runnable{
Integer value = next.getValue();
if(tick>value){
Integer monsterIndex = next.getKey();
System.out.println("the actor siz=" + sceneActorMap.size());
SceneManager.createMonster(this,monsterIndex);
processEventUpdate(EventType.SCENEACTORE_UPDATE,monsterIndex);
iterator.remove();
System.out.println("the actor after siz=" + sceneActorMap.size());
System.out.println("the monsterid={}" + monsterIndex + "recovery");
}
}
}
public void whenMonsterDead(int deadId){
System.out.println("the monster deadID="+deadId);
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
int[] monsterItem = sBloodyBattleSetting.getMonsterIndexMap().get(deadId);
monsterRecoryMap.put(deadId,monsterItem[1]*20 + tick);
@ -146,6 +159,31 @@ public class Scene implements Runnable{
}
public void checkNeedRestartQuickEnd(){
if(possibaleQuickUids.isEmpty()){
return;
}
int[] settleTime = SBloodyBattleSetting.sBloodyBattleSetting.getSettleTime();
int endTick = settleTime[1]*20 + tick;
if(endTick>SceneManager.bloodyMap.getEndRound()){
return;
}
for( Integer possibaleQuickUid : possibaleQuickUids){
if(quickPlayId!=0 || quickPlayId == possibaleQuickUid){
continue;
}
SceneActor sceneActor = sceneActorMap.get(possibaleQuickUid);
Creature creature = (Creature)sceneActor;
if(creature.getMineral()>settleTime[0]){
startQuickTime(possibaleQuickUid,endTick);
break;
}
}
possibaleQuickUids.clear();
}
public void tick() throws InterruptedException {
Iterator<Map.Entry<Integer, SceneActor>> iterator = sceneActorMap.entrySet().iterator();
while (iterator.hasNext()){
@ -157,12 +195,12 @@ public class Scene implements Runnable{
if(msgUpdate || !cacheMsg.isEmpty()){
for(Integer removeId : builder.getRemoveActorIdList()){
sceneActorMap.remove(removeId);
System.out.println("remove the id=------------" + removeId);
}
checkNeedRestartQuickEnd();
for(SceneActor sceneActor : sceneActorMap.values()){
if(sceneActor.getType() != ActorType.Npc){
if(willUpdateActors.contains(sceneActor.getId())){
builder.addSceneActor(BeanToProto.getSceneActor(sceneActor));
builder.addSceneActor(BeanToProto.getSceneActor(this,sceneActor));
}
}
}
@ -198,7 +236,6 @@ public class Scene implements Runnable{
*/
public void processEventUpdate(EventType eventType,Object parm){
msgUpdate = true;
System.out.println("the eventType = "+ eventType);
switch (eventType){
case SCENEACTORE_UPDATE:
willUpdateActors.add((int)parm);
@ -213,7 +250,6 @@ public class Scene implements Runnable{
case SCENEACTORE_REMOVE:
int deadId = (int) parm;
builder.addRemoveActorId(deadId);
System.out.println("remove the scene id is " + deadId);
break;
case POSMINERAL_REMOVE:
builder.addRemovePosMineralId( (int) parm);
@ -235,7 +271,11 @@ public class Scene implements Runnable{
if(isEnd){
break;
}
tick++;
if(checkIsEnd()){
break;
}
sysTick();
tick();
if(tick/20 == 1 && tick%20==0){
@ -248,6 +288,14 @@ public class Scene implements Runnable{
}
public boolean checkIsEnd(){
if(tick> SceneManager.bloodyMap.getEndRound() || (quickEnd!=-1 && tick>quickEnd)){
gameEnd();
return true;
}
return false;
}
public void startAllRunning(){
for(SceneActor sceneActor : sceneActorMap.values()){
if(sceneActor.getType()== ActorType.Player){
@ -294,7 +342,6 @@ public class Scene implements Runnable{
needAdd = flushNums;
}
SceneManager.createMinear(this,size,needAdd);
System.out.println("创建矿....");
}
}
@ -305,7 +352,7 @@ public class Scene implements Runnable{
//退出操作
public void gameEnd() {
System.out.println("game ending....");
LOGGER.info("the roomId={} is gameEnding" ,roomId);
isEnd = true;
//结算操作
List<SortDataBean> sortDataBeans = new ArrayList<>();
@ -363,7 +410,6 @@ public class Scene implements Runnable{
executorService.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
System.out.println("exce com.ljsd.battle...............................");
SceneActor attackActor = battleRequest.getAttackActor();
SceneActor defActor = battleRequest.getDefActor();
SceneActor temp = null;
@ -393,8 +439,6 @@ public class Scene implements Runnable{
effectBuffer.clearvalues();
effectBuffer.addEffectValue(checkResult[0]);
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
System.out.println(effectBuffer);
System.out.println(attackActor.getId());
}
}
Map<Integer, EffectBuffer> defBufferMap = defActor.getBufferMap();
@ -403,8 +447,6 @@ public class Scene implements Runnable{
effectBuffer.clearvalues();
effectBuffer.addEffectValue(checkResult[0]==1?0:1);
effectBuffer.setEndTime(effectBuffer.getStartTime() + displayTime *1000);
System.out.println(effectBuffer);
}
}
return 1;
@ -465,4 +507,24 @@ public class Scene implements Runnable{
public void addCahceBroadMsg(String msg){
cacheMsg.add(msg);
}
public int getQuickEnd() {
return quickEnd;
}
public int getQuickPlayId() {
return quickPlayId;
}
public void startQuickTime(int quickPlayId,int quickEnd){
this.quickPlayId = quickPlayId;
this.quickEnd = quickEnd;
addCahceBroadMsg("进入游戏狂欢时刻,剩余" + (quickEnd-tick)/20 + "秒");
}
public void clearQuickTime(){
this.quickEnd = -1;
this.quickPlayId = 0;
}
}

View File

@ -165,8 +165,9 @@ public abstract class SceneActor{
// 定位到出生点位置
this.setPos(SceneManager.selectForPlayerRebirth(scene));
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,id);
MessageBoxUtils.onGameEvent(AnalysisEventType.BATTLE,scene,new AnalysisSourceData(value.getTarget(),value.getCaster(),effectValue));
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));
}
}else{
Creature creature = (Creature) scene.getSceneActorMap().get(value.getCaster());
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));
}
stateType = StateType.MOVEABLE;
@ -192,13 +193,15 @@ public abstract class SceneActor{
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,this.getId());
}
}else if(type == BufferType.REBIRTH.getType()){
Creature creature = (Creature) this;
if(getType() == ActorType.Monster){
Creature creature = (Creature) this;
creature.setPreMoveTimestamp(now);
}
stateType = StateType.MOVEABLE;
if(getType() == ActorType.Player){
//如果是玩家获得无敌buffer
creature.getLife().setCurHp(creature.getLife().getMaxMp());
addOrUpdateBuffer(new EffectBuffer(scene.getBufferId(),BufferType.INVINCIBLE.getType(),now,now+SBloodyBattleSetting.sBloodyBattleSetting.getInvincible(),id,id,-1));
stateType=StateType.INVINCIBLE;
}

View File

@ -53,13 +53,13 @@ public class BattleManager {
if(resultCode == 1){
rebirth(blueUserBloodySnpInfo);
blueCreature.setLife(new Life(blueCreature.getLife().getMaxMp(),blueCreature.getLife().getMaxMp()));
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult,redCreature);
return checkResult;
}
rebirth(redUserBloodySnpInfo);
redCreature.setLife(new Life(redCreature.getLife().getMaxMp(),redCreature.getLife().getMaxMp()));
afterBattleRecord(blueUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(blueUserBloodySnpInfo.getHeroAllAttributes(),checkResult,blueCreature);
return checkResult;
}
@ -82,7 +82,7 @@ public class BattleManager {
int[] checkResult = CheckFight.getInstance().checkFight(seed, SArenaSetting.getSArenaSetting().getMostTime(), getFightData, getOptionData, FightType.BloodyFight);
int resultCode = checkResult[0];
if(resultCode == 1){
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult,creature);
return checkResult;
}
rebirth(redUserBloodySnpInfo);
@ -106,15 +106,18 @@ public class BattleManager {
//战斗之后血量计算
public static Map<String, FamilyHeroInfo> afterBattleRecord(Map<String, FamilyHeroInfo> heroAttribute,int[] fightResult){
public static Map<String, FamilyHeroInfo> afterBattleRecord(Map<String, FamilyHeroInfo> heroAttribute,int[] fightResult,Creature creature){
int index = 2;
int remainHp = 0;
for (Map.Entry<String, FamilyHeroInfo> entry : heroAttribute.entrySet()) {
FamilyHeroInfo value = entry.getValue();
Map<Integer, Integer> attribute = value.getAttribute();
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), fightResult[index]);
value.setAttribute(attribute);
index++;
remainHp+=attribute.get(HeroAttributeEnum.CurHP.getPropertyId());
}
creature.getLife().setCurHp(remainHp);
return heroAttribute;
}
@ -126,6 +129,7 @@ public class BattleManager {
Integer maxHp = familyHeroInfo.getAttribute().get(HeroAttributeEnum.Hp.getPropertyId());
familyHeroInfo.getAttribute().put(HeroAttributeEnum.CurHP.getPropertyId(),maxHp);
}
}

View File

@ -1,11 +1,13 @@
package com.ljsd.battle.room;
import com.ljsd.battle.manager.BattleManager;
import com.ljsd.battle.statics.AnalysisData;
import com.ljsd.battle.vo.UserBloodySnpInfo;
import com.ljsd.battle.actor.*;
import com.ljsd.battle.vo.FamilyHeroInfo;
import com.ljsd.battle.vo.HeroAttributeEnum;
import com.ljsd.jieling.config.SBloodyBattleSetting;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.RoomProto;
@ -14,7 +16,7 @@ import java.util.Map;
public class BeanToProto {
public static CommonProto.SceneActor getSceneActor(SceneActor sceneActor){
public static CommonProto.SceneActor getSceneActor(Scene scene,SceneActor sceneActor){
ActorType actorType = sceneActor.getType();
CommonProto.SceneActor.Builder builder = CommonProto.SceneActor.newBuilder()
.setId(sceneActor.getId())
@ -22,7 +24,7 @@ public class BeanToProto {
.setType(actorType.getStateCode())
.setState(sceneActor.getStateType().getState());
if(actorType != ActorType.Npc){
builder.setCreature(getCreature((Creature)sceneActor));
builder.setCreature(getCreature(scene,(Creature)sceneActor));
}
if(actorType == ActorType.Player){
builder.setUserName(BattleManager.bloodMyHeroInfoMap.get(sceneActor.getId()).getName());
@ -30,7 +32,7 @@ public class BeanToProto {
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();
if(creature.getType() == ActorType.Player){
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(creature.getId());
@ -43,6 +45,8 @@ public class BeanToProto {
Integer curHp = attribute.get(HeroAttributeEnum.CurHP.getPropertyId());
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){
builder.addAllPath(creature.getPath());
@ -50,7 +54,6 @@ public class BeanToProto {
return builder.setCurHp(creature.getLife().getCurHp())
.setMaxHp(creature.getLife().getMaxMp())
.setSpeed(creature.getSpeed())
.setCamp(creature.getCamp())
.setMineral(creature.getMineral())
.build();
@ -77,7 +80,7 @@ public class BeanToProto {
CommonProto.SceneInfo.Builder builder = CommonProto.SceneInfo.newBuilder().setMapId(scene.getMapId());
Map<Integer, SceneActor> sceneActorMap = scene.getSceneActorMap();
for(SceneActor sceneActor : sceneActorMap.values()){
builder.addSceneActor(getSceneActor(sceneActor));
builder.addSceneActor(getSceneActor(scene,sceneActor));
Map<Integer, EffectBuffer> bufferMap = sceneActor.getBufferMap();
Iterator<Map.Entry<Integer, EffectBuffer>> iterator = bufferMap.entrySet().iterator();
while (iterator.hasNext()){
@ -91,6 +94,13 @@ public class BeanToProto {
Integer value = item.getValue();
builder.addPosMineral(CommonProto.PosMineral.newBuilder().setPos(key).setNums(value).build());
}
long endTime = SBloodyBattleSetting.sBloodyBattleSetting.getBattleTime();
if(scene.getQuickEnd()!=-1){
long startTime = scene.getStartTime();
endTime = startTime + scene.getQuickEnd()*50;
}
int remainTime = SBloodyBattleSetting.sBloodyBattleSetting.getBattleTime() - (int)((System.currentTimeMillis() - scene.getStartTime()) / 1000);
builder.setRemainTime(remainTime);
builder.addAllBarrierPoint(SceneManager.bloodyMap.getBarrierPoints());
return builder.build();
}

View File

@ -10,6 +10,8 @@ public class BloodyMap {
private int round;
private int endRound;
public BloodyMap(int mapId) {
this.mapId = mapId;
}
@ -35,4 +37,12 @@ public class BloodyMap {
public void setRound(int round) {
this.round = round;
}
public int getEndRound() {
return endRound;
}
public void setEndRound(int endRound) {
this.endRound = endRound;
}
}

View File

@ -24,18 +24,56 @@ import com.ljsd.jieling.util.CellUtil;
import com.ljsd.jieling.util.MathUtils;
import com.ljsd.jieling.util.MonsterUtil;
import com.ljsd.network.session.ISession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledThreadPoolExecutor;
public class SceneManager {
private static final Logger LOGGER = LoggerFactory.getLogger(SceneManager.class);
private static Map<Integer, Scene> sceneMap = 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
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 Queue<List<Integer>> possibalePositions = new LinkedBlockingDeque<>();
@ -69,6 +107,7 @@ public class SceneManager {
}
bloodyMapTmp.setRound(max*20);
bloodyMapTmp.setEndRound(SBloodyBattleSetting.sBloodyBattleSetting.getBattleTime()*20);
bloodyMap = bloodyMapTmp;
calPossiblePoss();
@ -106,7 +145,7 @@ public class SceneManager {
createMonster(scene,-1);
sceneMap.put(room.getId(),scene);
System.out.println("create romm --- -"+room.getId());
}
public static void createMonster(Scene scene, int target) {
@ -149,8 +188,8 @@ public class SceneManager {
scene.addScenActor(sceneMonster);
monsterIndex++;
if(target!=-1){
System.out.println("find and break... " + monsterIndex);
break;
LOGGER.info("the roomId = {},the new monsterIndex={} " ,scene.getRoomId(), monsterIndex);
break;
}
}
}
@ -159,7 +198,7 @@ public class SceneManager {
public static void createMinear(Scene scene,int target,int nums){
//创建矿
System.out.println("target--" + target + "-- nums --" + nums);
LOGGER.info("the roomId = {},the mineral target ={},the nums = {} " ,scene.getRoomId(), target,nums);
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
Map<Integer, Integer> initializeMineMap = sBloodyBattleSetting.getInitializeMineMap();
Map<Integer, SCMap> scMap = SCMap.sCMap.get(bloodyMap.getMapId());
@ -167,7 +206,6 @@ public class SceneManager {
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
excluIndexs.add(sceneActor.getPos());
}
System.out.println(excluIndexs);
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
int event = scMap1.getEvent();
@ -184,10 +222,17 @@ public class SceneManager {
Set<Integer> cacheRemove = new HashSet<>();
while (nums -- >0){
int index = MathUtils.randomWeight(groups, randomIndex);
if(index == -1){
cacheRemove.add(index);
break;
}
int pos = CellUtil.xy2Pos(groups[index][0], groups[index][1]);
while(excluIndexs.contains(pos)){
cacheRemove.add(index);
index = MathUtils.randomWeight(groups, randomIndex);
if(index == -1){
break;
}
pos = CellUtil.xy2Pos(groups[index][0], groups[index][1]);
}
excluIndexs.add(pos);
@ -260,6 +305,10 @@ public class SceneManager {
Set<Integer> removeIndexs = new HashSet<>();
while (true){
int index= MathUtils.randomWeight(points,randomIndexs);
if(index ==-1){
removeIndexs.add(index);
break;
}
Set<Integer> cache = new HashSet<>();
int[] possiblePoint = points[index];
if( !CellUtil.calSurPos(possiblePoint[0],possiblePoint[1],sBloodyBattleSetting.getPointInterval(),maxX,maxY,cache) ){
@ -384,15 +433,21 @@ public class SceneManager {
public static void startGame(Scene scene) {
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
if(sceneActor.getType()== ActorType.Player){
MessageUtil.sendRoomStartGameIndication(sceneActor.getId());
synchronized (scene){
if(scene.getState() == 1){
return;
}
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
if(sceneActor.getType()== ActorType.Player){
MessageUtil.sendRoomStartGameIndication(sceneActor.getId());
}
}
scene.setState(1);
scene.setStartTime(System.currentTimeMillis());
scheduledExecutor.execute(scene);
LOGGER.info("the roomid={},start battle pvp",scene.getRoomId());
}
scene.setState(1);
scene.setStartTime(System.currentTimeMillis());
scheduledExecutor.execute(scene);
System.out.println("start com.ljsd.battle pvp...........................");
}
@ -402,4 +457,24 @@ public class SceneManager {
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;
}
}
}

View File

@ -3,6 +3,7 @@ package com.ljsd.battle.statics;
public enum AnalysisEventType {
BATTLE,
DIGGER,
DIGGER_NUMS,
}

View File

@ -18,6 +18,7 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
}else{
analysisData.fail();
}
analysis(scene,analysisData,analysisSourceData);
}
@ -37,28 +38,21 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
String targetName = targetBloodySnpInfo.getName();
String casterName = casterBloodySnpInfo.getName();
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){
int id = targetAnalysisData.getId();
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
String name = userBloodySnpInfo.getName();
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()){
int targetId = analysisSourceData.getTargetId();
int casterId = analysisSourceData.getCaster();
@ -70,8 +64,9 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
String targetName = targetBloodySnpInfo.getName();
String casterName = casterBloodySnpInfo.getName();
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{targetName,casterName}));
return;
}
return;
}
if(sBloodyMessagesConfig.getType() == AnalysisDataType.SEND_TO_DEATH.getType()){
if(targetAnalysisData.getContinuousDeadNums() >= count){
@ -79,8 +74,9 @@ public class BattleAnalysisProcessor implements AnalysisProcessor{
UserBloodySnpInfo userBloodySnpInfo = BattleManager.bloodMyHeroInfoMap.get(id);
String name = userBloodySnpInfo.getName();
scene.addCahceBroadMsg(MessageFormat.format(sBloodyMessagesConfig.getMessage(),new String[]{name}));
return;
}
return;
}
}

View File

@ -19,6 +19,7 @@ public class MessageBoxUtils {
//更新统计数据 数据汇总聚合
analysisEventTypeIntegerMap.put(AnalysisEventType.BATTLE,new BattleAnalysisProcessor());
analysisEventTypeIntegerMap.put(AnalysisEventType.DIGGER,new DiggerAnalysisProcessor());
analysisEventTypeIntegerMap.put(AnalysisEventType.DIGGER_NUMS,new MineralNumsAnalysisProcessor());
}
public static void init(){

View File

@ -0,0 +1,22 @@
package com.ljsd.battle.statics;
import com.ljsd.battle.actor.Scene;
import com.ljsd.jieling.config.SBloodyBattleSetting;
public class MineralNumsAnalysisProcessor implements AnalysisProcessor{
@Override
public void process(Scene scene, AnalysisSourceData analysisSourceData) {
int targetId = analysisSourceData.getTargetId();
int caster = analysisSourceData.getCaster();
int value = analysisSourceData.getValue();
int[] settleTime = SBloodyBattleSetting.sBloodyBattleSetting.getSettleTime();
int quickPlayId = scene.getQuickPlayId();
if(quickPlayId == targetId && caster == -1 && value<settleTime[0]){
scene.clearQuickTime();
}
if(quickPlayId != targetId && caster == 1 && value >= settleTime[0]){
scene.addQuickPossibalePlays(targetId);
}
}
}

View File

@ -95,7 +95,6 @@ public class MessageUtil {
return;
}
int indicationIndex = session.getIndicationIndex();
System.out.println("indicationIndex----"+indicationIndex);
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), indicationIndex,result, msgId, generatedMessage);
if (flush) {
session.writeAndFlush(byteBuf);

View File

@ -0,0 +1,56 @@
# redis config
# Redis数据库索引默认为0
spring.redis.database=2
#spring.redis.database=2
# Redis服务器地址
spring.redis.host=60.1.1.21
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=0
spring.data.mongodb.uri = mongodb://60.1.1.14:27017/jieling_50215_99991
#spring.data.mongodb.uri = mongodb://60.1.1.14:27017/jieling_10212
mongodb.options.maxWaitTime = 120000
mongodb.options.connectTimeout = 1000
mongodb.options.socketTimeout = 0
mongodb.options.threadsAllowedToBlockForConnectionMultiplier = 20
mongodb.options.connectionsPerHost = 256
mongodb.options.minConnectionsPerHost = 5
mongodb.options.maxConnectionIdleTime = 1000
netty.tcpPort = 36080
netty.tcpIp = 60.1.1.215
netty.reconnectDelay=3000
netty.bossThreadCount=1
netty.workerThreadCount=10
netty.readTimeout=32
netty.writeTimeout=32
netty.allTimeout=35
#core
services.core.ip=60.1.1.215
services.core.port=27900
services.core.area=1000
services.core.id=1
services.core.weight=5
logging.config = conf/logback-boot.xml

View File

@ -0,0 +1,37 @@
# redis config
# Redis数据库索引默认为0
spring.redis.database=2
#spring.redis.database=2
# Redis服务器地址
spring.redis.host=60.1.1.21
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=0
#core
services.core.ip=60.1.1.215
services.core.port=17900
services.core.area=1000
services.core.id=1
services.core.weight=5
logging.config = conf/logback-boot.xml

View File

@ -1,6 +1,9 @@
package com.ljsd;
import com.google.gson.Gson;
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.thrift.RPCServerTask;
import com.ljsd.jieling.thrift.pool.ThriftPoolUtils;
@ -17,6 +20,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
public class MatchServerApplication {
public static int arenId = 0;
private static Gson gson = new Gson();
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(MatchServerApplication.class);
springApplication.setRegisterShutdownHook(false);
@ -27,5 +31,17 @@ public class MatchServerApplication {
new RPCServerTask(configurableApplicationContext).start();
CoreSettings bean = configurableApplicationContext.getBean(CoreSettings.class);
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));
}
}

View File

@ -14,6 +14,10 @@ public class ServerInfo {
this.rpcUrl = rpcUrl;
}
public ServerInfo(String rpcUrl) {
this.rpcUrl = rpcUrl;
}
public String getUserSeeUrl() {
return userSeeUrl;
}

View File

@ -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("执行匹配开始");
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>>();
for (MatchPoolPlayerInfo matchPlayer : playerPool.values()) {
//在匹配池中是时间太长,直接移除

View File

@ -10,5 +10,7 @@ public class RedisKey {
public static final String BLOODY_ROOM_ADDRESS = "BLOODY_ROOM_ADDRESS"; //房间服务器地址信息
public static final String USER_LOGIN_URL = "USER_LOGIN_URL"; //房间服务器地址信息
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"; //匹配人数设置
}

View File

@ -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;
}
}

View File

@ -2,6 +2,7 @@ package com.ljsd;
import com.ljsd.common.mogodb.util.MongoKeys;
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.ServerProperties;
import com.ljsd.jieling.db.mongo.MongoUtil;
@ -67,7 +68,8 @@ public class GameApplication {
ServerConfiguration serverConfiguration = configurableApplicationContext.getBean(ServerConfiguration.class);
serverProperties = serverConfiguration.getServerProperties();
serverId = serverProperties.getId();
areaId = serverProperties.getId();
CoreSettings coreSettings = configurableApplicationContext.getBean(CoreSettings.class);
GameApplication.areaId = coreSettings.getArea();
LOGGER.info("ServerProperties ->{},coreIp=>{}", serverProperties.toString());
RedisUtil.getInstence().init(configurableApplicationContext);
MongoUtil.getInstence().init(configurableApplicationContext);

View File

@ -85,6 +85,8 @@ public class SBloodyBattleSetting implements BaseConfig {
private int[][] scoreConversion;
private int reloadTime;
@Override
public void init() throws Exception {
@ -292,4 +294,8 @@ public class SBloodyBattleSetting implements BaseConfig {
public int[][] getScoreConversion() {
return scoreConversion;
}
public int getReloadTime() {
return reloadTime;
}
}

View File

@ -166,6 +166,7 @@ public class RedisKey {
public static final String BLOODY_TEAM = "BLOODY_TEAM";
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 MATCH_SERVER_INFO = "MATCH_SERVER_INFO";
public static String getKey(String type, String key, boolean withoutServerId) {
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)){

View File

@ -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){
try {
redisTemplate.opsForSet().remove(key,member);

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.handler.room;
import com.google.gson.Gson;
import com.ljsd.GameApplication;
import com.ljsd.jieling.bloody.UserBloodySnpInfo;
import com.ljsd.jieling.config.SBloodyBattleSetting;
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.RoomProto;
import com.ljsd.jieling.thrift.pool.ServiceKey;
import com.ljsd.jieling.util.MathUtils;
import com.ljsd.jieling.util.MessageUtil;
import com.ljsd.jieling.util.StringUtil;
import com.ljsd.jieling.util.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.monitor.ServerInfo;
import org.springframework.stereotype.Component;
import java.util.Calendar;
@ -73,7 +76,16 @@ public class RoomMatchRequestHandler extends BaseHandler{
User user = UserManager.getUser(iSession.getUid());
snapUserFightInfo(user);
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;
try {
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
@ -93,8 +105,8 @@ public class RoomMatchRequestHandler extends BaseHandler{
public static void snapUserFightInfo(User mine){
//血量处理
// int myteamId = GlobalsDef.BLOODY_TEAM;
int myteamId = 1;
int myteamId = GlobalsDef.BLOODY_TEAM;
mine.getTeamPosManager().setCurTeamPosId(myteamId);
PlayerManager playerInfoManager = mine.getPlayerInfoManager();
UserBloodySnpInfo userBloodySnpInfo = new UserBloodySnpInfo(mine.getId(),playerInfoManager.getNickName());

View File

@ -64,6 +64,7 @@ public class EquipManager extends MongoBase {
public void addSoulEquip(SoulEquip soulEquip){
updateString("soulEquipMap." + soulEquip.getId(), soulEquip);
soulEquip.init(getRootId(),getMongoKey()+".soulEquipMap." + soulEquip.getId());
soulEquipMap.put(soulEquip.getId(), soulEquip);
}

View File

@ -103,7 +103,7 @@ public class QuestionLogic {
if(null ==sessionByUid){
return;
}
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.PLAYER_BACKCINFO_INDICATION_VALUE, builder, true);
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.QUESTION_INDICATION_VALUE, builder, true);
}
}, new ArrayList<>(OnlineUserManager.sessionMap.keySet()), 120);
@ -125,7 +125,7 @@ public class QuestionLogic {
user.getQuestionManager().setQuestId(qid);
user.getQuestionManager().setQuestState(0);
ISession sessionByUid = OnlineUserManager.getSessionByUid(user.getId());
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.PLAYER_BACKCINFO_INDICATION_VALUE, builder, true);
MessageUtil.sendIndicationMessage(sessionByUid, 1, MessageTypeProto.MessageType.QUESTION_INDICATION_VALUE, builder, true);
}
}, new ArrayList<>(OnlineUserManager.sessionMap.keySet()), 120);
}
@ -134,7 +134,10 @@ public class QuestionLogic {
}
}
//remove
RedisUtil.getInstence().removeMapEntrys(RedisKey.QUESTION_FROMBACK, "", remove);
for (Integer id:remove) {
RedisUtil.getInstence().removeMapEntrys(RedisKey.QUESTION_FROMBACK, "", String.valueOf(id));
}
}

View File

@ -165,7 +165,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
//处理多设备重登
dealRepeatLogin(session.getUid());
//刷新token
refreshToken(session);
//refreshToken(session);
//踢下线
//在线列表加入session
OnlineUserManager.userOnline(session.getUid(),session);
@ -180,10 +180,10 @@ public class ProtocolsManager implements ProtocolsAbstract {
return;
}
//检查token
// if (checkToken(session,packetNetData) != 0 ){
// MessageUtil.sendErrorCode(session,0,"您的账号token不正确请退出游戏重新登陆!");
// return;
// }
if (checkToken(session,packetNetData) != 0 ){
MessageUtil.sendErrorCode(session,0,"您的账号token不正确请退出游戏重新登陆!");
return;
}
if( packetNetData.getMsgId()== MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE){
processReconnect(session);
@ -274,16 +274,20 @@ public class ProtocolsManager implements ProtocolsAbstract {
int uid = packetNetData.getUserId();
int token = packetNetData.getToken();
session.setUid(uid);
// String tokenKey = RedisKey.getKey(RedisKey.TOKEN, String.valueOf(uid),false);
// if(null==tokenKey||tokenKey.isEmpty()){
// return false;
// }
// int serverToken = Integer.parseInt((String)RedisUtil.getInstence().get(tokenKey));
// if (token == serverToken){
// session.setToken(token);
// session.setUserLoginTime(System.currentTimeMillis()/1000);
// return true;
// }
String tokenKey = RedisKey.getKey(RedisKey.TOKEN, String.valueOf(uid),false);
if(null==tokenKey||tokenKey.isEmpty()){
return false;
}
String tokenK = (String)RedisUtil.getInstence().get(tokenKey);
if(null==tokenK||tokenK.isEmpty()){
return false;
}
int serverToken = Integer.parseInt((String)RedisUtil.getInstence().get(tokenKey));
if (token == serverToken){
session.setToken(token);
session.setUserLoginTime(System.currentTimeMillis()/1000);
return true;
}
return true;
}

View File

@ -2,6 +2,7 @@ package com.ljsd.jieling.thread.task;
import com.google.gson.Gson;
import com.ljsd.CoreService;
import com.ljsd.GameApplication;
import com.ljsd.jieling.config.json.CoreSettings;
import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
import org.apache.thrift.TProcessor;

View File

@ -504,7 +504,7 @@ public class ItemUtil {
List<CommonProto.Item> itemProtoList = new ArrayList<>();
List<CommonProto.Equip> equipProtoList = new ArrayList<>();
List<CommonProto.Equip> especialEquip = new ArrayList<>();
List<CommonProto.Equip> soulEquip = new ArrayList<>();
List<CommonProto.Equip> soulEquiplist = new ArrayList<>();
MapManager mapManager = user.getMapManager();
TemporaryItems temporaryItems = mapManager.getTemporaryItems();
if (temporaryItems == null) {
@ -556,7 +556,7 @@ public class ItemUtil {
}
SoulEquip soulEquip1 = new SoulEquip(user.getId(), entry.getKey());
soulEquips.add(soulEquip1);
equipProtoList.add(CBean2Proto.getEquipProto(soulEquip1));
soulEquiplist.add(CBean2Proto.getEquipProto(soulEquip1));
LOGGER.info("the uid={},the curMapId={},add equip={},equipNum={},totalEquipNum={}",user.getId(),user.getMapManager().getCurMapId(),entry.getKey(),1,equips.size());
}
@ -565,7 +565,7 @@ public class ItemUtil {
dropBuilder.addAllItemlist(itemProtoList);
dropBuilder.addAllEquipId(equipProtoList);
dropBuilder.addAllEspecialEquipId(especialEquip);
dropBuilder.addAllSoulEquip(soulEquip);
dropBuilder.addAllSoulEquip(soulEquiplist);
}
if(!sendToFront.isEmpty()){

View File

@ -254,12 +254,16 @@ public class MathUtils {
public static int randomWeight(int[][] source,Set<Integer> excluIndexs){
int length = source.length;
int randomIndex = 0;
while (true){
int times=100;
while (times-->0){
randomIndex= randomInt(length);
if(!excluIndexs.contains(randomIndex)){
break;
}
}
if(times<=0){
return -1;
}
excluIndexs.add(randomIndex);
return randomIndex;
}