| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import { _decorator, Component, Node, Sprite, Label, sp, SpriteFrame, Vec3, Animation } from 'cc';
- import { BattleData } from '../battle/BattleData';
- import { DataSystem } from '../core/data/DataSystem';
- import { Http } from '../core/net/Http';
- import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
- import { CountDown } from '../core/ui/CountDown';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../core/ui/window/WindowSystem';
- import { Utils } from '../core/utils/Utils';
- import { ConfigData } from '../data/ConfigData';
- import { UserData } from '../data/UserData';
- import { Guide, GuideType } from '../guide/Guide';
- import { FormationData } from '../hero/formation/FormationData';
- import { MarshalData } from '../marshal/MarshalData';
- const { ccclass, property } = _decorator;
- @ccclass('MarshalSkillBar')
- export class MarshalSkillBar extends Component {
- @property({ type: Http, displayName: "Http组件", tooltip: "Http组件" }) http: Http = null;
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: Node, displayName: "统帅技能节点", tooltip: "统帅技能节点" }) nodeMarshal: Node = null;
- @property({ type: Sprite, displayName: "技能头像", tooltip: "技能头像" }) imgSkill: Sprite = null;
- @property({ type: Label, displayName: "技能名称", tooltip: "技能名称" }) txtName: Label = null;
- @property({ type: Node, displayName: "冷却节点", tooltip: "冷却节点" }) nodeCooling: Node = null;
- @property({ type: Sprite, displayName: "等级进度图", tooltip: "等级进度图" }) progressLv: Sprite = null;
- @property({ type: Node, displayName: "倒计时指针节点", tooltip: "倒计时指针节点" }) progressNeedle: Node = null;
- @property({ type: Label, displayName: "文本冷却时间", tooltip: "文本冷却时间" }) txtTimer: Label = null;
- @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
- @property({ type: sp.Skeleton, displayName: "冷却完成动画", tooltip: "冷却完成动画" }) spineCool: sp.Skeleton = null;
- @property({ type: Node, displayName: "气泡", tooltip: "气泡" }) nodeTip: Node = null;
- private cfg: any;
- private remaindTime = 0;
- private isCanClick = false;
- onLoad() {
- this.cfg = DataSystem.getData(ConfigData).get("serverConfig");
- }
- async start() {
- this.updateMarshalSkillCool();
- }
- private async updateMarshalSkillCool() {
- let formationData = DataSystem.getData(FormationData);
- let unlockLevel = parseInt(DataSystem.getData(ConfigData).get("serverConfig").embattle_open.split(",")[4])
- let isUnlock = DataSystem.getData(UserData).level >= unlockLevel;
- let isExistMarshal = isUnlock && formationData.has(5) && formationData.get(5) != null && formationData.get(5) > 0;
- this.nodeMarshal.active = isExistMarshal;
- this.nodeTip.active = isUnlock && formationData.has(5) && formationData.get(5) == null;
- !isExistMarshal && this.nodeTip.getComponent(Animation).play();
- if (!isExistMarshal) return;
- let marshalData = DataSystem.getData(MarshalData);
- if (!marshalData.marshalSkillData) await marshalData.init();
- if (marshalData.defaultId <= 0) return;
- let date = new Date();
- let detlaTime = date.getTime() - marshalData.skillCoolingTime;
- if (detlaTime >= this.cfg.skillCD * 1000) {
- this.remaindTime = 0;
- } else {
- this.remaindTime = this.cfg.skillCD - detlaTime * 0.001;
- }
- this.txtTimer.string = this.remaindTime > 0 ? Utils.formatCountDown(this.remaindTime * 1000) : "";
- this.remaindTime == 0 && this.countDown.stop();
- if (!this.countDown.running && this.remaindTime) { this.countDown.value = this.remaindTime; this.countDown.play(); }
- let skillData = DataSystem.getData(ConfigData).get("skill")[marshalData.defaultId.toString()];
- //let skillData = marshalData.skillData[marshalData.defaultId];
- this.progressLv.fillRange = marshalData.marshalSkillData.lvMarshalSkill.get(marshalData.defaultId) / 3;
- this.txtName.string = skillData.name;
- this.nodeCooling.active = this.remaindTime > 0;
- this.progressNeedle.angle = 360 / this.cfg.skillCD * this.remaindTime;
- this.isCanClick = this.remaindTime == 0;
- this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
- }
- update() {
- this.watchFormation(5);
- this.watchDefaultSkill();
- this.watchDefaultSkillCd();
- }
- watchFormation(formationID: number) {
- if (DataSystem.watch(FormationData, formationID)) {
- this.updateMarshalSkillCool();
- }
- }
- watchDefaultSkill() {
- DataSystem.watch(MarshalData, "defaultId") && this.updateDefaultSkill();
- }
- watchDefaultSkillCd() {
- if (DataSystem.watch(MarshalData, "skillCoolingTime")) {
- this.updateMarshalSkillCool();
- this.remaindTime == 0 && DataSystem.getData(FormationData).get(5) > 0 && this.playAni();
- }
- }
- /**更新默认技能*/
- async updateDefaultSkill() {
- let marshalData = DataSystem.getData(MarshalData);
- let skillData = DataSystem.getData(ConfigData).get("skill")[marshalData.defaultId.toString()];
- //let skillData = marshalData.skillData[marshalData.defaultId];
- this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
- this.progressLv.fillRange = marshalData.marshalSkillData.lvMarshalSkill.get(marshalData.defaultId) / 3;
- this.txtName.string = skillData.name;
- }
- public updateTxtTime(progress) {
- this.txtTimer.string = Utils.formatCountDown(progress * 1000);
- this.progressNeedle.angle = 360 / this.cfg.skillCD * progress;
- }
- public finishCooling() {
- this.remaindTime = 0;
- this.nodeCooling.active = false;
- this.isCanClick = true;
- this.txtTimer.string = "";
- this.playAni();
- }
- private async playAni() {
- this.spineCool.node.setScale(Vec3.ONE);
- this.spineCool.setAnimation(0, "animation", false);
- await new Promise<void>(resolve => { setTimeout(() => resolve(), (this.spineCool.findAnimation("animation").duration + 0.1) * 1000) });
- this.spineCool.node.setScale(Vec3.ZERO);
- }
- private async onClickSkill() {
- Guide.close(GuideType.Marshal);
- if (!this.isCanClick) {
- WindowSystem.open("prefabs/ui/marshalStage/marshalSkillSwitch", WindowOpenMode.NotCloseAndAdd);
- return;
- }
- let marshalData = DataSystem.getData(MarshalData);
- marshalData.skillCoolingTime = (new Date()).getTime();
- localStorage.setItem("MarshalCoolTime", marshalData.skillCoolingTime.toString());
- this.updateMarshalSkillCool();
- //技能效果 TODO
- let skillId = marshalData.defaultId - 110000;
- DataSystem.getData(BattleData).useLeaderSkill = { id: skillId, lv: marshalData.marshalSkillData.lvMarshalSkill.get(marshalData.defaultId) };
- let result = await this.http.send("/api/task/AddCommanderSkillTimes");
- console.log("addCommander: " + result.code);
- }
- private onClickSwitchSkill() {
- WindowSystem.open("prefabs/ui/marshalStage/marshalSkillSwitch", WindowOpenMode.NotCloseAndAdd);
- }
- }
|