mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
update
This commit is contained in:
parent
5998a96d9e
commit
cb70ba12c7
@ -219,8 +219,8 @@
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"g": 61,
|
||||
"b": 61,
|
||||
"a": 255
|
||||
},
|
||||
"_spriteFrame": {
|
||||
@ -425,7 +425,7 @@
|
||||
"__expectedType__": "sp.SkeletonData"
|
||||
},
|
||||
"defaultSkin": "default",
|
||||
"defaultAnimation": "",
|
||||
"defaultAnimation": "walk",
|
||||
"_premultipliedAlpha": true,
|
||||
"_timeScale": 1,
|
||||
"_preCacheMode": 0,
|
||||
|
@ -116,8 +116,12 @@ export default class GPVPMode extends GBaseMode{
|
||||
});
|
||||
return sort[0]
|
||||
|
||||
}
|
||||
|
||||
|
||||
//销毁角色数据
|
||||
killRole(role:GRolePVPEntity){
|
||||
this.playerRoles.splice(this.playerRoles.indexOf(role),1);
|
||||
this.enemyRoles.splice(this.enemyRoles.indexOf(role),1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,20 @@ export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
//当前模式
|
||||
_mode:GBaseMode;
|
||||
|
||||
//是否镜像
|
||||
_isMirror:boolean = false;
|
||||
get isMirror(){
|
||||
return this._isMirror;
|
||||
}
|
||||
set isMirror(value:boolean){
|
||||
if(value){
|
||||
GObject.SetMirror(this);
|
||||
}else{
|
||||
GObject.SetMirror(this,false);
|
||||
}
|
||||
this._isMirror = value;
|
||||
}
|
||||
|
||||
get mode():GBaseMode{
|
||||
return this._mode;
|
||||
}
|
||||
@ -28,5 +42,15 @@ export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
return v2(world.x,world.y);
|
||||
}
|
||||
|
||||
//向后添加距离
|
||||
getWorldBackLen(add:Vec2){
|
||||
if(this.isMirror){
|
||||
return this.v2World.add(add);
|
||||
}else{
|
||||
add.y = 0-add.y;
|
||||
return this.v2World.subtract(add);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,9 @@ export enum GFSMProcessEnum{
|
||||
//状态机基类
|
||||
export default class GFSMBase{
|
||||
|
||||
//是否关闭
|
||||
isClose:boolean = false;
|
||||
|
||||
//状态流程图
|
||||
process:{[key:number]:GFSMProcessInfo} = {};
|
||||
|
||||
@ -38,14 +41,19 @@ export default class GFSMBase{
|
||||
//状态机刷新
|
||||
onUpdate(dt:number){
|
||||
|
||||
if(this.isClose) return;
|
||||
|
||||
if(!this.start) this.start = 0;
|
||||
if(!this.current) this.current = 0;
|
||||
|
||||
//运行流程
|
||||
this.execute(this.process[this.current],dt);
|
||||
|
||||
}
|
||||
|
||||
close(){
|
||||
this.isClose = true;
|
||||
}
|
||||
|
||||
//执行流程
|
||||
execute(process:GFSMProcessInfo,dt:number){
|
||||
if(!process) return;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import GRoleUtil from "../../../util/GRoleUtil";
|
||||
import GRoleBase from "../../role/GRoleBase";
|
||||
import GRolePVPEntity from "../../role/PVP/GRolePVPEntity";
|
||||
import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
|
||||
@ -6,11 +7,13 @@ import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
|
||||
//PVP 状态机
|
||||
export default class GFSMPVP extends GFSMBattle{
|
||||
|
||||
player:GRolePVPEntity;
|
||||
get player(): GRolePVPEntity {
|
||||
return super.player as GRolePVPEntity;
|
||||
}
|
||||
|
||||
constructor(player:GRolePVPEntity){
|
||||
super(player);
|
||||
this.player = player;
|
||||
this._player = GRoleUtil.get(player);
|
||||
}
|
||||
|
||||
//寻敌
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Vec2 } from "cc";
|
||||
import GRoleBase from "../../../role/GRoleBase";
|
||||
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../../GFSMBase";
|
||||
import GRoleUtil from "../../../../util/GRoleUtil";
|
||||
|
||||
|
||||
//流程枚举
|
||||
@ -17,7 +18,20 @@ enum ProcessEnum {
|
||||
|
||||
export default abstract class GFSMBattle extends GFSMBase{
|
||||
|
||||
player:GRoleBase<{}>;
|
||||
protected _player:() => GRoleBase<{}>;
|
||||
get player():GRoleBase<{}>{
|
||||
if(this._player)
|
||||
return this._player();
|
||||
return null;
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
_enemy:() => GRoleBase<any>;
|
||||
get enemy():GRoleBase<{}>{
|
||||
if(this._enemy)
|
||||
return this._enemy();
|
||||
return null;
|
||||
}
|
||||
|
||||
//流程图
|
||||
process: { [key: number]: GFSMProcessInfo; } = {
|
||||
@ -39,19 +53,16 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
execute: this.onAttackProcess.bind(this),
|
||||
to:[ProcessEnum.MoveToTactical],//移动回阵型
|
||||
},
|
||||
// [ProcessEnum.MoveToTactical]:{
|
||||
// title:"移动回阵型",
|
||||
// mode:GFSMProcessMode.WaitExecute,
|
||||
// execute: this.onMoveToTacticalProcess.bind(this),
|
||||
// }
|
||||
[ProcessEnum.MoveToTactical]:{
|
||||
title:"移动回阵型",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onMoveToTacticalProcess.bind(this),
|
||||
}
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
enemy:GRoleBase<any>;
|
||||
|
||||
constructor(player:GRoleBase<{}>){
|
||||
super();
|
||||
this.player = player;
|
||||
this._player = GRoleUtil.get(player);
|
||||
}
|
||||
|
||||
abstract onSeekEnemy():GRoleBase<any>;
|
||||
@ -68,7 +79,7 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
}
|
||||
|
||||
if(this.enemy = this.onSeekEnemy()){
|
||||
if((this._enemy = GRoleUtil.get(this.onSeekEnemy())) && this.enemy){
|
||||
//如果有敌人 直接 攻击
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
}
|
||||
@ -122,7 +133,12 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
//播放移动
|
||||
this.player.fsmAnim.isMove = false;
|
||||
this.player.fsmAnim.isAttack = true;
|
||||
//如果有敌人则攻击 没有 则 重置
|
||||
if(this.enemy){
|
||||
return GFSMProcessEnum.Wait;
|
||||
}else{
|
||||
return ProcessEnum.MoveToTactical;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,8 @@ enum ProcessEnum {
|
||||
Move = 1,
|
||||
//攻击
|
||||
Attack = 2,
|
||||
//死亡
|
||||
Die = 3,
|
||||
}
|
||||
|
||||
//动画状态机基类
|
||||
@ -43,6 +45,9 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
//是否移动
|
||||
isMove:boolean = false;
|
||||
|
||||
//是否死亡
|
||||
isDie:boolean = false;
|
||||
|
||||
//轨道的索引
|
||||
trackIndex:number;
|
||||
|
||||
@ -50,6 +55,7 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
spine:sp.Skeleton;
|
||||
|
||||
events:{event:string,fun:Function}[] = [];
|
||||
starts:{name:string,fun:Function}[] = [];
|
||||
|
||||
constructor(spine:sp.Skeleton,trackIndex?:number){
|
||||
super();
|
||||
@ -57,6 +63,7 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
this.trackIndex = trackIndex || 0;
|
||||
//设置监听
|
||||
this.spine.setEventListener(this.onEventListener.bind(this));
|
||||
this.spine.setStartListener(this.onStartListener.bind(this));
|
||||
}
|
||||
|
||||
//添加事件监听
|
||||
@ -67,6 +74,14 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
})
|
||||
}
|
||||
|
||||
//监听动画开始播放
|
||||
addStartListener(name:string,fun:Function){
|
||||
this.starts.push({
|
||||
name,
|
||||
fun,
|
||||
})
|
||||
}
|
||||
|
||||
onEventListener(entry: sp.spine.TrackEntry, ev: sp.spine.Event){
|
||||
this.events.forEach(item => {
|
||||
if(item.event == ev.data.name){
|
||||
@ -75,6 +90,14 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
});
|
||||
}
|
||||
|
||||
onStartListener(entry: sp.spine.TrackEntry){
|
||||
this.starts.forEach(item => {
|
||||
if(entry.animation.name == item.name){
|
||||
item.fun();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 流程图
|
||||
process: { [key: number]: GFSMProcessAnimInfo; } = {
|
||||
[ProcessEnum.Wait]:{
|
||||
@ -82,10 +105,11 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
isLoop:true,
|
||||
animName:GFSMBattleAminEnum.Wait,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Move,ProcessEnum.Attack],
|
||||
to:[ProcessEnum.Move,ProcessEnum.Attack,ProcessEnum.Die],
|
||||
ifTo:[
|
||||
() => this.isMove, //前往移动
|
||||
() => this.isAttack //前往攻击
|
||||
() => this.isAttack, //前往攻击
|
||||
() => this.isDie,
|
||||
],
|
||||
},
|
||||
[ProcessEnum.Move]:{
|
||||
@ -93,26 +117,36 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
animName:GFSMBattleAminEnum.Walk,
|
||||
isLoop:true,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Attack],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Attack,ProcessEnum.Die],
|
||||
ifTo:[
|
||||
() => !this.isMove, //前往等待
|
||||
() => this.isAttack, //前往攻击
|
||||
() => this.isDie,
|
||||
],
|
||||
},
|
||||
2:{
|
||||
[ProcessEnum.Attack]:{
|
||||
title:"攻击",
|
||||
animName:GFSMBattleAminEnum.Attack,
|
||||
isLoop:true,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Move],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Move,ProcessEnum.Die],
|
||||
ifTo:[
|
||||
() => !this.isAttack, //前往等待
|
||||
() => !this.isAttack && this.isMove, //前往移动
|
||||
() => this.isDie,
|
||||
],
|
||||
},
|
||||
[ProcessEnum.Die]:{
|
||||
title:"死亡",
|
||||
animName:GFSMBattleAminEnum.Fly,
|
||||
isLoop:true,
|
||||
mixs:[0.1,0.1],
|
||||
}
|
||||
}
|
||||
|
||||
execute(process:GFSMProcessAnimInfo,dt:number){
|
||||
process.ifTo = process.ifTo || [];
|
||||
process.to = process.to || [];
|
||||
process.mode = GFSMProcessMode.WaitExecute;
|
||||
process.execute = this.tick.bind(this);
|
||||
super.execute(process,dt);
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { _decorator, sp } from "cc";
|
||||
import GObject from "../GObject";
|
||||
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import GFSMBase from "../fsm/GFSMBase";
|
||||
import GFSMBattle from "../fsm/base/GFSMBattle/GFSMBattle";
|
||||
import { GFSMBattleAmin } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { GFSMBattleAmin, GFSMBattleAminEnum } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { Vec2 } from "cc";
|
||||
import { v2 } from "cc";
|
||||
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";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum GRoleAnimEvent{
|
||||
@ -26,9 +26,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
//动画状态机
|
||||
fsmAnim:GFSMBattleAmin;
|
||||
|
||||
//玩家是否镜像
|
||||
_isMirror:boolean = false;
|
||||
|
||||
//玩家攻击范围
|
||||
range:number = 100;
|
||||
|
||||
@ -48,16 +45,18 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
blood:number = 100;
|
||||
fullBlood:number = 100;
|
||||
|
||||
get isMirror(){
|
||||
return this._isMirror;
|
||||
//是否死亡
|
||||
_isDie:boolean = false;
|
||||
get isDie(){ return this._isDie}
|
||||
set isDie(value:boolean){
|
||||
this._isDie = value;
|
||||
//设置死亡状态
|
||||
this.fsmAnim.isDie = value;
|
||||
}
|
||||
set isMirror(value:boolean){
|
||||
if(value){
|
||||
GObject.SetMirror(this);
|
||||
}else{
|
||||
GObject.SetMirror(this,false);
|
||||
}
|
||||
this._isMirror = value;
|
||||
|
||||
get():GRoleBase<T>{
|
||||
if(this.isDie) return null;
|
||||
return this;
|
||||
}
|
||||
|
||||
onSyncLoad(){
|
||||
@ -76,21 +75,11 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
//监听攻击
|
||||
this.fsmAnim.addEventListener(GRoleAnimEvent.Attack,this.onAttack.bind(this));
|
||||
//监听死亡击飞
|
||||
this.fsmAnim.addStartListener(GFSMBattleAminEnum.Fly,this.onFly.bind(this));
|
||||
|
||||
}
|
||||
|
||||
//攻击
|
||||
onAttack(){
|
||||
//敌人扣血
|
||||
this.fsm.enemy.onHit();
|
||||
}
|
||||
|
||||
//受击
|
||||
onHit(){
|
||||
this.blood--;
|
||||
}
|
||||
|
||||
|
||||
//创建一个状态机
|
||||
protected abstract fsmCreate():GFSMBattle;
|
||||
//创建一个动画状态机
|
||||
@ -120,5 +109,42 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
}
|
||||
|
||||
//攻击
|
||||
onAttack(){
|
||||
//敌人扣血
|
||||
this.fsm.enemy.onHit();
|
||||
}
|
||||
|
||||
//受击
|
||||
onHit(){
|
||||
this.blood-=50;
|
||||
//检测是否死亡
|
||||
if(this.blood <= 0){
|
||||
//关闭状态机
|
||||
this.fsm.close();
|
||||
//设置死亡
|
||||
this.isDie = true;
|
||||
}
|
||||
}
|
||||
|
||||
//击飞
|
||||
onFly(){
|
||||
|
||||
console.log("onFly");
|
||||
let vWorld = this.node.worldPosition;
|
||||
let vEndWorld = this.getWorldBackLen(v2(800,500));
|
||||
JTween(vWorld)
|
||||
.to({x:vEndWorld.x},500)
|
||||
.onUpdate(pos => this.node.worldPosition = vWorld)
|
||||
.start();
|
||||
JTween(vWorld)
|
||||
.to({y:vEndWorld.y},500)
|
||||
.easing(JEasing.Circular.Out)
|
||||
.onUpdate(pos => this.node.worldPosition = vWorld)
|
||||
.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,12 +67,21 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
}
|
||||
|
||||
protected fsmCreate(): GFSMPVP {
|
||||
// return null;
|
||||
return new GFSMPVP(this);
|
||||
}
|
||||
protected fsmAnimCreate(): GFSMBattleAmin {
|
||||
return new GFSMBattleAmin(this.spine);
|
||||
}
|
||||
|
||||
//添加死亡销毁
|
||||
onHit(){
|
||||
super.onHit();
|
||||
if(this.isDie){
|
||||
//销毁数据
|
||||
this.mode.killRole(this);
|
||||
this.node.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
9
JisolGameCocos/assets/script/battle/util.meta
Normal file
9
JisolGameCocos/assets/script/battle/util.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "f07db6b6-6ffb-4cb1-9822-d9b248e3f57a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
19
JisolGameCocos/assets/script/battle/util/GRoleUtil.ts
Normal file
19
JisolGameCocos/assets/script/battle/util/GRoleUtil.ts
Normal file
@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9215634b-6c3f-47a2-a303-04408eb3e053",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user