123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /** @format */
- import GameUI from '../ui/GameUI'
- import {CardSkillConfig, ICardSkillConfig} from '../config/CardSkillConfig'
- import {Data, Mgr} from '../GameControl'
- import {EntryConfig, IEntryConfig} from '../config/EntryConfig'
- import {ENTRY, ROLE_TYPE} from '../enums/Enum'
- import {IRole} from '../interface/GlobalInterface'
- const {ccclass, property} = cc._decorator
- @ccclass
- export class RoleOptCell extends cc.Component {
- get canCreate(): boolean {
- return this._canCreate
- }
- set canCreate(value: boolean) {
- this._canCreate = value
- cc.find('gray', this.node).active = !value
- if (value && this.countDown <= 0 && this.gameUI.cost >= this.iRole.cfg.cost) {
- this.showCreateAni()
- }
- }
- mask: cc.Sprite = null //遮罩
- countDown: number = 0
- isStop: boolean = true //是否停止
- iRole: IRole = null
- gameUI: GameUI
- time: number = 1 //冷却时间
- createBackCostCfg: IEntryConfig
- private _canCreate: boolean = false
- onLoad() {
- this.mask = cc.find('mask', this.node).getComponent(cc.Sprite)
- this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchStart, this)
- }
- update(dt: number) {
- dt *= Data.game.gameSpeed
- if (!this.isStop && !this.gameUI.isStop) {
- this.countDown -= dt
- if (this.countDown <= 0) {
- this.countDown = 0
- this.isStop = true
- if (this.canCreate && this.gameUI.cost >= this.iRole.cfg.cost) {
- this.showCreateAni()
- }
- }
- this.mask.fillRange = this.time > 0 ? this.countDown / this.time : 0 //恢复技能
- }
- }
- init(iRole: IRole, gameUI: GameUI) {
- this.gameUI = gameUI
- this.iRole = iRole
- this.time = this.iRole.cfg.sumcd
- this.mask.fillRange = 1
- this.countDown = this.time
- this.isStop = false
- this.canCreate = true
- this.createBackCostCfg = null
- this.resetNode()
- for (let iEquip of this.iRole.equips) {
- if (iEquip && iEquip.cfg.entry) {
- let cfg = EntryConfig[iEquip.cfg.entry]
- if (cfg.type == ENTRY.createBackCost) {
- this.createBackCostCfg = cfg
- }
- }
- }
- }
- onTouchStart(e: cc.Event.EventTouch): void {
- if (!this.iRole || !this.isStop) return
- if (!this.canCreate) {
- //Mgr.ui.tip('唯一英雄只能存在一个')
- return
- }
- if (this.gameUI.cost >= this.iRole.cfg.cost) {
- this.countDown = this.time
- this.isStop = false
- this.gameUI.castCost += this.iRole.cfg.cost
- this.gameUI.cost -= this.iRole.cfg.cost
- //召唤返费
- let cfg = this.createBackCostCfg
- if (cfg && Math.getProb(cfg.rateArr[1] / Data.game.rateNum)) this.gameUI.cost += cfg.rateArr[0]
- this.gameUI.world.createRoleEntity(this.iRole.cfg.ID, false, null, this.iRole)
- //唯一卡第一次召唤后,死亡前不能再召唤
- this.canCreate = this.iRole.cfg.type != ROLE_TYPE.only
- this.resetNode()
- }
- }
- resetNode() {
- this.node.stopAllActions()
- this.node.y = 0
- this.node.scale = 1
- cc.find('light', this.node).active = false
- }
- showCreateAni() {
- cc.find('light', this.node).active = true
- let t = cc.tween
- t(this.node)
- .then(
- t().sequence(
- t().to(0.5, {y: 30}),
- t().to(0.8, {scale: 1.05}).to(0.8, {scale: 1}).delay(0.5).union().repeat(1),
- ),
- )
- .start()
- }
- }
|