/** @format */ import { EventAttack, EventBase, EventDie, EventGraphicsDraw, EventHPChange, EventRoleTip, EventSkill, EventType, } from './NodeEvent' import {ccUtils} from '../../utils/ccUtils' import FrameAnimation from '../../uiutils/FrameAnimation' import {Data} from '../../GameControl' import {IRoleConfig} from '../../config/RoleConfig' import {GAME_ROLE_TIP, MONSTER_TYPE, ROLE_TYPE} from '../../enums/Enum' import {EventProcess} from './EventProcess' import {IBuff} from './GameInterface' import {FlashColor} from './FlashColor' const {ccclass, property} = cc._decorator @ccclass export class RoleEventProcess extends EventProcess { public roleConfig: IRoleConfig public isFriend: boolean private eventDeath: EventDie private eventRoleTipMap: Map private frameAniNode: cc.Node private roleTipParents: Map private roleHeight: number = 100 private roleWidth: number = 60 private HPNode: cc.Node private HP: cc.Node private HPS: cc.Node private HPShield: cc.Node protected onLoad() { this.HPNode = cc.find('hpNode', this.node) this.HP = cc.find('hpNode/HP', this.node) this.HPShield = cc.find('hpNode/HPshield', this.node) this.HPS = cc.find('hpNode/HPS', this.node) this.frameAniNode = cc.find('fa', this.node) this.roleTipParents = new Map() this.eventRoleTipMap = new Map() for (let key in GAME_ROLE_TIP) { let parent = cc.find(`tips/${key}Parent`, this.node) if (!parent) { console.error('role预制体tips下缺少' + key + '父节点') } else { this.roleTipParents.set(key, parent) this.eventRoleTipMap.set(key, []) } } } onAttach(): void { this.frameAnimation = this.frameAniNode.getComponent(FrameAnimation) this._initHPNode() } onDetach(): void {} init(cfg: IRoleConfig, isFriend: boolean, width: number, height: number) { this.isFriend = isFriend this.roleConfig = cfg this.roleWidth = width this.roleHeight = height this.eventRoleTipMap.forEach((value, key) => { value.length = 0 }) this.node.name = this.roleConfig.url let entityLb = cc.find('entity', this.node) if (entityLb) entityLb.color = this.isFriend ? cc.Color.GREEN : cc.Color.RED this.HPNode.active = false } public syncDir(dir: cc.Vec2) { let scaleRate = 1 this.frameAniNode.scaleX = dir.x >= 0 ? scaleRate : -scaleRate } processEvent(event: EventBase): void { if (!cc.isValid(this.node)) return switch (event.type) { case EventType.Enter: break case EventType.Stand: break case EventType.Run: break case EventType.Attack: let attackEvent: EventAttack = event as EventAttack this.syncDir(attackEvent.dir) break case EventType.Skill: break case EventType.RoleTip: let eventRoleTip: EventRoleTip = event as EventRoleTip // let roleTips = this.eventRoleTipMap.get(eventRoleTip.tipType) // roleTips.push(eventRoleTip) this._showNextRoleTip(eventRoleTip) break case EventType.Die: this.eventDeath = event as EventDie break case EventType.HPChange: this._changeHP(event as EventHPChange) break // case EventType.BuffChange: // let eventBuff = event as EventBuffChange // this.initBuff(eventBuff.buffs) // break case EventType.GraphicsDraw: if (cc.debug.isDisplayStats()) { this.graphicsDraw(event as EventGraphicsDraw) } else { this.graphicsDraw(null) } break } } private _initHPNode() { if (!this.roleConfig) { console.warn('没有角色配置') return } let hpNode = this.HPNode let isBase = this.roleConfig.type == ROLE_TYPE.base //let hpWidth = isBase ? 200 : 100 //修改为配置 let hpWidth = this.roleConfig.hplength let hpHeight = isBase ? 20 : 10 let roleHeight = this.roleHeight let baseHeight = 454 let baseDurX = 820 - Data.game.fightSizeMaxX let baseDurY = 88 - (Data.game.fightSizeMaxY + Data.game.fightSizeMinY) / 2 hpNode.x = isBase ? (this.isFriend ? -1 : 1) * baseDurX : 0 hpNode.y = isBase ? baseHeight / 2 + baseDurY - hpHeight : roleHeight + hpHeight / 2 cc.find('green', this.HP).active = this.isFriend cc.find('red', this.HP).active = !this.isFriend this.HP.getComponent(cc.ProgressBar).barSprite = cc .find(this.isFriend ? 'green' : 'red', this.HP) .getComponent(cc.Sprite) this.setHPPbSize(this.HP, hpWidth, hpHeight) this.setHPPbSize(this.HPShield, hpWidth, hpHeight) let baseHPbg = cc.find('castle_blood_bottom', hpNode) baseHPbg.active = isBase baseHPbg.width = hpWidth + 8 baseHPbg.height = hpHeight + 8 this.HPS.width = hpWidth this.HPS.x = -hpWidth / 2 this.HPS.height = hpHeight this.HPS.children.forEach(v => (v.height = hpHeight)) } private setHPPbSize(node: cc.Node, width: number, height: number) { node.width = width node.height = height let pb = node.getComponent(cc.ProgressBar) pb.totalLength = width pb.barSprite.node.x = -width / 2 node.children.forEach(v => (v.height = height)) } private _changeHP(event: EventHPChange) { //let lastAllHp = event.HP let isFriend = this.roleConfig.type == ROLE_TYPE.normal || this.roleConfig.type == ROLE_TYPE.only || this.roleConfig.type == ROLE_TYPE.totem let isBase = this.roleConfig.type == ROLE_TYPE.base let isBoss = this.roleConfig.type == MONSTER_TYPE.boss if (!this.HPNode.active && !isBoss && !isBase && (event.HP != event.nowHP || event.shieldHP > 0) && !isFriend) this.HPNode.active = true if (!this.HPNode.active) return let allHp = event.HP //if (event.lastHP + event.lastShieldHP > lastAllHp) lastAllHp = event.lastHP + event.lastShieldHP if (event.nowHP + event.shieldHP > allHp) allHp = event.nowHP + event.shieldHP //let from = event.lastHP / lastAllHp this.HP.getComponent(cc.ProgressBar).progress = event.nowHP / allHp //let from = (event.lastHP + event.lastShieldHP) / lastAllHp this.HPShield.getComponent(cc.ProgressBar).progress = (event.nowHP + event.shieldHP) / allHp let hpCellNum = Math.ceil(allHp / 100) //if (hpCellNum > 10) hpCellNum = 10 //修改为固定10格血 if (hpCellNum > 10) hpCellNum = 10 if (hpCellNum != this.HPS.children.length) { ccUtils.instantChildren(cc.find('hp', this.HPS), hpCellNum) } } private _showNextRoleTip(roleTip: EventRoleTip) { let gameUI = this.world.fightCore //roleTips.length > 0 && if (this.node.isValid && gameUI.node.isValid) { //let roleTip: EventRoleTip = roleTips.shift() // 取出下一个提示对象 let tipNode = null let key = roleTip.tipType let pool = gameUI.roleTipPool.get(key) if (pool.size() > 0 && pool.size() < 100) { tipNode = pool.get() } else { tipNode = cc.instantiate(Data.game.gameAssetMap.get(`prefab/fight/roleTip/${key}`)) } let t = cc.tween let tipX: number, tipY: number, tipOpacity: number, moveTime: number, delayTime: number, tween: cc.Tween let scale = 1 let actionCallback = () => { tipNode.removeFromParent() gameUI.node.isValid && pool.put(tipNode) } let attackLbDur = 50 switch (roleTip.tipType) { case GAME_ROLE_TIP.buffTip: tipX = 0 tipY = this.roleHeight / 2 tipOpacity = 255 moveTime = 1 tween = t().by(moveTime, {y: this.roleHeight / 2}) let upNode = cc.find('up', tipNode) upNode.active = roleTip.num == 1 let downNode = cc.find('down', tipNode) downNode.active = roleTip.num == 2 let showNode = upNode.active ? upNode : downNode ccUtils.setLabel(roleTip.tip, showNode, 'lb') break case GAME_ROLE_TIP.hpTip: tipX = 0 tipY = 0 tipOpacity = 255 moveTime = 0.5 tween = t().by(moveTime, {y: this.roleHeight / 2}) break case GAME_ROLE_TIP.critTip: tipX = Math.randomRangeInt(-this.roleWidth / 4, this.roleWidth / 4) let left = tipX < 0 ? -1 : 1 tipY = this.roleHeight / 2 + Math.randomRangeInt(0, 20) scale = 1 tipOpacity = 255 moveTime = 1 tween = t().by(moveTime * 0.4, { x: (left * this.roleWidth) / 8, y: this.HP.height + tipNode.height + 30, }) tween = t().parallel( tween, t() .to(moveTime * 0.1, {scale: 3}) .to(moveTime * 0.3, {scale: 1}) .union(), ) tween = t().sequence(tween, t().to(moveTime, {opacity: 0}).by(moveTime, {y: 10}).union()) break case GAME_ROLE_TIP.damageTip: tipX = this.isFriend ? -attackLbDur : attackLbDur tipY = this.HP.parent.y - this.HP.height scale = 2 tipOpacity = 0 moveTime = 0.5 delayTime = 0.5 tween = t().by(moveTime, {y: 30}) tween = t().parallel(tween, t().to(moveTime, {opacity: 255, scale: 1.2}).delay(delayTime)) break case GAME_ROLE_TIP.missTip: tipX = this.isFriend ? -attackLbDur : attackLbDur tipY = this.HP.parent.y - this.HP.height tipOpacity = 0 moveTime = 0.5 delayTime = 0.5 tween = t().by(moveTime, {y: 30}) tween = t().parallel(tween, t().to(moveTime, {opacity: 255, scale: 1.2}).delay(delayTime)) break } if (roleTip.tipType != GAME_ROLE_TIP.buffTip) ccUtils.setLabel(roleTip.tip, tipNode) this.roleTipParents.get(key).addChild(tipNode) tipNode.stopAllActions() tipNode.scale = scale tipNode.x = tipX tipNode.y = tipY tipNode.opacity = tipOpacity // 执行飘出动画效果 t(tipNode).then(tween).call(actionCallback).start() // // 0.1秒后显示下一个提示 // this.scheduleOnce(() => { // this._showNextRoleTip(roleTips) // }, 0.1) } } // update (dt) {} }