55af1b886d3781f6b5a942ae6aaec8ff6b65ffff 15 KB

1234567891011121314151617181920212223
  1. {
  2. "code": "import { Role, RoleState, RoleData } 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 { GameUtils } from \"../Util/GameUtils\";\r\nimport { LevelManager } from \"./LevelManager\";\r\nimport { Player } from \"./Player\";\r\nimport { RigObj } from \"../Util/RigObj\";\r\nimport { MonsterDataManager } from \"./MonsterDataManager\";\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 MonsterData extends RoleData {\r\n constructor(_id, _startpos) {\r\n super(_id, _startpos);\r\n this.boos = false;\r\n this.monsterconfig = MonsterDataManager.MonsterDic.getValue(_id);\r\n }\r\n}\r\nexport class Warrior extends Role {\r\n constructor() {\r\n super(...arguments);\r\n this.movespeed = 0.3;\r\n this.awakedistance = 8;\r\n this.attackdistance = 2;\r\n this.attackrate = 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 this.landhit = new Laya.HitResult();\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(Warrior);\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.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.CheckAttack);\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 if (this.cuteffect)\r\n PoolManager.RecoverSprite3D(this.cuteffect);\r\n this.curanimator.speed = 1;\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 = GameUtils.Vector32Length(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 = GameUtils.Vector32Length(_playerpos, curpos);\r\n if (dis < this.attackdistance && this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Attack);\r\n }\r\n else if (dis < this.awakedistance && this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Awake);\r\n }\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.displayer < this.attackdistance && this.currolestate == RoleState.Idle) {\r\n this.ChangeState(RoleState.Attack);\r\n }\r\n else {\r\n this.ChangeState(RoleState.Awake);\r\n }\r\n }\r\n onStateChange(_state, _data) {\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 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 this.curanimator.play(\"warrioridle\");\r\n if (this.life) {\r\n Laya.timer.frameOnce(40, 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 Laya.timer.clear(this, this.AttackLoop);\r\n this.AttackLoop();\r\n }\r\n AttackLoop() {\r\n this.curanimator.play(\"attack\");\r\n Laya.timer.frameOnce(40, this, this.CheckAttack);\r\n var attackduation = 100 / this.attackrate;\r\n Laya.timer.frameOnce(attackduation, this, () => {\r\n this.ChangeState(RoleState.Idle);\r\n });\r\n }\r\n CheckAttack() {\r\n if (this.currolestate == RoleState.Die)\r\n return;\r\n if (this.displayer < this.attackdistance * 1.4) {\r\n Player.mainpalyer.ChangeState(RoleState.Die);\r\n }\r\n }\r\n OnEnterAwake() {\r\n EventManager.Off(EventType.Running, this, this.OnRunning);\r\n this.life = true;\r\n this.curanimator.play(\"run\");\r\n this.SetMove(Player.mainpalyer);\r\n }\r\n SetMove(_target) {\r\n this.AttackTarget = _target;\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 && this.AttackTarget.currolestate != RoleState.Wait) {\r\n var mpos = this.cursprite.transform.position.clone();\r\n Vector3.subtract(this.AttackTarget.cursprite.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 var curland = this.LandCheck;\r\n if (curland) {\r\n var gasgag = this.cursprite.transform.position;\r\n if (this.landhit) {\r\n this.cursprite.transform.position = new Vector3(gasgag.x, this.landhit.point.y, gasgag.z);\r\n }\r\n this.cursprite.transform.position = this.movepos;\r\n }\r\n this.cursprite.transform.rotation = this.RotLook(this.AttackTarget.cursprite.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.2);\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 onTriggerEnter(_collider) {\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 }\r\n else {\r\n weapon.active = false;\r\n }\r\n }\r\n }\r\n get LandCheck() {\r\n var hitenter = false;\r\n var curpos = this.cursprite.transform.position;\r\n var startpoint = new Vector3(curpos.x, curpos.y + 10, curpos.z);\r\n var dir = new Vector3(0, -1, 0);\r\n var ray = new Laya.Ray(startpoint, dir);\r\n var landlay = ColliderLay.plane | ColliderLay.end;\r\n if (SceneManager.mainscene.physicsSimulation.rayCast(ray, this.landhit, 100, 1, landlay)) {\r\n var hight = startpoint.y - this.landhit.point.y;\r\n hitenter = true;\r\n hitenter = (hight > 9 && hight < 13) ? true : false;\r\n if (hitenter == false) {\r\n }\r\n }\r\n return hitenter;\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/MonsterDataManager.ts",
  17. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/GameManager.ts",
  18. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AudioControl.ts",
  19. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/TtSdk.ts",
  20. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Network/PlayerAccount.ts"
  21. ]
  22. }