| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { _decorator, Component, Node, Sprite, Label, RichText, SpriteFrame } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { CountDown } from '../../core/ui/CountDown';
- import { StringUtils } from '../../core/utils/StringUtils';
- import { Utils } from '../../core/utils/Utils';
- import { ConfigData } from '../../data/ConfigData';
- import { Hero_Client } from '../../hero/UserHeroData';
- import { MarshalData } from '../MarshalData';
- import { MarshalSkillSystem } from '../MarshalSkillSystem';
- import { GrayEffectNode } from './GrayEffectNode';
- const { ccclass, property } = _decorator;
- /**
- * 统帅页默认技能
- * @author 郑聂华
- */
- @ccclass('DefaultSkill')
- export class DefaultSkill extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
- @property({ type: Sprite, displayName: "图_技能", tooltip: "图_技能" }) imgSkill: Sprite = null;
- @property({ type: Sprite, displayName: "图_冷却进度", tooltip: "图_冷却进度" }) imgFillCool: Sprite = null;
- @property({ type: Node, displayName: "图_冷却进度指针", tooltip: "图_冷却进度指针" }) imgNeedle: Node = null;
- @property({ type: Label, displayName: "文本_冷却计时器", tooltip: "文本_冷却计时器" }) txtTimeCool: Label = null;
- @property({ type: RichText, displayName: "文本_技能名称", tooltip: "文本_技能名称" }) txtRichName: RichText = null;
- @property({ type: RichText, displayName: "文本_技能描述", tooltip: "文本_技能描述" }) txtRichDes: RichText = null;
- @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
- @property({ type: Node, displayName: "锁", tooltip: "锁" }) nodeLock: Node = null;
- private cfg: any;
- private remaindTime = 0;
- private isExistMarshal: boolean;
- onLoad() {
- this.cfg = DataSystem.getData(ConfigData).get("serverConfig");
- }
- /**更新信息
- * @param hero 武将
- * @param skillId 技能id
- * @param lv 技能等级
- * @param isExistMarshal 是否存在统帅
- */
- public async updateInfo(hero: Hero_Client, skillId: number, lv: number, isExistMarshal: boolean) {
- this.isExistMarshal = isExistMarshal;
- let tempLv = lv < 0 ? 1 : lv;
- let marshalData = DataSystem.getData(MarshalData);
- let skillData = marshalData.skillData[skillId];
- this.updateCheckSkillCd();
- if (!this.countDown.running && this.remaindTime) { this.countDown.value = this.remaindTime; this.countDown.play(); }
- this.txtRichName.string = `<color=#4E301B>${skillData.name}</c><color=#E6181A>Lv.${tempLv}${tempLv == 3 ? "Max" : ""}</color>`;
- let addStr = MarshalSkillSystem.getSkillAddValueStr(skillData, tempLv, hero);
- let skillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, tempLv);
- let totalSkillStr = `${skillValueStr + (isExistMarshal ? "(+" + addStr + ")" : "")}`;
- let desStr = StringUtils.format(skillData.des, totalSkillStr);
- desStr = StringUtils.getRichText(desStr);
- //desStr = desStr.replace("$0", totalSkillStr);
- this.txtRichDes.string = desStr;
- (lv < 0 || !isExistMarshal) && this.lockSkill();
- this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
- }
- update() {
- this.watchDefaultSkillCd();
- }
- watchDefaultSkillCd() {
- if (DataSystem.watch(MarshalData, "skillCoolingTime")) {
- this.updateCheckSkillCd();
- this.remaindTime == 0 && this.countDown.stop();
- }
- }
- /**更新技能cd*/
- updateCheckSkillCd() {
- let marshalData = DataSystem.getData(MarshalData);
- 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.updateCdInfo();
- }
- /**倒计时更新方法*/
- public updateTxt(progress) {
- this.txtTimeCool.string = Utils.formatCountDown(progress * 1000);
- this.imgNeedle.angle = 360 / this.cfg.skillCD * progress;
- }
- /**倒计时结束方法*/
- public async finishCooling() {
- this.remaindTime = 0;
- this.updateCdInfo();
- }
- updateCdInfo() {
- this.imgNeedle.active = this.isExistMarshal && this.remaindTime > 0;
- this.imgFillCool.node.active = this.imgNeedle.active = this.isExistMarshal && this.remaindTime > 0;
- this.txtTimeCool.string = (this.isExistMarshal && this.remaindTime > 0) ? Utils.formatCountDown(this.remaindTime * 1000) : "";
- this.imgNeedle.angle = 360 / DataSystem.getData(ConfigData).get("serverConfig").skillCD * this.remaindTime;
- }
- lockSkill() {
- this.nodeLock.active = true;
- this.grayScr.setGray();
- }
- unlockSkill() {
- this.grayScr.revert();
- this.nodeLock.active = false;
- }
- }
|