back_recharge
parent
96bf0a392e
commit
eaa9ffcd43
|
|
@ -0,0 +1,27 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
/**
|
||||
* 场景演员类型
|
||||
*
|
||||
*/
|
||||
public enum ActorType {
|
||||
|
||||
Player(1),
|
||||
|
||||
Monster(2),
|
||||
|
||||
Mineral(3), //矿点
|
||||
|
||||
Npc(4),
|
||||
|
||||
;
|
||||
private int stateCode;
|
||||
|
||||
ActorType(int stateCode) {
|
||||
this.stateCode = stateCode;
|
||||
}
|
||||
|
||||
public int getStateCode() {
|
||||
return stateCode;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
|
||||
|
||||
import com.ljsd.jieling.util.CellUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 生物体,就是会动的场景演员( 玩家 & 怪物 & 矿 可以认为是一样的)
|
||||
*/
|
||||
public abstract class Creature extends SceneActor{
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Creature.class);
|
||||
|
||||
|
||||
private Life life;
|
||||
|
||||
private List<Integer> path = new ArrayList<>(); //路径
|
||||
|
||||
private long preMoveTimestamp; //上次移动时间
|
||||
|
||||
private int speed=500;
|
||||
|
||||
private int camp; // 阵营
|
||||
|
||||
private int mineral; // 矿石
|
||||
|
||||
public Creature(){
|
||||
setStateType(StateType.MOVEABLE);
|
||||
}
|
||||
|
||||
|
||||
public void tick(){
|
||||
move(null);
|
||||
}
|
||||
|
||||
public void exec(int tyep,Object parm){
|
||||
if(tyep == 1){
|
||||
move((List<Integer>) parm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bufferUpdateAfterEvent(long now) {
|
||||
checkEventTrigger(now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkCommand(int commandType,Object parm){
|
||||
boolean result = super.checkCommand(commandType,parm);
|
||||
if(result){
|
||||
if(commandType == 1){
|
||||
return CellUtil.isContinuous(getPos(), (List<Integer>) parm);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//用户移动到新位置, 返回下一个点的坐标,用户展示客户端的转向,及模拟移动
|
||||
public void move(List<Integer> path){
|
||||
long timestamp = System.currentTimeMillis();
|
||||
checkUpdateBuffer(timestamp);
|
||||
if(!this.path.isEmpty()){
|
||||
move(timestamp);
|
||||
}
|
||||
if(path == null){
|
||||
return;
|
||||
}
|
||||
this.path.clear();
|
||||
this.path.addAll(path);
|
||||
this.path.remove(0);
|
||||
preMoveTimestamp = timestamp;
|
||||
}
|
||||
|
||||
//服务器模拟移动,如果前端模拟,则不需要服务气端调用这个函数,服务器端在事件触发的时候做校验即可
|
||||
//如果位置发生变化,则返回新的当前点
|
||||
public int move(long timestamp){
|
||||
if(path.size() <= 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int moveDistance = (int)((timestamp - preMoveTimestamp)/speed);
|
||||
if(moveDistance < 1){
|
||||
//格子没有发生变化
|
||||
return -1;
|
||||
}
|
||||
LOGGER.info("the uid={} will move",getId());
|
||||
int oldXY=getPos();
|
||||
int pathSize = path.size();
|
||||
for(int i=0; i<moveDistance && i<pathSize; i++){
|
||||
setPos(path.remove(0));
|
||||
if(checkEventTrigger(timestamp)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
int curPos = getPos();
|
||||
LOGGER.info("the id={},preMoveTimestamp={},the time ={},move={},the oldXy={},the curXy={}",getId(),new Date(preMoveTimestamp),new Date(timestamp),moveDistance,oldXY,curPos);
|
||||
//LOGGER.info("the ox={},oy={},the nx={},the ny={}",CellUtil.pos2XY(oldXY)[0],CellUtil.pos2XY(oldXY)[1],CellUtil.pos2XY(curPos)[0],CellUtil.pos2XY(curPos)[1]);
|
||||
|
||||
preMoveTimestamp = timestamp;
|
||||
return curPos;
|
||||
}
|
||||
|
||||
public void whenTriggerEvent(EffectBuffer effectBuffer,long timestamp){
|
||||
this.addOrUpdateBuffer(effectBuffer); //战斗buffer
|
||||
//打断自己行使路线 广播自己状态 位置信息
|
||||
this.preMoveTimestamp = timestamp;
|
||||
this.path.clear();
|
||||
}
|
||||
|
||||
public boolean checkEventTrigger(long timestamp){
|
||||
Scene scene = getScene();
|
||||
int curPos = getPos();
|
||||
Set<Integer> xySet = CellUtil.getSurroundPos(100,100,curPos);
|
||||
Map<Integer, SceneActor> sceneActorMap = scene.getSceneActorMap();
|
||||
for(SceneActor sceneActor : sceneActorMap.values()){
|
||||
if(sceneActor == this) {
|
||||
continue;
|
||||
}
|
||||
if(triggerEvent(sceneActor,timestamp,xySet)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean triggerEvent(SceneActor sceneActor,long timestamp,Set<Integer> xySet){
|
||||
int curPos = getPos();
|
||||
boolean result= false;
|
||||
ActorType type = sceneActor.getType();
|
||||
int triggerEvent = 0;
|
||||
if(type == ActorType.Npc){
|
||||
if(curPos == sceneActor.getPos()){
|
||||
triggerEvent=1;
|
||||
}
|
||||
}
|
||||
if(type == ActorType.Mineral && !sceneActor.getBufferMap().containsKey(2)){
|
||||
if(curPos == sceneActor.getPos()){
|
||||
triggerEvent=2;
|
||||
}
|
||||
}
|
||||
if(type == ActorType.Monster || type == ActorType.Player){
|
||||
if( (!sceneActor.getBufferMap().containsKey(3) || !sceneActor.getBufferMap().containsKey(4)) && xySet.contains(sceneActor.getPos())){
|
||||
triggerEvent=3;
|
||||
}
|
||||
}
|
||||
if(triggerEvent!=0){
|
||||
EffectBuffer effectBuffer = new EffectBuffer(triggerEvent, timestamp, timestamp + 5000,getId(), sceneActor.getId(), 1);
|
||||
EffectBuffer othereffectBuffer = new EffectBuffer(triggerEvent, timestamp, timestamp + 5000, getId(),sceneActor.getId(), 0);
|
||||
whenTriggerEvent(effectBuffer,timestamp);
|
||||
sceneActor.whenTriggerEvent(othereffectBuffer,timestamp);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLife(Life life) {
|
||||
this.life = life;
|
||||
}
|
||||
|
||||
public Life getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
public List<Integer> getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public int getCamp() {
|
||||
return camp;
|
||||
}
|
||||
|
||||
public int getMineral() {
|
||||
return mineral;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EffectBuffer {
|
||||
private int id; // id
|
||||
private long startTime; //开始时间
|
||||
private long endTime;//结束时间
|
||||
|
||||
private int target; // buffer 作用对象id
|
||||
private int caster; //释放者
|
||||
private List<Integer> values = new ArrayList<>(1); //作用效果值
|
||||
|
||||
public EffectBuffer(int id, long startTime, long endTime,int target,int caster,int value) {
|
||||
this.id = id;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.target = target;
|
||||
this.caster = caster;
|
||||
this.values.add(value);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(int target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public List<Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public int getCaster() {
|
||||
return caster;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
public enum EventType {
|
||||
SCENEACTORE_UPDATE,
|
||||
BUFFER_UPDATE,
|
||||
BUFFER_REMOVE,
|
||||
SCENEACTORE_REMOVE,
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
|
||||
|
||||
public class Life {
|
||||
|
||||
|
||||
private int curMp;
|
||||
|
||||
private int maxMp;
|
||||
|
||||
public Life(int curMp, int maxMp) {
|
||||
this.curMp = curMp;
|
||||
this.maxMp = maxMp;
|
||||
}
|
||||
|
||||
public long reduceHp(int changeValue) {
|
||||
if (changeValue <= 0) {
|
||||
return this.curMp;
|
||||
}
|
||||
return this.curMp - changeValue;
|
||||
}
|
||||
|
||||
|
||||
public int getCurMp() {
|
||||
return curMp;
|
||||
}
|
||||
|
||||
public int getMaxMp() {
|
||||
return maxMp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
public class Monster extends Creature {
|
||||
@Override
|
||||
public ActorType getType() {
|
||||
return ActorType.Monster;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RoomMap {
|
||||
private int mapId;
|
||||
private Map<Integer,Creature> sceneActorMap = new HashMap<>(3);
|
||||
|
||||
public void addScenActor(Creature creature){
|
||||
sceneActorMap.put(creature.getId(),creature);
|
||||
}
|
||||
|
||||
public Map<Integer, Creature> getSceneActorMap() {
|
||||
return sceneActorMap;
|
||||
}
|
||||
|
||||
public void updateEveryActorPos(){
|
||||
long now = System.currentTimeMillis();
|
||||
for(Creature creature : sceneActorMap.values()){
|
||||
creature.move(now);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyMsg(String msg){
|
||||
for(int uid : sceneActorMap.keySet()){
|
||||
System.out.println("notify the uid=" + uid + " ,the msg=" + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
import com.googlecode.protobuf.format.JsonFormat;
|
||||
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
|
||||
import com.ljsd.jieling.battle.room.BeanToProto;
|
||||
import com.ljsd.jieling.battle.room.Command;
|
||||
import com.ljsd.jieling.protocols.SceneFight;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Scene implements Runnable{
|
||||
private int mapId; //地图id
|
||||
private Map<Integer,SceneActor> sceneActorMap = new HashMap<>(3);
|
||||
private BlockingUniqueQueue<Command> commandBlockingUniqueQueue = new BlockingUniqueQueue<>();
|
||||
|
||||
public void addScenActor(SceneActor sceneActor){
|
||||
sceneActorMap.put(sceneActor.getId(),sceneActor);
|
||||
}
|
||||
|
||||
public void addCommand(Command command){
|
||||
commandBlockingUniqueQueue.add(command);
|
||||
}
|
||||
|
||||
public Map<Integer, SceneActor> getSceneActorMap() {
|
||||
return sceneActorMap;
|
||||
}
|
||||
|
||||
private SceneFight.BroadMsgIndication.Builder builder = SceneFight.BroadMsgIndication.newBuilder();
|
||||
|
||||
private boolean msgUpdate;
|
||||
|
||||
|
||||
public void tick() throws InterruptedException {
|
||||
for(SceneActor sceneActor : sceneActorMap.values()){
|
||||
sceneActor.tick();
|
||||
}
|
||||
|
||||
//消息广播
|
||||
if(msgUpdate){
|
||||
System.out.println(JsonFormat.printToString(builder.build()));
|
||||
builder.clear();
|
||||
msgUpdate = false;
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息收集器
|
||||
*/
|
||||
public void processEventUpdate(EventType eventType,Object parm){
|
||||
msgUpdate = true;
|
||||
switch (eventType){
|
||||
case SCENEACTORE_UPDATE:
|
||||
builder.addSceneActor(BeanToProto.getSceneActor((SceneActor)parm));
|
||||
break;
|
||||
case BUFFER_UPDATE:
|
||||
builder.addActorEffectBufferInfo(BeanToProto.getActorEffectBufferInfo((EffectBuffer) parm));
|
||||
break;
|
||||
case BUFFER_REMOVE:
|
||||
int removeId = (int)parm;
|
||||
builder.addRemoveActorId(removeId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
try {
|
||||
Command poll = null;
|
||||
while ( (poll = commandBlockingUniqueQueue.poll())!=null){
|
||||
poll.getSceneActor().exec(poll.getType(),poll.getOperParm());
|
||||
}
|
||||
tick();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* 场景里的各种演员
|
||||
*/
|
||||
public abstract class SceneActor{
|
||||
private int id;
|
||||
private int pos;
|
||||
private Map<Integer,EffectBuffer> bufferMap = new HashMap<>(2);
|
||||
private Scene scene;
|
||||
private StateType stateType;
|
||||
|
||||
|
||||
public Scene getScene() {
|
||||
return scene;
|
||||
}
|
||||
|
||||
public void setScene(Scene scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
public void addOrUpdateBuffer(EffectBuffer effectBuffer){
|
||||
bufferMap.put(effectBuffer.getId(),effectBuffer);
|
||||
if(effectBuffer.getId() == 3){
|
||||
stateType = StateType.FROZEN;
|
||||
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,this);
|
||||
}
|
||||
scene.processEventUpdate(EventType.BUFFER_UPDATE,effectBuffer);
|
||||
}
|
||||
|
||||
public Map<Integer, EffectBuffer> getBufferMap() {
|
||||
return bufferMap;
|
||||
}
|
||||
|
||||
public void checkUpdateBuffer(long now){
|
||||
boolean isUpdate = false;
|
||||
Iterator<Map.Entry<Integer, EffectBuffer>> iterator = bufferMap.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
Map.Entry<Integer, EffectBuffer> next = iterator.next();
|
||||
EffectBuffer value = next.getValue();
|
||||
if( now>value.getEndTime() ){
|
||||
iterator.remove();
|
||||
isUpdate = true;
|
||||
whenBufferRemove(value,now);
|
||||
scene.processEventUpdate(EventType.BUFFER_REMOVE,value.getId());
|
||||
System.out.println("---------------------update--------------------------" + value.getId() +" "+new Date(now) + "end time" + new Date(value.getEndTime()));
|
||||
}
|
||||
}
|
||||
if(isUpdate){
|
||||
bufferUpdateAfterEvent(now);
|
||||
}
|
||||
}
|
||||
|
||||
public void whenBufferRemove(EffectBuffer value,long now){
|
||||
int id = value.getId();
|
||||
if(id == 3){
|
||||
int effectValue = value.getValues().get(0);
|
||||
if(effectValue == 0){ //战斗失败
|
||||
addOrUpdateBuffer(new EffectBuffer(4,now,now+5000,this.getId(),0,0));
|
||||
}else{
|
||||
stateType = StateType.MOVEABLE;
|
||||
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void setPos(int pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public StateType getStateType() {
|
||||
return stateType;
|
||||
}
|
||||
|
||||
public void setStateType(StateType stateType) {
|
||||
this.stateType = stateType;
|
||||
}
|
||||
|
||||
public boolean checkCommand(int commandType,Object parm){
|
||||
if(commandType == 1){
|
||||
return stateType == StateType.MOVEABLE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract ActorType getType();
|
||||
|
||||
|
||||
public abstract void tick();
|
||||
public abstract void exec(int type,Object parm);
|
||||
public abstract void whenTriggerEvent(EffectBuffer effectBuffer,long timestamp);
|
||||
public abstract void bufferUpdateAfterEvent(long now);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
|
||||
public class SceneMineral extends Creature {
|
||||
@Override
|
||||
public ActorType getType() {
|
||||
return ActorType.Mineral;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
public class SceneMonster extends Creature{
|
||||
@Override
|
||||
public ActorType getType() {
|
||||
return ActorType.Monster;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SceneNpc extends Creature{
|
||||
@Override
|
||||
public ActorType getType() {
|
||||
return ActorType.Npc;
|
||||
}
|
||||
|
||||
|
||||
public void exec(int tyep,Object parm){
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
public class ScenePlayer extends Creature {
|
||||
@Override
|
||||
public ActorType getType() {
|
||||
return ActorType.Player;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.ljsd.jieling.battle.actor;
|
||||
|
||||
public enum StateType {
|
||||
|
||||
FROZEN(1),
|
||||
MOVEABLE(2),
|
||||
;
|
||||
|
||||
|
||||
int state;
|
||||
|
||||
private StateType(int state){
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
|
||||
import com.ljsd.jieling.battle.room.Room;
|
||||
import com.ljsd.jieling.battle.room.SceneManager;
|
||||
import com.ljsd.jieling.battle.room.WaitingRoom;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BloodyBattleMatchServer {
|
||||
private static WaitingRoom waitingRoom = new WaitingRoom();
|
||||
private static Map<Integer,Integer> roomFull = new HashMap<>();
|
||||
static {
|
||||
roomFull.put(1,2);
|
||||
}
|
||||
|
||||
|
||||
public static void tryMatch(int uid, int type){
|
||||
Room room = waitingRoom.findRoom(uid, type, new IMatch.IRoomMatchFilter() {
|
||||
@Override
|
||||
public Room filter(List<Room> rooms) {
|
||||
int full = roomFull.get(type);
|
||||
for (Room room : rooms) {
|
||||
if (!room.isFull(full)) {
|
||||
return room;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
//房间已满,可以开始游戏,向房间里人广播事件。
|
||||
if(room!=null){
|
||||
room.addFightPlayer(uid);
|
||||
if(room.isFull(roomFull.get(type))){
|
||||
SceneManager.createScene(room);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
tryMatch(100000001,1);
|
||||
tryMatch(100000002,1);
|
||||
tryMatch(100000003,1);
|
||||
tryMatch(100000004,1);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
import com.ljsd.jieling.battle.room.Room;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IMatch {
|
||||
public void match();
|
||||
|
||||
/**
|
||||
* @return 匹配的方式
|
||||
*/
|
||||
public MatchType getMatchType();
|
||||
|
||||
/**
|
||||
* 从已有房间中找一个符合条件的房间
|
||||
*/
|
||||
public interface IRoomMatchFilter {
|
||||
/**
|
||||
* 过滤
|
||||
* @param rooms 人未满的房间
|
||||
* @return
|
||||
*/
|
||||
Room filter(List<Room> rooms) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
|
||||
//匹配规则
|
||||
public class Match {
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
public enum MatchType {
|
||||
RANDOM;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
public interface MatchUnit {
|
||||
|
||||
int getScore();
|
||||
|
||||
int getSize();
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MathcUnitGroup implements MatchUnit{
|
||||
|
||||
|
||||
private List<Integer> pids;
|
||||
|
||||
private int score;
|
||||
|
||||
@Override
|
||||
public int getScore() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return this.pids.size();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ljsd.jieling.battle.match;
|
||||
|
||||
public class MathcUnitPerson implements MatchUnit{
|
||||
private int pid;
|
||||
private int score;
|
||||
|
||||
@Override
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.ljsd.jieling.battle.room;
|
||||
|
||||
import com.ljsd.jieling.battle.actor.*;
|
||||
import com.ljsd.jieling.protocols.SceneFight;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BeanToProto {
|
||||
|
||||
public static SceneFight.SceneActor getSceneActor(SceneActor sceneActor){
|
||||
ActorType actorType = sceneActor.getType();
|
||||
SceneFight.SceneActor.Builder builder = SceneFight.SceneActor.newBuilder()
|
||||
.setId(sceneActor.getId())
|
||||
.setCurPos(sceneActor.getPos())
|
||||
.setType(actorType.getStateCode());
|
||||
if(actorType != ActorType.Npc){
|
||||
builder.setCreature(getCreature((Creature)sceneActor));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static SceneFight.Creature getCreature(Creature creature){
|
||||
return SceneFight.Creature.newBuilder()
|
||||
.setCurHp(creature.getLife().getCurMp())
|
||||
.setMaxHp(creature.getLife().getMaxMp())
|
||||
.setSpeed(creature.getSpeed())
|
||||
.addAllPath(creature.getPath())
|
||||
.setCamp(creature.getCamp())
|
||||
.setMineral(creature.getMineral())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static SceneFight.ActorEffectBufferInfo getActorEffectBufferInfo(EffectBuffer effectBuffer){
|
||||
return SceneFight.ActorEffectBufferInfo.newBuilder()
|
||||
.setId(effectBuffer.getId())
|
||||
.setStartTime((int)(effectBuffer.getStartTime()/1000))
|
||||
.setEndTime((int)(effectBuffer.getStartTime()/1000))
|
||||
.setTarget(effectBuffer.getTarget())
|
||||
.setCaster(effectBuffer.getCaster())
|
||||
.addAllValue(effectBuffer.getValues())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static SceneFight.SceneInfo getSceneInfo(Scene scene){
|
||||
SceneFight.SceneInfo.Builder builder = SceneFight.SceneInfo.newBuilder().setMapId(scene.getMapId());
|
||||
Map<Integer, SceneActor> sceneActorMap = scene.getSceneActorMap();
|
||||
for(SceneActor sceneActor : sceneActorMap.values()){
|
||||
builder.addSceneActor(getSceneActor(sceneActor));
|
||||
Map<Integer, EffectBuffer> bufferMap = sceneActor.getBufferMap();
|
||||
for(EffectBuffer effectBuffer : bufferMap.values()){
|
||||
builder.addActorEffectBufferInfo(getActorEffectBufferInfo(effectBuffer));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.ljsd.jieling.battle.room;
|
||||
|
||||
import com.ljsd.jieling.battle.actor.SceneActor;
|
||||
|
||||
public class Command {
|
||||
private int type; //操作类型
|
||||
private SceneActor sceneActor;//操作对象
|
||||
private Object operParm; //操作参数
|
||||
|
||||
public Command(int type, SceneActor sceneActor, Object operParm) {
|
||||
this.type = type;
|
||||
this.sceneActor = sceneActor;
|
||||
this.operParm = operParm;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public SceneActor getSceneActor() {
|
||||
return sceneActor;
|
||||
}
|
||||
|
||||
public Object getOperParm() {
|
||||
return operParm;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.ljsd.jieling.battle.room;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Room {
|
||||
public int id;
|
||||
public int type; //房间类型。开此房间玩什么模式
|
||||
public List<Integer> fightPlayer = new ArrayList<>(2); //把玩家数据迁移过来
|
||||
|
||||
public Room(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void addFightPlayer(int fightUid){
|
||||
fightPlayer.add(fightUid);
|
||||
}
|
||||
|
||||
public void removeFightPlayer(int fightUid){
|
||||
fightPlayer.remove(fightUid);
|
||||
}
|
||||
|
||||
public boolean isFull(int maxNum){
|
||||
return fightPlayer.size()>=maxNum;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.ljsd.jieling.battle.room;
|
||||
|
||||
import com.ljsd.jieling.battle.actor.Life;
|
||||
import com.ljsd.jieling.battle.actor.Scene;
|
||||
import com.ljsd.jieling.battle.actor.SceneMonster;
|
||||
import com.ljsd.jieling.battle.actor.ScenePlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
public class SceneManager {
|
||||
private static Map<Integer, Scene> sceneMap = new HashMap<>();
|
||||
|
||||
private static ScheduledThreadPoolExecutor scheduledExecutor=new ScheduledThreadPoolExecutor(8); //管理task
|
||||
|
||||
public static void createScene(Room room){
|
||||
Scene scene = new Scene();
|
||||
for(Integer uid : room.fightPlayer){
|
||||
ScenePlayer playerA = new ScenePlayer();
|
||||
playerA.setId(uid);
|
||||
playerA.setScene(scene);
|
||||
playerA.setLife(new Life(1000,1000));
|
||||
playerA.setPos(256*1+1);
|
||||
|
||||
scene.addScenActor(playerA);
|
||||
}
|
||||
|
||||
SceneMonster sceneMonster = new SceneMonster();
|
||||
sceneMonster.setId(52014);
|
||||
sceneMonster.setScene(scene);
|
||||
sceneMonster.setLife(new Life(1000,1000));
|
||||
|
||||
scheduledExecutor.execute(scene);
|
||||
}
|
||||
|
||||
|
||||
public static void createScene() throws InterruptedException {
|
||||
Scene scene = new Scene();
|
||||
ScenePlayer playerA = new ScenePlayer();
|
||||
playerA.setId(1);
|
||||
playerA.setScene(scene);
|
||||
|
||||
ScenePlayer playerB = new ScenePlayer();
|
||||
playerB.setId(100);
|
||||
playerB.setScene(scene);
|
||||
|
||||
SceneMonster sceneMonster = new SceneMonster();
|
||||
sceneMonster.setId(9999);
|
||||
sceneMonster.setScene(scene);
|
||||
|
||||
playerA.setLife(new Life(1000,1000));
|
||||
playerB.setLife(new Life(1000,1000));
|
||||
sceneMonster.setLife(new Life(1000,1000));
|
||||
|
||||
|
||||
scene.addScenActor(playerA);
|
||||
scene.addScenActor(playerB);
|
||||
scene.addScenActor(sceneMonster);
|
||||
|
||||
playerA.setPos(256*1+1);
|
||||
playerB.setPos(256*2+1);
|
||||
sceneMonster.setPos(256*3+2);
|
||||
|
||||
scheduledExecutor.execute(scene);
|
||||
Thread.sleep(2000);
|
||||
|
||||
List<Integer> firstPath = new ArrayList<>();
|
||||
firstPath.add(256*1+1);
|
||||
firstPath.add(256*1+2);
|
||||
firstPath.add(256*1+3);
|
||||
|
||||
List<Integer> secondPath = new ArrayList<>();
|
||||
secondPath.add(256*2+1);
|
||||
secondPath.add(256*2+2);
|
||||
secondPath.add(256*1+2);
|
||||
|
||||
List<Integer> thirdPath = new ArrayList<>();
|
||||
thirdPath.add(256*3+2);
|
||||
thirdPath.add(256*3+3);
|
||||
thirdPath.add(256*2+3);
|
||||
|
||||
System.out.println(new Date());
|
||||
|
||||
//验证用户操作合法性
|
||||
boolean playerACommandAllow = playerA.checkCommand(1, firstPath);
|
||||
boolean playerBCommandAllow = playerB.checkCommand(1, firstPath);
|
||||
boolean monsterCommandAllow = sceneMonster.checkCommand(1, firstPath);
|
||||
System.out.println(playerACommandAllow);
|
||||
System.out.println(playerBCommandAllow);
|
||||
System.out.println(monsterCommandAllow);
|
||||
|
||||
Command commandA = new Command(1,playerA,firstPath);
|
||||
Command commandB = new Command(1,playerB,secondPath);
|
||||
Command commandC = new Command(1,sceneMonster,thirdPath);
|
||||
scene.addCommand(commandA);
|
||||
scene.addCommand(commandB);
|
||||
scene.addCommand(commandC);
|
||||
System.out.println(new Date());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
createScene();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.ljsd.jieling.battle.room;
|
||||
|
||||
import com.ljsd.jieling.battle.match.IMatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class WaitingRoom {
|
||||
|
||||
private static Map<Integer, List<Room>> roomByType = new HashMap<>();
|
||||
static {
|
||||
roomByType.put(1,new ArrayList<>(50));
|
||||
}
|
||||
|
||||
private static AtomicInteger atomicInteger = new AtomicInteger(10000);
|
||||
|
||||
|
||||
|
||||
public static Room findRoom(int uid,int type, IMatch.IRoomMatchFilter filter){
|
||||
List<Room> rooms = roomByType.get(type);
|
||||
Room room = filter.filter(rooms);
|
||||
if(room!=null){
|
||||
return room;
|
||||
}
|
||||
room = new Room(getRoomId());
|
||||
rooms.add(room);
|
||||
return room;
|
||||
}
|
||||
|
||||
//如果房间人数已满,则直接开始游戏。
|
||||
public static void triggerWhenRoomIsFull(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//获取roomId
|
||||
public static int getRoomId(){
|
||||
return atomicInteger.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
|
@ -203,9 +203,11 @@ public class HeroLogic {
|
|||
int j=0;
|
||||
for(int i=0;i<perCount;i++){
|
||||
randCount++;
|
||||
pooId = getSpecialPoolByRandcount(type, randCount);
|
||||
if(pooId==0&&!isSpecial){
|
||||
pooId = getPooId(sLotterySetting, pooId);
|
||||
if(pooId == 0){
|
||||
pooId = getSpecialPoolByRandcount(type, randCount);
|
||||
if(pooId==0&&!isSpecial){
|
||||
pooId = getPooId(sLotterySetting, pooId);
|
||||
}
|
||||
}
|
||||
LOGGER.info("the uid={},the type={},the poolId={}",uid,type,pooId);
|
||||
totalCount++;
|
||||
|
|
@ -1331,7 +1333,7 @@ public class HeroLogic {
|
|||
int[][] cost = sDifferDemonsStageConfig.getCost();
|
||||
|
||||
if(!isEnough){
|
||||
MessageUtil.sendErrorResponse(session,0,MessageTypeProto.MessageType.POKEMON_ADVANCED_RESPONSE_VALUE,"not match");
|
||||
MessageUtil.sendErrorResponse(session,0,MessageTypeProto.MessageType.POKEMON_ADVANCED_RESPONSE_VALUE,"not tryMatch");
|
||||
return;
|
||||
}
|
||||
isEnough = ItemUtil.itemCost(user,cost,BIReason.POKEMON_ADVANCE_CONSUME,pokemonId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue