mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
@@ -23,7 +23,7 @@ class JNGLayer extends JNLayer{
|
||||
//重写Socket
|
||||
class JNGSocket extends JNSocket{
|
||||
public url() {
|
||||
return "ws://192.168.0.127:8080/websocket";
|
||||
return "ws://localhost:8080/websocket";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export const app = {
|
||||
event : EventDispatcher.getIns(), //通知
|
||||
proto : NGameMessage.getIns(), //消息
|
||||
api : axios.create({
|
||||
baseURL: "http://192.168.0.127:8080",
|
||||
baseURL: "http://localhost:8080",
|
||||
}), //请求
|
||||
battle : GBattleModeManager.getIns(), //战斗
|
||||
}
|
@@ -2,7 +2,6 @@ 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';
|
||||
import JNFrameTween, { JTween } from '../../extensions/ngame/assets/ngame/sync/frame/game/tween/JNFrameTween';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('Main')
|
||||
@@ -16,8 +15,6 @@ export class Main extends Component {
|
||||
|
||||
async onLoad(){
|
||||
|
||||
JTween().start();
|
||||
|
||||
//加载 APP
|
||||
await JNGame.Init(app,[
|
||||
{path:"proto/GDemo"}
|
||||
|
@@ -70,7 +70,8 @@ export default class GPVPMode extends GBaseMode{
|
||||
entity.ones = type;
|
||||
entity.tactical = this.getInfo(type).tactical;
|
||||
entity.tacticalIndex = index;
|
||||
this.addGObject(entity,this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type)));
|
||||
entity.tacticalPos = this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type));
|
||||
this.addGObject(entity,entity.tacticalPos);
|
||||
this.getOnesRole(type).push(entity);
|
||||
|
||||
}
|
||||
|
@@ -25,25 +25,25 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
title:"寻找敌人",
|
||||
execute: this.onSeekEnemyProcess.bind(this),
|
||||
// to:[ProcessEnum.MoveToAttackRange], //移动到可攻击范围
|
||||
to:[ProcessEnum.AttackEnemy], //移动到可攻击范围
|
||||
to:[ProcessEnum.MoveToAttackRange], //移动到可攻击范围
|
||||
},
|
||||
[ProcessEnum.MoveToAttackRange]:{
|
||||
title:"移动到可攻击范围",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onMoveToAttackRangeProcess.bind(this),
|
||||
to:[ProcessEnum.AttackEnemy,ProcessEnum.MoveToTactical] //攻击敌人 回阵型
|
||||
to:[ProcessEnum.AttackEnemy] //攻击敌人 回阵型
|
||||
},
|
||||
[ProcessEnum.AttackEnemy]:{
|
||||
title:"攻击敌人",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onAttackProcess.bind(this),
|
||||
to:[ProcessEnum.MoveToTactical],//移动回阵型
|
||||
},
|
||||
[ProcessEnum.MoveToTactical]:{
|
||||
title:"移动回阵型",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onMoveToTacticalProcess.bind(this),
|
||||
to:[ProcessEnum.SeekEnemy], //寻找敌人
|
||||
}
|
||||
// [ProcessEnum.MoveToTactical]:{
|
||||
// title:"移动回阵型",
|
||||
// mode:GFSMProcessMode.WaitExecute,
|
||||
// execute: this.onMoveToTacticalProcess.bind(this),
|
||||
// }
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
@@ -59,6 +59,10 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
//寻敌流程
|
||||
onSeekEnemyProcess(dt:number):number{
|
||||
|
||||
//播放等待
|
||||
this.player.fsmAnim.isMove = false;
|
||||
this.player.fsmAnim.isAttack = false;
|
||||
|
||||
if(this.enemy){
|
||||
//如果有敌人 直接 攻击
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
@@ -75,10 +79,14 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
}
|
||||
|
||||
//移动可攻击范围
|
||||
onMoveToAttackRangeProcess(){
|
||||
onMoveToAttackRangeProcess(dt:number){
|
||||
|
||||
//如果没有敌人则回阵型
|
||||
if(!this.enemy) return ProcessEnum.MoveToTactical;
|
||||
//播放移动
|
||||
this.player.fsmAnim.isMove = true;
|
||||
this.player.fsmAnim.isAttack = false;
|
||||
|
||||
//如果没有敌人则重置
|
||||
if(!this.enemy) return GFSMProcessEnum.Reset;
|
||||
|
||||
let distance = Vec2.distance(this.player.v2World,this.enemy.v2World);
|
||||
|
||||
@@ -87,24 +95,34 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
return ProcessEnum.AttackEnemy;
|
||||
}else{
|
||||
//靠近目标
|
||||
// this.player.
|
||||
this.player.onMoveTarget(this.enemy.v2World,dt);
|
||||
return GFSMProcessEnum.Wait;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//移动回阵型
|
||||
onMoveToTacticalProcess(){
|
||||
onMoveToTacticalProcess(dt:number){
|
||||
|
||||
//播放移动
|
||||
this.player.fsmAnim.isMove = true;
|
||||
this.player.fsmAnim.isAttack = false;
|
||||
|
||||
if(this.player.onMoveTarget(this.player.tacticalPos,dt)){
|
||||
//回到阵容 重置
|
||||
return GFSMProcessEnum.Reset;
|
||||
}
|
||||
|
||||
return GFSMProcessEnum.Wait;
|
||||
|
||||
}
|
||||
|
||||
onAttack(dt:number){
|
||||
this.player.onAttackUpdate(dt);
|
||||
}
|
||||
|
||||
|
||||
//攻击敌人
|
||||
onAttackProcess(dt:number){
|
||||
this.onAttack(dt);
|
||||
return GFSMProcessEnum.Reset;
|
||||
//播放移动
|
||||
this.player.fsmAnim.isMove = false;
|
||||
this.player.fsmAnim.isAttack = true;
|
||||
return GFSMProcessEnum.Wait;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -20,6 +20,7 @@ export interface GFSMProcessAnimInfo extends GFSMProcessInfo{
|
||||
mixs?:number[];
|
||||
//播放的轨道
|
||||
track?:sp.spine.TrackEntry;
|
||||
//条件跳转
|
||||
ifTo?:(() => boolean)[];
|
||||
}
|
||||
|
||||
@@ -48,12 +49,31 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
//动画Root
|
||||
spine:sp.Skeleton;
|
||||
|
||||
events:{event:string,fun:Function}[] = [];
|
||||
|
||||
constructor(spine:sp.Skeleton,trackIndex?:number){
|
||||
super();
|
||||
this.spine = spine;
|
||||
this.trackIndex = trackIndex || 0;
|
||||
//设置监听
|
||||
this.spine.setEventListener(this.onEventListener.bind(this));
|
||||
}
|
||||
|
||||
//添加事件监听
|
||||
addEventListener(event:string,fun:Function){
|
||||
this.events.push({
|
||||
event,
|
||||
fun,
|
||||
})
|
||||
}
|
||||
|
||||
onEventListener(entry: sp.spine.TrackEntry, ev: sp.spine.Event){
|
||||
this.events.forEach(item => {
|
||||
if(item.event == ev.data.name){
|
||||
item.fun();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 流程图
|
||||
process: { [key: number]: GFSMProcessAnimInfo; } = {
|
||||
@@ -130,6 +150,5 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -6,8 +6,14 @@ import GFSMBattle from "../fsm/base/GFSMBattle/GFSMBattle";
|
||||
import { GFSMBattleAmin } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
|
||||
import { Vec2 } from "cc";
|
||||
import { v2 } from "cc";
|
||||
import { v3 } from "cc";
|
||||
import { GTactical } from "../../entity/GTactical";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum GRoleAnimEvent{
|
||||
Attack = "attack", //普通攻击
|
||||
}
|
||||
|
||||
//角色基类
|
||||
export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
@@ -24,7 +30,23 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
_isMirror:boolean = false;
|
||||
|
||||
//玩家攻击范围
|
||||
range:number = 10;
|
||||
range:number = 100;
|
||||
|
||||
//移动速度
|
||||
moveSpeed:number = 80;
|
||||
|
||||
//在阵容中的下标
|
||||
tacticalIndex:number;
|
||||
//阵容
|
||||
tactical:GTactical;
|
||||
//阵容位置
|
||||
_tacticalPos:Vec2;
|
||||
get tacticalPos(){ return this._tacticalPos}
|
||||
set tacticalPos(value:Vec2){ this._tacticalPos = value}
|
||||
|
||||
//血量
|
||||
blood:number = 100;
|
||||
fullBlood:number = 100;
|
||||
|
||||
get isMirror(){
|
||||
return this._isMirror;
|
||||
@@ -51,9 +73,24 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
this.fsm = this.fsmCreate();
|
||||
//创建角色动画状态机
|
||||
this.fsmAnim = this.fsmAnimCreate();
|
||||
|
||||
//监听攻击
|
||||
this.fsmAnim.addEventListener(GRoleAnimEvent.Attack,this.onAttack.bind(this));
|
||||
|
||||
}
|
||||
|
||||
//攻击
|
||||
onAttack(){
|
||||
//敌人扣血
|
||||
this.fsm.enemy.onHit();
|
||||
}
|
||||
|
||||
//受击
|
||||
onHit(){
|
||||
this.blood--;
|
||||
}
|
||||
|
||||
|
||||
//创建一个状态机
|
||||
protected abstract fsmCreate():GFSMBattle;
|
||||
//创建一个动画状态机
|
||||
@@ -61,14 +98,26 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T){
|
||||
//更新状态机
|
||||
this.fsm && this.fsm.onUpdate(dt);
|
||||
this.fsmAnim && this.fsmAnim.onUpdate(dt);
|
||||
this.fsm && this.fsm.onUpdate(dt / 1000);
|
||||
this.fsmAnim && this.fsmAnim.onUpdate(dt / 1000);
|
||||
}
|
||||
|
||||
//普攻更新
|
||||
onAttackUpdate(dt:number){
|
||||
|
||||
this.fsmAnim.isAttack = true;
|
||||
//向目标点移动
|
||||
onMoveTarget(target:Vec2,dt:number){
|
||||
|
||||
//获取两个坐标差值向量
|
||||
let mins = this.v2World.subtract(target);
|
||||
let normal = this.v2World.subtract(target).normalize();
|
||||
|
||||
if(Vec2.len(normal) >= Vec2.len(mins)){
|
||||
this.node.setWorldPosition(Object.assign(v3(),target.clone()));
|
||||
return true;
|
||||
}else{
|
||||
//移动
|
||||
this.node.worldPosition = this.node.worldPosition.subtract(v3(normal.x*dt*this.moveSpeed,normal.y*dt*this.moveSpeed,0))
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,9 @@ import GPVPMode, { GPVPModePlayerEnum } from "../../../PVP/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";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export interface GDemoMessage{
|
||||
@@ -19,7 +22,6 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
|
||||
//所属阵容
|
||||
_ones:GPVPModePlayerEnum;
|
||||
|
||||
get ones():GPVPModePlayerEnum{
|
||||
return this._ones;
|
||||
}
|
||||
@@ -33,11 +35,12 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
this._ones = value;
|
||||
}
|
||||
|
||||
//攻击距离
|
||||
@property(ProgressBar)
|
||||
bloodVolume:ProgressBar;
|
||||
|
||||
//在阵容中的下标
|
||||
tacticalIndex:number;
|
||||
tactical:GTactical;
|
||||
onSyncLoad(){
|
||||
super.onSyncLoad();
|
||||
}
|
||||
|
||||
getClassName():string{return "GDemoMessage"}
|
||||
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: GDemoMessage) {
|
||||
@@ -50,6 +53,9 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
this.fsmAnim.isMove = input.isRun;
|
||||
}
|
||||
}
|
||||
|
||||
//更新血量显示
|
||||
this.bloodVolume.progress = this.blood / this.fullBlood;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +67,7 @@ export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
|
||||
}
|
||||
|
||||
protected fsmCreate(): GFSMPVP {
|
||||
return null;
|
||||
// return null;
|
||||
return new GFSMPVP(this);
|
||||
}
|
||||
protected fsmAnimCreate(): GFSMBattleAmin {
|
||||
|
Reference in New Issue
Block a user