first commit
This commit is contained in:
55
assets/scripts/skill/SkillCommand.ts
Normal file
55
assets/scripts/skill/SkillCommand.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { _decorator } from 'cc';
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import SkillProxy from "./SkillProxy";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
export default class SkillCommand {
|
||||
// //单例
|
||||
protected static _instance: SkillCommand;
|
||||
public static getInstance(): SkillCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new SkillCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constructor() {
|
||||
EventMgr.on(ServerConfig.skill_list, this.onSkillList, this);
|
||||
EventMgr.on(ServerConfig.skill_push, this.onSkillPush, this);
|
||||
}
|
||||
protected _proxy: SkillProxy = new SkillProxy();
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
public get proxy(): SkillProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
public qrySkillList(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.skill_list,
|
||||
msg: {}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
protected onSkillList(data: any): void {
|
||||
console.log("onSkillList", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateSkills(data.msg.list);
|
||||
EventMgr.emit("skill_list_info");
|
||||
}
|
||||
}
|
||||
protected onSkillPush(data: any): void {
|
||||
console.log("onSkillPush", data);
|
||||
this._proxy.updateSkills([data.msg]);
|
||||
EventMgr.emit("update_general");
|
||||
}
|
||||
}
|
||||
11
assets/scripts/skill/SkillCommand.ts.meta
Normal file
11
assets/scripts/skill/SkillCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fb7c0cd0-03ce-438d-8757-a89b6b6bd8a7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
60
assets/scripts/skill/SkillProxy.ts
Normal file
60
assets/scripts/skill/SkillProxy.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { _decorator } from 'cc';
|
||||
import { SkillConf, SkillOutline } from "../config/skill/Skill";
|
||||
|
||||
export class Skill {
|
||||
id:number = 0;
|
||||
cfgId: number = 0;
|
||||
generals: number[] = [];
|
||||
}
|
||||
|
||||
export default class SkillProxy {
|
||||
private _skillCfgMap:Map<number, SkillConf> = new Map<number, SkillConf>();
|
||||
protected _skillConfs: SkillConf[] = [];
|
||||
protected _skillOutLine: SkillOutline;
|
||||
protected _skills: Map<number, Skill> = new Map<number, Skill>();
|
||||
public initSkillConfig(cfgs: any[]): void {
|
||||
this._skillConfs = [];
|
||||
this._skillCfgMap.clear();
|
||||
|
||||
for (let i: number = 0; i < cfgs.length; i++) {
|
||||
|
||||
if (cfgs[i]._name == "skill_outline") {
|
||||
console.log("skill_outline");
|
||||
this._skillOutLine = cfgs[i].json;
|
||||
} else {
|
||||
this._skillConfs.push(cfgs[i].json);
|
||||
this._skillCfgMap.set(cfgs[i].json.cfgId, cfgs[i].json);
|
||||
}
|
||||
}
|
||||
}
|
||||
public get skillConfs(): SkillConf[] {
|
||||
return this._skillConfs;
|
||||
}
|
||||
public get outLine(): SkillOutline {
|
||||
return this._skillOutLine;
|
||||
}
|
||||
public getSkillCfg(cfgId:number): SkillConf{
|
||||
if(this._skillCfgMap.has(cfgId)){
|
||||
return this._skillCfgMap.get(cfgId);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public getSkill(cfgId:number): Skill{
|
||||
if(this._skills.has(cfgId)){
|
||||
return this._skills.get(cfgId);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public updateSkills(skills: Skill[]) {
|
||||
|
||||
skills.forEach(skill => {
|
||||
this._skills.set(skill.cfgId, skill);
|
||||
});
|
||||
|
||||
}
|
||||
public get skills():Skill[] {
|
||||
return Array.from(this._skills.values())
|
||||
}
|
||||
}
|
||||
11
assets/scripts/skill/SkillProxy.ts.meta
Normal file
11
assets/scripts/skill/SkillProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e75b3801-2194-4166-aa8d-ee05a2e93fd3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user