mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Vec2 } from "cc";
|
||||
import GObject from "./base/GObject";
|
||||
import { v3 } from "cc";
|
||||
import { JNFrameInfo } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
|
||||
|
||||
export default class GBaseMode extends GObject<{}> {
|
||||
export default class GBaseMode<T> extends GObject<T> {
|
||||
|
||||
//添加对象到场景中
|
||||
addGObject(obj: GObject<{}>,pos?:Vec2){
|
||||
@@ -14,5 +15,14 @@ export default class GBaseMode extends GObject<{}> {
|
||||
}
|
||||
}
|
||||
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) {
|
||||
|
||||
//重置 场景中的层级
|
||||
[...this.node.children].sort((node1,node2) => node2.worldPosition.y - node1.worldPosition.y).forEach((node,index) => {
|
||||
node.setSiblingIndex(index);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,11 +3,14 @@ import { JNGSyncProtoBase } from "../../App";
|
||||
import GBaseMode from "../GBaseMode";
|
||||
import { v2 } from "cc";
|
||||
|
||||
export enum GTowards{
|
||||
RIGHT,LEFT
|
||||
}
|
||||
|
||||
export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
|
||||
//当前模式
|
||||
_mode:GBaseMode;
|
||||
_mode:GBaseMode<{}>;
|
||||
|
||||
//是否镜像
|
||||
_isMirror:boolean = false;
|
||||
@@ -23,10 +26,10 @@ export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
this._isMirror = value;
|
||||
}
|
||||
|
||||
get mode():GBaseMode{
|
||||
get mode():GBaseMode<{}>{
|
||||
return this._mode;
|
||||
}
|
||||
set mode(value:GBaseMode){
|
||||
set mode(value:GBaseMode<{}>){
|
||||
this._mode = value;
|
||||
}
|
||||
|
||||
@@ -52,5 +55,14 @@ export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
}
|
||||
}
|
||||
|
||||
//设置朝向
|
||||
setTowards(towards:GTowards){
|
||||
if(towards == GTowards.LEFT){
|
||||
this.isMirror = true;
|
||||
}else{
|
||||
this.isMirror = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import GRoleUtil from "../../../util/GRoleUtil";
|
||||
import { GRoleUtil } from "../../../entity/GRole";
|
||||
import GRoleBase from "../../role/GRoleBase";
|
||||
import GRolePVPEntity from "../../role/PVP/GRolePVPEntity";
|
||||
import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { Vec2 } from "cc";
|
||||
import GRoleBase from "../../../role/GRoleBase";
|
||||
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../../GFSMBase";
|
||||
import GRoleUtil from "../../../../util/GRoleUtil";
|
||||
import { GRoleUtil } from "../../../../entity/GRole";
|
||||
|
||||
|
||||
//流程枚举
|
||||
@@ -39,7 +39,7 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
title:"寻找敌人",
|
||||
execute: this.onSeekEnemyProcess.bind(this),
|
||||
// to:[ProcessEnum.MoveToAttackRange], //移动到可攻击范围
|
||||
to:[ProcessEnum.MoveToAttackRange], //移动到可攻击范围
|
||||
to:[ProcessEnum.MoveToAttackRange,ProcessEnum.MoveToTactical], //移动到可攻击范围
|
||||
},
|
||||
[ProcessEnum.MoveToAttackRange]:{
|
||||
title:"移动到可攻击范围",
|
||||
@@ -51,12 +51,13 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
title:"攻击敌人",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onAttackProcess.bind(this),
|
||||
to:[ProcessEnum.MoveToTactical],//移动回阵型
|
||||
to:[ProcessEnum.SeekEnemy],//移动回阵型
|
||||
},
|
||||
[ProcessEnum.MoveToTactical]:{
|
||||
title:"移动回阵型",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onMoveToTacticalProcess.bind(this),
|
||||
to:[ProcessEnum.SeekEnemy],//移动回阵型
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +83,14 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
if((this._enemy = GRoleUtil.get(this.onSeekEnemy())) && this.enemy){
|
||||
//如果有敌人 直接 攻击
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
}else{
|
||||
//如果没有敌人则回去
|
||||
if(!(this.player.tacticalPos.equals(this.player.v2World))){
|
||||
return ProcessEnum.MoveToTactical
|
||||
}else{
|
||||
return GFSMProcessEnum.Reset;
|
||||
}
|
||||
}
|
||||
|
||||
//负责继续寻敌
|
||||
return GFSMProcessEnum.Reset;
|
||||
|
||||
}
|
||||
|
||||
@@ -120,8 +125,9 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
this.player.fsmAnim.isAttack = false;
|
||||
|
||||
if(this.player.onMoveTarget(this.player.tacticalPos,dt)){
|
||||
//回到阵容 重置
|
||||
return GFSMProcessEnum.Reset;
|
||||
this.player.onRecoverTacticalTowards();
|
||||
//回到阵容 搜索敌人
|
||||
return ProcessEnum.SeekEnemy;
|
||||
}
|
||||
|
||||
return GFSMProcessEnum.Wait;
|
||||
@@ -137,7 +143,7 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
if(this.enemy){
|
||||
return GFSMProcessEnum.Wait;
|
||||
}else{
|
||||
return ProcessEnum.MoveToTactical;
|
||||
return ProcessEnum.SeekEnemy;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { _decorator, sp } from "cc";
|
||||
import GObject from "../GObject";
|
||||
import GObject, { GTowards } from "../GObject";
|
||||
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import GFSMBattle from "../fsm/base/GFSMBattle/GFSMBattle";
|
||||
import { GFSMBattleAmin, GFSMBattleAminEnum } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
@@ -8,6 +8,8 @@ import { v3 } from "cc";
|
||||
import { GTactical } from "../../entity/GTactical";
|
||||
import { JEasing, JTween } from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/tween/JNFrameTween";
|
||||
import { v2 } from "cc";
|
||||
import GRole from "../../entity/GRole";
|
||||
import { app } from "../../../App";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum GRoleAnimEvent{
|
||||
@@ -20,6 +22,9 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
@property(sp.Skeleton)
|
||||
spine:sp.Skeleton;
|
||||
|
||||
//角色
|
||||
role:GRole
|
||||
|
||||
//状态机
|
||||
fsm:GFSMBattle;
|
||||
|
||||
@@ -35,7 +40,12 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
//在阵容中的下标
|
||||
tacticalIndex:number;
|
||||
//阵容
|
||||
tactical:GTactical;
|
||||
_tactical:GTactical;
|
||||
get tactical(){return this._tactical};
|
||||
set tactical(value:GTactical){
|
||||
this.setTowards(value.towards);
|
||||
this._tactical = value;
|
||||
}
|
||||
//阵容位置
|
||||
_tacticalPos:Vec2;
|
||||
get tacticalPos(){ return this._tacticalPos}
|
||||
@@ -67,6 +77,8 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
this.node.removeFromParent();
|
||||
return;
|
||||
}
|
||||
|
||||
this.bind(this.role);
|
||||
|
||||
//创建角色状态机
|
||||
this.fsm = this.fsmCreate();
|
||||
@@ -80,15 +92,24 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
}
|
||||
|
||||
//设置角色
|
||||
bind(role:GRole){
|
||||
if(this.spine)
|
||||
this.spine.skeletonData = app.role.skData[role.id];
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
//创建一个状态机
|
||||
protected abstract fsmCreate():GFSMBattle;
|
||||
//创建一个动画状态机
|
||||
protected abstract fsmAnimCreate():GFSMBattleAmin;
|
||||
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T){
|
||||
|
||||
//更新状态机
|
||||
this.fsm && this.fsm.onUpdate(dt / 1000);
|
||||
this.fsmAnim && this.fsmAnim.onUpdate(dt / 1000);
|
||||
|
||||
}
|
||||
|
||||
//向目标点移动
|
||||
@@ -98,6 +119,16 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
let mins = this.v2World.subtract(target);
|
||||
let normal = this.v2World.subtract(target).normalize();
|
||||
|
||||
//设置朝向
|
||||
if(normal.x != 0){
|
||||
if(normal.x < 0){
|
||||
this.setTowards(GTowards.RIGHT)
|
||||
}else{
|
||||
this.setTowards(GTowards.LEFT)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(Vec2.len(normal) >= Vec2.len(mins)){
|
||||
this.node.setWorldPosition(Object.assign(v3(),target.clone()));
|
||||
return true;
|
||||
@@ -112,7 +143,7 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
//攻击
|
||||
onAttack(){
|
||||
//敌人扣血
|
||||
this.fsm.enemy.onHit();
|
||||
this.fsm.enemy?.onHit();
|
||||
}
|
||||
|
||||
//受击
|
||||
@@ -145,6 +176,11 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
}
|
||||
|
||||
//恢复阵容朝向
|
||||
onRecoverTacticalTowards(){
|
||||
this.setTowards(this.tactical.towards);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,13 +2,14 @@ import { _decorator } from "cc";
|
||||
import GRoleBase from "../GRoleBase";
|
||||
import GFSMBase from "../../fsm/GFSMBase";
|
||||
import GFSMPVP from "../../fsm/PVP/GFSMPVP";
|
||||
import GPVPMode, { GPVPModePlayerEnum } from "../../../PVP/GPVPMode";
|
||||
import GPVPMode, { GPVPModePlayerEnum } from "../../../modes/GPVPMode";
|
||||
import { GTactical } from "../../../entity/GTactical";
|
||||
import { GFSMBattleAmin } from "../../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { JNFrameInfo } from "../../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import { Vec2 } from "cc";
|
||||
import { v2 } from "cc";
|
||||
import { ProgressBar } from "cc";
|
||||
import { GTowards } from "../../GObject";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export interface GDemoMessage{
|
||||
@@ -26,12 +27,6 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
return this._ones;
|
||||
}
|
||||
set ones(value:GPVPModePlayerEnum){
|
||||
//如果是敌方则设置镜像
|
||||
if(value == GPVPModePlayerEnum.ENEMY){
|
||||
this.isMirror = true;
|
||||
}else{
|
||||
this.isMirror = false;
|
||||
}
|
||||
this._ones = value;
|
||||
}
|
||||
|
||||
@@ -66,6 +61,7 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
this._mode = value;
|
||||
}
|
||||
|
||||
|
||||
protected fsmCreate(): GFSMPVP {
|
||||
return new GFSMPVP(this);
|
||||
}
|
||||
|
37
JisolGameCocos/assets/script/battle/entity/GRole.ts
Normal file
37
JisolGameCocos/assets/script/battle/entity/GRole.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { TableGRole } from "../../../resources/config/ts/TableGRole";
|
||||
import GRoleBase from "../base/role/GRoleBase";
|
||||
|
||||
//角色实体类
|
||||
export default interface GRole {
|
||||
id:number; //宠物Id
|
||||
}
|
||||
|
||||
//角色工具类
|
||||
export class GRoleUtil{
|
||||
|
||||
//获取存活的玩家 如果不存活则返回 null
|
||||
static get<T>(player:GRoleBase<T>):() => GRoleBase<T>{
|
||||
if(!player) return null;
|
||||
return ():GRoleBase<T> => {
|
||||
if(player)
|
||||
return player.get();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//通过Id 获取 GRole
|
||||
static getGRole(id:number):GRole{
|
||||
let info:TableGRole;
|
||||
if(!(info = TableGRole.getConfig(id))) return null;
|
||||
return {
|
||||
id:info.id
|
||||
}
|
||||
}
|
||||
|
||||
static getGRoles(ids:number[]):GRole[]{
|
||||
return ids.map(id => GRoleUtil.getGRole(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9215634b-6c3f-47a2-a303-04408eb3e053",
|
||||
"uuid": "ff6b5bb7-5bda-42bb-bf4c-0d91a7627524",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
@@ -1,11 +1,15 @@
|
||||
import { v2 } from "cc";
|
||||
import { Vec2 } from "cc";
|
||||
import { GTowards } from "../base/GObject";
|
||||
|
||||
//阵法类
|
||||
export class GTactical{
|
||||
|
||||
tactical:number[][];
|
||||
|
||||
//阵容朝向
|
||||
towards:GTowards;
|
||||
|
||||
//阵法位置
|
||||
static pos:Vec2[][] = [
|
||||
[v2(-100,150),v2(0,150),v2(100,150)],
|
||||
@@ -13,19 +17,21 @@ export class GTactical{
|
||||
[v2(-100,-150),v2(0,-150),v2(100,-150)],
|
||||
];
|
||||
|
||||
constructor(tactical:number[][]){
|
||||
constructor(tactical:number[][],towards:GTowards = GTowards.RIGHT){
|
||||
this.tactical = tactical;
|
||||
this.towards = towards;
|
||||
}
|
||||
|
||||
//获取阵法
|
||||
static getTactical(isReversed:boolean = false): GTactical{
|
||||
let tactical = [
|
||||
[0,0,3],
|
||||
[0,4,3],
|
||||
[0,0,1],
|
||||
[0,0,2],
|
||||
[0,5,2],
|
||||
];
|
||||
if(isReversed){
|
||||
tactical = this.getTacticalFlipX(tactical);
|
||||
return new GTactical(tactical,GTowards.LEFT);
|
||||
}
|
||||
return new GTactical(tactical);
|
||||
}
|
||||
@@ -38,6 +44,7 @@ export class GTactical{
|
||||
];
|
||||
if(isReversed){
|
||||
tactical = this.getTacticalFlipX(tactical);
|
||||
return new GTactical(tactical,GTowards.LEFT);
|
||||
}
|
||||
return new GTactical(tactical);
|
||||
}
|
||||
@@ -51,6 +58,7 @@ export class GTactical{
|
||||
];
|
||||
if(isReversed){
|
||||
tactical = this.getTacticalFlipX(tactical);
|
||||
return new GTactical(tactical,GTowards.LEFT);
|
||||
}
|
||||
return new GTactical(tactical);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "ca2cc88c-3cee-4223-927a-3a5ca27ffee3",
|
||||
"uuid": "e8874608-a5f4-47c8-8b57-6ff186b7ec2b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
10
JisolGameCocos/assets/script/battle/modes/GLDLEMode.ts
Normal file
10
JisolGameCocos/assets/script/battle/modes/GLDLEMode.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import GBaseMode from "../GBaseMode";
|
||||
|
||||
|
||||
/**
|
||||
* 挂机模式
|
||||
*/
|
||||
export default class GLDLEMode extends GBaseMode<{}>{
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c579d727-c0c2-422f-8571-3375047fd1b8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -5,6 +5,7 @@ import { Prefab } from "cc";
|
||||
import { instantiate } from "cc";
|
||||
import { Vec2 } from "cc";
|
||||
import GRolePVPEntity from "../base/role/PVP/GRolePVPEntity";
|
||||
import GRole, { GRoleUtil } from "../entity/GRole";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
@@ -20,22 +21,22 @@ export interface GPVPModePlayerInfo{
|
||||
//阵法
|
||||
tactical: GTactical;
|
||||
//宠物列表
|
||||
roles: any[];
|
||||
roles: GRole[];
|
||||
}
|
||||
|
||||
/**
|
||||
* PVP 模式
|
||||
*/
|
||||
@ccclass('GPVPMode')
|
||||
export default class GPVPMode extends GBaseMode{
|
||||
export default class GPVPMode extends GBaseMode<{}>{
|
||||
|
||||
@property(Prefab)
|
||||
rolePrefab: Prefab = null;
|
||||
|
||||
//玩家信息
|
||||
playerInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical1(),roles: [{},{},{}] };
|
||||
playerInfo: GPVPModePlayerInfo;
|
||||
//敌方信息
|
||||
enemyInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical2(true),roles: [{},{},{}] };
|
||||
enemyInfo: GPVPModePlayerInfo;
|
||||
|
||||
//玩家宠物
|
||||
playerRoles: GRolePVPEntity[] = [];
|
||||
@@ -47,25 +48,33 @@ export default class GPVPMode extends GBaseMode{
|
||||
//敌方位置
|
||||
enemyPos: Vec2 = new Vec2(400,0);
|
||||
|
||||
onLoad(){
|
||||
super.onLoad();
|
||||
}
|
||||
|
||||
|
||||
onSyncInitSuccess(): void {
|
||||
|
||||
//初始化战斗
|
||||
console.log("GPVPMode 模式初始化");
|
||||
|
||||
this.playerInfo = { tactical: GTactical.getTactical(),roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10001]) };
|
||||
this.enemyInfo = { tactical: GTactical.getTactical(true),roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10001]) };
|
||||
|
||||
//生成玩家
|
||||
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1))
|
||||
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.ENEMY,index+1))
|
||||
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1,info))
|
||||
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.ENEMY,index+1,info))
|
||||
|
||||
}
|
||||
|
||||
//生成角色
|
||||
onGenRole(type: GPVPModePlayerEnum,index:number) {
|
||||
onGenRole(type: GPVPModePlayerEnum,index:number,info:GRole) {
|
||||
|
||||
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
|
||||
if(!pos) return;
|
||||
let role = instantiate(this.rolePrefab);
|
||||
let entity = role.getComponent(GRolePVPEntity)
|
||||
entity.bind(info);
|
||||
//赋值阵容
|
||||
entity.ones = type;
|
||||
entity.tactical = this.getInfo(type).tactical;
|
||||
@@ -120,8 +129,12 @@ export default class GPVPMode extends GBaseMode{
|
||||
|
||||
//销毁角色数据
|
||||
killRole(role:GRolePVPEntity){
|
||||
this.playerRoles.splice(this.playerRoles.indexOf(role),1);
|
||||
this.enemyRoles.splice(this.enemyRoles.indexOf(role),1);
|
||||
let index = this.playerRoles.indexOf(role);
|
||||
if(index >= 0)
|
||||
this.playerRoles.splice(index,1);
|
||||
index = this.enemyRoles.indexOf(role);
|
||||
if(index >= 0)
|
||||
this.enemyRoles.splice(index,1);
|
||||
}
|
||||
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
import GRoleBase from "../base/role/GRoleBase";
|
||||
|
||||
|
||||
//角色工具类
|
||||
export default class GRoleUtil{
|
||||
|
||||
//获取存活的玩家 如果不存活则返回 null
|
||||
static get<T>(player:GRoleBase<T>):() => GRoleBase<T>{
|
||||
if(!player) return null;
|
||||
return ():GRoleBase<T> => {
|
||||
if(player)
|
||||
return player.get();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user