mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-08-11 01:39:08 +00:00
提交完美的无头模式
This commit is contained in:
parent
7389f6d716
commit
f890be0728
@ -28,10 +28,10 @@ import AppAction from "./AppAction";
|
||||
|
||||
// let APIPath = `http://localhost:8080`
|
||||
// let WsPath = `ws://localhost:8080/websocket`
|
||||
let APIPath = `http://192.168.1.23:8080`
|
||||
let WsPath = `ws://192.168.1.23:8080/websocket`
|
||||
// let APIPath = `http://192.168.0.174:8080`
|
||||
// let WsPath = `ws://192.168.0.174:8080/websocket`
|
||||
// let APIPath = `http://192.168.1.23:8080`
|
||||
// let WsPath = `ws://192.168.1.23:8080/websocket`
|
||||
let APIPath = `http://192.168.0.123:8080`
|
||||
let WsPath = `ws://192.168.0.123:8080/websocket`
|
||||
// let APIPath = `https://api.pet.jisol.cn`
|
||||
// let WsPath = `wss://api.pet.jisol.cn/websocket`
|
||||
|
||||
@ -231,8 +231,8 @@ export const app = {
|
||||
}
|
||||
|
||||
app.api.addRequestInterceptors((config:JAPIConfig) => {
|
||||
// //设置Token
|
||||
// if(StorageData.get(StorageEnum.Token))
|
||||
// config.headers["Token"] = StorageData.get(StorageEnum.Token);
|
||||
//设置Token
|
||||
if(StorageData.get(StorageEnum.Token))
|
||||
config.headers["Token"] = StorageData.get(StorageEnum.Token);
|
||||
return true;
|
||||
})
|
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
//打包环境
|
||||
export enum Env{
|
||||
Server, //服务器模式
|
||||
@ -5,4 +7,5 @@ export enum Env{
|
||||
}
|
||||
|
||||
//当前环境
|
||||
export const EnvCurrent:Env = Env.Server;
|
||||
export const EnvCurrent:Env = Env.H5;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { JNSyncFrameEvent } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import { app } from "../App";
|
||||
import { Env, EnvCurrent } from "../Env";
|
||||
import GBattleModeManager, { BattleMode } from "../battle/GBattleModeManager";
|
||||
import GBattleModeManager, { BattleMode, GBattleModeEvent } from "../battle/GBattleModeManager";
|
||||
import { GAction } from "../consts/GAction";
|
||||
import { GActionType } from "../consts/GActionType";
|
||||
import { GUI } from "../ui/UIConfig";
|
||||
@ -12,6 +11,8 @@ export interface GPVPStart{
|
||||
leftPets:{[key:number]:string}; //左边玩家的宠物
|
||||
rightTactical:string; //右边玩家的阵法
|
||||
rightPets:{[key:number]:string}; //左边玩家的宠物
|
||||
leftPlayerId:number; //左边的玩家Id
|
||||
rightPlayerId:number; //右边的玩家Id
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +23,7 @@ export interface GPVPText{
|
||||
export default class PVPAction extends BaseAction {
|
||||
|
||||
onInit(){
|
||||
|
||||
app.socket.on(GAction.C_MODE_PVP_START_WAIT,this.onModePVPStartWait,this);
|
||||
app.socket.on(GAction.C_MODE_PVP_END_WAIT,this.onModePVPEndWait,this);
|
||||
app.socket.on(GAction.C_MODE_PVP_START,this.onModePVPStart,this,GActionType.GPVPStart);
|
||||
@ -29,7 +31,9 @@ export default class PVPAction extends BaseAction {
|
||||
|
||||
if(EnvCurrent == Env.Server){
|
||||
app.socket.on(GAction.CR_REFEREE_PVP_MODE,this.onCrReferee,this,GActionType.GPVPStart); //监听PVP裁决
|
||||
app.event.on(GBattleModeEvent.Close,this.onBattleRefereeClose,this); //模式结束运行
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//PVP开始等待
|
||||
@ -63,6 +67,16 @@ export default class PVPAction extends BaseAction {
|
||||
app.layer.Open(GUI.Tips,{text:info.text})
|
||||
}
|
||||
|
||||
//裁决结束返回
|
||||
onBattleRefereeClose(type:BattleMode,data?:number){
|
||||
if(type == BattleMode.PVP){
|
||||
console.log("裁决结束胜利玩家",data)
|
||||
app.socket.Send(GAction.CR_REFEREE_PVP_END,{
|
||||
winnerId:data
|
||||
},GActionType.GPVPRefereeInfo)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,8 +37,8 @@ export default class GBaseMode<T,DT> extends GObject<T> {
|
||||
}
|
||||
|
||||
//结束场景
|
||||
Close(){
|
||||
GBattleModeManager.getIns().Close();
|
||||
Close(data?:any){
|
||||
GBattleModeManager.getIns().Close(data);
|
||||
}
|
||||
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) {
|
||||
|
@ -22,6 +22,12 @@ export interface GBattleModeInfo{
|
||||
root:Node, //世界场景Root
|
||||
}
|
||||
|
||||
//事件
|
||||
export enum GBattleModeEvent{
|
||||
//关闭模式
|
||||
Close = "GBattleModeEvent_Close",
|
||||
}
|
||||
|
||||
//全局战斗模式管理器
|
||||
export default class GBattleModeManager extends Singleton {
|
||||
|
||||
@ -93,13 +99,16 @@ export default class GBattleModeManager extends Singleton {
|
||||
}
|
||||
|
||||
//关闭当前模式
|
||||
async Close(){
|
||||
async Close(data?:any){
|
||||
|
||||
//主动调用场景销毁
|
||||
app.sync.onReset();
|
||||
let current = this.current;
|
||||
this.current = null;
|
||||
this.frameNoSwitch = true;
|
||||
|
||||
//结束通知
|
||||
app.event.emit(GBattleModeEvent.Close,current,data);
|
||||
}
|
||||
|
||||
//设置自动推帧 ( 帧不由addFrame控制 管理器自动推帧)
|
||||
@ -109,8 +118,6 @@ export default class GBattleModeManager extends Singleton {
|
||||
this.autoTime = 0;
|
||||
}
|
||||
|
||||
//设置自动追帧
|
||||
|
||||
//清除当前模式
|
||||
private clear(){
|
||||
if(!this.isInit) return;
|
||||
|
@ -214,10 +214,14 @@ export default class GPVPMode extends GBaseMode<{},GPVPStart>{
|
||||
//判断是否有队伍都死亡
|
||||
if(this.getOnesRoleAlive(GPVPModePlayerEnum.PLAYER).length == 0 || this.getOnesRoleAlive(GPVPModePlayerEnum.ENEMY).length == 0){
|
||||
this.isEndGame = true;
|
||||
let winner = this.data.leftPlayerId;
|
||||
if(this.getOnesRoleAlive(GPVPModePlayerEnum.ENEMY).length){
|
||||
winner = this.data.rightPlayerId;
|
||||
}
|
||||
//结束游戏
|
||||
JNFrameTime.getInstance().setTimeout(() => {
|
||||
console.log(this.getOnesRoleAlive(GPVPModePlayerEnum.PLAYER).length,this.getOnesRoleAlive(GPVPModePlayerEnum.ENEMY).length)
|
||||
this.Close();
|
||||
this.Close(winner);
|
||||
},3000)
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ export enum GAction {
|
||||
|
||||
|
||||
/*************** 裁决 *********************/
|
||||
CR_REFEREE_PVP_MODE = 4001, //裁决PVP模式
|
||||
CR_REFEREE_PVP_MODE = 4001, //裁决PVP模式
|
||||
CR_REFEREE_PVP_END = 4002, //裁决PVP结束
|
||||
|
||||
}
|
@ -15,4 +15,7 @@ export enum GActionType {
|
||||
GPVPStart = "GPVPStart", //PVP 开始
|
||||
GPVPText = "GPVPText", //PVP 提示
|
||||
|
||||
/*************** 裁决 ********************/
|
||||
GPVPRefereeInfo = "GPVPRefereeInfo" //PVP 裁决信息
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 95f8a3c6c6310f66d8671958e940291020636a81
|
||||
Subproject commit e527d34fb68064a47d20d21764044c7cda2ed719
|
@ -9,6 +9,8 @@ message GPVPStart {
|
||||
map<int64, string> leftPets = 2; //左边的宠物 key:宠物Id value 宠物配置Id
|
||||
string rightTactical = 3; //右边的布阵
|
||||
map<int64, string> rightPets = 4; //右边的宠物 key:宠物Id value 宠物配置Id
|
||||
int64 leftPlayerId = 5; //左边的玩家Id
|
||||
int64 rightPlayerId = 6; //右边的玩家Id
|
||||
}
|
||||
|
||||
//PVP 消息提示
|
||||
@ -16,4 +18,10 @@ message GPVPText {
|
||||
string text = 1; //消息提示
|
||||
}
|
||||
|
||||
//PVP 裁决结束返回
|
||||
message GPVPRefereeInfo{
|
||||
//获胜玩家Id
|
||||
int64 winnerId = 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,5 +21,6 @@ public interface GActionEnum {
|
||||
|
||||
/*************** 裁决 *********************/
|
||||
int CR_REFEREE_PVP_MODE = 4001; //裁决PVP模式
|
||||
int CR_REFEREE_PVP_END = 4002; //裁决PVP结束
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package cn.jisol.game.actions;
|
||||
|
||||
import cn.jisol.game.network.client.GClient;
|
||||
import cn.jisol.game.network.client.GRefereeClient;
|
||||
import cn.jisol.game.proto.GPVPMessage;
|
||||
import cn.jisol.ngame.actions.core.NAction;
|
||||
import cn.jisol.ngame.actions.core.NActionMethod;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 裁决员行为 处理裁决
|
||||
@ -20,27 +17,12 @@ public class GRefereeAction {
|
||||
//裁决员列表
|
||||
public static Map<String, GRefereeClient> REFEREES;
|
||||
|
||||
//裁决PVP
|
||||
public static void onPVPReferee(GPVPMessage.GPVPStart info){
|
||||
|
||||
GRefereeClient referee;
|
||||
|
||||
//判断是否有裁决员 如果 没有裁决员则返回
|
||||
if(Objects.isNull(referee = getFreeReferee())) {
|
||||
System.out.println("没有裁决员");
|
||||
return;
|
||||
}
|
||||
|
||||
//如果有裁决员则向裁决员发送要裁决的信息
|
||||
referee.invoke(GActionEnum.CR_REFEREE_PVP_MODE,info);
|
||||
|
||||
}
|
||||
|
||||
//获取一个空闲的裁决员
|
||||
public static GRefereeClient getFreeReferee(){
|
||||
|
||||
for (String key : REFEREES.keySet()) {
|
||||
if (!(REFEREES.get(key).isReferee)) {
|
||||
REFEREES.get(key).isReferee = true;
|
||||
return REFEREES.get(key);
|
||||
}
|
||||
}
|
||||
@ -48,4 +30,28 @@ public class GRefereeAction {
|
||||
|
||||
}
|
||||
|
||||
//放回一个空闲裁决员
|
||||
public static void addFreeReferee(GRefereeClient referee){
|
||||
referee.isReferee = false;
|
||||
}
|
||||
|
||||
//自动回收裁决
|
||||
public static boolean autoReferee(GRefereeActionAutoInter inter){
|
||||
GRefereeClient referee = getFreeReferee();
|
||||
if (Objects.nonNull(referee)) {
|
||||
referee = inter.run(referee);
|
||||
//未使用则收回
|
||||
if(Objects.nonNull(referee)){
|
||||
addFreeReferee(referee);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface GRefereeActionAutoInter{
|
||||
GRefereeClient run(GRefereeClient referee);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import cn.jisol.game.controller.game.GPlayerPetController;
|
||||
import cn.jisol.game.controller.game.GPlayerTacticalController;
|
||||
import cn.jisol.game.entity.game.PlayerTactical;
|
||||
import cn.jisol.game.network.client.GClient;
|
||||
import cn.jisol.game.network.client.GRefereeClient;
|
||||
import cn.jisol.game.proto.GPVPMessage;
|
||||
import cn.jisol.game.service.PlayerTacticalService;
|
||||
import cn.jisol.ngame.actions.core.NAction;
|
||||
@ -80,76 +81,104 @@ public class GPVPAction {
|
||||
|
||||
//判断是否有两人在等待 有 则两人匹配成功
|
||||
while (pool.size() >= 2){
|
||||
//匹配成功
|
||||
GClient client1 = pool.poll();
|
||||
GClient client2 = pool.poll();
|
||||
|
||||
if(Objects.isNull(client1) || Objects.isNull(client2)) continue;
|
||||
//确保玩家都在线
|
||||
if(!(client1.isOpen() && client2.isOpen())){
|
||||
if(client2.isOpen()) pool.addFirst(client2);
|
||||
if(client1.isOpen()) pool.addFirst(client1);
|
||||
continue;
|
||||
}
|
||||
if (!(GRefereeAction.autoReferee(referee -> {
|
||||
|
||||
//获取双方的阵型
|
||||
GPlayerTacticalController tacticalController = SpringBeanUtils.getBean(GPlayerTacticalController.class);
|
||||
GPlayerPetController petController = SpringBeanUtils.getBean(GPlayerPetController.class);
|
||||
//匹配成功
|
||||
GClient client1 = pool.poll();
|
||||
GClient client2 = pool.poll();
|
||||
|
||||
String leftTactical = tacticalController.getInfo(client1.player).data.getTacticalData();
|
||||
String rightTactical = tacticalController.getInfo(client2.player).data.getTacticalData();
|
||||
|
||||
|
||||
//如果有人阵法是默认 则 不开始
|
||||
if (leftTactical.equals(tacticalController.InitTactical) || rightTactical.equals(tacticalController.InitTactical)){
|
||||
if(leftTactical.equals(tacticalController.InitTactical)){
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_MESSAGE, GPVPMessage.GPVPText.newBuilder().setText("你的阵法没有宠物~").build());
|
||||
}else{
|
||||
//加入回列表
|
||||
pool.addFirst(client1);
|
||||
if(Objects.isNull(client1) || Objects.isNull(client2)) {
|
||||
return referee;
|
||||
}
|
||||
if(rightTactical.equals(tacticalController.InitTactical)){
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_MESSAGE, GPVPMessage.GPVPText.newBuilder().setText("你的阵法没有宠物~").build());
|
||||
}else{
|
||||
//加入回列表
|
||||
pool.addFirst(client2);
|
||||
//确保玩家都在线
|
||||
if(!(client1.isOpen() && client2.isOpen())){
|
||||
if(client2.isOpen()) pool.addFirst(client2);
|
||||
if(client1.isOpen()) pool.addFirst(client1);
|
||||
return referee;
|
||||
}
|
||||
|
||||
//获取双方的阵型
|
||||
GPlayerTacticalController tacticalController = SpringBeanUtils.getBean(GPlayerTacticalController.class);
|
||||
GPlayerPetController petController = SpringBeanUtils.getBean(GPlayerPetController.class);
|
||||
|
||||
String leftTactical = tacticalController.getInfo(client1.player).data.getTacticalData();
|
||||
String rightTactical = tacticalController.getInfo(client2.player).data.getTacticalData();
|
||||
|
||||
|
||||
//如果有人阵法是默认 则 不开始
|
||||
if (leftTactical.equals(tacticalController.InitTactical) || rightTactical.equals(tacticalController.InitTactical)){
|
||||
if(leftTactical.equals(tacticalController.InitTactical)){
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_MESSAGE, GPVPMessage.GPVPText.newBuilder().setText("你的阵法没有宠物~").build());
|
||||
}else{
|
||||
//加入回列表
|
||||
pool.addFirst(client1);
|
||||
}
|
||||
if(rightTactical.equals(tacticalController.InitTactical)){
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_MESSAGE, GPVPMessage.GPVPText.newBuilder().setText("你的阵法没有宠物~").build());
|
||||
}else{
|
||||
//加入回列表
|
||||
pool.addFirst(client2);
|
||||
}
|
||||
return referee;
|
||||
}
|
||||
|
||||
//构建匹配信息
|
||||
GPVPMessage.GPVPStart.Builder builder = GPVPMessage.GPVPStart.newBuilder()
|
||||
.setLeftPlayerId(client1.player.getPlayerId())
|
||||
.setRightPlayerId(client2.player.getPlayerId())
|
||||
.setLeftTactical(leftTactical)
|
||||
.setRightTactical(rightTactical);
|
||||
//构建玩家宠物列表
|
||||
petController.getPetList(client1.player).data.forEach(pet -> {
|
||||
builder.putLeftPets(pet.getPetId(), JSONUtil.toJsonStr(pet));
|
||||
});
|
||||
petController.getPetList(client2.player).data.forEach(pet -> {
|
||||
builder.putLeftPets(pet.getPetId(), JSONUtil.toJsonStr(pet));
|
||||
});
|
||||
|
||||
//取消等待
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
|
||||
GPVPMessage.GPVPStart info = builder.build();
|
||||
|
||||
//PVP 开始
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_START, info);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_START, info);
|
||||
|
||||
//PVP 裁决
|
||||
onPVPReferee(referee,info);
|
||||
|
||||
return null; //返回空则占用 需要 手动释放
|
||||
}))){
|
||||
System.out.println("匹配失败 暂无裁决者空闲");
|
||||
//如果获取不到裁决 则 返回
|
||||
return;
|
||||
}
|
||||
|
||||
//构建匹配信息
|
||||
GPVPMessage.GPVPStart.Builder builder = GPVPMessage.GPVPStart.newBuilder()
|
||||
.setLeftTactical(leftTactical)
|
||||
.setRightTactical(rightTactical);
|
||||
//构建玩家宠物列表
|
||||
petController.getPetList(client1.player).data.forEach(pet -> {
|
||||
builder.putLeftPets(pet.getPetId(), JSONUtil.toJsonStr(pet));
|
||||
});
|
||||
petController.getPetList(client2.player).data.forEach(pet -> {
|
||||
builder.putLeftPets(pet.getPetId(), JSONUtil.toJsonStr(pet));
|
||||
});
|
||||
|
||||
|
||||
|
||||
//取消等待
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_END_WAIT);
|
||||
|
||||
GPVPMessage.GPVPStart info = builder.build();
|
||||
|
||||
//PVP 开始
|
||||
client1.invoke(GActionEnum.C_MODE_PVP_START, info);
|
||||
client2.invoke(GActionEnum.C_MODE_PVP_START, info);
|
||||
|
||||
//发送裁决
|
||||
GRefereeAction.onPVPReferee(info);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//裁决PVP
|
||||
public static void onPVPReferee(GRefereeClient referee,GPVPMessage.GPVPStart info){
|
||||
//如果有裁决员则向裁决员发送要裁决的信息
|
||||
referee.invoke(GActionEnum.CR_REFEREE_PVP_MODE,info);
|
||||
}
|
||||
|
||||
//裁决结束返回
|
||||
@NActionMethod(GActionEnum.CR_REFEREE_PVP_END)
|
||||
public static void onPVPRefereeEnd(GPVPMessage.GPVPRefereeInfo info,GRefereeClient referee){
|
||||
|
||||
System.out.println("获胜的玩家是:"+info.getWinnerId());
|
||||
//裁决结束 等待下次裁决
|
||||
referee.isReferee = false;
|
||||
|
||||
}
|
||||
|
||||
//通知玩家等待定时器
|
||||
public static void onWaitTimer(){
|
||||
//向所有玩家发送等待
|
||||
|
@ -74,9 +74,10 @@ public class WebSocket {
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(Session session, InputStream inputStream){
|
||||
GClient client = CLIENTS.get(session.getId());
|
||||
GClient referee = REFEREES.get(session.getId());
|
||||
JNetwork.onMessage(inputStream,client,client,referee,CLIENTS,client.user,client.player);
|
||||
GClient client;
|
||||
if(Objects.isNull(client = CLIENTS.get(session.getId())))
|
||||
client = REFEREES.get(session.getId());
|
||||
JNetwork.onMessage(inputStream,client,client,CLIENTS,client.user,client.player);
|
||||
}
|
||||
|
||||
@OnClose
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,8 @@ message GPVPStart {
|
||||
map<int64, string> leftPets = 2; //左边的宠物 key:宠物Id value 宠物配置Id
|
||||
string rightTactical = 3; //右边的布阵
|
||||
map<int64, string> rightPets = 4; //右边的宠物 key:宠物Id value 宠物配置Id
|
||||
int64 leftPlayerId = 5; //左边的玩家Id
|
||||
int64 rightPlayerId = 6; //右边的玩家Id
|
||||
}
|
||||
|
||||
//PVP 消息提示
|
||||
@ -16,4 +18,10 @@ message GPVPText {
|
||||
string text = 1; //消息提示
|
||||
}
|
||||
|
||||
//PVP 裁决结束返回
|
||||
message GPVPRefereeInfo{
|
||||
//获胜玩家Id
|
||||
int64 winnerId = 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
// const URL = "http://192.168.0.174:7457/web-desktop/web-desktop/index.html"
|
||||
// const express = require("express");
|
||||
// const app = express();
|
||||
const URL = "http://192.168.1.23:7456/web-desktop/web-desktop-001/index.html"
|
||||
const URL = "http://192.168.0.123:7457/web-desktop/web-desktop/index.html"
|
||||
|
||||
// const runCocos = () => {
|
||||
const { JSDOM,ResourceLoader } = require('jsdom')
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
const axios = require('axios').default;
|
||||
const WebGL = require('gl');
|
||||
const { request } = require('express');
|
||||
const WebGLRenderingContext = WebGL.WebGLRenderingContext;
|
||||
@ -44,6 +44,7 @@ fetch(URL).then(res => res.text()).then(html => {
|
||||
window.fetch = fetch;
|
||||
window.GUser = "100000";
|
||||
window.GPassworld = "123456";
|
||||
window['axios'] = axios;
|
||||
})
|
||||
|
||||
setTimeout(() => {}, 99999999);
|
||||
|
Loading…
x
Reference in New Issue
Block a user