playerView.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import npcHelper from "../../../dataManager/npcHelper";
  2. import { AssetsHelper } from "../../../framework/asset/AssetsHelper";
  3. import AudioManager from "../../../framework/music/AudioManager";
  4. import Utils from "../../../framework/utils/utils";
  5. import effectManager from "../../../manager/effectManager";
  6. import playerActionMgr from "../../../manager/playerActionMgr";
  7. import { ANI_STATE } from "../../utrl/gameEnum";
  8. import JoyStick from "../../utrl/joy_stick";
  9. import PlayerObject from "./playerObject";
  10. const { ccclass, requireComponent } = cc._decorator;
  11. /**玩家视图类 */
  12. @ccclass
  13. @requireComponent(sp.Skeleton)
  14. export default class PlayerView extends cc.Component {
  15. /**spine视图 */
  16. private spine: sp.Skeleton = null;
  17. /**视图id */
  18. private view_id = -1;
  19. /**初始化完成 */
  20. private inited = false;
  21. /**动画播放中 */
  22. private playing = false;
  23. /**当前动画状态 */
  24. cur_ani_state: ANI_STATE = null;
  25. /**男角色id组 */
  26. private mans = [1, 2, 3, 4, 5, 11, 12, 15, 16, 17, 18, 19, 20, 21];
  27. /**初始化
  28. * @param view_id 视图id
  29. */
  30. init(view_id: number) {
  31. let self = this;
  32. this.view_id = view_id;
  33. this.spine = this.node.getComponent(sp.Skeleton);
  34. let spineName = npcHelper.getModelAttrByID(view_id).modelname;
  35. let isSetSkin = view_id >= 49 && view_id <= 52 ? false : true;
  36. let spinePath = view_id >= 49 && view_id <= 52 ? 'hero/' + spineName : 'role/people';
  37. Utils.loadSpineBunble(self.spine, spinePath, () => {
  38. if (isSetSkin) {
  39. playerActionMgr.setSkin(self.spine, view_id);
  40. }
  41. this.inited = true;
  42. let curWeapon = self.node.parent.getComponent(PlayerObject).player_prop.cur_weapon;
  43. let weaID = curWeapon ? curWeapon.id : null;
  44. self.playIdle(weaID);
  45. });
  46. }
  47. /**播放待机动画 */
  48. playIdle(w_id?: number) {
  49. if (!this.inited || this.cur_ani_state == ANI_STATE.idle) {
  50. return;
  51. }
  52. this.cur_ani_state = ANI_STATE.idle;
  53. playerActionMgr.playStandAnim(this.spine, this.view_id, true, w_id);
  54. }
  55. /**播放行走动画 */
  56. playWalk(w_id?: number) {
  57. if (!this.inited || this.cur_ani_state == ANI_STATE.walk) {
  58. return;
  59. }
  60. this.cur_ani_state = ANI_STATE.walk;
  61. playerActionMgr.playWallAnim(this.spine, this.view_id, true, w_id);
  62. }
  63. /**播放攻击动画 */
  64. playAttack(w_id?: number) {
  65. if (!this.inited || this.cur_ani_state == ANI_STATE.close_attack) {
  66. return;
  67. }
  68. let cb = () => {
  69. this.playIdle(w_id);
  70. }
  71. this.cur_ani_state = ANI_STATE.close_attack;
  72. playerActionMgr.playAttackAnim(this.spine, this.view_id, false, w_id, cb);
  73. AudioManager.play('attack');
  74. effectManager.playEff(this.node, 'closeAttack');
  75. }
  76. /**播放死亡动画 */
  77. playDie(w_id?: number) {
  78. if (!this.inited || this.cur_ani_state == ANI_STATE.die) {
  79. return;
  80. }
  81. this.cur_ani_state = ANI_STATE.die;
  82. playerActionMgr.playDieAnim(this.spine, this.view_id, false, w_id);
  83. if (this.mans.indexOf(this.view_id) >= 0) {
  84. AudioManager.play('mandeath');
  85. }
  86. else {
  87. AudioManager.play('womandeath');
  88. }
  89. }
  90. /**播放受伤动画 */
  91. playBeHurt(w_id?: number) {
  92. if (!this.inited || this.cur_ani_state == ANI_STATE.be_hurt) {
  93. return;
  94. }
  95. let cb = () => {
  96. this.playIdle(w_id);
  97. }
  98. this.cur_ani_state = ANI_STATE.be_hurt;
  99. playerActionMgr.playHitAnim(this.spine, this.view_id, false, w_id, cb);
  100. if (this.mans.indexOf(this.view_id) >= 0) {
  101. AudioManager.play('manhit');
  102. }
  103. else {
  104. AudioManager.play('womanhit');
  105. }
  106. }
  107. //枪口对僵尸
  108. AimZombie(targetNode, w_id: number) {
  109. playerActionMgr.AimZombie(this.node, targetNode, w_id);
  110. }
  111. //开火特效
  112. fireEff() {
  113. effectManager.fireEff(this.node, 'fire1');
  114. AudioManager.play('gun');
  115. }
  116. /**枪角度重置
  117. * @param w_id 武器视图id
  118. */
  119. resetGunAngle(w_id: number) {
  120. playerActionMgr.resetGun(this.node, w_id);
  121. }
  122. getViewId() {
  123. return this.view_id;
  124. }
  125. }