{ "code": "import { Role, RoleState, RoleData } from \"./Role\";\r\nimport { AssetManager } from \"./AssetManager\";\r\nimport { SceneManager } from \"./SceneManager\";\r\nimport PoolManager from \"../Util/PoolManager\";\r\nvar Vector3 = Laya.Vector3;\r\nimport { ColliderLay, GameState, TouchState, skintype, AccountUser } from \"./DataMaker\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport { GameManager } from \"./GameManager\";\r\nimport { LevelManager } from \"./LevelManager\";\r\nimport { GameUtils } from \"../Util/GameUtils\";\r\nimport { CameraManager } from \"./CameraManager\";\r\nimport { WeaponTrigger } from \"./WeaponTrigger\";\r\nimport { InputManager } from \"./InputManager\";\r\nimport { AudioControl, VoiceType } from \"./AudioControl\";\r\nimport { PlayerAccount } from \"../Network/PlayerAccount\";\r\nimport { TtSdk } from \"../Util/TtSdk\";\r\nexport class PlayerData extends RoleData {\r\n constructor(_id, _startpos) {\r\n super(_id, _startpos);\r\n }\r\n}\r\nexport class Player extends Role {\r\n constructor() {\r\n super(...arguments);\r\n this.onland = true;\r\n this.runpoint = [];\r\n this.movespeed = 1.25;\r\n this.curpos = new Vector3();\r\n this.currot = new Laya.Quaternion();\r\n this.landhit = new Laya.HitResult();\r\n this.forwardhit = new Laya.HitResult();\r\n this.playfall = false;\r\n this.canfowardmove = true;\r\n this.landg = 0;\r\n this.startcamerapos = new Vector3();\r\n this.startcamerarot = new Laya.Quaternion();\r\n this.find = false;\r\n }\r\n static Create(_data, _roleskin) {\r\n var roleid = _roleskin.skinid;\r\n var roleasset = AssetManager.role.getValue(roleid);\r\n if (roleasset == null)\r\n roleasset = AssetManager.role.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 mainrole = model.addComponent(Player);\r\n Player.mainpalyer = mainrole;\r\n var mneck;\r\n if (roleid > 1) {\r\n mneck = model.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(2).getChildAt(0).getChildAt(0);\r\n }\r\n else {\r\n mneck = model.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(2).getChildAt(0);\r\n }\r\n mainrole.lefthandpoint = mneck.getChildAt(1).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);\r\n mainrole.righthandpoint = mneck.getChildAt(2).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);\r\n mainrole.WeaponShow();\r\n mainrole.jseffect = PoolManager.GetSprite3D(AssetManager.effect.getValue(3));\r\n model.addChild(mainrole.jseffect);\r\n mainrole.jseffect.transform.localPosition = new Vector3(0, 0, 0);\r\n mainrole.jseffect.active = false;\r\n mainrole.mcollider = model.getChildAt(1).getComponent(Laya.PhysicsCollider);\r\n mainrole.mcollider.collisionGroup = ColliderLay.player;\r\n mainrole.Init(model);\r\n mainrole.OnInit();\r\n return mainrole;\r\n }\r\n OnInit() {\r\n this.mlevel = LevelManager.Instance.curlevel;\r\n this.movespeed = this.mlevel.leveldata.missiondata.move;\r\n this.RegEvent();\r\n CameraManager.Instance.SetFollow(this.cursprite);\r\n Laya.timer.frameLoop(1, this, this.OnLifeLoop);\r\n this.runpoint.push(this.cursprite.transform.position.clone());\r\n }\r\n OnClear() {\r\n this.curlweapontrigger.destroy();\r\n this.currweapontrigger.destroy();\r\n PoolManager.RecoverSprite3D(this.curlweapon);\r\n PoolManager.RecoverSprite3D(this.currweapon);\r\n PoolManager.RecoverSprite3D(this.jseffect, true);\r\n this.curlweaponeffect.destroy();\r\n this.currweaponeffect.destroy();\r\n if (this.wineffect)\r\n PoolManager.RecoverSprite3D(this.wineffect);\r\n EventManager.InputOff(TouchState.slider, this, this.OnSlider);\r\n EventManager.InputOff(TouchState.up, this, this.OnUp);\r\n EventManager.Off(EventType.Hit, this, this.OnHit);\r\n EventManager.GameOff(GameState.Playing, this, this.OnGamePlaying);\r\n Laya.timer.clear(this, this.OnLifeLoop);\r\n this.runpoint = [];\r\n }\r\n RegEvent() {\r\n EventManager.InputOn(TouchState.slider, this, this.OnSlider);\r\n EventManager.InputOn(TouchState.up, this, this.OnUp);\r\n EventManager.On(EventType.Hit, this, this.OnHit);\r\n EventManager.GameOn(GameState.Playing, this, this.OnGamePlaying);\r\n }\r\n OnGamePlaying() {\r\n }\r\n onStateChange(_state, _data) {\r\n if (_state == RoleState.Die) {\r\n this.OnEnterDie();\r\n }\r\n else if (_state == RoleState.Runing) {\r\n this.OnEnterRunning();\r\n }\r\n else if (_state == RoleState.Idle) {\r\n this.OnEnterIdle();\r\n }\r\n else if (_state == RoleState.Attack) {\r\n this.OnEnterAttack(_data);\r\n }\r\n else if (_state == RoleState.Win) {\r\n this.OnEnterWin();\r\n }\r\n }\r\n OnEnterWin() {\r\n TtSdk.Shake(false);\r\n this.curanimator.play(\"dance\");\r\n Laya.timer.clear(this, this.OnLifeLoop);\r\n this.wineffect = PoolManager.GetSprite3D(AssetManager.effect.getValue(6));\r\n SceneManager.mainscene.addChild(this.wineffect);\r\n this.wineffect.transform.position = this.cursprite.transform.position;\r\n AudioControl.ClearBgm();\r\n AudioControl.PlayVoice(VoiceType.win);\r\n Laya.timer.once(2500, this, () => {\r\n GameManager.Instance.ChangeGameState(GameState.Win);\r\n });\r\n }\r\n OnHit(_monster) {\r\n this.ChangeState(RoleState.Die);\r\n }\r\n OnEnterAttack(_sprite) {\r\n }\r\n OnEnterIdle() {\r\n if (!this.playfall)\r\n this.curanimator.play(\"idle\");\r\n }\r\n OnEnterRunning() {\r\n if (!this.playfall)\r\n this.curanimator.play(\"run\");\r\n }\r\n OnEnterDie() {\r\n TtSdk.Shake(false);\r\n AudioControl.ClearBgm();\r\n AudioControl.PlayVoice(VoiceType.lose);\r\n this.curanimator.play(\"die\");\r\n CameraManager.Instance.StopFollow();\r\n Laya.timer.frameOnce(80, this, () => {\r\n GameManager.Instance.ChangeGameState(GameState.Lose);\r\n });\r\n }\r\n OnEnterLose() {\r\n }\r\n OnGameWin(_player) {\r\n }\r\n OnSlider(_dir) {\r\n if (GameManager.Instance.curgamestate != GameState.Playing)\r\n return;\r\n var rotdir = _dir;\r\n this.Move(_dir, rotdir);\r\n }\r\n get revivepoint() {\r\n if (this.runpoint.length > 0) {\r\n return this.runpoint[0];\r\n }\r\n var datapos = LevelManager.Instance.curlevel.leveldata.playerdata.startpos;\r\n return new Vector3(datapos.x, datapos.y, datapos.z);\r\n }\r\n Revive() {\r\n this.cursprite.transform.position = this.revivepoint;\r\n this.end = false;\r\n this.ChangeState(RoleState.Idle, true);\r\n CameraManager.Instance.ResetTarget(this.cursprite);\r\n this.wudi = true;\r\n Laya.timer.once(5000, this, () => {\r\n this.wudi = false;\r\n });\r\n }\r\n Move(_dir, rotdir) {\r\n this.ChangeState(RoleState.Runing);\r\n if (this.currolestate != RoleState.Runing)\r\n return;\r\n var curdir = new Vector3(-rotdir.x, -rotdir.y, -rotdir.z);\r\n Laya.Quaternion.rotationLookAt(curdir, new Vector3(0, 1, 0), this.currot);\r\n this.currot.invert(this.currot);\r\n Laya.Quaternion.slerp(this.cursprite.transform.rotation, this.currot, 0.06, this.currot);\r\n this.cursprite.transform.rotation = this.currot;\r\n Vector3.add(this.cursprite.transform.position, _dir, this.curpos);\r\n var addv = 0.1 * this.movespeed;\r\n Vector3.lerp(this.cursprite.transform.position, this.curpos, addv, this.curpos);\r\n if (this.canfowardmove) {\r\n this.cursprite.transform.position = this.curpos;\r\n }\r\n EventManager.Trigger(EventType.Running, [this.cursprite.transform.position.clone()]);\r\n }\r\n OnUp() {\r\n this.ChangeState(RoleState.Idle);\r\n }\r\n WeaponShow(_skin = null) {\r\n var equip = PlayerAccount.CurAccountData.GetUser(AccountUser.equip_themes)[skintype.weapon];\r\n var equiipskin = PlayerAccount.CurAccountData.m_skinDic.getValue(equip);\r\n equiipskin = _skin == null ? equiipskin : _skin;\r\n var assetid = equiipskin.skinid - 6;\r\n if (this.curlweapon != null) {\r\n PoolManager.RecoverSprite3D(this.curlweapon);\r\n this.curlweaponeffect.destroy();\r\n }\r\n var weaponasset = AssetManager.weapon.getValue(assetid);\r\n if (weaponasset == null)\r\n weaponasset = AssetManager.weapon.getValue(1);\r\n this.curlweapon = PoolManager.GetSprite3D(weaponasset);\r\n this.curlweapontrigger = this.curlweapon.getChildAt(0).addComponent(WeaponTrigger);\r\n this.lefthandpoint.addChild(this.curlweapon);\r\n this.curlweapon.transform.localPosition = new Vector3(0, 0, 0);\r\n this.curlweapon.transform.localRotationEuler = new Vector3(0, 0, 0);\r\n this.curlweaponeffect = PoolManager.GetSprite3D(AssetManager.effect.getValue(7));\r\n this.curlweapon.addChild(this.curlweaponeffect);\r\n this.curlweaponeffect.transform.setWorldLossyScale(new Vector3(1, 1, 1));\r\n this.curlweaponeffect.transform.localPosition = new Vector3(0, 1, 0);\r\n if (this.currweapon != null) {\r\n PoolManager.RecoverSprite3D(this.currweapon);\r\n this.currweaponeffect.destroy();\r\n }\r\n this.currweapon = PoolManager.GetSprite3D(weaponasset);\r\n this.currweapontrigger = this.currweapon.getChildAt(0).addComponent(WeaponTrigger);\r\n this.righthandpoint.addChild(this.currweapon);\r\n this.currweapon.transform.localPosition = new Vector3(0, 0, 0);\r\n this.currweapon.transform.localRotationEuler = new Vector3(0, 0, 0);\r\n this.currweaponeffect = PoolManager.GetSprite3D(AssetManager.effect.getValue(7));\r\n this.currweapon.addChild(this.currweaponeffect);\r\n this.currweaponeffect.transform.setWorldLossyScale(new Vector3(1, 1, 1));\r\n this.currweaponeffect.transform.localPosition = new Vector3(0, 1, 0);\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 < 11) ? true : false;\r\n if (hitenter == false) {\r\n }\r\n if (this.landhit.collider.collisionGroup == ColliderLay.end) {\r\n this.ChangeState(RoleState.Win);\r\n }\r\n }\r\n return hitenter;\r\n }\r\n get ForwardCheck() {\r\n var hitenter = true;\r\n var curpos = this.cursprite.transform.position;\r\n var startpoint = new Vector3(curpos.x, curpos.y + 0.1, curpos.z);\r\n var dir = new Vector3();\r\n this.cursprite.transform.getForward(dir);\r\n dir = new Vector3(-dir.x, -dir.y, -dir.z);\r\n var ray = new Laya.Ray(startpoint, dir);\r\n if (SceneManager.mainscene.physicsSimulation.rayCast(ray, this.forwardhit, 0.5)) {\r\n if (this.forwardhit.collider.collisionGroup == ColliderLay.obstacle) {\r\n return false;\r\n }\r\n }\r\n return hitenter;\r\n }\r\n OnLifeLoop() {\r\n if (GameManager.Instance.curgamestate != GameState.Playing)\r\n return;\r\n var curland = this.LandCheck;\r\n if (curland) {\r\n var mpos = this.cursprite.transform.position;\r\n if (this.landhit) {\r\n this.cursprite.transform.position = new Vector3(mpos.x, this.landhit.point.y, mpos.z);\r\n this.runpoint.push(this.cursprite.transform.position.clone());\r\n if (this.runpoint.length > 50) {\r\n this.runpoint.splice(0, 1);\r\n }\r\n }\r\n }\r\n if (!this.onland && curland) {\r\n this.playfall = false;\r\n this.jseffect.active = false;\r\n if (this.currolestate == RoleState.Idle) {\r\n this.curanimator.play(\"idle\");\r\n }\r\n else if (this.currolestate == RoleState.Runing) {\r\n this.curanimator.play(\"run\");\r\n }\r\n this.landg = 0;\r\n }\r\n this.onland = curland;\r\n if (!this.onland) {\r\n if (this.playfall == false) {\r\n this.playfall = true;\r\n this.curanimator.play(\"fall\");\r\n this.jseffect.active = true;\r\n }\r\n if (this.landg != 0.1)\r\n this.landg = GameUtils.lerp(this.landg, 0.1, 0.025);\r\n var mpos = this.cursprite.transform.position;\r\n this.cursprite.transform.position = new Vector3(mpos.x, mpos.y - this.landg, mpos.z);\r\n this.CheckFallDie();\r\n }\r\n this.canfowardmove = this.ForwardCheck;\r\n }\r\n CheckFallDie() {\r\n if (this.cursprite.transform.position.y < LevelManager.Instance.curlevel.minhight - 3) {\r\n this.ChangeState(RoleState.Die);\r\n }\r\n }\r\n FindBoos(_boos) {\r\n if (this.find)\r\n return;\r\n this.find = true;\r\n InputManager.Instance.OnTouchOut();\r\n InputManager.caninput = false;\r\n this.startcamerapos = SceneManager.maincamera.transform.position.clone();\r\n this.startcamerarot = SceneManager.maincamera.transform.rotation.clone();\r\n CameraManager.Instance.StopFollow();\r\n this.ChangeState(RoleState.Wait);\r\n var lookdir = new Vector3();\r\n var boospos = _boos.cursprite.transform.position.clone();\r\n var mpos = Player.mainpalyer.cursprite.transform.position.clone();\r\n Vector3.subtract(mpos, boospos, lookdir);\r\n Vector3.normalize(lookdir, lookdir);\r\n Vector3.scale(lookdir, 6, lookdir);\r\n var lookpos = new Vector3();\r\n Vector3.add(boospos, lookdir, lookpos);\r\n lookpos = new Vector3(lookpos.x, lookpos.y + 3, lookpos.z);\r\n var booslookpos = new Vector3(boospos.x, boospos.y + 1, boospos.z);\r\n var ssf = GameUtils.TweenMove(SceneManager.maincamera.transform, lookpos, 1.2, Laya.Handler.create(this, () => {\r\n ssf.clear();\r\n _boos.Provocation(() => {\r\n this.BackCa();\r\n });\r\n }), Laya.Ease.quadOut, booslookpos);\r\n }\r\n BackCa() {\r\n SceneManager.maincamera.transform.rotation = this.startcamerarot;\r\n CameraManager.Instance.ResetTarget(this.cursprite);\r\n InputManager.caninput = true;\r\n }\r\n}\r\n", "references": [ "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Role.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AssetManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/PoolManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/EventManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/GameManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/Warrior.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelMaker.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/LevelManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/GameUtils.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/BezierCurve.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Window/InGameWindow.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/CameraManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/WeaponTrigger.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/InputManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/AudioControl.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SkinMaker.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Network/PlayerAccount.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/TtSdk.ts" ] }