123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Vec3, director, Game, PoolManager, GunBase, Bullet10, Utils, _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, Gun10;
- function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
- function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
- function _reportPossibleCrUseOfGame(extras) {
- _reporterNs.report("Game", "../../game/Game", _context.meta, extras);
- }
- function _reportPossibleCrUseOfPoolManager(extras) {
- _reporterNs.report("PoolManager", "../../core/manager/PoolManager", _context.meta, extras);
- }
- function _reportPossibleCrUseOfGunBase(extras) {
- _reporterNs.report("GunBase", "../base/GunBase", _context.meta, extras);
- }
- function _reportPossibleCrUseOfBullet(extras) {
- _reporterNs.report("Bullet10", "./Bullet10", _context.meta, extras);
- }
- function _reportPossibleCrUseOfUtils(extras) {
- _reporterNs.report("Utils", "../../utils/Utils", _context.meta, extras);
- }
- function _reportPossibleCrUseOfEnemy(extras) {
- _reporterNs.report("Enemy", "../../game/Enemy", _context.meta, extras);
- }
- function _reportPossibleCrUseOfPlayer(extras) {
- _reporterNs.report("Player", "../../game/Player", _context.meta, extras);
- }
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Node = _cc.Node;
- Vec3 = _cc.Vec3;
- director = _cc.director;
- }, function (_unresolved_2) {
- Game = _unresolved_2.Game;
- }, function (_unresolved_3) {
- PoolManager = _unresolved_3.PoolManager;
- }, function (_unresolved_4) {
- GunBase = _unresolved_4.GunBase;
- }, function (_unresolved_5) {
- Bullet10 = _unresolved_5.Bullet10;
- }, function (_unresolved_6) {
- Utils = _unresolved_6.Utils;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "02422u5XL9Ip55qizRWXZh6", "Gun10", undefined);
- __checkObsolete__(['_decorator', 'Node', 'Vec3', 'director']);
- ({
- ccclass,
- property
- } = _decorator);
- /**敌人所使用的枪 */
- // 1001 大兵手枪
- // 1007 将军手枪
- // 1005 机枪队长机关枪
- // 1002 使用的枪狙击兵狙击枪
- // 1004 狙击队长狙击枪
- _export("Gun10", Gun10 = (_dec = ccclass('Gun10'), _dec2 = property({
- type: Node,
- tooltip: "子弹节点"
- }), _dec3 = property({
- type: Node,
- tooltip: "烟雾特效"
- }), _dec4 = property({
- type: Node,
- tooltip: "开火特效节点"
- }), _dec(_class = (_class2 = class Gun10 extends (_crd && GunBase === void 0 ? (_reportPossibleCrUseOfGunBase({
- error: Error()
- }), GunBase) : GunBase) {
- constructor() {
- super(...arguments);
- _initializerDefineProperty(this, "bulletNode", _descriptor, this);
- _initializerDefineProperty(this, "impact", _descriptor2, this);
- _initializerDefineProperty(this, "fireEffect", _descriptor3, this);
- this.isCb = false;
- //枪的拥有者
- this.enemy = null;
- //开枪结束回调
- this.endCb = null;
- //换弹匣的回调
- this.ammoCb = null;
- //触发间隔时间统计
- this.curTime = 0;
- //是否是第一次开火
- this.isFristShot = false;
- //所有的烟雾
- this.smokes = [];
- //是否是第一次激活开枪
- this.isFristShoot = false;
- //为了戳开子弹产生的时间间隔统计
- this.diff = 0;
- //随机延迟的时间
- this.r_delay = 0;
- //继续正常统计时间
- this.isGo = true;
- }
- onLoad() {
- this.bulletNode.active = false;
- this.impact.active = false;
- this.muzzleNode.active = false;
- }
- /**
- * 设置枪的数据
- * @param data 枪的数据
- * @param endCB 结束回调
- * @param ammoCb 换弹匣回调
- */
- init(data, enemy, endCb, ammoCb) {
- this.data = data;
- this.curTime = 0;
- this.isFire = false;
- this.isFristShot = true;
- this.enemy = enemy;
- this.endCb = endCb;
- this.ammoCb = ammoCb;
- this.node.eulerAngles = new Vec3(0, 180, 0);
- } //开火
- fire() {
- this.isFire = true;
- this.playParticle(this.fireEffect);
- } //结束开火
- endFire() {
- var _this$endCb;
- this.isFire = false;
- (_this$endCb = this.endCb) == null || _this$endCb.call(this, this.data);
- this.recycle();
- }
- /**
- * 展示子弹
- */
- createBullet() {
- if (!this.getNextAllow()) return;
- var delay = 0.1;
- for (var i = 0; i < this.data.bullet_number; i++) {
- this.scheduleOnce(k => {
- delay += (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
- error: Error()
- }), Utils) : Utils).getRandomFloat(0, 0.2);
- if (!this.getNextAllow()) return; //获取射击的精准度
- var isHit = this.enemy.calculateIsHit(); //创建子弹
- this.getBulleNode(isHit);
- }, delay * i);
- }
- }
- /**
- * 初始化一个子弹
- * @param isGuaranteedHit 子弹是否必中(必中的时候targetNode不能为空)
- * @param targetNode 射击的目标对象
- * @returns 返回一颗子弹
- */
- getBulleNode(isGuaranteedHit) {
- if (isGuaranteedHit === void 0) {
- isGuaranteedHit = true;
- }
- //从对象池获取子弹节点
- var bulletNode = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(this.bulletNode, director.getScene());
- var bullet = bulletNode.getComponent(_crd && Bullet10 === void 0 ? (_reportPossibleCrUseOfBullet({
- error: Error()
- }), Bullet10) : Bullet10);
- bullet.init(this);
- bulletNode.setWorldPosition(this.muzzleNode.worldPosition);
- var playPos = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
- error: Error()
- }), Game) : Game).I.player.head.worldPosition.clone();
- var baseDirection = Vec3.subtract(new Vec3(), playPos, this.muzzleNode.worldPosition).normalize(); //最终弹道方向
- var finalDirection;
- if (isGuaranteedHit) {
- //100%必中(无偏移)
- finalDirection = baseDirection;
- } else {
- //非必中:在基准方向上添加小范围随机偏移
- var maxOffsetAngle = 5;
- var offsetX = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180;
- var offsetY = (Math.random() - 0.5) * maxOffsetAngle * Math.PI / 180; //应用偏移(保持Z轴主要方向)
- finalDirection = new Vec3(baseDirection.x + offsetX, baseDirection.y + offsetY, baseDirection.z // 保持主要前进方向
- ).normalize();
- } //设置子弹方向
- bulletNode.forward = finalDirection;
- bullet.setBulletVector(finalDirection);
- return bullet;
- } //激活调用 持续开火
- update(dt) {
- if (!this.getNextAllow()) return; //每几秒攻击一次
- var m = this.data.atk_speed; //不是第一次激活 有延迟间隔
- if (!this.isFristShoot) {
- m = this.isFristShoot ? 0 : m;
- if (this.diff >= this.r_delay && !this.isGo) {
- this.diff += dt;
- this.isGo = true;
- return;
- } else {
- this.curTime += dt;
- }
- } else {
- //第一次激活 就直接开枪不延迟
- m = this.isFristShoot ? 0 : m;
- } //在随机延迟的时间间隔里 发射一颗子弹
- if (this.curTime >= m - this.r_delay) {
- if (this.isFire) {
- this.isFristShoot = false;
- this.r_delay = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
- error: Error()
- }), Utils) : Utils).getRandomFloat(0, m);
- this.diff = 0;
- this.isGo = false; //audioMgr.playOneShot(this.data.gun_sound);
- //播放射击帧动画
- //this.playShootAnim();
- this.createBullet();
- this.curTime = 0;
- this.isCb = false;
- } else {
- if (!this.isFire && !this.isCb) {
- var _this$endCb2;
- this.isFire = false;
- (_this$endCb2 = this.endCb) == null || _this$endCb2.call(this, this.data.type);
- this.isCb = true;
- }
- }
- }
- }
- /**
- * 是否可以允许操作
- */
- getNextAllow() {
- var player = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
- error: Error()
- }), Game) : Game).I.player;
- if (!player || player.isDead || !this.isFire || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
- error: Error()
- }), Game) : Game).I.isPause || (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
- error: Error()
- }), Game) : Game).I.isGameOver) {
- return false;
- }
- return true;
- }
- /**
- * 回收烟雾
- */
- recycle() {
- this.smokes.forEach(e => {
- if (e && e.parent) {
- (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).putNode(e);
- }
- });
- this.smokes = [];
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "bulletNode", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "impact", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "fireEffect", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- })), _class2)) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=07c4522d3e8d15585922a238b5c4785bebda35a2.js.map
|