76f86765-0a97-4abf-b978-2adb15509ab6.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. "use strict";
  2. cc._RF.push(module, '76f86dlCpdKv7l4KtsVUJq2', 'weapon');
  3. // scripts/Game/weapon.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. exports.WeaponType = void 0;
  26. var CocosZ_1 = require("../Framework/CocosZ");
  27. var Constant_1 = require("../Framework/Constant");
  28. var Msg_1 = require("../Framework/Msg");
  29. var gameDate_1 = require("./gameDate");
  30. var gameMgr_1 = require("./gameMgr");
  31. // @ts-ignore
  32. var i18n = require('LanguageData');
  33. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  34. var WeaponType;
  35. (function (WeaponType) {
  36. WeaponType[WeaponType["weapon_melee"] = 0] = "weapon_melee";
  37. WeaponType[WeaponType["weapon_range"] = 1] = "weapon_range";
  38. WeaponType[WeaponType["weapon_rangeAd"] = 2] = "weapon_rangeAd";
  39. })(WeaponType = exports.WeaponType || (exports.WeaponType = {}));
  40. var Weapon = /** @class */ (function (_super) {
  41. __extends(Weapon, _super);
  42. function Weapon() {
  43. var _this = _super !== null && _super.apply(this, arguments) || this;
  44. _this.can_effect_hit = false;
  45. _this.hand_effect = null;
  46. _this.hand_2 = null;
  47. _this.weaponNum = 1;
  48. _this.bullet = null;
  49. _this.bulletCollor = cc.Color.WHITE;
  50. _this.shellCall = null;
  51. _this.atkEffect = null;
  52. _this.atkNum = 10;
  53. _this.atkRangeNum = 1000;
  54. _this.flySpeed = 2000;
  55. _this.atkSpeed = 0.4;
  56. _this.bulletNum = 5;
  57. _this.bulletTotal = 5;
  58. _this.reload = 3;
  59. _this.audioName = "read";
  60. _this.weaponLevel = 0;
  61. _this.weaponType = WeaponType.weapon_melee;
  62. // 武器拥有者
  63. _this.person = null;
  64. // 子弹
  65. _this._curBullet = 0;
  66. _this._arrName = ["", "y", "p", "r"];
  67. // 装弹效果
  68. _this._isReload = false;
  69. return _this;
  70. }
  71. Weapon_1 = Weapon;
  72. Object.defineProperty(Weapon.prototype, "isRangeWeapon", {
  73. // 是否是远程武器
  74. get: function () {
  75. return Weapon_1.rangeWeapon.includes(this.weaponNum);
  76. },
  77. enumerable: false,
  78. configurable: true
  79. });
  80. Object.defineProperty(Weapon.prototype, "curBullet", {
  81. get: function () {
  82. return this._curBullet;
  83. },
  84. set: function (v) {
  85. if (v > this.bulletNum) {
  86. v = this.bulletNum;
  87. }
  88. else if (v < 0) {
  89. v = 0;
  90. }
  91. // 远程武器
  92. if (this.isRangeWeapon) {
  93. this._curBullet = v;
  94. // 装弹
  95. if (this._curBullet <= 0) {
  96. this.reloadBullet();
  97. }
  98. // 设置子弹UI
  99. this.setBulletUI();
  100. }
  101. },
  102. enumerable: false,
  103. configurable: true
  104. });
  105. Weapon.prototype.onLoad = function () {
  106. // 等级
  107. if (!this.person || this.person.isPlayer) {
  108. this.weaponLevel = CocosZ_1.cocosz.dataMgr.getGunInfo(this.weaponNum - 1).Level;
  109. }
  110. else if ([1, 2, 3, 4, 5].includes(CocosZ_1.cocosz.gameMode)) {
  111. this.weaponLevel = Math.floor(Math.random() * 4);
  112. }
  113. this.atkNum = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].atk[this.weaponLevel];
  114. this.atkSpeed = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].atkSpeed[this.weaponLevel];
  115. this.bulletNum = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].bulletNum;
  116. this.bulletTotal = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].bulletTotal[this.weaponLevel];
  117. this.reload = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].reload;
  118. this.atkRangeNum = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].atkRange;
  119. if (this.person)
  120. this.bulletTotal = Math.ceil(this.bulletTotal * this.person.bulletRate);
  121. // 装弹
  122. this._curBullet = 0;
  123. this.addBullet();
  124. this.setSD();
  125. };
  126. Weapon.prototype.start = function () { };
  127. Weapon.prototype.setBulletUI = function () {
  128. // UI更新子弹数
  129. if (this.person && this.person.isPlayer) {
  130. if (this.weaponType == WeaponType.weapon_range) {
  131. if (gameMgr_1.gameMgr.ammo && gameMgr_1.gameMgr.ammo.isValid)
  132. gameMgr_1.gameMgr.ammo.string = this._curBullet + "/" + ([6, 7].includes(CocosZ_1.cocosz.gameMode) ? "♾" : this.bulletTotal);
  133. }
  134. else if (this.weaponType == WeaponType.weapon_rangeAd) {
  135. if (gameMgr_1.gameMgr.ammoAd && gameMgr_1.gameMgr.ammoAd.isValid)
  136. gameMgr_1.gameMgr.ammoAd.string = this._curBullet + "/" + ([6, 7].includes(CocosZ_1.cocosz.gameMode) ? "♾" : this.bulletTotal);
  137. }
  138. }
  139. };
  140. Weapon.prototype.setSD = function () {
  141. var _this = this;
  142. // 闪电颜色
  143. if (this.person) {
  144. this.node.walk(function (child) {
  145. if (child.name == "sd") {
  146. if (_this.weaponLevel > 0) {
  147. child.active = true;
  148. var spAni = child.getComponent(sp.Skeleton);
  149. spAni && spAni.setSkin(_this._arrName[_this.weaponLevel]);
  150. }
  151. else {
  152. child.active = false;
  153. }
  154. }
  155. }, null);
  156. }
  157. };
  158. // 重置子弹
  159. Weapon.prototype.reset = function () {
  160. this.bulletTotal = gameDate_1.default.Weapon[Weapon_1.WeaponName[this.weaponNum - 1]].bulletTotal[this.weaponLevel];
  161. if (this.person) {
  162. this.bulletTotal = Math.ceil(this.bulletTotal * this.person.bulletRate);
  163. }
  164. this._curBullet = 0;
  165. this.addBullet();
  166. };
  167. // 装弹
  168. Weapon.prototype.addBullet = function () {
  169. if (this.isRangeWeapon) {
  170. if (this.person && this.person.isPlayer) {
  171. // 子弹小于弹夹数量, 且还有备弹
  172. if (this.curBullet < this.bulletNum && this.bulletTotal > 0) {
  173. if ([6, 7].includes(CocosZ_1.cocosz.gameMode)) {
  174. this.curBullet = this.bulletNum;
  175. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_Bullet_Reload });
  176. }
  177. else {
  178. var n = this.bulletNum - this.curBullet;
  179. if (this.bulletTotal >= n) {
  180. // 子弹足够
  181. this.bulletTotal -= n;
  182. this.curBullet += n;
  183. }
  184. else {
  185. // 子弹不够
  186. this.bulletTotal = 0;
  187. this.curBullet += this.bulletTotal;
  188. }
  189. }
  190. }
  191. }
  192. else {
  193. this.curBullet = this.bulletNum;
  194. }
  195. }
  196. };
  197. Weapon.prototype.reloadBullet = function () {
  198. var _this = this;
  199. if (this.isRangeWeapon && this._isReload == false) {
  200. this._isReload = true;
  201. if (this.person && this.person.isPlayer) {
  202. if (this.bulletTotal > 0) {
  203. // 音效
  204. CocosZ_1.cocosz.audioMgr.playEffect("reload");
  205. // 动作
  206. var y_back_1 = 0;
  207. if (this.hand_effect) {
  208. y_back_1 = this.hand_effect.y;
  209. cc.tween(this.hand_effect)
  210. .by(0.5, { y: 50 })
  211. .by(0.5, { y: -50 })
  212. .union()
  213. .repeat(this.reload)
  214. .start();
  215. }
  216. // 闪红
  217. cc.tween(gameMgr_1.gameMgr.rangedWeaponMess.children[0])
  218. .to(0.2, { color: cc.Color.RED })
  219. .to(0.2, { color: cc.Color.WHITE })
  220. .start();
  221. CocosZ_1.cocosz.scheduleOnce(function () {
  222. if (_this && _this.isValid) {
  223. _this._isReload = false;
  224. _this.addBullet();
  225. if (_this.hand_effect) {
  226. _this.hand_effect.stopAllActions();
  227. _this.hand_effect.y = y_back_1; // 还原手的位置
  228. }
  229. // 闪绿
  230. cc.tween(gameMgr_1.gameMgr.rangedWeaponMess.children[0])
  231. .to(0.2, { color: cc.Color.GREEN })
  232. .to(0.2, { color: cc.Color.WHITE })
  233. .start();
  234. }
  235. }, this.reload * this.person.reloadRate);
  236. // 装弹按钮效果
  237. if (gameMgr_1.gameMgr.BtnBullet.active && gameMgr_1.gameMgr.BtnBullet.children[3] && gameMgr_1.gameMgr.BtnBullet.children[3].active) {
  238. // 装弹
  239. gameMgr_1.gameMgr.BtnBullet.children[3].active = false;
  240. gameMgr_1.gameMgr.BtnBullet.children[0].active = true;
  241. // 进度填充
  242. var t_1 = gameMgr_1.gameMgr.playerTs.curWeapon.reload * gameMgr_1.gameMgr.playerTs.reloadRate;
  243. gameMgr_1.gameMgr.BtnBullet.children[1].active = true;
  244. var pro_1 = gameMgr_1.gameMgr.BtnBullet.children[1].getComponent(cc.Sprite);
  245. cc.tween(pro_1)
  246. .set({ fillRange: 0 })
  247. .to(t_1, { fillRange: -1 })
  248. .call(function () {
  249. gameMgr_1.gameMgr.BtnBullet.children[0].active = false;
  250. gameMgr_1.gameMgr.BtnBullet.children[1].active = false;
  251. gameMgr_1.gameMgr.BtnBullet.children[2].active = false;
  252. gameMgr_1.gameMgr.BtnBullet.children[3].active = true;
  253. })
  254. .start();
  255. gameMgr_1.gameMgr.BtnBullet.children[2].active = true;
  256. var label_1 = gameMgr_1.gameMgr.BtnBullet.children[2].getComponent(cc.Label);
  257. cc.tween(label_1)
  258. .call(function () { label_1.string = (t_1 * (1 + pro_1.fillRange)).toFixed(1); })
  259. .delay(0.1)
  260. .union()
  261. .repeat(t_1 / 0.1)
  262. .start();
  263. }
  264. }
  265. else {
  266. //没有备弹,提醒
  267. this._isReload = false;
  268. Msg_1.default.Show(i18n.t("msg.myzd")); //没有子弹
  269. CocosZ_1.cocosz.audioMgr.playEffect("bag", false, 1);
  270. }
  271. }
  272. else {
  273. CocosZ_1.cocosz.scheduleOnce(function () {
  274. if (_this && _this.isValid) {
  275. _this._isReload = false;
  276. _this.addBullet();
  277. }
  278. }, this.reload);
  279. }
  280. }
  281. };
  282. var Weapon_1;
  283. Weapon.WeaponName = ["ak", "cfq", "dao", "gj", "jgb", "sd", "hdl", "sq", "ju", "ld", "nnp", "gtst", "tb", "mb", "mq", "szg", "rsq", "cjj", "jtl", "sq2", "tj", "fs"];
  284. Weapon.meleeWaapon = [3, 4, 5, 13, 14];
  285. Weapon.rangeWeapon = [1, 2, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22];
  286. __decorate([
  287. property({ tooltip: "是否播放开火升级效果" })
  288. ], Weapon.prototype, "can_effect_hit", void 0);
  289. __decorate([
  290. property(cc.Node)
  291. ], Weapon.prototype, "hand_effect", void 0);
  292. __decorate([
  293. property(cc.Node)
  294. ], Weapon.prototype, "hand_2", void 0);
  295. __decorate([
  296. property
  297. ], Weapon.prototype, "weaponNum", void 0);
  298. __decorate([
  299. property(cc.Prefab)
  300. ], Weapon.prototype, "bullet", void 0);
  301. __decorate([
  302. property(cc.Color)
  303. ], Weapon.prototype, "bulletCollor", void 0);
  304. __decorate([
  305. property(cc.Prefab)
  306. ], Weapon.prototype, "shellCall", void 0);
  307. __decorate([
  308. property(cc.Prefab)
  309. ], Weapon.prototype, "atkEffect", void 0);
  310. __decorate([
  311. property
  312. ], Weapon.prototype, "atkNum", void 0);
  313. __decorate([
  314. property
  315. ], Weapon.prototype, "atkRangeNum", void 0);
  316. __decorate([
  317. property
  318. ], Weapon.prototype, "flySpeed", void 0);
  319. __decorate([
  320. property({ tooltip: "开火时间" }),
  321. property
  322. ], Weapon.prototype, "atkSpeed", void 0);
  323. __decorate([
  324. property({ tooltip: "弹夹弹药数量" })
  325. ], Weapon.prototype, "bulletNum", void 0);
  326. __decorate([
  327. property({ tooltip: "总弹药数量" })
  328. ], Weapon.prototype, "bulletTotal", void 0);
  329. __decorate([
  330. property({ tooltip: "装弹时间" })
  331. ], Weapon.prototype, "reload", void 0);
  332. __decorate([
  333. property({ tooltip: "装弹音效" })
  334. ], Weapon.prototype, "audioName", void 0);
  335. Weapon = Weapon_1 = __decorate([
  336. ccclass
  337. ], Weapon);
  338. return Weapon;
  339. }(cc.Component));
  340. exports.default = Weapon;
  341. cc._RF.pop();