first commit
This commit is contained in:
251
assets/scripts/Main.ts
Normal file
251
assets/scripts/Main.ts
Normal file
@@ -0,0 +1,251 @@
|
||||
import { _decorator, Component, Prefab, Node, instantiate, TiledMapAsset, JsonAsset, SpriteFrame, sys, UITransform, view } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { GameConfig } from "./config/GameConfig";
|
||||
import LoaderManager, { LoadData, LoadDataType } from "./core/LoaderManager";
|
||||
import ArmyCommand from "./general/ArmyCommand";
|
||||
import GeneralCommand from "./general/GeneralCommand";
|
||||
import LoginCommand from "./login/LoginCommand";
|
||||
import MapCommand from "./map/MapCommand";
|
||||
import MapUICommand from "./map/ui/MapUICommand";
|
||||
import { HttpManager } from "./network/http/HttpManager";
|
||||
import { NetEvent } from "./network/socket/NetInterface";
|
||||
import { NetManager } from "./network/socket/NetManager";
|
||||
import { NetNodeType } from "./network/socket/NetNode";
|
||||
import SkillCommand from "./skill/SkillCommand";
|
||||
import Toast from "./utils/Toast";
|
||||
import { Tools } from "./utils/Tools";
|
||||
import { EventMgr } from './utils/EventMgr';
|
||||
|
||||
@ccclass('Main')
|
||||
export default class Main extends Component {
|
||||
@property(Prefab)
|
||||
loginScenePrefab: Prefab = null;
|
||||
|
||||
@property(Prefab)
|
||||
mapScenePrefab: Prefab = null;
|
||||
@property(Prefab)
|
||||
mapUIScenePrefab: Prefab = null;
|
||||
|
||||
@property(Prefab)
|
||||
loadingPrefab: Prefab = null;
|
||||
|
||||
|
||||
@property(Prefab)
|
||||
waitPrefab: Prefab = null;
|
||||
|
||||
@property(Prefab)
|
||||
toastPrefab: Prefab = null;
|
||||
|
||||
private toastNode: Node = null;
|
||||
|
||||
protected _loginScene: Node = null;
|
||||
protected _mapScene: Node = null;
|
||||
protected _mapUIScene: Node = null;
|
||||
protected _loadingNode: Node = null;
|
||||
protected _waitNode: Node = null;
|
||||
private _retryTimes: number = 0;
|
||||
|
||||
protected onLoad(): void {
|
||||
|
||||
console.log("main load");
|
||||
|
||||
// 添加窗口resize监听,确保游戏能自动适应浏览器窗口大小
|
||||
if (sys.isBrowser) {
|
||||
this.setupResizeHandler();
|
||||
}
|
||||
|
||||
EventMgr.on("enter_map", this.onEnterMap, this);
|
||||
EventMgr.on("enter_login", this.enterLogin, this);
|
||||
EventMgr.on("show_toast", this.onShowToast, this);
|
||||
EventMgr.on(NetEvent.ServerRequesting, this.showWaitNode,this);
|
||||
EventMgr.on(NetEvent.ServerRequestSucess,this.onServerRequest,this);
|
||||
|
||||
|
||||
//初始化连接
|
||||
NetManager.getInstance().connect({ url: GameConfig.serverUrl , type:NetNodeType.BaseServer });
|
||||
HttpManager.getInstance().setWebUrl(GameConfig.webUrl);
|
||||
|
||||
//初始化业务模块
|
||||
LoginCommand.getInstance();
|
||||
MapCommand.getInstance();
|
||||
MapUICommand.getInstance();
|
||||
GeneralCommand.getInstance();
|
||||
ArmyCommand.getInstance();
|
||||
|
||||
this.enterLogin();
|
||||
|
||||
}
|
||||
|
||||
private _resizeHandler: any = null;
|
||||
|
||||
private setupResizeHandler(): void {
|
||||
this._resizeHandler = () => {
|
||||
// 延迟执行,确保DOM更新完成
|
||||
setTimeout(() => {
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
if (width > 0 && height > 0) {
|
||||
view.resize(width, height);
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
window.addEventListener('resize', this._resizeHandler);
|
||||
// 初始执行一次,延迟执行确保游戏已初始化
|
||||
setTimeout(() => {
|
||||
this._resizeHandler();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
// 移除resize监听
|
||||
if (sys.isBrowser && this._resizeHandler) {
|
||||
window.removeEventListener('resize', this._resizeHandler);
|
||||
this._resizeHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected clearData(): void {
|
||||
MapCommand.getInstance().clearData();
|
||||
GeneralCommand.getInstance().clearData();
|
||||
ArmyCommand.getInstance().clearData();
|
||||
}
|
||||
|
||||
private enterLogin(): void {
|
||||
this.clearAllScene();
|
||||
this.clearData();
|
||||
this._loginScene = instantiate(this.loginScenePrefab);
|
||||
this._loginScene.parent = this.node;
|
||||
}
|
||||
|
||||
protected onEnterMap(): void {
|
||||
let dataList: LoadData[] = [];
|
||||
dataList.push(new LoadData("./world/map", LoadDataType.FILE, TiledMapAsset));
|
||||
dataList.push(new LoadData("./config/mapRes_0", LoadDataType.FILE, JsonAsset));
|
||||
dataList.push(new LoadData("./config/json/facility/", LoadDataType.DIR, JsonAsset));
|
||||
dataList.push(new LoadData("./config/json/general/", LoadDataType.DIR, JsonAsset));
|
||||
if(sys.isBrowser){
|
||||
dataList.push(new LoadData("./generalpic1", LoadDataType.DIR, SpriteFrame));
|
||||
}else{
|
||||
dataList.push(new LoadData("./generalpic", LoadDataType.DIR, SpriteFrame));
|
||||
}
|
||||
|
||||
dataList.push(new LoadData("./config/basic", LoadDataType.FILE, JsonAsset));
|
||||
dataList.push(new LoadData("./config/json/skill/", LoadDataType.DIR, JsonAsset));
|
||||
|
||||
this.addLoadingNode();
|
||||
console.log("onEnterMap");
|
||||
LoaderManager.getInstance().startLoadList(dataList, null,
|
||||
(error: Error, paths: string[], datas: any[]) => {
|
||||
if (error != null) {
|
||||
console.log("加载配置文件失败");
|
||||
return;
|
||||
}
|
||||
console.log("loadComplete", paths, datas);
|
||||
MapCommand.getInstance().proxy.tiledMapAsset = datas[0] as TiledMapAsset;
|
||||
MapCommand.getInstance().proxy.initMapResConfig((datas[1] as JsonAsset).json);
|
||||
|
||||
MapUICommand.getInstance().proxy.setAllFacilityCfg(datas[2]);
|
||||
GeneralCommand.getInstance().proxy.initGeneralConfig(datas[3],(datas[5] as JsonAsset).json);
|
||||
GeneralCommand.getInstance().proxy.initGeneralTex(datas[4]);
|
||||
MapUICommand.getInstance().proxy.setBasic(datas[5]);
|
||||
SkillCommand.getInstance().proxy.initSkillConfig(datas[6]);
|
||||
|
||||
var d = (datas[5] as JsonAsset).json
|
||||
MapCommand.getInstance().proxy.setWarFree(d["build"].war_free);
|
||||
|
||||
let cityId: number = MapCommand.getInstance().cityProxy.getMyMainCity().cityId;
|
||||
GeneralCommand.getInstance().qryMyGenerals();
|
||||
ArmyCommand.getInstance().qryArmyList(cityId);
|
||||
MapUICommand.getInstance().qryWarReport();
|
||||
SkillCommand.getInstance().qrySkillList();
|
||||
|
||||
this.clearAllScene();
|
||||
this._mapScene = instantiate(this.mapScenePrefab);
|
||||
this._mapScene.parent = this.node;
|
||||
this._mapUIScene = instantiate(this.mapUIScenePrefab);
|
||||
this._mapUIScene.parent = this.node;
|
||||
},
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
protected addLoadingNode(): void {
|
||||
if (this.loadingPrefab) {
|
||||
if (this._loadingNode == null) {
|
||||
this._loadingNode = instantiate(this.loadingPrefab);
|
||||
}
|
||||
this._loadingNode.setSiblingIndex(1);
|
||||
this._loadingNode.parent = this.node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected showWaitNode(isShow:boolean):void{
|
||||
if (this._waitNode == null) {
|
||||
this._waitNode = instantiate(this.waitPrefab);
|
||||
this._waitNode.parent = this.node;
|
||||
this._waitNode.setSiblingIndex(2);
|
||||
}
|
||||
this._waitNode.active = isShow;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected showTopToast(text:string = ""):void{
|
||||
if(this.toastNode == null){
|
||||
let toast = instantiate(this.toastPrefab);
|
||||
toast.parent = this.node;
|
||||
toast.setSiblingIndex(10);
|
||||
this.toastNode = toast;
|
||||
}
|
||||
this.toastNode.active = true;
|
||||
this.toastNode.getComponent(Toast).setText(text);
|
||||
}
|
||||
|
||||
|
||||
private onServerRequest(msg:any):void{
|
||||
if(msg.code == undefined || msg.code == 0 || msg.code == 9){
|
||||
this._retryTimes = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(msg.code == -1 || msg.code == -2 || msg.code == -3 || msg.code == -4 ){
|
||||
if (this._retryTimes < 3){
|
||||
LoginCommand.getInstance().role_enterServer(LoginCommand.getInstance().proxy.getSession(), false);
|
||||
this._retryTimes += 1;
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.showTopToast(Tools.getCodeStr(msg.code));
|
||||
}
|
||||
|
||||
private onShowToast(msg:string) {
|
||||
this.showTopToast(msg);
|
||||
}
|
||||
|
||||
protected clearAllScene() {
|
||||
if (this._mapScene) {
|
||||
this._mapScene.destroy();
|
||||
this._mapScene = null;
|
||||
}
|
||||
|
||||
if (this._mapUIScene) {
|
||||
this._mapUIScene.destroy();
|
||||
this._mapUIScene = null;
|
||||
}
|
||||
|
||||
if (this._loginScene) {
|
||||
this._loginScene.destroy();
|
||||
this._loginScene = null;
|
||||
}
|
||||
|
||||
if (this._waitNode) {
|
||||
this._waitNode.destroy();
|
||||
this._waitNode = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
assets/scripts/Main.ts.meta
Normal file
11
assets/scripts/Main.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f6d4ce04-90e2-413c-9990-aeb8f5296f0e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/chat.meta
Normal file
12
assets/scripts/chat.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "1f010ec1-71fe-41f5-a3ab-86abccdb1580",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
121
assets/scripts/chat/ChatCommand.ts
Normal file
121
assets/scripts/chat/ChatCommand.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
import { _decorator } from 'cc';
|
||||
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import ChatProxy from "./ChatProxy";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
export default class ChatCommand {
|
||||
//单例
|
||||
protected static _instance: ChatCommand;
|
||||
public static getInstance(): ChatCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new ChatCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
|
||||
//数据model
|
||||
protected _proxy:ChatProxy = new ChatProxy();
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//数据model
|
||||
|
||||
constructor() {
|
||||
// EventMgr.on(ServerConfig.chat_chat, this.onChat, this)
|
||||
EventMgr.on(ServerConfig.chat_history, this.onChatHistory, this)
|
||||
EventMgr.on(ServerConfig.chat_push, this.onChat, this)
|
||||
}
|
||||
|
||||
protected onChat(data:any):void{
|
||||
console.log("onChat:",data)
|
||||
if (data.code == 0) {
|
||||
if(data.msg.type == 0){
|
||||
this._proxy.updateWorldChat(data.msg);
|
||||
}else if (data.msg.type == 1){
|
||||
this._proxy.updateUnionChat(data.msg);
|
||||
}
|
||||
EventMgr.emit("update_chat_history");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected onChatHistory(data:any):void{
|
||||
console.log("onChatHistory:",data)
|
||||
if (data.code == 0) {
|
||||
if(data.msg.type == 0){
|
||||
this._proxy.updateWorldChatList(data.msg.msgs);
|
||||
}else if(data.msg.type == 1){
|
||||
this._proxy.updateUnionChatList(data.msg.msgs);
|
||||
}
|
||||
EventMgr.emit("update_chat_history");
|
||||
}
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._proxy.clearData();
|
||||
}
|
||||
|
||||
public get proxy(): ChatProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
|
||||
|
||||
public chat(msg:string,type:number = 0):void{
|
||||
let sendData: any = {
|
||||
name: ServerConfig.chat_chat,
|
||||
msg: {
|
||||
msg:msg,
|
||||
type:type,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public join(type:number,id:number):void{
|
||||
let sendData: any = {
|
||||
name: ServerConfig.chat_join,
|
||||
msg: {
|
||||
type:type,
|
||||
id:id,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public exit(type:number,id:number):void{
|
||||
let sendData: any = {
|
||||
name: ServerConfig.chat_exit,
|
||||
msg: {
|
||||
type:type,
|
||||
id:id,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public chatHistory(type:number):void{
|
||||
let sendData: any = {
|
||||
name: ServerConfig.chat_history,
|
||||
msg: {
|
||||
type:type,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
assets/scripts/chat/ChatCommand.ts.meta
Normal file
11
assets/scripts/chat/ChatCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8b45e0cf-3e10-42ca-b583-92de9b2db1e8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
24
assets/scripts/chat/ChatItemLogic.ts
Normal file
24
assets/scripts/chat/ChatItemLogic.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
import { ChatMsg } from "./ChatProxy";
|
||||
import { _decorator, Component, Label } from "cc";
|
||||
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@ccclass('ChatItemLogic')
|
||||
export default class ChatItemLogic extends Component {
|
||||
|
||||
|
||||
@property(Label)
|
||||
nameLabel: Label = null;
|
||||
|
||||
|
||||
protected onLoad():void{
|
||||
}
|
||||
|
||||
protected updateItem(data:ChatMsg):void{
|
||||
var time = DateUtil.converTimeStr(data.time * 1000);
|
||||
this.nameLabel.string = time + " " + data.nick_name + ":" +data.msg;
|
||||
}
|
||||
|
||||
}
|
||||
11
assets/scripts/chat/ChatItemLogic.ts.meta
Normal file
11
assets/scripts/chat/ChatItemLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ea99c0d7-de2f-4b87-b258-a97be3b9938d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
88
assets/scripts/chat/ChatLogic.ts
Normal file
88
assets/scripts/chat/ChatLogic.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
|
||||
import { _decorator, Component, EditBox, ScrollView } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { MapCityData } from "../map/MapCityProxy";
|
||||
import MapCommand from "../map/MapCommand";
|
||||
import ChatCommand from "./ChatCommand";
|
||||
import { ChatMsg } from "./ChatProxy";
|
||||
import ListLogic from '../utils/ListLogic';
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('ChatLogic')
|
||||
export default class ChatLogic extends Component {
|
||||
|
||||
@property(EditBox)
|
||||
editConent: EditBox = null;
|
||||
|
||||
@property(ScrollView)
|
||||
chatView:ScrollView = null;
|
||||
|
||||
_type:number = 0;
|
||||
|
||||
protected onLoad():void{
|
||||
EventMgr.on("update_chat_history", this.updateChat, this);
|
||||
EventMgr.on("unionChange", this.updateChat, this);
|
||||
}
|
||||
|
||||
protected onEnable():void{
|
||||
console.log("onEnable")
|
||||
this.updateUnion();
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
protected updateUnion():void{
|
||||
let city:MapCityData = MapCommand.getInstance().cityProxy.getMyMainCity();
|
||||
if (city.unionId > 0){
|
||||
//加入联盟频道
|
||||
ChatCommand.getInstance().join(1, city.unionId);
|
||||
}else{
|
||||
ChatCommand.getInstance().exit(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected updateChat(data:any[]){
|
||||
if(this._type == 0){
|
||||
var comp = this.chatView.node.getComponent(ListLogic);
|
||||
var list:ChatMsg[] = ChatCommand.getInstance().proxy.getWorldChatList();
|
||||
comp.setData(list);
|
||||
}else if (this._type == 1){
|
||||
var comp = this.chatView.node.getComponent(ListLogic);
|
||||
var list:ChatMsg[] = ChatCommand.getInstance().proxy.getUnionChatList();
|
||||
console.log("list:", list)
|
||||
comp.setData(list);
|
||||
}
|
||||
}
|
||||
|
||||
protected onClickClose(): void {
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
public updateView():void{
|
||||
console.log("type:", this._type)
|
||||
ChatCommand.getInstance().chatHistory(this._type);
|
||||
}
|
||||
|
||||
protected onClickChat(): void {
|
||||
if (this._type == 0){
|
||||
ChatCommand.getInstance().chat(this.editConent.string, this._type);
|
||||
}else if (this._type == 1){
|
||||
let city:MapCityData = MapCommand.getInstance().cityProxy.getMyMainCity();
|
||||
if (city.unionId > 0){
|
||||
ChatCommand.getInstance().chat(this.editConent.string, this._type);
|
||||
}
|
||||
}
|
||||
this.editConent.string = "";
|
||||
}
|
||||
|
||||
protected onClickWorld(): void {
|
||||
this._type = 0;
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
protected onClickUnion(): void {
|
||||
this._type = 1;
|
||||
this.updateView();
|
||||
}
|
||||
}
|
||||
11
assets/scripts/chat/ChatLogic.ts.meta
Normal file
11
assets/scripts/chat/ChatLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d26dd91f-18f3-47ec-a556-dcedf0c54493",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
78
assets/scripts/chat/ChatProxy.ts
Normal file
78
assets/scripts/chat/ChatProxy.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { _decorator } from 'cc';
|
||||
|
||||
export class ChatMsg {
|
||||
rid: number = 0;
|
||||
nick_name: string = "";
|
||||
type:number = 0;
|
||||
msg:string = "";
|
||||
time:number = 0;
|
||||
}
|
||||
|
||||
|
||||
export default class ChatProxy {
|
||||
|
||||
|
||||
private _worldMsgList:ChatMsg[] = [];
|
||||
private _unionMsgList:ChatMsg[] = [];
|
||||
|
||||
public clearData(): void {
|
||||
|
||||
}
|
||||
|
||||
public updateWorldChatList(data:any[]):void{
|
||||
this._worldMsgList = [];
|
||||
for(var i = 0; i < data.length;i++){
|
||||
var chat = new ChatMsg();
|
||||
chat.msg = data[i].msg;
|
||||
chat.rid = data[i].rid;
|
||||
chat.type = data[i].type;
|
||||
chat.time = data[i].time;
|
||||
chat.nick_name = data[i].nickName
|
||||
this._worldMsgList.push(chat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public updateUnionChatList(data:any[]):void{
|
||||
this._unionMsgList = [];
|
||||
for(var i = 0; i < data.length;i++){
|
||||
var chat = new ChatMsg();
|
||||
chat.msg = data[i].msg;
|
||||
chat.rid = data[i].rid;
|
||||
chat.type = data[i].type;
|
||||
chat.time = data[i].time;
|
||||
chat.nick_name = data[i].nickName
|
||||
this._unionMsgList.push(chat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public updateWorldChat(data:any):void{
|
||||
var chat = new ChatMsg();
|
||||
chat.msg = data.msg;
|
||||
chat.rid = data.rid;
|
||||
chat.type = data.type;
|
||||
chat.time = data.time;
|
||||
chat.nick_name = data.nickName
|
||||
this._worldMsgList.push(chat);
|
||||
}
|
||||
|
||||
public updateUnionChat(data:any):void{
|
||||
var chat = new ChatMsg();
|
||||
chat.msg = data.msg;
|
||||
chat.rid = data.rid;
|
||||
chat.type = data.type;
|
||||
chat.time = data.time;
|
||||
chat.nick_name = data.nickName
|
||||
this._unionMsgList.push(chat);
|
||||
}
|
||||
|
||||
|
||||
public getWorldChatList():ChatMsg[]{
|
||||
return this._worldMsgList;
|
||||
}
|
||||
|
||||
public getUnionChatList():ChatMsg[]{
|
||||
return this._unionMsgList;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/chat/ChatProxy.ts.meta
Normal file
11
assets/scripts/chat/ChatProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1731b4bb-b7ac-4011-983f-2420dc454954",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/common.meta
Normal file
12
assets/scripts/common.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "c869fa9f-d0d4-45fa-8fed-207dd9800397",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
92
assets/scripts/common/BgLogic.ts
Normal file
92
assets/scripts/common/BgLogic.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
// //因为适配的原因,背景和界面其他元素是分离的,
|
||||
// //那么背景的缩放包括场景图片背景和弹窗半透明黑色背景都可以挂这个脚本进行缩放
|
||||
|
||||
import { _decorator, Component, Enum, Widget, UITransform, game, view, Canvas } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum BgScaleType {
|
||||
FULL_SCREEN = 1,
|
||||
SCALE_BY_WIDTH = 2,
|
||||
SCALE_BY_HEIGHT = 3,
|
||||
SCALE_ONLY_WIDTH = 4,
|
||||
SCALE_ONLY_HEIGHT = 5,
|
||||
};
|
||||
// //bg对齐方位
|
||||
export enum BgAlignmentType {
|
||||
TOP = 1,
|
||||
BOTTOM = 2,
|
||||
CENTER = 3,
|
||||
LEFT = 4,
|
||||
RIGHT = 5
|
||||
};
|
||||
|
||||
@ccclass('BgLogic')
|
||||
export default class BgLogic extends Component {
|
||||
@property({ type: Enum(BgScaleType) })
|
||||
scaleType: BgScaleType = BgScaleType.FULL_SCREEN;
|
||||
@property({ type: Enum(BgAlignmentType) })
|
||||
alignmentType: BgAlignmentType = BgAlignmentType.CENTER;
|
||||
protected _realW: number = 0;
|
||||
protected _realH: number = 0;
|
||||
protected onLoad(): void {
|
||||
this._realW = this.node.getComponent(UITransform).width;
|
||||
this._realH = this.node.getComponent(UITransform).height;
|
||||
|
||||
this.updateFrameSize();
|
||||
}
|
||||
|
||||
|
||||
protected updateFrameSize(): void {
|
||||
|
||||
let scaleW: number = view.getVisibleSize().width / this._realW;
|
||||
let scaleH: number = view.getVisibleSize().height / this._realH;
|
||||
let scaleX: number = 1;
|
||||
let scaleY: number = 1;
|
||||
if (this.scaleType == BgScaleType.SCALE_BY_WIDTH) {
|
||||
scaleX = scaleY = scaleW;
|
||||
} else if (this.scaleType == BgScaleType.SCALE_BY_HEIGHT) {
|
||||
scaleX = scaleY = scaleH;
|
||||
} else if (this.scaleType == BgScaleType.SCALE_ONLY_WIDTH) {
|
||||
scaleX = scaleW;
|
||||
scaleY = 1;
|
||||
} else if (this.scaleType == BgScaleType.SCALE_ONLY_HEIGHT) {
|
||||
scaleX = 1;
|
||||
scaleY = scaleH;
|
||||
} else {
|
||||
scaleX = scaleY = Math.max(scaleW, scaleH);
|
||||
}
|
||||
|
||||
this.node.getComponent(UITransform).width = this._realW * scaleX;
|
||||
this.node.getComponent(UITransform).height = this._realH * scaleY;
|
||||
|
||||
let widget: Widget = this.node.getComponent(Widget);
|
||||
|
||||
|
||||
if (widget == null) {
|
||||
widget = this.node.addComponent(Widget);
|
||||
}
|
||||
|
||||
|
||||
if (this.alignmentType == BgAlignmentType.BOTTOM) {
|
||||
widget.isAlignHorizontalCenter = true;
|
||||
widget.isAlignBottom = true;
|
||||
widget.bottom = 0;
|
||||
} else if (this.alignmentType == BgAlignmentType.TOP) {
|
||||
widget.isAlignHorizontalCenter = true;
|
||||
widget.isAlignTop = true;
|
||||
widget.top = 0;
|
||||
} else if (this.alignmentType == BgAlignmentType.LEFT) {
|
||||
widget.isAlignVerticalCenter = true;
|
||||
widget.isAlignLeft = true;
|
||||
widget.left = 0;
|
||||
} else if (this.alignmentType == BgAlignmentType.RIGHT) {
|
||||
widget.isAlignVerticalCenter = true;
|
||||
widget.isAlignRight = true;
|
||||
widget.right = 0;
|
||||
} else if (this.alignmentType == BgAlignmentType.CENTER) {
|
||||
widget.isAlignHorizontalCenter = true;
|
||||
widget.isAlignVerticalCenter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
assets/scripts/common/BgLogic.ts.meta
Normal file
11
assets/scripts/common/BgLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "79100f0a-41a3-4bcc-8c91-fcbf516ad69a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
25
assets/scripts/common/LoadingLogic.ts
Normal file
25
assets/scripts/common/LoadingLogic.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { _decorator, Component, ProgressBar } from 'cc';
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('LoadingLogic')
|
||||
export default class LoadingLogic extends Component {
|
||||
@property(ProgressBar)
|
||||
bar: ProgressBar | null = null;
|
||||
protected onLoad(): void {
|
||||
this.bar.progress = 0;
|
||||
EventMgr.on("load_progress", this.onProgress, this);
|
||||
EventMgr.on("load_complete", this.onComplete, this);
|
||||
}
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
protected onProgress(precent: number): void {
|
||||
this.bar.progress = precent;
|
||||
}
|
||||
protected onComplete(): void {
|
||||
this.node.parent = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
assets/scripts/common/LoadingLogic.ts.meta
Normal file
11
assets/scripts/common/LoadingLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7411ef8c-8a07-4dc8-a363-fa8d28522884",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/config.meta
Normal file
12
assets/scripts/config.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "dd9edb4a-fac0-4de9-ae17-32d2367d6483",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
78
assets/scripts/config/Basci.ts
Normal file
78
assets/scripts/config/Basci.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
// /**征兵相关**/
|
||||
// /**武将相关**/
|
||||
|
||||
import { _decorator } from 'cc';
|
||||
export class Conscript {
|
||||
cost_wood: number = 0;
|
||||
cost_iron: number = 0;
|
||||
cost_stone: number = 0;
|
||||
cost_grain: number = 0;
|
||||
cost_gold: number = 0;
|
||||
}
|
||||
|
||||
export class General {
|
||||
physical_power_limit: number = 0; //体力上限
|
||||
cost_physical_power: number = 0; //消耗体力
|
||||
recovery_physical_power: number = 0; //恢复体力
|
||||
reclamation_time: number = 0; //屯田消耗时间,单位秒
|
||||
reclamation_cost: number = 0; //屯田消耗政令
|
||||
draw_general_cost: number = 0; //抽卡消耗金币
|
||||
pr_point: number = 0; //合成一个武将或者的技能点
|
||||
limit: number = 0; //武将数量上限
|
||||
}
|
||||
|
||||
export class Role {
|
||||
wood: number = 0;
|
||||
iron: number = 0;
|
||||
stone: number = 0;
|
||||
grain: number = 0;
|
||||
gold: number = 0;
|
||||
decree: number = 0;
|
||||
wood_yield: number = 0;
|
||||
iron_yield: number = 0;
|
||||
stone_yield: number = 0;
|
||||
grain_yield: number = 0;
|
||||
gold_yield: number = 0;
|
||||
depot_capacity: number = 0; //仓库初始容量
|
||||
build_limit: number = 0; //野外建筑上限
|
||||
recovery_time: number = 0;
|
||||
decree_limit: number = 0; //令牌上限
|
||||
collect_times_limit: number = 0; //每日征收次数上限
|
||||
collect_interval: number = 0; //征收间隔
|
||||
pos_tag_limit: number = 0; //位置标签上限
|
||||
}
|
||||
|
||||
export class City {
|
||||
cost: number = 0;
|
||||
durable: number = 0;
|
||||
recovery_time: number = 0;
|
||||
transform_rate: number = 0;
|
||||
}
|
||||
|
||||
export class Build {
|
||||
war_free: number = 0; //免战时间,单位秒
|
||||
giveUp_time: number = 0; //建筑放弃时间
|
||||
fortress_limit: number = 0; //要塞上限
|
||||
}
|
||||
|
||||
export class Union {
|
||||
member_limit: number = 0;
|
||||
}
|
||||
|
||||
export class NpcLevel {
|
||||
soilders: number
|
||||
}
|
||||
|
||||
export class Npc {
|
||||
levels: NpcLevel[]
|
||||
}
|
||||
|
||||
export class Basic {
|
||||
conscript: Conscript;
|
||||
general: General;
|
||||
role: Role;
|
||||
city: City;
|
||||
build: Build;
|
||||
union: Union;
|
||||
npc: Npc;
|
||||
}
|
||||
11
assets/scripts/config/Basci.ts.meta
Normal file
11
assets/scripts/config/Basci.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cc925316-fd26-4809-9a6f-dac71f76f339",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
13
assets/scripts/config/GameConfig.ts
Normal file
13
assets/scripts/config/GameConfig.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// /**连接配置*/
|
||||
// 使用nginx代理后的配置(通过80端口访问)
|
||||
// WebSocket通过 /ws 路径代理到8004端口
|
||||
// HTTP API通过 /api 路径代理到8088端口
|
||||
|
||||
import { _decorator } from 'cc';
|
||||
const GameConfig = {
|
||||
// 通过nginx代理的WebSocket地址(nginx将/ws代理到127.0.0.1:8004)
|
||||
serverUrl: "ws://103.236.81.216:6060/ws",
|
||||
// 通过nginx代理的HTTP API地址(nginx将/api代理到127.0.0.1:8088)
|
||||
webUrl: "http://103.236.81.216:6060/api",
|
||||
}
|
||||
export { GameConfig };
|
||||
11
assets/scripts/config/GameConfig.ts.meta
Normal file
11
assets/scripts/config/GameConfig.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c7559215-2f52-41ba-9e14-635f181819c5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
11
assets/scripts/config/HttpConfig.ts
Normal file
11
assets/scripts/config/HttpConfig.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// /**http接口配置*/
|
||||
// //账号注册
|
||||
|
||||
import { _decorator } from 'cc';
|
||||
const HttpConfig = {
|
||||
register: {
|
||||
name: "register",
|
||||
url: "/account/register"
|
||||
},
|
||||
}
|
||||
export { HttpConfig };
|
||||
11
assets/scripts/config/HttpConfig.ts.meta
Normal file
11
assets/scripts/config/HttpConfig.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5c375b87-4690-4892-a80f-8754f10d274a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
90
assets/scripts/config/ServerConfig.ts
Normal file
90
assets/scripts/config/ServerConfig.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
// /**服务器接口配置*/
|
||||
import { _decorator } from 'cc';
|
||||
|
||||
const ServerConfig = {
|
||||
account_login: "account.login",
|
||||
account_logout: "account.logout",
|
||||
account_reLogin: "account.reLogin",
|
||||
account_robLogin:"robLogin",
|
||||
|
||||
role_create: "role.create",
|
||||
role_roleList: "role.roleList",
|
||||
role_enterServer: "role.enterServer",
|
||||
role_myCity: "role.myCity",
|
||||
role_myRoleRes: "role.myRoleRes",
|
||||
role_myProperty: "role.myProperty",
|
||||
role_upPosition:"role.upPosition",
|
||||
role_posTagList:"role.posTagList",
|
||||
role_opPosTag:"role.opPosTag",
|
||||
|
||||
nationMap_config: "nationMap.config",
|
||||
nationMap_scanBlock: "nationMap.scanBlock",
|
||||
nationMap_giveUp: "nationMap.giveUp",
|
||||
nationMap_build: "nationMap.build",
|
||||
nationMap_upBuild: "nationMap.upBuild",
|
||||
nationMap_delBuild: "nationMap.delBuild",
|
||||
|
||||
city_facilities: "city.facilities",
|
||||
city_upFacility: "city.upFacility",
|
||||
|
||||
|
||||
general_myGenerals: "general.myGenerals",
|
||||
general_drawGeneral: "general.drawGeneral",
|
||||
general_composeGeneral: "general.composeGeneral",
|
||||
general_addPrGeneral: "general.addPrGeneral",
|
||||
general_convert: "general.convert",
|
||||
|
||||
general_upSkill: "general.upSkill",
|
||||
general_downSkill: "general.downSkill",
|
||||
general_lvSkill: "general.lvSkill",
|
||||
|
||||
army_myList: "army.myList",
|
||||
army_myOne: "army.myOne",
|
||||
army_dispose: "army.dispose",
|
||||
army_conscript: "army.conscript",
|
||||
army_assign: "army.assign",
|
||||
|
||||
war_report:"war.report",
|
||||
war_read:"war.read",
|
||||
|
||||
union_create:"union.create",
|
||||
union_join:"union.join",
|
||||
union_list:"union.list",
|
||||
union_member:"union.member",
|
||||
union_applyList:"union.applyList",
|
||||
union_dismiss:"union.dismiss",
|
||||
union_verify:"union.verify",
|
||||
union_exit:"union.exit",
|
||||
union_kick:"union.kick",
|
||||
union_appoint:"union.appoint",
|
||||
union_abdicate:"union.abdicate",
|
||||
union_modNotice:"union.modNotice",
|
||||
union_info:"union.info",
|
||||
union_log:"union.log",
|
||||
union_apply_push: "unionApply.push",
|
||||
|
||||
interior_collect: "interior.collect",
|
||||
interior_openCollect: "interior.openCollect",
|
||||
interior_transform: "interior.transform",
|
||||
|
||||
war_reportPush:"warReport.push",
|
||||
general_push: "general.push",
|
||||
army_push: "army.push",
|
||||
roleBuild_push:"roleBuild.push",
|
||||
roleCity_push:"roleCity.push",
|
||||
facility_push:"facility.push",
|
||||
roleRes_push:"roleRes.push",
|
||||
|
||||
skill_list:"skill.list",
|
||||
skill_push:"skill.push",
|
||||
|
||||
chat_login:"chat.login",
|
||||
chat_chat:"chat.chat",
|
||||
chat_history:"chat.history",
|
||||
chat_join:"chat.join",
|
||||
chat_exit:"chat.exit",
|
||||
chat_push:"chat.push",
|
||||
}
|
||||
|
||||
|
||||
export { ServerConfig };
|
||||
11
assets/scripts/config/ServerConfig.ts.meta
Normal file
11
assets/scripts/config/ServerConfig.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2c4e0735-a613-4b33-97db-17b187f5121f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/config/skill.meta
Normal file
12
assets/scripts/config/skill.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "0311a18e-52a9-47fa-8713-5c569f8b8153",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
58
assets/scripts/config/skill/Skill.ts
Normal file
58
assets/scripts/config/skill/Skill.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// //技能大纲
|
||||
// //技能配置
|
||||
|
||||
import { _decorator } from 'cc';
|
||||
export class trigger {
|
||||
type: number
|
||||
des: string
|
||||
}
|
||||
|
||||
export class triggerType {
|
||||
des: string
|
||||
list:trigger[]
|
||||
}
|
||||
|
||||
export class effect {
|
||||
type: number
|
||||
des: string
|
||||
isRate: boolean
|
||||
}
|
||||
|
||||
export class effectType {
|
||||
des: string
|
||||
list:effect[]
|
||||
}
|
||||
|
||||
export class target {
|
||||
type: number
|
||||
des: string
|
||||
}
|
||||
|
||||
export class targetType {
|
||||
des: string
|
||||
list:target[]
|
||||
}
|
||||
|
||||
export class SkillOutline {
|
||||
trigger_type: triggerType
|
||||
effect_type: effectType
|
||||
target_type: targetType
|
||||
}
|
||||
|
||||
export class SkillLevel {
|
||||
probability: number //发动概率
|
||||
effect_value:number[] //效果值
|
||||
effect_round: number[] //效果持续回合数
|
||||
}
|
||||
|
||||
export class SkillConf {
|
||||
cfgId: number
|
||||
name: string
|
||||
des: string
|
||||
trigger: number //发起类型
|
||||
target: number //目标类型
|
||||
limit: number //可以被武将装备上限
|
||||
arms:number[] //可以装备的兵种
|
||||
include_effect: number[] //技能包括的效果
|
||||
levels:SkillLevel[]
|
||||
}
|
||||
11
assets/scripts/config/skill/Skill.ts.meta
Normal file
11
assets/scripts/config/skill/Skill.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "167f604d-b3a0-4f71-bd33-03c2c6cb6d11",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/core.meta
Normal file
12
assets/scripts/core.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "425e00be-d311-499b-9cf4-0d4ecaf4a7ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
148
assets/scripts/core/LoaderManager.ts
Normal file
148
assets/scripts/core/LoaderManager.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import { _decorator, Asset, resources } from 'cc';
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
export enum LoadDataType {
|
||||
DIR,
|
||||
FILE
|
||||
}
|
||||
|
||||
export class LoadData {
|
||||
path: string = "";
|
||||
loadType: LoadDataType = LoadDataType.FILE;
|
||||
fileType: typeof Asset = Asset;
|
||||
|
||||
constructor(path: string = "", loadType: LoadDataType = LoadDataType.FILE, fileType: typeof Asset = Asset) {
|
||||
this.path = path;
|
||||
this.loadType = loadType;
|
||||
this.fileType = fileType;
|
||||
}
|
||||
}
|
||||
|
||||
export class LoadCompleteData {
|
||||
path: string = "";
|
||||
data: any;
|
||||
}
|
||||
|
||||
export default class LoaderManager {
|
||||
//单例
|
||||
protected static _instance: LoaderManager;
|
||||
public static getInstance(): LoaderManager {
|
||||
if (this._instance == null) {
|
||||
this._instance = new LoaderManager();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected _isLoading: boolean = false;
|
||||
protected _curIndex: number = -1;
|
||||
protected _loadDataList: LoadData[] = [];
|
||||
protected _completePaths: string[] = [];
|
||||
protected _completeAssets: any[] = [];
|
||||
protected _progressCallback: Function = null;
|
||||
protected _completeCallback: Function = null;
|
||||
protected _target: any = null;
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
this._loadDataList.length = 0;
|
||||
}
|
||||
|
||||
protected loadNext(): void {
|
||||
if (this._curIndex >= this._loadDataList.length) {
|
||||
this.onComplete();
|
||||
return;
|
||||
}
|
||||
let data: LoadData = this._loadDataList[this._curIndex];
|
||||
if (data.loadType == LoadDataType.DIR) {
|
||||
//加载目录
|
||||
resources.loadDir(data.path, data.fileType,
|
||||
(finish: number, total: number) => {
|
||||
this.onProgress(finish, total);
|
||||
},
|
||||
(error: Error, assets: any[]) => {
|
||||
if (error == null) {
|
||||
this._completePaths.push(data.path);
|
||||
this._completeAssets.push(assets);
|
||||
this._curIndex++;
|
||||
this.loadNext();
|
||||
} else {
|
||||
this.onComplete(error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//加载文件
|
||||
resources.load(data.path, data.fileType,
|
||||
(finish: number, total: number) => {
|
||||
this.onProgress(finish, total);
|
||||
},
|
||||
(error: Error, asset: any) => {
|
||||
if (error == null) {
|
||||
this._completePaths.push(data.path);
|
||||
this._completeAssets.push(asset);
|
||||
this._curIndex++;
|
||||
this.loadNext();
|
||||
} else {
|
||||
this.onComplete(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected onProgress(finish: number, total: number): void {
|
||||
let percent: number = 1 / this._loadDataList.length;
|
||||
let subPercent:number = (finish / total) * percent;
|
||||
let totalPercent:number = Number((subPercent + percent * this._curIndex).toFixed(2));
|
||||
if (this._target && this._progressCallback) {
|
||||
this._progressCallback.call(this._target, totalPercent);
|
||||
}
|
||||
EventMgr.emit("load_progress", totalPercent);
|
||||
}
|
||||
|
||||
protected onComplete(error: Error = null): void {
|
||||
if (this._target && this._completeCallback) {
|
||||
this._completeCallback.call(this._target, error, this._completePaths, this._completeAssets);
|
||||
}
|
||||
EventMgr.emit("load_complete");
|
||||
this.clearData();
|
||||
}
|
||||
|
||||
protected clearData(): void {
|
||||
this._isLoading = false;
|
||||
this._loadDataList.length = 0;
|
||||
this._progressCallback = null;
|
||||
this._completeCallback = null;
|
||||
this._target = null;
|
||||
this._completeAssets.length = 0;
|
||||
this._completePaths.length = 0;
|
||||
}
|
||||
|
||||
public startLoad(data: LoadData, loadProgress: (percent: number) => void, loadComplete: (error:Error, paths:string[], datas: any[]) => void, target: any = null): void {
|
||||
this.startLoadList([data], loadProgress, loadComplete);
|
||||
}
|
||||
|
||||
public startLoadList(dataList: LoadData[], loadProgress: (percent: number) => void, loadComplete: (error:Error, paths:string[], datas: any[]) => void, target: any = null): void {
|
||||
if (this._isLoading) {
|
||||
return;
|
||||
}
|
||||
this.clearData();
|
||||
this._isLoading = true;
|
||||
this._loadDataList = dataList;
|
||||
this._progressCallback = loadProgress;
|
||||
this._completeCallback = loadComplete;
|
||||
this._target = target;
|
||||
this._curIndex = 0;
|
||||
this.loadNext();
|
||||
}
|
||||
}
|
||||
11
assets/scripts/core/LoaderManager.ts.meta
Normal file
11
assets/scripts/core/LoaderManager.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b0f1a17a-0e99-4c02-90c1-7ccb7cb672f4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/general.meta
Normal file
12
assets/scripts/general.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "9d007c66-51be-4d60-a25c-c2cbe9e156a2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
353
assets/scripts/general/ArmyCommand.ts
Normal file
353
assets/scripts/general/ArmyCommand.ts
Normal file
@@ -0,0 +1,353 @@
|
||||
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import LoginCommand from "../login/LoginCommand";
|
||||
import { MapCityData } from "../map/MapCityProxy";
|
||||
import MapCommand from "../map/MapCommand";
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import ArmyProxy, { ArmyCmd, ArmyData } from "./ArmyProxy";
|
||||
import GeneralCommand from "./GeneralCommand";
|
||||
import { GenaralLevelConfig, GeneralConfig, GeneralData } from "./GeneralProxy";
|
||||
import { EventMgr } from "../utils/EventMgr";
|
||||
|
||||
|
||||
export default class ArmyCommand {
|
||||
//单例
|
||||
protected static _instance: ArmyCommand;
|
||||
public static getInstance(): ArmyCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new ArmyCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//数据model
|
||||
protected _proxy: ArmyProxy = new ArmyProxy();
|
||||
|
||||
constructor() {
|
||||
EventMgr.on(ServerConfig.army_myList, this.onQryArmyList, this);
|
||||
EventMgr.on(ServerConfig.army_myOne, this.onQryArmyOne, this);
|
||||
|
||||
EventMgr.on(ServerConfig.army_dispose, this.onGeneralDispose, this);
|
||||
EventMgr.on(ServerConfig.army_conscript, this.onGeneralConscript, this);
|
||||
EventMgr.on(ServerConfig.army_assign, this.onGeneralAssignArmy, this);
|
||||
EventMgr.on(ServerConfig.army_push, this.onGeneralArmyStatePush, this);
|
||||
EventMgr.on(ServerConfig.nationMap_scanBlock, this.onNationMapScanBlock, this);
|
||||
|
||||
//定时检测自己的军队是否有武将已经征兵完,如果是请求刷新
|
||||
setInterval(() => {
|
||||
let myCity: MapCityData = MapCommand.getInstance().cityProxy.getMyMainCity();
|
||||
if (myCity != null){
|
||||
let armyList: ArmyData[] = this.proxy.getArmyList(myCity.cityId);
|
||||
if (armyList == null){
|
||||
return
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < armyList.length; i++) {
|
||||
var army = armyList[i];
|
||||
if (army != null && army.isGenConEnd()){
|
||||
console.log("有武将征兵完了");
|
||||
this.qryArmyOne(army.cityId, army.order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._proxy.clearData();
|
||||
}
|
||||
|
||||
public get proxy(): ArmyProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
|
||||
/**军队列表回调*/
|
||||
protected onQryArmyList(data: any, otherData: any): void {
|
||||
console.log("onQryArmyList", data);
|
||||
if (data.code == 0) {
|
||||
let armyDatas: ArmyData[] = this._proxy.updateArmys(data.msg.cityId, data.msg.armys);
|
||||
EventMgr.emit("update_army_list", armyDatas);
|
||||
}
|
||||
}
|
||||
|
||||
protected onQryArmyOne(data: any, otherData: any): void {
|
||||
console.log("onQryArmyOne", data);
|
||||
if (data.code == 0) {
|
||||
let armyData = this._proxy.updateArmy(data.msg.army.cityId, data.msg.army);
|
||||
let armyDatas: ArmyData[] = this._proxy.getArmyList(data.msg.army.cityId);
|
||||
EventMgr.emit("update_army_list", armyDatas);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**配置将领回调*/
|
||||
protected onGeneralDispose(data: any, otherData: any): void {
|
||||
console.log("onGeneralDispose", data);
|
||||
if (data.code == 0) {
|
||||
let armyData: ArmyData = this._proxy.updateArmy(data.msg.army.cityId, data.msg.army);
|
||||
console.log("armyData", armyData);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
}
|
||||
}
|
||||
|
||||
/**征兵回调*/
|
||||
protected onGeneralConscript(data: any, otherData: any): void {
|
||||
console.log("onGeneralConscript", data);
|
||||
if (data.code == 0) {
|
||||
LoginCommand.getInstance().proxy.saveEnterData(data.msg);
|
||||
EventMgr.emit("upate_my_roleRes");
|
||||
|
||||
let armyData: ArmyData = this._proxy.updateArmy(data.msg.army.cityId, data.msg.army);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
EventMgr.emit("conscript_army_success");
|
||||
}
|
||||
}
|
||||
|
||||
/**出征回调*/
|
||||
protected onGeneralAssignArmy(data: any, otherData: any): void {
|
||||
console.log("onGeneralAssignArmy", data);
|
||||
if (data.code == 0) {
|
||||
let armyData: ArmyData = this._proxy.updateArmy(data.msg.army.cityId, data.msg.army);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
EventMgr.emit("update_army_assign");
|
||||
}
|
||||
}
|
||||
|
||||
/**军队状态变更*/
|
||||
protected onGeneralArmyStatePush(data: any): void {
|
||||
console.log("onGeneralArmyState", data);
|
||||
if (data.code == 0) {
|
||||
let armyData: ArmyData = this._proxy.updateArmy(data.msg.cityId, data.msg);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
}
|
||||
}
|
||||
|
||||
protected onNationMapScanBlock(data: any): void {
|
||||
if (data.code == 0) {
|
||||
for (let i: number = 0; i < data.msg.armys.length; i++) {
|
||||
let armyData: ArmyData = this._proxy.updateArmy(data.msg.armys[i].cityId, data.msg.armys[i]);
|
||||
EventMgr.emit("update_army", armyData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**我的角色属性*/
|
||||
public updateMyProperty(datas: any[]): void {
|
||||
if (datas.length > 0) {
|
||||
let armyDatas: ArmyData[] = this._proxy.updateArmys(datas[0].cityId, datas);
|
||||
EventMgr.emit("update_army_list", armyDatas);
|
||||
}
|
||||
}
|
||||
|
||||
/**获取军队当前体力*/
|
||||
public getArmyPhysicalPower(armyData: ArmyData): number {
|
||||
let minPower: number = 100;
|
||||
for (let i: number = 0; i < armyData.generals.length; i++) {
|
||||
let general: GeneralData = GeneralCommand.getInstance().proxy.getMyGeneral(armyData.generals[i]);
|
||||
if (general && minPower > general.physical_power) {
|
||||
minPower = general.physical_power;
|
||||
}
|
||||
}
|
||||
return minPower;
|
||||
}
|
||||
|
||||
/**获取军队将领列表*/
|
||||
public getArmyGenerals(armyData: ArmyData): GeneralData[] {
|
||||
let list: GeneralData[] = [];
|
||||
for (let i: number = 0; i < armyData.generals.length; i++) {
|
||||
let general: GeneralData = GeneralCommand.getInstance().proxy.getMyGeneral(armyData.generals[i]);
|
||||
list.push(general);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**根据将领列表获取军队体力*/
|
||||
public getArmyPhysicalPowerByGenerals(generals: GeneralData[]): number {
|
||||
let minPower: number = 100;
|
||||
for (let i: number = 0; i < generals.length; i++) {
|
||||
if (generals[i] && minPower > generals[i].physical_power) {
|
||||
minPower = generals[i].physical_power;
|
||||
}
|
||||
}
|
||||
return minPower;
|
||||
}
|
||||
|
||||
/**获取军队当前士兵数*/
|
||||
public getArmyCurSoldierCnt(armyData: ArmyData): number {
|
||||
let cnt: number = 0;
|
||||
for (let i: number = 0; i < armyData.soldiers.length; i++) {
|
||||
cnt += armyData.soldiers[i];
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**根据将领列表获取军队总士兵数*/
|
||||
public getArmyTotalSoldierCntByGenerals(generals: GeneralData[]): number {
|
||||
let cnt: number = 0;
|
||||
let levelCfg: GenaralLevelConfig = null;
|
||||
for (let i: number = 0; i < generals.length; i++) {
|
||||
if (generals[i]) {
|
||||
levelCfg = GeneralCommand.getInstance().proxy.getGeneralLevelCfg(generals[i].level);
|
||||
cnt += levelCfg.soldiers;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**获取速度**/
|
||||
public getArmySpeed(generals: GeneralData[]): number {
|
||||
let empyt: boolean = true;
|
||||
let speed: number = 1000000;
|
||||
let cfg: GeneralConfig = null;
|
||||
for (let i: number = 0; i < generals.length; i++) {
|
||||
if (generals[i]) {
|
||||
cfg = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[i].cfgId);
|
||||
speed = Math.min(speed, GeneralData.getPrValue(cfg.speed, cfg.speed_grow*generals[i].level, generals[i].speed_added));
|
||||
empyt = false;
|
||||
}
|
||||
}
|
||||
if (empyt){
|
||||
return 0;
|
||||
}else{
|
||||
return speed;
|
||||
}
|
||||
}
|
||||
|
||||
public getArmyDestroy(generals: GeneralData[]): number {
|
||||
let empyt: boolean = true;
|
||||
let destory: number = 0;
|
||||
let cfg: GeneralConfig = null;
|
||||
for (let i: number = 0; i < generals.length; i++) {
|
||||
if (generals[i]) {
|
||||
cfg = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[i].cfgId);
|
||||
destory += GeneralData.getPrValue(cfg.destroy, cfg.destroy_grow*generals[i].level, generals[i].destroy_added);
|
||||
empyt = false;
|
||||
}
|
||||
}
|
||||
if (empyt){
|
||||
return 0;
|
||||
}else{
|
||||
return destory;
|
||||
}
|
||||
}
|
||||
|
||||
/**根据将领列表获取军队阵营*/
|
||||
public getArmyCamp(generals: GeneralData[]): number {
|
||||
let cnt: number = 0;
|
||||
let lastCamp: number = 0;
|
||||
for (let i: number = 0; i < generals.length; i++) {
|
||||
if (generals[i] && (generals[i].config.camp == lastCamp || lastCamp == 0)) {
|
||||
lastCamp = generals[i].config.camp;
|
||||
cnt++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cnt >= 3) {
|
||||
return lastCamp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public getArmyStateDes(armyData: ArmyData): string {
|
||||
let stateStr: string = "";
|
||||
if (armyData.state > 0) {
|
||||
if (armyData.cmd == ArmyCmd.Return) {
|
||||
stateStr = "[撤退]";
|
||||
} else {
|
||||
stateStr = "[行军]";
|
||||
}
|
||||
} else {
|
||||
if (armyData.cmd == ArmyCmd.Idle) {
|
||||
stateStr = "[待命]";
|
||||
} else if (armyData.cmd == ArmyCmd.Reclaim) {
|
||||
stateStr = "[屯田]";
|
||||
} else if (armyData.cmd == ArmyCmd.Conscript) {
|
||||
stateStr = "[征兵]";
|
||||
} else if (armyData.cmd == ArmyCmd.Garrison) {
|
||||
stateStr = "[驻守]";
|
||||
}else {
|
||||
stateStr = "[停留]";
|
||||
}
|
||||
}
|
||||
return stateStr;
|
||||
}
|
||||
|
||||
/**请求自己的军队信息*/
|
||||
public qryArmyList(cityId: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.army_myList,
|
||||
msg: {
|
||||
cityId: cityId
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public qryArmyOne(cityId: number, order: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.army_myOne,
|
||||
msg: {
|
||||
cityId: cityId,
|
||||
order:order,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
/**给军队配置将领*/
|
||||
public generalDispose(cityId: number = 0, generalId: number = 0, order: number = 0, position: number = 0, otherData: any): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.army_dispose,
|
||||
msg: {
|
||||
cityId: cityId,
|
||||
generalId: generalId,
|
||||
order: order,
|
||||
position: position,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData, otherData);
|
||||
}
|
||||
|
||||
/**给军队征兵*/
|
||||
public generalConscript(armyId: number = 0, cnts: number[] = [], otherData: any): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.army_conscript,
|
||||
msg: {
|
||||
armyId: armyId,
|
||||
cnts: cnts,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData, otherData);
|
||||
}
|
||||
|
||||
/**出兵*/
|
||||
public generalAssignArmy(armyId: number = 0, cmd: number = 0, x: number = 0, y: Number = 0, otherData: any = null): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.army_assign,
|
||||
msg: {
|
||||
armyId: armyId,
|
||||
cmd: cmd,
|
||||
x: x,
|
||||
y: y,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData, otherData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/general/ArmyCommand.ts.meta
Normal file
11
assets/scripts/general/ArmyCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a02fca78-a476-4f81-8f42-c990e2acb027",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
185
assets/scripts/general/ArmyProxy.ts
Normal file
185
assets/scripts/general/ArmyProxy.ts
Normal file
@@ -0,0 +1,185 @@
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
|
||||
/**军队命令*/
|
||||
export class ArmyCmd {
|
||||
static Idle: number = 0;//空闲
|
||||
static Attack: number = 1;//攻击
|
||||
static Garrison: number = 2;//驻军
|
||||
static Reclaim: number = 3;//屯田
|
||||
static Return: number = 4;//撤退
|
||||
static Conscript: number = 5;//征兵
|
||||
static Transfer: number = 6;//调动
|
||||
}
|
||||
|
||||
/**军队数据*/
|
||||
export class ArmyData {
|
||||
id: number = 0;
|
||||
cityId: number = 0;
|
||||
order: number = 0;
|
||||
generals: number[] = [];
|
||||
soldiers: number[] = [];
|
||||
conTimes: number[] = [];
|
||||
conCnts: number[] = [];
|
||||
cmd: number = 0;
|
||||
state: number = 0;
|
||||
fromX: number = 0;
|
||||
fromY: number = 0;
|
||||
toX: number = 0;
|
||||
toY: number = 0;
|
||||
startTime: number = 0;
|
||||
endTime: number = 0;
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
|
||||
static createFromServer(serverData: any, armyData: ArmyData = null): ArmyData {
|
||||
let data: ArmyData = armyData;
|
||||
if (armyData == null) {
|
||||
data = new ArmyData();
|
||||
}
|
||||
data.id = serverData.id;
|
||||
data.cityId = serverData.cityId;
|
||||
data.order = serverData.order;
|
||||
data.generals = serverData.generals;
|
||||
data.soldiers = serverData.soldiers;
|
||||
|
||||
data.conTimes = serverData.con_times;
|
||||
data.conCnts = serverData.con_cnts;
|
||||
|
||||
data.state = serverData.state;
|
||||
data.cmd = serverData.cmd;
|
||||
if (data.cmd == ArmyCmd.Return) {
|
||||
//返回的时候 坐标是反的
|
||||
data.fromX = serverData.to_x;
|
||||
data.fromY = serverData.to_y;
|
||||
data.toX = serverData.from_x;
|
||||
data.toY = serverData.from_y;
|
||||
} else {
|
||||
data.fromX = serverData.from_x;
|
||||
data.fromY = serverData.from_y;
|
||||
data.toX = serverData.to_x;
|
||||
data.toY = serverData.to_y;
|
||||
}
|
||||
if (data.cmd == ArmyCmd.Idle || data.cmd == ArmyCmd.Conscript) {
|
||||
//代表是停留在城池中
|
||||
data.x = data.fromX;
|
||||
data.y = data.fromY;
|
||||
} else {
|
||||
data.x = data.toX;
|
||||
data.y = data.toY;
|
||||
}
|
||||
|
||||
data.startTime = serverData.start * 1000;
|
||||
data.endTime = serverData.end * 1000;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public isGenConEnd():boolean {
|
||||
for (let index = 0; index < this.conTimes.length; index++) {
|
||||
const conTime = this.conTimes[index];
|
||||
if (conTime == 0) {
|
||||
continue
|
||||
}
|
||||
if (DateUtil.isAfterServerTime(conTime*1000)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default class ArmyProxy {
|
||||
protected _maxArmyCnt: number = 5;//一个城池最大军队数量
|
||||
//武将基础配置数据
|
||||
protected _armys: Map<number, ArmyData[]> = new Map<number, ArmyData[]>();
|
||||
|
||||
public clearData(): void {
|
||||
this._armys.clear();
|
||||
}
|
||||
|
||||
public getArmyList(cityId: number): ArmyData[] {
|
||||
if (this._armys.has(cityId) == false) {
|
||||
return null;
|
||||
}
|
||||
return this._armys.get(cityId);
|
||||
}
|
||||
|
||||
public updateArmys(cityId: number, datas: any[]): ArmyData[] {
|
||||
let list: ArmyData[] = this.getArmyList(cityId);
|
||||
if (list == null) {
|
||||
list = new Array(this._maxArmyCnt);
|
||||
this._armys.set(cityId, list);
|
||||
}
|
||||
for (var i = 0; i < datas.length; i++) {
|
||||
let armyData: ArmyData = ArmyData.createFromServer(datas[i]);
|
||||
list[armyData.order - 1] = armyData;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public updateArmy(cityId: number, data: any): ArmyData {
|
||||
let list: ArmyData[] = this.getArmyList(cityId);
|
||||
if (list == null) {
|
||||
list = new Array(this._maxArmyCnt);
|
||||
this._armys.set(cityId, list);
|
||||
}
|
||||
let armyData: ArmyData = list[data.order - 1];
|
||||
list[data.order - 1] = ArmyData.createFromServer(data, armyData);
|
||||
return list[data.order - 1];
|
||||
}
|
||||
|
||||
|
||||
public updateArmysNoCity(datas: any): ArmyData[] {
|
||||
let list: ArmyData[] = [];
|
||||
for(var i = 0; i < datas.length ;i++){
|
||||
let armyData: ArmyData = ArmyData.createFromServer(datas[i]);
|
||||
this.updateArmy(armyData.cityId,armyData);
|
||||
list.push(armyData)
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**根据id获取军队*/
|
||||
public getArmyById(id: number, cityId: number): ArmyData {
|
||||
let list: ArmyData[] = this.getArmyList(cityId);
|
||||
if (list) {
|
||||
for (let i: number = 0; i < list.length; i++) {
|
||||
if (list[i] && list[i].id == id) {
|
||||
return list[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**根据位置获取军队*/
|
||||
public getArmyByOrder(order: number, cityId: number): ArmyData {
|
||||
let list: ArmyData[] = this.getArmyList(cityId);
|
||||
console.log("getArmyByOrder", order, cityId, list);
|
||||
if (list) {
|
||||
return list[order - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getAllArmys(): ArmyData[] {
|
||||
let list:ArmyData[] = [];
|
||||
this._armys.forEach((datas:ArmyData[]) => {
|
||||
list = list.concat(datas);
|
||||
})
|
||||
return list;
|
||||
}
|
||||
|
||||
public getArmysByPos(x: number, y: number) {
|
||||
let list:ArmyData[] = [];
|
||||
this._armys.forEach((armys:ArmyData[]) => {
|
||||
armys.forEach(army => {
|
||||
if (army.fromX == x && army.fromY == y){
|
||||
list.push(army);
|
||||
}
|
||||
});
|
||||
})
|
||||
return list;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/general/ArmyProxy.ts.meta
Normal file
11
assets/scripts/general/ArmyProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e294bf68-3877-4252-9b17-821521fdad8f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
234
assets/scripts/general/GeneralCommand.ts
Normal file
234
assets/scripts/general/GeneralCommand.ts
Normal file
@@ -0,0 +1,234 @@
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import GeneralProxy from "./GeneralProxy";
|
||||
import { EventMgr } from "../utils/EventMgr";
|
||||
|
||||
export default class GeneralCommand {
|
||||
//单例
|
||||
protected static _instance: GeneralCommand;
|
||||
public static getInstance(): GeneralCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new GeneralCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//数据model
|
||||
protected _proxy: GeneralProxy = new GeneralProxy();
|
||||
|
||||
constructor() {
|
||||
EventMgr.on(ServerConfig.general_myGenerals, this.onMyGenerals, this);
|
||||
EventMgr.on(ServerConfig.general_push, this.onGeneralPush, this);
|
||||
EventMgr.on(ServerConfig.general_drawGeneral, this.onDrawGenerals, this);
|
||||
EventMgr.on(ServerConfig.general_composeGeneral, this.onComposeGeneral, this);
|
||||
EventMgr.on(ServerConfig.general_addPrGeneral, this.onAddPrGeneral, this);
|
||||
EventMgr.on(ServerConfig.general_convert, this.onGeneralConvert , this);
|
||||
EventMgr.on(ServerConfig.general_upSkill, this.onUpSkill, this);
|
||||
EventMgr.on(ServerConfig.general_downSkill, this.onDownSkill, this);
|
||||
EventMgr.on(ServerConfig.general_lvSkill, this.onLvSkill, this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._proxy.clearData();
|
||||
}
|
||||
|
||||
public get proxy(): GeneralProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
|
||||
/**我的将领列表*/
|
||||
protected onMyGenerals(data: any): void {
|
||||
console.log("onMyGeneralsonMyGenerals ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateMyGenerals(data.msg.generals);
|
||||
EventMgr.emit("update_my_generals");
|
||||
}
|
||||
}
|
||||
|
||||
protected onGeneralPush(data: any): void {
|
||||
console.log("onGeneralPush ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateGeneral(data.msg);
|
||||
EventMgr.emit("update_general");
|
||||
}
|
||||
}
|
||||
|
||||
protected onDrawGenerals(data: any): void {
|
||||
console.log("onDrawGenerals ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateMyGenerals(data.msg.generals);
|
||||
EventMgr.emit("update_my_generals");
|
||||
EventMgr.emit("open_draw_result", data.msg.generals);
|
||||
}
|
||||
}
|
||||
|
||||
protected onComposeGeneral(data:any):void{
|
||||
console.log("onComposeGeneral ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateMyGenerals(data.msg.generals);
|
||||
EventMgr.emit("update_my_generals");
|
||||
EventMgr.emit("update_one_generals", data.msg.generals[data.msg.generals.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected onAddPrGeneral(data:any):void{
|
||||
console.log("onAddPrGeneral ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.updateGeneral(data.msg.general);
|
||||
EventMgr.emit("update_one_generals",data.msg.general);
|
||||
}
|
||||
}
|
||||
|
||||
protected onGeneralConvert(data:any):void{
|
||||
console.log("onGeneralConvert ", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.removeMyGenerals(data.msg.gIds);
|
||||
EventMgr.emit("general_convert", data.msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpSkill(data:any):void{
|
||||
console.log("onUpSkill ", data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected onDownSkill(data:any):void{
|
||||
console.log("onDownSkill ", data);
|
||||
|
||||
}
|
||||
|
||||
protected onLvSkill(data:any):void{
|
||||
console.log("onLvSkill ", data);
|
||||
}
|
||||
|
||||
|
||||
/**我的角色属性*/
|
||||
public updateMyProperty(datas: any[]): void {
|
||||
this._proxy.updateMyGenerals(datas);
|
||||
EventMgr.emit("update_my_generals");
|
||||
}
|
||||
|
||||
public qryMyGenerals(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_myGenerals,
|
||||
msg: {
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 抽卡
|
||||
* @param drawTimes
|
||||
*/
|
||||
public drawGenerals(drawTimes:number = 1): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_drawGeneral,
|
||||
msg: {
|
||||
drawTimes:drawTimes
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param compId
|
||||
* @param gIds
|
||||
*/
|
||||
public composeGeneral(compId:number = 1,gIds:number[] = []): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_composeGeneral,
|
||||
msg: {
|
||||
compId:compId,
|
||||
gIds:gIds
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
public addPrGeneral(compId:number = 1,force_add:number,strategy_add:number,defense_add:number,speed_add:number,destroy_add:number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_addPrGeneral,
|
||||
msg: {
|
||||
compId:compId,
|
||||
forceAdd:force_add,
|
||||
strategyAdd:strategy_add,
|
||||
defenseAdd:defense_add,
|
||||
speedAdd:speed_add,
|
||||
destroyAdd:destroy_add
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public convert(gIds:number[]): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_convert,
|
||||
msg: {
|
||||
gIds:gIds
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public upSkill(gId:number, cfgId:number, pos:number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_upSkill,
|
||||
msg: {
|
||||
gId:gId,
|
||||
cfgId:cfgId,
|
||||
pos:Number(pos)
|
||||
}
|
||||
};
|
||||
|
||||
console.log("send upSkill:", sendData);
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public downSkill(gId:number, cfgId:number, pos:number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_downSkill,
|
||||
msg: {
|
||||
gId:gId,
|
||||
cfgId:cfgId,
|
||||
pos:Number(pos)
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
public lvSkill(gId:number, pos:number) {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.general_lvSkill,
|
||||
msg: {
|
||||
gId:gId,
|
||||
pos:Number(pos)
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/general/GeneralCommand.ts.meta
Normal file
11
assets/scripts/general/GeneralCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c4f639d5-6166-491e-9150-f41d145c7395",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
371
assets/scripts/general/GeneralProxy.ts
Normal file
371
assets/scripts/general/GeneralProxy.ts
Normal file
@@ -0,0 +1,371 @@
|
||||
|
||||
import { SpriteFrame } from "cc";
|
||||
|
||||
/**武将(配置)*/
|
||||
export class GeneralConfig {
|
||||
name: string = "";
|
||||
cfgId: number = 0;
|
||||
force: number = 0;
|
||||
strategy: number = 0;
|
||||
defense: number = 0;
|
||||
speed: number = 0;
|
||||
destroy: number = 0;
|
||||
cost: number = 0;
|
||||
|
||||
force_grow: number = 0;
|
||||
strategy_grow: number = 0;
|
||||
defense_grow: number = 0;
|
||||
speed_grow: number = 0;
|
||||
destroy_grow: number = 0;
|
||||
physical_power_limit: number = 0;
|
||||
cost_physical_power: number = 0;
|
||||
probability: number = 0;
|
||||
|
||||
star: number = 0;
|
||||
arms: number[] = [];
|
||||
camp: number = 0;
|
||||
}
|
||||
|
||||
/**武将等级配置*/
|
||||
export class GenaralLevelConfig {
|
||||
level: number = 0;
|
||||
exp: number = 0;
|
||||
soldiers: number = 0;
|
||||
}
|
||||
|
||||
/**武将阵营枚举*/
|
||||
export class GeneralCampType {
|
||||
static Han: number = 1;
|
||||
static Qun: number = 2;
|
||||
static Wei: number = 3;
|
||||
static Shu: number = 4;
|
||||
static Wu: number = 5;
|
||||
}
|
||||
|
||||
/**武将共有配置*/
|
||||
export class GeneralCommonConfig {
|
||||
physical_power_limit: number = 100;
|
||||
cost_physical_power: number = 10;
|
||||
recovery_physical_power: number = 10;
|
||||
reclamation_time: number = 3600;
|
||||
draw_general_cost: number = 0;
|
||||
}
|
||||
|
||||
export class gSkill {
|
||||
id: number = 0;
|
||||
lv: number = 0;
|
||||
cfgId: number = 0;
|
||||
}
|
||||
|
||||
/**武将数据*/
|
||||
export class GeneralData {
|
||||
id: number = 0;
|
||||
cfgId: number = 0;
|
||||
exp: number = 0;
|
||||
level: number = 0;
|
||||
physical_power: number = 0;
|
||||
order: number = 0;
|
||||
star_lv: number = 0;
|
||||
parentId: number = 0;
|
||||
state: number = 0;
|
||||
|
||||
hasPrPoint: number = 0;
|
||||
usePrPoint: number = 0;
|
||||
force_added: number = 0;
|
||||
strategy_added: number = 0;
|
||||
defense_added: number = 0;
|
||||
speed_added: number = 0;
|
||||
destroy_added: number = 0;
|
||||
config: GeneralConfig = new GeneralConfig();
|
||||
skills: gSkill[] = [];
|
||||
|
||||
|
||||
public static createFromServer(serverData: any, generalData: GeneralData = null, generalCfg: GeneralConfig): GeneralData {
|
||||
let data: GeneralData = generalData;
|
||||
if (data == null) {
|
||||
data = new GeneralData();
|
||||
}
|
||||
data.id = serverData.id;
|
||||
data.cfgId = serverData.cfgId;
|
||||
data.exp = serverData.exp;
|
||||
data.level = serverData.level;
|
||||
data.order = serverData.order;
|
||||
data.physical_power = serverData.physical_power;
|
||||
data.star_lv = serverData.star_lv;
|
||||
data.parentId = serverData.parentId;
|
||||
data.state = serverData.state;
|
||||
|
||||
data.hasPrPoint = serverData.hasPrPoint;
|
||||
data.usePrPoint = serverData.usePrPoint;
|
||||
data.force_added = serverData.force_added;
|
||||
data.strategy_added = serverData.strategy_added;
|
||||
data.defense_added = serverData.defense_added;
|
||||
data.speed_added = serverData.speed_added;
|
||||
data.destroy_added = serverData.destroy_added;
|
||||
data.config = generalCfg;
|
||||
data.skills = serverData.skills;
|
||||
|
||||
// console.log("createFromServer:", data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static getPrValue(pr: number = 0, group:number, add: number = 0): number {
|
||||
return (pr + group + add) / 100;
|
||||
}
|
||||
|
||||
public static getPrStr(pr: number = 0, add: number = 0, lv: number = 0, grow: number = 0): string {
|
||||
return (pr + add) / 100 + "+(" + lv * grow / 100 + ")";
|
||||
}
|
||||
}
|
||||
|
||||
export default class GeneralProxy {
|
||||
//武将基础配置数据
|
||||
protected _generalConfigs: Map<number, GeneralConfig> = new Map<number, GeneralConfig>();
|
||||
protected _levelConfigs: GenaralLevelConfig[] = [];
|
||||
protected _commonConfig: GeneralCommonConfig = new GeneralCommonConfig();
|
||||
protected _generalTexs: Map<number, SpriteFrame> = new Map<number, SpriteFrame>();
|
||||
protected _myGenerals: Map<number, GeneralData> = new Map<number, GeneralData>();
|
||||
|
||||
public clearData(): void {
|
||||
this._myGenerals.clear();
|
||||
}
|
||||
|
||||
public initGeneralConfig(cfgs: any[], bCost: any): void {
|
||||
let cfgData: any = null;
|
||||
let levelData: any = null;
|
||||
for (let i: number = 0; i < cfgs.length; i++) {
|
||||
console
|
||||
if (cfgs[i]._name == "general") {
|
||||
cfgData = cfgs[i].json.list;
|
||||
} else if (cfgs[i]._name == "general_basic") {
|
||||
levelData = cfgs[i].json.levels;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgData) {
|
||||
this._generalConfigs.clear();
|
||||
for (let i: number = 0; i < cfgData.length; i++) {
|
||||
var cfg: GeneralConfig = new GeneralConfig();
|
||||
cfg.cfgId = cfgData[i].cfgId;
|
||||
cfg.name = cfgData[i].name;
|
||||
cfg.force = cfgData[i].force;
|
||||
cfg.strategy = cfgData[i].strategy;
|
||||
cfg.defense = cfgData[i].defense;
|
||||
cfg.speed = cfgData[i].speed;
|
||||
cfg.destroy = cfgData[i].destroy;
|
||||
cfg.cost = cfgData[i].cost;
|
||||
|
||||
cfg.force_grow = cfgData[i].force_grow;
|
||||
cfg.strategy_grow = cfgData[i].strategy_grow;
|
||||
cfg.defense_grow = cfgData[i].defense_grow;
|
||||
cfg.speed_grow = cfgData[i].speed_grow;
|
||||
cfg.destroy_grow = cfgData[i].destroy_grow;
|
||||
cfg.physical_power_limit = bCost.general.physical_power_limit;
|
||||
cfg.cost_physical_power = bCost.general.cost_physical_power;
|
||||
|
||||
cfg.star = cfgData[i].star;
|
||||
cfg.arms = cfgData[i].arms;
|
||||
cfg.camp = cfgData[i].camp;
|
||||
this._generalConfigs.set(cfg.cfgId, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
if (levelData) {
|
||||
this._levelConfigs.length = levelData.length;
|
||||
for (let i: number = 0; i < levelData.length; i++) {
|
||||
var levelCfg: GenaralLevelConfig = new GenaralLevelConfig();
|
||||
levelCfg.level = levelData[i].level;
|
||||
levelCfg.exp = levelData[i].exp;
|
||||
levelCfg.soldiers = levelData[i].soldiers;
|
||||
this._levelConfigs[levelCfg.level - 1] = levelCfg;
|
||||
}
|
||||
}
|
||||
|
||||
this._commonConfig.physical_power_limit = bCost.general.physical_power_limit;
|
||||
this._commonConfig.cost_physical_power = bCost.general.cost_physical_power;
|
||||
this._commonConfig.recovery_physical_power = bCost.general.recovery_physical_power;
|
||||
this._commonConfig.reclamation_time = bCost.general.reclamation_time;
|
||||
this._commonConfig.draw_general_cost = bCost.general.draw_general_cost;
|
||||
}
|
||||
|
||||
public initGeneralTex(texs: SpriteFrame[]): void {
|
||||
this._generalTexs.clear();
|
||||
for (let i: number = 0; i < texs.length; i++) {
|
||||
let id: number = Number(String(texs[i].name).split("_")[1]);
|
||||
this._generalTexs.set(id, texs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public updateMyGenerals(datas: any[]): void {
|
||||
for (var i = 0; i < datas.length; i++) {
|
||||
let data: GeneralData = GeneralData.createFromServer(datas[i], null, this._generalConfigs.get(datas[i].cfgId));
|
||||
this._myGenerals.set(data.id, data);
|
||||
}
|
||||
}
|
||||
|
||||
public updateGeneral(data: any) {
|
||||
if(data.state != 0){
|
||||
this._myGenerals.delete(data.id);
|
||||
}else{
|
||||
let ids: number[] = [];
|
||||
let general: GeneralData = GeneralData.createFromServer(data, this._myGenerals.get(data.id), this._generalConfigs.get(data.cfgId));
|
||||
this._myGenerals.set(general.id, general);
|
||||
ids.push(general.id);
|
||||
}
|
||||
}
|
||||
|
||||
public removeMyGenerals(ids: number[]) {
|
||||
ids.forEach(id => {
|
||||
this._myGenerals.delete(id);
|
||||
});
|
||||
}
|
||||
|
||||
/**武将配置*/
|
||||
public getGeneralCfg(cfgId: number): GeneralConfig {
|
||||
if (this._generalConfigs.has(cfgId)) {
|
||||
return this._generalConfigs.get(cfgId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getGeneralAllCfg(): Map<number, GeneralConfig>{
|
||||
return this._generalConfigs
|
||||
}
|
||||
|
||||
/**武将等级配置*/
|
||||
public getGeneralLevelCfg(level: number): GenaralLevelConfig {
|
||||
if (level > 0 && level <= this._levelConfigs.length) {
|
||||
return this._levelConfigs[level - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getMaxLevel(): number {
|
||||
return this._levelConfigs.length;
|
||||
}
|
||||
|
||||
/**武将头像素材*/
|
||||
public getGeneralTex(cfgId: number): SpriteFrame {
|
||||
if (this._generalTexs.has(cfgId)) {
|
||||
return this._generalTexs.get(cfgId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public setGeneralTex(cfgId: number, frame: SpriteFrame) {
|
||||
this._generalTexs.set(cfgId, frame);
|
||||
}
|
||||
|
||||
/**武将相关公有配置*/
|
||||
public getCommonCfg(): GeneralCommonConfig {
|
||||
return this._commonConfig;
|
||||
}
|
||||
|
||||
|
||||
public getMyActiveGeneralCnt() {
|
||||
var arr = this.getMyGenerals()
|
||||
var cnt = 0
|
||||
arr.forEach(g => {
|
||||
if(g.state == 0){
|
||||
cnt += 1
|
||||
}
|
||||
});
|
||||
return cnt
|
||||
}
|
||||
|
||||
/**我的武将列表*/
|
||||
public getMyGenerals(): GeneralData[] {
|
||||
return Array.from(this._myGenerals.values());
|
||||
}
|
||||
|
||||
public getMyGeneralsNotUse(): GeneralData[] {
|
||||
var arr = Array.from(this._myGenerals.values());
|
||||
let generals: GeneralData[] = [];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const obj = arr[i];
|
||||
if (obj.order == 0 && obj.state == 0){
|
||||
generals.push(obj);
|
||||
}
|
||||
}
|
||||
return generals;
|
||||
}
|
||||
|
||||
|
||||
/**我的武将*/
|
||||
public getMyGeneral(id: number): GeneralData {
|
||||
if (this._myGenerals.has(id)) {
|
||||
return this._myGenerals.get(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**相同类型的武将id */
|
||||
public getGeneralIds(cfgId: number): number[] {
|
||||
let myGenerals: GeneralData[] = this.getMyGenerals();
|
||||
let tempGenerals: number[] = [];
|
||||
for (var i = 0; i < myGenerals.length; i++) {
|
||||
if (myGenerals[i].cfgId == cfgId) {
|
||||
tempGenerals.push(myGenerals[i].id)
|
||||
}
|
||||
}
|
||||
return tempGenerals;
|
||||
}
|
||||
|
||||
|
||||
protected sortStar(a: GeneralData, b: GeneralData): number {
|
||||
|
||||
if(a.config.star < b.config.star){
|
||||
return 1;
|
||||
}else if(a.config.star == b.config.star){
|
||||
return a.cfgId - b.cfgId;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序 已经使用的
|
||||
*/
|
||||
public getUseGenerals(): GeneralData[] {
|
||||
var tempArr: GeneralData[] = this.getMyGenerals().concat();
|
||||
tempArr.sort(this.sortStar);
|
||||
var temp: GeneralData[] = [];
|
||||
|
||||
for (var i = 0; i < tempArr.length; i++) {
|
||||
if (tempArr[i].order > 0) {
|
||||
console.log("tempArr[i].order:",tempArr[i].order,tempArr[i].config.name)
|
||||
temp.push(tempArr[i]);
|
||||
tempArr.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < tempArr.length; i++) {
|
||||
if (tempArr[i].parentId > 0) {
|
||||
tempArr.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
temp = temp.concat(tempArr);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public getComposeGenerals(cfgId: number = 0, id: number = 0): GeneralData[] {
|
||||
var temp: GeneralData[] = [];
|
||||
var tempArr: GeneralData[] = this.getMyGenerals().concat();
|
||||
|
||||
for (var i = 0; i < tempArr.length; i++) {
|
||||
if (tempArr[i].order > 0 || tempArr[i].id == id || tempArr[i].cfgId != cfgId || tempArr[i].parentId > 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
temp.push(tempArr[i]);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/general/GeneralProxy.ts.meta
Normal file
11
assets/scripts/general/GeneralProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9a494869-e1d0-43e7-b99a-735d5668fdd8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/libs.meta
Normal file
12
assets/scripts/libs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "9dde25ec-eb16-46bb-9e14-90a0680372c3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
50
assets/scripts/libs/convert.ts
Normal file
50
assets/scripts/libs/convert.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
|
||||
export class convert {
|
||||
stringToByte(str) {
|
||||
var bytes = new Array();
|
||||
var len, c;
|
||||
len = str.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
c = str.charCodeAt(i);
|
||||
if (c >= 0x010000 && c <= 0x10FFFF) {
|
||||
bytes.push(((c >> 18) & 0x07) | 0xF0);
|
||||
bytes.push(((c >> 12) & 0x3F) | 0x80);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000800 && c <= 0x00FFFF) {
|
||||
bytes.push(((c >> 12) & 0x0F) | 0xE0);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000080 && c <= 0x0007FF) {
|
||||
bytes.push(((c >> 6) & 0x1F) | 0xC0);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else {
|
||||
bytes.push(c & 0xFF);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
byteToString(arr) {
|
||||
if (typeof arr === 'string') {
|
||||
return arr;
|
||||
}
|
||||
var str = '', _arr = arr;
|
||||
for (var i = 0; i < _arr.length; i++) {
|
||||
var one = _arr[i].toString(2), v = one.match(/^1+?(?=0)/);
|
||||
if (v && one.length == 8) {
|
||||
var bytesLength = v[0].length;
|
||||
var store = _arr[i].toString(2).slice(7 - bytesLength);
|
||||
for (var st = 1; st < bytesLength; st++) {
|
||||
store += _arr[st + i].toString(2).slice(2);
|
||||
}
|
||||
str += String.fromCharCode(parseInt(store, 2));
|
||||
i += bytesLength - 1;
|
||||
} else {
|
||||
str += String.fromCharCode(_arr[i]);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
9
assets/scripts/libs/convert.ts.meta
Normal file
9
assets/scripts/libs/convert.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "827c1ab9-c3c0-4a7b-990a-c7f6e6e58340",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/libs/crypto.meta
Normal file
12
assets/scripts/libs/crypto.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "06b8b43e-7e62-42d0-a003-5a7d480d4e98",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
2277
assets/scripts/libs/crypto/crypto.ts
Normal file
2277
assets/scripts/libs/crypto/crypto.ts
Normal file
File diff suppressed because it is too large
Load Diff
9
assets/scripts/libs/crypto/crypto.ts.meta
Normal file
9
assets/scripts/libs/crypto/crypto.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7b2dc4c7-2f77-4861-bfdd-17bad2444b41",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
400
assets/scripts/libs/crypto/md5.ts
Normal file
400
assets/scripts/libs/crypto/md5.ts
Normal file
@@ -0,0 +1,400 @@
|
||||
"use strict";
|
||||
/*
|
||||
|
||||
TypeScript Md5
|
||||
==============
|
||||
|
||||
Based on work by
|
||||
* Joseph Myers: http://www.myersdaily.org/joseph/javascript/md5-text.html
|
||||
* André Cruz: https://github.com/satazor/SparkMD5
|
||||
* Raymond Hill: https://github.com/gorhill/yamd5.js
|
||||
|
||||
Effectively a TypeScrypt re-write of Raymond Hill JS Library
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 2014 Raymond Hill
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2015 André Cruz <amdfcruz@gmail.com>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
|
||||
*/
|
||||
var Md5 = /** @class */ (function () {
|
||||
function Md5() {
|
||||
this._state = new Int32Array(4);
|
||||
this._buffer = new ArrayBuffer(68);
|
||||
this._buffer8 = new Uint8Array(this._buffer, 0, 68);
|
||||
this._buffer32 = new Uint32Array(this._buffer, 0, 17);
|
||||
this.start();
|
||||
}
|
||||
Md5.hashStr = function (str, raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
return this.onePassHasher
|
||||
.start()
|
||||
.appendStr(str)
|
||||
.end(raw);
|
||||
};
|
||||
|
||||
Md5.encrypt = function(str){
|
||||
return Md5.hashStr(str, false);
|
||||
}
|
||||
Md5.hashAsciiStr = function (str, raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
return this.onePassHasher
|
||||
.start()
|
||||
.appendAsciiStr(str)
|
||||
.end(raw);
|
||||
};
|
||||
Md5._hex = function (x) {
|
||||
var hc = Md5.hexChars;
|
||||
var ho = Md5.hexOut;
|
||||
var n;
|
||||
var offset;
|
||||
var j;
|
||||
var i;
|
||||
for (i = 0; i < 4; i += 1) {
|
||||
offset = i * 8;
|
||||
n = x[i];
|
||||
for (j = 0; j < 8; j += 2) {
|
||||
ho[offset + 1 + j] = hc.charAt(n & 0x0F);
|
||||
n >>>= 4;
|
||||
ho[offset + 0 + j] = hc.charAt(n & 0x0F);
|
||||
n >>>= 4;
|
||||
}
|
||||
}
|
||||
return ho.join('');
|
||||
};
|
||||
Md5._md5cycle = function (x, k) {
|
||||
var a = x[0];
|
||||
var b = x[1];
|
||||
var c = x[2];
|
||||
var d = x[3];
|
||||
// ff()
|
||||
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
// gg()
|
||||
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
// hh()
|
||||
a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
// ii()
|
||||
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
x[0] = a + x[0] | 0;
|
||||
x[1] = b + x[1] | 0;
|
||||
x[2] = c + x[2] | 0;
|
||||
x[3] = d + x[3] | 0;
|
||||
};
|
||||
Md5.prototype.start = function () {
|
||||
this._dataLength = 0;
|
||||
this._bufferLength = 0;
|
||||
this._state.set(Md5.stateIdentity);
|
||||
return this;
|
||||
};
|
||||
// Char to code point to to array conversion:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
|
||||
// #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown
|
||||
Md5.prototype.appendStr = function (str) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var code;
|
||||
var i;
|
||||
for (i = 0; i < str.length; i += 1) {
|
||||
code = str.charCodeAt(i);
|
||||
if (code < 128) {
|
||||
buf8[bufLen++] = code;
|
||||
}
|
||||
else if (code < 0x800) {
|
||||
buf8[bufLen++] = (code >>> 6) + 0xC0;
|
||||
buf8[bufLen++] = code & 0x3F | 0x80;
|
||||
}
|
||||
else if (code < 0xD800 || code > 0xDBFF) {
|
||||
buf8[bufLen++] = (code >>> 12) + 0xE0;
|
||||
buf8[bufLen++] = (code >>> 6 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else {
|
||||
code = ((code - 0xD800) * 0x400) + (str.charCodeAt(++i) - 0xDC00) + 0x10000;
|
||||
if (code > 0x10FFFF) {
|
||||
throw new Error('Unicode standard supports code points up to U+10FFFF');
|
||||
}
|
||||
buf8[bufLen++] = (code >>> 18) + 0xF0;
|
||||
buf8[bufLen++] = (code >>> 12 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code >>> 6 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code & 0x3F) | 0x80;
|
||||
}
|
||||
if (bufLen >= 64) {
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen -= 64;
|
||||
buf32[0] = buf32[16];
|
||||
}
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.appendAsciiStr = function (str) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var i;
|
||||
var j = 0;
|
||||
for (;;) {
|
||||
i = Math.min(str.length - j, 64 - bufLen);
|
||||
while (i--) {
|
||||
buf8[bufLen++] = str.charCodeAt(j++);
|
||||
}
|
||||
if (bufLen < 64) {
|
||||
break;
|
||||
}
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen = 0;
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.appendByteArray = function (input) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var i;
|
||||
var j = 0;
|
||||
for (;;) {
|
||||
i = Math.min(input.length - j, 64 - bufLen);
|
||||
while (i--) {
|
||||
buf8[bufLen++] = input[j++];
|
||||
}
|
||||
if (bufLen < 64) {
|
||||
break;
|
||||
}
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen = 0;
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.getState = function () {
|
||||
var self = this;
|
||||
var s = self._state;
|
||||
return {
|
||||
buffer: String.fromCharCode.apply(null, self._buffer8),
|
||||
buflen: self._bufferLength,
|
||||
length: self._dataLength,
|
||||
state: [s[0], s[1], s[2], s[3]]
|
||||
};
|
||||
};
|
||||
Md5.prototype.setState = function (state) {
|
||||
var buf = state.buffer;
|
||||
var x = state.state;
|
||||
var s = this._state;
|
||||
var i;
|
||||
this._dataLength = state.length;
|
||||
this._bufferLength = state.buflen;
|
||||
s[0] = x[0];
|
||||
s[1] = x[1];
|
||||
s[2] = x[2];
|
||||
s[3] = x[3];
|
||||
for (i = 0; i < buf.length; i += 1) {
|
||||
this._buffer8[i] = buf.charCodeAt(i);
|
||||
}
|
||||
};
|
||||
Md5.prototype.end = function (raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
var bufLen = this._bufferLength;
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var i = (bufLen >> 2) + 1;
|
||||
var dataBitsLen;
|
||||
this._dataLength += bufLen;
|
||||
buf8[bufLen] = 0x80;
|
||||
buf8[bufLen + 1] = buf8[bufLen + 2] = buf8[bufLen + 3] = 0;
|
||||
buf32.set(Md5.buffer32Identity.subarray(i), i);
|
||||
if (bufLen > 55) {
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
buf32.set(Md5.buffer32Identity);
|
||||
}
|
||||
// Do the final computation based on the tail and length
|
||||
// Beware that the final length may not fit in 32 bits so we take care of that
|
||||
dataBitsLen = this._dataLength * 8;
|
||||
if (dataBitsLen <= 0xFFFFFFFF) {
|
||||
buf32[14] = dataBitsLen;
|
||||
}
|
||||
else {
|
||||
var matches = dataBitsLen.toString(16).match(/(.*?)(.{0,8})$/);
|
||||
if (matches === null) {
|
||||
return;
|
||||
}
|
||||
var lo = parseInt(matches[2], 16);
|
||||
var hi = parseInt(matches[1], 16) || 0;
|
||||
buf32[14] = lo;
|
||||
buf32[15] = hi;
|
||||
}
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
return raw ? this._state : Md5._hex(this._state);
|
||||
};
|
||||
// Private Static Variables
|
||||
Md5.stateIdentity = new Int32Array([1732584193, -271733879, -1732584194, 271733878]);
|
||||
Md5.buffer32Identity = new Int32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
Md5.hexChars = '0123456789abcdef';
|
||||
Md5.hexOut = [];
|
||||
// Permanent instance is to use for one-call hashing
|
||||
Md5.onePassHasher = new Md5();
|
||||
return Md5;
|
||||
}());
|
||||
export { Md5 };
|
||||
9
assets/scripts/libs/crypto/md5.ts.meta
Normal file
9
assets/scripts/libs/crypto/md5.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b247f0c9-522a-4358-85ae-a223525516c3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/libs/gzip.meta
Normal file
12
assets/scripts/libs/gzip.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "309a794f-ea53-469b-a13b-7504210605c8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
83
assets/scripts/libs/gzip/crc32.ts
Normal file
83
assets/scripts/libs/gzip/crc32.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
var table = [];
|
||||
var poly = 0xEDB88320; // reverse polynomial
|
||||
|
||||
function makeTable() {
|
||||
var c, n, k;
|
||||
|
||||
for (n = 0; n < 256; n += 1) {
|
||||
c = n;
|
||||
for (k = 0; k < 8; k += 1) {
|
||||
if (c & 1) {
|
||||
c = poly ^ (c >>> 1);
|
||||
} else {
|
||||
c = c >>> 1;
|
||||
}
|
||||
}
|
||||
table[n] = c >>> 0;
|
||||
}
|
||||
}
|
||||
|
||||
function strToArr(str) {
|
||||
// sweet hack to turn string into a 'byte' array
|
||||
return Array.prototype.map.call(str, function (c) {
|
||||
return c.charCodeAt(0);
|
||||
});
|
||||
}
|
||||
|
||||
function crcDirect(arr) {
|
||||
var crc = -1, // initial contents of LFBSR
|
||||
i, j, l, temp;
|
||||
|
||||
for (i = 0, l = arr.length; i < l; i += 1) {
|
||||
temp = (crc ^ arr[i]) & 0xff;
|
||||
|
||||
// read 8 bits one at a time
|
||||
for (j = 0; j < 8; j += 1) {
|
||||
if ((temp & 1) === 1) {
|
||||
temp = (temp >>> 1) ^ poly;
|
||||
} else {
|
||||
temp = (temp >>> 1);
|
||||
}
|
||||
}
|
||||
crc = (crc >>> 8) ^ temp;
|
||||
}
|
||||
|
||||
// flip bits
|
||||
return crc ^ -1;
|
||||
}
|
||||
|
||||
|
||||
function crcTable(arr, append) {
|
||||
var crc, i, l;
|
||||
|
||||
// if we're in append mode, don't reset crc
|
||||
// if arr is null or undefined, reset table and return
|
||||
if (typeof crcTable.crc === 'undefined' || !append || !arr) {
|
||||
crcTable.crc = 0 ^ -1;
|
||||
|
||||
if (!arr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// store in temp variable for minor speed gain
|
||||
crc = crcTable.crc;
|
||||
|
||||
for (i = 0, l = arr.length; i < l; i += 1) {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ arr[i]) & 0xff];
|
||||
}
|
||||
|
||||
crcTable.crc = crc;
|
||||
|
||||
return crc ^ -1;
|
||||
}
|
||||
|
||||
makeTable();
|
||||
|
||||
export function crc32(val, direct) {
|
||||
var val = (typeof val === 'string') ? strToArr(val) : val,
|
||||
ret = direct ? crcDirect(val) : crcTable(val);
|
||||
|
||||
// convert to 2's complement hex
|
||||
return (ret >>> 0).toString(16);
|
||||
};
|
||||
9
assets/scripts/libs/gzip/crc32.ts.meta
Normal file
9
assets/scripts/libs/gzip/crc32.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fc769e4d-a6ae-4a81-b1b1-3703913d3afb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
5
assets/scripts/libs/gzip/deflate-js.ts
Normal file
5
assets/scripts/libs/gzip/deflate-js.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import {inflate} from "./rawinflate"
|
||||
import {deflate} from "./rawdeflate"
|
||||
|
||||
export {inflate, deflate}
|
||||
9
assets/scripts/libs/gzip/deflate-js.ts.meta
Normal file
9
assets/scripts/libs/gzip/deflate-js.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8f67b3f2-2af7-40ad-bfc9-46a299252d4e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
273
assets/scripts/libs/gzip/gzip.ts
Normal file
273
assets/scripts/libs/gzip/gzip.ts
Normal file
@@ -0,0 +1,273 @@
|
||||
|
||||
|
||||
import { crc32 } from "./crc32";
|
||||
import * as deflate from "./deflate-js";
|
||||
|
||||
// magic numbers marking this file as GZIP
|
||||
var ID1 = 0x1F,
|
||||
ID2 = 0x8B,
|
||||
compressionMethods = {
|
||||
'deflate': 8
|
||||
},
|
||||
possibleFlags = {
|
||||
'FTEXT': 0x01,
|
||||
'FHCRC': 0x02,
|
||||
'FEXTRA': 0x04,
|
||||
'FNAME': 0x08,
|
||||
'FCOMMENT': 0x10
|
||||
},
|
||||
osMap = {
|
||||
'fat': 0, // FAT file system (DOS, OS/2, NT) + PKZIPW 2.50 VFAT, NTFS
|
||||
'amiga': 1, // Amiga
|
||||
'vmz': 2, // VMS (VAX or Alpha AXP)
|
||||
'unix': 3, // Unix
|
||||
'vm/cms': 4, // VM/CMS
|
||||
'atari': 5, // Atari
|
||||
'hpfs': 6, // HPFS file system (OS/2, NT 3.x)
|
||||
'macintosh': 7, // Macintosh
|
||||
'z-system': 8, // Z-System
|
||||
'cplm': 9, // CP/M
|
||||
'tops-20': 10, // TOPS-20
|
||||
'ntfs': 11, // NTFS file system (NT)
|
||||
'qdos': 12, // SMS/QDOS
|
||||
'acorn': 13, // Acorn RISC OS
|
||||
'vfat': 14, // VFAT file system (Win95, NT)
|
||||
'vms': 15, // MVS (code also taken for PRIMOS)
|
||||
'beos': 16, // BeOS (BeBox or PowerMac)
|
||||
'tandem': 17, // Tandem/NSK
|
||||
'theos': 18 // THEOS
|
||||
},
|
||||
os = 'unix',
|
||||
DEFAULT_LEVEL = 6;
|
||||
|
||||
function putByte(n, arr) {
|
||||
arr.push(n & 0xFF);
|
||||
}
|
||||
|
||||
// LSB first
|
||||
function putShort(n, arr) {
|
||||
arr.push(n & 0xFF);
|
||||
arr.push(n >>> 8);
|
||||
}
|
||||
|
||||
// LSB first
|
||||
function putLong(n, arr) {
|
||||
putShort(n & 0xffff, arr);
|
||||
putShort(n >>> 16, arr);
|
||||
}
|
||||
|
||||
function putString(s, arr) {
|
||||
var i, len = s.length;
|
||||
for (i = 0; i < len; i += 1) {
|
||||
putByte(s.charCodeAt(i), arr);
|
||||
}
|
||||
}
|
||||
|
||||
function readByte(arr) {
|
||||
return arr.shift();
|
||||
}
|
||||
|
||||
function readShort(arr) {
|
||||
return arr.shift() | (arr.shift() << 8);
|
||||
}
|
||||
|
||||
function readLong(arr) {
|
||||
var n1 = readShort(arr),
|
||||
n2 = readShort(arr);
|
||||
|
||||
// JavaScript can't handle bits in the position 32
|
||||
// we'll emulate this by removing the left-most bit (if it exists)
|
||||
// and add it back in via multiplication, which does work
|
||||
if (n2 > 32768) {
|
||||
n2 -= 32768;
|
||||
|
||||
return ((n2 << 16) | n1) + 32768 * Math.pow(2, 16);
|
||||
}
|
||||
|
||||
return (n2 << 16) | n1;
|
||||
}
|
||||
|
||||
function readString(arr) {
|
||||
var charArr = [];
|
||||
|
||||
// turn all bytes into chars until the terminating null
|
||||
while (arr[0] !== 0) {
|
||||
charArr.push(String.fromCharCode(arr.shift()));
|
||||
}
|
||||
|
||||
// throw away terminating null
|
||||
arr.shift();
|
||||
|
||||
// join all characters into a cohesive string
|
||||
return charArr.join('');
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads n number of bytes and return as an array.
|
||||
*
|
||||
* @param arr- Array of bytes to read from
|
||||
* @param n- Number of bytes to read
|
||||
*/
|
||||
function readBytes(arr, n) {
|
||||
var i, ret = [];
|
||||
for (i = 0; i < n; i += 1) {
|
||||
ret.push(arr.shift());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* ZIPs a file in GZIP format. The format is as given by the spec, found at:
|
||||
* http://www.gzip.org/zlib/rfc-gzip.html
|
||||
*
|
||||
* Omitted parts in this implementation:
|
||||
*/
|
||||
export function zip(data, options) {
|
||||
var flags = 0,
|
||||
level,
|
||||
crc, out = [];
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
level = options.level || DEFAULT_LEVEL;
|
||||
|
||||
if (typeof data === 'string') {
|
||||
data = Array.prototype.map.call(data, function (char) {
|
||||
return char.charCodeAt(0);
|
||||
});
|
||||
}
|
||||
|
||||
// magic number marking this file as GZIP
|
||||
putByte(ID1, out);
|
||||
putByte(ID2, out);
|
||||
|
||||
putByte(compressionMethods['deflate'], out);
|
||||
|
||||
if (options.name) {
|
||||
flags |= possibleFlags['FNAME'];
|
||||
}
|
||||
|
||||
putByte(flags, out);
|
||||
putLong(options.timestamp || parseInt(Date.now() / 1000, 10), out);
|
||||
|
||||
// put deflate args (extra flags)
|
||||
if (level === 1) {
|
||||
// fastest algorithm
|
||||
putByte(4, out);
|
||||
} else if (level === 9) {
|
||||
// maximum compression (fastest algorithm)
|
||||
putByte(2, out);
|
||||
} else {
|
||||
putByte(0, out);
|
||||
}
|
||||
|
||||
// OS identifier
|
||||
putByte(osMap[os], out);
|
||||
|
||||
if (options.name) {
|
||||
// ignore the directory part
|
||||
putString(options.name.substring(options.name.lastIndexOf('/') + 1), out);
|
||||
|
||||
// terminating null
|
||||
putByte(0, out);
|
||||
}
|
||||
|
||||
deflate.deflate(data, level).forEach(function (byte) {
|
||||
putByte(byte, out);
|
||||
});
|
||||
|
||||
putLong(parseInt(crc32(data), 16), out);
|
||||
putLong(data.length, out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
export function unzip(data) {
|
||||
// start with a copy of the array
|
||||
var arr = Array.prototype.slice.call(data, 0),
|
||||
t,
|
||||
compressionMethod,
|
||||
flags,
|
||||
mtime,
|
||||
xFlags,
|
||||
key,
|
||||
os,
|
||||
crc,
|
||||
size,
|
||||
res;
|
||||
|
||||
// check the first two bytes for the magic numbers
|
||||
if (readByte(arr) !== ID1 || readByte(arr) !== ID2) {
|
||||
throw 'Not a GZIP file';
|
||||
}
|
||||
|
||||
t = readByte(arr);
|
||||
t = Object.keys(compressionMethods).some(function (key) {
|
||||
compressionMethod = key;
|
||||
return compressionMethods[key] === t;
|
||||
});
|
||||
|
||||
if (!t) {
|
||||
throw 'Unsupported compression method';
|
||||
}
|
||||
|
||||
flags = readByte(arr);
|
||||
mtime = readLong(arr);
|
||||
xFlags = readByte(arr);
|
||||
t = readByte(arr);
|
||||
Object.keys(osMap).some(function (key) {
|
||||
if (osMap[key] === t) {
|
||||
os = key;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// just throw away the bytes for now
|
||||
if (flags & possibleFlags['FEXTRA']) {
|
||||
t = readShort(arr);
|
||||
readBytes(arr, t);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FNAME']) {
|
||||
readString(arr);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FCOMMENT']) {
|
||||
readString(arr);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FHCRC']) {
|
||||
readShort(arr);
|
||||
}
|
||||
|
||||
if (compressionMethod === 'deflate') {
|
||||
// give deflate everything but the last 8 bytes
|
||||
// the last 8 bytes are for the CRC32 checksum and filesize
|
||||
res = deflate.inflate(arr.splice(0, arr.length - 8));
|
||||
}
|
||||
|
||||
if (flags & possibleFlags['FTEXT']) {
|
||||
res = Array.prototype.map.call(res, function (byte) {
|
||||
return String.fromCharCode(byte);
|
||||
}).join('');
|
||||
}
|
||||
|
||||
crc = readLong(arr) >>> 0;
|
||||
if (crc !== parseInt(crc32(res), 16)) {
|
||||
throw 'Checksum does not match';
|
||||
}
|
||||
|
||||
size = readLong(arr);
|
||||
if (size !== res.length) {
|
||||
throw 'Size of decompressed file not correct';
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
9
assets/scripts/libs/gzip/gzip.ts.meta
Normal file
9
assets/scripts/libs/gzip/gzip.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "333c586f-0634-4727-b1a3-cbf2d0461cf2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
1692
assets/scripts/libs/gzip/rawdeflate.ts
Normal file
1692
assets/scripts/libs/gzip/rawdeflate.ts
Normal file
File diff suppressed because it is too large
Load Diff
9
assets/scripts/libs/gzip/rawdeflate.ts.meta
Normal file
9
assets/scripts/libs/gzip/rawdeflate.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "edd7bf06-20cc-41a7-ad71-138340c69a5e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
808
assets/scripts/libs/gzip/rawinflate.ts
Normal file
808
assets/scripts/libs/gzip/rawinflate.ts
Normal file
@@ -0,0 +1,808 @@
|
||||
/*
|
||||
* $Id: rawinflate.js,v 0.2 2009/03/01 18:32:24 dankogai Exp $
|
||||
*
|
||||
* original:
|
||||
* http://www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
|
||||
* Version: 1.0.0.1
|
||||
* LastModified: Dec 25 1999
|
||||
*/
|
||||
|
||||
/* Interface:
|
||||
* data = inflate(src);
|
||||
*/
|
||||
|
||||
/* constant parameters */
|
||||
var WSIZE = 32768, // Sliding Window size
|
||||
STORED_BLOCK = 0,
|
||||
STATIC_TREES = 1,
|
||||
DYN_TREES = 2,
|
||||
|
||||
/* for inflate */
|
||||
lbits = 9, // bits in base literal/length lookup table
|
||||
dbits = 6, // bits in base distance lookup table
|
||||
|
||||
/* variables (inflate) */
|
||||
slide,
|
||||
wp, // current position in slide
|
||||
fixed_tl = null, // inflate static
|
||||
fixed_td, // inflate static
|
||||
fixed_bl, // inflate static
|
||||
fixed_bd, // inflate static
|
||||
bit_buf, // bit buffer
|
||||
bit_len, // bits in bit buffer
|
||||
method,
|
||||
eof,
|
||||
copy_leng,
|
||||
copy_dist,
|
||||
tl, // literal length decoder table
|
||||
td, // literal distance decoder table
|
||||
bl, // number of bits decoded by tl
|
||||
bd, // number of bits decoded by td
|
||||
|
||||
inflate_data,
|
||||
inflate_pos,
|
||||
|
||||
|
||||
/* constant tables (inflate) */
|
||||
MASK_BITS = [
|
||||
0x0000,
|
||||
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
],
|
||||
// Tables for deflate from PKZIP's appnote.txt.
|
||||
// Copy lengths for literal codes 257..285
|
||||
cplens = [
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
],
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
// Extra bits for literal codes 257..285
|
||||
cplext = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 // 99==invalid
|
||||
],
|
||||
// Copy offsets for distance codes 0..29
|
||||
cpdist = [
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577
|
||||
],
|
||||
// Extra bits for distance codes
|
||||
cpdext = [
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13
|
||||
],
|
||||
// Order of the bit length code lengths
|
||||
border = [
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
];
|
||||
/* objects (inflate) */
|
||||
|
||||
function HuftList() {
|
||||
this.next = null;
|
||||
this.list = null;
|
||||
}
|
||||
|
||||
function HuftNode() {
|
||||
this.e = 0; // number of extra bits or operation
|
||||
this.b = 0; // number of bits in this code or subcode
|
||||
|
||||
// union
|
||||
this.n = 0; // literal, length base, or distance base
|
||||
this.t = null; // (HuftNode) pointer to next level of table
|
||||
}
|
||||
|
||||
/*
|
||||
* @param b- code lengths in bits (all assumed <= BMAX)
|
||||
* @param n- number of codes (assumed <= N_MAX)
|
||||
* @param s- number of simple-valued codes (0..s-1)
|
||||
* @param d- list of base values for non-simple codes
|
||||
* @param e- list of extra bits for non-simple codes
|
||||
* @param mm- maximum lookup bits
|
||||
*/
|
||||
function HuftBuild(b, n, s, d, e, mm) {
|
||||
this.BMAX = 16; // maximum bit length of any code
|
||||
this.N_MAX = 288; // maximum number of codes in any set
|
||||
this.status = 0; // 0: success, 1: incomplete table, 2: bad input
|
||||
this.root = null; // (HuftList) starting table
|
||||
this.m = 0; // maximum lookup bits, returns actual
|
||||
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return zero on success, one if
|
||||
the given code set is incomplete (the tables are still built in this
|
||||
case), two if the input is invalid (all zero length codes or an
|
||||
oversubscribed set of lengths), and three if not enough memory.
|
||||
The code with value 256 is special, and the tables are constructed
|
||||
so that no bits beyond that code are fetched when that code is
|
||||
decoded. */
|
||||
var a; // counter for codes of length k
|
||||
var c = [];
|
||||
var el; // length of EOB code (value 256)
|
||||
var f; // i repeats in table every f entries
|
||||
var g; // maximum code length
|
||||
var h; // table level
|
||||
var i; // counter, current code
|
||||
var j; // counter
|
||||
var k; // number of bits in current code
|
||||
var lx = [];
|
||||
var p; // pointer into c[], b[], or v[]
|
||||
var pidx; // index of p
|
||||
var q; // (HuftNode) points to current table
|
||||
var r = new HuftNode(); // table entry for structure assignment
|
||||
var u = [];
|
||||
var v = [];
|
||||
var w;
|
||||
var x = [];
|
||||
var xp; // pointer into x or c
|
||||
var y; // number of dummy codes added
|
||||
var z; // number of entries in current table
|
||||
var o;
|
||||
var tail; // (HuftList)
|
||||
|
||||
tail = this.root = null;
|
||||
|
||||
// bit length count table
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
c[i] = 0;
|
||||
}
|
||||
// stack of bits per table
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
lx[i] = 0;
|
||||
}
|
||||
// HuftNode[BMAX][] table stack
|
||||
for (i = 0; i < this.BMAX; i++) {
|
||||
u[i] = null;
|
||||
}
|
||||
// values in order of bit length
|
||||
for (i = 0; i < this.N_MAX; i++) {
|
||||
v[i] = 0;
|
||||
}
|
||||
// bit offsets, then code stack
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
x[i] = 0;
|
||||
}
|
||||
|
||||
// Generate counts for each bit length
|
||||
el = n > 256 ? b[256] : this.BMAX; // set length of EOB code, if any
|
||||
p = b; pidx = 0;
|
||||
i = n;
|
||||
do {
|
||||
c[p[pidx]]++; // assume all entries <= BMAX
|
||||
pidx++;
|
||||
} while (--i > 0);
|
||||
if (c[0] === n) { // null input--all zero length codes
|
||||
this.root = null;
|
||||
this.m = 0;
|
||||
this.status = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find minimum and maximum length, bound *m by those
|
||||
for (j = 1; j <= this.BMAX; j++) {
|
||||
if (c[j] !== 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
k = j; // minimum code length
|
||||
if (mm < j) {
|
||||
mm = j;
|
||||
}
|
||||
for (i = this.BMAX; i !== 0; i--) {
|
||||
if (c[i] !== 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g = i; // maximum code length
|
||||
if (mm > i) {
|
||||
mm = i;
|
||||
}
|
||||
|
||||
// Adjust last length count to fill out codes, if needed
|
||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||
if ((y -= c[j]) < 0) {
|
||||
this.status = 2; // bad input: more codes than bits
|
||||
this.m = mm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0) {
|
||||
this.status = 2;
|
||||
this.m = mm;
|
||||
return;
|
||||
}
|
||||
c[i] += y;
|
||||
|
||||
// Generate starting offsets into the value table for each length
|
||||
x[1] = j = 0;
|
||||
p = c;
|
||||
pidx = 1;
|
||||
xp = 2;
|
||||
while (--i > 0) { // note that i == g from above
|
||||
x[xp++] = (j += p[pidx++]);
|
||||
}
|
||||
|
||||
// Make a table of values in order of bit lengths
|
||||
p = b; pidx = 0;
|
||||
i = 0;
|
||||
do {
|
||||
if ((j = p[pidx++]) !== 0) {
|
||||
v[x[j]++] = i;
|
||||
}
|
||||
} while (++i < n);
|
||||
n = x[g]; // set n to length of v
|
||||
|
||||
// Generate the Huffman codes and for each, make the table entries
|
||||
x[0] = i = 0; // first Huffman code is zero
|
||||
p = v; pidx = 0; // grab values in bit order
|
||||
h = -1; // no tables yet--level -1
|
||||
w = lx[0] = 0; // no bits decoded yet
|
||||
q = null; // ditto
|
||||
z = 0; // ditto
|
||||
|
||||
// go through the bit lengths (k already is bits in shortest code)
|
||||
for (null; k <= g; k++) {
|
||||
a = c[k];
|
||||
while (a-- > 0) {
|
||||
// here i is the Huffman code of length k bits for value p[pidx]
|
||||
// make tables up to required level
|
||||
while (k > w + lx[1 + h]) {
|
||||
w += lx[1 + h]; // add bits already decoded
|
||||
h++;
|
||||
|
||||
// compute minimum size table less than or equal to *m bits
|
||||
z = (z = g - w) > mm ? mm : z; // upper limit
|
||||
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
|
||||
// too few codes for k-w bit table
|
||||
f -= a + 1; // deduct codes from patterns left
|
||||
xp = k;
|
||||
while (++j < z) { // try smaller tables up to z bits
|
||||
if ((f <<= 1) <= c[++xp]) {
|
||||
break; // enough codes to use up j bits
|
||||
}
|
||||
f -= c[xp]; // else deduct codes from patterns
|
||||
}
|
||||
}
|
||||
if (w + j > el && w < el) {
|
||||
j = el - w; // make EOB code end at table
|
||||
}
|
||||
z = 1 << j; // table entries for j-bit table
|
||||
lx[1 + h] = j; // set table size in stack
|
||||
|
||||
// allocate and link in new table
|
||||
q = [];
|
||||
for (o = 0; o < z; o++) {
|
||||
q[o] = new HuftNode();
|
||||
}
|
||||
|
||||
if (!tail) {
|
||||
tail = this.root = new HuftList();
|
||||
} else {
|
||||
tail = tail.next = new HuftList();
|
||||
}
|
||||
tail.next = null;
|
||||
tail.list = q;
|
||||
u[h] = q; // table starts after link
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h > 0) {
|
||||
x[h] = i; // save pattern for backing up
|
||||
r.b = lx[h]; // bits to dump before this table
|
||||
r.e = 16 + j; // bits in this table
|
||||
r.t = q; // pointer to this table
|
||||
j = (i & ((1 << w) - 1)) >> (w - lx[h]);
|
||||
u[h - 1][j].e = r.e;
|
||||
u[h - 1][j].b = r.b;
|
||||
u[h - 1][j].n = r.n;
|
||||
u[h - 1][j].t = r.t;
|
||||
}
|
||||
}
|
||||
|
||||
// set up table entry in r
|
||||
r.b = k - w;
|
||||
if (pidx >= n) {
|
||||
r.e = 99; // out of values--invalid code
|
||||
} else if (p[pidx] < s) {
|
||||
r.e = (p[pidx] < 256 ? 16 : 15); // 256 is end-of-block code
|
||||
r.n = p[pidx++]; // simple code is just the value
|
||||
} else {
|
||||
r.e = e[p[pidx] - s]; // non-simple--look up in lists
|
||||
r.n = d[p[pidx++] - s];
|
||||
}
|
||||
|
||||
// fill code-like entries with r //
|
||||
f = 1 << (k - w);
|
||||
for (j = i >> w; j < z; j += f) {
|
||||
q[j].e = r.e;
|
||||
q[j].b = r.b;
|
||||
q[j].n = r.n;
|
||||
q[j].t = r.t;
|
||||
}
|
||||
|
||||
// backwards increment the k-bit code i
|
||||
for (j = 1 << (k - 1); (i & j) !== 0; j >>= 1) {
|
||||
i ^= j;
|
||||
}
|
||||
i ^= j;
|
||||
|
||||
// backup over finished tables
|
||||
while ((i & ((1 << w) - 1)) !== x[h]) {
|
||||
w -= lx[h]; // don't need to update q
|
||||
h--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* return actual size of base table */
|
||||
this.m = lx[1];
|
||||
|
||||
/* Return true (1) if we were given an incomplete table */
|
||||
this.status = ((y !== 0 && g !== 1) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
/* routines (inflate) */
|
||||
|
||||
function GET_BYTE() {
|
||||
if (inflate_data.length === inflate_pos) {
|
||||
return -1;
|
||||
}
|
||||
return inflate_data[inflate_pos++] & 0xff;
|
||||
}
|
||||
|
||||
function NEEDBITS(n) {
|
||||
while (bit_len < n) {
|
||||
bit_buf |= GET_BYTE() << bit_len;
|
||||
bit_len += 8;
|
||||
}
|
||||
}
|
||||
|
||||
function GETBITS(n) {
|
||||
return bit_buf & MASK_BITS[n];
|
||||
}
|
||||
|
||||
function DUMPBITS(n) {
|
||||
bit_buf >>= n;
|
||||
bit_len -= n;
|
||||
}
|
||||
|
||||
function inflate_codes(buff, off, size) {
|
||||
// inflate (decompress) the codes in a deflated (compressed) block.
|
||||
// Return an error code or zero if it all goes ok.
|
||||
var e; // table entry flag/number of extra bits
|
||||
var t; // (HuftNode) pointer to table entry
|
||||
var n;
|
||||
|
||||
if (size === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// inflate the coded data
|
||||
n = 0;
|
||||
for (;;) { // do until end of block
|
||||
NEEDBITS(bl);
|
||||
t = tl.list[GETBITS(bl)];
|
||||
e = t.e;
|
||||
while (e > 16) {
|
||||
if (e === 99) {
|
||||
return -1;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
e -= 16;
|
||||
NEEDBITS(e);
|
||||
t = t.t[GETBITS(e)];
|
||||
e = t.e;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
|
||||
if (e === 16) { // then it's a literal
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = t.n;
|
||||
if (n === size) {
|
||||
return size;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// exit if end of block
|
||||
if (e === 15) {
|
||||
break;
|
||||
}
|
||||
|
||||
// it's an EOB or a length
|
||||
|
||||
// get length of block to copy
|
||||
NEEDBITS(e);
|
||||
copy_leng = t.n + GETBITS(e);
|
||||
DUMPBITS(e);
|
||||
|
||||
// decode distance of block to copy
|
||||
NEEDBITS(bd);
|
||||
t = td.list[GETBITS(bd)];
|
||||
e = t.e;
|
||||
|
||||
while (e > 16) {
|
||||
if (e === 99) {
|
||||
return -1;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
e -= 16;
|
||||
NEEDBITS(e);
|
||||
t = t.t[GETBITS(e)];
|
||||
e = t.e;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
NEEDBITS(e);
|
||||
copy_dist = wp - t.n - GETBITS(e);
|
||||
DUMPBITS(e);
|
||||
|
||||
// do the copy
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
copy_dist &= WSIZE - 1;
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = slide[copy_dist++];
|
||||
}
|
||||
|
||||
if (n === size) {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
method = -1; // done
|
||||
return n;
|
||||
}
|
||||
|
||||
function inflate_stored(buff, off, size) {
|
||||
/* "decompress" an inflated type 0 (stored) block. */
|
||||
var n;
|
||||
|
||||
// go to byte boundary
|
||||
n = bit_len & 7;
|
||||
DUMPBITS(n);
|
||||
|
||||
// get the length and its complement
|
||||
NEEDBITS(16);
|
||||
n = GETBITS(16);
|
||||
DUMPBITS(16);
|
||||
NEEDBITS(16);
|
||||
if (n !== ((~bit_buf) & 0xffff)) {
|
||||
return -1; // error in compressed data
|
||||
}
|
||||
DUMPBITS(16);
|
||||
|
||||
// read and output the compressed data
|
||||
copy_leng = n;
|
||||
|
||||
n = 0;
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
wp &= WSIZE - 1;
|
||||
NEEDBITS(8);
|
||||
buff[off + n++] = slide[wp++] = GETBITS(8);
|
||||
DUMPBITS(8);
|
||||
}
|
||||
|
||||
if (copy_leng === 0) {
|
||||
method = -1; // done
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function inflate_fixed(buff, off, size) {
|
||||
// decompress an inflated type 1 (fixed Huffman codes) block. We should
|
||||
// either replace this with a custom decoder, or at least precompute the
|
||||
// Huffman tables.
|
||||
|
||||
// if first time, set up tables for fixed blocks
|
||||
if (!fixed_tl) {
|
||||
var i; // temporary variable
|
||||
var l = []; // 288 length list for huft_build (initialized below)
|
||||
var h; // HuftBuild
|
||||
|
||||
// literal table
|
||||
for (i = 0; i < 144; i++) {
|
||||
l[i] = 8;
|
||||
}
|
||||
for (null; i < 256; i++) {
|
||||
l[i] = 9;
|
||||
}
|
||||
for (null; i < 280; i++) {
|
||||
l[i] = 7;
|
||||
}
|
||||
for (null; i < 288; i++) { // make a complete, but wrong code set
|
||||
l[i] = 8;
|
||||
}
|
||||
fixed_bl = 7;
|
||||
|
||||
h = new HuftBuild(l, 288, 257, cplens, cplext, fixed_bl);
|
||||
if (h.status !== 0) {
|
||||
console.error("HufBuild error: " + h.status);
|
||||
return -1;
|
||||
}
|
||||
fixed_tl = h.root;
|
||||
fixed_bl = h.m;
|
||||
|
||||
// distance table
|
||||
for (i = 0; i < 30; i++) { // make an incomplete code set
|
||||
l[i] = 5;
|
||||
}
|
||||
fixed_bd = 5;
|
||||
|
||||
h = new HuftBuild(l, 30, 0, cpdist, cpdext, fixed_bd);
|
||||
if (h.status > 1) {
|
||||
fixed_tl = null;
|
||||
console.error("HufBuild error: " + h.status);
|
||||
return -1;
|
||||
}
|
||||
fixed_td = h.root;
|
||||
fixed_bd = h.m;
|
||||
}
|
||||
|
||||
tl = fixed_tl;
|
||||
td = fixed_td;
|
||||
bl = fixed_bl;
|
||||
bd = fixed_bd;
|
||||
return inflate_codes(buff, off, size);
|
||||
}
|
||||
|
||||
function inflate_dynamic(buff, off, size) {
|
||||
// decompress an inflated type 2 (dynamic Huffman codes) block.
|
||||
var i; // temporary variables
|
||||
var j;
|
||||
var l; // last length
|
||||
var n; // number of lengths to get
|
||||
var t; // (HuftNode) literal/length code table
|
||||
var nb; // number of bit length codes
|
||||
var nl; // number of literal/length codes
|
||||
var nd; // number of distance codes
|
||||
var ll = [];
|
||||
var h; // (HuftBuild)
|
||||
|
||||
// literal/length and distance code lengths
|
||||
for (i = 0; i < 286 + 30; i++) {
|
||||
ll[i] = 0;
|
||||
}
|
||||
|
||||
// read in table lengths
|
||||
NEEDBITS(5);
|
||||
nl = 257 + GETBITS(5); // number of literal/length codes
|
||||
DUMPBITS(5);
|
||||
NEEDBITS(5);
|
||||
nd = 1 + GETBITS(5); // number of distance codes
|
||||
DUMPBITS(5);
|
||||
NEEDBITS(4);
|
||||
nb = 4 + GETBITS(4); // number of bit length codes
|
||||
DUMPBITS(4);
|
||||
if (nl > 286 || nd > 30) {
|
||||
return -1; // bad lengths
|
||||
}
|
||||
|
||||
// read in bit-length-code lengths
|
||||
for (j = 0; j < nb; j++) {
|
||||
NEEDBITS(3);
|
||||
ll[border[j]] = GETBITS(3);
|
||||
DUMPBITS(3);
|
||||
}
|
||||
for (null; j < 19; j++) {
|
||||
ll[border[j]] = 0;
|
||||
}
|
||||
|
||||
// build decoding table for trees--single level, 7 bit lookup
|
||||
bl = 7;
|
||||
h = new HuftBuild(ll, 19, 19, null, null, bl);
|
||||
if (h.status !== 0) {
|
||||
return -1; // incomplete code set
|
||||
}
|
||||
|
||||
tl = h.root;
|
||||
bl = h.m;
|
||||
|
||||
// read in literal and distance code lengths
|
||||
n = nl + nd;
|
||||
i = l = 0;
|
||||
while (i < n) {
|
||||
NEEDBITS(bl);
|
||||
t = tl.list[GETBITS(bl)];
|
||||
j = t.b;
|
||||
DUMPBITS(j);
|
||||
j = t.n;
|
||||
if (j < 16) { // length of code in bits (0..15)
|
||||
ll[i++] = l = j; // save last length in l
|
||||
} else if (j === 16) { // repeat last length 3 to 6 times
|
||||
NEEDBITS(2);
|
||||
j = 3 + GETBITS(2);
|
||||
DUMPBITS(2);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = l;
|
||||
}
|
||||
} else if (j === 17) { // 3 to 10 zero length codes
|
||||
NEEDBITS(3);
|
||||
j = 3 + GETBITS(3);
|
||||
DUMPBITS(3);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
} else { // j === 18: 11 to 138 zero length codes
|
||||
NEEDBITS(7);
|
||||
j = 11 + GETBITS(7);
|
||||
DUMPBITS(7);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// build the decoding tables for literal/length and distance codes
|
||||
bl = lbits;
|
||||
h = new HuftBuild(ll, nl, 257, cplens, cplext, bl);
|
||||
if (bl === 0) { // no literals or lengths
|
||||
h.status = 1;
|
||||
}
|
||||
if (h.status !== 0) {
|
||||
if (h.status !== 1) {
|
||||
return -1; // incomplete code set
|
||||
}
|
||||
// **incomplete literal tree**
|
||||
}
|
||||
tl = h.root;
|
||||
bl = h.m;
|
||||
|
||||
for (i = 0; i < nd; i++) {
|
||||
ll[i] = ll[i + nl];
|
||||
}
|
||||
bd = dbits;
|
||||
h = new HuftBuild(ll, nd, 0, cpdist, cpdext, bd);
|
||||
td = h.root;
|
||||
bd = h.m;
|
||||
|
||||
if (bd === 0 && nl > 257) { // lengths but no distances
|
||||
// **incomplete distance tree**
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if (h.status === 1) {
|
||||
// **incomplete distance tree**
|
||||
}
|
||||
*/
|
||||
if (h.status !== 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// decompress until an end-of-block code
|
||||
return inflate_codes(buff, off, size);
|
||||
}
|
||||
|
||||
function inflate_start() {
|
||||
if (!slide) {
|
||||
slide = []; // new Array(2 * WSIZE); // slide.length is never called
|
||||
}
|
||||
wp = 0;
|
||||
bit_buf = 0;
|
||||
bit_len = 0;
|
||||
method = -1;
|
||||
eof = false;
|
||||
copy_leng = copy_dist = 0;
|
||||
tl = null;
|
||||
}
|
||||
|
||||
function inflate_internal(buff, off, size) {
|
||||
// decompress an inflated entry
|
||||
var n, i;
|
||||
|
||||
n = 0;
|
||||
while (n < size) {
|
||||
if (eof && method === -1) {
|
||||
return n;
|
||||
}
|
||||
|
||||
if (copy_leng > 0) {
|
||||
if (method !== STORED_BLOCK) {
|
||||
// STATIC_TREES or DYN_TREES
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
copy_dist &= WSIZE - 1;
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = slide[copy_dist++];
|
||||
}
|
||||
} else {
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
wp &= WSIZE - 1;
|
||||
NEEDBITS(8);
|
||||
buff[off + n++] = slide[wp++] = GETBITS(8);
|
||||
DUMPBITS(8);
|
||||
}
|
||||
if (copy_leng === 0) {
|
||||
method = -1; // done
|
||||
}
|
||||
}
|
||||
if (n === size) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
if (method === -1) {
|
||||
if (eof) {
|
||||
break;
|
||||
}
|
||||
|
||||
// read in last block bit
|
||||
NEEDBITS(1);
|
||||
if (GETBITS(1) !== 0) {
|
||||
eof = true;
|
||||
}
|
||||
DUMPBITS(1);
|
||||
|
||||
// read in block type
|
||||
NEEDBITS(2);
|
||||
method = GETBITS(2);
|
||||
DUMPBITS(2);
|
||||
tl = null;
|
||||
copy_leng = 0;
|
||||
}
|
||||
|
||||
switch (method) {
|
||||
case STORED_BLOCK:
|
||||
i = inflate_stored(buff, off + n, size - n);
|
||||
break;
|
||||
|
||||
case STATIC_TREES:
|
||||
if (tl) {
|
||||
i = inflate_codes(buff, off + n, size - n);
|
||||
} else {
|
||||
i = inflate_fixed(buff, off + n, size - n);
|
||||
}
|
||||
break;
|
||||
|
||||
case DYN_TREES:
|
||||
if (tl) {
|
||||
i = inflate_codes(buff, off + n, size - n);
|
||||
} else {
|
||||
i = inflate_dynamic(buff, off + n, size - n);
|
||||
}
|
||||
break;
|
||||
|
||||
default: // error
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === -1) {
|
||||
if (eof) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
n += i;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
export function inflate(arr) {
|
||||
var buff = [], i;
|
||||
|
||||
inflate_start();
|
||||
inflate_data = arr;
|
||||
inflate_pos = 0;
|
||||
|
||||
do {
|
||||
i = inflate_internal(buff, buff.length, 1024);
|
||||
} while (i > 0);
|
||||
inflate_data = null; // G.C.
|
||||
return buff;
|
||||
}
|
||||
9
assets/scripts/libs/gzip/rawinflate.ts.meta
Normal file
9
assets/scripts/libs/gzip/rawinflate.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "05939942-dd2a-4db3-be1e-079633424127",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/login.meta
Normal file
12
assets/scripts/login.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "0835767a-c826-4cac-88de-ef44535d9bc5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
65
assets/scripts/login/CreateLogic.ts
Normal file
65
assets/scripts/login/CreateLogic.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { _decorator, Component, EditBox, Toggle } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import LoginCommand from "./LoginCommand";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('CreateLogic')
|
||||
export default class CreateLogic extends Component {
|
||||
|
||||
@property(EditBox)
|
||||
editName: EditBox = null;
|
||||
|
||||
|
||||
@property(Toggle)
|
||||
manToggle: Toggle = null;
|
||||
|
||||
|
||||
@property(Toggle)
|
||||
girlToggle: Toggle = null;
|
||||
|
||||
|
||||
protected onLoad():void{
|
||||
EventMgr.on(ServerConfig.role_create, this.create, this);
|
||||
this.editName.string = this.getRandomName();
|
||||
}
|
||||
|
||||
protected onCreate() {
|
||||
var sex = this.manToggle.isChecked?0:1;
|
||||
var loginData: any = LoginCommand.getInstance().proxy.getLoginData();
|
||||
LoginCommand.getInstance().role_create(loginData.uid, this.editName.string, sex,LoginCommand.getInstance().proxy.serverId, 0)
|
||||
}
|
||||
|
||||
|
||||
protected create(data):void{
|
||||
console.log("create:", data);
|
||||
if(data.code == 0){
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected onRandomName():void{
|
||||
this.editName.string = this.getRandomName();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*@param Number NameLength 要获取的名字长度
|
||||
*/
|
||||
protected getRandomName():string{
|
||||
let name = ""
|
||||
var firstname:string[] = ["李","西门","沈","张","上官","司徒","欧阳","轩辕"];
|
||||
var nameq:string[] = ["彪","巨昆","锐","翠花","小小","撒撒","熊大","宝强"];
|
||||
var xingxing = firstname[Math.floor(Math.random() * (firstname.length))];
|
||||
var mingming = nameq[Math.floor(Math.random() * (nameq.length))];
|
||||
name = xingxing + mingming;
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected onDestroy():void{
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/login/CreateLogic.ts.meta
Normal file
11
assets/scripts/login/CreateLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "acbeb367-8f97-426d-aeb0-1a82437a62f8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
287
assets/scripts/login/LoginCommand.ts
Normal file
287
assets/scripts/login/LoginCommand.ts
Normal file
@@ -0,0 +1,287 @@
|
||||
import { HttpConfig } from "../config/HttpConfig";
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import { HttpManager } from "../network/http/HttpManager";
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import { Tools } from "../utils/Tools";
|
||||
import LoginProxy from "./LoginProxy";
|
||||
import { NetEvent } from "../network/socket/NetInterface";
|
||||
import MapCommand from "../map/MapCommand";
|
||||
import { LocalCache } from "../utils/LocalCache";
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
import { EventMgr } from "../utils/EventMgr";
|
||||
import { Md5 } from "../libs/crypto/md5";
|
||||
|
||||
export default class LoginCommand {
|
||||
//单例
|
||||
protected static _instance: LoginCommand;
|
||||
public static getInstance(): LoginCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new LoginCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//数据model
|
||||
protected _proxy: LoginProxy = new LoginProxy();
|
||||
|
||||
constructor() {
|
||||
EventMgr.on(NetEvent.ServerCheckLogin, this.onServerConneted, this);
|
||||
EventMgr.on(HttpConfig.register.name, this.onRegister, this);
|
||||
EventMgr.on(ServerConfig.account_login, this.onAccountLogin, this);
|
||||
EventMgr.on(ServerConfig.role_enterServer, this.onEnterServer, this);
|
||||
EventMgr.on(ServerConfig.account_reLogin, this.onAccountRelogin, this);
|
||||
EventMgr.on(ServerConfig.role_create, this.onRoleCreate, this);
|
||||
EventMgr.on(ServerConfig.account_logout, this.onAccountLogout, this);
|
||||
EventMgr.on(ServerConfig.account_robLogin, this.onAccountRobLogin, this)
|
||||
EventMgr.on(ServerConfig.chat_login, this.onChatLogin, this)
|
||||
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
//抢登录
|
||||
private onAccountRobLogin(): void{
|
||||
console.log("onAccountRobLogin")
|
||||
EventMgr.emit("robLoginUI");
|
||||
}
|
||||
|
||||
/**注册回调*/
|
||||
private onRegister(data: any, otherData: any): void {
|
||||
console.log("LoginProxy register:", data, otherData);
|
||||
if (data.code == 0) {
|
||||
this.accountLogin(otherData.username, otherData.password);
|
||||
LocalCache.setLoginValidation(otherData);
|
||||
}
|
||||
}
|
||||
|
||||
/**登录回调*/
|
||||
private onAccountLogin(data: any, otherData:any): void {
|
||||
console.log("LoginProxy login:", data , otherData);
|
||||
if (data.code == 0) {
|
||||
// this._proxy.loginData = data.msg;
|
||||
this._proxy.saveLoginData(data.msg);
|
||||
LocalCache.setLoginValidation(otherData);
|
||||
|
||||
|
||||
this.role_enterServer(this._proxy.getSession());
|
||||
EventMgr.emit("loginComplete", data.code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**进入服务器回调*/
|
||||
private onEnterServer(data: any,isLoadMap:boolean): void {
|
||||
console.log("LoginProxy enter:", data,isLoadMap);
|
||||
//没有创建打开创建
|
||||
if (data.code == 9) {
|
||||
EventMgr.emit("CreateRole");
|
||||
DateUtil.setServerTime(data.msg.time);
|
||||
} else {
|
||||
if(data.code == 0){
|
||||
this._proxy.saveEnterData(data.msg);
|
||||
DateUtil.setServerTime(data.msg.time);
|
||||
|
||||
// var roleData = this._proxy.getRoleData();
|
||||
// this.chatLogin(roleData.rid, data.msg.token, roleData.nickName);
|
||||
|
||||
//进入游戏
|
||||
if(isLoadMap == true){
|
||||
console.log("enterServerComplete");
|
||||
MapCommand.getInstance().enterMap();
|
||||
EventMgr.emit("enterServerComplete");
|
||||
}else{
|
||||
EventMgr.emit(NetEvent.ServerHandShake);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**重连回调*/
|
||||
private onServerConneted(): void {
|
||||
//重新连接成功 重新登录
|
||||
var loginData = this._proxy.getLoginData();
|
||||
var roleData = this._proxy.getRoleData();
|
||||
console.log("LoginProxy conneted:", loginData,roleData);
|
||||
|
||||
if (loginData) {
|
||||
this.account_reLogin(loginData.session);
|
||||
}else{
|
||||
EventMgr.emit(NetEvent.ServerHandShake);
|
||||
}
|
||||
}
|
||||
|
||||
/**重新登录回调回调*/
|
||||
private onAccountRelogin(data: any): void {
|
||||
//断线重新登录
|
||||
console.log("LoginProxy relogin:", data);
|
||||
if(data.code == 0){
|
||||
// EventMgr.emit(NetEvent.ServerHandShake);
|
||||
this.role_enterServer(this._proxy.getSession(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**创建角色回调*/
|
||||
private onRoleCreate(data: any): void {
|
||||
//重换成功再次调用
|
||||
if (data.code == 0) {
|
||||
this.role_enterServer(this._proxy.getSession());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**登出回调*/
|
||||
private onAccountLogout(data: any): void {
|
||||
//重换成功再次调用
|
||||
if (data.code == 0) {
|
||||
this._proxy.clear();
|
||||
EventMgr.emit("enter_login");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//聊天登录
|
||||
private onChatLogin(data: any): void{
|
||||
console.log("onChatLogin:",data);
|
||||
}
|
||||
|
||||
public get proxy(): LoginProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* register
|
||||
* @param data
|
||||
*/
|
||||
public register(name: string, password: string) {
|
||||
|
||||
var pwd = Md5.encrypt(password);
|
||||
var params = "username=" + name
|
||||
+ "&password=" + pwd
|
||||
+ "&hardware=" + Tools.getUUID();
|
||||
|
||||
console.log("register:", params);
|
||||
var otherData = { username: name, password: password };
|
||||
HttpManager.getInstance().doGet(HttpConfig.register.name, HttpConfig.register.url, params, otherData);
|
||||
}
|
||||
|
||||
/**
|
||||
* login
|
||||
* @param data
|
||||
*/
|
||||
public accountLogin(name: string, password: string) {
|
||||
|
||||
var api_name = ServerConfig.account_login;
|
||||
var pwd = Md5.encrypt(password);
|
||||
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
username: name,
|
||||
password: pwd,
|
||||
hardware: Tools.getUUID()
|
||||
}
|
||||
};
|
||||
|
||||
console.log("accountLogin:", send_data);
|
||||
var otherData = { username: name, password: password };
|
||||
NetManager.getInstance().send(send_data,otherData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param uid
|
||||
* @param nickName
|
||||
* @param sex
|
||||
* @param sid
|
||||
* @param headId
|
||||
*/
|
||||
public role_create(uid: string, nickName: string, sex: number = 0, sid: number = 0, headId: number = 0) {
|
||||
var api_name = ServerConfig.role_create;
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
uid: uid,
|
||||
nickName: nickName,
|
||||
sex: sex,
|
||||
sid: sid,
|
||||
headId: headId
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(send_data);
|
||||
}
|
||||
|
||||
|
||||
public role_enterServer(session: string,isLoadMap:boolean = true) {
|
||||
var api_name = ServerConfig.role_enterServer;
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
session: session,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(send_data,isLoadMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新登录
|
||||
* @param session
|
||||
*/
|
||||
public account_reLogin(session: string) {
|
||||
var api_name = ServerConfig.account_reLogin;
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
session: session,
|
||||
hardware: Tools.getUUID()
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(send_data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* logout
|
||||
*/
|
||||
public account_logout():void{
|
||||
var api_name = ServerConfig.account_logout;
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(send_data);
|
||||
}
|
||||
|
||||
|
||||
public chatLogin(rid:number, token: string, nick_name:string = ''):void{
|
||||
var api_name = ServerConfig.chat_login;
|
||||
var send_data = {
|
||||
name: api_name,
|
||||
msg: {
|
||||
rid:rid,
|
||||
token:token,
|
||||
nickName:nick_name
|
||||
}
|
||||
};
|
||||
|
||||
console.log("send_data:", send_data);
|
||||
NetManager.getInstance().send(send_data);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/login/LoginCommand.ts.meta
Normal file
11
assets/scripts/login/LoginCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c0f44f5b-d2c2-4792-893c-22fe0322073f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
47
assets/scripts/login/LoginLogic.ts
Normal file
47
assets/scripts/login/LoginLogic.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { _decorator, Component, EditBox, Label } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { LocalCache } from "../utils/LocalCache";
|
||||
import LoginCommand from "./LoginCommand";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('LoginLogic')
|
||||
export default class LoginLogic extends Component {
|
||||
|
||||
@property(EditBox)
|
||||
editName:EditBox = null;
|
||||
|
||||
@property(EditBox)
|
||||
editPass:Label = null;
|
||||
|
||||
protected onLoad(): void {
|
||||
EventMgr.on("loginComplete", this.onLoginComplete, this);
|
||||
|
||||
var data = LocalCache.getLoginValidation();
|
||||
console.log("LoginLogic data:",data)
|
||||
if(data){
|
||||
this.editName.string = data.username;
|
||||
this.editPass.string = data.password;
|
||||
}
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
protected onLoginComplete():void {
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
protected onClickRegister(): void {
|
||||
LoginCommand.getInstance().register(this.editName.string, this.editPass.string);
|
||||
}
|
||||
|
||||
protected onClickLogin(): void {
|
||||
LoginCommand.getInstance().accountLogin(this.editName.string, this.editPass.string)
|
||||
}
|
||||
|
||||
protected onClickClose(): void {
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/login/LoginLogic.ts.meta
Normal file
11
assets/scripts/login/LoginLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e8d5386f-3122-4cdd-af4e-49d4c3dd7441",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
96
assets/scripts/login/LoginProxy.ts
Normal file
96
assets/scripts/login/LoginProxy.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
export class Role{
|
||||
rid:number = 0;
|
||||
uid:number = 0;
|
||||
nickName:string = "";
|
||||
sex:number = 0;
|
||||
sid:number = 0;
|
||||
balance:number = 0;
|
||||
headId:number = 0;
|
||||
profile:string = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default class LoginProxy {
|
||||
//登录数据
|
||||
private _loginData: any = null;
|
||||
public serverId:number = 0;
|
||||
|
||||
|
||||
//角色数据
|
||||
private _roleData :Role = null;
|
||||
|
||||
//角色资源
|
||||
private _roleResData:any = null;
|
||||
|
||||
private _token:string = null;
|
||||
|
||||
public clear() {
|
||||
this._loginData = null;
|
||||
this._roleData = null;
|
||||
this._roleResData = null;
|
||||
this._token = ""
|
||||
}
|
||||
|
||||
|
||||
public saveEnterData(data:any):void{
|
||||
if(data.role){
|
||||
this.setRoleData(data.role);
|
||||
}
|
||||
|
||||
if(data.role_res){
|
||||
this.setRoleResData(data.role_res);
|
||||
}
|
||||
|
||||
if(data.token){
|
||||
this._token = data.token
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public setRoleResData(data:any):void{
|
||||
this._roleResData = data;
|
||||
}
|
||||
|
||||
|
||||
public setRoleData(data:any):void{
|
||||
if(!this._roleData){
|
||||
this._roleData = new Role();
|
||||
}
|
||||
this._roleData.rid = data.rid;
|
||||
this._roleData.uid = data.uid;
|
||||
this._roleData.nickName = data.nickName;
|
||||
this._roleData.sex = data.sex;
|
||||
this._roleData.sid = data.sid;
|
||||
this._roleData.balance = data.balance;
|
||||
this._roleData.headId = data.headId;
|
||||
this._roleData.profile = data.profile;
|
||||
}
|
||||
|
||||
|
||||
public getRoleData():Role{
|
||||
return this._roleData;
|
||||
}
|
||||
|
||||
|
||||
public getRoleResData():any{
|
||||
return this._roleResData;
|
||||
}
|
||||
|
||||
|
||||
public saveLoginData(data:any):void{
|
||||
this._loginData = data;
|
||||
}
|
||||
|
||||
public getLoginData():any{
|
||||
return this._loginData;
|
||||
}
|
||||
|
||||
public getToken():string{
|
||||
return this._token;
|
||||
}
|
||||
|
||||
public getSession():string{
|
||||
return this._loginData.session;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/login/LoginProxy.ts.meta
Normal file
11
assets/scripts/login/LoginProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "46618d7f-b86f-4e88-990a-4afd67f29d0a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
12
assets/scripts/map.meta
Normal file
12
assets/scripts/map.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "5dd23ece-5581-4f93-9b7f-8a778f573f01",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
138
assets/scripts/map/MapArmyLogic.ts
Normal file
138
assets/scripts/map/MapArmyLogic.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import { _decorator, Component, Node, Prefab, NodePool, instantiate } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import ArmyCommand from "../general/ArmyCommand";
|
||||
import { ArmyCmd, ArmyData } from "../general/ArmyProxy";
|
||||
import ArmyLogic from "./entries/ArmyLogic";
|
||||
import MapCommand from "./MapCommand";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapArmyLogic')
|
||||
export default class MapArmyLogic extends Component {
|
||||
@property(Node)
|
||||
parentLayer: Node = null;
|
||||
@property(Prefab)
|
||||
armyPrefab: Prefab = null;
|
||||
@property(Prefab)
|
||||
arrowPrefab: Prefab = null;
|
||||
|
||||
protected _armyLogics: Map<number, ArmyLogic> = new Map<number, ArmyLogic>();
|
||||
protected _armyPool: NodePool = new NodePool();
|
||||
protected _arrowPool: NodePool = new NodePool();
|
||||
|
||||
protected onLoad(): void {
|
||||
EventMgr.on("update_army_list", this.onUpdateArmyList, this);
|
||||
EventMgr.on("update_army", this.onUpdateArmy, this);
|
||||
this.initArmys();
|
||||
|
||||
this.schedule(this.checkVisible, 0.5);
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
this._armyPool.clear();
|
||||
this._arrowPool.clear();
|
||||
this._armyLogics.forEach((logic:ArmyLogic) => {
|
||||
logic.destroy();
|
||||
})
|
||||
}
|
||||
|
||||
protected update():void {
|
||||
this._armyLogics.forEach((logic:ArmyLogic) => {
|
||||
logic.update();
|
||||
});
|
||||
}
|
||||
|
||||
protected initArmys(): void {
|
||||
let datas: ArmyData[] = ArmyCommand.getInstance().proxy.getAllArmys();
|
||||
if (datas && datas.length > 0) {
|
||||
this.onUpdateArmyList(datas);
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateArmyList(datas: ArmyData[]): void {
|
||||
for (let i:number = 0; i < datas.length; i++) {
|
||||
if (datas[i] && datas[i].cmd > 0) {
|
||||
this.onUpdateArmy(datas[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateArmy(data: ArmyData): void {
|
||||
console.log("update_army", data);
|
||||
let aniNode: Node = null;
|
||||
let arrowNode: Node = null;
|
||||
if (data.cmd == ArmyCmd.Idle || data.cmd == ArmyCmd.Conscript) {
|
||||
//代表不在地图上
|
||||
this.removeArmyById(data.id);
|
||||
return;
|
||||
}
|
||||
let logic:ArmyLogic = this._armyLogics.get(data.id);
|
||||
console.log("onUpdateArmy 1111:", logic);
|
||||
|
||||
if (logic == null) {
|
||||
logic = new ArmyLogic();
|
||||
aniNode = this.createArmy();
|
||||
aniNode.zIndex = 1;
|
||||
aniNode.parent = this.parentLayer;
|
||||
arrowNode = this.createArrow();
|
||||
arrowNode.zIndex = 2;
|
||||
arrowNode.parent = this.parentLayer;
|
||||
this._armyLogics.set(data.id, logic);
|
||||
|
||||
console.log("onUpdateArmy 2222:", logic);
|
||||
} else {
|
||||
aniNode = logic.aniNode;
|
||||
arrowNode = logic.arrowNode;
|
||||
logic = this._armyLogics.get(data.id);
|
||||
}
|
||||
console.log("onUpdateArmy 3333:", logic);
|
||||
logic.setArmyData(data, aniNode, arrowNode);
|
||||
}
|
||||
|
||||
protected createArmy(): Node {
|
||||
if (this._armyPool.size() > 0) {
|
||||
return this._armyPool.get();
|
||||
} else {
|
||||
return instantiate(this.armyPrefab);
|
||||
}
|
||||
}
|
||||
|
||||
protected createArrow():Node {
|
||||
if (this._arrowPool.size() > 0) {
|
||||
return this._arrowPool.get();
|
||||
} else {
|
||||
return instantiate(this.arrowPrefab);
|
||||
}
|
||||
}
|
||||
|
||||
protected removeArmyById(id: number): void {
|
||||
if (this._armyLogics.has(id)) {
|
||||
let logic:ArmyLogic = this._armyLogics.get(id);
|
||||
this._armyPool.put(logic.aniNode);
|
||||
this._arrowPool.put(logic.arrowNode);
|
||||
logic.clear();
|
||||
this._armyLogics.delete(id);
|
||||
console.log("removeArmyById", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected checkVisible(): void {
|
||||
|
||||
this._armyLogics.forEach((logic:ArmyLogic) => {
|
||||
let city = MapCommand.getInstance().cityProxy.getMyCityById(logic.data.cityId);
|
||||
if(!city || city.rid != MapCommand.getInstance().buildProxy.myId){
|
||||
|
||||
var visible1 = MapUtil.armyIsInView(logic.data.x, logic.data.y);
|
||||
var visible2 = MapUtil.armyIsInView(logic.data.toX, logic.data.toY);
|
||||
var visible3 = MapUtil.armyIsInView(logic.data.fromX, logic.data.fromY);
|
||||
if(!visible1 && !visible2 && !visible3){
|
||||
this.removeArmyById(logic.data.id);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapArmyLogic.ts.meta
Normal file
11
assets/scripts/map/MapArmyLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f81f0497-999d-4b1b-97c0-3d4bced3a7d3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
128
assets/scripts/map/MapBaseLayerLogic.ts
Normal file
128
assets/scripts/map/MapBaseLayerLogic.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import { _decorator, Component, Node, Prefab, NodePool, instantiate } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import MapCommand from "./MapCommand";
|
||||
|
||||
@ccclass('MapBaseLayerLogic')
|
||||
export default class MapBaseLayerLogic extends Component {
|
||||
@property(Node)
|
||||
parentLayer: Node = null;
|
||||
@property(Prefab)
|
||||
entryPrefab: Prefab = null;
|
||||
|
||||
protected _cmd: MapCommand;
|
||||
protected _itemPool: NodePool = new NodePool();
|
||||
protected _itemMap: Map<number, Map<number, Node>> = new Map<number, Map<number, Node>>();
|
||||
|
||||
protected onLoad(): void {
|
||||
this._cmd = MapCommand.getInstance();
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this._cmd = null;
|
||||
this._itemMap.forEach((value: Map<number, Node>, key: number) => {
|
||||
value.clear();
|
||||
});
|
||||
this._itemMap.clear();
|
||||
this._itemMap = null;
|
||||
this._itemPool.clear();
|
||||
this._itemPool = null;
|
||||
}
|
||||
|
||||
public addItem(areaIndex: number, data: any): Node {
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
let id: number = this.getIdByData(data);
|
||||
let item: Node = this.getItem(areaIndex, id);
|
||||
if (item == null) {
|
||||
item = this.createItem();
|
||||
item.parent = this.parentLayer;
|
||||
let list: Map<number, Node> = this._itemMap.get(areaIndex);
|
||||
list.set(this.getIdByData(data), item);
|
||||
}
|
||||
this.updateItem(areaIndex, data, item);
|
||||
return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public updateItem(areaIndex: number, data: any, item: Node = null): void {
|
||||
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
let realItem: Node = item;
|
||||
if (item == null) {
|
||||
let id: number = this.getIdByData(data);
|
||||
realItem = this.getItem(areaIndex, id);
|
||||
}
|
||||
if (realItem) {
|
||||
this.setItemData(realItem, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//子类重写
|
||||
public setItemData(item: Node, data: any): void {
|
||||
|
||||
}
|
||||
|
||||
public removeItem(areaIndex: number, id: number): boolean {
|
||||
let list: Map<number, Node> = this._itemMap.get(areaIndex);
|
||||
if (list.has(id)) {
|
||||
let item: Node = list.get(id);
|
||||
this._itemPool.put(item);
|
||||
list.delete(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getItem(areaIndex: number, id: number): Node {
|
||||
let list: Map<number, Node> = this._itemMap.get(areaIndex);
|
||||
if (list.has(id)) {
|
||||
return list.get(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected createItem(): Node {
|
||||
if (this._itemPool.size() > 0) {
|
||||
return this._itemPool.get();
|
||||
}
|
||||
let node: Node = instantiate(this.entryPrefab);
|
||||
return node;
|
||||
}
|
||||
|
||||
public removeArea(areaIndex: number): void {
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
let list: Map<number, Node> = this._itemMap.get(areaIndex);
|
||||
list.forEach((node: Node, key: number) => {
|
||||
this._itemPool.put(node);
|
||||
});
|
||||
list.clear();
|
||||
this._itemMap.delete(areaIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public addArea(areaIndex: number): void {
|
||||
if (this._itemMap.has(areaIndex) == false) {
|
||||
this._itemMap.set(areaIndex, new Map<number, Node>());
|
||||
}
|
||||
}
|
||||
|
||||
public udpateShowAreas(addIndexs: number[], removeIndexs: number[]): void {
|
||||
|
||||
for (let i: number = 0; i < removeIndexs.length; i++) {
|
||||
this.removeArea(removeIndexs[i]);
|
||||
}
|
||||
for (let i: number = 0; i < addIndexs.length; i++) {
|
||||
this.addArea(addIndexs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public initNodeByArea(areaIndex: number): void {
|
||||
|
||||
}
|
||||
|
||||
public getIdByData(data: any): number {
|
||||
return data.id;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapBaseLayerLogic.ts.meta
Normal file
11
assets/scripts/map/MapBaseLayerLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6875a9ab-6b4b-4d61-a5bc-e6d29240ba72",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
290
assets/scripts/map/MapBuildProxy.ts
Normal file
290
assets/scripts/map/MapBuildProxy.ts
Normal file
@@ -0,0 +1,290 @@
|
||||
import { _decorator } from 'cc';
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
import MapCommand from "./MapCommand";
|
||||
import {MapResType } from "./MapProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
/**地图建筑和占领数据*/
|
||||
export class MapBuildData {
|
||||
id: number = 0;
|
||||
rid: number = 0;
|
||||
nickName: string = "";
|
||||
name: string = "";
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
type: number = 0;
|
||||
level: number = 0;
|
||||
opLevel: number = 0;
|
||||
curDurable: number = 0;
|
||||
maxDurable: number = 0;
|
||||
defender: number = 0;
|
||||
unionId: number = 0;
|
||||
parentId: number = 0;
|
||||
unionName: string;
|
||||
occupyTime: number;
|
||||
giveUpTime: number;
|
||||
endTime: number;
|
||||
|
||||
public equalsServerData(data: any) {
|
||||
if (this.rid == data.rid
|
||||
&& this.name == data.name
|
||||
&& this.nickName == data.RNick
|
||||
&& this.type == data.type
|
||||
&& this.level == data.level
|
||||
&& this.opLevel == data.op_level
|
||||
&& this.curDurable == data.cur_durable
|
||||
&& this.maxDurable == data.maxDurable
|
||||
&& this.defender == data.defender
|
||||
&& this.unionId == data.union_id
|
||||
&& this.parentId == data.parent_id
|
||||
&& this.unionName == data.union_name
|
||||
&& this.occupyTime == data.occupy_time
|
||||
&& this.giveUpTime == data.giveUp_time
|
||||
&& this.endTime == data.end_time) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static createBuildData(data: any, id: number = 0, buildData: MapBuildData = null): MapBuildData {
|
||||
let build: MapBuildData = buildData;
|
||||
if (buildData == null) {
|
||||
build = new MapBuildData();
|
||||
}
|
||||
build.id = id;
|
||||
build.rid = data.rid;
|
||||
build.nickName = data.RNick;
|
||||
build.name = data.name;
|
||||
build.x = data.x;
|
||||
build.y = data.y;
|
||||
build.type = data.type;
|
||||
build.level = data.level;
|
||||
build.opLevel = data.op_level;
|
||||
build.curDurable = data.cur_durable;
|
||||
build.maxDurable = data.max_durable;
|
||||
build.defender = data.defender;
|
||||
build.unionId = data.union_id;
|
||||
build.parentId = data.parent_id;
|
||||
build.unionName = data.union_name;
|
||||
build.occupyTime = data.occupy_time;
|
||||
build.giveUpTime = data.giveUp_time;
|
||||
build.endTime = data.end_time;
|
||||
return build;
|
||||
}
|
||||
|
||||
public getCellRadius() :number {
|
||||
if (this.isSysCity()) {
|
||||
if (this.level >= 8){
|
||||
return 3
|
||||
}else if (this.level >= 5){
|
||||
return 2
|
||||
}else {
|
||||
return 1
|
||||
}
|
||||
}else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
public isSysCity():boolean{
|
||||
return this.type == MapResType.SYS_CITY;
|
||||
}
|
||||
|
||||
public isSysFortress():boolean{
|
||||
return this.type == MapResType.SYS_FORTRESS;
|
||||
}
|
||||
|
||||
public isWarFree(): boolean {
|
||||
var diff = DateUtil.getServerTime() - this.occupyTime;
|
||||
if(diff < MapCommand.getInstance().proxy.getWarFree()){
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isResBuild(): boolean{
|
||||
return this.type>=MapResType.WOOD && this.type < MapResType.FORTRESS
|
||||
}
|
||||
|
||||
public isInGiveUp(): boolean {
|
||||
var diff = DateUtil.leftTime(this.giveUpTime);
|
||||
return diff > 0
|
||||
}
|
||||
|
||||
//正在建设中
|
||||
public isBuilding(): boolean {
|
||||
var diff = DateUtil.leftTime(this.endTime);
|
||||
return diff > 0 && this.level == 0
|
||||
}
|
||||
|
||||
//正在升级中
|
||||
public isUping(): boolean {
|
||||
var diff = DateUtil.leftTime(this.endTime);
|
||||
return diff > 0 && this.level > 0 && this.opLevel > 0
|
||||
}
|
||||
|
||||
//正在拆除中
|
||||
public isDestroying(): boolean {
|
||||
var diff = DateUtil.leftTime(this.endTime);
|
||||
return diff > 0 && this.opLevel == 0
|
||||
}
|
||||
}
|
||||
|
||||
export default class MapBuildProxy {
|
||||
protected _mapBuilds: MapBuildData[] = [];
|
||||
protected _myBuilds: MapBuildData[] = [];
|
||||
protected _lastBuildCellIds: Map<number, number[]> = new Map<number, number[]>();
|
||||
public myId: number = 0;
|
||||
public myUnionId: number = 0;
|
||||
public myParentId: number = 0;
|
||||
// 初始化数据
|
||||
public initData(): void {
|
||||
this._mapBuilds.length = MapUtil.mapCellCount;
|
||||
this._lastBuildCellIds.clear();
|
||||
this.updateMyBuildIds();//建筑信息比加载更前 所以id需要根据加载的地图做更新
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._mapBuilds.length = 0;
|
||||
this._lastBuildCellIds.clear();
|
||||
}
|
||||
|
||||
/**我的建筑信息*/
|
||||
public initMyBuilds(builds: any[]): void {
|
||||
this._myBuilds.length = 0;
|
||||
for (let i: number = 0; i < builds.length; i++) {
|
||||
let id: number = MapUtil.getIdByCellPoint(builds[i].x, builds[i].y);
|
||||
let build: MapBuildData = MapBuildData.createBuildData(builds[i], id);
|
||||
this._myBuilds.push(build);
|
||||
}
|
||||
}
|
||||
|
||||
/**更新建筑id*/
|
||||
public updateMyBuildIds(): void {
|
||||
for (let i: number = 0; i < this._myBuilds.length; i++) {
|
||||
let id: number = MapUtil.getIdByCellPoint(this._myBuilds[i].x, this._myBuilds[i].y);
|
||||
this._myBuilds[i].id = id;
|
||||
this._mapBuilds[id] = this._myBuilds[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**更新建筑*/
|
||||
public updateBuild(build: any): void {
|
||||
if (build.rid == 0) {
|
||||
//代表是放弃领地
|
||||
if(build.type > MapResType.SYS_CITY){
|
||||
this.removeBuild(build.x, build.y);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
let id: number = MapUtil.getIdByCellPoint(build.x, build.y);
|
||||
let buildData: MapBuildData = null;
|
||||
if (this._mapBuilds[id] == null) {
|
||||
//代表是新增
|
||||
buildData = MapBuildData.createBuildData(build, id);
|
||||
this._myBuilds.push(build);
|
||||
this._mapBuilds[id] = buildData;
|
||||
} else {
|
||||
buildData = MapBuildData.createBuildData(build, id, this._mapBuilds[id]);
|
||||
}
|
||||
EventMgr.emit("update_build", buildData);
|
||||
if (buildData.rid == this.myId) {
|
||||
//代表是自己的领地
|
||||
EventMgr.emit("my_build_change");
|
||||
}
|
||||
}
|
||||
|
||||
public removeBuild(x: number, y: number): void {
|
||||
let id: number = MapUtil.getIdByCellPoint(x, y);
|
||||
this._mapBuilds[id] = null;
|
||||
EventMgr.emit("delete_build", id, x, y);
|
||||
this.removeMyBuild(x, y);
|
||||
}
|
||||
|
||||
public removeMyBuild(x: number, y:number):void {
|
||||
let index: number = -1;
|
||||
for (let i: number = 0; i < this._myBuilds.length; i++) {
|
||||
if (this._myBuilds[i].x == x
|
||||
&& this._myBuilds[i].y == y) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != -1) {
|
||||
this._myBuilds.splice(index, 1);
|
||||
EventMgr.emit("my_build_change");
|
||||
}
|
||||
}
|
||||
|
||||
public setMapScanBlock(scanDatas: any, areaId: number = 0): void {
|
||||
let rBuilds: any[] = scanDatas.mr_builds;
|
||||
if (rBuilds.length > 0) {
|
||||
let lastBuildCellIds: number[] = null;
|
||||
if (this._lastBuildCellIds.has(areaId)) {
|
||||
lastBuildCellIds = this._lastBuildCellIds.get(areaId);
|
||||
}
|
||||
let buildCellIds: number[] = [];
|
||||
let addBuildCellIds: number[] = [];
|
||||
let updateBuildCellIds: number[] = [];
|
||||
let removeBuildCellIds: number[] = [];
|
||||
for (let i: number = 0; i < rBuilds.length; i++) {
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(rBuilds[i].x, rBuilds[i].y);
|
||||
if (areaIndex != areaId) {
|
||||
//代表服务端给过来的数据不在当前区域
|
||||
console.log("代表服务端给过来的数据不在当前区域");
|
||||
continue;
|
||||
}
|
||||
let cellId: number = MapUtil.getIdByCellPoint(rBuilds[i].x, rBuilds[i].y);
|
||||
buildCellIds.push(cellId);
|
||||
if (lastBuildCellIds) {
|
||||
let index: number = lastBuildCellIds.indexOf(cellId);
|
||||
if (index != -1) {
|
||||
//存在就列表中 就代表是已存在的数据
|
||||
if (this._mapBuilds[cellId].equalsServerData(rBuilds[i]) == false) {
|
||||
//代表数据不一样需要刷新
|
||||
this._mapBuilds[cellId] = MapBuildData.createBuildData(rBuilds[i], cellId, this._mapBuilds[cellId]);
|
||||
updateBuildCellIds.push(cellId);
|
||||
}else{
|
||||
console.log("equalsServerData true");
|
||||
}
|
||||
lastBuildCellIds.splice(index, 1);//移除重复数据
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
//其他情况就是新数据了
|
||||
this._mapBuilds[cellId] = MapBuildData.createBuildData(rBuilds[i], cellId);
|
||||
addBuildCellIds.push(cellId);
|
||||
}
|
||||
if (lastBuildCellIds && lastBuildCellIds.length > 0) {
|
||||
//代表有需要删除的数据
|
||||
removeBuildCellIds = lastBuildCellIds;
|
||||
for (let i: number = 0; i < removeBuildCellIds.length; i++) {
|
||||
this._mapBuilds[removeBuildCellIds[i]] = null;
|
||||
}
|
||||
}
|
||||
this._lastBuildCellIds.set(areaId, buildCellIds);
|
||||
if (addBuildCellIds.length > 0 || removeBuildCellIds.length > 0 || updateBuildCellIds.length > 0) {
|
||||
console.log("update_builds", areaId, addBuildCellIds, removeBuildCellIds, updateBuildCellIds);
|
||||
EventMgr.emit("update_builds", areaId, addBuildCellIds, removeBuildCellIds, updateBuildCellIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getBuild(id: number): MapBuildData {
|
||||
return this._mapBuilds[id];
|
||||
}
|
||||
|
||||
public getMyBuildList():MapBuildData[] {
|
||||
return this._myBuilds;
|
||||
}
|
||||
|
||||
public updateSub(rid: number, unionId: number, parentId: number): void {
|
||||
if (rid == this.myId){
|
||||
this.myUnionId = unionId;
|
||||
this.myParentId = parentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapBuildProxy.ts.meta
Normal file
11
assets/scripts/map/MapBuildProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "30f95def-adfa-4692-ae01-1428da4c294a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
26
assets/scripts/map/MapBuildTagLogic.ts
Normal file
26
assets/scripts/map/MapBuildTagLogic.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
import BuildTagLogic from "./entries/BuildTagLogic";
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import { MapResData } from "./MapProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
|
||||
@ccclass('MapBuildTagLogic')
|
||||
export default class MapBuildTagLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let resData: MapResData = data as MapResData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(resData.x, resData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(BuildTagLogic).setResourceData(resData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapBuildTagLogic.ts.meta
Normal file
11
assets/scripts/map/MapBuildTagLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3419de09-e445-4de4-8f58-daae4bf77dcd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
58
assets/scripts/map/MapBuildTipsLogic.ts
Normal file
58
assets/scripts/map/MapBuildTipsLogic.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
import BuildTipsLogic from "./entries/BuildTipsLogic";
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapBuildTipsLogic')
|
||||
export default class MapBuildTipsLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
EventMgr.on("update_builds", this.onUpdateBuilds, this);
|
||||
EventMgr.on("update_build", this.onUpdateBuild, this);
|
||||
EventMgr.on("delete_build", this.onDeleteBuild, this);
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected onUpdateBuilds(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
this.addItem(areaIndex, this._cmd.buildProxy.getBuild(addIds[i]));
|
||||
}
|
||||
for (let i: number = 0; i < removeIds.length; i++) {
|
||||
this.removeItem(areaIndex, removeIds[i]);
|
||||
}
|
||||
for (let i: number = 0; i < updateIds.length; i++) {
|
||||
this.updateItem(areaIndex, this._cmd.buildProxy.getBuild(updateIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateBuild(data: MapBuildData): void {
|
||||
// console.log("update_build", data);
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(data.x, data.y);
|
||||
this.addItem(areaIndex, data);
|
||||
}
|
||||
|
||||
protected onDeleteBuild(id: number, x: number, y: number): void {
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(x, y);
|
||||
this.removeItem(areaIndex, id);
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
|
||||
let buildData: MapBuildData = data as MapBuildData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(buildData.x, buildData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(BuildTipsLogic).setBuildData(buildData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapBuildTipsLogic.ts.meta
Normal file
11
assets/scripts/map/MapBuildTipsLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8f3bc2f4-27f3-4218-b0d1-05bd5462d1f1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
57
assets/scripts/map/MapCityLogic.ts
Normal file
57
assets/scripts/map/MapCityLogic.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import CityLogic from "./entries/CityLogic";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { MapCityData } from "./MapCityProxy";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapCityLogic')
|
||||
|
||||
export default class MapCityLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
EventMgr.on("update_citys", this.onUpdateCitys, this);
|
||||
EventMgr.on("update_city", this.onUpdateCity, this);
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected onUpdateCitys(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
|
||||
// console.log("update_citys", arguments);
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
this.addItem(areaIndex, this._cmd.cityProxy.getCity(addIds[i]));
|
||||
}
|
||||
for (let i: number = 0; i < removeIds.length; i++) {
|
||||
this.removeItem(areaIndex, removeIds[i]);
|
||||
}
|
||||
for (let i: number = 0; i < updateIds.length; i++) {
|
||||
this.updateItem(areaIndex, this._cmd.cityProxy.getCity(updateIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateCity(city:MapCityData):void {
|
||||
let areaIndex:number = MapUtil.getAreaIdByCellPoint(city.x, city.y);
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
this.addItem(areaIndex, city);
|
||||
}
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let cityData: MapCityData = data as MapCityData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(cityData.x, cityData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(CityLogic).setCityData(cityData);
|
||||
}
|
||||
|
||||
public getIdByData(data: any): number {
|
||||
return (data as MapCityData).cityId;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapCityLogic.ts.meta
Normal file
11
assets/scripts/map/MapCityLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "517a6f06-32e1-478f-8835-7ae847be86c4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
257
assets/scripts/map/MapCityProxy.ts
Normal file
257
assets/scripts/map/MapCityProxy.ts
Normal file
@@ -0,0 +1,257 @@
|
||||
import { _decorator } from 'cc';
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
|
||||
/**地图城池配置*/
|
||||
export class MapCityData {
|
||||
id: number = 0;
|
||||
cityId: number = 0;
|
||||
rid: number = 0;
|
||||
name: string = "";
|
||||
x: number = null;
|
||||
y: number = 0;
|
||||
isMain: number = 0;
|
||||
level: number = 0;
|
||||
curDurable: number = 0;
|
||||
maxDurable: number = 0;
|
||||
unionId:number = 0;
|
||||
parentId:number = 0;
|
||||
unionName:string = "";
|
||||
occupyTime:number;
|
||||
|
||||
public equalsServerData(data: any) {
|
||||
if (this.cityId == data.cityId
|
||||
&& this.rid == data.rid
|
||||
&& this.name == data.name
|
||||
&& this.x == data.x
|
||||
&& this.y == data.y
|
||||
&& this.isMain == data.is_main
|
||||
&& this.level == data.level
|
||||
&& this.curDurable == data.cur_durable
|
||||
&& this.maxDurable == data.maxDurable
|
||||
&& this.unionId == data.union_id
|
||||
&& this.parentId == data.parent_id
|
||||
&& this.unionName == data.union_name
|
||||
&& this.occupyTime == data.occupy_time) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static createCityData(data: any, id: number, cityData: MapCityData = null): MapCityData {
|
||||
let city: MapCityData = cityData;
|
||||
if (cityData == null) {
|
||||
city = new MapCityData();
|
||||
}
|
||||
city.id = id;
|
||||
city.cityId = data.cityId;
|
||||
city.rid = data.rid;
|
||||
city.name = data.name;
|
||||
city.x = data.x;
|
||||
city.y = data.y;
|
||||
city.isMain = data.is_main;
|
||||
city.level = data.level;
|
||||
city.curDurable = data.cur_durable;
|
||||
city.maxDurable = data.max_durable;
|
||||
city.unionId = data.union_id;
|
||||
city.parentId = data.parent_id;
|
||||
city.unionName = data.union_name;
|
||||
city.occupyTime = data.occupy_time;
|
||||
return city;
|
||||
}
|
||||
|
||||
public getCellRadius() :number {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
export default class MapCityProxy {
|
||||
protected _mapCitys: MapCityData[] = [];
|
||||
protected _lastCityCellIds: Map<number, number[]> = new Map<number, number[]>();
|
||||
protected _myCitys: MapCityData[] = [];
|
||||
public myId: number = 0;
|
||||
public myUnionId: number = 0;
|
||||
public myParentId: number = 0;
|
||||
|
||||
// 初始化数据
|
||||
public initData(): void {
|
||||
this._mapCitys.length = MapUtil.mapCellCount;
|
||||
this._lastCityCellIds.clear();
|
||||
this.updateMyCityIds();
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._mapCitys.length = 0;
|
||||
this._lastCityCellIds.clear();
|
||||
}
|
||||
|
||||
public addCityData(data: any, cellId: number): void {
|
||||
let cityData: MapCityData = MapCityData.createCityData(data, cellId, this._mapCitys[cellId]);
|
||||
this._mapCitys[cellId] = cityData;
|
||||
this._mapCitys[cellId - 1] = cityData;
|
||||
this._mapCitys[cellId + 1] = cityData;
|
||||
this._mapCitys[cellId - MapUtil.mapSize.width] = cityData;
|
||||
this._mapCitys[cellId - MapUtil.mapSize.width - 1] = cityData;
|
||||
this._mapCitys[cellId - MapUtil.mapSize.width + 1] = cityData;
|
||||
this._mapCitys[cellId + MapUtil.mapSize.width] = cityData;
|
||||
this._mapCitys[cellId + MapUtil.mapSize.width - 1] = cityData;
|
||||
this._mapCitys[cellId + MapUtil.mapSize.width + 1] = cityData;
|
||||
}
|
||||
|
||||
public removeCityData(cellId: number): void {
|
||||
let cityData: MapCityData = this._mapCitys[cellId];
|
||||
if (cityData) {
|
||||
this._mapCitys[cellId] = null;
|
||||
this.checkAndRemoveCityCell(cellId - 1, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId + 1, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId - MapUtil.mapSize.width, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId - MapUtil.mapSize.width - 1, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId - MapUtil.mapSize.width + 1, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId + MapUtil.mapSize.width, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId + MapUtil.mapSize.width - 1, cityData.cityId);
|
||||
this.checkAndRemoveCityCell(cellId + MapUtil.mapSize.width + 1, cityData.cityId);
|
||||
}
|
||||
}
|
||||
|
||||
public checkAndRemoveCityCell(cellId: number, cityId: number): boolean {
|
||||
let cityData: MapCityData = this._mapCitys[cellId];
|
||||
if (cityData && cityData.cityId == cityId) {
|
||||
this._mapCitys[cityId] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**我的建筑信息*/
|
||||
public initMyCitys(citys: any[]): void {
|
||||
this._myCitys.length = 0;
|
||||
for (let i: number = 0; i < citys.length; i++) {
|
||||
let id: number = MapUtil.getIdByCellPoint(citys[i].x, citys[i].y);
|
||||
let city: MapCityData = MapCityData.createCityData(citys[i], id);
|
||||
if (city.isMain) {
|
||||
this._myCitys.unshift(city);
|
||||
} else {
|
||||
this._myCitys.push(city);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**更新建筑id*/
|
||||
public updateMyCityIds(): void {
|
||||
for (let i: number = 0; i < this._myCitys.length; i++) {
|
||||
let id: number = MapUtil.getIdByCellPoint(this._myCitys[i].x, this._myCitys[i].y);
|
||||
this._myCitys[i].id = id;
|
||||
this._mapCitys[id] = this._myCitys[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**更新建筑*/
|
||||
public updateCity(city: any): MapCityData {
|
||||
let id: number = MapUtil.getIdByCellPoint(city.x, city.y);
|
||||
let cityData: MapCityData = null;
|
||||
if (this._mapCitys[id] == null) {
|
||||
//代表是新增
|
||||
cityData = MapCityData.createCityData(city, id);
|
||||
this._mapCitys[id] = cityData;
|
||||
if (city.rid == this.myId) {
|
||||
this._myCitys.push(cityData);
|
||||
this.myUnionId = cityData.unionId
|
||||
this.myParentId = cityData.parentId
|
||||
}
|
||||
} else {
|
||||
cityData = MapCityData.createCityData(city, id, this._mapCitys[id]);
|
||||
if (city.rid == this.myId) {
|
||||
this.myUnionId = cityData.unionId
|
||||
this.myParentId = cityData.parentId
|
||||
}
|
||||
}
|
||||
return cityData;
|
||||
}
|
||||
|
||||
public setMapScanBlock(scanDatas: any, areaId: number = 0): void {
|
||||
let cBuilds: any[] = scanDatas.mc_builds;
|
||||
if (cBuilds.length > 0) {
|
||||
let lastCityCellIds: number[] = null;
|
||||
if (this._lastCityCellIds.has(areaId)) {
|
||||
lastCityCellIds = this._lastCityCellIds.get(areaId);
|
||||
}
|
||||
let cityCellIds: number[] = [];
|
||||
let addCityCellIds: number[] = [];
|
||||
let updateCityCellIds: number[] = [];
|
||||
let removeCityCellIds: number[] = [];
|
||||
for (let i: number = 0; i < cBuilds.length; i++) {
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(cBuilds[i].x, cBuilds[i].y);
|
||||
if (areaIndex != areaId) {
|
||||
//代表服务端给过来的数据不在当前区域
|
||||
continue;
|
||||
}
|
||||
let cellId: number = MapUtil.getIdByCellPoint(cBuilds[i].x, cBuilds[i].y);
|
||||
cityCellIds.push(cellId);
|
||||
if (lastCityCellIds) {
|
||||
let index: number = lastCityCellIds.indexOf(cellId);
|
||||
if (index != -1) {
|
||||
//存在就列表中 就代表是已存在的数据
|
||||
if (this._mapCitys[cellId].equalsServerData(cBuilds[i]) == false) {
|
||||
//代表数据不一样需要刷新
|
||||
this.addCityData(cBuilds[i], cellId);
|
||||
updateCityCellIds.push(cellId);
|
||||
}
|
||||
lastCityCellIds.splice(index, 1);//移除重复数据
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//其他情况就是新数据了
|
||||
this.addCityData(cBuilds[i], cellId);
|
||||
addCityCellIds.push(cellId);
|
||||
}
|
||||
if (lastCityCellIds && lastCityCellIds.length > 0) {
|
||||
//代表有需要删除的数据
|
||||
removeCityCellIds = lastCityCellIds;
|
||||
for (let i: number = 0; i < removeCityCellIds.length; i++) {
|
||||
this.removeCityData(removeCityCellIds[i]);
|
||||
}
|
||||
}
|
||||
this._lastCityCellIds.set(areaId, cityCellIds);
|
||||
if (addCityCellIds.length > 0 || removeCityCellIds.length > 0 || updateCityCellIds.length > 0) {
|
||||
EventMgr.emit("update_citys", areaId, addCityCellIds, removeCityCellIds, updateCityCellIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getCity(id: number): MapCityData {
|
||||
return this._mapCitys[id];
|
||||
}
|
||||
|
||||
public getMyMainCity(): MapCityData {
|
||||
if (this._myCitys.length > 0) {
|
||||
return this._myCitys[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public isMyCity(cityId: number): boolean {
|
||||
return this.getMyCityById(cityId) != null;
|
||||
}
|
||||
|
||||
public getMyCityById(cityId: number): MapCityData {
|
||||
for (let i: number = 0; i < this._myCitys.length; i++) {
|
||||
if (this._myCitys[i].cityId == cityId) {
|
||||
return this._myCitys[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getMyCitys(): MapCityData[] {
|
||||
return this._myCitys;
|
||||
}
|
||||
|
||||
public getMyPlayerId(): number {
|
||||
if (this._myCitys.length > 0) {
|
||||
return this._myCitys[0].rid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapCityProxy.ts.meta
Normal file
11
assets/scripts/map/MapCityProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "617d703b-ad2a-4935-861e-4a1619550f5d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
388
assets/scripts/map/MapClickUILogic.ts
Normal file
388
assets/scripts/map/MapClickUILogic.ts
Normal file
@@ -0,0 +1,388 @@
|
||||
import { _decorator, Component, Node, Label, ProgressBar, Button, Vec2, tween, UIOpacity, Tween, UITransform, UIRenderable } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { ArmyCmd } from "../general/ArmyProxy";
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import { MapCityData } from "./MapCityProxy";
|
||||
import MapCommand from "./MapCommand";
|
||||
import { MapResConfig, MapResData, MapResType } from "./MapProxy";
|
||||
import MapUICommand from "./ui/MapUICommand";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapClickUILogic')
|
||||
export default class MapClickUILogic extends Component {
|
||||
@property(Node)
|
||||
bgSelect: Node = null;
|
||||
@property(Label)
|
||||
labelName: Label = null;
|
||||
@property(Label)
|
||||
labelUnion: Label = null;
|
||||
@property(Label)
|
||||
labelLunxian: Label = null;
|
||||
@property(Label)
|
||||
labelPos: Label = null;
|
||||
@property(Label)
|
||||
labelMian: Label = null;
|
||||
@property(Node)
|
||||
bgMain: Node = null;
|
||||
|
||||
@property(Node)
|
||||
durableNode: Node = null;
|
||||
@property(Label)
|
||||
labelDurable: Label = null;
|
||||
@property(ProgressBar)
|
||||
progressBarDurable: ProgressBar = null;
|
||||
@property(Node)
|
||||
leftInfoNode: Node = null;
|
||||
@property(Label)
|
||||
labelYield: Label = null;
|
||||
@property(Label)
|
||||
labelSoldierCnt: Label = null;
|
||||
@property(Button)
|
||||
btnMove: Button = null;
|
||||
@property(Button)
|
||||
btnOccupy: Button = null;
|
||||
@property(Button)
|
||||
btnGiveUp: Button = null;
|
||||
@property(Button)
|
||||
btnReclaim: Button = null;
|
||||
@property(Button)
|
||||
btnEnter: Button = null;
|
||||
@property(Button)
|
||||
btnBuild: Button = null;
|
||||
@property(Button)
|
||||
btnTransfer: Button = null;
|
||||
|
||||
@property(Button)
|
||||
btnTagAdd: Button = null;
|
||||
@property(Button)
|
||||
btnTagRemove: Button = null;
|
||||
|
||||
protected _data: any = null;
|
||||
protected _pixelPos: Vec2 = null;
|
||||
protected _t = null;
|
||||
|
||||
protected onLoad(): void {
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this._data = null;
|
||||
this._pixelPos = null;
|
||||
}
|
||||
|
||||
protected onEnable(): void {
|
||||
EventMgr.on("update_build", this.onUpdateBuild, this);
|
||||
|
||||
var uiOpacity = this.bgSelect.getComponent(UIOpacity);
|
||||
uiOpacity.opacity = 255;
|
||||
|
||||
let t = tween(uiOpacity).to(0.8, { opacity: 0 }).to(0.8, { opacity: 255 });
|
||||
t = t.repeatForever(t);
|
||||
t.start();
|
||||
|
||||
this._t = t;
|
||||
|
||||
}
|
||||
|
||||
protected onDisable(): void {
|
||||
EventMgr.targetOff(this);
|
||||
this._t.stop();
|
||||
this.stopCountDown();
|
||||
}
|
||||
|
||||
protected onUpdateBuild(data: MapBuildData): void {
|
||||
if (this._data
|
||||
&& this._data instanceof MapBuildData
|
||||
&& this._data.x == data.x
|
||||
&& this._data.y == data.y) {
|
||||
this.setCellData(data, this._pixelPos);
|
||||
}
|
||||
}
|
||||
|
||||
protected onClickEnter(): void {
|
||||
console.log("onClickEnter");
|
||||
|
||||
if (this._data instanceof MapBuildData){
|
||||
EventMgr.emit("open_fortress_about", this._data);
|
||||
}else if (this._data instanceof MapCityData){
|
||||
EventMgr.emit("open_city_about", this._data);
|
||||
}
|
||||
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onClickReclaim(): void {
|
||||
EventMgr.emit("open_army_select_ui", ArmyCmd.Reclaim, this._data.x, this._data.y);
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onClickGiveUp(): void {
|
||||
MapCommand.getInstance().giveUpBuild(this._data.x, this._data.y);
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onClickBuild(): void {
|
||||
MapCommand.getInstance().build(this._data.x, this._data.y, MapResType.FORTRESS);
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onClickTransfer(): void{
|
||||
console.log("onClickTransfer");
|
||||
this.node.parent = null;
|
||||
EventMgr.emit("open_army_select_ui", ArmyCmd.Transfer, this._data.x, this._data.y);
|
||||
}
|
||||
|
||||
protected onClickMove(): void {
|
||||
if (MapCommand.getInstance().isCanMoveCell(this._data.x, this._data.y)) {
|
||||
EventMgr.emit("open_army_select_ui", ArmyCmd.Garrison, this._data.x, this._data.y);
|
||||
} else {
|
||||
console.log("只能驻军自己占领的地");
|
||||
}
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
|
||||
protected onTagAdd(): void {
|
||||
MapCommand.getInstance().opPosTag(1, this._data.x, this._data.y, this.labelName.string);
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onTagRemove(): void {
|
||||
MapCommand.getInstance().opPosTag(0, this._data.x, this._data.y);
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
protected onClickOccupy(): void {
|
||||
if (MapCommand.getInstance().isCanOccupyCell(this._data.x, this._data.y)) {
|
||||
EventMgr.emit("open_army_select_ui", ArmyCmd.Attack, this._data.x, this._data.y);
|
||||
} else {
|
||||
console.log("只能占领自己相邻的地");
|
||||
}
|
||||
|
||||
this.node.parent = null;
|
||||
}
|
||||
|
||||
public setCellData(data: any, pixelPos: Vec2): void {
|
||||
this._data = data;
|
||||
this._pixelPos = pixelPos;
|
||||
this.labelPos.string = "(" + data.x + ", " + data.y + ")";
|
||||
this.leftInfoNode.active = true;
|
||||
this.btnReclaim.node.active = false;
|
||||
this.btnEnter.node.active = false;
|
||||
this.bgSelect.getComponent(UITransform).width = 200;
|
||||
this.bgSelect.getComponent(UITransform).height = 100;
|
||||
|
||||
var isTag = MapCommand.getInstance().proxy.isPosTag(this._data.x, this._data.y);
|
||||
|
||||
// console.log("isTag:", isTag);
|
||||
|
||||
this.btnTagAdd.node.active = !isTag;
|
||||
this.btnTagRemove.node.active = isTag;
|
||||
|
||||
if (this._data instanceof MapResData) {
|
||||
//点击的是野外
|
||||
this.btnMove.node.active = false;
|
||||
this.btnOccupy.node.active = true;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
this.durableNode.active = false;
|
||||
|
||||
} else if (this._data instanceof MapBuildData) {
|
||||
//点击的是占领地
|
||||
if ((this._data as MapBuildData).rid == MapCommand.getInstance().buildProxy.myId) {
|
||||
//我自己的地
|
||||
this.btnMove.node.active = true;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = !this._data.isInGiveUp();
|
||||
this.btnReclaim.node.active = this._data.isResBuild();
|
||||
this.btnBuild.node.active = !this._data.isWarFree();
|
||||
|
||||
//是资源地
|
||||
if(this._data.isResBuild()){
|
||||
this.btnTransfer.node.active = false;
|
||||
this.btnEnter.node.active = false;
|
||||
this.btnBuild.node.active = !this._data.isBuilding();
|
||||
}else if(this._data.isSysCity()){
|
||||
this.btnTransfer.node.active = false;
|
||||
this.btnEnter.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
}else if(this._data.isSysFortress){
|
||||
this.btnTransfer.node.active = true;
|
||||
this.btnEnter.node.active = true;
|
||||
this.btnBuild.node.active = false;
|
||||
}
|
||||
|
||||
if (this._data.isInGiveUp()){
|
||||
this.btnBuild.node.active = false;
|
||||
}
|
||||
|
||||
if (this._data.isWarFree()){
|
||||
this.btnGiveUp.node.active = false;
|
||||
}
|
||||
|
||||
} else if ((this._data as MapBuildData).unionId > 0
|
||||
&& (this._data as MapBuildData).unionId == MapCommand.getInstance().buildProxy.myUnionId) {
|
||||
//盟友的地
|
||||
this.btnMove.node.active = true;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
} else if ((this._data as MapBuildData).parentId > 0
|
||||
&& (this._data as MapBuildData).parentId == MapCommand.getInstance().buildProxy.myUnionId) {
|
||||
//俘虏的地
|
||||
this.btnMove.node.active = true;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
}else {
|
||||
this.btnMove.node.active = false;
|
||||
this.btnOccupy.node.active = true;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
}
|
||||
this.durableNode.active = true;
|
||||
this.labelDurable.string = Math.ceil(this._data.curDurable/100) + "/" + Math.ceil(this._data.maxDurable/100);
|
||||
this.progressBarDurable.progress = this._data.curDurable / this._data.maxDurable;
|
||||
} else if (this._data instanceof MapCityData) {
|
||||
//点击其他城市
|
||||
if (this._data.rid == MapCommand.getInstance().cityProxy.myId) {
|
||||
//我自己的城池
|
||||
this.btnEnter.node.active = true;
|
||||
this.btnMove.node.active = false;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
this.btnTagAdd.node.active = false;
|
||||
this.btnTagRemove.node.active = false;
|
||||
|
||||
} else if ((this._data as MapCityData).unionId > 0
|
||||
&& (this._data as MapCityData).unionId == MapCommand.getInstance().cityProxy.myUnionId) {
|
||||
//盟友的城池
|
||||
this.btnMove.node.active = true;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
}else if ((this._data as MapCityData).parentId > 0
|
||||
&& (this._data as MapCityData).parentId == MapCommand.getInstance().cityProxy.myUnionId) {
|
||||
//俘虏的城池
|
||||
this.btnMove.node.active = true;
|
||||
this.btnOccupy.node.active = false;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
}else {
|
||||
this.btnMove.node.active = false;
|
||||
this.btnOccupy.node.active = true;
|
||||
this.btnGiveUp.node.active = false;
|
||||
this.btnBuild.node.active = false;
|
||||
this.btnTransfer.node.active = false;
|
||||
}
|
||||
this.bgSelect.getComponent(UITransform).setContentSize(600, 300);
|
||||
this.leftInfoNode.active = false;
|
||||
this.durableNode.active = true;
|
||||
this.labelDurable.string = Math.ceil(this._data.curDurable/100) + "/" + Math.ceil(this._data.maxDurable/100);
|
||||
this.progressBarDurable.progress = this._data.curDurable / this._data.maxDurable;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(this._data.type == MapResType.SYS_CITY){
|
||||
|
||||
if(this._data.level >= 8){
|
||||
this.bgSelect.getComponent(UITransform).setContentSize(960*1.5, 480*1.5);
|
||||
}else if(this._data.level >= 5){
|
||||
this.bgSelect.getComponent(UITransform).setContentSize(960, 480);
|
||||
}else {
|
||||
this.bgSelect.getComponent(UITransform).setContentSize(960*0.5, 480*0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.leftInfoNode.active ) {
|
||||
|
||||
let resData: MapResData = MapCommand.getInstance().proxy.getResData(this._data.id);
|
||||
let resCfg: MapResConfig = MapCommand.getInstance().proxy.getResConfig(resData.type, resData.level);
|
||||
|
||||
let soldiers = MapUICommand.getInstance().proxy.getDefenseSoldiers(resData.level);
|
||||
this.labelYield.string = MapCommand.getInstance().proxy.getResYieldDesList(resCfg).join("\n");
|
||||
this.labelSoldierCnt.string = "守备兵力 " + soldiers*3;
|
||||
|
||||
if (this._data.nickName){
|
||||
this.labelName.string = this._data.nickName + ":" + this._data.name;
|
||||
}else{
|
||||
this.labelName.string = resCfg.name;
|
||||
}
|
||||
} else {
|
||||
this.labelName.string = this._data.name;
|
||||
}
|
||||
|
||||
//归属属性
|
||||
if (this._data.rid == null || this._data.rid == 0){
|
||||
this.labelUnion.string = "未占领";
|
||||
}else{
|
||||
if (this._data.unionId > 0){
|
||||
this.labelUnion.string = this._data.unionName;
|
||||
}else{
|
||||
this.labelUnion.string = "在野";
|
||||
}
|
||||
}
|
||||
|
||||
if (this._data.parentId > 0){
|
||||
this.labelLunxian.string = "沦陷";
|
||||
}else{
|
||||
this.labelLunxian.string = "";
|
||||
}
|
||||
|
||||
|
||||
//免战信息
|
||||
var limitTime = MapCommand.getInstance().proxy.getWarFree();
|
||||
var diff = DateUtil.getServerTime() - this._data.occupyTime;
|
||||
if (this._data instanceof MapBuildData){
|
||||
if(diff > limitTime){
|
||||
this.bgMain.active = false;
|
||||
this.labelMian.string = "";
|
||||
}else{
|
||||
this.bgMain.active = true;
|
||||
this.schedule(this.countDown, 1);
|
||||
this.countDown()
|
||||
}
|
||||
|
||||
}else if(this._data instanceof MapCityData){
|
||||
if(diff < limitTime && this._data.parentId > 0){
|
||||
this.bgMain.active = true;
|
||||
this.schedule(this.countDown, 1);
|
||||
this.countDown()
|
||||
}else{
|
||||
this.bgMain.active = false;
|
||||
this.labelMian.string = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public countDown() {
|
||||
var diff = DateUtil.getServerTime() - this._data.occupyTime;
|
||||
var limitTime = MapCommand.getInstance().proxy.getWarFree();
|
||||
if (diff>limitTime){
|
||||
this.stopCountDown();
|
||||
|
||||
}else{
|
||||
var str = DateUtil.converSecondStr(limitTime-diff);
|
||||
this.labelMian.string = "免战:" + str;
|
||||
}
|
||||
}
|
||||
|
||||
public stopCountDown() {
|
||||
this.unscheduleAllCallbacks();
|
||||
this.labelMian.string = "";
|
||||
this.bgMain.active = false;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapClickUILogic.ts.meta
Normal file
11
assets/scripts/map/MapClickUILogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f2deb972-ceab-454c-998d-c0c07434d621",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
427
assets/scripts/map/MapCommand.ts
Normal file
427
assets/scripts/map/MapCommand.ts
Normal file
@@ -0,0 +1,427 @@
|
||||
import { _decorator } from 'cc';
|
||||
import { ServerConfig } from "../config/ServerConfig";
|
||||
import ArmyCommand from "../general/ArmyCommand";
|
||||
import GeneralCommand from "../general/GeneralCommand";
|
||||
import { NetManager } from "../network/socket/NetManager";
|
||||
import DateUtil from "../utils/DateUtil";
|
||||
import MapBuildProxy, { MapBuildData } from "./MapBuildProxy";
|
||||
import MapCityProxy, { MapCityData } from "./MapCityProxy";
|
||||
import MapProxy, { MapAreaData } from "./MapProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import MapUICommand from "./ui/MapUICommand";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
export default class MapCommand {
|
||||
//单例
|
||||
protected static _instance: MapCommand;
|
||||
public static getInstance(): MapCommand {
|
||||
if (this._instance == null) {
|
||||
this._instance = new MapCommand();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public static destory(): boolean {
|
||||
if (this._instance) {
|
||||
this._instance.onDestory();
|
||||
this._instance = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//数据model
|
||||
protected _proxy: MapProxy = new MapProxy();
|
||||
protected _cityProxy: MapCityProxy = new MapCityProxy();
|
||||
protected _buildProxy: MapBuildProxy = new MapBuildProxy();
|
||||
protected _isQryMyProperty: boolean = false;
|
||||
|
||||
constructor() {
|
||||
EventMgr.on(ServerConfig.role_myProperty, this.onRoleMyProperty, this);
|
||||
EventMgr.on(ServerConfig.roleBuild_push, this.onRoleBuildStatePush, this);
|
||||
EventMgr.on(ServerConfig.nationMap_config, this.onNationMapConfig, this);
|
||||
EventMgr.on(ServerConfig.nationMap_scanBlock, this.onNationMapScanBlock, this);
|
||||
EventMgr.on(ServerConfig.nationMap_giveUp, this.onNationMapGiveUp, this);
|
||||
EventMgr.on(ServerConfig.nationMap_build, this.onNationMapBuild, this);
|
||||
EventMgr.on(ServerConfig.nationMap_upBuild, this.onNationMapUpBuild, this);
|
||||
EventMgr.on(ServerConfig.roleCity_push, this.onRoleCityPush, this);
|
||||
EventMgr.on(ServerConfig.role_posTagList, this.onPosTagList, this);
|
||||
EventMgr.on(ServerConfig.role_opPosTag, this.onOpPosTag, this);
|
||||
}
|
||||
|
||||
public onDestory(): void {
|
||||
EventMgr.targetOff(this);
|
||||
}
|
||||
|
||||
public initData(): void {
|
||||
this._proxy.initData();
|
||||
this._cityProxy.initData();
|
||||
this._buildProxy.initData();
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._proxy.clearData();
|
||||
this._cityProxy.clearData();
|
||||
this._buildProxy.clearData();
|
||||
this._isQryMyProperty = false;
|
||||
}
|
||||
|
||||
public get proxy(): MapProxy {
|
||||
return this._proxy;
|
||||
}
|
||||
|
||||
public get cityProxy(): MapCityProxy {
|
||||
return this._cityProxy;
|
||||
}
|
||||
|
||||
public get buildProxy(): MapBuildProxy {
|
||||
return this._buildProxy;
|
||||
}
|
||||
|
||||
protected onRoleMyProperty(data: any): void {
|
||||
console.log("onRoleMyProperty", data);
|
||||
if (data.code == 0) {
|
||||
this._isQryMyProperty = true;
|
||||
MapUICommand.getInstance().updateMyProperty(data);
|
||||
GeneralCommand.getInstance().updateMyProperty(data.msg.generals);
|
||||
ArmyCommand.getInstance().updateMyProperty(data.msg.armys);
|
||||
this._cityProxy.initMyCitys(data.msg.citys);
|
||||
this._buildProxy.initMyBuilds(data.msg.mr_builds);
|
||||
this._cityProxy.myId = this._cityProxy.getMyPlayerId();
|
||||
this._buildProxy.myId = this._cityProxy.getMyPlayerId();
|
||||
this._cityProxy.myUnionId = this._cityProxy.getMyMainCity().unionId;
|
||||
this._cityProxy.myParentId = this._cityProxy.getMyMainCity().parentId;
|
||||
this._buildProxy.myUnionId = this._cityProxy.getMyMainCity().unionId;
|
||||
this._buildProxy.myParentId = this._cityProxy.getMyMainCity().parentId;
|
||||
MapCommand.getInstance().posTagList();
|
||||
|
||||
this.enterMap();
|
||||
}
|
||||
}
|
||||
|
||||
protected onRoleBuildStatePush(data: any): void {
|
||||
console.log("onRoleBuildStatePush", data);
|
||||
if (data.code == 0) {
|
||||
this._buildProxy.updateBuild(data.msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected onNationMapConfig(data: any): void {
|
||||
console.log("onNationMapConfig", data);
|
||||
if (data.code == 0) {
|
||||
this._proxy.setNationMapConfig(data.msg.Confs);
|
||||
this.enterMap();
|
||||
}
|
||||
}
|
||||
|
||||
protected onNationMapScanBlock(data: any, otherData: any): void {
|
||||
console.log("onNationMapScan", data, otherData);
|
||||
if (data.code == 0) {
|
||||
this._cityProxy.setMapScanBlock(data.msg, otherData.id);
|
||||
this._buildProxy.setMapScanBlock(data.msg, otherData.id);
|
||||
}
|
||||
}
|
||||
|
||||
protected onNationMapGiveUp(data: any, otherData: any): void {
|
||||
console.log("onNationMapGiveUp", data, otherData);
|
||||
}
|
||||
|
||||
protected onNationMapBuild(data: any, otherData: any): void {
|
||||
console.log("onNationMapBuild", data, otherData);
|
||||
}
|
||||
|
||||
protected onNationMapUpBuild(data: any, otherData: any): void {
|
||||
console.log("onNationMapUpBuild", data, otherData);
|
||||
}
|
||||
|
||||
protected onPosTagList(data: any, otherData: any): void {
|
||||
console.log("onPosTagList", data, otherData);
|
||||
if(data.code == 0){
|
||||
this._proxy.updateMapPosTags(data.msg.pos_tags);
|
||||
}
|
||||
}
|
||||
|
||||
protected onOpPosTag(data: any, otherData: any): void {
|
||||
console.log("onOpPosTag", data, otherData);
|
||||
if(data.code == 0){
|
||||
if(data.msg.type == 0){
|
||||
this._proxy.removeMapPosTag(data.msg.x, data.msg.y);
|
||||
// EventMgr.emit("show_toast", "移除成功");
|
||||
EventMgr.emit("update_tag");
|
||||
}else if(data.msg.type == 1){
|
||||
this._proxy.addMapPosTag(data.msg.x, data.msg.y, data.msg.name);
|
||||
// EventMgr.emit("show_toast", "添加成功");
|
||||
EventMgr.emit("update_tag");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected onRoleCityPush(data: any): void {
|
||||
console.log("onRoleCityPush:", data)
|
||||
this._buildProxy.updateSub(data.msg.rid, data.msg.union_id, data.msg.parent_id);
|
||||
this._cityProxy.updateCity(data.msg);
|
||||
EventMgr.emit("unionChange", data.msg.rid, data.msg.union_id, data.msg.parent_id);
|
||||
|
||||
}
|
||||
|
||||
public isBuildSub(id: number): boolean {
|
||||
let buiildData: MapBuildData = this.buildProxy.getBuild(id);
|
||||
if (buiildData) {
|
||||
if (buiildData.rid == this.buildProxy.myId){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (buiildData.unionId > 0 && buiildData.unionId == this.buildProxy.myUnionId){
|
||||
return true
|
||||
}
|
||||
|
||||
if (buiildData.parentId > 0 && buiildData.parentId == this.buildProxy.myUnionId){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isBuildWarFree(id: number): boolean {
|
||||
let buiildData: MapBuildData = this.buildProxy.getBuild(id);
|
||||
if(buiildData){
|
||||
return buiildData.isWarFree();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public isCitySub(id: number): boolean {
|
||||
let cityData: MapCityData = this.cityProxy.getCity(id);
|
||||
if (cityData) {
|
||||
if (cityData.rid == this.cityProxy.myId){
|
||||
return true
|
||||
}
|
||||
|
||||
if (cityData.unionId > 0 && cityData.unionId == this.cityProxy.myUnionId){
|
||||
return true
|
||||
}
|
||||
|
||||
if (cityData.parentId > 0 && cityData.parentId == this.cityProxy.myUnionId){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isCityWarFree(id: number): boolean {
|
||||
let cityData: MapCityData = this.cityProxy.getCity(id);
|
||||
if (cityData && cityData.parentId > 0) {
|
||||
var diff = DateUtil.getServerTime() - cityData.occupyTime;
|
||||
if(diff < MapCommand.getInstance().proxy.getWarFree()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
/**是否是可行军的位置*/
|
||||
public isCanMoveCell(x: number, y: number): boolean {
|
||||
let id: number = MapUtil.getIdByCellPoint(x, y);
|
||||
if (this.isBuildSub(id)){
|
||||
return true
|
||||
}
|
||||
|
||||
if (this.isCitySub(id)){
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
public isCanOccupyCell(x: number, y: number): boolean {
|
||||
var radius = 0;
|
||||
let id: number = MapUtil.getIdByCellPoint(x, y);
|
||||
let cityData: MapCityData = this.cityProxy.getCity(id);
|
||||
if (cityData) {
|
||||
if(this.isCityWarFree(id)){
|
||||
return false;
|
||||
}
|
||||
radius = cityData.getCellRadius();
|
||||
}
|
||||
|
||||
let buildData: MapBuildData = this.buildProxy.getBuild(id);
|
||||
if (buildData) {
|
||||
if(this.isBuildWarFree(id)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// console.log("buildData 11111:", buildData);
|
||||
radius = buildData.getCellRadius();
|
||||
}
|
||||
|
||||
//查找半径10
|
||||
for (let tx = x-10; tx <= x+10; tx++) {
|
||||
for (let ty = y-10; ty <= y+10; ty++) {
|
||||
|
||||
let id: number = MapUtil.getIdByCellPoint(tx, ty);
|
||||
let cityData: MapCityData = this.cityProxy.getCity(id);
|
||||
if (cityData) {
|
||||
var absX = Math.abs(x-tx);
|
||||
var absY = Math.abs(y-ty);
|
||||
if (absX <= radius+cityData.getCellRadius()+1 && absY <= radius+cityData.getCellRadius()+1){
|
||||
var ok = this.isCitySub(id)
|
||||
if(ok){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let buildData: MapBuildData = this.buildProxy.getBuild(id);
|
||||
if (buildData) {
|
||||
var absX = Math.abs(x-tx);
|
||||
var absY = Math.abs(y-ty);
|
||||
// console.log("MapBuildData:", absX, absY, radius+buildData.getCellRadius()+1, buildData);
|
||||
if (absX <= radius+buildData.getCellRadius()+1 && absY <= radius+buildData.getCellRadius()+1){
|
||||
var ok = this.isBuildSub(id)
|
||||
if(ok){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public enterMap(): void {
|
||||
if (this._proxy.hasResConfig() == false) {
|
||||
this.qryNationMapConfig();
|
||||
return;
|
||||
}
|
||||
if (this._isQryMyProperty == false) {
|
||||
this.qryRoleMyProperty();
|
||||
return;
|
||||
}
|
||||
EventMgr.emit("enter_map");
|
||||
}
|
||||
|
||||
/**请求角色全量信息*/
|
||||
public qryRoleMyProperty(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.role_myProperty,
|
||||
msg: {
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
/**请求自己的城池信息*/
|
||||
public qryRoleMyCity(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.role_myCity,
|
||||
msg: {}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
/**请求地图基础配置*/
|
||||
public qryNationMapConfig(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_config,
|
||||
msg: {}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public qryNationMapScanBlock(qryData: MapAreaData): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_scanBlock,
|
||||
msg: {
|
||||
x: qryData.startCellX,
|
||||
y: qryData.startCellY,
|
||||
length: qryData.len
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData, qryData);
|
||||
}
|
||||
|
||||
public giveUpBuild(x: number, y: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_giveUp,
|
||||
msg: {
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public build(x: number, y: number, type: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_build,
|
||||
msg: {
|
||||
x: x,
|
||||
y: y,
|
||||
type: type,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public upBuild(x: number, y: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_upBuild,
|
||||
msg: {
|
||||
x: x,
|
||||
y: y,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public delBuild(x: number, y: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.nationMap_delBuild,
|
||||
msg: {
|
||||
x: x,
|
||||
y: y,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
|
||||
public upPosition(x: number, y: number): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.role_upPosition,
|
||||
msg: {
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
public posTagList(): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.role_posTagList,
|
||||
msg: {
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
//1添加、0移除
|
||||
public opPosTag(type:number, x: number, y: number, name = ""): void {
|
||||
let sendData: any = {
|
||||
name: ServerConfig.role_opPosTag,
|
||||
msg: {
|
||||
type:type,
|
||||
x:x,
|
||||
y:y,
|
||||
name:name,
|
||||
}
|
||||
};
|
||||
NetManager.getInstance().send(sendData);
|
||||
}
|
||||
|
||||
}
|
||||
11
assets/scripts/map/MapCommand.ts.meta
Normal file
11
assets/scripts/map/MapCommand.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0257052c-05b8-4090-abff-1f27ea2c95b1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
58
assets/scripts/map/MapFacilityBuildLogic.ts
Normal file
58
assets/scripts/map/MapFacilityBuildLogic.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
import FacilityBuildLogic from "./entries/FacilityBuildLogic";
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapFacilityBuildLogic')
|
||||
export default class MapFacilityBuildLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
EventMgr.on("update_builds", this.onUpdateBuilds, this);
|
||||
EventMgr.on("update_build", this.onUpdateBuild, this);
|
||||
EventMgr.on("delete_build", this.onDeleteBuild, this);
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected onUpdateBuilds(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
|
||||
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
this.addItem(areaIndex, this._cmd.buildProxy.getBuild(addIds[i]));
|
||||
}
|
||||
for (let i: number = 0; i < removeIds.length; i++) {
|
||||
this.removeItem(areaIndex, removeIds[i]);
|
||||
}
|
||||
for (let i: number = 0; i < updateIds.length; i++) {
|
||||
this.updateItem(areaIndex, this._cmd.buildProxy.getBuild(updateIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateBuild(data: MapBuildData): void {
|
||||
// console.log("update_build", data);
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(data.x, data.y);
|
||||
this.addItem(areaIndex, data);
|
||||
}
|
||||
|
||||
protected onDeleteBuild(id: number, x: number, y: number): void {
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(x, y);
|
||||
this.removeItem(areaIndex, id);
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let buildData: MapBuildData = data as MapBuildData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(buildData.x, buildData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(FacilityBuildLogic).setBuildData(buildData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapFacilityBuildLogic.ts.meta
Normal file
11
assets/scripts/map/MapFacilityBuildLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5c7b5dbd-6117-4f72-b4a7-b8048284edb7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
192
assets/scripts/map/MapLogic.ts
Normal file
192
assets/scripts/map/MapLogic.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
import { _decorator, Component, TiledMap, Camera, Node, Vec2, Event, game, UITransform, EventMouse, EventTouch, Vec3, view } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import MapCommand from "./MapCommand";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapLogic')
|
||||
export default class MapLogic extends Component {
|
||||
protected _cmd: MapCommand;
|
||||
protected _tiledMap: TiledMap = null;
|
||||
protected _mapCamera: Camera = null;
|
||||
protected _isTouch: boolean = false;
|
||||
protected _isMove: boolean = false;
|
||||
//地图相机缩放倍率边界
|
||||
protected _minZoomRatio: number = 1;
|
||||
protected _maxZoomRatio: number = 0.8;
|
||||
protected _changeZoomRadix: number = 200;
|
||||
protected _orthoHeight:number = 360;
|
||||
|
||||
//地图相机移动边界
|
||||
protected _maxMapX: number = 1;
|
||||
protected _maxMapY: number = 1;
|
||||
|
||||
protected _touchAniNode: Node = null;
|
||||
protected _centerPoint: Vec2 = null;
|
||||
|
||||
protected onLoad(): void {
|
||||
console.log("MapLogic onLoad");
|
||||
this._cmd = MapCommand.getInstance();
|
||||
this._mapCamera = this.node.parent.getChildByName("Map Camera").getComponent(Camera);
|
||||
console.log("_mapCamera:", this._mapCamera);
|
||||
this._orthoHeight = this._mapCamera.orthoHeight;
|
||||
|
||||
EventMgr.on("open_city_about", this.openCityAbout, this);
|
||||
EventMgr.on("close_city_about", this.closeCityAbout, this);
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
|
||||
this._cmd = null;
|
||||
}
|
||||
|
||||
public setTiledMap(tiledMap: TiledMap): void {
|
||||
this._tiledMap = tiledMap;
|
||||
this._tiledMap.enableCulling = true;
|
||||
|
||||
this.updateCulling();
|
||||
|
||||
var uit = this._tiledMap.node.getComponent(UITransform);
|
||||
this._maxMapX = (uit.width - view.getVisibleSize().width) * 0.5;
|
||||
this._maxMapY = (uit.height - view.getVisibleSize().height) * 0.5;
|
||||
this._tiledMap.node.on(Node.EventType.MOUSE_WHEEL, this.onMouseWheel, this);
|
||||
this._tiledMap.node.on(Node.EventType.TOUCH_START, this.onTouchBegan, this);
|
||||
this._tiledMap.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
this._tiledMap.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
this._tiledMap.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
|
||||
}
|
||||
|
||||
protected openCityAbout(data: any): void {
|
||||
this._mapCamera.orthoHeight = this._orthoHeight * this._maxZoomRatio;
|
||||
}
|
||||
|
||||
protected closeCityAbout(): void {
|
||||
this._mapCamera.orthoHeight = this._orthoHeight * this._minZoomRatio;
|
||||
}
|
||||
|
||||
protected onMouseWheel(event: EventMouse): void {
|
||||
console.log("onMouseWheel");
|
||||
|
||||
let scrollY: number = event.getScrollY();
|
||||
let changeRatio: number = Number((scrollY / this._changeZoomRadix).toFixed(1));
|
||||
let newZoomRatio: number = Math.min(this._minZoomRatio, Math.max(this._maxZoomRatio, this._mapCamera.orthoHeight/this._orthoHeight + changeRatio));
|
||||
|
||||
console.log("onMouseWheel:", newZoomRatio);
|
||||
this._mapCamera.orthoHeight = this._orthoHeight * newZoomRatio;
|
||||
}
|
||||
|
||||
protected onTouchMove(event: EventTouch): void {
|
||||
if (this._isTouch) {
|
||||
let delta: Vec2 = event.getDelta();
|
||||
if (delta.x != 0 || delta.y != 0) {
|
||||
this._isMove = true;
|
||||
let pixelPoint: Vec2 = new Vec2(0, 0);
|
||||
pixelPoint.x = this._mapCamera.node.position.x - delta.x;
|
||||
pixelPoint.y = this._mapCamera.node.position.y - delta.y;
|
||||
pixelPoint.x = Math.min(this._maxMapX, Math.max(-this._maxMapX, pixelPoint.x));
|
||||
pixelPoint.y = Math.min(this._maxMapY, Math.max(-this._maxMapY, pixelPoint.y));
|
||||
this._mapCamera.node.setPosition(new Vec3(pixelPoint.x, pixelPoint.y, this._mapCamera.node.position.z));
|
||||
this.setCenterMapCellPoint(MapUtil.mapPixelToCellPoint(pixelPoint), pixelPoint);
|
||||
this.updateCulling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onTouchBegan(event: EventTouch): void {
|
||||
this._isTouch = true;
|
||||
this._isMove = false;
|
||||
}
|
||||
|
||||
protected onTouchEnd(event: EventTouch): void {
|
||||
this._isTouch = false;
|
||||
if (this._isMove == false) {
|
||||
let touchLocation: Vec2 = event.touch.getUILocation();
|
||||
let touchLocation1 = this.viewPointToWorldPoint(touchLocation);
|
||||
let mapPoint: Vec2 = MapUtil.worldPixelToMapCellPoint(touchLocation1);
|
||||
let clickCenterPoint: Vec2 = MapUtil.mapCellToPixelPoint(mapPoint);
|
||||
//派发事件
|
||||
// console.log("onTouchEnd:", touchLocation1, clickCenterPoint);
|
||||
|
||||
EventMgr.emit("touch_map", mapPoint, clickCenterPoint);
|
||||
} else {
|
||||
EventMgr.emit("move_map");
|
||||
}
|
||||
this._isMove = false;
|
||||
}
|
||||
|
||||
protected onTouchCancel(event: EventTouch): void {
|
||||
this._isTouch = false;
|
||||
this._isMove = false;
|
||||
}
|
||||
|
||||
//界面坐标转世界坐标
|
||||
protected viewPointToWorldPoint(point: Vec2): Vec2 {
|
||||
// console.log("viewPointToWorldPoint in", point.x, point.y);
|
||||
|
||||
let canvasNode: Node = this.node.parent;
|
||||
let cuit = canvasNode.getComponent(UITransform);
|
||||
let uit = this._tiledMap.node.getComponent(UITransform);
|
||||
|
||||
|
||||
let cameraWorldX: number = uit.width * uit.anchorX - view.getVisibleSize().width * cuit.anchorX + this._mapCamera.node.position.x;
|
||||
let cameraWorldY: number = uit.height * uit.anchorY - view.getVisibleSize().height * cuit.anchorY + this._mapCamera.node.position.y;
|
||||
|
||||
return new Vec2(point.x + cameraWorldX, point.y + cameraWorldY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//世界坐标转化为相对地图的像素坐标
|
||||
protected worldToMapPixelPoint(point: Vec2): Vec2 {
|
||||
var uit = this._tiledMap.node.getComponent(UITransform);
|
||||
let pixelX: number = point.x - uit.width * uit.anchorX;
|
||||
let pixelY: number = point.y - uit.height * uit.anchorY;
|
||||
return new Vec2(pixelX, pixelY);
|
||||
}
|
||||
|
||||
public scrollToMapPoint(point: Vec2): void {
|
||||
let pixelPoint: Vec2 = MapUtil.mapCellToPixelPoint(point);
|
||||
// console.log("scrollToMapPoint", pixelPoint.x, pixelPoint.y);
|
||||
let positionX: number = Math.min(this._maxMapX, Math.max(-this._maxMapX, pixelPoint.x));
|
||||
let positionY: number = Math.min(this._maxMapY, Math.max(-this._maxMapY, pixelPoint.y));
|
||||
let pos = this._mapCamera.node.position.clone();
|
||||
pos.x = positionX;
|
||||
pos.y = positionY;
|
||||
this._mapCamera.node.position = pos;
|
||||
|
||||
this.setCenterMapCellPoint(point, pixelPoint);
|
||||
|
||||
this.updateCulling();
|
||||
}
|
||||
|
||||
protected setCenterMapCellPoint(point: Vec2, pixelPoint: Vec2): void {
|
||||
this._cmd.proxy.setCurCenterPoint(point, pixelPoint);
|
||||
}
|
||||
|
||||
private updateCulling() {
|
||||
if(this._tiledMap){
|
||||
// let layers = this._tiledMap.getLayers();
|
||||
// for (let index = 0; index < layers.length; index++) {
|
||||
// const l = layers[index];
|
||||
// l.updateCulling();
|
||||
// }
|
||||
|
||||
// this.scheduleOnce(()=>{
|
||||
// for (let index = 0; index < layers.length; index++) {
|
||||
// const l = layers[index];
|
||||
// l.updateCulling();
|
||||
// }
|
||||
// })
|
||||
|
||||
this._tiledMap.node.emit(Node.EventType.TRANSFORM_CHANGED);
|
||||
this.scheduleOnce(()=>{
|
||||
this._tiledMap.node.emit(Node.EventType.TRANSFORM_CHANGED);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapLogic.ts.meta
Normal file
11
assets/scripts/map/MapLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "066de832-f6af-4230-b05a-a413e2a0f985",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
396
assets/scripts/map/MapProxy.ts
Normal file
396
assets/scripts/map/MapProxy.ts
Normal file
@@ -0,0 +1,396 @@
|
||||
import { _decorator, TiledMapAsset, Vec2, game, view } from 'cc';
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
|
||||
export class MapResConfig {
|
||||
type: number = 0;
|
||||
level: number = 0;
|
||||
name: string = "";
|
||||
wood: number = 0;
|
||||
iron: number = 0;
|
||||
stone: number = 0;
|
||||
grain: number = 0;
|
||||
durable: number = 0;
|
||||
defender: number = 0;
|
||||
}
|
||||
|
||||
/**地图资源类型*/
|
||||
export class MapResType {
|
||||
static SYS_FORTRESS: number = 50; //系统要塞
|
||||
static SYS_CITY: number = 51;
|
||||
static WOOD: number = 52;
|
||||
static IRON: number = 53;
|
||||
static STONE: number = 54;
|
||||
static GRAIN: number = 55;
|
||||
static FORTRESS: number = 56; //要塞
|
||||
|
||||
}
|
||||
|
||||
/**地图资源数据*/
|
||||
export class MapResData {
|
||||
id: number = 0;
|
||||
type: number = 0;
|
||||
level: number = 0;
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class MapTagPos {
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
name: string = "";
|
||||
}
|
||||
|
||||
/**地图区域数据*/
|
||||
export class MapAreaData {
|
||||
static MAX_TIME: number = 10000;
|
||||
id: number = 0;
|
||||
x: number = 0;
|
||||
y: number = 0;
|
||||
startCellX: number = 0;
|
||||
startCellY: number = 0;
|
||||
endCellX: number = 0;
|
||||
endCellY: number = 0;
|
||||
len: number = 0;
|
||||
qryStartTime: number = 0;
|
||||
|
||||
public checkAndUpdateQryTime(): boolean {
|
||||
let nowTime: number = Date.now();
|
||||
if (nowTime - this.qryStartTime >= MapAreaData.MAX_TIME) {
|
||||
this.qryStartTime = nowTime;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public equals(other: MapAreaData): boolean {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
return this.id == other.id;
|
||||
}
|
||||
|
||||
public fuzzyEquals(other: MapAreaData, variance: number): boolean {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.x - variance <= other.x && other.x <= this.x + variance) {
|
||||
if (this.y - variance <= other.y && other.y <= this.y + variance)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default class MapProxy {
|
||||
public warFree:number = 0; //免战时间
|
||||
public tiledMapAsset: TiledMapAsset = null;
|
||||
//当前地图中心点
|
||||
protected _curCenterPoint: Vec2 = null;
|
||||
//当前展示区域
|
||||
protected _curCenterAreaId: number = -1;
|
||||
protected _mapAreaDatas: MapAreaData[] = [];
|
||||
protected _mapResDatas: MapResData[] = [];
|
||||
protected _mapSysCityResDatas: MapResData[] = [];
|
||||
protected _mapPosTags: MapTagPos[] = [];
|
||||
|
||||
//地图请求列表
|
||||
public qryAreaIds: number[] = [];
|
||||
//地图基础配置数据
|
||||
protected _mapResConfigs: Map<string, MapResConfig> = new Map<string, MapResConfig>();
|
||||
|
||||
// 初始化地图配置
|
||||
public initData(): void {
|
||||
this._mapAreaDatas.length = MapUtil.areaCount;
|
||||
}
|
||||
|
||||
public clearData(): void {
|
||||
this._curCenterPoint = null;
|
||||
this._curCenterAreaId = -1;
|
||||
this._mapAreaDatas.length = 0;
|
||||
this.qryAreaIds.length = 0;
|
||||
}
|
||||
|
||||
/**地图建筑基础配置信息*/
|
||||
public setNationMapConfig(configList: any[]): void {
|
||||
this._mapResConfigs.clear();
|
||||
for (let i: number = 0; i < configList.length; i++) {
|
||||
let cfg: MapResConfig = new MapResConfig();
|
||||
cfg.type = configList[i].type;
|
||||
cfg.level = configList[i].level;
|
||||
cfg.name = configList[i].name;
|
||||
cfg.wood = configList[i].Wood;
|
||||
cfg.iron = configList[i].iron;
|
||||
cfg.stone = configList[i].stone;
|
||||
cfg.grain = configList[i].grain;
|
||||
cfg.durable = configList[i].durable;
|
||||
cfg.defender = configList[i].defender;
|
||||
this._mapResConfigs.set(configList[i].type + "_" + cfg.level, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
public setWarFree(time) {
|
||||
this.warFree = time;
|
||||
}
|
||||
|
||||
public getWarFree(): number{
|
||||
return this.warFree*1000
|
||||
}
|
||||
|
||||
public initMapResConfig(jsonData: any): void {
|
||||
let w: number = jsonData.w;
|
||||
let list: Array<Array<number>> = jsonData.list;
|
||||
this._mapResDatas = [];
|
||||
this._mapSysCityResDatas = [];
|
||||
for (let i: number = 0; i < jsonData.list.length; i++) {
|
||||
let data: MapResData = new MapResData();
|
||||
data.id = i;
|
||||
data.type = list[i][0];
|
||||
data.level = list[i][1];
|
||||
data.x = i % w;
|
||||
data.y = Math.floor(i / w);
|
||||
this._mapResDatas.push(data);
|
||||
|
||||
if(data.type == MapResType.SYS_CITY){
|
||||
this._mapSysCityResDatas.push(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public getSysCityResData(x, y): MapResData{
|
||||
for (let index = 0; index < this._mapSysCityResDatas.length; index++) {
|
||||
|
||||
var resData = this._mapSysCityResDatas[index];
|
||||
var level = resData.level;
|
||||
var dis = 0;
|
||||
if(level >= 8){
|
||||
dis = 3;
|
||||
}else if(level >= 5){
|
||||
dis = 2;
|
||||
}else {
|
||||
dis = 1;
|
||||
}
|
||||
|
||||
if( dis >= Math.abs(x-resData.x) && dis >= Math.abs(y-resData.y)){
|
||||
return resData;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**设置地图当前中心点的信息*/
|
||||
public setCurCenterPoint(point: Vec2, pixelPoint: Vec2): boolean {
|
||||
if (this._curCenterPoint == null
|
||||
|| this._curCenterPoint.x != point.x
|
||||
|| this._curCenterPoint.y != point.y) {
|
||||
this._curCenterPoint = point;
|
||||
let areaPoint: Vec2 = MapUtil.getAreaPointByCellPoint(point.x, point.y);
|
||||
let areaId: number = MapUtil.getIdByAreaPoint(areaPoint.x, areaPoint.y);
|
||||
|
||||
EventMgr.emit("map_center_change", this._curCenterPoint);
|
||||
if (this._curCenterAreaId == -1 || this._curCenterAreaId != areaId) {
|
||||
//展示区域变化
|
||||
let areaData: MapAreaData = this.getMapAreaData(areaId);
|
||||
let oldIds: number[] = null;
|
||||
let newIds: number[] = MapUtil.get9GridVaildAreaIds(areaData.id);
|
||||
let addIds: number[] = [];
|
||||
let removeIds: number[] = [];
|
||||
let firstAreaIds: number[] = null;
|
||||
let otherAreaIds: number[] = [];
|
||||
if (this._curCenterAreaId == -1
|
||||
|| this.getMapAreaData(this._curCenterAreaId).fuzzyEquals(areaData, 3) == false) {
|
||||
//全量刷新
|
||||
oldIds = [];
|
||||
addIds = newIds;
|
||||
//计算四个角所在的区域 用于判断需要优先请求的区域
|
||||
let temp = pixelPoint.clone();
|
||||
let leftTopPixelPoint: Vec2 = temp.add(new Vec2(-view.getVisibleSize().width * 0.5, view.getVisibleSize().height * 0.5));
|
||||
temp = pixelPoint.clone();
|
||||
|
||||
let leftDownPixelPoint: Vec2 = temp.add(new Vec2(-view.getVisibleSize().width * 0.5, -view.getVisibleSize().height * 0.5));
|
||||
temp = pixelPoint.clone();
|
||||
|
||||
let rightTopPixelPoint: Vec2 = temp.add(new Vec2(view.getVisibleSize().width * 0.5, view.getVisibleSize().height * 0.5));
|
||||
temp = pixelPoint.clone();
|
||||
|
||||
let rightDownPixelPoint: Vec2 = temp.add(new Vec2(view.getVisibleSize().width * 0.5, -view.getVisibleSize().height * 0.5));
|
||||
temp = pixelPoint.clone();
|
||||
|
||||
firstAreaIds = MapUtil.getVaildAreaIdsByPixelPoints(temp, leftTopPixelPoint, leftDownPixelPoint, rightTopPixelPoint, rightDownPixelPoint);
|
||||
} else {
|
||||
oldIds = MapUtil.get9GridVaildAreaIds(this._curCenterAreaId);
|
||||
for (let i: number = 0; i < newIds.length; i++) {
|
||||
if (oldIds.indexOf(newIds[i]) == -1) {
|
||||
addIds.push(newIds[i]);
|
||||
}
|
||||
}
|
||||
for (let i: number = 0; i < oldIds.length; i++) {
|
||||
if (newIds.indexOf(oldIds[i]) == -1) {
|
||||
removeIds.push(oldIds[i]);
|
||||
}
|
||||
}
|
||||
//其他情况优先请求中心区域
|
||||
if (addIds.indexOf(areaData.id)) {
|
||||
firstAreaIds = [areaData.id];
|
||||
}
|
||||
}
|
||||
|
||||
if (firstAreaIds && firstAreaIds.length > 0) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
if (firstAreaIds.indexOf(addIds[i]) == -1) {
|
||||
otherAreaIds.push(addIds[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
otherAreaIds = addIds;
|
||||
}
|
||||
|
||||
let qryIndexs: number[] = null;
|
||||
if (firstAreaIds && firstAreaIds.length > 0) {
|
||||
qryIndexs = firstAreaIds.concat(otherAreaIds);
|
||||
} else {
|
||||
qryIndexs = otherAreaIds;
|
||||
}
|
||||
this.qryAreaIds = this.qryAreaIds.concat(qryIndexs);
|
||||
// this.qryAreaIds = [18];
|
||||
|
||||
this._curCenterAreaId = areaId;
|
||||
EventMgr.emit("map_show_area_change", point, this._curCenterAreaId, addIds, removeIds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getCurCenterPoint():Vec2 {
|
||||
return this._curCenterPoint;
|
||||
}
|
||||
|
||||
public getCurCenterAreaId(): number {
|
||||
return this._curCenterAreaId;
|
||||
}
|
||||
|
||||
/**获取地图区域数据*/
|
||||
public getMapAreaData(id: number): MapAreaData {
|
||||
if (this._mapAreaDatas[id] == undefined) {
|
||||
let data: MapAreaData = new MapAreaData();
|
||||
data.id = id;
|
||||
let point: Vec2 = MapUtil.getAreaPointById(id);
|
||||
let startCellPoint: Vec2 = MapUtil.getStartCellPointByAreaPoint(point.x, point.y);
|
||||
data.x = point.x;
|
||||
data.y = point.y;
|
||||
data.startCellX = startCellPoint.x;
|
||||
data.startCellY = startCellPoint.y;
|
||||
data.endCellX = startCellPoint.x + MapUtil.areaCellSize.width;
|
||||
data.endCellY = startCellPoint.y + MapUtil.areaCellSize.width;
|
||||
data.len = MapUtil.areaCellSize.width;
|
||||
this._mapAreaDatas[id] = data;
|
||||
return data;
|
||||
}
|
||||
return this._mapAreaDatas[id];
|
||||
}
|
||||
|
||||
/*获取产量描述**/
|
||||
public getResYieldDesList(cfg: MapResConfig): string[] {
|
||||
let list: string[] = [];
|
||||
if (cfg.grain > 0) {
|
||||
list.push("粮食 +" + cfg.grain + "/小时");
|
||||
}
|
||||
if (cfg.wood > 0) {
|
||||
list.push("木材 +" + cfg.wood + "/小时");
|
||||
}
|
||||
if (cfg.iron > 0) {
|
||||
list.push("铁矿 +" + cfg.iron + "/小时");
|
||||
}
|
||||
if (cfg.stone > 0) {
|
||||
list.push("石料 +" + cfg.stone + "/小时");
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public getResData(id: number): MapResData {
|
||||
return this._mapResDatas[id];
|
||||
}
|
||||
|
||||
/**根据类型获取配置数据*/
|
||||
public getResConfig(type: number, level: number): MapResConfig {
|
||||
let key: string = type + "_" + level;
|
||||
if (this._mapResConfigs.has(key)) {
|
||||
return this._mapResConfigs.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public hasResDatas(): boolean {
|
||||
return this._mapResDatas.length > 0;
|
||||
}
|
||||
|
||||
public hasResConfig(): boolean {
|
||||
return this._mapResConfigs.size > 0;
|
||||
}
|
||||
|
||||
public updateMapPosTags(posTag: any) {
|
||||
this._mapPosTags = [];
|
||||
posTag.forEach(data => {
|
||||
var tag = new MapTagPos();
|
||||
tag.x = data.x;
|
||||
tag.y = data.y;
|
||||
tag.name = data.name;
|
||||
|
||||
this._mapPosTags.push(tag);
|
||||
});
|
||||
}
|
||||
|
||||
public removeMapPosTag(x: number, y:number) {
|
||||
var tags: MapTagPos[] = [];
|
||||
this._mapPosTags.forEach(tag => {
|
||||
if(tag.x != x || y != tag.y){
|
||||
tags.push(tag);
|
||||
}
|
||||
});
|
||||
|
||||
this._mapPosTags = tags;
|
||||
}
|
||||
|
||||
public addMapPosTag(x: number, y:number, name:string) {
|
||||
var tag = new MapTagPos();
|
||||
tag.x = x;
|
||||
tag.y = y;
|
||||
tag.name = name;
|
||||
|
||||
var ok = true;
|
||||
this._mapPosTags.forEach(tag => {
|
||||
if (tag.x == x && tag.y == y){
|
||||
ok = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (ok){
|
||||
this._mapPosTags.push(tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public isPosTag(x: number, y:number):boolean {
|
||||
var ret = false;
|
||||
for (let index = 0; index < this._mapPosTags.length; index++) {
|
||||
const tag = this._mapPosTags[index];
|
||||
if (tag.x == x && tag.y == y){
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public getPosTags() :MapTagPos[]{
|
||||
return this._mapPosTags;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapProxy.ts.meta
Normal file
11
assets/scripts/map/MapProxy.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b9c230e5-ddad-419a-8a5a-d48e5a680942",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
58
assets/scripts/map/MapResBuildLogic.ts
Normal file
58
assets/scripts/map/MapResBuildLogic.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import ResBuildLogic from "./entries/ResBuildLogic";
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapResBuildLogic')
|
||||
export default class MapResBuildLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
EventMgr.on("update_builds", this.onUpdateBuilds, this);
|
||||
EventMgr.on("update_build", this.onUpdateBuild, this);
|
||||
EventMgr.on("delete_build", this.onDeleteBuild, this);
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected onUpdateBuilds(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
|
||||
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
this.addItem(areaIndex, this._cmd.buildProxy.getBuild(addIds[i]));
|
||||
}
|
||||
for (let i: number = 0; i < removeIds.length; i++) {
|
||||
this.removeItem(areaIndex, removeIds[i]);
|
||||
}
|
||||
for (let i: number = 0; i < updateIds.length; i++) {
|
||||
this.updateItem(areaIndex, this._cmd.buildProxy.getBuild(updateIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateBuild(data: MapBuildData): void {
|
||||
// console.log("update_build", data);
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(data.x, data.y);
|
||||
this.addItem(areaIndex, data);
|
||||
}
|
||||
|
||||
protected onDeleteBuild(id: number, x: number, y: number): void {
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(x, y);
|
||||
this.removeItem(areaIndex, id);
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let buildData: MapBuildData = data as MapBuildData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(buildData.x, buildData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(ResBuildLogic).setBuildData(buildData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapResBuildLogic.ts.meta
Normal file
11
assets/scripts/map/MapResBuildLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ac52a5ec-46c9-4a6b-a4e4-ae8df0367c7c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
26
assets/scripts/map/MapResLogic.ts
Normal file
26
assets/scripts/map/MapResLogic.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import ResLogic from "./entries/ResLogic";
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import { MapResData } from "./MapProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
|
||||
@ccclass('MapResLogic')
|
||||
export default class MapResLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let resData: MapResData = data as MapResData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(resData.x, resData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(ResLogic).setResourceData(resData);
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapResLogic.ts.meta
Normal file
11
assets/scripts/map/MapResLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2aed42a4-4916-4d4c-8df5-c04f6e75890a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
63
assets/scripts/map/MapSysCityLogic.ts
Normal file
63
assets/scripts/map/MapSysCityLogic.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { _decorator, Node, Vec2, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import MapBaseLayerLogic from "./MapBaseLayerLogic";
|
||||
import MapUtil from "./MapUtil";
|
||||
import SysCityLogic from "./entries/SysCityLogic";
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapSysCityLogic')
|
||||
export default class MapSysCityLogic extends MapBaseLayerLogic {
|
||||
|
||||
protected onLoad(): void {
|
||||
super.onLoad();
|
||||
EventMgr.on("update_builds", this.onUpdateBuilds, this);
|
||||
EventMgr.on("update_build", this.onUpdateBuild, this);
|
||||
EventMgr.on("delete_build", this.onDeleteBuild, this);
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected onUpdateBuilds(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
|
||||
|
||||
if (this._itemMap.has(areaIndex)) {
|
||||
for (let i: number = 0; i < addIds.length; i++) {
|
||||
this.addItem(areaIndex, this._cmd.buildProxy.getBuild(addIds[i]));
|
||||
}
|
||||
for (let i: number = 0; i < removeIds.length; i++) {
|
||||
this.removeItem(areaIndex, removeIds[i]);
|
||||
}
|
||||
for (let i: number = 0; i < updateIds.length; i++) {
|
||||
this.updateItem(areaIndex, this._cmd.buildProxy.getBuild(updateIds[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onUpdateBuild(data: MapBuildData): void {
|
||||
// console.log("update_build", data);
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(data.x, data.y);
|
||||
this.addItem(areaIndex, data);
|
||||
}
|
||||
|
||||
protected onDeleteBuild(id: number, x: number, y: number): void {
|
||||
console.log("onDeleteBuild");
|
||||
let areaIndex: number = MapUtil.getAreaIdByCellPoint(x, y);
|
||||
this.removeItem(areaIndex, id);
|
||||
}
|
||||
|
||||
public setItemData(item: Node, data: any): void {
|
||||
let cityData: MapBuildData = data as MapBuildData;
|
||||
let position: Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(cityData.x, cityData.y));
|
||||
item.setPosition(new Vec3(position.x, position.y, 0));
|
||||
item.getComponent(SysCityLogic).setCityData(cityData);
|
||||
}
|
||||
|
||||
public getIdByData(data: any): number {
|
||||
return (data as MapBuildData).id;
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/MapSysCityLogic.ts.meta
Normal file
11
assets/scripts/map/MapSysCityLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1d2f048c-9ecd-44d9-ae0c-02c27c3446c0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
105
assets/scripts/map/MapTouchLogic.ts
Normal file
105
assets/scripts/map/MapTouchLogic.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { _decorator, Component, Prefab, Node, Vec2, instantiate, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
import { MapBuildData } from "./MapBuildProxy";
|
||||
import { MapCityData } from "./MapCityProxy";
|
||||
import MapClickUILogic from "./MapClickUILogic";
|
||||
import MapCommand from "./MapCommand";
|
||||
import { MapResData } from "./MapProxy";
|
||||
import MapUtil from "./MapUtil";
|
||||
import { EventMgr } from '../utils/EventMgr';
|
||||
|
||||
@ccclass('MapTouchLogic')
|
||||
export default class MapTouchLogic extends Component {
|
||||
@property(Prefab)
|
||||
clickUIPrefab: Prefab = null;
|
||||
|
||||
@property(Node)
|
||||
touch:Node = null;
|
||||
|
||||
protected _cmd: MapCommand;
|
||||
protected _clickUINode: Node = null;
|
||||
|
||||
protected onLoad(): void {
|
||||
this._cmd = MapCommand.getInstance();
|
||||
EventMgr.on("touch_map", this.onTouchMap, this);
|
||||
EventMgr.on("move_map", this.onMoveMap, this);
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
EventMgr.targetOff(this);
|
||||
this._cmd = null;
|
||||
this._clickUINode = null;
|
||||
}
|
||||
|
||||
protected onTouchMap(mapPoint: Vec2, clickPixelPoint: Vec2): void {
|
||||
console.log("点击区域 (" + mapPoint.x + "," + mapPoint.y + ")");
|
||||
this.removeClickUINode();
|
||||
if (MapUtil.isVaildCellPoint(mapPoint) == false) {
|
||||
console.log("点击到无效区域");
|
||||
return;
|
||||
}
|
||||
|
||||
let cellId: number = MapUtil.getIdByCellPoint(mapPoint.x, mapPoint.y);
|
||||
let cityData: MapCityData = this._cmd.cityProxy.getCity(cellId);;
|
||||
if (cityData != null) {
|
||||
//代表点击的是城市
|
||||
clickPixelPoint = MapUtil.mapCellToPixelPoint(new Vec2(cityData.x, cityData.y));
|
||||
this.showClickUINode(cityData, clickPixelPoint);
|
||||
return;
|
||||
}
|
||||
|
||||
let buildData: MapBuildData = this._cmd.buildProxy.getBuild(cellId);
|
||||
if (buildData != null) {
|
||||
if(buildData.isSysCity() == false){
|
||||
//代表点击被占领的区域
|
||||
console.log("点击被占领的区域", buildData);
|
||||
this.showClickUINode(buildData, clickPixelPoint);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let resData: MapResData = this._cmd.proxy.getResData(cellId);
|
||||
if (resData.type > 0) {
|
||||
var temp = MapCommand.getInstance().proxy.getSysCityResData(resData.x, resData.y);
|
||||
if (temp){
|
||||
clickPixelPoint = MapUtil.mapCellToPixelPoint(new Vec2(temp.x, temp.y));
|
||||
let cellId: number = MapUtil.getIdByCellPoint(temp.x, temp.y);
|
||||
let buildData: MapBuildData = this._cmd.buildProxy.getBuild(cellId);
|
||||
if(buildData){
|
||||
this.showClickUINode(buildData, clickPixelPoint);
|
||||
}else{
|
||||
this.showClickUINode(temp, clickPixelPoint);
|
||||
}
|
||||
console.log("点击野外城池", temp);
|
||||
}else{
|
||||
this.showClickUINode(resData, clickPixelPoint);
|
||||
console.log("点击野外区域", resData);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("点击山脉河流区域");
|
||||
}
|
||||
}
|
||||
|
||||
protected onMoveMap(): void {
|
||||
this.removeClickUINode();
|
||||
}
|
||||
|
||||
public showClickUINode(data: any, pos: Vec2): void {
|
||||
if (this._clickUINode == null) {
|
||||
this._clickUINode = instantiate(this.clickUIPrefab);
|
||||
|
||||
}
|
||||
this._clickUINode.parent = this.touch;
|
||||
this._clickUINode.setPosition(new Vec3(pos.x, pos.y, 0));
|
||||
this._clickUINode.getComponent(MapClickUILogic).setCellData(data, pos);
|
||||
}
|
||||
|
||||
public removeClickUINode(): void {
|
||||
if (this._clickUINode) {
|
||||
this._clickUINode.parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user