9c57a5b7-c9d5-4a27-a5ec-b7c290afc77d.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. "use strict";
  2. cc._RF.push(module, '9c57aW3ydVKJ6Xst8KQr8d9', 'person');
  3. // scripts/Game/person.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("./gameDate");
  29. var gameMgr_1 = require("./gameMgr");
  30. var weapon_1 = require("./weapon");
  31. // @ts-ignore
  32. var i18n = require('LanguageData');
  33. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  34. var Person = /** @class */ (function (_super) {
  35. __extends(Person, _super);
  36. function Person() {
  37. var _this = _super !== null && _super.apply(this, arguments) || this;
  38. // 光环特效
  39. _this.ghAniNode = null;
  40. // 烟尘动画节点
  41. _this.ycAniNode = null;
  42. _this.personAtk = 0;
  43. _this.playerName = "";
  44. _this.personLevel = 0;
  45. _this.atkNum = 40;
  46. _this.atkRange = 800;
  47. _this.atkSpeed = 4;
  48. _this.reloadSpeed = 2;
  49. _this.totleHp = 300;
  50. _this.curHp = 300;
  51. _this.atkRate = 1;
  52. _this.speedRate = 1;
  53. _this.atkSpeedRate = 1;
  54. _this.reloadRate = 1;
  55. _this.bulletRate = 1;
  56. _this.meleeAtkRate = 1;
  57. _this.damageReduction = 0;
  58. _this.recoverItemNum = 0;
  59. _this.killNum = 0;
  60. _this.curKillNum = 0;
  61. _this.MoveSpeed = 600;
  62. _this.moveDir = cc.v2(0, 0);
  63. _this.atkDir = cc.v2(0, 0);
  64. _this.footNum = 0;
  65. _this.lastPos = cc.v2(0, 0);
  66. // 开关
  67. _this.canMove = true; //能否移动
  68. _this.canMoveDir = true; //能否改变移动方向
  69. // 检测范围
  70. _this.detectRange = 1000;
  71. _this.mat_common = null;
  72. _this.mat_attacked = null;
  73. // onLoad () {}
  74. _this.body = null;
  75. _this.leg = null;
  76. _this.leg_back = null;
  77. _this.head = null;
  78. _this.hpBar = null;
  79. _this.hpSpr = null;
  80. _this.shieldBar = null;
  81. _this.atkBar = null;
  82. _this.head_atk = null;
  83. _this.head_hart = null;
  84. _this.head_death = null;
  85. _this.playerMess = null;
  86. _this.ani = null;
  87. _this.id = 0; //1玩家
  88. _this.isPlayer = false;
  89. _this.atkTarget = null;
  90. _this.weapon = null;
  91. _this.weapon_dao = null;
  92. _this.hpNumNode = null;
  93. _this._shield = 0;
  94. _this.maxShield = 100;
  95. _this.rig = null;
  96. _this.curTime = 0;
  97. _this._playerMessY = 200;
  98. _this.isReady = false;
  99. _this.curSkin = 0;
  100. /** 视频武器 */
  101. _this.weaponAdArr = [9, 10, 14, 17, 18];
  102. _this.weaponAdIndex = Math.floor(Math.random() * _this.weaponAdArr.length);
  103. _this.meleeWeaponNum = 3;
  104. _this.rangedWeaponNum = 1;
  105. _this.rangedWeaponAdNum = 1;
  106. _this.meleeWeapon = null;
  107. _this.rangedWeapon = null;
  108. _this.rangedWeaponAd = null;
  109. _this.curWeapon = null;
  110. _this.startPosNode = null;
  111. _this.lastTime = 0;
  112. _this._aniName = "";
  113. _this.isAtk = false;
  114. _this.atkList = [];
  115. _this.curItem = 0;
  116. _this.curItemEffect = null;
  117. _this.itemTarget = null;
  118. _this.grassID = 0;
  119. _this.houseID = 0;
  120. _this.isInHouse = false;
  121. _this.newWeapon = -1;
  122. _this.newWeaponItem = null;
  123. _this.poisonCount = 0;
  124. _this.isDeath = false;
  125. _this.isAttackedEffect = false;
  126. _this.maxNum = 0;
  127. _this.isAvoidInjury = 0;
  128. _this.killer = null;
  129. // findTime: number = 0;
  130. _this.revivePos = cc.v2(0, 0);
  131. return _this;
  132. }
  133. Person_1 = Person;
  134. Object.defineProperty(Person.prototype, "HP", {
  135. get: function () {
  136. return this.curHp;
  137. },
  138. set: function (num) {
  139. num = Math.floor(num);
  140. if (num < 0)
  141. num = 0;
  142. else if (num > this.totleHp)
  143. num = this.totleHp;
  144. this.curHp = num;
  145. // 血条
  146. if (this.hpBar && this.hpBar.isValid) {
  147. this.hpBar.progress = this.curHp / this.totleHp;
  148. }
  149. // 主动使用道具
  150. if (this.isPlayer) {
  151. if (CocosZ_1.cocosz.gameMode == 6) {
  152. gameMgr_1.gameMgr.update_model6_xuedi();
  153. }
  154. }
  155. },
  156. enumerable: false,
  157. configurable: true
  158. });
  159. Object.defineProperty(Person.prototype, "Shiled", {
  160. get: function () {
  161. return this._shield;
  162. },
  163. set: function (num) {
  164. cc.Tween.stopAllByTarget(this.shieldBar);
  165. this._shield = num;
  166. if (this._shield < 0) {
  167. this._shield = 0;
  168. this.shieldBar.node.opacity = 0;
  169. this.body.getChildByName("body").children[0].active = false;
  170. }
  171. else {
  172. this.shieldBar.node.opacity = 255;
  173. }
  174. cc.tween(this.shieldBar).to(0.3, { progress: this._shield / this.maxShield }).start();
  175. },
  176. enumerable: false,
  177. configurable: true
  178. });
  179. Person.prototype.onLoad = function () { };
  180. Person.prototype.start = function () {
  181. // 人物信息
  182. if (this.playerMess && this.playerMess.isValid) {
  183. this._playerMessY = this.playerMess.y;
  184. this.playerMess.setParent(this.node.parent);
  185. this.playerMess.zIndex = Constant_1.ZindexLayer.zindex_hp;
  186. this.updateMess();
  187. }
  188. else if (this.hpBar && this.hpBar.isValid) {
  189. this._playerMessY = this.hpBar.node.y;
  190. this.hpBar.node.setParent(this.node.parent);
  191. this.hpBar.node.zIndex = Constant_1.ZindexLayer.zindex_hp;
  192. this.updateMess();
  193. }
  194. };
  195. Person.prototype.update = function (dt) { };
  196. Person.prototype.lateUpdate = function (dt) { };
  197. /** 人物信息 */
  198. Person.prototype.updateMess = function () {
  199. if (this.playerMess && this.playerMess.isValid) {
  200. if (this.node && this.node.isValid && this.node.active && this.node.opacity && this.HP) {
  201. this.playerMess.active = true;
  202. this.playerMess.setPosition(this.node.x, this.node.y + this._playerMessY);
  203. }
  204. else {
  205. this.playerMess.active = false;
  206. }
  207. }
  208. else if (this.hpBar && this.hpBar.isValid && this.hpBar.node && this.hpBar.node.isValid) {
  209. if (this.node && this.node.isValid && this.node.active && this.node.opacity && this.HP) {
  210. this.hpBar.node.active = true;
  211. this.hpBar.node.setPosition(this.node.x, this.node.y + this._playerMessY);
  212. }
  213. else {
  214. this.hpBar.node.active = false;
  215. }
  216. }
  217. };
  218. /** 光环 */
  219. Person.prototype.updateGhAni = function () {
  220. if (this.ghAniNode && this.ghAniNode.isValid) {
  221. if (this.node && this.node.isValid && this.node.active && this.node.opacity && this.HP) {
  222. this.ghAniNode.active = true;
  223. this.ghAniNode.angle = this.node.angle;
  224. this.ghAniNode.setPosition(this.node.x, this.node.y - 90);
  225. }
  226. else {
  227. this.ghAniNode.active = false;
  228. }
  229. }
  230. };
  231. /** 烟尘 */
  232. Person.prototype.updateYcAni = function () {
  233. if (this.ycAniNode && this.ycAniNode.isValid) {
  234. if (this.node && this.node.isValid && this.node.active && this.node.opacity && this.HP && !this.moveDir.equals(cc.Vec2.ZERO)) {
  235. this.ycAniNode.active = true;
  236. this.ycAniNode.setPosition(this.node.x, this.node.y - 50);
  237. this.ycAniNode.scaleX = this.moveDir.x > 0 ? 1 : -1;
  238. }
  239. else {
  240. this.ycAniNode.active = false;
  241. }
  242. }
  243. };
  244. Person.prototype.setProperty = function () {
  245. var _this = this;
  246. this.ani = this.body.getComponent(cc.Animation);
  247. this.node.getComponent(cc.CircleCollider).radius = this.detectRange;
  248. if (this.isPlayer)
  249. this.atkRange = 1000;
  250. this.personLevel = Math.floor(Math.random() * 6);
  251. var num1 = weapon_1.default.meleeWaapon[Math.floor(Math.random() * weapon_1.default.meleeWaapon.length)];
  252. var num2 = weapon_1.default.rangeWeapon[Math.floor(Math.random() * 13 /* Weapon.rangedWeapon.length */)];
  253. if (this.isPlayer) {
  254. num1 = CocosZ_1.cocosz.dataMgr.CurMelee + 1;
  255. num2 = CocosZ_1.cocosz.dataMgr.CurRange + 1;
  256. if (CocosZ_1.cocosz.gameMgr.gameCtr.curUseSkinId < 0) {
  257. this.curSkin = CocosZ_1.cocosz.dataMgr.CurSkinId;
  258. }
  259. else {
  260. this.curSkin = CocosZ_1.cocosz.gameMgr.gameCtr.curUseSkinId;
  261. }
  262. this.head.children[0].children[this.curSkin].active = true;
  263. var head1 = this.head.children[0].children[this.curSkin];
  264. this.head.children[1].children[this.curSkin].active = true;
  265. var head2 = this.head.children[1].children[this.curSkin];
  266. for (var i = this.head.children[0].childrenCount - 1; i >= 0; i--) {
  267. if (this.head.children[0].children[i].uuid != head1.uuid) {
  268. this.head.children[0].children[i].destroy();
  269. }
  270. }
  271. for (var i = this.head.children[1].childrenCount - 1; i >= 0; i--) {
  272. if (this.head.children[1].children[i].uuid != head2.uuid) {
  273. this.head.children[1].children[i].destroy();
  274. }
  275. }
  276. // 表情(父节点设置为正脸)
  277. this.head_atk = this.head.children[2].children[this.curSkin];
  278. this.head_atk.active = true;
  279. this.head_atk.opacity = 0;
  280. this.head_hart = this.head.children[3].children[this.curSkin];
  281. this.head_hart.active = true;
  282. this.head_hart.opacity = 0;
  283. this.head_death = this.head.children[4].children[this.curSkin];
  284. this.head_death.active = true;
  285. this.head_death.opacity = 0;
  286. this.head_atk.setParent(this.head.children[0]);
  287. this.head_hart.setParent(this.head.children[0]);
  288. this.head_death.setParent(this.head.children[0]);
  289. this.head_atk.zIndex = 1;
  290. this.head_hart.zIndex = 2;
  291. this.head_death.zIndex = 3;
  292. // 删除多余表情
  293. this.head.children[2].destroy();
  294. this.head.children[3].destroy();
  295. this.head.children[4].destroy();
  296. this.personLevel = CocosZ_1.cocosz.dataMgr.getSkinInfo(this.curSkin).Level;
  297. this.personAtk = gameDate_1.default.SkinMess["" + (this.curSkin + 1)].atk[this.personLevel];
  298. if (CocosZ_1.cocosz.gameMode == 6) {
  299. this.totleHp = gameDate_1.default.SkinMess["" + (this.curSkin + 1)].xuedi;
  300. }
  301. else {
  302. this.totleHp = gameDate_1.default.SkinMess["" + (this.curSkin + 1)].hp[this.personLevel];
  303. }
  304. // 玩家血量增加
  305. if ([1, 2, 4].includes(CocosZ_1.cocosz.gameMode)) {
  306. this.totleHp *= 4;
  307. }
  308. else if (3 == CocosZ_1.cocosz.gameMode) {
  309. if (CocosZ_1.cocosz.curLevel >= 15) {
  310. this.totleHp *= 9;
  311. }
  312. else if (CocosZ_1.cocosz.curLevel >= 10) {
  313. this.totleHp *= 8;
  314. }
  315. else if (CocosZ_1.cocosz.curLevel >= 5) {
  316. this.totleHp *= 6;
  317. }
  318. else {
  319. this.totleHp *= 4;
  320. }
  321. }
  322. else if (5 == CocosZ_1.cocosz.gameMode) {
  323. this.totleHp *= 6;
  324. }
  325. else if (7 == CocosZ_1.cocosz.gameMode) {
  326. this.totleHp *= 3;
  327. }
  328. this.HP = this.totleHp;
  329. }
  330. else { }
  331. // 初始武器
  332. if (CocosZ_1.cocosz.gameMode == 4) {
  333. if (this.isPlayer) {
  334. this.setNewWeapon(14 - 1); // 玩家固定木棒
  335. }
  336. else {
  337. this.setNewWeapon(num1 - 1); // 敌人随机近战武器
  338. }
  339. this.changeCurWeapon(this.meleeWeapon, false);
  340. }
  341. else {
  342. if (CocosZ_1.cocosz.gameMode === 7) {
  343. this.setNewWeapon(num2 - 1);
  344. }
  345. else {
  346. this.setNewWeapon(num1 - 1);
  347. this.setNewWeapon(num2 - 1);
  348. }
  349. this.changeCurWeapon(this.rangedWeapon, false);
  350. // 广告远程武器
  351. if (this.isPlayer /* && cocosz.isShowAd */) {
  352. cc.tween(gameMgr_1.gameMgr.rangedWeaponAdMess)
  353. .call(function () {
  354. _this.refreshWeaponAd();
  355. })
  356. .delay(10)
  357. .union()
  358. .repeatForever()
  359. .start();
  360. }
  361. }
  362. // 血条
  363. if (CocosZ_1.cocosz.gameMode == 6) {
  364. this.hpBar.node.active = false;
  365. this.atkBar.node.active = false;
  366. }
  367. // 角色速度
  368. this.MoveSpeed = 200 + gameDate_1.default.SkinMess["" + (this.curSkin + 1)].speed[this.personLevel];
  369. if (PlatUtils_1.default.IsOPPO) {
  370. this.MoveSpeed /= 2;
  371. }
  372. // 光环
  373. if (this.personLevel > 0) {
  374. this.ghAniNode.color = cc.Color.WHITE;
  375. var arr = ["", "y", "p", "r"];
  376. var ghAni = this.ghAniNode.getComponent(sp.Skeleton);
  377. if (ghAni) {
  378. ghAni.setSkin(arr[Math.ceil(this.personLevel / 2)]);
  379. }
  380. }
  381. else {
  382. this.ghAniNode.color = cc.Color.BLACK;
  383. var ghAni = this.ghAniNode.getComponent(sp.Skeleton);
  384. ghAni.setSkin("r");
  385. ghAni.setAnimation(0, "animation", true);
  386. }
  387. if (!this.playerName) {
  388. this.playerName = i18n.t("game.player") + this.id;
  389. }
  390. var name = this.playerMess.getChildByName("nameLabel");
  391. if (name)
  392. name.active = false;
  393. this.lastPos = this.node.getPosition();
  394. this.isReady = true;
  395. };
  396. Person.prototype.refreshWeaponAd = function () {
  397. if (CocosZ_1.cocosz.isPause || !this.isPlayer) {
  398. return;
  399. }
  400. if (++this.weaponAdIndex >= this.weaponAdArr.length) {
  401. this.weaponAdIndex = 0;
  402. }
  403. var weaponNum = this.weaponAdArr[this.weaponAdIndex];
  404. var str = weapon_1.default.WeaponName[weaponNum];
  405. var prefab = CocosZ_1.cocosz.resMgr.getRes("weapon_" + str, cc.Prefab);
  406. var new_weapon = cc.instantiate(prefab);
  407. var new_weaponTs = new_weapon.getComponent(weapon_1.default);
  408. // 初始化
  409. new_weaponTs.person = this;
  410. this.body.addChild(new_weapon);
  411. new_weapon.active = false;
  412. new_weaponTs.weaponType = weapon_1.WeaponType.weapon_rangeAd;
  413. this.rangedWeaponAd && this.rangedWeaponAd.destroy();
  414. this.rangedWeaponAd = new_weapon;
  415. this.rangedWeaponAdNum = new_weaponTs.weaponNum;
  416. var str2 = "w_" + weapon_1.default.WeaponName[this.rangedWeaponAdNum - 1];
  417. var spr2 = CocosZ_1.cocosz.resMgr.getRes(str2, cc.SpriteFrame);
  418. gameMgr_1.gameMgr.rangedWeaponAdMess.children[3].getComponent(cc.Sprite).spriteFrame = spr2;
  419. gameMgr_1.gameMgr.rangedWeaponAdMess.children[4].getComponent(cc.Sprite).spriteFrame = CocosZ_1.cocosz.resMgr.getRes("w_" + (weaponNum + 1), cc.SpriteFrame);
  420. gameMgr_1.gameMgr.rangedWeaponAdMess.children[5].getComponent(cc.Label).string = new_weaponTs.atkNum.toString();
  421. new_weaponTs.setBulletUI();
  422. };
  423. Person.prototype.setNewWeapon = function (weaponNum) {
  424. if (weaponNum === void 0) { weaponNum = this.newWeapon; }
  425. if (weaponNum < 0)
  426. return;
  427. var str = weapon_1.default.WeaponName[weaponNum];
  428. var prefab = CocosZ_1.cocosz.resMgr.getRes("weapon_" + str, cc.Prefab);
  429. var new_weapon = cc.instantiate(prefab);
  430. var new_weaponTs = new_weapon.getComponent(weapon_1.default);
  431. new_weaponTs.person = this;
  432. this.body.addChild(new_weapon);
  433. new_weapon.active = false;
  434. if (new_weaponTs.isRangeWeapon) {
  435. if (this.curWeapon && this.curWeapon.weaponType == weapon_1.WeaponType.weapon_rangeAd) {
  436. // 设置广告远程
  437. new_weaponTs.weaponType = weapon_1.WeaponType.weapon_rangeAd;
  438. this.rangedWeaponAd && this.rangedWeaponAd.destroy();
  439. this.rangedWeaponAd = new_weapon;
  440. this.rangedWeaponAdNum = new_weaponTs.weaponNum;
  441. if (this.isPlayer) {
  442. var str2 = "w_" + weapon_1.default.WeaponName[this.rangedWeaponAdNum - 1];
  443. var spr2 = CocosZ_1.cocosz.resMgr.getRes(str2, cc.SpriteFrame);
  444. gameMgr_1.gameMgr.rangedWeaponAdMess.children[3].getComponent(cc.Sprite).spriteFrame = spr2;
  445. gameMgr_1.gameMgr.rangedWeaponAdMess.children[4].getComponent(cc.Sprite).spriteFrame = CocosZ_1.cocosz.resMgr.getRes("w_" + (weaponNum + 1), cc.SpriteFrame);
  446. gameMgr_1.gameMgr.rangedWeaponAdMess.children[5].getComponent(cc.Label).string = new_weaponTs.atkNum.toString();
  447. new_weaponTs.setBulletUI();
  448. }
  449. }
  450. else {
  451. // 设置远程
  452. new_weaponTs.weaponType = weapon_1.WeaponType.weapon_range;
  453. this.rangedWeapon && this.rangedWeapon.destroy();
  454. this.rangedWeapon = new_weapon;
  455. this.rangedWeaponNum = new_weaponTs.weaponNum;
  456. if (this.isPlayer) {
  457. var str2 = "w_" + weapon_1.default.WeaponName[this.rangedWeaponNum - 1];
  458. var spr2 = CocosZ_1.cocosz.resMgr.getRes(str2, cc.SpriteFrame);
  459. gameMgr_1.gameMgr.rangedWeaponMess.children[3].getComponent(cc.Sprite).spriteFrame = spr2;
  460. gameMgr_1.gameMgr.rangedWeaponMess.children[4].getComponent(cc.Sprite).spriteFrame = CocosZ_1.cocosz.resMgr.getRes("w_" + (weaponNum + 1), cc.SpriteFrame);
  461. gameMgr_1.gameMgr.rangedWeaponMess.children[5].getComponent(cc.Label).string = new_weaponTs.atkNum.toString();
  462. new_weaponTs.setBulletUI();
  463. }
  464. }
  465. }
  466. else {
  467. // 设置近战
  468. new_weaponTs.weaponType = weapon_1.WeaponType.weapon_melee;
  469. this.meleeWeapon && this.meleeWeapon.destroy();
  470. this.meleeWeapon = new_weapon;
  471. this.meleeWeaponNum = new_weaponTs.weaponNum;
  472. }
  473. // 替换当前武器
  474. if (this.curWeapon && this.curWeapon.isRangeWeapon === new_weaponTs.isRangeWeapon) {
  475. this.changeCurWeapon(new_weapon, false);
  476. }
  477. // 销毁武器道具
  478. this.newWeapon = -1;
  479. if (this.newWeaponItem && this.newWeaponItem.isValid)
  480. this.newWeaponItem.destroy();
  481. this.newWeaponItem = null;
  482. };
  483. Person.prototype.changeCurWeapon = function (newWeaponNode, isCheck) {
  484. if (isCheck === void 0) { isCheck = true; }
  485. if (!newWeaponNode || !newWeaponNode.isValid)
  486. return;
  487. if (this.curWeapon && this.curWeapon.isValid && newWeaponNode == this.curWeapon.node)
  488. return;
  489. var curTime = Number(new Date());
  490. if (isCheck && (curTime - this.lastTime < 1000))
  491. return;
  492. this.lastTime = curTime;
  493. // 切换武器显示
  494. if (this.curWeapon && cc.isValid(this.curWeapon))
  495. this.curWeapon.node.active = false;
  496. newWeaponNode.active = true;
  497. // 切换当前武器
  498. var newWeapinTs = newWeaponNode.getComponent(weapon_1.default);
  499. if (newWeapinTs) {
  500. // UI效果
  501. if (this.isPlayer) {
  502. var newWeapinMess = null;
  503. if (newWeapinTs.weaponType == weapon_1.WeaponType.weapon_melee) {
  504. gameMgr_1.gameMgr.BtnBullet.active = false;
  505. }
  506. else if (newWeapinTs.weaponType == weapon_1.WeaponType.weapon_range) {
  507. newWeapinMess = gameMgr_1.gameMgr.rangedWeaponMess;
  508. }
  509. else if (newWeapinTs.weaponType == weapon_1.WeaponType.weapon_rangeAd) {
  510. newWeapinMess = gameMgr_1.gameMgr.rangedWeaponAdMess;
  511. }
  512. newWeapinMess.children[0].active = true;
  513. if (this.curWeapon && this.curWeapon.isValid) {
  514. CocosZ_1.cocosz.audioMgr.playEffect("changeWeapon");
  515. var oldWeapinMess_1 = null;
  516. if (this.curWeapon.weaponType == weapon_1.WeaponType.weapon_melee) {
  517. }
  518. else if (this.curWeapon.weaponType == weapon_1.WeaponType.weapon_range) {
  519. oldWeapinMess_1 = gameMgr_1.gameMgr.rangedWeaponMess;
  520. }
  521. else if (this.curWeapon.weaponType == weapon_1.WeaponType.weapon_rangeAd) {
  522. oldWeapinMess_1 = gameMgr_1.gameMgr.rangedWeaponAdMess;
  523. }
  524. if (oldWeapinMess_1 !== newWeapinMess) {
  525. oldWeapinMess_1.children[0].active = false;
  526. oldWeapinMess_1.children[1].active = true;
  527. cc.tween(oldWeapinMess_1.children[1].getComponent(cc.Sprite))
  528. .set({ fillRange: -1 })
  529. .to(1, { fillRange: 0 })
  530. .call(function () {
  531. if (oldWeapinMess_1.isValid) {
  532. oldWeapinMess_1.children[1].active = false;
  533. }
  534. })
  535. .start();
  536. }
  537. }
  538. }
  539. // 开火点
  540. if (newWeapinTs.isRangeWeapon) {
  541. this.startPosNode = newWeaponNode.getChildByName("startPos");
  542. }
  543. this.curWeapon = newWeapinTs;
  544. this.atkNum = this.curWeapon.atkNum * (this.curWeapon.isRangeWeapon ? 1 : this.meleeAtkRate);
  545. this.atkSpeed = this.curWeapon.atkSpeed;
  546. this.reloadSpeed = this.curWeapon.reload;
  547. }
  548. };
  549. Person.prototype.atkStart = function () { };
  550. Person.prototype.atkEnemy = function () { };
  551. Person.prototype.atkComplete = function () { };
  552. Person.prototype.setWeaponAngle = function (dir) {
  553. if (this.curWeapon && this.curWeapon.isValid && this.curWeapon.isRangeWeapon) {
  554. if (dir.equals(cc.Vec2.ZERO)) {
  555. this.curWeapon.node.angle = 0;
  556. }
  557. else {
  558. if (dir.x < 0) {
  559. this.curWeapon.node.angle = cc.v2(dir).signAngle(cc.v2(-1, 0)) / Math.PI * 180;
  560. }
  561. else {
  562. this.curWeapon.node.angle = -cc.v2(dir).signAngle(cc.v2(1, 0)) / Math.PI * 180;
  563. }
  564. if (dir.y > 0) {
  565. if (this.curWeapon.node)
  566. this.rangedWeapon.zIndex = -1;
  567. }
  568. else {
  569. if (this.curWeapon.node)
  570. this.rangedWeapon.zIndex = 1;
  571. }
  572. }
  573. }
  574. };
  575. /**
  576. * 设置动画
  577. * @param name 动画名字
  578. * @param enforce 强制播放
  579. */
  580. Person.prototype.updateAni = function (name, enforce) {
  581. if (enforce === void 0) { enforce = false; }
  582. if (enforce) {
  583. this._playAni(name);
  584. }
  585. else if (gameMgr_1.gameMgr.isGameStart) {
  586. if (this.isDeath) {
  587. name = "die";
  588. }
  589. else if (this.moveDir.equals(cc.Vec2.ZERO)) {
  590. name = "daiji_body";
  591. }
  592. else {
  593. name = "run_body";
  594. }
  595. this._playAni(name);
  596. }
  597. };
  598. Person.prototype._playAni = function (name) {
  599. if (name && name != this._aniName) {
  600. this.ani.play(name);
  601. this._aniName = name;
  602. }
  603. };
  604. Person.prototype.getCurSpeed = function () {
  605. var speed = this.MoveSpeed * this.speedRate * (this.curWeapon && this.curWeapon.isRangeWeapon ? 1 : 1.2);
  606. if (speed > 1000)
  607. speed = 1000;
  608. return speed;
  609. };
  610. Person.prototype.udpateRBody = function (dir) {
  611. if (this.rig.type == cc.RigidBodyType.Dynamic) {
  612. if (this.canMove) {
  613. if (!dir.equals(cc.Vec2.ZERO)) {
  614. this.rig.linearVelocity = dir.mul(this.getCurSpeed());
  615. }
  616. else {
  617. this.rig.linearVelocity = cc.Vec2.ZERO;
  618. }
  619. }
  620. }
  621. };
  622. Person.prototype.updatePerson = function () {
  623. var dir = null;
  624. if (this.atkDir && !this.atkDir.equals(cc.Vec2.ZERO)) {
  625. dir = this.atkDir;
  626. }
  627. else if (this.moveDir && !this.moveDir.equals(cc.Vec2.ZERO)) {
  628. dir = this.moveDir;
  629. }
  630. else {
  631. return;
  632. }
  633. if (dir.x < 0)
  634. this.body.scaleX = -Math.abs(this.body.scaleX);
  635. else
  636. this.body.scaleX = Math.abs(this.body.scaleX);
  637. if (dir.y > 0) {
  638. this.leg_back.opacity = 255;
  639. this.leg.opacity = 0;
  640. this.head.children[1].opacity = 255;
  641. this.head.children[0].opacity = 0;
  642. }
  643. else {
  644. this.leg_back.opacity = 0;
  645. this.leg.opacity = 255;
  646. this.head.children[0].opacity = 255;
  647. this.head.children[1].opacity = 0;
  648. }
  649. // 远程武器
  650. this.setWeaponAngle(dir);
  651. };
  652. Person.prototype.updateAtk = function () {
  653. if (this.atkList.length > 0) {
  654. var dt = 1000;
  655. var n = -1;
  656. for (var i = 0; i < this.atkList.length; i++) {
  657. var ts = this.atkList[i].getComponent(Person_1);
  658. var dt2 = this.atkList[i].getPosition().sub(this.node.getPosition()).mag();
  659. if (dt2 < dt) {
  660. dt = dt2;
  661. n = i;
  662. }
  663. }
  664. if (n >= 0) {
  665. this.atkDir = cc.v2(this.atkList[n].getPosition().sub(this.node.getPosition()).normalize());
  666. this.atkTarget = this.atkList[n];
  667. }
  668. else {
  669. this.atkDir = this.moveDir.mag() == 0 ? this.atkDir : cc.v2(this.moveDir);
  670. }
  671. }
  672. else {
  673. this.atkDir = this.moveDir.mag() == 0 ? this.atkDir : cc.v2(this.moveDir);
  674. }
  675. };
  676. // 0:检测碰撞;1:检测子弹;2:检测在层级下,3:检测在层级上
  677. Person.prototype.onCollisionEnter = function (other, self) { };
  678. Person.prototype.onCollisionExit = function (other, self) { };
  679. /** 受伤 */
  680. Person.prototype.hart = function (atkNum, from, dir, isAudio, isEmit, labelColor) {
  681. if (dir === void 0) { dir = null; }
  682. if (isAudio === void 0) { isAudio = true; }
  683. if (isEmit === void 0) { isEmit = true; }
  684. };
  685. /** 免伤 */
  686. Person.prototype.avoidInjury = function (time) {
  687. var _this = this;
  688. this.isAvoidInjury++;
  689. this.scheduleOnce(function () {
  690. _this.isAvoidInjury--;
  691. }, time);
  692. };
  693. Person.prototype.death = function () {
  694. this.isDeath = true;
  695. // 隐藏光环
  696. if (this.ghAniNode && this.ghAniNode.isValid) {
  697. this.ghAniNode.active = false;
  698. }
  699. if (this.playerMess && this.playerMess.isValid) {
  700. this.playerMess.active = false;
  701. }
  702. this.head_death.opacity = 255;
  703. // 死亡音效
  704. gameMgr_1.gameMgr.playEffect("death", this.node);
  705. this.unscheduleAllCallbacks();
  706. // this.ani.stop();
  707. // this.ani.play("die");
  708. this.updateAni("die");
  709. if (this.meleeWeapon) {
  710. var ani = this.meleeWeapon.getComponent(cc.Animation);
  711. ani && ani.stop();
  712. }
  713. this.leg.opacity = 255;
  714. this.leg_back.opacity = 0;
  715. this.head.children[0].opacity = 255;
  716. this.head.children[1].opacity = 0;
  717. if (this.curWeapon && this.curWeapon.isValid)
  718. this.curWeapon.node.active = false;
  719. if (this.rig)
  720. this.rig.active = false;
  721. this.node.getComponent(cc.BoxCollider).enabled = false;
  722. this.node.getComponent(cc.CircleCollider).enabled = false;
  723. gameMgr_1.gameMgr.deathNum++;
  724. if (this.isPlayer) {
  725. var rate = 0.3;
  726. cc.director.getScheduler().setTimeScale(rate);
  727. setTimeout(function () {
  728. cc.director.getScheduler().setTimeScale(1);
  729. }, rate * 3000);
  730. }
  731. if (CocosZ_1.cocosz.gameMode == 6) {
  732. if (this.isPlayer) {
  733. if (!gameMgr_1.gameMgr.isWin && !gameMgr_1.gameMgr.isFail) {
  734. this.revivePos = this.node.getPosition();
  735. this.scheduleOnce(function () {
  736. CocosZ_1.cocosz.uiMgr.openPanel(Constant_1.PanelName.UIRevivePanel);
  737. }, 2);
  738. }
  739. }
  740. }
  741. };
  742. Person.prototype.revive = function () {
  743. if (gameMgr_1.gameMgr && !gameMgr_1.gameMgr.isWin && !gameMgr_1.gameMgr.isFail) {
  744. gameMgr_1.gameMgr.deathNum--;
  745. // 恢复光环
  746. if (this.ghAniNode && this.ghAniNode.isValid) {
  747. this.ghAniNode.active = true;
  748. }
  749. if (this.playerMess && this.playerMess.isValid) {
  750. this.playerMess.active = true;
  751. }
  752. if (this.rangedWeapon)
  753. this.rangedWeapon.getComponent(weapon_1.default).reset();
  754. if (this.rangedWeaponAd)
  755. this.rangedWeaponAd.getComponent(weapon_1.default).reset();
  756. // if (this.rangedWeapon) this.rangedWeapon.zIndex = 1;
  757. // if (this.rangedWeapon) this.rangedWeapon.angle = 0;
  758. if (this.meleeWeapon) {
  759. var ani = this.meleeWeapon.getComponent(cc.Animation);
  760. ani && ani.play();
  761. }
  762. if (this.curWeapon && this.curWeapon.isValid)
  763. this.curWeapon.node.active = true;
  764. this.head_death.opacity = 0;
  765. var pos = this.revivePos;
  766. this.node.setPosition(pos);
  767. this.HP = this.totleHp;
  768. this.body.setPosition(cc.v2(0, 0));
  769. this.body.angle = 0;
  770. this.leg.opacity = 255;
  771. this.leg_back.opacity = 0;
  772. this.head.children[0].opacity = 255;
  773. this.head.children[1].opacity = 0;
  774. if (this.node.scaleX < 0)
  775. this.node.scaleX *= -1;
  776. if (this.rig)
  777. this.rig.active = true;
  778. // this.node.getComponent(cc.RigidBody).enabled = true;
  779. this.node.getComponent(cc.BoxCollider).enabled = true;
  780. this.node.getComponent(cc.CircleCollider).enabled = true;
  781. this.isDeath = false;
  782. this.canMove = true;
  783. }
  784. };
  785. Person.prototype.creatItem = function () { };
  786. var Person_1;
  787. __decorate([
  788. property(cc.Material)
  789. ], Person.prototype, "mat_common", void 0);
  790. __decorate([
  791. property(cc.Material)
  792. ], Person.prototype, "mat_attacked", void 0);
  793. __decorate([
  794. property(cc.Node)
  795. ], Person.prototype, "body", void 0);
  796. __decorate([
  797. property(cc.Node)
  798. ], Person.prototype, "leg", void 0);
  799. __decorate([
  800. property(cc.Node)
  801. ], Person.prototype, "leg_back", void 0);
  802. __decorate([
  803. property(cc.Node)
  804. ], Person.prototype, "head", void 0);
  805. __decorate([
  806. property(cc.ProgressBar)
  807. ], Person.prototype, "hpBar", void 0);
  808. __decorate([
  809. property(cc.Node)
  810. ], Person.prototype, "hpSpr", void 0);
  811. __decorate([
  812. property(cc.ProgressBar)
  813. ], Person.prototype, "shieldBar", void 0);
  814. __decorate([
  815. property(cc.ProgressBar)
  816. ], Person.prototype, "atkBar", void 0);
  817. Person = Person_1 = __decorate([
  818. ccclass
  819. ], Person);
  820. return Person;
  821. }(cc.Component));
  822. exports.default = Person;
  823. cc._RF.pop();