This commit is contained in:
PC-20230316NUNE\Administrator
2023-10-23 18:56:01 +08:00
parent ac94959a45
commit 77d44ee300
328 changed files with 16429 additions and 2 deletions

View File

@@ -0,0 +1,112 @@
import { BehaviorManager } from "../../extensions/Behavior Creator/runtime/main";
import JNSocket from "../../extensions/ngame/assets/ngame/network/JNSocket";
import { JNSyncAction } from "../../extensions/ngame/assets/ngame/sync/JNSyncAction";
import { JNSyncMessage } from "../../extensions/ngame/assets/ngame/sync/JNSyncMessage";
import JNSyncFrame, { JNFrameInfo, JNFrameInfos, JNFrameInputs } from "../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import JNSyncFrameComponent from "../../extensions/ngame/assets/ngame/sync/frame/game/JNSyncFrameComponent";
import JNSyncFrameProtoComponent from "../../extensions/ngame/assets/ngame/sync/frame/game/JNSyncFrameProtoComponent";
import JNLayer, { JNLayerAnim, JNLayerInfo } from "../../extensions/ngame/assets/ngame/ui/JNLayer";
import JNLayerBase from "../../extensions/ngame/assets/ngame/ui/base/JNLayerBase";
import { EventDispatcher } from "../../extensions/ngame/assets/ngame/util/EventDispatcher";
import NGameMessage from "../../extensions/ngame/assets/ngame/util/NGameMessage";
import axios from "../../extensions/ngame/assets/plugins/axios.js";
import GBattleModeManager from "./battle/GBattleModeManager";
import { GLayer, UIConfig } from "./ui/UIConfig";
//重写UI
class JNGLayer extends JNLayer{
layers: string[] = [GLayer.View];
views: { [key: string]: JNLayerInfo; } = UIConfig;
}
//重写Socket
class JNGSocket extends JNSocket{
public url() {
return "ws://192.168.0.127:8080/websocket";
}
}
// 重写帧同步
class JNGSyncFrame extends JNSyncFrame{
//更新
protected onUpdate(): JNFrameInfo {
let info = super.onUpdate();
if(info){
//更新状态机
BehaviorManager.getInstance().tick(this.dt);
}
return info;
}
protected onResetValue(){
//重置状态机
BehaviorManager.deleteInstance();
super.onResetValue();
}
async onServerData(start?:number,end?:number): Promise<JNFrameInfos> {
return app.proto
.getType(JNSyncMessage.JNFrameInfos)
.decode(
new Uint8Array(
(await app.api.get("/sync/frame",{
responseType:'arraybuffer',
params:{
start,
end
}
})).data
)
) as any;
}
onSendInput(message: JNFrameInputs) {
app.socket.Send(JNSyncAction.NSyncFrameInput,message,JNSyncMessage.JNFrameInputs);
}
}
//重写UI Base
export class JNGLayerBase extends JNLayerBase{
public close():void {
console.log("close");
app.layer.CloseNode(this.node);
}
}
//重写Sync Base
export class JNGSyncBase<T> extends JNSyncFrameComponent<T>{
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) { }
protected getSync(): JNSyncFrame {
return app.sync
}
}
//重写Sync Proto Base
export abstract class JNGSyncProtoBase<T> extends JNSyncFrameProtoComponent<T>{
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) { }
protected getSync(): JNSyncFrame {
return app.sync
}
}
export const app = {
layer : new JNGLayer(), //UI
socket : new JNGSocket(), //Socket
sync : new JNGSyncFrame(), //同步
event : EventDispatcher.getIns(), //通知
proto : NGameMessage.getIns(), //消息
api : axios.create({
baseURL: "http://192.168.0.127:8080",
}), //请求
battle : GBattleModeManager.getIns(), //战斗
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5731a7ad-a5c5-435f-8721-db5d0b231aaf",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,33 @@
import { _decorator, Component, director, instantiate, Node, Prefab } from 'cc';
import { app } from './App';
import { JNGame } from '../../extensions/ngame/assets/ngame/JNGame';
import { JNSyncAction } from '../../extensions/ngame/assets/ngame/sync/JNSyncAction';
const { ccclass, property } = _decorator;
@ccclass('Main')
export class Main extends Component {
@property(Prefab)
UIPrefab: Prefab = null;
@property(Prefab)
WorldPrefab: Prefab = null;
async onLoad(){
//加载 APP
await JNGame.Init(app);
//发生帧同步开始
app.socket.Send(JNSyncAction.NSyncFrameStart);
// 创建UI
director.getScene().addChild(instantiate(this.UIPrefab));
// 创建世界
director.getScene().addChild(instantiate(this.WorldPrefab));
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1e0e111f-b198-4e39-90e5-a7e20532bc80",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,24 @@
import { _decorator, Component, Node } from 'cc';
import { app } from './App';
import { GUI } from './ui/UIConfig';
const { ccclass, property } = _decorator;
@ccclass('UICanvas')
export class UICanvas extends Component {
@property(Node)
root:Node;
protected onLoad(): void {
//绑定层级
app.layer.bind(this.root);
//显示Home
app.layer.Open(GUI.Home);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "34651639-1d20-4741-9cdf-13e4fde10355",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,55 @@
import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { JNFrameInfo, JNSyncFrameEvent } from '../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame';
import { app } from './App';
import { JNSyncAction } from '../../extensions/ngame/assets/ngame/sync/JNSyncAction';
import { Camera } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('WorldCanvas')
export class WorldCanvas extends Component {
@property(Node)
root:Node = null;
@property(Camera)
camera:Camera = null;
@property(Prefab)
prefab:Prefab = null;
async onLoad(){
//重置相机位置
this.camera.node.setWorldPosition(0,0,1000);
//监听帧同步
app.event.on(JNSyncFrameEvent.CLEAR,this.clear,this);
app.event.on(JNSyncFrameEvent.CREATE,this.create,this);
//监听帧回调
app.socket.on(JNSyncAction.NSyncFrameBack,this.onFrameBack,this,"JNFrameInfo");
app.sync.onReset();
app.sync.onStart();
}
//清除世界
clear(){
this.root.removeAllChildren();
}
//创建世界
create(){
this.root.addChild(instantiate(this.prefab))
}
update(deltaTime: number) {
app.sync.update(deltaTime);
}
onFrameBack(info:JNFrameInfo){
app.sync.addFrame(info,true);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "40653af9-3902-4f15-97fb-71347a8421d7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "cb339af5-3d29-4bb0-a9c8-e80c5ea885e2",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,17 @@
import { Vec2 } from "cc";
import GObject from "./base/GObject";
import { v3 } from "cc";
export default class GBaseMode extends GObject<{}> {
//添加对象到场景中
addGObject(obj: GObject<{}>,pos?:Vec2){
this.node.addChild(obj.node);
if(pos){
obj.node.setWorldPosition(v3(pos.x,pos.y,0));
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4ec90971-34c8-4746-b0c6-af2dbfb23ec4",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,14 @@
import Singleton from "../../../extensions/ngame/assets/ngame/util/Singleton";
export enum BattleMode{
//PVP 模式
PVP,
}
//全局战斗模式管理器
export default class GBattleModeManager extends Singleton {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9e4513c8-8f5d-4fb7-a210-106d50d4a7c6",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "ca2cc88c-3cee-4223-927a-3a5ca27ffee3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,87 @@
import { _decorator } from "cc";
import GBaseMode from "../GBaseMode";
import { GTactical } from "../entity/GTactical";
import { Prefab } from "cc";
import GRoleEntity from "../base/role/impl/GRoleEntity";
import { instantiate } from "cc";
import { Vec2 } from "cc";
const { ccclass, property } = _decorator;
//PVP 角色
export enum GPVPModePlayerEnum{
PLAYER, //玩家
ENEMY, //敌人
}
//PVP 玩家信息
export interface GPVPModePlayerInfo{
//阵法
tactical: GTactical;
//宠物列表
roles: any[];
}
/**
* PVP 模式
*/
@ccclass('GPVPMode')
export default class GPVPMode extends GBaseMode{
@property(Prefab)
rolePrefab: Prefab = null;
//玩家信息
playerInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical1(),roles: [{},{},{}] };
//敌方信息
enemyInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical2(true),roles: [{},{},{}] };
//玩家宠物
playerRoles: GRoleEntity[] = [];
//敌方宠物
enemyRoles: GRoleEntity[] = [];
//玩家位置
playerPos: Vec2 = new Vec2(-400,0);
//敌方位置
enemyPos: Vec2 = new Vec2(400,0);
onSyncInitSuccess(): void {
//初始化战斗
console.log("GPVPMode 模式初始化");
//生成玩家
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1))
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.ENEMY,index+1))
}
//生成角色
onGenRole(type: GPVPModePlayerEnum,index:number) {
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
if(!pos) return;
let role = instantiate(this.rolePrefab);
let entity = role.getComponent(GRoleEntity)
this.addGObject(entity,this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type)));
}
//获取配置
getInfo(type: GPVPModePlayerEnum): GPVPModePlayerInfo {
if(type == GPVPModePlayerEnum.PLAYER) return this.playerInfo;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyInfo;
}
//获取位置
getTacticalPos(type: GPVPModePlayerEnum):Vec2{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerPos;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyPos;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "31e6d29e-41d4-4d7d-a24a-b37f9c0caabd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "4a00fcca-5d44-43da-a085-2aece0aaf683",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,7 @@
import { JNGSyncProtoBase } from "../../App";
export default class GObject<T> extends JNGSyncProtoBase<T>{
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "465eb18e-e84c-4cbf-930f-9490c5f51510",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a178786e-130e-4422-b7cd-1fab35d66c76",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,6 @@
//状态机基类
export default abstract class GFSMBase{
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6b762164-9367-4f6b-a168-8b715ac9d5b5",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "03218a59-18c0-42bc-aa22-117d45bc314a",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
import GFSMBase from "../GFSMBase";
//角色状态机实现
export default class GFSMRoleController extends GFSMBase{
//状态机更新
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bf6010d3-4d2e-4ecf-abc4-a4e770ebd5df",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "4c6a60ae-2e26-4c45-8d64-1d7a9b32e7be",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,27 @@
import { _decorator, sp } from "cc";
import { JNGSyncProtoBase } from "../../../App";
import GObject from "../GObject";
import { BehaviorStatus } from "../../../../../extensions/Behavior Creator/runtime/main";
const { ccclass, property } = _decorator;
//角色基类
export default abstract class GRoleBase<T> extends GObject<T>{
@property(sp.Skeleton)
spine:sp.Skeleton;
onLoad(){
super.onLoad();
if(!this.spine) this.spine = this.node.getComponent(sp.Skeleton);
//如果没有生成则直接销毁
this.node.removeFromParent();
}
//攻击
public onAttack(data){
return BehaviorStatus.Success;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "15e9145c-4eb8-485d-99eb-6d709b3991e7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "b2af28db-e925-419f-81b8-3bf755a3224f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,16 @@
import { _decorator } from "cc";
import GRoleBase from "../GRoleBase";
const { ccclass, property } = _decorator;
/**
* 基础实现
*/
@ccclass('GRoleEntity')
export default class GRoleEntity extends GRoleBase<{}> {
onLoad(){
super.onLoad();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c6d20914-49fe-45ea-9bf2-750de7cc7ed2",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "5edb3581-4314-4923-8efb-b0b37d182533",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,78 @@
import { v2 } from "cc";
import { Vec2 } from "cc";
//阵法类
export class GTactical{
tactical:number[][];
//阵法位置
static pos:Vec2[][] = [
[v2(-100,150),v2(0,150),v2(100,150)],
[v2(-100,0),v2(0,0),v2(100,0)],
[v2(-100,-150),v2(0,-150),v2(100,-150)],
];
constructor(tactical:number[][]){
this.tactical = tactical;
}
//获取阵法
static getTactical(isReversed:boolean = false): GTactical{
let tactical = [
[0,0,3],
[0,0,1],
[0,0,2],
];
if(isReversed){
tactical = this.getTacticalFlipX(tactical);
}
return new GTactical(tactical);
}
//获取阵法
static getTactical1(isReversed:boolean = false): GTactical{
let tactical = [
[0,3,0],
[0,1,0],
[0,2,0],
];
if(isReversed){
tactical = this.getTacticalFlipX(tactical);
}
return new GTactical(tactical);
}
//获取阵法
static getTactical2(isReversed:boolean = false): GTactical{
let tactical = [
[0,0,3],
[0,1,0],
[2,0,0],
];
if(isReversed){
tactical = this.getTacticalFlipX(tactical);
}
return new GTactical(tactical);
}
//阵法取反
static getTacticalFlipX(tactical:number[][]){
return tactical.map(row => row.reverse());
}
//返回阵法位置
getPosition(index:number,father:Vec2 = v2(0,0)){
for(let i = 0;i < 3;i++){
for(let j = 0;j < 3;j++){
let tag = this.tactical[i][j];
if(tag == index){
return father.clone().add(GTactical.pos[i][j].clone());
}
}
}
return null;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1b621f7a-3cbd-4165-8a3e-5765f08bf19f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e88419d0-1e3c-41eb-a2eb-751e2819dff8",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "cd3ec3e2-0338-4821-b0b4-77166dea08b0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,17 @@
import { _decorator, Component, Label, Node } from 'cc';
import { app, JNGLayerBase } from '../../App';
const { ccclass, property } = _decorator;
@ccclass('HomeView')
export class HomeView extends JNGLayerBase {
@property(Label)
frameText:Label;
update(){
this.frameText.string = `当前帧数: ${app.sync.frame}`;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "15051ada-4206-4de8-9e48-0a063639f492",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,14 @@
import { JNLayerInfo } from "../../../extensions/ngame/assets/ngame/ui/JNLayer";
export enum GLayer{
View = "View",
}
export enum GUI{
Home = "Home",
}
export const UIConfig:{ [key: string]: JNLayerInfo; } = {
[GUI.Home]:{ layer:GLayer.View, uri: "prefab/ui/Home/HomeView"}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "08b7edc1-2a78-4e26-9de4-2de41a3ac1bd",
"files": [],
"subMetas": {},
"userData": {}
}