12345678910111213141516171819202122 |
- {
- "code": "import Role from \"./Role\";\r\nimport AimController, { Aim } from \"./AimController\";\r\nimport { AimColliderType, EnemyCarType, AnimatorClip } from \"./DefinedType\";\r\nimport { GlobalVariable } from \"../game_module/GlobalVariable\";\r\nimport { PoolManager } from \"./PoolManager\";\r\nimport EnemyController from \"./EnemyController\";\r\nimport { Mathf } from \"../Util/Mathf\";\r\nimport GameManager from \"./GameManager\";\r\nimport { PlayerManager } from \"./PlayerManager\";\r\nimport { SettingController } from \"./SettingController\";\r\nimport GameDefined from \"./GameDefined\";\r\nimport Game_Tool from \"../Util/Game_Tool\";\r\nexport class Enemy extends Role {\r\n constructor() {\r\n super(...arguments);\r\n this.isdead = false;\r\n this._speed = Mathf.VecZero;\r\n this._rotate = Mathf.VecZero;\r\n }\r\n onAwake() {\r\n super.onAwake();\r\n this.nexkNode = this.selfobj.getChildAt(0).getChildAt(0).getChildByName(\"Bip001 Pelvis\").getChildByName(\"Bip001 Spine\").getChildByName(\"Bip001 Spine1\").getChildByName(\"Bip001 Spine2\").getChildByName(\"Bip001 Neck\");\r\n this.headHit = this.nexkNode.getChildByName(\"Bip001 Head\").getChildByName(\"HeadTarget\");\r\n this.HelmetPos = this.nexkNode.getChildByName(\"Bip001 Head\").getChildByName(\"HelmetPos\");\r\n }\r\n SetCar(car, carB, id, ishalmet, halmet_hp, isDriver, hit_count, frequency) {\r\n this.car = car;\r\n this.carB = carB;\r\n this._id = Number(id);\r\n this.ishavahamet = Number(ishalmet);\r\n this.origHp = Number(halmet_hp);\r\n this.halmetHp = Number(halmet_hp);\r\n this.isDriver = isDriver;\r\n this.isdead = false;\r\n this.frequency = Number(frequency);\r\n this.hit_rate = Number(this.carB.enemycardata.hit_rate);\r\n this.SetData();\r\n this.GetGun();\r\n this.SetSkin();\r\n this.CreateBullet();\r\n }\r\n SetSkin() {\r\n if (this.id == 7)\r\n return;\r\n let body = this.selfobj.getChildAt(0).getChildByName(\"character\");\r\n let mats = body.skinnedMeshRenderer.materials;\r\n mats[0].albedoTexture = Laya.loader.getRes(GameDefined.enemyTexture + this.id + \".png\");\r\n mats[0].emissionTexture = Laya.loader.getRes(GameDefined.enemyTexture + this.id + \".png\");\r\n mats[1].albedoTexture = Laya.loader.getRes(GameDefined.enemyTexture + this.id + \".png\");\r\n mats[1].emissionTexture = Laya.loader.getRes(GameDefined.enemyTexture + this.id + \".png\");\r\n }\r\n GetGun() {\r\n if (this.carB.carType == EnemyCarType.redchongfeng) {\r\n let body = this.selfobj.getChildAt(0).getChildByName(\"character\");\r\n this.body = body.skinnedMeshRenderer.materials[1];\r\n return;\r\n }\r\n ;\r\n if (this.isDriver == 1 || this.isDriver == 3) {\r\n this.Gun = this.nexkNode.getChildByName(\"Bip001 L Clavicle\").getChildByName(\"Bip001 L UpperArm\").getChildByName(\"Bip001 L Forearm\").getChildByName(\"Bip001 L Hand\").getChildByName(\"Gun\");\r\n this.Gun.active = true;\r\n let Gunr = this.nexkNode.getChildByName(\"Bip001 R Clavicle\").getChildByName(\"Bip001 R UpperArm\").getChildByName(\"Bip001 R Forearm\").getChildByName(\"Bip001 R Hand\").getChildByName(\"Gun\");\r\n Gunr.active = false;\r\n }\r\n else if (this.isDriver == 2 || this.isDriver == 4) {\r\n let Gunl = this.nexkNode.getChildByName(\"Bip001 L Clavicle\").getChildByName(\"Bip001 L UpperArm\").getChildByName(\"Bip001 L Forearm\").getChildByName(\"Bip001 L Hand\").getChildByName(\"Gun\");\r\n Gunl.active = false;\r\n this.Gun = this.nexkNode.getChildByName(\"Bip001 R Clavicle\").getChildByName(\"Bip001 R UpperArm\").getChildByName(\"Bip001 R Forearm\").getChildByName(\"Bip001 R Hand\").getChildByName(\"Gun\");\r\n this.Gun.active = true;\r\n }\r\n else\r\n this.Gun = this.nexkNode.getChildByName(\"Bip001 R Clavicle\").getChildByName(\"Bip001 R UpperArm\").getChildByName(\"Bip001 R Forearm\").getChildByName(\"Bip001 R Hand\").getChildByName(\"Gun\");\r\n this.FxMuzzle = this.Gun.getChildByName(\"FxMuzzle\").transform;\r\n }\r\n SetData() {\r\n let id4 = this.headHit.id;\r\n let aim = new Aim(EnemyController.rolePriority[this._id], this.headHit.transform, AimColliderType.role, 2, null, this);\r\n AimController.Instance.SetAim(id4, aim);\r\n this.CreateHalmet();\r\n }\r\n CreateHalmet() {\r\n if (!this.ishavahamet)\r\n return;\r\n Laya.timer.frameOnce(1, this, this._CreateHelmet);\r\n console.log(\"创建头盔\");\r\n }\r\n _CreateHelmet() {\r\n let h = EnemyController.Instance._CreateHalmet(this.ishavahamet);\r\n if (!h)\r\n return;\r\n this.helmetSp = h;\r\n this.helmetMat = this.helmetSp.meshRenderer.material;\r\n this.HelmetPos.addChild(h);\r\n h.transform.localPosition = Mathf.VecZero;\r\n h.transform.localRotationEuler = Mathf.VecZero;\r\n }\r\n CreateBullet() {\r\n Laya.timer.once(GlobalVariable.enemyShartShootTime * 1000, this, this._CreateBullet);\r\n }\r\n _CreateBullet() {\r\n if (this.carB.carType == EnemyCarType.redchongfeng) {\r\n Laya.timer.once(this.frequency * 1000, this, this.CB1);\r\n }\r\n else {\r\n Laya.timer.loop(this.frequency * 1000, this, this.CB);\r\n }\r\n }\r\n CB1() {\r\n this.carB.BoomMove();\r\n let a = this.body.albedoColorG;\r\n Laya.timer.loop(500, this, () => {\r\n a = a == 1 ? 0 : 1;\r\n this.body.albedoColorG = a;\r\n this.body.albedoColorB = a;\r\n });\r\n }\r\n CB() {\r\n if (GameManager.Instance.isgamePause)\r\n return;\r\n let clip;\r\n if (this.isDriver == 1 || this.isDriver == 3)\r\n clip = AnimatorClip.animator.RightShoot;\r\n else if (this.isDriver == 2 || this.isDriver == 4)\r\n clip = AnimatorClip.animator.LeftShoot;\r\n else if (this.carB.carType == EnemyCarType.pickup)\r\n clip = AnimatorClip.animator.pickupRoleShoot;\r\n else\r\n clip = AnimatorClip.animator.Shoot;\r\n this.PlayAni(clip, () => {\r\n EnemyController.Instance.CreateEnemyBullet(this.carB.trackType, this.FxMuzzle, this.hit_rate);\r\n SettingController.Instance.PlayerGunFire(1);\r\n if (this.carB.carType == EnemyCarType.pickup) {\r\n Laya.timer.once(800, this, () => {\r\n this.PlayAni(AnimatorClip.animator.pickupRoleStand);\r\n });\r\n }\r\n else {\r\n this.PlayAni(AnimatorClip.animator.Idea);\r\n }\r\n });\r\n }\r\n Atked(point) {\r\n if (this.isdead)\r\n return;\r\n if (this.ishavahamet) {\r\n this.HitEffect(false, point);\r\n this.halmetHp -= PlayerManager.bulletAttack;\r\n if (this.halmetHp <= 0) {\r\n this.ishavahamet = 0;\r\n this.RemoveHelmat();\r\n return;\r\n }\r\n this.SetMat(this.halmetHp / this.origHp);\r\n }\r\n else {\r\n PlayerManager.Instance.killCount++;\r\n this.isdead = true;\r\n this.End();\r\n this.CreateRigs();\r\n EnemyController.Instance.ShowTips(this.headHit.transform.position);\r\n if (this.isDriver == 1) {\r\n this.carB.Wreck();\r\n SettingController.Instance.PlayerCrash();\r\n }\r\n else {\r\n this.carB.Jundgerpassenger();\r\n }\r\n this.HitEffect(true, point);\r\n }\r\n }\r\n HitEffect(isxue, point) {\r\n if (isxue)\r\n this.carB.XueEffect(point);\r\n else\r\n this.carB.HitEffect(point);\r\n }\r\n SetMat(offset) {\r\n if (!this.helmetSp)\r\n return;\r\n if (!this.mat) {\r\n this.mat = new Laya.PBRStandardMaterial();\r\n this.mat.enableEmission = true;\r\n this.helmetSp.meshRenderer.material = this.mat;\r\n }\r\n }\r\n End() {\r\n AimController.Instance.RemoveAim(this.headHit.id);\r\n Laya.timer.clearAll(this);\r\n }\r\n RemoveSelf() {\r\n if (this.body) {\r\n this.body.albedoColorG = 1;\r\n this.body.albedoColorB = 1;\r\n }\r\n PoolManager.Instance.SetDisableObject(this.selfobj);\r\n this.destroy();\r\n }\r\n RemoveHelmat() {\r\n if (!this.helmetSp)\r\n return;\r\n if (this.mat) {\r\n this.helmetSp.meshRenderer.material = this.helmetMat;\r\n this.mat.destroy();\r\n }\r\n PoolManager.Instance.SetDisableObject(this.helmetSp);\r\n }\r\n onEnable() {\r\n }\r\n onDisable() {\r\n }\r\n CreateRigs() {\r\n let x = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomInt(0, 1);\r\n this._rotate.x = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._rotate.y = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._rotate.z = (Math.random() > 0.5 ? 1 : -1) * Game_Tool.randomFl(0, 0.1);\r\n this._speed.x = 0.01;\r\n this._speed.y = 0.3;\r\n this._speed.z = -0.2;\r\n Laya.timer.frameLoop(1, this, this._move);\r\n }\r\n _move() {\r\n this.tran.translate(this._speed, false);\r\n this.tran.rotate(this._rotate);\r\n this._speed.y -= 0.005;\r\n if (this.tran.position.y <= 0) {\r\n this.selfobj.active = false;\r\n Laya.timer.clearAll(this);\r\n }\r\n }\r\n onDestroy() {\r\n Laya.timer.clearAll(this);\r\n if (this.rig)\r\n this.rig.destroy();\r\n }\r\n}\r\n",
- "references": [
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/Role.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/Car.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EnemyCar.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/AimController.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/PoolManager.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/PlayerController.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EnemyController.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Mathf.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/PlayerManager.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/SettingController.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/GameDefined.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Game_Tool.ts"
- ]
- }
|