using System.Collections; using System.Collections.Generic; using UnityEngine; using RPGCreationKit; using RPGCreationKit.SaveSystem; namespace RPGCreationKit.Player { public class RckPlayer : PlayerUI { #region Singleton public static RckPlayer instance; private void Awake() { if (!instance) instance = this; } #endregion public override void Start() { // Set RckSettings RckInput.SetPlayerInputInstance(input); AssemblePlayerFromSavegame(); base.Start(); LoadSavegamePlayerStats(); } public void AssemblePlayerFromSavegame() { PlayerData f = SaveSystemManager.instance.saveFile.PlayerData; // Load and spawn Character related stuff Race pRace = RaceDatabase.GetItem(f.playerRace); // Spawn FPS arms and assign all we have to assign GameObject arms = (f.playerSex == false) ? pRace.maleFPS.gameObject : pRace.femaleFPS.gameObject; PlayerCombat.instance.AssignNewFPSArms(arms); GameObject character = (f.playerSex == false) ? pRace.maleModel.gameObject : pRace.femaleModel.gameObject; PlayerInInventory.instance.SpawnNewPlayer(pRace, character, f.playerSex, f.faceData, f.hairType, f.eyesType, f.SkinColor, f.LipsColor, f.HairColor); ThirdPersonPlayer.instance.SpawnNewPlayer(pRace, character, f.playerSex, f.faceData, f.hairType, f.eyesType, f.SkinColor, f.LipsColor, f.HairColor); } public void LoadSavegamePlayerStats() { FreezeAndDisableControl(); // Load Quests QuestManager.instance.LoadQuestDataFromSavefile(); // Move player first PlayerData f = SaveSystemManager.instance.saveFile.PlayerData; transform.position = f.playerPos; transform.rotation = f.playerRot; // Load Mouse state mouseLook.LoadSavegameRotation(); // Load Position WorldManager.instance.StartLoadingFromSavegame(); // Load Entity Attributes playerAttributes.attributes = SaveSystemManager.instance.saveFile.PlayerData.playerAttributes.attributes; playerAttributes.derivedAttributes = SaveSystemManager.instance.saveFile.PlayerData.playerAttributes.derivedAttributes; playerAttributes.ExecuteEffects(SaveSystemManager.instance.saveFile.PlayerData.playerAttributes.activeEffects.ToArray()); RPGCreationKit.Player.RckPlayer.instance.ResetRecover(); // Equip after everything else List toEquipAfter = new List(); // Load Inventory for (int i = 0; i < SaveSystemManager.instance.saveFile.PlayerData.playerInventory.items.Count; i++) { ItemInInventory item = SaveSystemManager.instance.saveFile.PlayerData.playerInventory.items[i]; var aItem = inventory.AddItem(item.externalItemID, item.Amount, false); if (item.isEquipped) { if (aItem.item.itemType == ItemTypes.ArmorItem && RCKFunctions.ContainsBiped(((ArmorItem)(aItem.item)).Bipeds, BipedObject.Shield)) { // Delay the equipment of shields toEquipAfter.Add(aItem); } else equipment.Equip(aItem); } } // Load Spells Knoweldge (From Save V 1.3 and forward) if (RCKSettings.GetSaveVersion(SaveSystemManager.instance.saveFile.SaveFileData.fileVersion) >= 13) // 13 means 1.3 { List spellsIDs = SaveSystemManager.instance.saveFile.PlayerData.spellsKnowledge.items; for (int i = 0; i < spellsIDs.Count; i++) SpellsKnowledge.Player.LearnSpell(spellsIDs[i]); if (!string.IsNullOrEmpty(SaveSystemManager.instance.saveFile.PlayerData.spellsKnowledge.equippedSpell)) SpellsKnowledge.Player.EquipSpell(SpellsDatabase.GetSpell(SaveSystemManager.instance.saveFile.PlayerData.spellsKnowledge.equippedSpell)); } //else we're loading an old 1.0 save, so no spells are knew if (PlayerCombat.instance != null) PlayerCombat.instance.OnEquipmentChanges(); if(PlayerInInventory.instance != null) PlayerInInventory.instance.OnEquipmentChangesHands(); if (PlayerInInventory.instance != null) PlayerInInventory.instance.OnEquipmentChangesAmmo(); for (int i = 0; i < toEquipAfter.Count; i++) { equipment.Equip(toEquipAfter[i]); } Inventory.PlayerInventory.InitializeInventory(); // Load other data PlayerData data = SaveSystemManager.instance.saveFile.PlayerData; if (data.playerCrouched) ForceCrouch(); if (data.weaponDrawn) PlayerCombat.instance.DrawWeapon(); // Load factions for (int i = 0; i < data.playerFactions.Count; i++) RckPlayer.instance.AddToFaction(data.playerFactions[i]); // Load Camera (From Save V 1.1 and forward) if (RCKSettings.GetSaveVersion(SaveSystemManager.instance.saveFile.SaveFileData.fileVersion) >= 11) // 11 means 1.1 { if (data.isInThirdPerson) SwitchToThirdPerson(); else SwitchToFirstPerson(); } else // If we're loading a 1.0 save, just stick with FPS SwitchToFirstPerson(); UpdateHealthStaminaGUI(); //UnfreezeAndEnableControls(); done by WorldManager } public void EnterInCutsceneMode() { isInCutsceneMode = true; Player.RckPlayer.instance.FreezeOnly(); // Disable GUI and other things Player.RckPlayer.instance.uiManager.compassGameObject.SetActive(false); Player.RckPlayer.instance.uiManager.crosshairGameObject.gameObject.SetActive(false); Player.RckPlayer.instance.uiManager.playerHealthSlider.gameObject.SetActive(false); Player.RckPlayer.instance.uiManager.playerStaminaSlider.gameObject.SetActive(false); Player.RckPlayer.instance.uiManager.playerManaSlider.gameObject.SetActive(false); PlayerCombat.instance.weaponUI.weaponIcon.gameObject.SetActive(false); PlayerCombat.instance.equippedSpellUI.gameObject.SetActive(false); PlayerCombat.instance.weaponUI.weaponContainer.gameObject.SetActive(false); PlayerCombat.instance.weaponUI.spellContainer.gameObject.SetActive(false); Player.RckPlayer.instance.cameraAnim.m_Animator.enabled = false; if (PlayerCombat.instance.fpcAnim != null) { PlayerCombat.instance.fpcAnim.SetBool("isMoving", false); PlayerCombat.instance.fpcAnim.SetBool("isSprinting", false); ThirdPersonPlayer.instance.m_Animator.SetFloat("Speed", 0.0f); ThirdPersonPlayer.instance.m_Animator.SetFloat("Sideways", 0.0f); } } public void LeaveCutsceneMode() { isInCutsceneMode = false; Player.RckPlayer.instance.Unfreeze(); // Restore GUI and other things Player.RckPlayer.instance.uiManager.compassGameObject.SetActive(true); Player.RckPlayer.instance.uiManager.crosshairGameObject.gameObject.SetActive(true); Player.RckPlayer.instance.uiManager.playerHealthSlider.gameObject.SetActive(true); Player.RckPlayer.instance.uiManager.playerStaminaSlider.gameObject.SetActive(true); Player.RckPlayer.instance.uiManager.playerManaSlider.gameObject.SetActive(true); PlayerCombat.instance.weaponUI.weaponIcon.gameObject.SetActive(true); PlayerCombat.instance.weaponUI.weaponIcon.gameObject.SetActive(true); PlayerCombat.instance.equippedSpellUI.gameObject.SetActive(true); PlayerCombat.instance.weaponUI.weaponContainer.gameObject.SetActive(true); PlayerCombat.instance.weaponUI.spellContainer.gameObject.SetActive(true); Player.RckPlayer.instance.cameraAnim.m_Animator.enabled = true; } public void KillCamera() { if (isInThirdPerson) { mainCamera.cullingMask = 0; tpsCamera.cullingMask = 1283383; } else { mainCamera.cullingMask = 1283895; tpsCamera.cullingMask = 0; } } [ContextMenu("SDAIJDASJIOAS")] public void Disableiea() { input.DeactivateInput(); Debug.Log(input.user); input.ActivateInput(); } } }