System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5"], function (_export, _context) {
  "use strict";

  var _reporterNs, _cclegacy, _decorator, instantiate, Collider, Vec3, v3, PHY_GROUP, OTWTroopFlagComponent, OTWTroopRenderComponent, OTWObjectComponent, OTWFlagComponent, _dec, _class, _temp, _crd, ccclass, property, OTWTroopComponent;

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  function _reportPossibleCrUseOfITroop(extras) {
    _reporterNs.report("ITroop", "../../../shared/gameClient/games/OccupationTheWarModels", _context.meta, extras);
  }

  function _reportPossibleCrUseOfICountry(extras) {
    _reporterNs.report("ICountry", "../../../shared/gameClient/games/OccupationTheWarModels", _context.meta, extras);
  }

  function _reportPossibleCrUseOfPHY_GROUP(extras) {
    _reporterNs.report("PHY_GROUP", "../Const", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWTroopFlagComponent(extras) {
    _reporterNs.report("OTWTroopFlagComponent", "./OTWTroopFlagComponent", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWTroopData(extras) {
    _reporterNs.report("OTWTroopData", "../Data/OTWTroopData", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWTroopRenderComponent(extras) {
    _reporterNs.report("OTWTroopRenderComponent", "./OTWTroopRenderComponent", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWObjectComponent(extras) {
    _reporterNs.report("OTWObjectComponent", "./OTWObjectComponent", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWGameData(extras) {
    _reporterNs.report("OTWGameData", "../Data/OTWGameData", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWFlagComponent(extras) {
    _reporterNs.report("OTWFlagComponent", "./OTWFlagComponent", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      _decorator = _cc._decorator;
      instantiate = _cc.instantiate;
      Collider = _cc.Collider;
      Vec3 = _cc.Vec3;
      v3 = _cc.v3;
    }, function (_unresolved_2) {
      PHY_GROUP = _unresolved_2.PHY_GROUP;
    }, function (_unresolved_3) {
      OTWTroopFlagComponent = _unresolved_3.OTWTroopFlagComponent;
    }, function (_unresolved_4) {
      OTWTroopRenderComponent = _unresolved_4.OTWTroopRenderComponent;
    }, function (_unresolved_5) {
      OTWObjectComponent = _unresolved_5.OTWObjectComponent;
    }, function (_unresolved_6) {
      OTWFlagComponent = _unresolved_6.OTWFlagComponent;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "a01a7rVXh5A7bN+i2t1ozHN", "OTWTroopComponent", undefined);

      ({
        ccclass,
        property
      } = _decorator);

      _export("OTWTroopComponent", OTWTroopComponent = (_dec = ccclass('OTWTroopComponent'), _dec(_class = (_temp = class OTWTroopComponent extends (_crd && OTWObjectComponent === void 0 ? (_reportPossibleCrUseOfOTWObjectComponent({
        error: Error()
      }), OTWObjectComponent) : OTWObjectComponent) {
        constructor(...args) {
          super(...args);

          _defineProperty(this, "troopInfo", null);

          _defineProperty(this, "moveSpeed", 1);

          _defineProperty(this, "isMoving", false);

          _defineProperty(this, "moveFrom", v3());

          _defineProperty(this, "moveTo", v3());

          _defineProperty(this, "distance", 0);

          _defineProperty(this, "useSec", 0);

          _defineProperty(this, "goSec", 0);

          _defineProperty(this, "tmpPos", v3());
        }

        onDestroy() {
          this.troopInfo = null;
        }

        setMove(targetX, targetZ) {
          this.moveFrom.set(this.troopInfo.troop.x, 0, this.troopInfo.troop.z);
          this.moveTo.set(targetX, 0, targetZ);
          this.distance = Vec3.distance(this.moveFrom, this.moveTo);
          this.useSec = this.distance / this.moveSpeed;
          this.node.lookAt(this.moveTo);
          this.goSec = 0;
          this.isMoving = true;
        }

        start() {
          var collider = this.getComponentInChildren(Collider);
          collider === null || collider === void 0 ? void 0 : collider.setGroup((_crd && PHY_GROUP === void 0 ? (_reportPossibleCrUseOfPHY_GROUP({
            error: Error()
          }), PHY_GROUP) : PHY_GROUP).Troop);
          collider === null || collider === void 0 ? void 0 : collider.setMask(0xffffffff);
        }

        updateData(dt) {
          if (!this.troopInfo) return;

          if (this.isMoving) {
            this.goSec += dt;

            if (this.goSec > this.useSec) {
              //时间到,直接设为目标值
              this.isMoving = false; //this.tmpPos.set(this.moveTo);
              //this._result.currIsTarget = true;

              this.node.setPosition(this.moveTo);
            } else {
              //中间用线性差值
              Vec3.lerp(this.tmpPos, this.moveFrom, this.moveTo, this.goSec / this.useSec);
              this.node.setPosition(this.tmpPos);
            }

            this.troopInfo.troop.x = this.node.position.x;
            this.troopInfo.troop.z = this.node.position.z;
            console.log('Troop.updateData', this.node.position);
          }
        }

        static createNode(troopPrefab, troopColliderPrefab, troopFlagPrefab, getGameData, troop, country, mainCamera, gameMgrNode, gameFlagUIWrapNode, gameObjWrapNode) {
          var renderNode = instantiate(troopPrefab);
          renderNode.name = "TroopRender_" + troop.troopIndex;
          let flagComp;
          var flagNode = (_crd && OTWFlagComponent === void 0 ? (_reportPossibleCrUseOfOTWFlagComponent({
            error: Error()
          }), OTWFlagComponent) : OTWFlagComponent).createFlagNode(_crd && OTWTroopFlagComponent === void 0 ? (_reportPossibleCrUseOfOTWTroopFlagComponent({
            error: Error()
          }), OTWTroopFlagComponent) : OTWTroopFlagComponent, getGameData, troopFlagPrefab, renderNode, mainCamera, gameMgrNode, "OTWGameManager", "onTroopFlagUIUpdate", troop.troopIndex.toString(), country, c => {
            flagComp = c;
          });
          gameFlagUIWrapNode.addChild(flagNode);
          var renderComp = renderNode.getComponent(_crd && OTWTroopRenderComponent === void 0 ? (_reportPossibleCrUseOfOTWTroopRenderComponent({
            error: Error()
          }), OTWTroopRenderComponent) : OTWTroopRenderComponent);
          renderNode.setPosition(troop.x, 0, troop.z);
          gameObjWrapNode.addChild(renderNode);
          var troopNode = instantiate(troopColliderPrefab);
          troopNode.name = "Troop_" + troop.troopIndex;
          var troopComp = troopNode.getComponent(OTWTroopComponent);
          troopNode.setPosition(troop.x, 0, troop.z);
          gameObjWrapNode.addChild(troopNode);
          var troopInfo = {
            troop: troop,
            fromArea: getGameData().allAreaInfo[troop.fromAreaIndex].area,
            toArea: getGameData().allAreaInfo[troop.toAreaIndex].area,
            country: country,
            renderNode: renderNode,
            renderComp: renderComp,
            troopNode: troopNode,
            troopComp: troopComp,
            flagNode: flagNode,
            flagComp: flagComp
          };
          renderComp.troopInfo = troopInfo;
          renderComp.getGameData = getGameData;
          flagComp.troopInfo = troopInfo;
          flagComp.getGameData = getGameData;
          troopComp.troopInfo = troopInfo;
          troopComp.getGameData = getGameData;
          troopComp.setMove(troopInfo.toArea.x, troopInfo.toArea.z);
          flagComp.updateShow();
          return troopInfo;
        }

      }, _temp)) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=OTWTroopComponent.js.map