4f9b3ac1-35d3-4fcb-a5aa-2eb36ed37640.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. "use strict";
  2. cc._RF.push(module, '4f9b3rBNdNPy6WqLrNu03ZA', 'ZombieBase');
  3. // scripts/Game/ZombieBase.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var PlatUtils_1 = require("../../common-plugin/Scripts/PlatUtils");
  26. var CocosZ_1 = require("../Framework/CocosZ");
  27. var Constant_1 = require("../Framework/Constant");
  28. var gameDate_1 = require("../Game/gameDate");
  29. var gameMgr_1 = require("../Game/gameMgr");
  30. var person_1 = require("../Game/person");
  31. var UpgradeMgr_1 = require("../Game/UpgradeMgr");
  32. var bullet_1 = require("./bullet");
  33. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  34. var AtkType;
  35. (function (AtkType) {
  36. AtkType[AtkType["front"] = 0] = "front";
  37. AtkType[AtkType["area"] = 1] = "area";
  38. AtkType[AtkType["charge"] = 2] = "charge";
  39. AtkType[AtkType["range"] = 3] = "range";
  40. })(AtkType || (AtkType = {}));
  41. var ZombieBase = /** @class */ (function (_super) {
  42. __extends(ZombieBase, _super);
  43. function ZombieBase() {
  44. var _this = _super !== null && _super.apply(this, arguments) || this;
  45. _this.zombieId = 0;
  46. _this.bullet_prefab = null;
  47. _this.sp_hongzhaquan = null;
  48. _this.audio_attack1 = null;
  49. _this.audio_attack2 = null;
  50. _this.audio_hart = null;
  51. _this.audio_die = null;
  52. _this.isBoss = false;
  53. _this._aniLayer = null;
  54. _this._spAni = null;
  55. _this._divToPlayer = cc.Vec2.ZERO;
  56. _this._time = -1;
  57. _this._canColor = true;
  58. _this._canAtk = true;
  59. return _this;
  60. }
  61. ZombieBase.prototype.onLoad = function () {
  62. var _this = this;
  63. this.id = 94;
  64. // 初始化配置表属性
  65. if (gameDate_1.default.ZombieMess[this.zombieId]) {
  66. this.totleHp = gameDate_1.default.ZombieMess[this.zombieId].hp;
  67. this.atkNum = gameDate_1.default.ZombieMess[this.zombieId].atk;
  68. this.atkRange = gameDate_1.default.ZombieMess[this.zombieId].atkRange;
  69. this.MoveSpeed = gameDate_1.default.ZombieMess[this.zombieId].speed;
  70. if (PlatUtils_1.default.IsOPPO) {
  71. this.MoveSpeed /= 2;
  72. }
  73. }
  74. // 大小缩放
  75. if (this.isBoss) {
  76. this.node.scale = 1;
  77. }
  78. else {
  79. this.node.scale = 0.8;
  80. }
  81. // 刚体
  82. this.rig = this.node.getComponent(cc.RigidBody);
  83. if (this.rig) {
  84. this.rig.linearDamping = 0.2;
  85. }
  86. // spine动画
  87. this._aniLayer = this.node.getChildByName("aniLayer");
  88. if (this._aniLayer) {
  89. this._spAni = this._aniLayer.getChildByName("ani").getComponent(sp.Skeleton);
  90. }
  91. // 监听动画
  92. if (this._spAni) {
  93. this._spAni.setStartListener(function () { _this.startListenerCall(); });
  94. this._spAni.setCompleteListener(function () { _this.endListenerCall(); });
  95. }
  96. };
  97. ZombieBase.prototype.onDestroy = function () {
  98. // 取消监听
  99. cc.game.targetOff(this);
  100. };
  101. ZombieBase.prototype.start = function () { };
  102. ZombieBase.prototype.initNode = function () {
  103. var _this = this;
  104. gameMgr_1.gameMgr && gameMgr_1.gameMgr.setMapTs.checkNode(this.node, true);
  105. // 消息监听
  106. cc.game.on(Constant_1.default.E_GAME_LOGIC, this._onGameMessageHandler, this);
  107. gameMgr_1.gameMgr.zombieCurNum++;
  108. this.node.stopAllActions();
  109. this.node.zIndex = Constant_1.ZindexLayer.zindex_zombie + this.zombieId;
  110. this.node.opacity = 255;
  111. this.atkDir = cc.Vec2.ZERO;
  112. this.curHp = this.totleHp;
  113. this.isDeath = false;
  114. this.isAtk = false;
  115. this._canAtk = true;
  116. this.canMoveDir = true;
  117. this.canMove = true;
  118. // 播放出场动画
  119. if (this._spAni && this._spAni.isValid) {
  120. this._spAni.node.scaleX = Math.abs(this._spAni.node.scaleX);
  121. this._spAni.node.opacity = 255;
  122. this._spAni.node.color = cc.Color.WHITE;
  123. if (this.isBoss) {
  124. this._spAni.setAnimation(0, "spawn", false);
  125. this.scheduleOnce(function () {
  126. // 碰撞体
  127. var boxCollider = _this.node.getComponent(cc.BoxCollider);
  128. if (boxCollider)
  129. boxCollider.enabled = true;
  130. }, 2);
  131. }
  132. else {
  133. this._spAni.setAnimation(0, "idle", true);
  134. // 碰撞体
  135. var boxCollider = this.node.getComponent(cc.BoxCollider);
  136. if (boxCollider)
  137. boxCollider.enabled = true;
  138. }
  139. }
  140. // 轰炸圈
  141. if (this.sp_hongzhaquan) {
  142. this.sp_hongzhaquan.node.setParent(this.node.parent);
  143. this.sp_hongzhaquan.node.zIndex = Constant_1.ZindexLayer.zinedx_floorTip;
  144. this.sp_hongzhaquan.setCompleteListener(function () {
  145. if (_this.sp_hongzhaquan && _this.sp_hongzhaquan.isValid) {
  146. _this.sp_hongzhaquan.node.active = false;
  147. }
  148. });
  149. }
  150. // boss
  151. if (this.isBoss) {
  152. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_Commonzombie_Destory });
  153. gameMgr_1.gameMgr && gameMgr_1.gameMgr.showBossHp(1);
  154. if (this.node.getChildByName("boos"))
  155. this.node.getChildByName("boos").active = true;
  156. }
  157. };
  158. ZombieBase.prototype.putNodePool = function () {
  159. // 取消监听
  160. cc.game.targetOff(this);
  161. // boss
  162. if (this.isBoss) {
  163. // boss光影
  164. if (this.node.getChildByName("boos"))
  165. this.node.getChildByName("boos").active = false;
  166. // boss边界
  167. if (gameMgr_1.gameMgr) {
  168. gameMgr_1.gameMgr && gameMgr_1.gameMgr.showBossHp(0);
  169. if (gameMgr_1.gameMgr.boss_border && cc.isValid(gameMgr_1.gameMgr.boss_border)) {
  170. gameMgr_1.gameMgr.boss_border.destroy();
  171. gameMgr_1.gameMgr.boss_border = null;
  172. }
  173. }
  174. this.isBoss = false;
  175. }
  176. // 轰炸圈
  177. if (this.sp_hongzhaquan && this.sp_hongzhaquan.isValid) {
  178. this.sp_hongzhaquan.node.setParent(this.node);
  179. this.sp_hongzhaquan.node.active = false;
  180. }
  181. gameMgr_1.gameMgr.zombieCurNum--;
  182. gameMgr_1.gameMgr && gameMgr_1.gameMgr.isValid && gameMgr_1.gameMgr.nodePut(this.node.name, this.node);
  183. };
  184. ZombieBase.prototype.startListenerCall = function () {
  185. var _this = this;
  186. if (this._spAni.animation.includes("spawn")) {
  187. this._spAni.timeScale = 0.4;
  188. this.scheduleOnce(function () { _this._spAni.timeScale = 1; }, 1);
  189. this.canMoveDir = false;
  190. // 出场方向
  191. var fromPos = this.node.getPosition();
  192. var toPos = gameMgr_1.gameMgr.playerTs.node.getPosition();
  193. var div = toPos.subSelf(fromPos);
  194. this._spAni.node.scaleX = (div.x > 0 ? 1 : -1) * Math.abs(this._spAni.node.scaleX);
  195. }
  196. else if (this._spAni.animation.includes("attack")) {
  197. this.isAtk = true;
  198. this.canMoveDir = false;
  199. if ([8, 9, 18].includes(this.zombieId) && this._spAni.animation == "attack2") {
  200. this.speedRate *= 2.5;
  201. this.udpateRBody(this.moveDir);
  202. this.scheduleOnce(function () {
  203. _this.speedRate /= 2.5;
  204. _this.moveDir = cc.Vec2.ZERO;
  205. _this.udpateRBody(_this.moveDir);
  206. }, 0.2);
  207. }
  208. else if ([10, 11, 12, 13].includes(this.zombieId) && this._spAni.animation == "attack2") {
  209. this.speedRate *= 3;
  210. this.udpateRBody(this.moveDir);
  211. this.scheduleOnce(function () {
  212. _this.speedRate /= 3;
  213. _this.moveDir = cc.Vec2.ZERO;
  214. _this.udpateRBody(_this.moveDir);
  215. }, 0.2);
  216. }
  217. else if ([14, 19].includes(this.zombieId) && this._spAni.animation.includes("attack")) {
  218. this.speedRate *= 3;
  219. this.udpateRBody(this.moveDir);
  220. this.scheduleOnce(function () {
  221. _this.speedRate /= 3;
  222. _this.moveDir = cc.Vec2.ZERO;
  223. _this.udpateRBody(_this.moveDir);
  224. }, 0.2);
  225. }
  226. else if (this.zombieId == 15 && this._spAni.animation == "attack") {
  227. this.speedRate *= 3;
  228. this.udpateRBody(this.moveDir);
  229. this.scheduleOnce(function () {
  230. _this.speedRate /= 3;
  231. _this.moveDir = cc.Vec2.ZERO;
  232. _this.udpateRBody(_this.moveDir);
  233. }, 0.4);
  234. }
  235. else if (this.zombieId == 16 && this._spAni.animation == "attack") {
  236. this.speedRate *= 2;
  237. this.udpateRBody(this.moveDir);
  238. this.scheduleOnce(function () {
  239. _this.speedRate /= 2;
  240. _this.moveDir = cc.Vec2.ZERO;
  241. _this.udpateRBody(_this.moveDir);
  242. }, 0.3);
  243. }
  244. else if (this.zombieId == 17 && this._spAni.animation.includes("attack")) {
  245. this.speedRate *= 2;
  246. this.udpateRBody(this.moveDir);
  247. this.scheduleOnce(function () {
  248. _this.speedRate /= 2;
  249. _this.moveDir = cc.Vec2.ZERO;
  250. _this.udpateRBody(_this.moveDir);
  251. }, 0.3);
  252. }
  253. else {
  254. this.moveDir = cc.Vec2.ZERO;
  255. this.udpateRBody(this.moveDir);
  256. }
  257. }
  258. else if (this._spAni.animation.includes("jump_up")) {
  259. this.canMoveDir = false;
  260. }
  261. };
  262. ZombieBase.prototype.endListenerCall = function () {
  263. if (this._spAni.animation.includes("spawn")) {
  264. this._spAni.setAnimation(0, "idle", true);
  265. this.canMoveDir = true;
  266. this.updateMove();
  267. this.updatePerson();
  268. this.udpateRBody(this.moveDir);
  269. }
  270. else if (this._spAni.animation.includes("attack")) {
  271. this._spAni.setAnimation(0, "idle", true);
  272. this.isAtk = false;
  273. this.canMoveDir = true;
  274. this.updateMove();
  275. this.updatePerson();
  276. this.udpateRBody(this.moveDir);
  277. this.atkDir = cc.Vec2.ZERO;
  278. }
  279. else if (this._spAni.animation.includes("jump_down")) {
  280. this._spAni.setAnimation(0, "idle", true);
  281. this.canMoveDir = true;
  282. this.moveDir = cc.Vec2.ZERO;
  283. this.udpateRBody(this.moveDir);
  284. }
  285. };
  286. /** 消息 */
  287. ZombieBase.prototype._onGameMessageHandler = function (event) {
  288. var _this = this;
  289. switch (event.type) {
  290. // 清除所有僵尸
  291. case Constant_1.default.E_Allzombie_Destory: {
  292. this.hart(9999999, null, null, true, true, cc.Color.WHITE, true);
  293. break;
  294. }
  295. // boss出现清除普通僵尸
  296. case Constant_1.default.E_Commonzombie_Destory: {
  297. if (!this.isBoss) {
  298. cc.tween(this.node).to(0.3, { opacity: 1 }, { easing: "fade" }).call(function () { _this.putNodePool(); }).start();
  299. }
  300. break;
  301. }
  302. }
  303. };
  304. ZombieBase.prototype.lateUpdate = function (dt) {
  305. if (this.isDeath || CocosZ_1.cocosz.isPause || !gameMgr_1.gameMgr.isGameStart || gameMgr_1.gameMgr.isWin || gameMgr_1.gameMgr.isFail) {
  306. this.udpateRBody(cc.Vec2.ZERO);
  307. return;
  308. }
  309. this._time++;
  310. if (this._time % 15 == 0) {
  311. if (this._time % 30 == 0) {
  312. this.updateDiv();
  313. this.updateMove();
  314. }
  315. this.updateAtk();
  316. this.updateAni();
  317. this.updatePerson();
  318. this.udpateRBody(this.moveDir);
  319. }
  320. };
  321. ZombieBase.prototype.updateDiv = function () {
  322. var fromPos = this.node.getPosition();
  323. var toPos = gameMgr_1.gameMgr.playerTs.node.getPosition();
  324. this._divToPlayer = toPos.subSelf(fromPos);
  325. // 超出屏幕距离删除
  326. if (!this.isBoss && this._divToPlayer.mag() > cc.winSize.height / 2 / gameMgr_1.gameMgr.mainCamera.zoomRatio) {
  327. this.putNodePool();
  328. }
  329. };
  330. /** 更新移动 */
  331. ZombieBase.prototype.updateMove = function () {
  332. if (this.rig.type == cc.RigidBodyType.Dynamic) {
  333. if (this.canMove && this.canMoveDir) {
  334. // 有目标
  335. if (gameMgr_1.gameMgr.playerTs) {
  336. // 玩家存活
  337. if (!gameMgr_1.gameMgr.playerTs.isDeath) {
  338. // 跳跃
  339. if (this.zombieId == 3 && Math.random() < 0.2) {
  340. if (!this._spAni.animation.includes("jump")) {
  341. this._spAni.setAnimation(0, "jump_up", false);
  342. this._spAni.addAnimation(0, "jump_down", false);
  343. this.moveDir = this._divToPlayer.normalize();
  344. }
  345. }
  346. // 朝着玩家移动
  347. else if (this._divToPlayer.mag() >= this.atkRange * 0.8) {
  348. this.moveDir = cc.v2(this._divToPlayer.normalize()).rotateSelf(Math.PI / 2 * (0.5 - Math.random()));
  349. }
  350. // 距离玩家很近,停止移动
  351. else {
  352. this.moveDir = cc.Vec2.ZERO;
  353. }
  354. }
  355. // 玩家死亡
  356. else {
  357. // 距离很近则远离玩家
  358. if (this._divToPlayer.mag() < (this.isBoss ? 800 : 1500)) {
  359. this.moveDir = this._divToPlayer.normalize().negSelf();
  360. }
  361. // 随机移动
  362. else {
  363. this.moveDir = cc.v2(this._divToPlayer.normalize()).rotateSelf(2 * Math.PI * Math.random());
  364. }
  365. }
  366. }
  367. }
  368. }
  369. };
  370. /** 更新攻击 */
  371. ZombieBase.prototype.updateAtk = function () {
  372. // 能否攻击攻击
  373. if (!this.canAtk()) {
  374. // ...
  375. }
  376. // 新的攻击
  377. else if (gameMgr_1.gameMgr.playerTs && !gameMgr_1.gameMgr.playerTs.isDeath) {
  378. // 普通距离攻击
  379. if (this._divToPlayer.mag() < this.atkRange) {
  380. this.atkDir = this._divToPlayer.normalize();
  381. this.atk();
  382. }
  383. // 远距离攻击
  384. else {
  385. switch (this.zombieId) {
  386. case 8:
  387. case 9:
  388. case 10:
  389. case 11:
  390. case 12:
  391. case 13:
  392. case 18: {
  393. if (this._divToPlayer.mag() < 600 && Math.random() < 0.1 * (this.isBoss ? 2 : 1)) {
  394. this.atkDir = this._divToPlayer.normalize();
  395. this.moveDir = this._divToPlayer.normalize();
  396. this.atk("attack2");
  397. }
  398. break;
  399. }
  400. case 14:
  401. case 16:
  402. case 19: {
  403. if (this._divToPlayer.mag() < 800 && Math.random() < 0.1 * (this.isBoss ? 2 : 1)) {
  404. this.atkDir = this._divToPlayer.normalize();
  405. this.moveDir = this._divToPlayer.normalize();
  406. this.atk("attack");
  407. }
  408. break;
  409. }
  410. case 15: {
  411. if (this._divToPlayer.mag() < 800 && Math.random() < 0.1 * (this.isBoss ? 2 : 1)) {
  412. this.atkDir = this._divToPlayer.normalize();
  413. this.moveDir = this._divToPlayer.normalize();
  414. this.atk("attack");
  415. }
  416. break;
  417. }
  418. case 16: {
  419. if (this._divToPlayer.mag() < 600 && Math.random() < 0.1 * (this.isBoss ? 2 : 1)) {
  420. this.atkDir = this._divToPlayer.normalize();
  421. this.moveDir = this._divToPlayer.normalize();
  422. this.atk("attack");
  423. }
  424. break;
  425. }
  426. case 17: {
  427. if (this._divToPlayer.mag() < 600 && Math.random() < 0.15 * (this.isBoss ? 2 : 1)) {
  428. this.atkDir = this._divToPlayer.normalize();
  429. this.moveDir = this._divToPlayer.normalize();
  430. this.atk();
  431. }
  432. break;
  433. }
  434. case 20: {
  435. if (this._divToPlayer.mag() < 600) {
  436. if (Math.random() < 0.15 * (this.isBoss ? 2 : 1)) {
  437. this.atkDir = this._divToPlayer.normalize();
  438. this.moveDir = this._divToPlayer.normalize();
  439. this.atk("attack");
  440. }
  441. }
  442. else if (this.sp_hongzhaquan.isValid && !this.sp_hongzhaquan.node.active && this._divToPlayer.mag() > 800) {
  443. this.atk("bullet_chui");
  444. }
  445. break;
  446. }
  447. }
  448. }
  449. }
  450. else {
  451. this.atkDir = cc.Vec2.ZERO;
  452. }
  453. };
  454. /** 更新动画 */
  455. ZombieBase.prototype.updateAni = function () {
  456. if (this.isDeath == false) {
  457. // 暂停
  458. if (this._spAni.timeScale == 0) {
  459. // ...a
  460. }
  461. // 出场
  462. else if (this._spAni.animation.includes("spawn")) { }
  463. // 攻击
  464. else if (this._spAni.animation.includes("attack")) { }
  465. // 跳跃
  466. else if (this._spAni.animation.includes("jump")) { }
  467. // 其它
  468. else {
  469. // 移动
  470. if (this.moveDir && this.moveDir.mag()) {
  471. if (this.zombieId == 17) {
  472. !this._spAni.animation.includes("wing") && this._spAni.setAnimation(0, "wing", true);
  473. }
  474. else {
  475. !this._spAni.animation.includes("run") && this._spAni.setAnimation(0, "run", true);
  476. }
  477. }
  478. // 待机
  479. else {
  480. !this._spAni.animation.includes("idle") && this._spAni.setAnimation(0, "idle", true);
  481. }
  482. }
  483. }
  484. // 死亡
  485. else if (this._spAni && this._spAni.skeletonData && this._spAni.skeletonData.skeletonJson.animations["die"]) {
  486. !this._spAni.animation.includes("die") && this._spAni.setAnimation(0, "die", false);
  487. }
  488. };
  489. ZombieBase.prototype.updatePerson = function () {
  490. var dir = null;
  491. if (this.atkDir && this.atkDir.mag()) {
  492. dir = this.atkDir;
  493. }
  494. else if (this.moveDir && this.moveDir.mag()) {
  495. dir = this.moveDir;
  496. }
  497. // 动画方向
  498. if (dir) {
  499. this._spAni.node.scaleX = Math.abs(this._spAni.node.scaleX) * (dir.x > 0 ? 1 : -1);
  500. }
  501. };
  502. /** 刚体移动 */
  503. ZombieBase.prototype.udpateRBody = function (dir, isMust) {
  504. if (isMust === void 0) { isMust = false; }
  505. if (this.rig.type == cc.RigidBodyType.Dynamic) {
  506. if (this.canMove || isMust) {
  507. if (dir && !dir.equals(cc.Vec2.ZERO)) {
  508. this.rig.linearVelocity = dir.mul(Math.floor(this.MoveSpeed * this.speedRate * (1 - 0.2 * Math.random())));
  509. }
  510. else {
  511. this.rig.linearVelocity = cc.Vec2.ZERO;
  512. }
  513. }
  514. }
  515. };
  516. /** 攻击 */
  517. ZombieBase.prototype.atk = function (aniName) {
  518. var _this = this;
  519. if (aniName === void 0) { aniName = ""; }
  520. var atkType = AtkType.front;
  521. var atkRange = this.atkRange;
  522. var atkTime = 0;
  523. var bulletTime = 2;
  524. var clip = this.audio_attack1;
  525. switch (this.zombieId) {
  526. case 0:
  527. case 1: {
  528. if (Math.random() < 0.5) {
  529. aniName = "attack";
  530. }
  531. else {
  532. aniName = "attack2";
  533. clip = this.audio_attack2;
  534. }
  535. atkTime = 0.3;
  536. break;
  537. }
  538. case 2:
  539. case 3: {
  540. aniName = "attack1";
  541. atkTime = 0.3;
  542. break;
  543. }
  544. case 4: {
  545. aniName = "attack";
  546. atkTime = 0.3;
  547. break;
  548. }
  549. case 5: {
  550. aniName = "attack";
  551. atkTime = 4;
  552. atkType = AtkType.range;
  553. bulletTime = 2;
  554. this._canAtk = false;
  555. break;
  556. }
  557. case 6: {
  558. aniName = "attack";
  559. atkTime = 4;
  560. atkType = AtkType.range;
  561. bulletTime = 2;
  562. this._canAtk = false;
  563. break;
  564. }
  565. case 7: {
  566. break;
  567. }
  568. case 8:
  569. case 18: {
  570. if (aniName == "attack2") {
  571. aniName = "attack2";
  572. atkRange = 300;
  573. atkTime = 0.3;
  574. atkType = AtkType.area;
  575. clip = this.audio_attack2;
  576. }
  577. else {
  578. aniName = "attack";
  579. atkRange = 350;
  580. atkTime = 0.3;
  581. }
  582. break;
  583. }
  584. case 9: {
  585. if (aniName == "attack2") {
  586. aniName = "attack2";
  587. atkRange = 450;
  588. atkTime = 0.3;
  589. clip = this.audio_attack2;
  590. }
  591. else {
  592. aniName = "attack";
  593. atkRange = 350;
  594. atkTime = 0.3;
  595. }
  596. break;
  597. }
  598. case 10: {
  599. if (aniName == "attack2") {
  600. aniName = "attack2";
  601. atkRange = 200;
  602. atkTime = 0.3;
  603. clip = this.audio_attack2;
  604. }
  605. else {
  606. aniName = "attack";
  607. atkRange = 200;
  608. atkTime = 0.3;
  609. }
  610. break;
  611. }
  612. case 11:
  613. case 12:
  614. case 13: {
  615. if (aniName == "attack2") {
  616. aniName = "attack2";
  617. atkRange = 250;
  618. atkTime = 0.3;
  619. clip = this.audio_attack2;
  620. }
  621. else {
  622. aniName = "attack";
  623. atkRange = 250;
  624. atkTime = 0.3;
  625. }
  626. break;
  627. }
  628. case 14:
  629. case 19: {
  630. if (Math.random() < 0.6) { //冲盾
  631. aniName = "attack";
  632. atkRange = 350;
  633. atkTime = 0.3;
  634. atkType = AtkType.charge;
  635. clip = this.audio_attack1;
  636. }
  637. else {
  638. aniName = "attack2"; //挥棍
  639. atkRange = 350;
  640. atkTime = 0.3;
  641. clip = this.audio_attack2;
  642. }
  643. break;
  644. }
  645. case 15: {
  646. if (aniName == "attack") { //冲锋
  647. aniName = "attack";
  648. atkRange = 250;
  649. atkTime = 0.3;
  650. atkType = AtkType.charge;
  651. }
  652. else {
  653. aniName = "attack2"; //喷火
  654. atkRange = 400;
  655. atkTime = 0.3;
  656. }
  657. break;
  658. }
  659. case 16: {
  660. if (aniName == "attack" || Math.random() < 0.4) {
  661. aniName = "attack";
  662. atkRange = 450;
  663. atkTime = 0.3;
  664. atkType = AtkType.area;
  665. }
  666. else {
  667. aniName = "attack2";
  668. atkRange = 300;
  669. atkTime = 0.3;
  670. }
  671. break;
  672. }
  673. case 17: {
  674. if (Math.random() < 0.5) {
  675. aniName = "attack";
  676. atkRange = 200;
  677. atkTime = 0.3;
  678. }
  679. else {
  680. aniName = "attack2";
  681. atkRange = 200;
  682. atkTime = 0.3;
  683. atkType = AtkType.charge;
  684. }
  685. break;
  686. }
  687. case 20: {
  688. if (aniName == "bullet_chui") {
  689. atkType = AtkType.range;
  690. aniName = "attack2";
  691. bulletTime = 1.5;
  692. }
  693. else if (aniName == "attack") {
  694. aniName = "attack";
  695. atkRange = 500;
  696. atkTime = 0.3;
  697. }
  698. else {
  699. aniName = "attack2";
  700. atkRange = 300;
  701. atkTime = 0.3;
  702. }
  703. break;
  704. }
  705. }
  706. // 执行动画
  707. if (aniName)
  708. this._spAni.setAnimation(0, aniName, false);
  709. if (clip && clip.isValid)
  710. gameMgr_1.gameMgr.playClip(clip, this.node, 0.5);
  711. // 攻击伤害
  712. var call = function () {
  713. if (gameMgr_1.gameMgr.playerTs && !gameMgr_1.gameMgr.playerTs.isDeath) {
  714. var fromPos = _this.node.getPosition();
  715. var toPos = gameMgr_1.gameMgr.playerTs.node.getPosition();
  716. var div = toPos.subSelf(fromPos);
  717. // 判断是否在攻击范围和攻击方向
  718. if (div.mag() < atkRange) {
  719. if (atkType == AtkType.front) {
  720. if (div.mag() < 200 || (div.x * _this._spAni.node.scale > 0 && Math.abs(div.y / div.x) < 1.4)) {
  721. gameMgr_1.gameMgr.playerTs.hart(1, _this.node, div.normalizeSelf(), true);
  722. }
  723. }
  724. else if (atkType === AtkType.charge) {
  725. gameMgr_1.gameMgr.playerTs.hart(1, _this.node, div.normalizeSelf(), true);
  726. _this.unschedule(call);
  727. }
  728. else {
  729. gameMgr_1.gameMgr.playerTs.hart(1, _this.node, div.normalizeSelf(), true);
  730. }
  731. }
  732. }
  733. ;
  734. };
  735. if (atkType == AtkType.front || atkType == AtkType.area) {
  736. this.scheduleOnce(call, atkTime);
  737. }
  738. else if (atkType == AtkType.charge) {
  739. this.schedule(call, 0, 15);
  740. }
  741. else if (atkType == AtkType.range) {
  742. var pos_from = this.node.getPosition();
  743. var pos_to_1 = gameMgr_1.gameMgr.playerTs.node.getPosition();
  744. var p2 = cc.v2((pos_from.x + pos_to_1.x) / 2, pos_from.y + 1500);
  745. // 生成子弹
  746. if (this.bullet_prefab) {
  747. var bullet_2 = cc.instantiate(this.bullet_prefab);
  748. // 子弹脚本
  749. var ts_1 = bullet_2.getComponent(bullet_1.default);
  750. ts_1.id = this.id;
  751. ts_1.atker = this.node;
  752. ts_1.atk = this.atkNum;
  753. ts_1.isAngle = true;
  754. // 子弹属性
  755. bullet_2.setPosition(pos_from);
  756. bullet_2.zIndex = Constant_1.ZindexLayer.zindex_bullet_sky;
  757. bullet_2.parent = this.node.parent;
  758. // 子弹移动
  759. cc.tween(bullet_2)
  760. .call(function () {
  761. // 轰炸预警
  762. if (_this.sp_hongzhaquan && _this.sp_hongzhaquan.isValid) {
  763. _this.sp_hongzhaquan.node.active = true;
  764. _this.sp_hongzhaquan.node.setPosition(pos_to_1);
  765. _this.sp_hongzhaquan.setAnimation(0, "animation", false);
  766. }
  767. })
  768. .bezierTo(bulletTime, pos_from, p2, pos_to_1)
  769. .call(function () {
  770. // 生成爆炸子弹
  771. if (ts_1.boomEffect) {
  772. var boom = cc.instantiate(ts_1.boomEffect);
  773. boom.parent = ts_1.node.parent;
  774. boom.setPosition(ts_1.node.getPosition());
  775. var curBullet = boom.getComponent(bullet_1.default);
  776. curBullet.atk = ts_1.atk;
  777. curBullet.atker = ts_1.atker;
  778. curBullet.id = ts_1.id;
  779. gameMgr_1.gameMgr.playEffect("explo", boom);
  780. if (ts_1.hitEffect) {
  781. var pos = bullet_2.getPosition();
  782. var node = cc.instantiate(ts_1.hitEffect);
  783. node.parent = bullet_2.parent;
  784. node.setPosition(pos);
  785. node.zIndex = Constant_1.ZindexLayer.zindex_effect_hit;
  786. }
  787. }
  788. bullet_2.destroy();
  789. })
  790. .start();
  791. this.scheduleOnce(function () { _this._canAtk = true; }, atkTime);
  792. }
  793. }
  794. };
  795. /** 受伤 */
  796. ZombieBase.prototype.hart = function (atkNum, from, dir, isAudio, isEmit, labelColor, isMust) {
  797. var _this = this;
  798. if (isAudio === void 0) { isAudio = true; }
  799. if (isEmit === void 0) { isEmit = true; }
  800. if (isMust === void 0) { isMust = false; }
  801. if (this.isDeath)
  802. return;
  803. if (isMust == false && CocosZ_1.cocosz.isPause)
  804. return;
  805. // 防止dir过大
  806. if (dir && dir.mag() > 3)
  807. dir.normalizeSelf().mulSelf(3);
  808. // 减伤
  809. atkNum = (1 - this.damageReduction) * atkNum;
  810. // 数字
  811. gameMgr_1.gameMgr.showRoleTip(this.node, Math.min(this.HP, atkNum).toFixed(0), labelColor);
  812. // 设置血量
  813. this.HP -= atkNum;
  814. if (this.isBoss) {
  815. gameMgr_1.gameMgr && gameMgr_1.gameMgr.showBossHp(this.HP / this.totleHp);
  816. }
  817. // 受伤效果
  818. if (!this.isAttackedEffect && this._spAni && this._spAni.node && this._spAni.node.isValid) {
  819. this.isAttackedEffect = true;
  820. // 受伤音效
  821. if (isAudio) {
  822. // 受伤音效
  823. if (this.audio_hart) {
  824. gameMgr_1.gameMgr.playClip(this.audio_hart, this.node, 0.5);
  825. }
  826. }
  827. // 缩放
  828. cc.tween(this._aniLayer)
  829. .to(0.1, { scale: 0.7 }, { easing: "sineIn" })
  830. .to(0.1, { scale: 1 }, { easing: "sineOut" })
  831. .call(function () { _this.isAttackedEffect = false; })
  832. .start();
  833. // 变色
  834. if (this._canColor) {
  835. cc.tween(this._spAni.node)
  836. .to(0.1, { color: new cc.Color(0, 0, 0, 255) })
  837. .to(0.1, { color: cc.Color.WHITE })
  838. .start();
  839. }
  840. // 后退
  841. if (this.rig.type == cc.RigidBodyType.Dynamic && dir && this.canMove && this.canMoveDir) {
  842. // 控制
  843. this.canMove = false;
  844. this.scheduleOnce(function () { _this.canMove = true; }, 0.1);
  845. // 后退
  846. var div = dir.mulSelf(400 * dir.mag()).addSelf(this.rig.linearVelocity);
  847. var maxDiv = this.isBoss ? 100 : 300;
  848. if (div.mag() > maxDiv) {
  849. div.normalizeSelf().mulSelf(maxDiv);
  850. }
  851. this.rig.linearVelocity = div;
  852. }
  853. }
  854. if (this.HP <= 0) {
  855. this.death();
  856. // 死亡事件
  857. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_Zombie_Death, node: this.node, from: from });
  858. }
  859. else {
  860. // 受伤事件
  861. if (from && isEmit) {
  862. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_Zombie_Hart, node: this.node });
  863. }
  864. }
  865. };
  866. /** 死亡 */
  867. ZombieBase.prototype.death = function () {
  868. var _this = this;
  869. this.isAtk = false;
  870. this.isDeath = true;
  871. this._spAni.timeScale = 1;
  872. // 碰撞体
  873. this.node.getComponents(cc.Collider).forEach(function (v) { return v.enabled = false; });
  874. // 隐藏销毁
  875. cc.tween(this._spAni.node).to(1, { opacity: 0 }).start();
  876. // 死亡音效
  877. if (this.audio_die)
  878. gameMgr_1.gameMgr.playClip(this.audio_die, null, 0.2);
  879. // 死亡效果
  880. this.updateAni();
  881. if (this.zombieId < 8) {
  882. var pre = CocosZ_1.cocosz.resMgr.getRes("effect_death", cc.Prefab);
  883. if (pre) {
  884. var effect_death = cc.instantiate(pre);
  885. effect_death.zIndex = Constant_1.ZindexLayer.zinedx_floorSkill;
  886. effect_death.setPosition(this.node.position);
  887. effect_death.setParent(this.node.parent);
  888. }
  889. }
  890. // 死亡掉落道具
  891. this.creatItem();
  892. this.scheduleOnce(function () { _this.putNodePool(); }, 2);
  893. };
  894. ZombieBase.prototype.creatItem = function () {
  895. if (gameMgr_1.gameMgr.isWin || gameMgr_1.gameMgr.isFail)
  896. return;
  897. if (UpgradeMgr_1.upgradeMgr && UpgradeMgr_1.upgradeMgr.isValid) {
  898. var count = (this.zombieId < 8 ? 1 : 10);
  899. for (var i = 0; i < count; i++) {
  900. var pos = this.node.getPosition();
  901. if (i > 0) {
  902. pos.addSelf(cc.v2(20 * i, 0).rotateSelf(2 * Math.PI * Math.random()));
  903. }
  904. UpgradeMgr_1.upgradeMgr.createJingyan(pos);
  905. }
  906. }
  907. };
  908. ZombieBase.prototype.frozenStart = function () {
  909. this._canColor = false;
  910. // 停止受伤变色
  911. this._spAni.node.stopAllActions();
  912. // 启动变色
  913. this._spAni.node.color = cc.Color.BLUE;
  914. if (this._spAni) {
  915. this._spAni.timeScale = 0;
  916. }
  917. // 移动暂停
  918. this.isAtk = false;
  919. this.canMoveDir = false;
  920. this.moveDir = cc.Vec2.ZERO;
  921. this.udpateRBody(this.moveDir, true);
  922. };
  923. ZombieBase.prototype.frozenEnd = function () {
  924. if (!this.isDeath) {
  925. this._canColor = true;
  926. // 恢复颜色
  927. this._spAni.node.color = cc.Color.WHITE;
  928. if (this._spAni) {
  929. this._spAni.timeScale = 1;
  930. this._spAni.setAnimation(0, "idle", true);
  931. }
  932. // 移动恢复
  933. this.canMoveDir = true;
  934. this.isAtk = false;
  935. this.atkDir = cc.Vec2.ZERO;
  936. this.updateMove();
  937. this.updatePerson();
  938. this.udpateRBody(this.moveDir);
  939. }
  940. };
  941. ZombieBase.prototype.fire_start = function () {
  942. this._canColor = false;
  943. // 停止受伤变色
  944. this._spAni.node.stopAllActions();
  945. // 启动变色
  946. this._spAni.node.color = cc.Color.RED;
  947. };
  948. ZombieBase.prototype.fire_end = function () {
  949. this._canColor = true;
  950. // 恢复颜色
  951. this._spAni.node.color = cc.Color.WHITE;
  952. };
  953. ZombieBase.prototype.canAtk = function () {
  954. if (!this._canAtk || this.isAtk || this._spAni.timeScale == 0 || this._spAni.animation.includes("spawn") || this._spAni.animation.includes("jump")) {
  955. return false;
  956. }
  957. return true;
  958. };
  959. __decorate([
  960. property({ tooltip: "僵尸id" })
  961. ], ZombieBase.prototype, "zombieId", void 0);
  962. __decorate([
  963. property({ type: cc.Prefab, tooltip: "子弹预制体", visible: function () { return [5, 6, 20].includes(this.zombieId); } })
  964. ], ZombieBase.prototype, "bullet_prefab", void 0);
  965. __decorate([
  966. property({ type: sp.Skeleton, tooltip: "警告圈", visible: function () { return [5, 6, 20].includes(this.zombieId); } })
  967. ], ZombieBase.prototype, "sp_hongzhaquan", void 0);
  968. __decorate([
  969. property({ type: cc.AudioClip, tooltip: "攻击音效1" })
  970. ], ZombieBase.prototype, "audio_attack1", void 0);
  971. __decorate([
  972. property({ type: cc.AudioClip, tooltip: "攻击音效2" })
  973. ], ZombieBase.prototype, "audio_attack2", void 0);
  974. __decorate([
  975. property({ type: cc.AudioClip, tooltip: "受伤音效" })
  976. ], ZombieBase.prototype, "audio_hart", void 0);
  977. __decorate([
  978. property({ type: cc.AudioClip, tooltip: "死亡音效" })
  979. ], ZombieBase.prototype, "audio_die", void 0);
  980. ZombieBase = __decorate([
  981. ccclass
  982. ], ZombieBase);
  983. return ZombieBase;
  984. }(person_1.default));
  985. exports.default = ZombieBase;
  986. cc._RF.pop();