first commit
This commit is contained in:
123
assets/scripts/map/entries/ArmyLogic.ts
Normal file
123
assets/scripts/map/entries/ArmyLogic.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/entries/ArmyLogic.ts.meta
Normal file
11
assets/scripts/map/entries/ArmyLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3903486e-b092-48bf-8a8f-ee81d0c4a383",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
44
assets/scripts/map/entries/BuildTagLogic.ts
Normal file
44
assets/scripts/map/entries/BuildTagLogic.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/entries/BuildTagLogic.ts.meta
Normal file
11
assets/scripts/map/entries/BuildTagLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9679b472-99f4-42e2-b6f0-081d5591e1b3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
80
assets/scripts/map/entries/BuildTipsLogic.ts
Normal file
80
assets/scripts/map/entries/BuildTipsLogic.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
assets/scripts/map/entries/BuildTipsLogic.ts.meta
Normal file
11
assets/scripts/map/entries/BuildTipsLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7ee88d2b-3d10-4f49-8c02-38fbfa9ecf71",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
92
assets/scripts/map/entries/CityLogic.ts
Normal file
92
assets/scripts/map/entries/CityLogic.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
11
assets/scripts/map/entries/CityLogic.ts.meta
Normal file
11
assets/scripts/map/entries/CityLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "44838483-d210-4672-b8de-d984de7e1102",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
95
assets/scripts/map/entries/FacilityBuildLogic.ts
Normal file
95
assets/scripts/map/entries/FacilityBuildLogic.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
11
assets/scripts/map/entries/FacilityBuildLogic.ts.meta
Normal file
11
assets/scripts/map/entries/FacilityBuildLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9f6fce8d-e1e6-4d42-a579-cee53ffcca76",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
67
assets/scripts/map/entries/ResBuildLogic.ts
Normal file
67
assets/scripts/map/entries/ResBuildLogic.ts
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/entries/ResBuildLogic.ts.meta
Normal file
11
assets/scripts/map/entries/ResBuildLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "596a6a3a-e391-40ca-851b-52dbd47a828a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
76
assets/scripts/map/entries/ResLogic.ts
Normal file
76
assets/scripts/map/entries/ResLogic.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/entries/ResLogic.ts.meta
Normal file
11
assets/scripts/map/entries/ResLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c340e883-5c05-4d66-9020-47b889ab4950",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
115
assets/scripts/map/entries/SysCityLogic.ts
Normal file
115
assets/scripts/map/entries/SysCityLogic.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
11
assets/scripts/map/entries/SysCityLogic.ts.meta
Normal file
11
assets/scripts/map/entries/SysCityLogic.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0eddd58f-a832-4b42-9318-cbda95943e82",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user