Skip to content

Commit

Permalink
攻击动作
Browse files Browse the repository at this point in the history
  • Loading branch information
drugmoon committed Aug 16, 2020
1 parent 77f9421 commit 0d103b2
Show file tree
Hide file tree
Showing 16 changed files with 904 additions and 175 deletions.
604 changes: 490 additions & 114 deletions MHXY_RPGGame/assets/scene/main.fire

Large diffs are not rendered by default.

112 changes: 110 additions & 2 deletions MHXY_RPGGame/assets/script/SceneMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import PlotManager from "./plot/PlotManager";
import Formation ,{ FormationProperty }from "./fight/FormationPosDef"
import Character, { CharacterState } from "./map/character/Character";
import {RoleAttributeVo} from "./vo/RoleAttributeVo";
import {FightInfoVo, AttackType} from "./vo/FightInfoVo";
// Learn TypeScript:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
Expand Down Expand Up @@ -101,6 +102,7 @@ export default class SceneMap extends cc.Component {

private roadSign:RoadSign = null;

fightState:boolean = false;
// LIFE-CYCLE CALLBACKS:

onLoad ()
Expand All @@ -116,6 +118,15 @@ export default class SceneMap extends cc.Component {
this.transforDoors = this.getComponentsInChildren(TransferDoor);
this.spawnPoints = this.getComponentsInChildren(SpawnPoint);

//1. 数据管理
DataManager.instance.init();
//2. 逻辑管理
LogicManager.instance.init();
//3. 通讯管理
MsgManager.instance.init();
//4. 战斗管理
FightManager.instance.init();

if(SceneManager.instance.currentMapId != 0)
{

Expand All @@ -129,7 +140,7 @@ export default class SceneMap extends cc.Component {
},2.5);
}

this.player = GameManager.instance.getPlayer(1);
this.player = GameManager.instance.getPlayer(10);
this.player.node.parent = this.entityLayer.node;
this.player.controlMode = GameManager.instance.controllMode;

Expand All @@ -145,11 +156,13 @@ export default class SceneMap extends cc.Component {
SceneManager.instance.mapLoadModel,
);
}

//
}

public init(mapData:MapData,bgTex:cc.Texture2D,mapLoadModel:MapLoadModel = 1)
{

this.isInit = true;

MapRoadUtils.instance.updateMapInfo(mapData.mapWidth,mapData.mapHeight,mapData.nodeWidth,mapData.nodeHeight,mapData.type);
Expand Down Expand Up @@ -210,6 +223,101 @@ export default class SceneMap extends cc.Component {

}

public initFightScene()
{
//默认读取第一个阵法站位
let FormationPos:FormationProperty = Formation.instance.FormationPos[0];

let SelfArray:RoleAttributeVo[] = DataManager.instance.playersSelf

let FoeArray:RoleAttributeVo[] = DataManager.instance.playersFoe

for (let i = 0 ; i < SelfArray.length; i++)
{
//角色在阵法所在位置
let pos = FormationPos.self[i] ;

//设置模型
this.players_self[i] = GameManager.instance.getPlayer( SelfArray[i]._PlayerID);
this.players_self[i].node.parent = this.entityLayer.node;
this.players_self[i].controlMode = GameManager.instance.controllMode;
this.players_self[i].node.position = cc.v2( pos[0] , pos[1] )//spawnPoint.node.position;

//方向设置
this.players_self[i].direction = 0;

//默认将第一个设置为自己
if (i == 0)
{
this.player = this.players_self[i]
}
}

//敌方
// for (let i = 0 ; i < FoeArray.length; i++)
// {
// //角色在阵法所在位置
// let pos = FormationPos.foe[i] ;

// //设置模型
// this.players_foe[i] = GameManager.instance.getPlayer(FoeArray[i]._PlayerID);
// this.players_foe[i].node.parent = this.entityLayer.node;
// this.players_foe[i].controlMode = GameManager.instance.controllMode;
// this.players_foe[i].node.position = cc.v2( pos[0] , pos[1] )//spawnPoint.node.position;

// //方向设置
// this.players_foe[i].direction = 0;
// }


//this.setViewToPlayer();
}
//清理战斗场景
cleanFightScene()
{
for (let i = 0 ; i < this.players_self.length; i++)
{
this.players_self[i].node.destroy();
}
//敌方
for (let i = 0 ; i < this.players_foe.length; i++)
{
this.players_foe[i].node.destroy();
}
}
actionFightScene()
{
let fightInfoVo:FightInfoVo[] = DataManager.instance._fightInfoVo;

//敌方
for (let i = 0 ; i < fightInfoVo.length; i++)
{
this.actionFight(fightInfoVo[i]);
}
}
actionFight(fightInfoVo:FightInfoVo) {

console.log("actionFight ");
//1. 攻击类型
if (fightInfoVo._Type == AttackType.Att_None)
{
//
for (let i = 0 ; i < this.players_self.length; i++)
{
let player:Player = this.players_self[i];
player.attack();

//测试 使用一条信息就删除掉
DataManager.instance._fightInfoVo = [];
console.log("player.attack() ");
}
}
}
actionIdle()
{
let player:Player = this.players_self[0];
player.stop();
}
/**
* 根据像素坐标获得地图节点
* @param px
Expand Down
60 changes: 60 additions & 0 deletions MHXY_RPGGame/assets/script/common/EventType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@


/**
* 事件名称
* 自定义事件名统一放到这里,从这里去获取事件名
*/
export class EventType
{

public static Ack_JoinFight:string='Ack_JoinFight';
public static Ack_FightAction:string='Ack_FightAction';
public static Ack_LeaveFight:string='Ack_LeaveFight';

public static Req_cmd_Attack :string='Req_cmd_Attack'; //攻击
public static Req_cmd_Casting :string='Req_cmd_Casting';//施法
public static Req_cmd_def :string='Req_cmd_def'; //防御


public static playActionFinish:string="playActionFinish";
// public static EVENT_NAME:string='event_name';
// public static MAIN_BTN_EVENT:string='main_btn_event';
// public static SWITCH_PANEL:string='Switch_panel';
// public static SWITCH_SYSTEM:string='switch_system';
/** 加载进度完成,加载主场景 */
public static LOAD_COMPLETED:string='load_completed';
/**
* UI界面加载完成
*/
public static UI_LOBBY_COMPLETE:string='ui_panel_load_loaded';
}

export class System_Event
{
/** Mouse Event */
public static MOUSE_CLICK:string='click';
public static MOUSE_DOWN:string='mousedown'
public static MOUSE_ENTER:string='mouseenter';
public static MOUSE_MOVE:string='mousemove';
public static MOUSE_LEAVE:string='mouseleave';
public static MOUSE_UP:string='mouseup';
public static MOUSE_WHEEL:string='mousewheel';

/** Touch Event */
public static TOUCH_START:string='touchstart';
public static TOUCH_MOVE:string='touchmove';
public static TOUCH_END:string='touchend';
public static TOUCH_CANCEL:string='touchcancel';

public constructor(){

}
}


export enum EventEnum
{
SWITCH='',
JDLSD=''

}
9 changes: 9 additions & 0 deletions MHXY_RPGGame/assets/script/common/EventType.ts.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "8412ff74-b2e7-40d1-aa06-51bfa976a7bc",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
40 changes: 37 additions & 3 deletions MHXY_RPGGame/assets/script/core/DataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Formation ,{ FormationProperty } from "../fight/FormationPosDef"
import GameManager from "../core/GameManager";
import RoadSign from "../gamescene/RoadSign";
import {RoleAttributeVo} from "../vo/RoleAttributeVo";
import {FightInfoVo} from "../vo/FightInfoVo";
const {ccclass, property} = cc._decorator;

@ccclass
Expand All @@ -35,6 +36,7 @@ export default class DataManager extends cc.Component {
public playersSelf:RoleAttributeVo[] = []; //自己人
public playersFoe:RoleAttributeVo[] = []; //敌人

public _fightInfoVo:FightInfoVo[] = []; //战斗信息

// /** role数据 */
// private playersSelfMap: Map<number, RoleAttributeVo> = new Map();
Expand Down Expand Up @@ -71,10 +73,18 @@ export default class DataManager extends cc.Component {
//人物角色id 装备信息物品 宠物信息
//hp mp
// let forma:FormationProperty = Formation.instance.FormationPos[0];
console.log("setDataJoinFight ");

this.playersSelf[0]._PlayerID = 11;

this.playersFoe[0]._PlayerID = 11;
let RoleAttr_S = new RoleAttributeVo;
RoleAttr_S._ID = 1001;
RoleAttr_S._PlayerID = 10;

let RoleAttr_F = new RoleAttributeVo;
RoleAttr_F._ID = 1002;
RoleAttr_F._PlayerID = 10;

this.playersSelf[RoleAttr_S._Idx] = RoleAttr_S;
this.playersFoe[RoleAttr_F._Idx] = RoleAttr_F;
// for(var i:number = 0 ; i < 1 ; i++)
// {
// let pos = forma.self[i] ;
Expand All @@ -101,6 +111,30 @@ export default class DataManager extends cc.Component {
}
public setDataFightAction(){

// A > B
//A攻击B
//a 攻击动作
//b 受伤动作
console.log("setDataFightAction ");

let fightInfoVo = new FightInfoVo;

//A>B B hp - 999
fightInfoVo._ID_Att = 1001;
fightInfoVo._ID_Def = 1002;

//普通攻击
fightInfoVo._Type = 0;

//Hp
fightInfoVo._Hp_att = 0;
fightInfoVo._Hp_def = -999;

//Mp
fightInfoVo._Mp_att = 0;
fightInfoVo._Mp_def = 0;

this._fightInfoVo.push(fightInfoVo);
}

/*start () {
Expand Down
43 changes: 40 additions & 3 deletions MHXY_RPGGame/assets/script/core/FightManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import Player, { ControlMode } from "../gamescene/player/Player";
import RoadSign from "../gamescene/RoadSign";
import { EventMgr } from "../common/EventManager";
import { EventType } from "../common/EventType";
import SceneMap from "../SceneMap";

const {ccclass, property} = cc._decorator;

Expand Down Expand Up @@ -62,9 +65,43 @@ export default class FightManager extends cc.Component {

public init()
{

this.Listener();
}
public Listener(){
//接受到进入战斗消息 基础信息
// Req_JoinFight
EventMgr.addEventListener(EventType.Ack_JoinFight,this.recvMsg)

//离开战斗 基础信息
// Req_LeaveFight
EventMgr.addEventListener(EventType.Ack_LeaveFight,this.recvMsg)

//战斗动作
//Req_FightAction
//
EventMgr.addEventListener(EventType.Ack_FightAction,this.recvMsg)
}
public recvMsg(Event,target){

console.log("Event ", Event);
console.log("recvMsg ", target);
switch(Event)
{
case EventType.Ack_JoinFight:
SceneMap.instance.initFightScene();
break;

case EventType.Ack_FightAction:
SceneMap.instance.actionFightScene();
break;

case EventType.Ack_LeaveFight:
SceneMap.instance.cleanFightScene();
break;

}

}
public Tick(time)
{ //时间加速
//time *= speed;
Expand Down Expand Up @@ -131,9 +168,9 @@ export default class FightManager extends cc.Component {
// {
// this.fightState = state;
// }
/*start () {
start () {

}*/
}

// update (dt) {}
}
2 changes: 2 additions & 0 deletions MHXY_RPGGame/assets/script/core/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export default class GameManager extends cc.Component {
player.node.position = cc.Vec2.ZERO;
player.roleId = roleId;
player.node.active = true;
player.init();
console.log("======creat play");
return player;
}

Expand Down
Loading

0 comments on commit 0d103b2

Please sign in to comment.