{ "code": "var Tween = Laya.Tween;\r\nvar Vector3 = Laya.Vector3;\r\nimport { Mathf } from \"../Util/Mathf\";\r\nimport Game_Tool from \"../Util/Game_Tool\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport Car from \"./Car\";\r\nimport { TrackType, EnemyCarType, AimColliderType } from \"./DefinedType\";\r\nimport { GlobalVariable } from \"../game_module/GlobalVariable\";\r\nimport EnemyController from \"./EnemyController\";\r\nimport { Enemy } from \"./Enemy\";\r\nimport AimController, { Aim } from \"./AimController\";\r\nimport Dictionary from \"../Util/Dictionary\";\r\nimport PlayerController from \"./PlayerController\";\r\nimport AIController from \"./AIController\";\r\nimport { PoolManager } from \"./PoolManager\";\r\nimport GameManager from \"./GameManager\";\r\nvar Quaternion = Laya.Quaternion;\r\nimport { EffectController } from \"./EffectController\";\r\nimport { SceneController } from \"./SceneController\";\r\nimport { PlayerManager } from \"./PlayerManager\";\r\nimport { WXSdk } from \"../game_module/WXSdk\";\r\nimport { SettingController } from \"./SettingController\";\r\nexport class EnemyCar extends Car {\r\n constructor() {\r\n super(...arguments);\r\n this._speed = new Vector3(0, 0, 0.3);\r\n this.speed = new Vector3(0, 0, 0.3);\r\n this.isBoom = false;\r\n this.forW = Mathf.VecZero;\r\n this._up = new Vector3(0, 1, 0);\r\n this.quaternion1 = new Laya.Quaternion;\r\n this._s = Mathf.VecZero;\r\n this._r = Mathf.VecZero;\r\n }\r\n onAwake() {\r\n super.onAwake();\r\n this.BackLeftPoint3 = this.selfobj.getChildByName(\"BackLeftPoint3\");\r\n this.BackRightPoint4 = this.selfobj.getChildByName(\"BackRightPoint4\");\r\n this.FrontRightPoint2 = this.selfobj.getChildByName('FrontRightPoint2');\r\n this.DriverPoint = this.selfobj.getChildByName(\"DriverPoint\");\r\n this.ATV = this.selfobj.getChildByName(\"ATV\");\r\n if (this.ATV) {\r\n this.WheelBL = this.ATV.getChildByName(\"WheelBL\");\r\n this.blMat = this.WheelBL.meshRenderer.material;\r\n this.WheelBR = this.ATV.getChildByName(\"WheelBR\");\r\n this.brMat = this.WheelBR.meshRenderer.material;\r\n this.WheelFL = this.ATV.getChildByName(\"WheelFL\");\r\n this.flMat = this.WheelFL.meshRenderer.material;\r\n this.WheelFR = this.ATV.getChildByName(\"WheelFR\");\r\n this.frMat = this.WheelFR.meshRenderer.material;\r\n }\r\n this.effectPoint = this.selfobj.getChildByName(\"effectPoint\");\r\n this.rolesForCar = new Dictionary();\r\n }\r\n onStart() {\r\n }\r\n StartMove() {\r\n Laya.timer.frameLoop(1, this, this._move);\r\n }\r\n _move() {\r\n if (GameManager.Instance.isgamePause)\r\n return;\r\n if (!this.isBoom) {\r\n this.tran.translate(this.speed);\r\n this.CheackMove();\r\n }\r\n else {\r\n this._BoomMove();\r\n }\r\n }\r\n SetTrack(track, tar, carType, enemycardata) {\r\n this.tar = tar;\r\n this.tarTra = this.tar.transform;\r\n this.trackType = track;\r\n this.carType = carType;\r\n let t = (Math.random() > 0.5 ? -1 : 1) * Game_Tool.randomFl(1, 3);\r\n this.InitData(enemycardata);\r\n switch (track) {\r\n case TrackType.midP:\r\n this.trackTarX = GlobalVariable.midX;\r\n this.trackTarZ = GlobalVariable.midZ + t;\r\n break;\r\n case TrackType.leftP:\r\n this.trackTarX = -GlobalVariable.sideX;\r\n this.trackTarZ = GlobalVariable.sideZ + t;\r\n break;\r\n case TrackType.right:\r\n this.trackTarX = GlobalVariable.sideX;\r\n this.trackTarZ = GlobalVariable.sideZ + t;\r\n break;\r\n }\r\n this.TweenSpaw();\r\n this.StartMove();\r\n }\r\n TweenSpaw() {\r\n this.tween1 = Tween.to(this.tran, { localPositionX: this.trackTarX, localRotationEulerY: 0 }, 600, Laya.Ease.linearIn, Laya.Handler.create(this, () => {\r\n this.tween1.clear();\r\n }, null, false));\r\n }\r\n CheackMove() {\r\n let dis = this.tarTra.localPositionZ - this.tran.localPositionZ;\r\n if (dis <= this.trackTarZ - 2) {\r\n this.speed.z -= 0.01;\r\n this.speed.z = Mathf.MixNumber(this.speed.z, this._speed.z, 0.1);\r\n }\r\n else if (dis <= this.trackTarZ) {\r\n this.speed.z = Mathf.MixNumber(this.speed.z, this._speed.z, 0.01);\r\n }\r\n else {\r\n this.speed.z += 0.005;\r\n }\r\n }\r\n CreateEnemy() {\r\n if (this.carType == EnemyCarType.pickup) {\r\n for (let index = 0; index < 2; index++) {\r\n let a = index;\r\n let t = (index + 1);\r\n Laya.timer.frameOnce(t, this, this.CreateRole, [a], false);\r\n }\r\n }\r\n else if (this.carType == EnemyCarType.redchongfeng) {\r\n this.CreateRole(0);\r\n }\r\n else if (this.carType == EnemyCarType.bluechongfeng) {\r\n this.CreateRole(0);\r\n }\r\n else if (this.carType == EnemyCarType.greenJeep) {\r\n for (let index = 0; index < 4; index++) {\r\n let a = index;\r\n let t = (index + 1);\r\n Laya.timer.frameOnce(t, this, this.CreateRole, [a], false);\r\n }\r\n }\r\n Laya.timer.frameOnce(6, this, this.SetAim);\r\n }\r\n CreateRole(index) {\r\n if (this.carType == EnemyCarType.pickup) {\r\n if (index <= this.enemycardata.enemy_list.length - 1) {\r\n let id = this.enemycardata.enemy_list[index];\r\n let enemy = EnemyController.Instance._CreateRole(this.carType, id);\r\n let enemyB = enemy.addComponent(Enemy);\r\n if (index == 0) {\r\n this.BackLeftPoint3.addChild(enemy);\r\n }\r\n else {\r\n this.BackRightPoint4.addChild(enemy);\r\n }\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 0, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n enemy.transform.localPosition = Mathf.VecZero;\r\n enemy.transform.localRotationEuler = Mathf.VecZero;\r\n this.rolesForCar.set(enemy.id, enemyB);\r\n }\r\n }\r\n else if (this.carType == EnemyCarType.redchongfeng) {\r\n let id = this.enemycardata.enemy_list[index];\r\n let enemy = EnemyController.Instance._CreateRole(this.carType, id);\r\n this.DriverPoint.addChild(enemy);\r\n let enemyB = enemy.addComponent(Enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 0, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n enemy.transform.localPosition = Mathf.VecZero;\r\n enemy.transform.localRotationEuler = Mathf.VecZero;\r\n this.rolesForCar.set(enemy.id, enemyB);\r\n }\r\n else if (this.carType == EnemyCarType.bluechongfeng) {\r\n let id = this.enemycardata.enemy_list[index];\r\n let enemy = EnemyController.Instance._CreateRole(this.carType, id);\r\n this.DriverPoint.addChild(enemy);\r\n let enemyB = enemy.addComponent(Enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 0, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n enemy.transform.localPosition = Mathf.VecZero;\r\n enemy.transform.localRotationEuler = Mathf.VecZero;\r\n this.rolesForCar.set(enemy.id, enemyB);\r\n }\r\n else if (this.carType == EnemyCarType.greenJeep) {\r\n if (index <= this.enemycardata.enemy_list.length - 1) {\r\n let id = this.enemycardata.enemy_list[index];\r\n let enemy = EnemyController.Instance._CreateRole(this.carType, id);\r\n let enemyB = enemy.addComponent(Enemy);\r\n if (index == 0) {\r\n this.DriverPoint.addChild(enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 1, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n }\r\n else if (index == 1) {\r\n this.FrontRightPoint2.addChild(enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 2, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n }\r\n else if (index == 2) {\r\n this.BackLeftPoint3.addChild(enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 3, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n }\r\n else if (index == 3) {\r\n this.BackRightPoint4.addChild(enemy);\r\n enemyB.SetCar(this.selfobj, this, id, this.enemycardata.halmet_type[index], this.enemycardata.halmet_hp[index], 4, this.enemycardata.hit_count[index], this.enemycardata.frequency[index]);\r\n }\r\n enemy.transform.localPosition = Mathf.VecZero;\r\n enemy.transform.localRotationEuler = Mathf.VecZero;\r\n this.rolesForCar.set(enemy.id, enemyB);\r\n }\r\n }\r\n }\r\n SetAim() {\r\n if (this.carType == EnemyCarType.pickup) {\r\n }\r\n else if (this.carType == EnemyCarType.redchongfeng) {\r\n let id1 = this.WheelFL.id;\r\n let p = EnemyController.carPriority[EnemyCarType.redchongfeng][1];\r\n let aim1 = new Aim(p, this.WheelFL.transform, AimColliderType.tyre1, 1, this);\r\n AimController.Instance.SetAim(id1, aim1);\r\n let id2 = this.WheelFR.id;\r\n let aim2 = new Aim(EnemyController.carPriority[EnemyCarType.redchongfeng][2], this.WheelFR.transform, AimColliderType.tyre2, 1, this);\r\n AimController.Instance.SetAim(id2, aim2);\r\n }\r\n else if (this.carType == EnemyCarType.bluechongfeng) {\r\n let id1 = this.WheelFL.id;\r\n let aim1 = new Aim(EnemyController.carPriority[EnemyCarType.bluechongfeng][1], this.WheelFL.transform, AimColliderType.tyre1, 1, this);\r\n AimController.Instance.SetAim(id1, aim1);\r\n let id2 = this.WheelFR.id;\r\n let aim2 = new Aim(EnemyController.carPriority[EnemyCarType.bluechongfeng][2], this.WheelFR.transform, AimColliderType.tyre2, 1, this);\r\n AimController.Instance.SetAim(id2, aim2);\r\n }\r\n else if (this.carType == EnemyCarType.greenJeep) {\r\n let id1 = this.WheelFL.id;\r\n let aim1 = new Aim(EnemyController.carPriority[EnemyCarType.greenJeep][1], this.WheelFL.transform, AimColliderType.tyre1, 1, this);\r\n AimController.Instance.SetAim(id1, aim1);\r\n let id2 = this.WheelFR.id;\r\n let aim2 = new Aim(EnemyController.carPriority[EnemyCarType.greenJeep][2], this.WheelFR.transform, AimColliderType.tyre2, 1, this);\r\n AimController.Instance.SetAim(id2, aim2);\r\n }\r\n AimController.Instance.JundgerAim();\r\n }\r\n InitData(enemycardata) {\r\n this.enemycardata = enemycardata;\r\n this.wheelbl_hp = this.wheelbr_hp = this.wheelfl_hp = this.wheelfr_hp = this.enemycardata.wheel_hp;\r\n }\r\n Atked(type) {\r\n switch (type) {\r\n case AimColliderType.tyre1:\r\n this.wheelfl_hp -= PlayerManager.bulletAttack;\r\n if (this.wheelfl_hp <= 0) {\r\n SettingController.Instance.PlayerCrash();\r\n this.Wreck();\r\n return;\r\n }\r\n this.SetMat(type, this.wheelfl_hp / this.enemycardata.wheel_hp);\r\n break;\r\n case AimColliderType.tyre2:\r\n this.wheelfr_hp -= PlayerManager.bulletAttack;\r\n if (this.wheelfr_hp <= 0) {\r\n SettingController.Instance.PlayerCrash();\r\n this.Wreck();\r\n return;\r\n }\r\n this.SetMat(type, this.wheelfr_hp / this.enemycardata.wheel_hp);\r\n break;\r\n case AimColliderType.tyre3:\r\n this.wheelbl_hp -= PlayerManager.bulletAttack;\r\n if (this.wheelbl_hp <= 0) {\r\n SettingController.Instance.PlayerCrash();\r\n this.Wreck();\r\n return;\r\n }\r\n this.SetMat(type, this.wheelbl_hp / this.enemycardata.wheel_hp);\r\n break;\r\n case AimColliderType.tyre4:\r\n this.wheelbr_hp -= PlayerManager.bulletAttack;\r\n if (this.wheelbr_hp <= 0) {\r\n SettingController.Instance.PlayerCrash();\r\n this.Wreck();\r\n return;\r\n }\r\n this.SetMat(type, this.wheelbr_hp / this.enemycardata.wheel_hp);\r\n break;\r\n }\r\n }\r\n HitEffect(point) {\r\n EffectController.Instance.CreateEffect(EffectController.effectName.hit, this.effectPoint, point);\r\n }\r\n XueEffect(point) {\r\n EffectController.Instance.CreateEffect(EffectController.effectName.xue, this.effectPoint, point);\r\n }\r\n SetMat(type, offset) {\r\n switch (type) {\r\n case AimColliderType.tyre1:\r\n if (!this.matfl) {\r\n this.matfl = new Laya.PBRStandardMaterial();\r\n this.matfl.enableEmission = true;\r\n this.WheelFL.meshRenderer.material = this.matfl;\r\n }\r\n break;\r\n case AimColliderType.tyre2:\r\n if (!this.matfr) {\r\n this.matfr = new Laya.PBRStandardMaterial();\r\n this.matfr.enableEmission = true;\r\n this.WheelFR.meshRenderer.material = this.matfr;\r\n }\r\n break;\r\n case AimColliderType.tyre3:\r\n if (!this.matbl) {\r\n this.matbl = new Laya.PBRStandardMaterial();\r\n this.matbl.enableEmission = true;\r\n this.WheelBL.meshRenderer.material = this.matbl;\r\n }\r\n break;\r\n case AimColliderType.tyre4:\r\n if (!this.matbr) {\r\n this.matbr = new Laya.PBRStandardMaterial();\r\n this.matbr.enableEmission = true;\r\n this.WheelBR.meshRenderer.material = this.matbr;\r\n }\r\n break;\r\n }\r\n }\r\n Wreck() {\r\n WXSdk.LongVibrate();\r\n if (this.ATV) {\r\n AimController.Instance.RemoveAim(this.WheelBL.id);\r\n AimController.Instance.RemoveAim(this.WheelBR.id);\r\n AimController.Instance.RemoveAim(this.WheelFL.id);\r\n AimController.Instance.RemoveAim(this.WheelFR.id);\r\n if (this.matfl) {\r\n this.WheelFL.meshRenderer.material = this.flMat;\r\n this.matfl.destroy();\r\n }\r\n if (this.matfr) {\r\n this.WheelFR.meshRenderer.material = this.frMat;\r\n this.matfr.destroy();\r\n }\r\n if (this.matbl) {\r\n this.WheelBL.meshRenderer.material = this.blMat;\r\n this.matbl.destroy();\r\n }\r\n if (this.matbr) {\r\n this.WheelBR.meshRenderer.material = this.brMat;\r\n this.matbr.destroy();\r\n }\r\n }\r\n for (const key in this.rolesForCar.container) {\r\n const element = this.rolesForCar.get(key);\r\n element.End();\r\n element.RemoveHelmat();\r\n element.RemoveSelf();\r\n }\r\n this.RemoveCar();\r\n this.TurnOver();\r\n let name = Math.random() > 0.5 ? EffectController.effectName.yan : EffectController.effectName.boom;\r\n EffectController.Instance.CreateEffect(name, SceneController.Instance._effectNode, this.tran.position.clone());\r\n EventManager.event(EventType.Event.RefreshRemainEnemyCount);\r\n }\r\n Jundgerpassenger() {\r\n for (const key in this.rolesForCar.container) {\r\n const element = this.rolesForCar.get(key);\r\n if (!element.isdead) {\r\n AimController.Instance._SetAim(element.headHit.id);\r\n return false;\r\n }\r\n }\r\n SettingController.Instance.PlayerCrash();\r\n this.Wreck();\r\n }\r\n BoomMove() {\r\n this.isBoom = true;\r\n }\r\n _BoomMove() {\r\n let tp = this.tarTra.position;\r\n let trp = this.tran.position;\r\n if (tp.z - trp.z > GlobalVariable.boomDisFor) {\r\n tp.x = trp.x;\r\n }\r\n Vector3.subtract(tp, trp, this.forW);\r\n Vector3.normalize(this.forW, this.forW);\r\n this.forW = new Vector3(this.forW.x * GlobalVariable.boomCarSpeed, this.forW.y, this.forW.z * GlobalVariable.boomCarSpeed);\r\n this.tran.translate(this.forW, false);\r\n if (Vector3.distance(trp, tp) < GlobalVariable.boomDisBoom) {\r\n PlayerController.Instance.PlayerAtked(true);\r\n SettingController.Instance.PlayerExplotion();\r\n this.Wreck();\r\n return;\r\n }\r\n Quaternion.lookAt(tp, trp, this._up, this.quaternion1);\r\n this.quaternion1.invert(this.quaternion1);\r\n this.tran.rotation = this.quaternion1.clone();\r\n }\r\n RemoveCar() {\r\n AimController.Instance.JundgerAim();\r\n this.rolesForCar.clear();\r\n }\r\n TurnOver() {\r\n Laya.timer.clearAll(this);\r\n let x = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomInt(0, 1);\r\n this._r.x = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._r.y = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._r.z = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._s.x = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0.01, 0.1);\r\n this._s.y = Game_Tool.randomFl(0.15, 0.3);\r\n this._s.z = -0.2;\r\n Laya.timer.frameLoop(1, this, this._m);\r\n }\r\n _m() {\r\n this.tran.translate(this._s, false);\r\n this.tran.rotate(this._r);\r\n this._s.y -= 0.005;\r\n if (this.tran.position.y <= 0) {\r\n Laya.timer.clearAll(this);\r\n this.TurnOverRemoveSelf();\r\n }\r\n }\r\n TurnOverRemoveSelf() {\r\n AIController.Instance.ClearCar(this.trackType);\r\n PoolManager.Instance.SetDisableObject(this.selfobj);\r\n this.destroy();\r\n PlayerController.Instance.EnemyDeadCreate();\r\n }\r\n Reset() {\r\n if (this.ATV) {\r\n AimController.Instance.RemoveAim(this.WheelBL.id);\r\n AimController.Instance.RemoveAim(this.WheelBR.id);\r\n AimController.Instance.RemoveAim(this.WheelFL.id);\r\n AimController.Instance.RemoveAim(this.WheelFR.id);\r\n if (this.matfl) {\r\n this.WheelFL.meshRenderer.material = this.flMat;\r\n this.matfl.destroy();\r\n }\r\n if (this.matfr) {\r\n this.WheelFR.meshRenderer.material = this.frMat;\r\n this.matfr.destroy();\r\n }\r\n if (this.matbl) {\r\n this.WheelBL.meshRenderer.material = this.blMat;\r\n this.matbl.destroy();\r\n }\r\n if (this.matbr) {\r\n this.WheelBR.meshRenderer.material = this.brMat;\r\n this.matbr.destroy();\r\n }\r\n }\r\n for (const key in this.rolesForCar.container) {\r\n const element = this.rolesForCar.get(key);\r\n element.End();\r\n element.RemoveHelmat();\r\n element.RemoveSelf();\r\n }\r\n AIController.Instance.ClearCar(this.trackType);\r\n PoolManager.Instance.SetDisableObject(this.selfobj);\r\n this.destroy();\r\n }\r\n onDisable() {\r\n }\r\n onDestroy() {\r\n Laya.timer.clearAll(this);\r\n super.onDestroy();\r\n }\r\n}\r\n", "references": [ "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Mathf.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Game_Tool.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EventManager.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/RoadController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/Car.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/DefinedType.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/game_module/GlobalVariable.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EnemyController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/Enemy.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/AimController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Dictionary.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/PlayerController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/AIController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/PoolManager.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/GameManager.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EffectController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/SceneController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/PlayerManager.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/game_module/WXSdk.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/SettingController.ts" ] }