using OWML.Common; using QSB.Animation; using QSB.Events; using QSB.Instruments.QSBCamera; using QSB.Player; using QSB.Utility; using UnityEngine; namespace QSB.Instruments { public class InstrumentsManager : PlayerSyncObject { private Transform rootObj; private AnimationType _savedType; private GameObject ChertDrum; public void InitLocal(Transform root) { rootObj = root; gameObject.AddComponent(); QSBInputManager.ChertTaunt += () => StartInstrument(AnimationType.Chert); QSBInputManager.EskerTaunt += () => StartInstrument(AnimationType.Esker); QSBInputManager.FeldsparTaunt += () => StartInstrument(AnimationType.Feldspar); QSBInputManager.GabbroTaunt += () => StartInstrument(AnimationType.Gabbro); QSBInputManager.RiebeckTaunt += () => StartInstrument(AnimationType.Riebeck); QSBInputManager.ExitTaunt += () => ReturnToPlayer(); QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments); } public void InitRemote(Transform root) { rootObj = root; QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments); } protected override void OnDestroy() { base.Awake(); if (!IsLocalPlayer) { return; } QSBInputManager.ChertTaunt -= () => StartInstrument(AnimationType.Chert); QSBInputManager.EskerTaunt -= () => StartInstrument(AnimationType.Esker); QSBInputManager.FeldsparTaunt -= () => StartInstrument(AnimationType.Feldspar); QSBInputManager.GabbroTaunt -= () => StartInstrument(AnimationType.Gabbro); QSBInputManager.RiebeckTaunt -= () => StartInstrument(AnimationType.Riebeck); QSBInputManager.ExitTaunt -= () => ReturnToPlayer(); } private void SetupInstruments() { var bundle = QSBCore.InstrumentAssetBundle; ChertDrum = MakeChertDrum(bundle); } private GameObject MakeChertDrum(AssetBundle bundle) { var drum = new GameObject(); var mf = drum.AddComponent(); mf.sharedMesh = bundle.LoadAsset("assets/Chert/hourglasstwinsmeshescharacters2.asset") as Mesh; var mr = drum.AddComponent(); if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) { mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent().material; } else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) { //mr.sharedMaterial = GameObject.Find("Props_HEA_Drums").GetComponent().material; // TODO : fix for instrument release mr.sharedMaterial = null; } drum.transform.parent = rootObj; drum.transform.rotation = rootObj.rotation; drum.transform.localPosition = Vector3.zero; drum.transform.localScale = new Vector3(16.0f, 16.5f, 16.0f); drum.SetActive(false); return drum; } public void StartInstrument(AnimationType type) { if (!IsLocalPlayer) { DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error); return; } if (Player.PlayingInstrument || !Locator.GetPlayerController().IsGrounded()) { return; } _savedType = Player.AnimationSync.CurrentType; CameraManager.Instance.SwitchTo3rdPerson(); SwitchToType(type); } public void ReturnToPlayer() { if (!Player.PlayingInstrument) { return; } CameraManager.Instance.SwitchTo1stPerson(); SwitchToType(_savedType); } public void SwitchToType(AnimationType type) { DebugLog.DebugWrite($"switch to type {type} player {PlayerId}"); GlobalMessenger.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type); QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type); CheckInstrumentProps(type); } public void CheckInstrumentProps(AnimationType type) { switch (type) { case AnimationType.Chert: ChertDrum.SetActive(true); break; case AnimationType.PlayerSuited: case AnimationType.PlayerUnsuited: ChertDrum.SetActive(false); break; } } } }