import npcHelper from "../../../dataManager/npcHelper"; import { AssetsHelper } from "../../../framework/asset/AssetsHelper"; import AudioManager from "../../../framework/music/AudioManager"; import Utils from "../../../framework/utils/utils"; import effectManager from "../../../manager/effectManager"; import playerActionMgr from "../../../manager/playerActionMgr"; import { ANI_STATE } from "../../utrl/gameEnum"; import JoyStick from "../../utrl/joy_stick"; import PlayerObject from "./playerObject"; const { ccclass, requireComponent } = cc._decorator; /**玩家视图类 */ @ccclass @requireComponent(sp.Skeleton) export default class PlayerView extends cc.Component { /**spine视图 */ private spine: sp.Skeleton = null; /**视图id */ private view_id = -1; /**初始化完成 */ private inited = false; /**动画播放中 */ private playing = false; /**当前动画状态 */ cur_ani_state: ANI_STATE = null; /**男角色id组 */ private mans = [1, 2, 3, 4, 5, 11, 12, 15, 16, 17, 18, 19, 20, 21]; /**初始化 * @param view_id 视图id */ init(view_id: number) { let self = this; this.view_id = view_id; this.spine = this.node.getComponent(sp.Skeleton); let spineName = npcHelper.getModelAttrByID(view_id).modelname; let isSetSkin = view_id >= 49 && view_id <= 52 ? false : true; let spinePath = view_id >= 49 && view_id <= 52 ? 'hero/' + spineName : 'role/people'; Utils.loadSpineBunble(self.spine, spinePath, () => { if (isSetSkin) { playerActionMgr.setSkin(self.spine, view_id); } this.inited = true; let curWeapon = self.node.parent.getComponent(PlayerObject).player_prop.cur_weapon; let weaID = curWeapon ? curWeapon.id : null; self.playIdle(weaID); }); } /**播放待机动画 */ playIdle(w_id?: number) { if (!this.inited || this.cur_ani_state == ANI_STATE.idle) { return; } this.cur_ani_state = ANI_STATE.idle; playerActionMgr.playStandAnim(this.spine, this.view_id, true, w_id); } /**播放行走动画 */ playWalk(w_id?: number) { if (!this.inited || this.cur_ani_state == ANI_STATE.walk) { return; } this.cur_ani_state = ANI_STATE.walk; playerActionMgr.playWallAnim(this.spine, this.view_id, true, w_id); } /**播放攻击动画 */ playAttack(w_id?: number) { if (!this.inited || this.cur_ani_state == ANI_STATE.close_attack) { return; } let cb = () => { this.playIdle(w_id); } this.cur_ani_state = ANI_STATE.close_attack; playerActionMgr.playAttackAnim(this.spine, this.view_id, false, w_id, cb); AudioManager.play('attack'); effectManager.playEff(this.node, 'closeAttack'); } /**播放死亡动画 */ playDie(w_id?: number) { if (!this.inited || this.cur_ani_state == ANI_STATE.die) { return; } this.cur_ani_state = ANI_STATE.die; playerActionMgr.playDieAnim(this.spine, this.view_id, false, w_id); if (this.mans.indexOf(this.view_id) >= 0) { AudioManager.play('mandeath'); } else { AudioManager.play('womandeath'); } } /**播放受伤动画 */ playBeHurt(w_id?: number) { if (!this.inited || this.cur_ani_state == ANI_STATE.be_hurt) { return; } let cb = () => { this.playIdle(w_id); } this.cur_ani_state = ANI_STATE.be_hurt; playerActionMgr.playHitAnim(this.spine, this.view_id, false, w_id, cb); if (this.mans.indexOf(this.view_id) >= 0) { AudioManager.play('manhit'); } else { AudioManager.play('womanhit'); } } //枪口对僵尸 AimZombie(targetNode, w_id: number) { playerActionMgr.AimZombie(this.node, targetNode, w_id); } //开火特效 fireEff() { effectManager.fireEff(this.node, 'fire1'); AudioManager.play('gun'); } /**枪角度重置 * @param w_id 武器视图id */ resetGunAngle(w_id: number) { playerActionMgr.resetGun(this.node, w_id); } getViewId() { return this.view_id; } }