first commit

This commit is contained in:
ytc1012
2025-11-18 18:38:53 +08:00
commit bea9db4488
1582 changed files with 335346 additions and 0 deletions

View 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);
}
}
});
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f81f0497-999d-4b1b-97c0-3d4bced3a7d3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6875a9ab-6b4b-4d61-a5bc-e6d29240ba72",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "30f95def-adfa-4692-ae01-1428da4c294a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3419de09-e445-4de4-8f58-daae4bf77dcd",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8f3bc2f4-27f3-4218-b0d1-05bd5462d1f1",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "517a6f06-32e1-478f-8835-7ae847be86c4",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "617d703b-ad2a-4935-861e-4a1619550f5d",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "f2deb972-ceab-454c-998d-c0c07434d621",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0257052c-05b8-4090-abff-1f27ea2c95b1",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5c7b5dbd-6117-4f72-b4a7-b8048284edb7",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
})
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "066de832-f6af-4230-b05a-a413e2a0f985",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b9c230e5-ddad-419a-8a5a-d48e5a680942",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ac52a5ec-46c9-4a6b-a4e4-ae8df0367c7c",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2aed42a4-4916-4d4c-8df5-c04f6e75890a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1d2f048c-9ecd-44d9-ae0c-02c27c3446c0",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c63372be-5493-4648-bdfb-67e9db707f3a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,297 @@
import { _decorator, Size, Vec2, size, v2, TiledMap, UITransform, game, view } from 'cc';
import MapCommand from "./MapCommand";
export default class MapUtil {
//地图像素大小
protected static _mapPixelSize: Size = null;
//地图锚点偏移量
protected static _mapOffsetPoint: Vec2 = null;
//格子大小
protected static _tileSize: Size = size(256, 128);;
//地图大小 宽高需要相同
protected static _mapSize: Size = size(20, 20);
//地图 (0, 0)点对应的像素坐标
protected static _zeroPixelPoint: Vec2 = v2(0, 0);
//划分区域的格子大小
protected static _areaCellSize: Size = null;
protected static _areaSize: Size = null;
// 初始化地图配置
public static initMapConfig(map: TiledMap): void {
var uit = map.node.getComponent(UITransform);
this._mapPixelSize = size(uit.width, uit.height);
this._mapOffsetPoint = v2(uit.width * uit.anchorX, uit.height * uit.anchorY);
this._tileSize = map.getTileSize();
this._mapSize = map.getMapSize();
this._mapPixelSize = size(uit.width, uit.height);
this._zeroPixelPoint.x = this._mapSize.width * this._tileSize.width * 0.5;
this._zeroPixelPoint.y = this._mapSize.height * this._tileSize.height - this._tileSize.height * 0.5;
var vsize = view.getVisibleSize();
//划分区域的大小
let showH: number = Math.min(Math.ceil(vsize.height / this._tileSize.height / 2) * 2 + 2, this._mapSize.height);
this._areaCellSize = size(showH, showH);
this._areaSize = size(Math.ceil(this._mapSize.width / showH), Math.ceil(this._mapSize.height / showH));
}
/**地图的像素大小*/
public static get mapPixcelSize(): Size {
return this._mapPixelSize;
}
public static get mapSize(): Size {
return this._mapSize;
}
/**格子数量*/
public static get mapCellCount(): number {
return this._mapSize.width * this._mapSize.height;
}
/**每个区域包含的格子数量*/
public static get areaCellSize(): Size {
return this._areaCellSize;
}
/**区域大小*/
public static get areaSize(): Size {
return this._areaSize;
}
/**区域数量*/
public static get areaCount(): number {
return this._areaSize.width * this._areaSize.height;
}
/**获取格子id*/
public static getIdByCellPoint(x: number, y: number): number {
return x + y * this._mapSize.width;
}
/**获取格子坐标*/
public static getCellPointById(id: number): Vec2 {
return v2(id % this._mapSize.width, Math.floor(id / this._mapSize.width));
}
/**获取区域id*/
public static getIdByAreaPoint(x: number, y: number): number {
return x + y * this._areaSize.width;
}
/**获取区域坐标*/
public static getAreaPointById(id: number): Vec2 {
return v2(id % this._areaSize.width, Math.floor(id / this._areaSize.width));
}
/**获取格子为中点的九宫格id列表*/
public static get9GridCellIds(id:number):number[] {
return [
id + this._mapSize.width - 1, id + this._mapSize.width, id + this._mapSize.width + 1,
id - 1, id, id + 1,
id - this._mapSize.width - 1, id - this._mapSize.width, id - this._mapSize.width + 1
];
}
public static getSideIdsForRoleCity(id:number):number[] {
return [
id + this._mapSize.width * 2 - 2, id + this._mapSize.width * 2 - 1, id + this._mapSize.width * 2, id + this._mapSize.width * 2 + 1, id + this._mapSize.width * 2 + 2,
id + this._mapSize.width - 2, id + this._mapSize.width + 2,
id - 2, id + 2,
id - this._mapSize.width - 2, id - this._mapSize.width + 2,
id - this._mapSize.width * 2 - 2, id - this._mapSize.width * 2 - 1, id - this._mapSize.width - 1, id - this._mapSize.width * 2 + 1, id - this._mapSize.width * 2 + 2
];
}
public static getSideIdsForSysCity(x, y, level): number[] {
let ids: number[] = [];
var dis = 0;
if(level >= 8){
dis = 3;
}else if(level >= 5){
dis = 2;
}else {
dis = 1;
}
//上
for (let tx = x-dis; tx <= x+dis; tx++) {
var ty:number = y + dis;
var id = MapUtil.getIdByCellPoint(tx, ty);
ids.push(id);
}
//下
for (let tx = x-dis; tx <= x+dis; tx++) {
var ty:number = y - dis;
var id = MapUtil.getIdByCellPoint(tx, ty);
ids.push(id);
}
//左
for (let ty = y-dis; ty <= y+dis; ty++) {
var tx:number = x - dis;
var id = MapUtil.getIdByCellPoint(tx, ty);
ids.push(id);
}
//右
for (let ty = y-dis; ty <= y+dis; ty++) {
var tx:number = x + dis;
var id = MapUtil.getIdByCellPoint(tx, ty);
ids.push(id);
}
return ids;
}
/**获取区域为中点的九宫格id列表*/
public static get9GridAreaIds(id: number): number[] {
return [
id + this._areaSize.width - 1, id + this._areaSize.width, id + this._areaSize.width + 1,
id - 1, id, id + 1,
id - this._areaSize.width - 1, id - this._areaSize.width, id - this._areaSize.width + 1
];
}
public static get9GridVaildAreaIds(id: number): number[] {
let list: number[] = [];
let totalList: number[] = this.get9GridAreaIds(id);
for (let i: number = 0; i < totalList.length; i++) {
if (this.isVaildAreaId(totalList[i])) {
list.push(totalList[i]);
}
}
return list;
}
public static getAreaPointByCellPoint(x: number, y: number): Vec2 {
return v2(Math.floor(x / this._areaCellSize.width), Math.floor(y / this._areaCellSize.height));
}
/**获取区域id*/
public static getAreaIdByCellPoint(x: number, y: number): number {
let point: Vec2 = this.getAreaPointByCellPoint(x, y);
return this.getIdByAreaPoint(point.x, point.y);
}
public static getStartCellPointByAreaPoint(x: number, y: number): Vec2 {
return v2(x * this._areaCellSize.width, y * this._areaCellSize.height);
}
public static getEndCellPointByAreaPoint(x: number, y: number): Vec2 {
return v2((x + 1) * this._areaCellSize.width, (y + 1) * this._areaCellSize.height);
}
public static getVaildAreaIdsByPixelPoints(...points: Vec2[]): number[] {
let list: number[] = [];
for (let i: number = 0; i < points.length; i++) {
let cellPoint: Vec2 = this.mapPixelToCellPoint(points[i]);
let areaPoint: Vec2 = this.getAreaPointByCellPoint(cellPoint.x, cellPoint.y);
let index: number = this.getIdByAreaPoint(areaPoint.x, areaPoint.y);
if (this.isVaildAreaId(index)
&& list.indexOf(index) == -1) {
list.push(index);
}
}
return list;
}
//是否是有效的格子
public static isVaildCellPoint(point: Vec2): boolean {
if (point.x >= 0 && point.x < this._mapSize.width
&& point.y >= 0 && point.y < this._mapSize.height) {
return true;
}
return false;
}
//是否是有效的格子
public static isVaildAreaPoint(point: Vec2): boolean {
if (point.x >= 0 && point.x < this._areaSize.width
&& point.y >= 0 && point.y < this._areaSize.height) {
return true;
}
return false;
}
public static isVaildAreaId(id: number) {
if (id >= 0 && id < this.areaCount) {
return true;
}
return false;
}
// 世界像素坐标转地图坐标
public static worldPixelToMapCellPoint(point: Vec2): Vec2 {
// 转换原理
// tiledMap 45度地图是已上方为(0,0)点 以左上方边界为y轴 右上方边界为x轴的坐标系
// 所以只需要将点击坐标点的平行映射到地图坐标系的边界上 求解出映射点的像素坐标 / 格子大小 即可计算出对饮的 格子坐标
let x: number = Math.floor(0.5 * this._mapSize.height + point.x / this._tileSize.width - point.y / this._tileSize.height);
let y: number = Math.floor(1.5 * this._mapSize.width - point.x / this._tileSize.width - point.y / this._tileSize.height);
return v2(x, y);
}
//地图坐标(格子的中心点)转世界像素坐标
public static mapCellToWorldPixelPoint(point: Vec2): Vec2 {
let pixelX: number = this._zeroPixelPoint.x - (point.y - point.x) * this._tileSize.width * 0.5;
let pixelY: number = this._zeroPixelPoint.y - (point.x + point.y) * this._tileSize.height * 0.5;
return v2(pixelX, pixelY);
}
// 地图坐标转地图像素坐标
public static mapCellToPixelPoint(point: Vec2): Vec2 {
let worldPoint: Vec2 = this.mapCellToWorldPixelPoint(point);
return worldPoint.subtract(this._mapOffsetPoint);
}
//地图像素转地图坐标
public static mapPixelToCellPoint(point: Vec2): Vec2 {
let temp = point.clone();
let worldPoint: Vec2 = temp.add(this._mapOffsetPoint);
return this.worldPixelToMapCellPoint(worldPoint);
}
public static armyIsInView(x:number, y:number): boolean {
let buildProxy = MapCommand.getInstance().buildProxy;
let cityProxy = MapCommand.getInstance().cityProxy;
let myId = cityProxy.getMyPlayerId();
let myUnionId = cityProxy.myUnionId;
// let parentId = cityProxy.myParentId;
//可视觉区域以当前为原点半径为5
for (let i = Math.max(0, x-5); i<= Math.min(x+5, this._mapSize.width); i++) {
for (let j = Math.max(0, y-5); j<= Math.min(y+5, this._mapSize.height); j++) {
let id: number = MapUtil.getIdByCellPoint(i, j);
var b = buildProxy.getBuild(id);
if (!b){
continue
}
if(b.rid == myId || (myUnionId != 0 && (b.unionId == myUnionId || b.parentId == myUnionId))){
return true;
}
var c = cityProxy.getCity(id)
if (!c){
continue
}
if(c.rid == myId || (myUnionId != 0 && (b.unionId == myUnionId || b.parentId == myUnionId))){
return true;
}
}
}
return false
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8439e997-79fc-4ac1-b669-c6f099642719",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "86a6fe9b-9a4d-4360-801a-4f37894aa3ac",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,123 @@
import { ArmyData } from "../../general/ArmyProxy";
import DateUtil from "../../utils/DateUtil";
import MapUtil from "../MapUtil";
import { Vec2, Node, Animation, Vec3, UITransform } from "cc";
export default class ArmyLogic {
public data: ArmyData = null;
public aniNode: Node = null;
public arrowNode: Node = null;
protected _parentLayer: Node;
protected _aniName: string = "";
protected _startPixelPos: Vec3 = new Vec3(0, 0, 0);
protected _endPixelPos: Vec3 = new Vec3(0, 0, 0);
protected _lenX: number = 0;
protected _lenY: number = 0;
public clear() {
this.data = null;
this.aniNode = null;
this.arrowNode = null;
this._parentLayer = null;
}
public destroy(): void {
this.aniNode.parent = null;
this.arrowNode.parent = null;
this.clear();
}
public update(): Vec2 {
if (this.data && this.data.state > 0) {
let nowTime: number = DateUtil.getServerTime();
if (nowTime < this.data.endTime) {
//代表移动中
let percent: number = Math.max(0, (nowTime - this.data.startTime) / (this.data.endTime - this.data.startTime));
let pos = this.aniNode.position.clone();
pos.x = this._startPixelPos.x + percent * this._lenX;
pos.y = this._startPixelPos.y + percent * this._lenY;
this.aniNode.setPosition(pos);
let cellPoint: Vec2 = MapUtil.mapPixelToCellPoint(new Vec2(pos.x, pos.y));
this.data.x = cellPoint.x;
this.data.y = cellPoint.y;
} else {
this.aniNode.setPosition(this._endPixelPos);
this.data.x = this.data.toX;
this.data.y = this.data.toY;
}
this.updateArrow();
return new Vec2(this.data.x, this.data.y);
}
return null;
}
protected updateArrow(): void {
this.arrowNode.active = this.data && this.data.state > 0;
if (this.arrowNode.active == true) {
this.arrowNode.setPosition(this.aniNode.getPosition());
let len: number = Math.sqrt(
Math.abs((this._endPixelPos.y - this.arrowNode.position.y) * (this._endPixelPos.y - this.arrowNode.position.y))
+ Math.abs((this._endPixelPos.x - this.arrowNode.position.x) * (this._endPixelPos.x - this.arrowNode.position.x)));
let angle: number = Math.atan2(this._endPixelPos.y - this.arrowNode.position.y, this._endPixelPos.x - this.arrowNode.position.x);
this.arrowNode.angle = angle * 180 / Math.PI + 90;
this.arrowNode.getComponent(UITransform).height = len;
}
}
public setArmyData(data: ArmyData, aniNode: Node, arrowNode: Node): void {
this.data = data;
this.aniNode = aniNode;
this.arrowNode = arrowNode;
let startPos:Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(this.data.fromX, this.data.fromY));
this._startPixelPos.x = startPos.x;
this._startPixelPos.y = startPos.y;
let endPos:Vec2 = MapUtil.mapCellToPixelPoint(new Vec2(this.data.toX, this.data.toY));
this._endPixelPos.x = endPos.x;
this._endPixelPos.y = endPos.y;
this._lenX = this._endPixelPos.x - this._startPixelPos.x;
this._lenY = this._endPixelPos.y - this._startPixelPos.y;
let pos = MapUtil.mapCellToPixelPoint(new Vec2(this.data.x, this.data.y));
this.aniNode.setPosition(new Vec3(pos.x, pos.y, 0));
this._aniName = "qb_run_r";
if (this._startPixelPos.y == this._endPixelPos.y) {
//平行
if (this._startPixelPos.x < this._endPixelPos.x) {
this._aniName = "qb_run_r";
} else {
this._aniName = "qb_run_l";
}
} else if (this._startPixelPos.y < this._endPixelPos.y) {
//往上走
if (this._startPixelPos.x < this._endPixelPos.x) {
this._aniName = "qb_run_ru";
} else if (this._startPixelPos.x == this._endPixelPos.x) {
this._aniName = "qb_run_u";
} else {
this._aniName = "qb_run_lu";
}
} else if (this._startPixelPos.y > this._endPixelPos.y) {
//往下走
if (this._startPixelPos.x < this._endPixelPos.x) {
this._aniName = "qb_run_rd";
} else if (this._startPixelPos.x == this._endPixelPos.x) {
this._aniName = "qb_run_d";
} else {
this._aniName = "qb_run_ld";
}
}
this.aniNode.getComponent(Animation).play(this._aniName);
this.updateArrow();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3903486e-b092-48bf-8a8f-ee81d0c4a383",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,44 @@
import { _decorator, Component, Node } from 'cc';
import MapCommand from "../MapCommand";
import { MapResData } from "../MapProxy";
import { EventMgr } from '../../utils/EventMgr';
const { ccclass, property } = _decorator;
@ccclass('BuildTagLogic')
export default class BuildTagLogic extends Component {
protected _data: MapResData = null;
@property(Node)
tagIconNode: Node = null;
protected onLoad(): void {
this.tagIconNode.active = false;
}
protected onEnable(): void {
EventMgr.on("update_tag", this.onUpdateTag, this);
}
protected onDisable(): void {
this._data = null;
EventMgr.targetOff(this);
}
public setResourceData(data: MapResData): void {
this._data = data;
this.updateUI();
}
public updateUI(): void {
if (this._data) {
this.tagIconNode.active = MapCommand.getInstance().proxy.isPosTag(this._data.x, this._data.y);
}
}
protected onUpdateTag() {
this.updateUI();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9679b472-99f4-42e2-b6f0-081d5591e1b3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,80 @@
import { _decorator, Component, Sprite, Node, Label } from 'cc';
const { ccclass, property } = _decorator;
import DateUtil from "../../utils/DateUtil";
import { MapBuildData } from "../MapBuildProxy";
import MapCommand from "../MapCommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('BuildTipsLogic')
export default class BuildTipsLogic extends Component {
@property(Sprite)
warFreeSprite: Sprite | null = null;
protected _data: MapBuildData = null;
protected _warFreeTime: number = 0;
@property(Node)
giveUpNode: Node | null = null;
@property(Label)
giveUpLabTime: Label | null = null;
protected onLoad(): void {
}
protected onEnable(): void {
this.giveUpNode.active = false;
this._warFreeTime = MapCommand.getInstance().proxy.getWarFree();
}
protected onDisable(): void {
this._data = null;
this.unscheduleAllCallbacks();
EventMgr.targetOff(this);
}
public setBuildData(data: MapBuildData): void {
this._data = data;
this.updateUI();
}
public updateUI(): void {
if (this._data) {
var diff = DateUtil.getServerTime() - this._data.occupyTime;
var isShow = diff<this._warFreeTime && this._data.rid > 0;
this.warFreeSprite.node.active = isShow;
if (isShow){
this.stopWarFree();
this.schedule(this.countDownWarFree, 1.0);
this.countDownWarFree();
}
if(this._data.rid == MapCommand.getInstance().cityProxy.myId){
this.startGiveUp();
}
}
}
public countDownWarFree() {
var diff = DateUtil.getServerTime() - this._data.occupyTime;
if (diff>this._warFreeTime){
this.stopWarFree();
this.warFreeSprite.node.active = false;
}
}
public stopWarFree() {
this.unschedule(this.countDownWarFree);
}
protected startGiveUp(){
this.stopGiveUp();
this.schedule(this.updateGiveUpTime, 1);
this.updateGiveUpTime();
}
protected stopGiveUp(){
this.unschedule(this.updateGiveUpTime);
this.giveUpNode.active = false;
}
protected updateGiveUpTime(){
if (this._data.isInGiveUp() == false){
this.stopGiveUp();
}else{
this.giveUpNode.active = true;
this.giveUpLabTime.string = DateUtil.leftTimeStr(this._data.giveUpTime);
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7ee88d2b-3d10-4f49-8c02-38fbfa9ecf71",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,92 @@
import { _decorator, Component, Label, Sprite, SpriteAtlas, Node } from 'cc';
const { ccclass, property } = _decorator;
import DateUtil from "../../utils/DateUtil";
import { MapCityData } from "../MapCityProxy";
import MapCommand from "../MapCommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CityLogic')
export default class CityLogic extends Component {
@property(Label)
labelName: Label | null = null;
@property(Sprite)
upSpr: Sprite | null = null;
@property(Sprite)
downSpr: Sprite | null = null;
@property(SpriteAtlas)
resourceAtlas: SpriteAtlas | null = null;
@property(Node)
mianNode: Node | null = null;
protected _data: MapCityData = null;
protected _limitTime: number = 0;
protected onLoad(): void {
this._limitTime = MapCommand.getInstance().proxy.getWarFree();
}
protected onDestroy(): void {
}
protected onEnable(): void {
EventMgr.on("unionChange", this.onUnionChange, this);
}
protected onDisable(): void {
this._data = null;
this.unscheduleAllCallbacks();
EventMgr.targetOff(this);
}
protected onUnionChange(rid: number, unionId: number, parentId: number): void {
if (this._data.rid == rid ){
this._data.unionId = unionId;
this._data.parentId = parentId;
}
this.updateUI();
}
public setCityData(data: MapCityData): void {
this._data = data;
console.log("setCityData:", data);
this.updateUI();
}
public updateUI(): void {
if (this._data) {
this.labelName.string = this._data.name;
if (this._data.rid == MapCommand.getInstance().buildProxy.myId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_1_3");
} else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_1_3");
}else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myParentId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_1_3");
} else if (this._data.parentId > 0 && this._data.parentId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_1_3");
}else {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_1_3");
}
var diff = DateUtil.getServerTime() - this._data.occupyTime;
console.log("diff", diff, this._limitTime);
if (this._data.parentId > 0 && diff<this._limitTime){
this.mianNode.active = true;
this.stopCountDown();
this.schedule(this.countDown, 1.0);
}else{
this.mianNode.active = false;
}
}
}
public countDown() {
var diff = DateUtil.getServerTime() - this._data.occupyTime;
if (diff>this._limitTime){
this.stopCountDown();
this.mianNode.active = false;
}
}
public stopCountDown() {
this.unscheduleAllCallbacks();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "44838483-d210-4672-b8de-d984de7e1102",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,95 @@
import { _decorator, Component, Sprite, Label, SpriteAtlas, Vec2 } from 'cc';
const { ccclass, property } = _decorator;
import DateUtil from "../../utils/DateUtil";
import { MapBuildData } from "../MapBuildProxy";
import MapCommand from "../MapCommand";
import { MapAreaData, MapResConfig, MapResData, MapResType } from "../MapProxy";
import MapUtil from "../MapUtil";
@ccclass('FacilityBuildLogic')
export default class FacilityBuildLogic extends Component {
@property(Sprite)
spr: Sprite | null = null;
@property(Label)
nameLab: Label | null = null;
@property(Label)
tipsLab: Label | null = null;
@property(SpriteAtlas)
buildAtlas: SpriteAtlas | null = null;
protected _data: MapBuildData = null;
protected _cmd: MapCommand = null;
protected onLoad(): void {
this._cmd = MapCommand.getInstance();
}
protected onEnable():void {
this.nameLab.string = "";
this.tipsLab.string = "";
this.spr.spriteFrame = null;
}
protected onDisable(): void {
this._data = null;
this.unscheduleAllCallbacks();
}
public setBuildData(data: MapBuildData): void {
this._data = data;
this.updateUI();
}
public updateUI(): void {
if (this._data) {
if (this._data.type == MapResType.FORTRESS){
this.spr.spriteFrame = this.buildAtlas.getSpriteFrame("component_119");
let resData: MapResData = MapCommand.getInstance().proxy.getResData(this._data.id);
let resCfg: MapResConfig = MapCommand.getInstance().proxy.getResConfig(resData.type, resData.level);
if (this._data.nickName != null){
this.nameLab.string = this._data.nickName + ":" + this._data.name;
}else{
this.nameLab.string = resCfg.name;
}
if (this._data.isBuilding() || this._data.isUping() || this._data.isDestroying()){
this.startCountDownTime();
}
else{
this.tipsLab.string = "";
}
}else{
this.spr.spriteFrame = null;
this.nameLab.string = "";
}
}
}
public startCountDownTime(){
console.log("startCountDownTime");
this.stopCountDownTime();
this.schedule(this.countDownTime, 1.0);
this.countDownTime();
}
public countDownTime() {
if (this._data.isBuilding()){
this.tipsLab.string = "建设中..." + DateUtil.leftTimeStr(this._data.endTime);
} else if(this._data.isUping()){
this.tipsLab.string = "升级中..." + DateUtil.leftTimeStr(this._data.endTime);
} else if(this._data.isDestroying()){
this.tipsLab.string = "拆除中..." + DateUtil.leftTimeStr(this._data.endTime);
} else{
this.tipsLab.string = "";
this.stopCountDownTime();
console.log("qryNationMapScanBlock");
let areaPoint: Vec2 = MapUtil.getAreaPointByCellPoint(this._data.x, this._data.y);
let areaId: number = MapUtil.getIdByAreaPoint(areaPoint.x, areaPoint.y);
let areaData: MapAreaData = this._cmd.proxy.getMapAreaData(areaId);
this._cmd.qryNationMapScanBlock(areaData);
}
}
public stopCountDownTime() {
this.unschedule(this.countDownTime);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9f6fce8d-e1e6-4d42-a579-cee53ffcca76",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,67 @@
import { _decorator, Component, Sprite, SpriteAtlas } from 'cc';
const { ccclass, property } = _decorator;
import { MapBuildData } from "../MapBuildProxy";
import MapCommand from "../MapCommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('ResBuildLogic')
export default class ResBuildLogic extends Component {
@property(Sprite)
upSpr: Sprite | null = null;
@property(Sprite)
downSpr: Sprite | null = null;
@property(SpriteAtlas)
resourceAtlas: SpriteAtlas | null = null;
protected _data: MapBuildData = null;
protected onLoad(): void {
}
protected onDestroy(): void {
}
protected onEnable():void {
EventMgr.on("unionChange", this.onUnionChange, this);
}
protected onDisable():void {
this._data = null;
EventMgr.targetOff(this);
}
protected onUnionChange(rid: number, unionId: number, parentId: number): void {
if (this._data.rid == rid ){
this._data.unionId = unionId;
this._data.parentId = parentId;
}
this.updateUI();
}
public setBuildData(data: MapBuildData): void {
this._data = data;
this.updateUI();
}
public updateUI(): void {
if (this._data) {
if(!this._data.rid){
this.upSpr.spriteFrame = null;
this.downSpr.spriteFrame = null;
}else if (this._data.rid == MapCommand.getInstance().buildProxy.myId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_1_3");
} else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_1_3");
}else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myParentId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_1_3");
} else if (this._data.parentId > 0 && this._data.parentId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_1_3");
}else {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_1_3");
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "596a6a3a-e391-40ca-851b-52dbd47a828a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,76 @@
import { _decorator, Component, Sprite, SpriteAtlas } from 'cc';
const { ccclass, property } = _decorator;
import {MapResData, MapResType } from "../MapProxy";
@ccclass('ResLogic')
export default class ResLogic extends Component {
@property(Sprite)
spr: Sprite = null;
@property(SpriteAtlas)
resourceAtlas1: SpriteAtlas = null;
@property(SpriteAtlas)
resourceAtlas2: SpriteAtlas = null;
protected _data: MapResData = null;
protected onLoad(): void {
}
protected onDestroy(): void {
}
public setResourceData(data: MapResData): void {
this._data = data;
if (data.type == MapResType.WOOD) {
//木头
if(data.level == 1){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_1_1");
}else if(data.level == 2){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_2_1");
}else{
this.spr.spriteFrame = this.resourceAtlas2.getSpriteFrame("land_2_" + (data.level-2));
}
} else if (data.type == MapResType.IRON) {
//铁
if(data.level == 1){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_1_1");
}else if(data.level == 2){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_2_1");
}else{
this.spr.spriteFrame = this.resourceAtlas2.getSpriteFrame("land_4_" + (data.level-2));
}
} else if (data.type == MapResType.STONE) {
//石头
if(data.level == 1){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_1_1");
}else if(data.level == 2){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_2_1");
}else{
this.spr.spriteFrame = this.resourceAtlas2.getSpriteFrame("land_2_" + (data.level-2));
}
} else if (data.type == MapResType.GRAIN) {
//田
if(data.level == 1){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_1_1");
}else if(data.level == 2){
this.spr.spriteFrame = this.resourceAtlas1.getSpriteFrame("land_ground_2_1");
}else{
this.spr.spriteFrame = this.resourceAtlas2.getSpriteFrame("land_1_" + (data.level-2));
}
} else if (data.type == MapResType.SYS_FORTRESS) {
//系统要塞
this.spr.spriteFrame = this.resourceAtlas2.getSpriteFrame("sys_fortress");
}else {
this.spr.spriteFrame = null;
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c340e883-5c05-4d66-9020-47b889ab4950",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,115 @@
import { _decorator, Component, Sprite, SpriteAtlas, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import DateUtil from "../../utils/DateUtil";
import MapCommand from "../MapCommand";
import { MapResType } from "../MapProxy";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('SysCityLogic')
export default class SysCityLogic extends Component {
@property(Sprite)
upSpr: Sprite = null;
@property(Sprite)
downSpr: Sprite = null;
@property(SpriteAtlas)
resourceAtlas: SpriteAtlas = null;
@property(Node)
mianNode: Node = null;
protected _limitTime: number = 0;
protected _data: any = null;
protected onLoad(): void {
this._limitTime = MapCommand.getInstance().proxy.getWarFree();
}
protected onEnable(): void {
EventMgr.on("unionChange", this.onUnionChange, this);
}
protected onDisable(): void {
this._data = null;
this.unscheduleAllCallbacks();
EventMgr.targetOff(this);
}
public setCityData(data: any): void {
// console.log("setCityData:", data);
this._data = data;
this.updateUI();
}
protected onUnionChange(rid: number, unionId: number, parentId: number): void {
if (this._data.rid == rid ){
this._data.unionId = unionId;
this._data.parentId = parentId;
}
this.updateUI();
}
public updateUI(): void {
if(this._data.type != MapResType.SYS_CITY){
this.node.active = false;
return
}else{
this.node.active = true;
}
if(this._data.level >= 8){
this.node.scale = new Vec3(1.5, 1.5, 1.5);
}else if(this._data.level >= 5){
this.node.scale = new Vec3(1, 1, 1);
}else {
this.node.scale = new Vec3(0.5, 0.5, 0.5);
}
if(!this._data.rid){
this.upSpr.spriteFrame = null;
this.downSpr.spriteFrame = null;
}else if (this._data.rid == MapCommand.getInstance().buildProxy.myId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("blue_1_3");
} else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("green_1_3");
}else if (this._data.unionId > 0 && this._data.unionId == MapCommand.getInstance().buildProxy.myParentId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("purple_1_3");
} else if (this._data.parentId > 0 && this._data.parentId == MapCommand.getInstance().buildProxy.myUnionId) {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("yellow_1_3");
}else {
this.upSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_2_3");
this.downSpr.spriteFrame = this.resourceAtlas.getSpriteFrame("red_1_3");
}
var diff = DateUtil.getServerTime() - this._data.occupyTime;
console.log("diff", diff, this._limitTime);
if (this._data.parentId > 0 && diff<this._limitTime){
this.mianNode.active = true;
this.stopCountDown();
this.schedule(this.countDown, 1.0);
}else{
this.mianNode.active = false;
}
}
public countDown() {
var diff = DateUtil.getServerTime() - this._data.occupyTime;
if (diff>this._limitTime){
this.stopCountDown();
this.mianNode.active = false;
}
}
public stopCountDown() {
this.unscheduleAllCallbacks();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0eddd58f-a832-4b42-9318-cbda95943e82",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "0b7f2c51-516d-4f98-ab3b-417e484c5096",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,131 @@
import { _decorator, Component, Node, Label, Sprite, ProgressBar } from 'cc';
const { ccclass, property } = _decorator;
import { ArmyCmd, ArmyData } from "../../general/ArmyProxy";
import GeneralCommand from "../../general/GeneralCommand";
import ArmyCommand from "../../general/ArmyCommand";
import { GeneralCommonConfig, GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import GeneralHeadLogic from "./GeneralHeadLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('ArmySelectItemLogic')
export default class ArmySelectItemLogic extends Component {
@property(Node)
tipNode: Node = null;
@property(Label)
labelTip: Label = null;
@property(Sprite)
headIcon: Sprite = null;
@property(Label)
labelLv: Label = null;
@property(Label)
labelName: Label = null;
@property(Label)
labelState: Label = null;
@property(Label)
labelMorale: Label = null;
@property(Label)
labelSoldierCnt: Label = null;
@property(Label)
labelVice1: Label = null;
@property(Label)
labelVice2: Label = null;
@property(ProgressBar)
progressSoldier: ProgressBar = null;
protected _data: ArmyData = null;
protected _cmd: number = 0;
protected _toX: number = 0;
protected _toY: number = 0;
protected onLoad(): void {
EventMgr.on("update_army", this.onUpdateArmy, this);
this.tipNode.active = false;
}
protected onDestroy(): void {
EventMgr.targetOff(this);
this._data = null;
}
protected onUpdateArmy(armyData: ArmyData): void {
if (armyData.id == this._data.id) {
this.setArmyData(armyData, this._cmd, this._toX, this._toY);
}
}
protected onClickItem(): void {
if (this.tipNode.active == false) {
ArmyCommand.getInstance().generalAssignArmy(this._data.id, this._cmd, this._toX, this._toY);
EventMgr.emit("close_army_select_ui");
} else {
console.log("军队忙");
}
}
protected updateItem(): void {
if (this._data && this._data.generals[0] != 0) {
console.log("updateItem", this._data);
let commonCfg: GeneralCommonConfig = GeneralCommand.getInstance().proxy.getCommonCfg();
let generals: GeneralData[] = ArmyCommand.getInstance().getArmyGenerals(this._data);
let firstGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[0].cfgId);
let power: number = ArmyCommand.getInstance().getArmyPhysicalPowerByGenerals(generals);
let curSoldierCnt: number = ArmyCommand.getInstance().getArmyCurSoldierCnt(this._data);
let totalSoldierCnt: number = ArmyCommand.getInstance().getArmyTotalSoldierCntByGenerals(generals);
if (this._data.cmd == ArmyCmd.Conscript) {
//体力不足
this.tipNode.active = true;
this.labelTip.string = "征兵中...";
}else if (power < commonCfg.recovery_physical_power) {
//体力不足
this.tipNode.active = true;
this.labelTip.string = "体力不足";
} else if (this._data.soldiers[0] <= 0) {
//兵力不足
this.tipNode.active = true;
this.labelTip.string = "主将兵力不足";
} else if (this._data.state > 0) {
//行军中
this.tipNode.active = true;
this.labelTip.string = "行军中...";
} else if (this._data.cmd == ArmyCmd.Reclaim) {
//屯田中
this.tipNode.active = true;
this.labelTip.string = "屯田中...";
} else {
this.tipNode.active = false;
}
this.headIcon.getComponent(GeneralHeadLogic).setHeadId(generals[0].cfgId);
this.labelLv.string = generals[0].level + "";
this.labelName.string = firstGeneralCfg.name;
this.labelState.string = ArmyCommand.getInstance().getArmyStateDes(this._data);
this.labelSoldierCnt.string = curSoldierCnt + "/" + totalSoldierCnt;
this.progressSoldier.progress = curSoldierCnt / totalSoldierCnt;
if (generals[1]) {
let sencondGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[1].cfgId);
this.labelVice1.string = sencondGeneralCfg.name;
} else {
this.labelVice1.string = "";
}
if (generals[2]) {
let thirdGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[2].cfgId);
this.labelVice2.string = thirdGeneralCfg.name;
} else {
this.labelVice2.string = "";
}
}
}
public setArmyData(data: ArmyData, cmd: number, x: number, y: number): void {
this._data = data;
this._cmd = cmd;
this._toX = x;
this._toY = y;
// console.log("setArmyData", arguments);
this.updateItem();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6319e0b2-db18-4371-97ff-fda2ca7f92dd",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,42 @@
import { _decorator, Component, Node, Prefab, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import ArmyCommand from "../../general/ArmyCommand";
import { ArmyData } from "../../general/ArmyProxy";
import { MapCityData } from "../MapCityProxy";
import MapCommand from "../MapCommand";
import ArmySelectItemLogic from "./ArmySelectItemLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('ArmySelectNodeLogic')
export default class ArmySelectNodeLogic extends Component {
@property(Node)
armyContainer: Node = null;
@property(Prefab)
itemPrefab: Prefab = null;
protected onLoad(): void {
EventMgr.on("close_army_select_ui", this.onClickBack, this);
}
protected onDestroy(): void {
EventMgr.targetOff(this);
}
protected onClickBack(): void {
this.node.active = false;
}
public setData(cmd: number, x: number, y: number): void {
this.armyContainer.removeAllChildren();
let myCity: MapCityData = MapCommand.getInstance().cityProxy.getMyMainCity();
let armyList: ArmyData[] = ArmyCommand.getInstance().proxy.getArmyList(myCity.cityId);
for (let i: number = 0; i < armyList.length; i++) {
if (armyList[i] && armyList[i].generals[0] > 0) {
let item: Node = instantiate(this.itemPrefab);
item.parent = this.armyContainer;
item.getComponent(ArmySelectItemLogic).setArmyData(armyList[i], cmd, x, y);
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "34c19263-312a-43f7-ace3-113afe0500d6",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,82 @@
import { _decorator, Component, Node, Prefab, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import ArmyCommand from "../../general/ArmyCommand";
import { ArmyData } from "../../general/ArmyProxy";
import { MapCityData } from "../MapCityProxy";
import CityArmyItemLogic from "./CityArmyItemLogic";
import MapUICommand from "./MapUICommand";
import { CityAddition } from "./MapUIProxy";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CityAboutLogic')
export default class CityAboutLogic extends Component {
@property(Node)
armyLayer: Node = null;
@property(Prefab)
armyItem: Prefab = null;
protected _armyCnt: number = 5;//队伍数量 固定值
protected _cityData: MapCityData = null;
protected _armyComps: CityArmyItemLogic[] = [];
protected onEnable(): void {
this.initView();
EventMgr.on("update_city_addition", this.onUpdateCityAdditon, this);
}
protected onDisable(): void {
EventMgr.targetOff(this);
}
protected initView(): void {
for (let i: number = 0; i < this._armyCnt; i++) {
let item = instantiate(this.armyItem);
item.parent = this.armyLayer;
let comp: CityArmyItemLogic = item.getComponent(CityArmyItemLogic);
comp.order = i + 1;
this._armyComps.push(comp);
}
}
protected onUpdateCityAdditon(cityId: number): void {
if (this._cityData.cityId == cityId) {
this.updateArmyList();
}
}
protected updateArmyList(): void {
let additon: CityAddition = MapUICommand.getInstance().proxy.getMyCityAddition(this._cityData.cityId);
let armyList: ArmyData[] = ArmyCommand.getInstance().proxy.getArmyList(this._cityData.cityId);
for (let i: number = 0; i < this._armyComps.length; i++) {
if (i >= additon.armyCnt) {
//未开启
this._armyComps[i].isOpenedArmy(false, false);
} else {
//已开启
this._armyComps[i].isOpenedArmy(true, false);
this._armyComps[i].setArmyData(this._cityData.cityId, armyList[i]);
}
}
}
public setData(data: MapCityData): void {
this._cityData = data;
this.updateArmyList();
MapUICommand.getInstance().qryCityFacilities(this._cityData.cityId);
}
protected onClickFacility(): void {
//设施
EventMgr.emit("open_facility", this._cityData);
}
protected onClickClose(): void {
this.node.active = false;
EventMgr.emit("close_city_about", this._cityData);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "01d02052-cf3e-436a-8c3a-401ab77e916b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,155 @@
import { _decorator, Component, Node, Label, Sprite } from 'cc';
const { ccclass, property } = _decorator;
import { ArmyCmd, ArmyData } from "../../general/ArmyProxy";
import GeneralCommand from "../../general/GeneralCommand";
import ArmyCommand from "../../general/ArmyCommand";
import { GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import MapUICommand from "./MapUICommand";
import GeneralHeadLogic from "./GeneralHeadLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CityArmyItemLogic')
export default class CityArmyItemLogic extends Component {
@property(Node)
infoNode: Node = null;
@property(Node)
maskNode: Node = null;
@property(Node)
tipNode: Node = null;
@property(Label)
labelTip: Label = null;
@property(Sprite)
headIcon: Sprite = null;
@property(Label)
labelId: Label = null;
@property(Label)
labelState: Label = null;
@property(Label)
labelLv: Label = null;
@property(Label)
labelName: Label = null;
@property(Label)
labelArms: Label = null;
@property(Label)
labelSoldierCnt: Label = null;
@property(Label)
labelVice1: Label = null;
@property(Label)
labelVice2: Label = null;
public order: number = 0;
protected _cityId: number = 0;
protected _data: ArmyData = null;
protected _isOpened: boolean = true;
protected _isOut: boolean = true;
protected onLoad(): void {
EventMgr.on("update_army", this.onUpdateArmy, this);
this.tipNode.active = false;
}
protected onDestroy(): void {
EventMgr.targetOff(this);
this._data = null;
}
protected onUpdateArmy(armyData: ArmyData): void {
if (this._data && armyData.id == this._data.id) {
this.setArmyData(this._cityId, armyData);
}
}
protected onClickItem(): void {
if (this.maskNode.active == false) {
if(this._isOut){
if(this._data){
EventMgr.emit("open_army_setting", this._cityId, this._data.order);
}
}else{
EventMgr.emit("open_army_setting", this._cityId, this.order);
}
}
}
protected updateItem(): void {
console.log("cityarmyitem:", this._data);
if(this._isOpened == false){
return
}
if (this._data && this._data.generals[0] != 0) {
//有数据 并且配置了第一个将
this.tipNode.active = false;
this.infoNode.active = true;
let generals: GeneralData[] = ArmyCommand.getInstance().getArmyGenerals(this._data);
let firstGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[0].cfgId);
let curSoldierCnt: number = ArmyCommand.getInstance().getArmyCurSoldierCnt(this._data);
let totalSoldierCnt: number = ArmyCommand.getInstance().getArmyTotalSoldierCntByGenerals(generals);
if (this._data.cmd == ArmyCmd.Reclaim) {
//屯田中
this.labelState.string = "屯田中...";
} else if(this._data.cmd == ArmyCmd.Conscript){
this.labelState.string = "征兵中...";
} else if (this._data.cmd > 0) {
this.labelState.string = "队伍外派中...";
} else {
this.labelState.string = "";
}
this.labelId.string = this.order + "";
this.headIcon.getComponent(GeneralHeadLogic).setHeadId(generals[0].cfgId);
this.labelLv.string = generals[0].level + "";
this.labelName.string = firstGeneralCfg.name;
this.labelSoldierCnt.string = curSoldierCnt + "/" + totalSoldierCnt;
// this.labelArms.string = "";
if (generals[1]) {
let sencondGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[1].cfgId);
this.labelVice1.string = sencondGeneralCfg.name;
} else {
this.labelVice1.string = "无";
}
if (generals[2]) {
let thirdGeneralCfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(generals[2].cfgId);
this.labelVice2.string = thirdGeneralCfg.name;
} else {
this.labelVice2.string = "无";
}
} else {
if(this._isOut){
this.tipNode.active = true;
this.infoNode.active = false;
this.labelTip.string = "暂无队伍";
}else{
this.tipNode.active = true;
this.infoNode.active = false;
this.labelTip.string = "点击编制队伍";
}
}
}
public isOpenedArmy(bool: boolean, isOut: boolean): void {
this._isOpened = bool;
this.infoNode.active = false;
this.maskNode.active = !this._isOpened;
this.tipNode.active = !this._isOpened;
this._isOut = isOut;
if (this._isOpened == false) {
if (this._isOut){
this.labelTip.string = " 等级" + this.order + "开启";
}else{
let desName: string = MapUICommand.getInstance().proxy.getFacilityCfgByType(13).name;
this.labelTip.string = desName + " 等级" + this.order + "开启";
}
}
}
public setArmyData(cityId: number, data: ArmyData): void {
this._cityId = cityId;
this._data = data;
this.updateItem();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ac85ee91-ac2f-46b3-b530-9160e9b5eb3a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,358 @@
import { _decorator, Component, Label, Node, Prefab, EditBox, Slider, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import { ArmyCmd, ArmyData } from "../../general/ArmyProxy";
import GeneralCommand from "../../general/GeneralCommand";
import ArmyCommand from "../../general/ArmyCommand";
import { GeneralCampType, GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import MapUICommand from "./MapUICommand";
import MapCommand from "../MapCommand";
import { MapCityData } from "../MapCityProxy";
import { CityAddition, CityAdditionType, Facility } from "./MapUIProxy";
import CityGeneralItemLogic from "./CityGeneralItemLogic";
import LoginCommand from "../../login/LoginCommand";
import { Conscript } from "../../config/Basci";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CityArmySettingLogic')
export default class CityArmySettingLogic extends Component {
@property(Label)
labelId: Label = null;
@property(Label)
labelCost: Label = null;
@property(Label)
labelSoldierCnt: Label = null;
@property(Label)
labelSpeed: Label = null;
@property(Label)
labelAtkCity: Label = null;
@property(Label)
labelAddition: Label = null;
@property(Label)
labelAdditionTip: Label = null;
@property(Node)
additionTouchNode: Node = null;
@property(Node)
additionTipNode: Node = null;
@property(Label)
labelResCost: Label = null;
@property(Node)
generalLayer: Node = null;
@property(Prefab)
generalPrefab: Prefab = null;
@property([EditBox])
editBoxs: EditBox[] = [];
@property([Slider])
sliders: Slider[] = [];
@property([Node])
tipNodes: Node[] = [];
protected _generalCnt: number = 3;
protected _order: number = 0;
protected _cityId: number = 0;
protected _cityData: MapCityData = null;
protected _isUnlock: boolean = false;
protected _data: ArmyData = null;
protected _addition: CityAddition = null;
protected _gengeralLogics: CityGeneralItemLogic[] = [];
protected _soldiers: number[] = null;
protected _totalSoldiers: number[] = null;
protected _curConscripts: number[] = null;//当前征兵数
protected _conTimes: number[] = null;
protected _conCnts: number[] = null;
protected onLoad(): void {
this.initView();
this.additionTipNode.active = false;
this.additionTouchNode.on(Node.EventType.TOUCH_START, this.onShowAdditionTip, this);
this.additionTouchNode.on(Node.EventType.TOUCH_END, this.onHideAdditionTip, this);
this.additionTouchNode.on(Node.EventType.TOUCH_CANCEL, this.onHideAdditionTip, this);
}
protected onDestroy(): void {
this._gengeralLogics.length = 0;
}
protected onEnable(): void {
this._soldiers = [0, 0, 0];
this._totalSoldiers = [0, 0, 0];
this._curConscripts = [0, 0, 0];
this._conTimes = [0, 0, 0];
this._conCnts = [0, 0, 0];
EventMgr.on("update_army", this.onUpdateArmy, this);
EventMgr.on("chosed_general", this.onChooseGeneral, this);
EventMgr.on("update_city_addition", this.onUpdateAddition, this);
}
protected onDisable(): void {
EventMgr.targetOff(this);
this._data = null;
this._addition = null;
this._cityData = null;
}
protected initView(): void {
for (let i: number = 0; i < this._generalCnt; i++) {
let item: Node = instantiate(this.generalPrefab);
item.parent = this.generalLayer;
let comp: CityGeneralItemLogic = item.getComponent(CityGeneralItemLogic);
comp.index = i;
this._gengeralLogics.push(comp);
}
}
protected onShowAdditionTip(): void {
if (this._data && this.labelAddition.string != "无") {
this.additionTipNode.active = true;
}
}
protected onHideAdditionTip(): void {
this.additionTipNode.active = false;
}
protected clearSoldiers(): void {
for (let i: number = 0; i < this._generalCnt; i++) {
this._soldiers[i] = 0;
this._totalSoldiers[i] = 0;
}
}
protected onUpdateArmy(armyData: ArmyData): void {
if (armyData.cityId == this._cityId && armyData.order == this._order) {
this.setData(this._cityId, this._order);
}
}
protected onUpdateAddition(cityId: number): void {
if (this._cityId == cityId) {
this.setData(this._cityId, this._order);
}
}
protected onChooseGeneral(cfgData: any, curData: any, position: any): void {
ArmyCommand.getInstance().generalDispose(this._cityData.cityId, curData.id, this._order, Number(position), this._cityData);
}
protected updateView(): void {
let comp: CityGeneralItemLogic = null;
let generalData: GeneralData = null;
let generalCfg: GeneralConfig = null;
let isUnlock: boolean = false;
let totalCost: number = 0;
let soldierCnt: number = 0;
let totalSoldierCnt: number = 0;
this.clearSoldiers();
if (this._isUnlock) {
for (let i: number = 0; i < this._gengeralLogics.length; i++) {
comp = this._gengeralLogics[i];
generalData = null;
isUnlock = true;
if (i == 2) {
//只有第二个副将才需要判断是否解锁
isUnlock = this._addition.vanguardCnt >= this._order;
}
if (this._data && this._data.generals[i] > 0) {
generalData = GeneralCommand.getInstance().proxy.getMyGeneral(this._data.generals[i]);
generalCfg = GeneralCommand.getInstance().proxy.getGeneralCfg(generalData.cfgId);
totalCost += generalCfg.cost;
this._soldiers[i] = this._data.soldiers[i];
this._totalSoldiers[i] = generalData.level * 100 + this._addition.soldierCnt;
soldierCnt += this._soldiers[i];
totalSoldierCnt += this._totalSoldiers[i];
this._conTimes[i] = this._data.conTimes[i];
this._conCnts[i] = this._data.conCnts[i];
}
if (isUnlock == false || generalData == null) {
this.tipNodes[i].active = true;
this.editBoxs[i].node.active = false;
this.sliders[i].node.active = false;
} else {
this.tipNodes[i].active = false;
this.editBoxs[i].node.active = true;
this.sliders[i].node.active = true;
let totalValue: number = this._totalSoldiers[i] - this._soldiers[i];
if(this._data && this._data.cmd == ArmyCmd.Conscript){
var can = this._conCnts[i] == 0
this.sliders[i].enabled = can;
this.editBoxs[i].string = "0";
this.sliders[i].progress = 0;
this.editBoxs[i].enabled = can;
}else if(this._data && this._data.cmd > ArmyCmd.Idle || totalValue <= 0) {
//不可征兵
this.editBoxs[i].string = "0";
this.sliders[i].progress = 0;
this.editBoxs[i].enabled = false;
this.sliders[i].enabled = false;
this.setCurConscriptForIndex(i, 0);
} else {
this.editBoxs[i].enabled = true;
this.sliders[i].enabled = true;
let curValue: number = 0;
if (this.editBoxs[i].string != "") {
curValue = Math.max(0, Math.min(parseInt(this.editBoxs[i].string), totalValue));
}
this.setCurConscriptForIndex(i, curValue);
}
}
comp.setData(this._cityId, this._order, generalData, this._soldiers[i], this._totalSoldiers[i], this._conCnts[i], this._conTimes[i], isUnlock);
}
}
this.labelId.string = "部队" + this._order;
this.labelCost.string = totalCost + "/" + MapUICommand.getInstance().proxy.getMyCityCost(this._cityId);
this.labelSoldierCnt.string = soldierCnt + "/" + totalSoldierCnt;
this.labelAddition.string = "无";
if (this._data) {
let generals: GeneralData[] = ArmyCommand.getInstance().getArmyGenerals(this._data);
let speed: number = ArmyCommand.getInstance().getArmySpeed(generals);
this.labelSpeed.string = speed.toFixed(2);
let destroy: number = ArmyCommand.getInstance().getArmyDestroy(generals);
this.labelAtkCity.string = destroy.toFixed(2);
let camp: number = ArmyCommand.getInstance().getArmyCamp(generals);
if (camp > 0) {
if (camp == GeneralCampType.Han && this._addition.han > 0) {
this.labelAdditionTip.string = "汉阵营加成:" + this._addition.han;
this.labelAddition.string = "阵营";
} else if (camp == GeneralCampType.Qun && this._addition.han > 0) {
this.labelAdditionTip.string = "群阵营加成:" + this._addition.qun;
this.labelAddition.string = "阵营";
} else if (camp == GeneralCampType.Wei && this._addition.han > 0) {
this.labelAdditionTip.string = "魏阵营加成:" + this._addition.wei;
this.labelAddition.string = "阵营";
} else if (camp == GeneralCampType.Shu && this._addition.han > 0) {
this.labelAdditionTip.string = "蜀阵营加成:" + this._addition.shu;
this.labelAddition.string = "阵营";
} else if (camp == GeneralCampType.Wu && this._addition.han > 0) {
this.labelAdditionTip.string = "吴阵营加成:" + this._addition.wu;
this.labelAddition.string = "阵营";
}
}
} else {
this.labelSpeed.string = "0";
}
this.updateResCost();
}
protected setCurConscriptForIndex(index: number, cnt: number = 0): void {
let maxCnt: number = this._totalSoldiers[index] - this._soldiers[index];
cnt = Math.min(cnt, maxCnt);
let percent: number = cnt / maxCnt;
this.editBoxs[index].string = cnt + "";
this.sliders[index].progress = percent;
this._curConscripts[index] = cnt;
}
protected getTotalConscriptCnt(): number {
let totalCnt: number = 0;
for (let i = 0; i < this._curConscripts.length; i++) {
totalCnt += this._curConscripts[i];
}
return totalCnt;
}
protected updateResCost(): void {
let totalCnt: number = this.getTotalConscriptCnt();
if (totalCnt > 0) {
var myRoleRes = LoginCommand.getInstance().proxy.getRoleResData();
var baseCost: Conscript = MapUICommand.getInstance().proxy.getConscriptBaseCost();
let str: string = "消耗: " + "金币:" + totalCnt * baseCost.cost_gold + "/" + myRoleRes.gold;
str += " 木材:" + totalCnt * baseCost.cost_wood + "/" + myRoleRes.wood;
str += " 金属:" + totalCnt * baseCost.cost_iron + "/" + myRoleRes.iron;
str += " 谷物:" + totalCnt * baseCost.cost_grain + "/" + myRoleRes.grain;
this.labelResCost.string = str;
} else {
this.labelResCost.string = "";
}
}
protected onChangeEditBox(editBox: EditBox): void {
let index: number = this.editBoxs.indexOf(editBox);
if (index >= 0) {
this.setCurConscriptForIndex(index, parseInt(this.editBoxs[index].string));
this.updateResCost();
}
}
protected onChangeSlider(slider: Slider): void {
let index: number = this.sliders.indexOf(slider);
if (index >= 0) {
let maxCnt: number = this._totalSoldiers[index] - this._soldiers[index];
this.setCurConscriptForIndex(index, Math.floor(this.sliders[index].progress * maxCnt));
this.updateResCost();
}
}
protected onClickQuick(): void {
if (this._data && this._data.cmd == ArmyCmd.Idle || this._data.cmd == ArmyCmd.Conscript) {
for (let i: number = 0; i < this._totalSoldiers.length; i++) {
if(this._conCnts[i] > 0){
//正在征兵的不能重复征兵
this.setCurConscriptForIndex(i, 0);
}else{
let maxCnt: number = this._totalSoldiers[i] - this._soldiers[i];
if (maxCnt > 0) {
this.setCurConscriptForIndex(i, maxCnt);
}
}
}
this.updateResCost();
}
}
protected onClickSure(): void {
if (this._data && this._data.cmd == ArmyCmd.Idle || this._data.cmd == ArmyCmd.Conscript) {
let totalCnt: number = this.getTotalConscriptCnt();
if (totalCnt > 0) {
ArmyCommand.getInstance().generalConscript(this._data.id, this._curConscripts, null);
}
}
}
protected onClickPrev(): void {
this._curConscripts = [0, 0, 0];
if (this._order == 1) {
//第一个就跳到最后一个
this.setData(this._cityId, this._addition.armyCnt);
} else {
this.setData(this._cityId, this._order - 1);
}
}
protected onClickNext(): void {
this._curConscripts = [0, 0, 0];
if (this._order == this._addition.armyCnt) {
//最后一个就跳到第一个
this.setData(this._cityId, 1);
} else {
this.setData(this._cityId, this._order + 1);
}
}
protected onClickClose(): void {
this.node.active = false;
}
public setData(cityId: number, order: number = 1): void {
this._curConscripts = [0, 0, 0];
this._cityId = cityId;
this._order = order;
this._cityData = MapCommand.getInstance().cityProxy.getMyCityById(this._cityId);
this._data = ArmyCommand.getInstance().proxy.getArmyByOrder(order, cityId);
this._addition = MapUICommand.getInstance().proxy.getMyCityAddition(cityId);
this._isUnlock = this._addition.armyCnt >= this._order;
let facility: Map<number, Facility> = MapUICommand.getInstance().proxy.getMyFacilitys(this._cityId);
if (facility == null) {
MapUICommand.getInstance().qryCityFacilities(this._cityId);
}
this.updateView();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fa97f626-3fc1-46be-9108-d756122cc651",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,196 @@
import { _decorator, Component, Node, Label, Sprite, ProgressBar } from 'cc';
const { ccclass, property } = _decorator;
import ArmyCommand from "../../general/ArmyCommand";
import { ArmyData } from "../../general/ArmyProxy";
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralCampType, GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import DateUtil from "../../utils/DateUtil";
import GeneralHeadLogic from "./GeneralHeadLogic";
import MapUICommand from "./MapUICommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CityGeneralItemLogic')
export default class CityGeneralItemLogic extends Component {
@property(Node)
infoNode: Node = null;
@property(Node)
addNode: Node = null;
@property(Node)
lockNode: Node = null;
@property(Node)
btnDown: Node = null;
@property(Label)
labelTitle: Label = null;
@property(Sprite)
headIcon: Sprite = null;
@property(Label)
labelLv: Label = null;
@property(Label)
labelName: Label = null;
@property(Label)
labelArms: Label = null;
@property(Label)
labelSoldierCnt: Label = null;
@property(Label)
labelCost: Label = null;
@property(Label)
labelCamp: Label = null;
@property(Label)
labelTip: Label = null;
@property(Label)
labelConTime: Label = null;
@property(Label)
labelConCnt: Label = null;
@property(ProgressBar)
progressBar: ProgressBar = null;
@property(Node)
conBg: Node = null;
public index: number = 0;
protected _order: number = 0;
protected _cityId: number = 0;
protected _data: GeneralData = null;
protected _soldierCnt: number = 0;
protected _totalSoldierCnt: number = 0;
protected _conCnt: number = 0;
protected _conTime: number = 0;
protected _isUnlock: boolean = false;
protected onLoad(): void {
this.schedule(this.updateCon, 1.0);
}
protected onEnable(): void{
this.conBg.active = false;
}
protected onDestroy(): void {
this._data = null;
}
protected onClickDown(): void {
ArmyCommand.getInstance().generalDispose(this._cityId, this._data.id, this._data.order, -1, null);
}
protected onClickItem(): void {
if (this._data) {
//点击展示武将信息
let cfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(this._data.cfgId);
EventMgr.emit("open_general_des", cfg, this._data);
} else if (this.addNode.active) {
//上阵武将
var generalArr: number[] = this.getAllGenerals();
EventMgr.emit("open_general_choose", generalArr, this.index);
}
}
protected getAllGenerals(): number[] {
let cityArmyData: ArmyData[] = ArmyCommand.getInstance().proxy.getArmyList(this._cityId);
let general: GeneralData = null;
var arr = [];
for (var i = 0; i < cityArmyData.length; i++) {
if (cityArmyData[i]) {
arr = arr.concat(cityArmyData[i].generals);
for (let j: number = 0; j < cityArmyData[i].generals.length; j++) {
if (cityArmyData[i].generals[j] > 0) {
general = GeneralCommand.getInstance().proxy.getMyGeneral(cityArmyData[i].generals[j]);
if (general) {
arr = arr.concat(GeneralCommand.getInstance().proxy.getGeneralIds(general.cfgId));
}
}
}
}
}
return arr;
}
protected updateItem(): void {
if (this.index == 0) {
this.labelTitle.string = "主将"
} else {
this.labelTitle.string = "副将"
}
if (this._isUnlock == false) {
//未解锁
this.infoNode.active = false;
this.addNode.active = false;
this.lockNode.active = true;
this.btnDown.active = false;
let desName: string = MapUICommand.getInstance().proxy.getFacilityCfgByType(14).name;
this.labelTip.string = desName + " 等级" + this._order + "开启";
this.conBg.active = false;
} else if (this._data == null) {
//未配置武将
this.infoNode.active = false;
this.addNode.active = true;
this.lockNode.active = false;
this.btnDown.active = false;
this.conBg.active = false;
} else {
//展示武将信息
this.infoNode.active = true;
this.addNode.active = false;
this.lockNode.active = false;
this.btnDown.active = true;
this.updateCon();
let cfg: GeneralConfig = GeneralCommand.getInstance().proxy.getGeneralCfg(this._data.cfgId);
this.headIcon.getComponent(GeneralHeadLogic).setHeadId(this._data.cfgId);
this.labelLv.string = this._data.level + "";
this.labelName.string = cfg.name;
this.labelSoldierCnt.string = this._soldierCnt + "/" + this._totalSoldierCnt;
this.progressBar.progress = this._soldierCnt / this._totalSoldierCnt;
this.labelCost.string = "Cost " + cfg.cost;
switch (this._data.config.camp) {
case GeneralCampType.Han:
this.labelCamp.string = "汉";
break;
case GeneralCampType.Qun:
this.labelCamp.string = "群";
break;
case GeneralCampType.Wei:
this.labelCamp.string = "魏";
break;
case GeneralCampType.Shu:
this.labelCamp.string = "蜀";
break;
case GeneralCampType.Wu:
this.labelCamp.string = "吴";
break;
default:
this.labelCamp.string = "无";
break;
}
}
}
protected updateCon(){
if (DateUtil.isAfterServerTime(this._conTime*1000)){
this.conBg.active = false;
this.labelConTime.string = "";
this.labelConCnt.string = "";
}else{
this.conBg.active = true;
this.labelConTime.string = DateUtil.leftTimeStr(this._conTime*1000);
this.labelConCnt.string = "+" + this._conCnt;
}
}
public setData(cityId: number, order: number, data: GeneralData,
soldierCnt: number, totalSoldierCnt: number, conCnt:number,
conTime:number, isUnlock: boolean): void {
this._cityId = cityId;
this._order = order;
this._data = data;
this._soldierCnt = soldierCnt;
this._totalSoldierCnt = totalSoldierCnt;
this._conCnt = conCnt;
this._conTime = conTime;
this._isUnlock = isUnlock;
this.updateItem();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9d98dfbb-5f5f-4d46-a5e7-5b3a695c25bb",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,92 @@
// // Learn TypeScript:
// // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// // Learn Attribute:
// // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// // Learn life-cycle callbacks:
// // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { _decorator, Component, Label, Button } from 'cc';
const {ccclass, property} = _decorator;
import LoginCommand from "../../login/LoginCommand";
import DateUtil from "../../utils/DateUtil";
import { Tools } from "../../utils/Tools";
import MapUICommand from "./MapUICommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('CollectLogic')
export default class CollectLogic extends Component {
@property(Label)
cdLab: Label = null;
@property(Label)
timesLab: Label = null;
@property(Label)
goldLab: Label = null;
@property(Button)
collectBtn: Button = null;
_data: any = null;
protected onEnable():void{
console.log("add interior_openCollect");
EventMgr.on("interior_openCollect", this.onOpenCollect, this);
EventMgr.on("interior_collect", this.onCollect, this);
var roleRes = LoginCommand.getInstance().proxy.getRoleResData();
this.goldLab.string = Tools.numberToShow(roleRes.gold_yield);
MapUICommand.getInstance().interiorOpenCollect();
}
protected onDisable():void{
EventMgr.targetOff(this);
}
protected onOpenCollect(msg:any):void{
console.log("onOpenCollect:", msg);
this._data = msg;
this.startCountDown();
}
protected onCollect(msg:any):void{
console.log("onOpenCollect:", msg);
this._data = msg;
this.startCountDown();
}
protected onClickClose(): void {
this.node.active = false;
}
protected onClickCollect(): void{
MapUICommand.getInstance().interiorCollect();
}
protected startCountDown(){
this.stopCountDown();
this.schedule(this.countDown, 1.0);
this.countDown();
}
public countDown() {
this.timesLab.string = this._data.cur_times + "/" + this._data.limit;
var diff = DateUtil.leftTime(this._data.next_time);
if (diff>0){
this.cdLab.string = DateUtil.leftTimeStr(this._data.next_time);
this.collectBtn.interactable = false;
}else{
this.cdLab.string = "目前可以征收";
this.collectBtn.interactable = true;
}
}
public stopCountDown() {
this.unschedule(this.countDown);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "27056b00-731c-4bc0-ae3e-7bd3e9f3b15b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,35 @@
// // Learn TypeScript:
// // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// // Learn Attribute:
// // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// // Learn life-cycle callbacks:
// // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { _decorator, Component, Label } from 'cc';
const {ccclass, property} = _decorator;
@ccclass('Dialog')
export default class Dialog extends Component {
@property(Label)
label: Label = null;
protected closeCallBack: Function = null;
protected onClickClose(): void {
if (this.closeCallBack){
this.closeCallBack()
}
this.node.active = false;
}
public text(text: any): void {
this.label.string = text
}
public setClose(close :Function){
this.closeCallBack = close
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "28245652-c17c-4533-b0e6-80e01c76736b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,64 @@
import { _decorator, Component, Label } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralCommonConfig } from "../../general/GeneralProxy";
import LoginCommand from "../../login/LoginCommand";
import MapUICommand from "./MapUICommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('DrawLogic')
export default class DrawLogic extends Component {
@property(Label)
labelOnce: Label = null;
@property(Label)
labelTen: Label = null;
@property(Label)
cntLab: Label = null;
protected onEnable():void{
EventMgr.on("upate_my_roleRes", this.updateRoleRes, this);
EventMgr.on("update_my_generals", this.updateRoleRes, this);
this.updateRoleRes();
}
protected onDisable():void{
EventMgr.targetOff(this);
}
protected onClickClose(): void {
this.node.active = false;
}
protected updateRoleRes():void{
let commonCfg: GeneralCommonConfig = GeneralCommand.getInstance().proxy.getCommonCfg();
var roleResData = LoginCommand.getInstance().proxy.getRoleResData();
this.labelOnce.string = "消耗:"+commonCfg.draw_general_cost +"/"+ roleResData.gold;
this.labelTen.string = "消耗:"+commonCfg.draw_general_cost * 10 +"/"+ roleResData.gold;
var basic = MapUICommand.getInstance().proxy.getBasicGeneral();
var cnt = GeneralCommand.getInstance().proxy.getMyActiveGeneralCnt();
this.cntLab.string = "(" + cnt + "/" + basic.limit + ")";
}
protected drawGeneralOnce():void{
GeneralCommand.getInstance().drawGenerals();
}
protected drawGeneralTen():void{
GeneralCommand.getInstance().drawGenerals(10);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2928eb4a-fe99-4700-9421-4031994b843a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,82 @@
import { _decorator, Component, Prefab, Layout, instantiate, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import GeneralItemLogic, { GeneralItemType } from "./GeneralItemLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('DrawRLogic')
export default class DrawRLogic extends Component {
@property(Prefab)
generalItemPrefab: Prefab = null;
@property(Layout)
tenLayout:Layout = null;
@property(Layout)
oneLayout:Layout = null;
private _maxSize:number = 10;
private _scale:number = 0.4;
protected onLoad():void{
for(var i = 0; i < this._maxSize;i++){
let _generalNode = instantiate(this.generalItemPrefab);
_generalNode.parent = this.tenLayout.node;
_generalNode.scale = new Vec3(this._scale, this._scale, this._scale);
_generalNode.active = false;
}
let _generalNode = instantiate(this.generalItemPrefab);
_generalNode.parent = this.oneLayout.node;
_generalNode.scale = new Vec3(this._scale, this._scale, this._scale);
_generalNode.active = false;
}
public setData(data:any):void{
this.tenLayout.node.active = this.oneLayout.node.active = false;
if(data.length == 1){
this.oneLayout.node.active = true;
var children = this.oneLayout.node.children;
let com = children[0].getComponent(GeneralItemLogic);
children[0].active = true;
if(com){
com.setData(data[0],GeneralItemType.GeneralNoThing);
}
}else{
this.tenLayout.node.active = true;
var children = this.tenLayout.node.children;
for(var i = 0; i < this._maxSize;i++){
var child = children[i];
if(data[i]){
child.active = true;
let com = child.getComponent(GeneralItemLogic);
if(com){
com.setData(data[i],GeneralItemType.GeneralNoThing);
}
}
else{
child.active = false;
}
}
}
}
protected onClickClose(): void {
this.node.active = false;
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "64665783-4486-4d93-b93f-4a23114a2544",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,60 @@
import { _decorator, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;
import MapUICommand from "./MapUICommand";
import { Facility, FacilityAdditionCfg, FacilityConfig, CityAdditionType } from "./MapUIProxy";
@ccclass('FacilityAdditionItemLogic')
export default class FacilityAdditionItemLogic extends Component {
@property(Label)
labelName: Label = null;
@property(Node)
upNode: Node = null;
@property(Node)
maxNode: Node = null;
@property(Label)
labelOld: Label = null;
@property(Label)
labelNew: Label = null;
@property(Label)
labeMax: Label = null;
public setData(data:Facility, cfg:FacilityConfig, index:number): void {
let additionType:number = cfg.additions[index];
let additionCfg: FacilityAdditionCfg = MapUICommand.getInstance().proxy.getFacilityAdditionCfgByType(additionType);
this.labelName.string = additionCfg.des;
if (data.level >= cfg.upLevels.length) {
//达到最大等级
this.upNode.active = false;
this.maxNode.active = true;
var v = cfg.upLevels[data.level - 1].values[index];
if(additionType == CityAdditionType.Durable){
v = v/100
}
this.labeMax.string = additionCfg.value.replace("%n%", v+ "");
} else {
this.upNode.active = true;
this.maxNode.active = false;
if (data.level == 0) {
//代表未升级过
this.labelOld.string = "---";
} else {
var v = cfg.upLevels[data.level - 1].values[index];
if(additionType == CityAdditionType.Durable){
v = v/100
}
this.labelOld.string = additionCfg.value.replace("%n%", v + "");
}
var v = cfg.upLevels[data.level].values[index];
if(additionType == CityAdditionType.Durable){
v = v/100
}
this.labelNew.string = additionCfg.value.replace("%n%", v + "");
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "153121a9-12ea-4e64-a654-a2d2ef1a4b8e",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,219 @@
import { _decorator, Component, Label, RichText, Button, Node, Prefab, NodePool, instantiate, UITransform } from 'cc';
const { ccclass, property } = _decorator;
import LoginCommand from "../../login/LoginCommand";
import DateUtil from "../../utils/DateUtil";
import FacilityAdditionItemLogic from "./FacilityAdditionItemLogic";
import MapUICommand from "./MapUICommand";
import { Facility, FacilityAdditionCfg, FacilityConfig, FacilityUpLevel } from "./MapUIProxy";
@ccclass('FacilityDesLogic')
export default class FacilityDesLogic extends Component {
@property(Label)
labelTitle: Label = null;
@property(Label)
labelDes: Label = null;
@property(RichText)
labelConditions: RichText = null;
@property(RichText)
labelNeed: RichText = null;
@property(Button)
btnUp: Button = null;
@property(Label)
labelUp: Label = null;
@property(Label)
labelNeedTime: Label = null;
@property(Node)
additionNode: Node = null;
@property(Prefab)
additionItemPrefab: Prefab = null;
protected _cityId: number = 0;
protected _data: Facility = null;
protected _cfg: FacilityConfig = null;
protected _additonCfg: FacilityAdditionCfg = null;
protected _isUnLock: boolean = false;//是否解锁
protected _isNeedComplete: boolean = false;//是否满足升级需求
protected _isLevelMax: boolean = false;//是否已达最高等级
protected _additionPool: NodePool = new NodePool();
protected onLoad(): void {
this.schedule(this.updateNeedTime);
}
protected onDestroy(): void {
}
protected removeAllAdditionItems(): void {
let children: Node[] = this.additionNode.children.concat();
this.additionNode.removeAllChildren();
for (let i: number = 0; i < children.length; i++) {
this._additionPool.put(children[i]);
}
}
protected getAdditionItem(): Node {
if (this._additionPool.size() > 0) {
return this._additionPool.get();
} else {
return instantiate(this.additionItemPrefab);
}
}
//更新加成描述界面
public updateAdditionView() {
this.removeAllAdditionItems();
for (let i: number = 0; i < this._cfg.additions.length; i++) {
let item: Node = this.getAdditionItem();
item.parent = this.additionNode;
item.getComponent(FacilityAdditionItemLogic).setData(this._data, this._cfg, i);
}
}
//更新解锁条件
public updateContidionView() {
this._isUnLock = true;
if (this._cfg.conditions.length > 0) {
//有解锁条件
let contidionList: string[] = [];
for (let i: number = 0; i < this._cfg.conditions.length; i++) {
let data: Facility = MapUICommand.getInstance().proxy.getMyFacilityByType(this._cityId, this._cfg.conditions[i].type);
let cfg: FacilityConfig = MapUICommand.getInstance().proxy.getFacilityCfgByType(this._cfg.conditions[i].type);
if (data == null || data.level < this._cfg.conditions[i].level) {
//不满足条件
contidionList.push("<color=#ff0000>" + cfg.name + this._cfg.conditions[i].level + "级</color>");
this._isUnLock = false;
} else {
//满足条件
contidionList.push("<color=#00ff00>" + cfg.name + this._cfg.conditions[i].level + "级</color>");
}
}
this.labelConditions.node.parent.active = true;
this.labelConditions.string = contidionList.join("<br/>");
this.labelConditions.node.parent.getComponent(UITransform).height = this.labelConditions.node.getComponent(UITransform).height + 30;
} else {
this.labelConditions.node.parent.active = false;
}
}
//更新资源需求
public updateNeedView(): void {
this._isNeedComplete = true;
let curLevel: number = this._data.level;
if (curLevel >= 0 && curLevel < this._cfg.upLevels.length) {
//未达到最高级时
let roleRes: any = LoginCommand.getInstance().proxy.getRoleResData();
let upLevel: FacilityUpLevel = this._cfg.upLevels[curLevel];
let needStrList: string[] = [];
if (upLevel.grain > 0) {
if (roleRes.grain < upLevel.grain) {
this._isNeedComplete = false;
needStrList.push("粮食:<color=#ff0000>" + upLevel.grain + "/" + roleRes.grain + "</color>");
} else {
needStrList.push("粮食:<color=#00ff00>" + upLevel.grain + "/" + roleRes.grain + "</color>");
}
}
if (upLevel.wood > 0) {
if (roleRes.wood < upLevel.wood) {
this._isNeedComplete = false;
needStrList.push("木材:<color=#ff0000>" + upLevel.wood + "/" + roleRes.wood + "</color>");
} else {
needStrList.push("木材:<color=#00ff00>" + upLevel.wood + "/" + roleRes.wood + "</color>");
}
}
if (upLevel.iron > 0) {
if (roleRes.iron < upLevel.iron) {
this._isNeedComplete = false;
needStrList.push("铁矿:<color=#ff0000>" + upLevel.iron + "/" + roleRes.iron + "</color>");
} else {
needStrList.push("铁矿:<color=#00ff00>" + upLevel.iron + "/" + roleRes.iron + "</color>");
}
}
if (upLevel.stone > 0) {
if (roleRes.stone < upLevel.stone) {
this._isNeedComplete = false;
needStrList.push("石头:<color=#ff0000>" + upLevel.stone + "/" + roleRes.stone + "</color>");
} else {
needStrList.push("石头:<color=#00ff00>" + upLevel.stone + "/" + roleRes.stone + "</color>");
}
}
if (upLevel.decree > 0) {
if (roleRes.decree < upLevel.decree) {
this._isNeedComplete = false;
needStrList.push("政令:<color=#ff0000>" + upLevel.decree + "/" + roleRes.decree + "</color>");
} else {
needStrList.push("政令:<color=#00ff00>" + upLevel.decree + "/" + roleRes.decree + "</color>");
}
}
this.labelNeed.node.parent.active = true;
this.labelNeed.string = needStrList.join("<br/>");
this.labelNeed.node.parent.getComponent(UITransform).height = this.labelNeed.node.getComponent(UITransform).height + 30;
this._isLevelMax = false;
} else {
this.labelNeed.node.parent.active = false;
this._isLevelMax = true;
}
}
public updateNeedTime(): void {
if(this._isLevelMax == false){
var level = this._cfg.upLevels[this._data.level];
if (this._data.isUping() == false){
this.labelNeedTime.string = DateUtil.converSecondStr(level.time*1000);
}else{
this.labelNeedTime.string = DateUtil.converSecondStr(this._data.upLastTime());
}
}else{
this.labelNeedTime.string = "等级已满";
}
}
//更新升级按钮
public updateUpBtn(): void {
if (this._isLevelMax) {
//升满级了
this.btnUp.node.active = false;
} else {
this.btnUp.node.active = true;
if (this._isUnLock == false) {
//未解锁
this.btnUp.interactable = false;
this.labelUp.string = "未解锁";
} else if (this._isNeedComplete == false) {
//资源不足
this.btnUp.interactable = false;
this.labelUp.string = "升级";
} else if(this._data.isUping()){
//正在升级中
this.btnUp.interactable = false;
this.labelUp.string = "升级中";
}
else {
this.btnUp.interactable = true;
this.labelUp.string = "升级";
}
}
}
public setData(cityId: number, data: Facility, cfg: FacilityConfig): void {
this._cityId = cityId;
this._data = data;
this._cfg = cfg;
this.labelTitle.string = cfg.name;
this.labelDes.string = cfg.des;
this.updateAdditionView();
this.updateContidionView();
this.updateNeedView();
this.updateNeedTime();
this.updateUpBtn();
}
protected onClickUp(): void {
MapUICommand.getInstance().upFacility(this._cityId, this._data.type);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "dfb4e119-6064-407a-9336-80ce4bd8661a",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,81 @@
import { _decorator, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;
import DateUtil from "../../utils/DateUtil";
import { Facility, FacilityConfig } from "./MapUIProxy";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('FacilityItemLogic')
export default class FacilityItemLogic extends Component {
@property(Label)
labelRate: Label = null;
@property(Label)
labelName: Label = null;
@property(Label)
labelTime: Label = null;
@property(Node)
lockNode: Node = null;
public type: number = 0;
public isUnlock: boolean = false;
public cityId: number = 0;
public data: Facility = null;
public cfg: FacilityConfig = null;
protected onLoad(): void {
this.node.on(Node.EventType.TOUCH_END, this.onTouchItem, this);
}
protected onDestroy(): void {
this.node.off(Node.EventType.TOUCH_END, this.onTouchItem, this);
EventMgr.targetOff(this);
}
protected updateItem(): void {
this.labelRate.string = this.data.level + "/" + this.cfg.upLevels.length;
this.labelName.string = this.cfg.name;
this.lockNode.active = !this.isUnlock;
}
protected onTouchItem() {
EventMgr.emit("select_facility_item", this.cityId, this.data.type);
}
public setData(cityId: number, data: Facility, cfg:FacilityConfig, isUnlock:boolean): void {
// console.log("setData:", data);
this.cityId = cityId;
this.data = data;
this.cfg = cfg;
this.isUnlock = isUnlock;
if(this.data.isUping()){
this.startUpTime();
}else{
this.stopCountDown();
}
this.updateItem();
}
protected countDown(){
if (this.data.isUping()){
this.labelTime.string = DateUtil.converSecondStr(this.data.upLastTime());
}else{
this.stopCountDown();
}
}
protected stopCountDown(){
this.unscheduleAllCallbacks();
this.labelTime.string = "";
}
protected startUpTime(){
this.stopCountDown();
this.schedule(this.countDown, 1.0);
this.countDown();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3f5e7cea-6be6-4faf-b4b6-039ab258473d",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,130 @@
import { _decorator, Component, ScrollView, Node, Label } from 'cc';
const { ccclass, property } = _decorator;
import FacilityDesLogic from "./FacilityDesLogic";
import FacilityItemLogic from "./FacilityItemLogic";
import MapUICommand from "./MapUICommand";
import { Facility, FacilityConfig } from "./MapUIProxy";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('FacilityListLogic')
export default class FacilityListLogic extends Component {
@property(ScrollView)
scrollView: ScrollView = null;
protected _curCityId: number = 0;
protected _curSelectType: number = -1;
protected _itemLogics: Map<number, FacilityItemLogic> = new Map<number, FacilityItemLogic>();
protected onLoad(): void {
this.initView();
EventMgr.on("update_my_facilities", this.updateView, this);
EventMgr.on("update_my_facility", this.updateFacility, this);
EventMgr.on("select_facility_item", this.onSelectItem, this);
EventMgr.on("upate_my_roleRes", this.onUpdateMyRoleRes, this);
}
protected onDestroy(): void {
EventMgr.targetOff(this);
this._itemLogics.clear();
this._itemLogics = null;
}
protected initView(): void {
let children: Node[] = this.scrollView.content.children;
for (let i: number = 0; i < children.length; i++) {
let subChildren: Node[] = children[i].children;
for (let j: number = 0; j < subChildren.length; j++) {
let item: Node = subChildren[j];
if (item.name.indexOf("CityFacilityItem") == 0) {
let type: number = parseInt(item.name.substring(16));
let comp: FacilityItemLogic = item.addComponent(FacilityItemLogic);
comp.labelRate = item.getChildByName("labelRate").getComponent(Label);
comp.labelName = item.getChildByName("labelName").getComponent(Label);
comp.labelTime = item.getChildByName("labelTime").getComponent(Label);
comp.lockNode = item.getChildByName("lockNode");
comp.labelTime.string = "";
comp.type = type;
this._itemLogics.set(type, comp);
}
}
}
}
protected updateView(): void {
let dataList: Map<number, Facility> = MapUICommand.getInstance().proxy.getMyFacilitys(this._curCityId);
if (dataList && dataList.size > 0) {
dataList.forEach((data: Facility, type: number) => {
if (this._itemLogics.has(type)) {
//有数据就更新
let logic: FacilityItemLogic = this._itemLogics.get(type);
let cfg: FacilityConfig = MapUICommand.getInstance().proxy.getFacilityCfgByType(type);
let isUnlock: boolean = MapUICommand.getInstance().proxy.isFacilityUnlock(this._curCityId, type);
logic.setData(this._curCityId, data, cfg, isUnlock);
}
});
if (this._curSelectType == -1) {
this.setCurSelectType(0);//默认选中主城
}
}
this.updateDesView();
}
protected updateFacility(cityId: number, data: Facility): void {
if (this._curCityId == cityId) {
if (this._itemLogics.has(data.type)) {
//有数据就更新
let logic: FacilityItemLogic = this._itemLogics.get(data.type);
let cfg: FacilityConfig = MapUICommand.getInstance().proxy.getFacilityCfgByType(data.type);
let isUnlock: boolean = MapUICommand.getInstance().proxy.isFacilityUnlock(this._curCityId, data.type);
logic.setData(this._curCityId, data, cfg, isUnlock);
}
this._itemLogics.forEach((logic: FacilityItemLogic, type: number) => {
let cfg: FacilityConfig = MapUICommand.getInstance().proxy.getFacilityCfgByType(logic.data.type);
for (let i: number = 0; i < cfg.conditions.length; i++) {
if (cfg.conditions[i].type == data.type) {
//涉及到了解锁条件
let data: Facility = MapUICommand.getInstance().proxy.getMyFacilityByType(this._curCityId, logic.data.type);
let isUnlock: boolean = MapUICommand.getInstance().proxy.isFacilityUnlock(this._curCityId, logic.data.type);
logic.setData(this._curCityId, data, cfg, isUnlock);
break;
}
}
})
}
this.updateDesView();
}
protected onUpdateMyRoleRes(): void {
this.updateDesView();
}
protected onSelectItem(cityId: number, type: number): void {
if (this._curCityId == cityId) {
this.setCurSelectType(type);
}
}
protected updateDesView(): void {
let data: Facility = MapUICommand.getInstance().proxy.getMyFacilityByType(this._curCityId, this._curSelectType);
let cfg: FacilityConfig = MapUICommand.getInstance().proxy.getFacilityCfgByType(this._curSelectType);
this.node.getComponent(FacilityDesLogic).setData(this._curCityId, data, cfg);
}
protected onClickClose(): void {
this.node.active = false;
}
public setCurSelectType(type: number): void {
if (this._curSelectType != type) {
this._curSelectType = type;
this.updateDesView();
}
}
public setData(data: any): void {
this._curCityId = data.cityId;
this.updateView();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c3bc233e-cb57-4c5b-b2aa-0cff964a8fb3",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,174 @@
import { _decorator, Component, Node, Label, Button, Prefab, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import ArmyCommand from "../../general/ArmyCommand";
import { ArmyData } from "../../general/ArmyProxy";
import DateUtil from "../../utils/DateUtil";
import { MapBuildData } from "../MapBuildProxy";
import MapCommand from "../MapCommand";
import { MapResType } from "../MapProxy";
import CityArmyItemLogic from "./CityArmyItemLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('FortressAbout')
export default class FortressAbout extends Component {
@property(Node)
armyLayer: Node = null;
@property(Label)
nameLab: Label = null;
@property(Label)
lvLab: Label = null;
@property(Label)
timeLab: Label = null;
@property(Button)
upBtn: Button = null;
@property(Button)
destroyBtn: Button = null;
@property(Prefab)
armyItem: Prefab = null;
protected _armyCnt: number = 5;//队伍数量 固定值
protected _data: MapBuildData = null;
protected _armyComps: CityArmyItemLogic[] = [];
protected _cmd: MapCommand;
protected onLoad(): void {
this._cmd = MapCommand.getInstance();
}
onEnable (): void{
EventMgr.on("update_builds", this.onUpdateBuilds, this);
EventMgr.on("update_build", this.onUpdateBuild, this);
EventMgr.on("delete_build", this.onDeleteBuild, this);
this.initView();
}
protected onDisable(): void {
EventMgr.targetOff(this);
}
protected initView(): void {
for (let i: number = 0; i < this._armyCnt; i++) {
let item = instantiate(this.armyItem);
item.parent = this.armyLayer;
let comp: CityArmyItemLogic = item.getComponent(CityArmyItemLogic);
comp.order = i + 1;
this._armyComps.push(comp);
}
}
protected updateArmyList(): void {
let armyList: ArmyData[] = ArmyCommand.getInstance().proxy.getArmysByPos(this._data.x, this._data.y);
console.log("updateArmyList:", armyList, this._data);
for (let i: number = 0; i < this._armyComps.length; i++) {
if (this._data.level > i){
this._armyComps[i].isOpenedArmy(true, true);
}else{
this._armyComps[i].isOpenedArmy(false, true);
}
this._armyComps[i].setArmyData(0, null);
if (armyList.length > i){
this._armyComps[i].setArmyData(armyList[i].cityId, armyList[i]);
}
}
}
public setData(data: MapBuildData): void {
this._data = data;
this.nameLab.string = data.name;
this.lvLab.string = "lv:" + data.level;
this.startCountDownTime();
this.updateArmyList();
if (this._data.type == MapResType.SYS_FORTRESS){
this.upBtn.node.active = false;
this.destroyBtn.node.active = false;
}else if(this._data.type == MapResType.FORTRESS){
this.upBtn.node.active = true;
this.destroyBtn.node.active = true;
}
}
protected onUpdateBuilds(areaIndex: number, addIds: number[], removeIds: number[], updateIds: number[]): void {
console.log("onUpdateBuilds:", removeIds);
for (let i: number = 0; i < addIds.length; i++) {
let data = this._cmd.buildProxy.getBuild(addIds[i]);
if (data.x == this._data.x && data.y == this._data.y){
this.setData(data);
}
}
for (let i: number = 0; i < removeIds.length; i++) {
console.log("data:", this._data);
if(this._data.rid == 0){
this.node.parent = null;
}
}
for (let i: number = 0; i < updateIds.length; i++) {
let data = this._cmd.buildProxy.getBuild(updateIds[i]);
if (data.x == this._data.x && data.y == this._data.y){
this.setData(data);
}
}
}
protected onUpdateBuild(data: MapBuildData): void {
if(data.x == this._data.x && data.y == this._data.y){
this.setData(data);
}
}
protected onDeleteBuild(id: number, x: number, y: number): void {
if(x == this._data.x && y == this._data.y){
this.node.parent = null;
}
}
protected onClickUpBuild(): void {
this._cmd.upBuild(this._data.x, this._data.y);
}
protected onClickDestroyBuild(): void {
this._cmd.delBuild(this._data.x, this._data.y);
}
protected onClickClose(): void {
this.node.active = false;
}
public startCountDownTime(){
this.stopCountDownTime();
this.schedule(this.countDownTime, 1.0);
this.countDownTime();
}
public countDownTime() {
if (this._data.isBuilding()){
this.timeLab.string = "建设中..." + DateUtil.leftTimeStr(this._data.endTime);
} else if(this._data.isUping()){
this.timeLab.string = "升级中..." + DateUtil.leftTimeStr(this._data.endTime);
} else if(this._data.isDestroying()){
this.timeLab.string = "拆除中..." + DateUtil.leftTimeStr(this._data.endTime);
}else{
this.timeLab.string = "";
this.stopCountDownTime();
}
}
public stopCountDownTime() {
this.unschedule(this.countDownTime);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "79f56279-7997-4a57-8064-5efeecf793ac",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,179 @@
import { _decorator, Component, Label, Prefab, Node, Layout, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import GeneralItemLogic, { GeneralItemType } from "./GeneralItemLogic";
@ccclass('GeneralAddPrLogic')
export default class GeneralAddPrLogic extends Component {
@property(Label)
nameLab: Label = null;
@property(Prefab)
generalItemPrefab: Prefab = null;
@property(Node)
generalItemParent: Node = null;
@property(Layout)
srollLayout:Layout = null;
@property(Label)
prLabel: Label = null;
@property(Node)
addPr: Node = null;
private _currData:GeneralData = null;
private _cfgData:GeneralConfig = null;
private _generalNode:Node = null;
private _nameObj:any = {};
private _addPrObj:any = {};
private _addPrArr:string[] = [];
private _canUsePr:number = -1;
private _step:number = 100;
protected _curAll:number = 0;
@property([Node])
prItems: Node[] = [];
protected onLoad():void{
this._generalNode = instantiate(this.generalItemPrefab);
this._generalNode.parent = this.generalItemParent;
this._nameObj = {
force:"武力",
strategy:"战略",
defense:"防御",
speed:"速度",
destroy:"破坏",
};
this._addPrArr = ["force","strategy","defense","speed","destroy"]
}
public setData(cfgData:any,curData:any):void{
console.log("curData:",curData)
this._canUsePr =-1;
this._currData = curData;
this._cfgData = cfgData;
this.nameLab.string = this._cfgData.name;
var com = this._generalNode.getComponent(GeneralItemLogic);
if(com){
com.updateItem(this._currData, GeneralItemType.GeneralNoThing);
}
this._addPrObj = {
force:this._currData.force_added,
strategy:this._currData.strategy_added,
defense:this._currData.defense_added,
speed:this._currData.speed_added,
destroy:this._currData.destroy_added,
};
this._curAll = Math.abs(this._currData.hasPrPoint - this._currData.usePrPoint);
this.updateView();
}
protected updateView():void{
var children = this.srollLayout.node.children;
var i = 0;
for(var key in this._nameObj){
children[i].getChildByName("New Label").getComponent(Label).string = this._nameObj[key] +":" +
GeneralData.getPrStr(this._cfgData[key],this._addPrObj[key],this._currData.level,this._cfgData[key+"_grow"]);
var node:Label = children[i].getChildByName("New Sprite").getChildByName("change Label").getComponent(Label);
node.string = this._addPrObj[key]/this._step +''
i++;
}
if(this._canUsePr == -1){
this._canUsePr = Math.abs(this._currData.hasPrPoint - this._currData.usePrPoint);
}
this.prLabel.string = "可用属性点:" + this._canUsePr/this._step + "/" + this._currData.hasPrPoint/this._step;
this.addPr.active = this._currData.hasPrPoint > 0?true:false;
}
protected plus(target:any,index:number = 0):void{
var num:number = this._addPrObj[this._addPrArr[index]]
if(!this.isCanePlus() || num >= this._currData.hasPrPoint){
return
}
num = num + this._step;
num = num > this._currData.hasPrPoint?this._currData.hasPrPoint:num;
this._addPrObj[this._addPrArr[index]] = num;
this._canUsePr -= this._step
this.updateView();
}
protected reduce(target:any,index:number = 0):void{
var num:number = this._addPrObj[this._addPrArr[index]]
if(!this.isCaneReduce() || num == 0){
return
}
num = num - this._step;
num = num < 0?0:num;
this._addPrObj[this._addPrArr[index]] = num;
this._canUsePr += this._step
this.updateView();
}
private getAllUse():number{
var num:number = 0;
for(var key in this._addPrObj){
num +=this._addPrObj[key];
}
return num
}
private isCanePlus():boolean{
var all:number = this.getAllUse();
if(all + this._step > this._currData.hasPrPoint){
return false;
}
return true;
}
private isCaneReduce():boolean{
var all:number = this.getAllUse();
if(all - this._step < 0){
return false;
}
return true;
}
protected onClickAddPr():void{
GeneralCommand.getInstance().addPrGeneral(
this._currData.id,
this._addPrObj.force,
this._addPrObj.strategy,
this._addPrObj.defense,
this._addPrObj.speed,
this._addPrObj.destroy);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "53556fc9-1dce-4bdd-94b9-70704d738fe4",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,100 @@
import { _decorator, Component, Label, Prefab, Node, ScrollView, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralConfig, GeneralData } from "../../general/GeneralProxy";
import { GeneralItemType } from "./GeneralItemLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('GeneralComposeLogic')
export default class GeneralComposeLogic extends Component {
@property(Label)
nameLab: Label = null;
@property(Prefab)
generalItemPrefab: Prefab = null;
@property(Node)
generalItemParent: Node = null;
@property(ScrollView)
scrollView:ScrollView = null;
@property(Node)
composeNode: Node = null;
private _currData:GeneralData = null;
private _cfgData:GeneralConfig = null;
private _generalNode:Node = null;
private _gIdsArr:number[] = [];
protected onLoad():void{
this._generalNode = instantiate(this.generalItemPrefab);
this._generalNode.parent = this.generalItemParent;
}
protected onEnable():void{
EventMgr.on("open_general_select", this.selectItem, this);
this.updataView();
}
protected onDisable():void{
EventMgr.targetOff(this);
}
private selectItem(cfg:any,curData:any):void{
var index = this._gIdsArr.indexOf(curData.id);
if(index >= 0){
this._gIdsArr.splice(index,1)
}else{
this._gIdsArr.push(curData.id);
}
this.updataView();
}
public setData(cfgData:any,curData:any):void{
this._currData = curData;
this._cfgData = cfgData;
this._gIdsArr = [];
var com = this._generalNode.getComponent("GeneralItemLogic");
if(com){
com.updateItem(this._currData,GeneralItemType.GeneralNoThing);
}
this.nameLab.string = this._cfgData.name;
this.updateGeneral();
this.updataView();
}
protected updateGeneral():void{
let list:any[] = GeneralCommand.getInstance().proxy.getComposeGenerals(this._cfgData.cfgId,this._currData.id);
let listTemp = list.concat();
listTemp.forEach(item => {
item.type = GeneralItemType.GeneralSelect;
})
var comp = this.scrollView.node.getComponent("ListLogic");
comp.setData(listTemp);
}
private updataView():void{
this.composeNode.active = ((this._gIdsArr.length > 0) && (this._currData.star_lv < this._cfgData.star));
}
protected onCompose(): void {
GeneralCommand.getInstance().composeGeneral(this._currData.id,this._gIdsArr);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "146ed275-dc40-4cfd-97ad-fcd747dd8e45",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,118 @@
import { _decorator, Component, ScrollView, Node, Prefab, instantiate, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import GeneralItemLogic, { GeneralItemType } from "./GeneralItemLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('GeneralConvertLogic')
export default class GeneralConvertLogic extends Component {
@property(ScrollView)
scrollView:ScrollView = null;
@property(Node)
contentNode:Node = null;
@property(Prefab)
generalPrefab = null;
private _cunGeneral:number[] = [];
private _upMap:Map<number, Node> = new Map<number, Node>();
private _selectMap:Map<number, Node> = new Map<number, Node>();
protected onEnable():void{
this.initGeneralCfg();
EventMgr.on("open_general_select", this.onSelectGeneral, this);
EventMgr.on("general_convert", this.onGeneralConvert, this);
}
protected onDisable():void{
EventMgr.targetOff(this);
}
protected onClickClose(): void {
this.node.active = false;
EventMgr.emit("open_general");
}
protected initGeneralCfg():void{
let list:any[] = GeneralCommand.getInstance().proxy.getMyGeneralsNotUse();
let listTemp = list.concat();
listTemp.forEach(item => {
item.type = GeneralItemType.GeneralSelect;
})
for(var i = 0; i < listTemp.length ;i++){
if(this._cunGeneral.indexOf(listTemp[i].id) >= 0 ){
listTemp.splice(i,1);
i--;
}
}
var comp = this.scrollView.node.getComponent("ListLogic");
comp.setData(listTemp);
}
protected onSelectGeneral(cfgData: any, curData: any, node:Node): void {
//console.log("curData:", curData, this._upMap.size);
var has = this._upMap.has(curData.id);
if (has){
var obj = this._upMap.get(curData.id);
obj.parent = null;
this._upMap.delete(curData.id);
var g = this._selectMap.get(curData.id);
if (g){
g.getComponent(GeneralItemLogic).select(false);
}
}else{
if (this._upMap.size >= 9){
node.getComponent(GeneralItemLogic).select(false);
return
}
var g:Node = instantiate(this.generalPrefab);
g.getComponent(GeneralItemLogic).setData(curData, GeneralItemType.GeneralSelect);
g.getComponent(GeneralItemLogic).select(true);
g.getComponent(UITransform).width *=0.5;
g.getComponent(UITransform).height*=0.5;
g.scale = new Vec3(0.5, 0.5, 0.5);
g.parent = this.contentNode;
this._upMap.set(curData.id, g);
this._selectMap.set(curData.id, node);
}
}
protected onGeneralConvert(msg:any):void{
EventMgr.emit("show_toast", "获得金币:"+msg.add_gold);
this._upMap.forEach((g:Node) => {
g.parent = null;
});
this._upMap.clear();
this._selectMap.clear();
this.initGeneralCfg();
}
protected onClickOK():void{
var keys = this._upMap.keys();
var ids = Array.from(keys);
GeneralCommand.getInstance().convert(ids);
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8c6e4078-04fd-4430-8f46-59b03888e083",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,172 @@
import { _decorator, Component, Label, Layout, Prefab, Node, EventTouch, instantiate } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import {GeneralData } from "../../general/GeneralProxy";
import SkillCommand from "../../skill/SkillCommand";
import GeneralItemLogic, { GeneralItemType } from "./GeneralItemLogic";
import SkillIconLogic from "./SkillIconLogic";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('GeneralDesLogic')
export default class GeneralDesLogic extends Component {
@property(Label)
nameLab: Label = null;
@property(Layout)
srollLayout:Layout = null;
@property(Label)
lvLabel: Label = null;
@property(Label)
foreLabel: Label = null;
@property(Label)
defenseLabel: Label = null;
@property(Label)
speedLabel: Label = null;
@property(Label)
strategyLabel: Label = null;
@property(Label)
destroyLabel: Label = null;
@property(Label)
expLabel: Label = null;
@property(Label)
powerLabel: Label = null;
@property(Label)
costLabel: Label = null;
@property(Prefab)
generalItemPrefab: Prefab = null;
@property(Node)
generalItemParent: Node = null;
@property([Node])
skillIcons: Node[] = [];
@property([Label])
skillNameLab: Label[] = [];
private _currData:GeneralData = null;
private _cfgData:any = null;
private _nameObj:any = {};
private _addPrObj:any = {};
private _generalNode:Node = null;
protected onEnable(){
EventMgr.on("update_general", this.updateGeneral, this)
}
protected onDisable(){
EventMgr.targetOff(this);
}
protected onLoad():void{
this._nameObj = {
force:"武力",
strategy:"战略",
defense:"防御",
speed:"速度",
destroy:"破坏",
};
this._generalNode = instantiate(this.generalItemPrefab);
this._generalNode.parent = this.generalItemParent;
}
protected updateGeneral(){
var data = GeneralCommand.getInstance().proxy.getMyGeneral(this._currData.id);
if(data){
this.setData(this._cfgData, data);
}
}
public setData(cfgData:any, curData:GeneralData):void{
this._currData = curData;
this._cfgData = cfgData;
var nextCfg = GeneralCommand.getInstance().proxy.getGeneralLevelCfg(this._currData.level + 1);
var levelExp = nextCfg?nextCfg.exp:"MAX";
var maxLevel: number = GeneralCommand.getInstance().proxy.getMaxLevel();
this.lvLabel.string = '等级:' + this._currData.level + "/" + maxLevel;
this.expLabel.string = "经验:" + curData.exp +"/" + levelExp;
this.nameLab.string = this._cfgData.name;
this._addPrObj = {
force:this._currData.force_added,
strategy:this._currData.strategy_added,
defense:this._currData.defense_added,
speed:this._currData.speed_added,
destroy:this._currData.destroy_added,
};
this.foreLabel.string = this.getAttrStr("force");
this.strategyLabel.string = this.getAttrStr("strategy");
this.defenseLabel.string = this.getAttrStr("defense");
this.speedLabel.string = this.getAttrStr("speed");
this.destroyLabel.string = this.getAttrStr("destroy");
var com = this._generalNode.getComponent(GeneralItemLogic);
if(com){
com.updateItem(this._currData, GeneralItemType.GeneralNoThing);
}
this.powerLabel.string = "体力:" + curData.physical_power + "/" + cfgData.physical_power_limit;
this.costLabel.string = "cost:"+cfgData.cost;
for (let index = 0; index < curData.skills.length; index++) {
let gSkill = curData.skills[index];
let icon = this.skillIcons[index];
let iconNameLab = this.skillNameLab[index];
if(gSkill == null){
icon.getComponent(SkillIconLogic).setData(null, null);
iconNameLab.string = "";
}else{
let skillConf = SkillCommand.getInstance().proxy.getSkillCfg(gSkill.cfgId);
let skill = SkillCommand.getInstance().proxy.getSkill(gSkill.cfgId);
if(skillConf && skill){
icon.getComponent(SkillIconLogic).setData(skill, gSkill);
iconNameLab.string = skillConf.name;
}else{
icon.getComponent(SkillIconLogic).setData(null, null);
iconNameLab.string = "";
}
}
}
}
private getAttrStr(key: string) :string{
var str = GeneralData.getPrStr(this._cfgData[key], this._addPrObj[key], this._currData.level, this._cfgData[key + "_grow"])
return this._nameObj[key] + ":" + str;
}
protected onClickSkill(event: EventTouch, pos){
console.log("event", event, pos);
var node: Node = event.target;
var isEmpty = node.getComponent(SkillIconLogic).isEmpty();
if(isEmpty){
EventMgr.emit("open_skill", 1, this._currData, pos);
}else{
let skill = node.getComponent(SkillIconLogic).getSkill();
EventMgr.emit("open_skillInfo", skill, 2, this._currData, pos);
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4986f436-70f5-4373-9813-61a448f35b77",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,39 @@
import { _decorator, Component, Sprite, SpriteFrame, resources } from 'cc';
const {ccclass} = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
@ccclass('GeneralHeadLogic')
export default class GeneralHeadLogic extends Component {
public setHeadId(id:number) {
// console.log("setHeadId:", id);
var frame = GeneralCommand.getInstance().proxy.getGeneralTex(id);
if(frame){
var sp = this.node.getComponent(Sprite);
if(sp){
sp.spriteFrame = frame;
}
}else{
console.log("load setHeadId:", id);
resources.load("./generalpic/card_" + id + "/spriteFrame", SpriteFrame,
(finish: number, total: number) => {
},
(error: Error, asset: any) => {
if (error != null) {
console.log("setHeadId error:", error.message);
}else{
var frame = asset as SpriteFrame;
var sp = this.node.getComponent(Sprite);
if(sp){
sp.spriteFrame = frame;
}
GeneralCommand.getInstance().proxy.setGeneralTex(id, frame);
}
});
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e558b072-202c-4577-9ca7-07e5ee9fef5b",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,101 @@
import { _decorator, Component, Prefab, ToggleContainer, Node, instantiate } from 'cc';
import { EventMgr } from '../../utils/EventMgr';
const { ccclass, property } = _decorator;
@ccclass('GeneralInfoLogic')
export default class GeneralInfoLogic extends Component {
@property(Prefab)
generalDesPrefab: Prefab = null;
@property(Prefab)
generalComposePrefab: Prefab = null;
@property(Prefab)
generalAddPrefab: Prefab = null;
@property(ToggleContainer)
generalToggleContainer: ToggleContainer = null;
private _currData:any = null;
private _cfgData:any = null;
private _curIndex:number = 0;
private _nodeList:Node[] = [];
protected onLoad():void{
EventMgr.on("update_one_generals", this.updateOnce, this);
var des = instantiate(this.generalDesPrefab);
des.parent = this.node;
des.active = false;
var comp = instantiate(this.generalComposePrefab);
comp.parent = this.node;
comp.active = false;
var addd = instantiate(this.generalAddPrefab);
addd.parent = this.node;
addd.active = false;
this._nodeList[0] = des;
this._nodeList[1] = comp;
this._nodeList[2] = addd;
}
protected updateOnce(curData:any):void{
this.setData(this._cfgData,curData)
}
protected onDestroy():void{
this._nodeList = []
EventMgr.targetOff(this);
}
protected onClickClose(): void {
this.node.active = false;
}
public setData(cfgData:any,curData:any):void{
this._currData = curData;
this._cfgData = cfgData;
this.setIndex(this._curIndex);
}
protected setIndex(index:number = 0):void{
this._curIndex = index;
this.allVisible();
this._nodeList[index].active = true;
this.generalToggleContainer.toggleItems[index].isChecked = true;
let logicNameArr:string[] = ["GeneralDesLogic","GeneralComposeLogic","GeneralAddPrLogic"]
let com = this._nodeList[index].getComponent(logicNameArr[index]);
if(com){
com.setData(this._cfgData, this._currData);
}
}
protected allVisible():void{
for(var i = 0; i < this._nodeList.length; i++){
this._nodeList[i].active = false;
}
}
protected selectHandle(event:any,other:any):void{
// console.log("event:",event,other)
this.setIndex(other)
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "96f821a7-11eb-4c5e-a507-83f8bf493b45",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,216 @@
import { _decorator, Component, Label, Sprite, Layout, Node, color } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralCampType, GeneralData } from "../../general/GeneralProxy";
import GeneralHeadLogic from "./GeneralHeadLogic";
import { EventMgr } from '../../utils/EventMgr';
// /**军队命令*/
export class GeneralItemType {
static GeneralInfo: number = 0;//武将详情
static GeneralDispose: number = 1;//武将上阵
static GeneralConScript: number = 2;//武将征兵
static GeneralNoThing: number = 3;//无用
static GeneralSelect: number = 4;//选择
}
@ccclass('GeneralItemLogic')
export default class GeneralItemLogic extends Component {
@property(Label)
nameLabel: Label = null;
@property(Label)
lvLabel: Label = null;
@property(Sprite)
spritePic:Sprite = null;
@property(Label)
costLabel: Label = null;
@property(Label)
campLabel: Label = null;
@property(Label)
armLabel: Label = null;
@property(Layout)
starLayout:Layout = null;
@property(Node)
delNode:Node = null;
@property(Node)
useNode:Node = null;
@property(Node)
selectNode:Node = null;
private _curData:any = null;
private _type:number = -1;
private _position:number = 0;
private _cityData:any = null;
private _orderId:number = 1;
private _isSelect:boolean = false;
protected onLoad():void{
this.delNode.active = false;
this._isSelect = false;
}
public setData(curData:GeneralData,type:number = 0,position:number = 0):void{
this.updateItem(curData);
}
public updateItem(curData:any):void{
this.updateView(curData);
this._type = this._curData.type == undefined?-1:this._curData.type;
this._position = this._curData.position == undefined?0:this._curData.position;
}
protected updateView(curData:any):void{
this._curData = curData;
var cfgData = GeneralCommand.getInstance().proxy.getGeneralCfg(this._curData.cfgId);
this.nameLabel.string = cfgData.name
this.lvLabel.string = " Lv." + this._curData.level ;
this.spritePic.getComponent(GeneralHeadLogic).setHeadId(this._curData.cfgId);
this.showStar(cfgData.star,this._curData.star_lv);
this.delNode.active = false;
if(cfgData.camp == GeneralCampType.Han){
this.campLabel.string = "汉";
}else if(cfgData.camp == GeneralCampType.Qun){
this.campLabel.string = "群";
}else if(cfgData.camp == GeneralCampType.Wei){
this.campLabel.string = "魏";
}else if(cfgData.camp == GeneralCampType.Shu){
this.campLabel.string = "蜀";
}else if(cfgData.camp == GeneralCampType.Wu){
this.campLabel.string = "吴";
}
this.armLabel.string = this.armstr(cfgData.arms);
if(this.useNode){
if(this._type == GeneralItemType.GeneralInfo && this._curData.order > 0){
this.useNode.active = true;
}else{
this.useNode.active = false;
}
}
if(this.costLabel){
this.costLabel.string = cfgData.cost + "";
}
this.select(false);
}
protected armstr(arms:number []): string{
// console.log("armstr:", arms);
var str = ""
if(arms.indexOf(1)>=0 || arms.indexOf(4)>=0 || arms.indexOf(7)>=0){
str += "步"
}else if(arms.indexOf(2)>=0 || arms.indexOf(5)>=0 || arms.indexOf(8)>=0){
str += "弓"
}else if(arms.indexOf(3)>=0 || arms.indexOf(6)>=0 || arms.indexOf(9)>=0){
str += "骑"
}
return str;
}
public select(flag:boolean):void{
if(this.selectNode){
this.selectNode.active = flag;
}
this._isSelect = flag;
}
protected showStar(star:number = 3,star_lv:number = 0):void{
var childen = this.starLayout.node.children;
for(var i = 0;i<childen.length;i++){
if(i < star){
childen[i].active = true;
if(i < star_lv){
childen[i].getComponent(Sprite).color = color(255,0,0);
}else{
childen[i].getComponent(Sprite).color = color(255,255,255);
}
}else{
childen[i].active = false;
}
}
}
protected setOtherData(cityData:any,orderId:number = 1):void{
this._cityData = cityData;
this._orderId = orderId
this.delNode.active = true;
}
protected onClickGeneral(event:any): void {
if(this._curData){
var cfgData = this._curData.config;
console.log("onClickGeneral:", this._type);
//武将详情
if(this._type == GeneralItemType.GeneralInfo){
EventMgr.emit("open_general_des",cfgData, this._curData);
}
//上阵
else if(this._type == GeneralItemType.GeneralDispose){
EventMgr.emit("chosed_general", cfgData, this._curData, this._position);
}
//征兵
else if(this._type == GeneralItemType.GeneralConScript){
EventMgr.emit("open_army_conscript", this._orderId, this._cityData);
}
else if(this._type == GeneralItemType.GeneralSelect){
this._isSelect = !this._isSelect;
this.select(this._isSelect);
EventMgr.emit("open_general_select", cfgData, this._curData, this.node);
}
}
}
/**
* 下阵
*/
protected onDelete():void{
var cfgData = this._curData.config;
EventMgr.emit("chosed_general",cfgData,this._curData,-1);
}
/**
* 战报的
* @param curData
*/
public setWarReportData(curData:any):void{
this.updateView(curData)
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "96e83c2a-c652-46c2-9ae9-5fc532a302b7",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,89 @@
import { _decorator, Component, ScrollView, Label } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import MapUICommand from "./MapUICommand";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('GeneralListLogic')
export default class GeneralListLogic extends Component {
@property(ScrollView)
scrollView:ScrollView = null;
@property(Label)
cntLab:Label = null;
private _cunGeneral:number[] = [];
private _type:number = 0;
private _position:number = 0;
protected onEnable():void{
EventMgr.on("update_my_generals", this.initGeneralCfg, this);
EventMgr.on("general_convert", this.initGeneralCfg, this);
EventMgr.on("chosed_general", this.onClickClose, this);
}
protected onDisable():void{
EventMgr.targetOff(this);
}
protected onClickClose(): void {
this.node.active = false;
}
protected onClickConvert(): void {
EventMgr.emit("open_general_convert");
this.node.active = false;
}
protected onTuJianConvert(): void {
EventMgr.emit("open_general_roster");
this.node.active = false;
}
protected initGeneralCfg():void{
var basic = MapUICommand.getInstance().proxy.getBasicGeneral();
var cnt = GeneralCommand.getInstance().proxy.getMyActiveGeneralCnt();
this.cntLab.string = "(" + cnt + "/" + basic.limit + ")";
let list:any[] = GeneralCommand.getInstance().proxy.getUseGenerals();
let listTemp = list.concat();
listTemp.forEach(item => {
item.type = this._type;
item.position = this._position;
})
for(var i = 0; i < listTemp.length ;i++){
if(this._cunGeneral.indexOf(listTemp[i].id) >= 0 ){
listTemp.splice(i,1);
i--;
}
}
var comp = this.scrollView.node.getComponent("ListLogic");
comp.setData(listTemp);
}
public setData(data:number[],type:number = 0,position:number = 0):void{
this._cunGeneral = [];
if(data && data.length > 0){
this._cunGeneral = data;
}
this._type = type;
this._position = position;
this.initGeneralCfg();
GeneralCommand.getInstance().qryMyGenerals();
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4a20faad-c58f-419c-9ce2-600a2db74d34",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

View File

@@ -0,0 +1,47 @@
import { _decorator, Component, ScrollView } from 'cc';
const { ccclass, property } = _decorator;
import GeneralCommand from "../../general/GeneralCommand";
import { GeneralConfig } from "../../general/GeneralProxy";
import { EventMgr } from '../../utils/EventMgr';
@ccclass('GeneralRosterListLogic')
export default class GeneralRosterListLogic extends Component {
@property(ScrollView)
scrollView:ScrollView = null;
protected onEnable(): void {
this.initGeneralCfg();
}
protected onClickClose(): void {
this.node.active = false;
EventMgr.emit("open_general");
}
protected initGeneralCfg():void{
let cfgs = GeneralCommand.getInstance().proxy.getGeneralAllCfg();
var arr = Array.from(cfgs.values());
arr.sort(this.sortStar);
var comp = this.scrollView.node.getComponent("ListLogic");
comp.setData(arr);
}
protected sortStar(a: GeneralConfig, b: GeneralConfig): number {
if(a.star < b.star){
return 1;
}else if(a.star == b.star){
return a.cfgId - b.cfgId;
}else{
return -1;
}
}
}

View File

@@ -0,0 +1,11 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "cd7a369e-5a03-44d0-ab87-294694e4241f",
"files": [],
"subMetas": {},
"userData": {
"simulateGlobals": []
}
}

Some files were not shown because too many files have changed in this diff Show More