03ab5cf9f3eb3ebcd3a3830fd0701a074be91106 18 KB

123456789101112131415161718192021222324
  1. {
  2. "code": "import { Role, RoleState } from \"./Role\";\r\nvar Vector3 = Laya.Vector3;\r\nimport { AssetManager } from \"./AssetManager\";\r\nimport PoolManager from \"../Util/PoolManager\";\r\nimport { SceneManager } from \"./SceneManager\";\r\nimport { ColliderLay } from \"./DataMaker\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport { LevelManager } from \"./LevelManager\";\r\nimport { Player } from \"./Player\";\r\nimport { RigObj } from \"../Util/RigObj\";\r\nimport { Bullet } from \"./Bullet\";\r\nimport { GameManager } from \"./GameManager\";\r\nimport { AudioControl, VoiceType } from \"./AudioControl\";\r\nimport { TtSdk } from \"../Util/TtSdk\";\r\nimport { PlayerAccount } from \"../Network/PlayerAccount\";\r\nexport class Shooter extends Role {\r\n constructor() {\r\n super(...arguments);\r\n this.awakespeed = 0.3;\r\n this.awakedistance = 10;\r\n this.attackdistance = 10;\r\n this.attackrate = 1;\r\n this.bulletspeed = 1;\r\n this.life = false;\r\n this.movedir = new Vector3();\r\n this.movepos = new Vector3();\r\n this.moverot = new Laya.Quaternion;\r\n }\r\n static Create(_data) {\r\n var roleid = _data.id;\r\n var roleasset = AssetManager.enemy.getValue(1);\r\n var model = PoolManager.GetSprite3D(roleasset);\r\n SceneManager.mainscene.addChild(model);\r\n model.transform.position = new Vector3(_data.startpos.x, _data.startpos.y, _data.startpos.z);\r\n model.transform.rotationEuler = new Vector3(model.transform.rotationEuler.x, 360 - _data.startpos.w, model.transform.rotationEuler.z);\r\n var monster = model.addComponent(Shooter);\r\n monster.mdata = _data;\r\n monster.provocationclip = _data.monsterconfig.provocationclip;\r\n var neck = model.getChildAt(0).getChildAt(0).getChildAt(1).getChildAt(0).getChildAt(2).getChildAt(0);\r\n monster.headpoint = neck.getChildAt(0).getChildAt(0);\r\n monster.weaponpoint = neck.getChildAt(2).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);\r\n monster.Init(model);\r\n monster.collider = model.getChildAt(1).getComponent(Laya.PhysicsCollider);\r\n monster.collider.collisionGroup = ColliderLay.monster;\r\n monster.collider.enabled = true;\r\n monster.SkinShow(monster.mdata.monsterconfig.masktype, monster.mdata.monsterconfig.weapontype);\r\n monster.awakedistance = _data.monsterconfig.recognition;\r\n monster.attackdistance = _data.monsterconfig.attack_range;\r\n monster.movespeed = _data.monsterconfig.move_speed;\r\n monster.attackrate = _data.monsterconfig.frequency;\r\n monster.bulletspeed = _data.monsterconfig.bullet_speed;\r\n monster.upsprite = model.getChildAt(0).getChildAt(2);\r\n monster.upsprite.active = true;\r\n monster.downsprite = model.getChildAt(0).getChildAt(1);\r\n monster.downsprite.active = true;\r\n monster.OnInit();\r\n return monster;\r\n }\r\n OnInit() {\r\n this.mlevel = LevelManager.Instance.curlevel;\r\n this.RegEvent();\r\n if (this.mdata.boos) {\r\n this.cursprite.transform.setWorldLossyScale(new Vector3(1.5, 1.5, 1.5));\r\n }\r\n }\r\n OnClear() {\r\n EventManager.Off(EventType.Cut, this, this.OnCut);\r\n EventManager.Off(EventType.Running, this, this.OnRunning);\r\n Laya.timer.clearAll(this);\r\n Laya.timer.clear(this, this.AttackLoop);\r\n Laya.timer.clear(this, this.MoveLoop);\r\n Laya.timer.clear(this, this.OnLife);\r\n this.SkinShow(0, 0);\r\n this.curanimator.speed = 1;\r\n if (this.cuteffect)\r\n PoolManager.RecoverSprite3D(this.cuteffect);\r\n if (this.diedownsprite) {\r\n var dieani = this.diedownsprite.getChildAt(0).getComponent(Laya.Animator);\r\n dieani.speed = 1;\r\n PoolManager.RecoverSprite3D(this.diedownsprite);\r\n }\r\n }\r\n RegEvent() {\r\n EventManager.On(EventType.Cut, this, this.OnCut);\r\n EventManager.On(EventType.Running, this, this.OnRunning);\r\n }\r\n WithPlaying() {\r\n if (this.mdata.boos) {\r\n Player.mainpalyer.FindBoos(this);\r\n }\r\n }\r\n OnCut(_collider) {\r\n if (_collider != this.collider)\r\n return;\r\n TtSdk.Shake(false);\r\n AudioControl.PlayVoice(VoiceType.cut);\r\n if (this.AttackTarget)\r\n this.StopMove();\r\n this.ChangeState(RoleState.Die, !PlayerAccount.CurAccountData.cuteffect);\r\n }\r\n get displayer() {\r\n var curpos = this.cursprite.transform.position.clone();\r\n var mainplayerpos = Player.mainpalyer.cursprite.transform.position.clone();\r\n var dis = Vector3.distance(mainplayerpos, curpos);\r\n return dis;\r\n }\r\n OnRunning(_playerpos) {\r\n if (this.life)\r\n return;\r\n var curpos = this.cursprite.transform.position.clone();\r\n var dis = Vector3.distance(_playerpos, curpos);\r\n if (dis < this.attackdistance && this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Attack);\r\n }\r\n if (this.AttackTarget)\r\n this.cursprite.transform.rotation = this.RotLook(this.AttackTarget.transform.position, false);\r\n }\r\n OnLife() {\r\n if (Player.mainpalyer.currolestate == RoleState.Die || Player.mainpalyer.currolestate == RoleState.Win)\r\n return;\r\n if (this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Attack);\r\n }\r\n if (this.AttackTarget)\r\n this.cursprite.transform.rotation = this.RotLook(this.AttackTarget.transform.position, false);\r\n }\r\n onStateChange(_state, _data) {\r\n Laya.timer.clear(this, this.AttackLoop);\r\n Laya.timer.clear(this, this.MoveLoop);\r\n Laya.timer.clear(this, this.OnLife);\r\n if (_state == RoleState.Awake) {\r\n this.OnEnterAwake();\r\n }\r\n else if (_state == RoleState.Die) {\r\n this.OnEnterDie(_data);\r\n }\r\n else if (_state == RoleState.Attack) {\r\n this.OnEnterAttack();\r\n }\r\n else if (_state == RoleState.Idle) {\r\n this.OnEnterIdle();\r\n }\r\n }\r\n OnEnterIdle() {\r\n if (this.curweaponid == 5) {\r\n this.curanimator.crossFade(\"dartsidle\", 0.2);\r\n }\r\n else if (this.curweaponid == 6) {\r\n this.curanimator.crossFade(\"gunidle\", 0.2);\r\n }\r\n else if (this.curweaponid == 7) {\r\n this.curanimator.crossFade(\"paoboosidle\", 0.2);\r\n }\r\n if (this.life) {\r\n Laya.timer.frameOnce(80, this, () => {\r\n Laya.timer.clear(this, this.OnLife);\r\n Laya.timer.frameLoop(1, this, this.OnLife);\r\n });\r\n }\r\n }\r\n OnEnterAttack() {\r\n this.life = true;\r\n Laya.timer.clear(this, this.AttackLoop);\r\n this.AttackLoop();\r\n this.AttackTarget = Player.mainpalyer.cursprite;\r\n this.cursprite.transform.rotation = this.RotLook(this.AttackTarget.transform.position, false);\r\n }\r\n AttackLoop() {\r\n if (this.curweaponid == 5) {\r\n this.curanimator.crossFade(\"darts\", 0.2);\r\n }\r\n else if (this.curweaponid == 6) {\r\n this.curanimator.play(\"shoot\");\r\n }\r\n else if (this.curweaponid == 7) {\r\n this.curanimator.crossFade(\"paoboosattack\", 0.2);\r\n }\r\n Laya.timer.frameOnce(30, this, () => {\r\n if (this.currolestate != RoleState.Die)\r\n this.Fire();\r\n });\r\n var attackrate = 100 / this.attackrate;\r\n Laya.timer.frameOnce(attackrate, this, () => {\r\n this.ChangeState(RoleState.Idle);\r\n });\r\n }\r\n Fire() {\r\n var bulletid;\r\n var firepo;\r\n var follow = false;\r\n var speed = this.mdata.monsterconfig.bullet_speed;\r\n if (this.curweaponid == 5) {\r\n bulletid = 2;\r\n firepo = this.curweapon.transform.position;\r\n }\r\n else if (this.curweaponid == 6) {\r\n bulletid = 1;\r\n firepo = this.firepoint.transform.position;\r\n }\r\n else if (this.curweaponid == 7) {\r\n bulletid = 3;\r\n firepo = this.curweapon.transform.position;\r\n follow = true;\r\n }\r\n if (this.mdata.monsterconfig.bulletamount == 1) {\r\n var bullet = new Bullet(this, firepo, bulletid, speed);\r\n bullet.Fire(null, Player.mainpalyer.cursprite, follow);\r\n }\r\n else if (this.mdata.monsterconfig.bulletamount == 2) {\r\n var bullet1 = new Bullet(this, firepo, bulletid, speed);\r\n bullet1.Fire(null, Player.mainpalyer.cursprite, follow);\r\n var dir = new Vector3();\r\n Vector3.subtract(Player.mainpalyer.cursprite.transform.position, bullet1.cursprite.transform.position, dir);\r\n var ggy = Math.atan(dir.z / dir.x) * 180 / Math.PI;\r\n var f = Vector3.scalarLength(dir);\r\n if (dir.x > 0)\r\n ggy += 180;\r\n console.log(\"angle:\", ggy);\r\n var ggy1 = ggy + 5;\r\n var xf1 = dir.x > 0 ? Math.abs(Math.sin(ggy1)) : -Math.abs(Math.sin(ggy1));\r\n var zf1 = dir.z > 0 ? Math.abs(Math.sin(ggy1)) : -Math.abs(Math.sin(ggy1));\r\n dir = new Vector3(xf1 * f, dir.y, zf1 * f);\r\n var bullet2 = new Bullet(this, firepo, bulletid, speed);\r\n bullet2.Fire(dir, null, follow);\r\n }\r\n else if (this.mdata.monsterconfig.bulletamount == 3) {\r\n var bullet = new Bullet(this, firepo, bulletid, speed);\r\n bullet.Fire(null, Player.mainpalyer.cursprite, follow);\r\n var dir = new Vector3();\r\n Vector3.subtract(Player.mainpalyer.cursprite.transform.position, bullet.cursprite.transform.position, dir);\r\n var ggy = Math.atan(dir.z / dir.x) * 180 / Math.PI;\r\n var f = Vector3.scalarLength(dir);\r\n if (dir.x > 0)\r\n ggy += 180;\r\n var ggy1 = ggy + 5;\r\n var xf1 = dir.x > 0 ? Math.abs(Math.sin(ggy1)) : -Math.abs(Math.sin(ggy1));\r\n var zf1 = dir.z > 0 ? Math.abs(Math.sin(ggy1)) : -Math.abs(Math.sin(ggy1));\r\n dir = new Vector3(xf1 * f, dir.y, zf1 * f);\r\n var bullet2 = new Bullet(this, firepo, bulletid, speed);\r\n bullet2.Fire(dir, null, follow);\r\n var dir2 = new Vector3();\r\n var ggy2 = ggy + 10;\r\n var xf2 = dir.x > 0 ? Math.abs(Math.sin(ggy2)) : -Math.abs(Math.sin(ggy2));\r\n var zf2 = dir.z > 0 ? Math.abs(Math.sin(ggy2)) : -Math.abs(Math.sin(ggy2));\r\n dir2 = new Vector3(xf2 * f, dir.y, zf2 * f);\r\n var bullet3 = new Bullet(this, firepo, bulletid, speed);\r\n bullet3.Fire(dir2, null, follow);\r\n }\r\n }\r\n OnEnterAwake() {\r\n EventManager.Off(EventType.Running, this, this.OnRunning);\r\n this.curanimator.play(\"run\");\r\n this.SetMove(Player.mainpalyer.cursprite);\r\n }\r\n SetMove(_target) {\r\n this.AttackTarget = _target;\r\n this.movespeed = this.awakespeed;\r\n Laya.timer.clear(this, this.MoveLoop);\r\n Laya.timer.frameLoop(1, this, this.MoveLoop);\r\n }\r\n StopMove() {\r\n Laya.timer.clear(this, this.MoveLoop);\r\n this.AttackTarget = null;\r\n }\r\n MoveLoop() {\r\n if (this.AttackTarget) {\r\n var mpos = this.cursprite.transform.position.clone();\r\n Vector3.subtract(this.AttackTarget.transform.position, mpos, this.movedir);\r\n Vector3.normalize(this.movedir, this.movedir);\r\n Vector3.scale(this.movedir, this.movespeed, this.movedir);\r\n Vector3.add(mpos, this.movedir, this.movepos);\r\n Vector3.lerp(mpos, this.movepos, 0.12, this.movepos);\r\n this.cursprite.transform.position = this.movepos;\r\n this.cursprite.transform.rotation = this.RotLook(this.AttackTarget.transform.position);\r\n if (this.displayer < this.attackdistance) {\r\n this.ChangeState(RoleState.Attack);\r\n }\r\n }\r\n }\r\n RotLook(_targetpos, _lerp = true) {\r\n var mpos = this.cursprite.transform.position.clone();\r\n _targetpos = new Vector3(_targetpos.x, mpos.y, _targetpos.z);\r\n Laya.Quaternion.lookAt(_targetpos, mpos, new Vector3(0, 1, 0), this.moverot);\r\n this.moverot.invert(this.moverot);\r\n if (_lerp)\r\n Laya.Quaternion.slerp(this.cursprite.transform.rotation, this.moverot, 0.2, this.moverot);\r\n this.cursprite.transform.rotation = this.moverot;\r\n return this.moverot;\r\n }\r\n BeBoom() {\r\n this.ChangeState(RoleState.Die, true);\r\n }\r\n OnEnterDie(_die = false) {\r\n GameManager.Instance.goldnum += LevelManager.Instance.curlevel.leveldata.missiondata.masterdrop;\r\n if (_die) {\r\n this.collider.enabled = false;\r\n this.curanimator.play(\"die\");\r\n if (this.mdata.boos)\r\n EventManager.Trigger(EventType.BoosDie, [this]);\r\n Laya.timer.frameOnce(80, this, () => {\r\n this.FallLand(this.cursprite.transform.position.y - 1, () => {\r\n this.Clear();\r\n });\r\n });\r\n return;\r\n }\r\n var cutasset = AssetManager.effect.getValue(4);\r\n this.cuteffect = PoolManager.GetSprite3D(cutasset);\r\n SceneManager.mainscene.addChild(this.cuteffect);\r\n this.cuteffect.transform.position = this.upsprite.transform.position.clone();\r\n this.diedownsprite = PoolManager.GetSprite3D(AssetManager.enemy.getValue(1));\r\n SceneManager.mainscene.addChild(this.diedownsprite);\r\n this.diedownsprite.transform.position = this.cursprite.transform.position.clone();\r\n this.diedownsprite.transform.rotationEuler = this.cursprite.transform.rotationEuler.clone();\r\n if (this.mdata.boos) {\r\n this.diedownsprite.transform.setWorldLossyScale(new Vector3(1.5, 1.5, 1.5));\r\n }\r\n var dieupsprite = this.diedownsprite.getChildAt(0).getChildAt(2);\r\n dieupsprite.active = false;\r\n var dieupsprite2 = this.diedownsprite.getChildAt(0).getChildAt(1);\r\n dieupsprite2.active = true;\r\n var dieani = this.diedownsprite.getChildAt(0).getComponent(Laya.Animator);\r\n dieani.speed = 0;\r\n var diec = this.diedownsprite.getChildAt(1).getComponent(Laya.PhysicsCollider);\r\n diec.enabled = false;\r\n var downrig = new RigObj(this.diedownsprite, null, 1, 1);\r\n downrig.minhight = 1;\r\n downrig.AddForce(new Laya.Vector3(0, 1, 0.5), 0.3);\r\n this.curanimator.speed = 0;\r\n this.downsprite.active = false;\r\n var mrig = new RigObj(this.cursprite, () => {\r\n mrig.Clear();\r\n this.Clear();\r\n }, 1);\r\n mrig.AddForce(new Laya.Vector3(0, 1, 1), 0.5, 2);\r\n if (this.mdata.boos)\r\n EventManager.Trigger(EventType.BoosDie, [this]);\r\n }\r\n OnEnterLose() {\r\n }\r\n onUpdate() {\r\n }\r\n EscapeLoop() {\r\n }\r\n AwakeLoop() {\r\n }\r\n SkinShow(headid, weaponid) {\r\n for (var i = 0; i < this.headpoint.numChildren; i++) {\r\n var head = this.headpoint.getChildAt(i);\r\n head.active = headid - 1 == i;\r\n }\r\n for (var i = 0; i < this.weaponpoint.numChildren; i++) {\r\n var weapon = this.weaponpoint.getChildAt(i);\r\n if (weaponid - 1 == i) {\r\n this.curweapon = weapon;\r\n this.curweapon.active = true;\r\n this.curweaponid = weaponid;\r\n if (weaponid == 6) {\r\n this.firepoint = this.curweapon.getChildAt(1);\r\n }\r\n }\r\n else {\r\n weapon.active = false;\r\n }\r\n }\r\n }\r\n}\r\n",
  3. "references": [
  4. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Role.ts",
  5. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AssetManager.ts",
  6. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PoolManager.ts",
  7. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts",
  8. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts",
  9. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/EventManager.ts",
  10. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/GameUtils.ts",
  11. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelMaker.ts",
  12. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelManager.ts",
  13. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Player.ts",
  14. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PathMove.ts",
  15. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/RigObj.ts",
  16. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Warrior.ts",
  17. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Bullet.ts",
  18. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/GameManager.ts",
  19. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AudioControl.ts",
  20. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/TtSdk.ts",
  21. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Network/PlayerAccount.ts"
  22. ]
  23. }