725 lines
29 KiB
C#
725 lines
29 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Invector;
|
|
using Invector.vCharacterController;
|
|
using UnityEngine.Events;
|
|
using PixelCrushers.DialogueSystem;
|
|
using PixelCrushers.Wrappers;
|
|
using Sirenix.OdinInspector;
|
|
using PixelCrushers.QuestMachine;
|
|
using QuestState = PixelCrushers.QuestMachine.QuestState;
|
|
using Random = UnityEngine.Random;
|
|
using UnityEngine.UI;
|
|
using Invector.vCharacterController.vActions;
|
|
using Invector.vMelee;
|
|
using static PixelCrushers.DialogueSystem.DialogueSystemEvents;
|
|
|
|
namespace Beyond
|
|
{
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class Player : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<PlayerAttribute> m_playerAttributes = new List<PlayerAttribute>();
|
|
|
|
public static readonly int[] BrightnessPoints_Th = { 30, 20, 0 };
|
|
|
|
public List<PlayerAttribute> Attributes => m_playerAttributes;
|
|
|
|
public GameObject audioSource;
|
|
|
|
public AudioClip[] m_onHitClips, m_noFaithClips, m_cantDoThatYetClips, m_BrightnessLostClips, m_BrightnessGainedClips, m_deathClips;
|
|
public AudioClip[] consumeDefaultSounds, consumeFaithSounds, consumeGemstoneSounds, equipWeaponSounds, equipConsumablesSounds, equipPowerSounds, unequipWeaponSounds, unequipConsumablesSounds, unequipPowerSounds, changePageSounds, changeCategorySounds, openMenuSounds, acceptGuiltSounds, declineGuiltSounds, fullyChargedSounds;
|
|
|
|
private List<bItemType> weaponTypes = new List<bItemType> { bItemType.Swords, bItemType.Axes };
|
|
private List<bItemType> consumablesTypes = new List<bItemType> { bItemType.Consumable, bItemType.ConsumablesFaith };
|
|
|
|
public Image interactionImage;
|
|
private Sprite defaultInteractionImage;
|
|
public Sprite dialogueInteractionImage;
|
|
protected AudioSource m_audioSource;
|
|
public AudioSource AudioSource => m_audioSource;
|
|
|
|
private bThirdPersonInput m_vInputs;
|
|
private bThirdPersonController m_vController;
|
|
private vMeleeManager m_meleeManager;
|
|
private Respawner m_Respawner;
|
|
private bool m_cutScenePlaying = false;
|
|
|
|
private QuestJournal m_questJournal;
|
|
private PlayerConfessionController m_playerConfessionController;
|
|
public QuestJournal QuestJournal => m_questJournal;
|
|
public PlayerConfessionController PlayerConfessionController => m_playerConfessionController;
|
|
public bThirdPersonInput PlayerInput => m_vInputs;
|
|
public bThirdPersonController ThirdPersonController => m_vController;
|
|
|
|
public float slowMoOnHtScale = 0.1f;
|
|
public float slowMoOnHitTime = 0.1f;
|
|
public vMeleeManager MeleeManager => m_meleeManager;
|
|
|
|
private static Player s_instance;
|
|
public static Player Instance => s_instance;
|
|
|
|
public bItemManager ItemManager { private set; get; }
|
|
public WeaponTrail ActiveWeaponTrail { set; get; }
|
|
|
|
private PlayerAttribute faithAttribute;
|
|
private PlayerAttribute brightnessAttribute;
|
|
private PlayerAttribute maturityAttribute;
|
|
private MagicAttacks m_magicAttacks;
|
|
private bMeleeCombatInput m_meleeCombatInput;
|
|
|
|
public MagicAttacks Magic => m_magicAttacks;
|
|
public bMeleeCombatInput MeleeCombatInput => m_meleeCombatInput;
|
|
|
|
// --- TRINKET SYSTEM INTEGRATION START ---
|
|
private TrinketManager.TrinketStats m_trinketStats = new TrinketManager.TrinketStats
|
|
{
|
|
healthMult = 1f,
|
|
defenseMult = 1f,
|
|
faithMult = 1f,
|
|
damageMult = 1f,
|
|
speedMult = 1f,
|
|
faithRegenMult = 1f,
|
|
attackSpeedMult = 1f,
|
|
thornDamageMult = 1f
|
|
};
|
|
|
|
public TrinketManager.TrinketStats CurrentTrinketStats => m_trinketStats;
|
|
|
|
public void UpdateTrinketStats(TrinketManager.TrinketStats newStats)
|
|
{
|
|
m_trinketStats = newStats;
|
|
// Force stats recalculation
|
|
UodatePlayerStatistics();
|
|
|
|
// Apply immediate effects
|
|
if (m_vController)
|
|
{
|
|
m_vController.speedMultiplier = m_trinketStats.speedMult;
|
|
}
|
|
}
|
|
// --- TRINKET SYSTEM INTEGRATION END ---
|
|
|
|
public PlayerAttribute MaturityAttribute
|
|
{
|
|
get
|
|
{
|
|
SetMaturityAttributeIfNull();
|
|
return maturityAttribute;
|
|
}
|
|
}
|
|
|
|
public PlayerAttribute BrightnessAttribute
|
|
{
|
|
get
|
|
{
|
|
SetBrightnessAttributeIfNull();
|
|
return brightnessAttribute;
|
|
}
|
|
}
|
|
|
|
public PlayerAttribute FaithAttribute
|
|
{
|
|
get
|
|
{
|
|
SetFaithAttributeIfNull();
|
|
return faithAttribute;
|
|
}
|
|
}
|
|
|
|
private void SetMaturityAttributeIfNull()
|
|
{
|
|
if (maturityAttribute == null) maturityAttribute = GetAttribute("Maturity");
|
|
}
|
|
|
|
private void SetBrightnessAttributeIfNull()
|
|
{
|
|
if (brightnessAttribute == null) brightnessAttribute = GetAttribute("BrightnessPoints");
|
|
}
|
|
|
|
private void SetFaithAttributeIfNull()
|
|
{
|
|
if (maturityAttribute == null) faithAttribute = GetAttribute("Faith");
|
|
}
|
|
|
|
[SerializeField] public MenuScroll menuScroll;
|
|
|
|
public float sceneDependantFaithRegenMultiplier = 1f, faithRegenMultiplier = 1f;
|
|
|
|
private float healthBaseMaxValue = 200;
|
|
private float healthBaseRegenValue = 0f;
|
|
private float staminaBaseMaxValue = 200;
|
|
private float staminaBaseRegenValue = 1.2f;
|
|
private float faithBaseMaxValue = 100f;
|
|
|
|
private System.Action onMenuScrollClosed;
|
|
public System.Action<float> onStatsUpdated;
|
|
private UnityAction<Transform> onDialogueEnded;
|
|
private bLockOn m_lockOn;
|
|
public bLockOn LockOn => m_lockOn;
|
|
private vLadderAction ladderAction;
|
|
|
|
public float CurrentHealth => m_vController.currentHealth;
|
|
public float MaxHealth => m_vController.MaxHealth;
|
|
|
|
public AutoTargetting AutoTarget => m_autoTargetting;
|
|
private AutoTargetting m_autoTargetting;
|
|
|
|
private void Awake()
|
|
{
|
|
if (s_instance == null) s_instance = this;
|
|
else
|
|
{
|
|
Debug.LogError($"Player instance already exists! Destroying...({gameObject.name})");
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
m_lockOn = GetComponent<bLockOn>();
|
|
ladderAction = GetComponent<vLadderAction>();
|
|
m_audioSource = GetComponent<AudioSource>();
|
|
m_vInputs = GetComponent<bThirdPersonInput>();
|
|
m_vController = GetComponent<bThirdPersonController>();
|
|
ItemManager = GetComponent<bItemManager>();
|
|
m_questJournal = GetComponent<QuestJournal>();
|
|
m_Respawner = GetComponent<Respawner>();
|
|
m_playerConfessionController = GetComponent<PlayerConfessionController>();
|
|
m_meleeManager = GetComponent<vMeleeManager>();
|
|
m_magicAttacks = GetComponent<MagicAttacks>();
|
|
m_autoTargetting = GetComponent<AutoTargetting>();
|
|
m_meleeCombatInput = GetComponent<bMeleeCombatInput>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
HideUI.SetActive += OnCustcene;
|
|
if (m_vInputs) m_vInputs.forceWalking = false;
|
|
}
|
|
|
|
protected void Start()
|
|
{
|
|
InitAttributesValues();
|
|
InitAttributListeners();
|
|
RegisterLuaFunctions();
|
|
DialogueManager.instance.conversationStarted += OnConversationStarted;
|
|
DialogueManager.instance.conversationEnded += OnConversationEnded;
|
|
m_Respawner.m_onRespawned.AddListener(ResetInputs);
|
|
m_vController.onDead.AddListener(ResetAnimator);
|
|
if (m_meleeManager)
|
|
{
|
|
m_meleeManager.onDamageHit.AddListener(OnDamageHit);
|
|
}
|
|
}
|
|
|
|
private void OnDamageHit(vHitInfo arg0)
|
|
{
|
|
// Slow motion logic (existing)
|
|
if (slowMoOnHtScale < 1f - float.Epsilon)
|
|
{
|
|
TimeController.Instance.Reset();
|
|
}
|
|
|
|
// 1. Health Vampirism
|
|
if (m_trinketStats.effectHealthVampirism)
|
|
{
|
|
// Logic: Heal 2% of Player's Max Health per hit
|
|
// Mathf.Max ensures we always heal at least 1 HP
|
|
int healAmount = Mathf.Max(1, (int)(MaxHealth * 0.02f));
|
|
m_vController.ChangeHealth(healAmount);
|
|
}
|
|
|
|
// 2. Faith Vampirism
|
|
if (m_trinketStats.effectFaithVampirism)
|
|
{
|
|
// Logic: Add 1 Faith point per hit
|
|
UpdateFaithCurrentValue(1);
|
|
}
|
|
// ----------------------------
|
|
}
|
|
|
|
private void OnConversationStarted(Transform transform)
|
|
{
|
|
PlayerInput.SetLockAllInput(true);
|
|
}
|
|
|
|
private void OnConversationEnded(Transform transform)
|
|
{
|
|
PlayerInput.SetLockAllInput(false);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
HideUI.SetActive -= OnCustcene;
|
|
}
|
|
|
|
protected void OnDestroy()
|
|
{
|
|
RemoveAttributeListeners();
|
|
UnregisterLuaFunctions();
|
|
if (menuScroll != null) menuScroll.OnClosed -= onMenuScrollClosed;
|
|
if (DialogueManager.instance != null)
|
|
{
|
|
DialogueManager.instance.conversationStarted -= OnConversationStarted;
|
|
DialogueManager.instance.conversationEnded -= OnConversationEnded;
|
|
}
|
|
m_Respawner.m_onRespawned.RemoveListener(ResetInputs);
|
|
m_Respawner.m_onRespawnedStart.RemoveListener(ResetAnimator);
|
|
}
|
|
|
|
protected void Update()
|
|
{
|
|
float faith = faithAttribute.AttributeCurrentValue;
|
|
faith += Time.deltaTime * faithRegenMultiplier;
|
|
faithAttribute.SetValue(faith);
|
|
}
|
|
|
|
public void ResetInputs()
|
|
{
|
|
bThirdPersonController controller = (bThirdPersonController)m_vController;
|
|
controller.triggerDieBehaviour = false;
|
|
ladderAction = GetComponent<vLadderAction>();
|
|
ladderAction.ResetPlayerSettings();
|
|
}
|
|
|
|
public void ResetAnimator(GameObject gameObject)
|
|
{
|
|
ResetAnimator();
|
|
}
|
|
|
|
public void ResetAnimator()
|
|
{
|
|
bThirdPersonController controller = (bThirdPersonController)m_vController;
|
|
controller.animator.SetInteger(vAnimatorParameters.ActionState, 0);
|
|
controller.RemoveAnimatorTags();
|
|
}
|
|
|
|
// ... [Audio Play Methods - kept same] ...
|
|
public void PlayNoFaithClip() { PlayRandomSound(m_noFaithClips); }
|
|
private void PlayRandomSound(AudioClip[] sounds)
|
|
{
|
|
if (Time.timeSinceLevelLoad < 1f) return;
|
|
int soundsCount = sounds.Length;
|
|
if (audioSource != null && soundsCount > 0)
|
|
{
|
|
AudioClip clip = sounds[Random.Range(0, soundsCount)];
|
|
GameObject audioObject = Instantiate(audioSource, transform.position, transform.rotation) as GameObject;
|
|
audioObject.GetComponent<AudioSource>().PlayOneShot(clip);
|
|
}
|
|
}
|
|
public void PlayICantDoThatYet() { PlayRandomSound(m_cantDoThatYetClips); }
|
|
public void PlayBrightnessLost() { PlayRandomSound(m_BrightnessLostClips); }
|
|
public void PlayBrightnessGained() { PlayRandomSound(m_BrightnessGainedClips); }
|
|
public void PlayMaturityGained() { PlayRandomSound(m_BrightnessGainedClips); }
|
|
public void PlayConsumeSound(bItem consumedItem)
|
|
{
|
|
if (consumedItem.type == bItemType.ConsumablesFaith) PlayRandomSound(consumeFaithSounds);
|
|
else if (consumedItem.type == bItemType.Gemstones) PlayRandomSound(consumeGemstoneSounds);
|
|
else if (consumedItem.type == bItemType.PowerScroll) { }
|
|
else PlayRandomSound(consumeDefaultSounds);
|
|
}
|
|
public void PlayFullyChargedSound() { PlayRandomSound(fullyChargedSounds); }
|
|
public void PlayEquipSound(bEquipArea equipArea, bItem item)
|
|
{
|
|
if (consumablesTypes.Contains(item.type)) PlayRandomSound(equipConsumablesSounds);
|
|
else if (weaponTypes.Contains(item.type)) PlayRandomSound(equipWeaponSounds);
|
|
else PlayRandomSound(equipPowerSounds);
|
|
}
|
|
public void PlayUnequipSound(bEquipArea equipArea, bItem item)
|
|
{
|
|
if (consumablesTypes.Contains(item.type)) PlayRandomSound(unequipConsumablesSounds);
|
|
else if (weaponTypes.Contains(item.type)) PlayRandomSound(unequipWeaponSounds);
|
|
else PlayRandomSound(unequipPowerSounds);
|
|
}
|
|
public void PlayCategoryChangeSound() { PlayRandomSound(changeCategorySounds); }
|
|
public void PlayChangePageSound() { PlayRandomSound(changePageSounds); }
|
|
public void PlayOpenMenuSound() { PlayRandomSound(openMenuSounds); }
|
|
public void PlayAcceptGuiltSound() { PlayRandomSound(acceptGuiltSounds); }
|
|
public void PlayDeclineGuiltSound() { PlayRandomSound(declineGuiltSounds); }
|
|
public void PlayOnHitSound() { PlayRandomSound(m_onHitClips); }
|
|
public void PlayOnDeathSound() { PlayRandomSound(m_deathClips); }
|
|
|
|
private void OnCustcene(bool b)
|
|
{
|
|
m_audioSource.Stop();
|
|
m_audioSource.clip = null;
|
|
m_cutScenePlaying = !b;
|
|
m_vController.isImmortal = !b;
|
|
}
|
|
|
|
public void OnReceivedDamage(vDamage damage)
|
|
{
|
|
if (m_cutScenePlaying) return;
|
|
|
|
// --- TRINKET DEFENSE CALCULATION ---
|
|
// defenseMult of 0.9 means 90% damage taken (10% reduction)
|
|
if (Mathf.Abs(m_trinketStats.defenseMult - 1f) > float.Epsilon)
|
|
{
|
|
damage.damageValue = (int)(damage.damageValue * m_trinketStats.defenseMult);
|
|
}
|
|
// -----------------------------------
|
|
|
|
#if UNITY_IOS && !UNITY_EDITOR
|
|
HapticEngine.ImpactFeedbackHeavy();
|
|
#endif
|
|
if (m_onHitClips != null && m_onHitClips.Length > 0) PlayOnHitSound();
|
|
}
|
|
|
|
public void OnDead(GameObject gameObject)
|
|
{
|
|
if (m_cutScenePlaying) return;
|
|
#if UNITY_IOS && !UNITY_EDITOR
|
|
HapticEngine.ImpactFeedbackHeavy();
|
|
#endif
|
|
if (m_deathClips != null && m_deathClips.Length > 0) PlayOnDeathSound();
|
|
}
|
|
|
|
public void OnCheckpoint()
|
|
{
|
|
if (m_Respawner) m_Respawner.SaveRespawnPoint();
|
|
}
|
|
|
|
public List<Quest> GetAllGuilts()
|
|
{
|
|
if (!m_questJournal)
|
|
{
|
|
Debug.LogError("There is no Players Journal component on player game object");
|
|
return null;
|
|
}
|
|
List<Quest> guilts = new List<Quest>();
|
|
for (int i = 0; i < m_questJournal.questList.Count; i++)
|
|
{
|
|
if (m_questJournal.questList[i].isTrackable == false)
|
|
{
|
|
guilts.Add(m_questJournal.questList[i]);
|
|
}
|
|
}
|
|
return guilts;
|
|
}
|
|
|
|
[Button]
|
|
public void Debug_DisplayAllGuilts()
|
|
{
|
|
var guilts = GetAllGuilts();
|
|
guilts.ForEach(x => Debug.LogError(x.title));
|
|
}
|
|
|
|
public PlayerAttribute GetAttribute(string name)
|
|
{
|
|
for (int i = 0; i < m_playerAttributes.Count; i++)
|
|
{
|
|
if (m_playerAttributes[i].AttributeName == name) return m_playerAttributes[i];
|
|
}
|
|
Debug.LogError("There is no player attribute such " + name);
|
|
return null;
|
|
}
|
|
|
|
public void SetAttribute(string name, int value)
|
|
{
|
|
PlayerAttribute playerAttribute = GetAttribute(name);
|
|
if (playerAttribute == null) return;
|
|
playerAttribute.SetValue(value);
|
|
}
|
|
|
|
public void SetAttribute(PlayerAttribute attribute)
|
|
{
|
|
PlayerAttribute playerAttribute = GetAttribute(attribute.AttributeName);
|
|
if (playerAttribute == null) return;
|
|
playerAttribute.SetValue(attribute);
|
|
}
|
|
|
|
public void ClearAttributesValue()
|
|
{
|
|
m_playerAttributes.ForEach(x => x.ClearValue());
|
|
}
|
|
|
|
private void InitAttributesValues()
|
|
{
|
|
m_playerAttributes.ForEach(x => x.Init());
|
|
}
|
|
|
|
private void InitAttributListeners()
|
|
{
|
|
brightnessAttribute = GetAttribute("BrightnessPoints");
|
|
if (brightnessAttribute != null)
|
|
{
|
|
brightnessAttribute.OnValueChanged.AddListener(OnBrightnessPointsValueChanged);
|
|
brightnessAttribute.OnValueChanged.AddListener(UpdatePlayerStatisticsOnBrightnessChange);
|
|
}
|
|
else Debug.LogError("Couldnt get Brightness attribute ");
|
|
|
|
faithAttribute = GetAttribute("Faith");
|
|
if (faithAttribute == null) Debug.LogError("Couldnt get Faith attribute ");
|
|
|
|
maturityAttribute = GetAttribute("Maturity");
|
|
if (maturityAttribute != null)
|
|
{
|
|
maturityAttribute.OnValueChanged.AddListener(UpdatePlayerStatisticsOnMaturityChange);
|
|
maturityAttribute.OnValueChanged.AddListener(OnMaturityPointsValueChanged);
|
|
}
|
|
else Debug.LogError("Couldnt get Maturity attribute ");
|
|
}
|
|
|
|
private void RemoveAttributeListeners()
|
|
{
|
|
maturityAttribute.OnValueChanged.RemoveListener(UpdatePlayerStatisticsOnMaturityChange);
|
|
maturityAttribute.OnValueChanged.RemoveListener(OnMaturityPointsValueChanged);
|
|
brightnessAttribute.OnValueChanged.RemoveListener(UpdatePlayerStatisticsOnBrightnessChange);
|
|
}
|
|
|
|
private void RegisterLuaFunctions()
|
|
{
|
|
Lua.RegisterFunction("GetBrightness", this, SymbolExtensions.GetMethodInfo(() => GetBrightness()));
|
|
Lua.RegisterFunction("SetBrightness", this, SymbolExtensions.GetMethodInfo(() => SetBrightness((double)0)));
|
|
Lua.RegisterFunction("SetMaturity", this, SymbolExtensions.GetMethodInfo(() => SetMaturity((double)0)));
|
|
Lua.RegisterFunction("GetMaturity", this, SymbolExtensions.GetMethodInfo(() => GetMaturity()));
|
|
}
|
|
|
|
private void UnregisterLuaFunctions()
|
|
{
|
|
Lua.UnregisterFunction("GetBrightness");
|
|
Lua.UnregisterFunction("SetBrightness");
|
|
Lua.UnregisterFunction("SetMaturity");
|
|
Lua.UnregisterFunction("GetMaturity");
|
|
}
|
|
|
|
public void UodatePlayerStatistics()
|
|
{
|
|
float maturityMupltiplier = (float)(1 + (float)(0.5f * maturityAttribute.AttributeCurrentValue / maturityAttribute.AttributeMaxValue));
|
|
float maxBrightness = brightnessAttribute.AttributeMaxValue;
|
|
float halfB = maxBrightness / 2;
|
|
float brightnessMultiplier = 1 + (brightnessAttribute.AttributeCurrentValue - halfB) / halfB;
|
|
float finalMultiplier = maturityMupltiplier * brightnessMultiplier;
|
|
SetPlayerStatisticsBasedOn(finalMultiplier);
|
|
}
|
|
|
|
public void UpdatePlayerStatisticsOnBrightnessChange(float val = 0, float prevVal = 0)
|
|
{
|
|
float maturityMupltiplier = (float)(1 + (float)(0.5f * maturityAttribute.AttributeCurrentValue / maturityAttribute.AttributeMaxValue));
|
|
float maxBrightness = brightnessAttribute.AttributeMaxValue;
|
|
float halfB = maxBrightness / 2;
|
|
float brightnessMultiplier = 1 + (val - halfB) / halfB;
|
|
float finalMultiplier = maturityMupltiplier * brightnessMultiplier;
|
|
SetPlayerStatisticsBasedOn(finalMultiplier);
|
|
}
|
|
|
|
private void SetPlayerStatisticsBasedOn(float finalMultiplier)
|
|
{
|
|
// --- TRINKET INTEGRATION IN STATS CALCULATION ---
|
|
|
|
// Faith Regen
|
|
faithRegenMultiplier = sceneDependantFaithRegenMultiplier * finalMultiplier * m_trinketStats.faithRegenMult;
|
|
|
|
// Max Faith
|
|
float totalFaithMult = finalMultiplier * m_trinketStats.faithMult;
|
|
faithAttribute.AttributeMaxValue = Mathf.RoundToInt(faithBaseMaxValue * totalFaithMult);
|
|
|
|
// Max Health
|
|
float totalHealthMult = finalMultiplier * m_trinketStats.healthMult;
|
|
m_vController.maxHealth = Mathf.RoundToInt(totalHealthMult * healthBaseMaxValue);
|
|
|
|
// Reset health if caps changed downwards
|
|
if (m_vController.maxHealth < m_vController.currentHealth)
|
|
{
|
|
m_vController.ResetHealth();
|
|
}
|
|
|
|
// Health Recovery
|
|
m_vController.SetHealthRecovery(finalMultiplier * healthBaseRegenValue);
|
|
|
|
// Stamina (assuming no trinket mult for stamina yet, if needed add m_trinketStats.staminaMult)
|
|
m_vController.maxStamina = Mathf.Round(finalMultiplier * staminaBaseMaxValue);
|
|
m_vController.staminaRecovery = (finalMultiplier * staminaBaseRegenValue);
|
|
|
|
// ------------------------------------------------
|
|
|
|
onStatsUpdated?.Invoke(finalMultiplier);
|
|
}
|
|
|
|
public void UpdatePlayerStatisticsOnMaturityChange(float val = 0, float prevVal = 0)
|
|
{
|
|
float maturityMupltiplier = (float)(1 + ((float)val * 0.5f / maturityAttribute.AttributeMaxValue));
|
|
float maxBrightness = brightnessAttribute.AttributeMaxValue;
|
|
float halfB = maxBrightness / 2f;
|
|
float brightnessMultiplier = 1 + (brightnessAttribute.AttributeCurrentValue - halfB) / halfB;
|
|
float finalMultiplier = maturityMupltiplier * brightnessMultiplier;
|
|
SetPlayerStatisticsBasedOn(finalMultiplier);
|
|
}
|
|
|
|
[Button]
|
|
public void UpdateMaturityCurrentValue(int valueChange, int prevVal)
|
|
{
|
|
float newVal = maturityAttribute.AttributeCurrentValue + valueChange;
|
|
if (newVal > maturityAttribute.AttributeMaxValue) newVal = maturityAttribute.AttributeMaxValue;
|
|
else if (newVal < maturityAttribute.AttributeMinValue) newVal = maturityAttribute.AttributeMinValue;
|
|
maturityAttribute.SetValue(newVal);
|
|
}
|
|
|
|
public float GetCurrentMaturityValue() { return maturityAttribute.AttributeCurrentValue; }
|
|
public double GetBrightness() { var attr = GetAttribute("BrightnessPoints"); return (double)attr.AttributeCurrentValue; }
|
|
public void SetBrightness(double value) { brightnessAttribute.SetValue((int)value); }
|
|
public double GetMaturity() { var attr = GetAttribute("Maturity"); return (double)attr.AttributeCurrentValue; }
|
|
public void SetMaturity(double value) { maturityAttribute.SetValue((int)value); }
|
|
public void UpdateBrightnessCurrentValue(int points) { UpdateBrightnessCurrentValue((float)points); }
|
|
|
|
[Button]
|
|
public void UpdateBrightnessCurrentValue(float points)
|
|
{
|
|
if (points < 0)
|
|
{
|
|
float multiplier = 1f;
|
|
for (int i = 0; i < BrightnessPoints_Th.Length; i++)
|
|
{
|
|
if (brightnessAttribute.AttributeCurrentValue < BrightnessPoints_Th[i]) multiplier *= 0.5f;
|
|
else break;
|
|
}
|
|
brightnessAttribute.SetValue(brightnessAttribute.AttributeCurrentValue + (int)(points * multiplier));
|
|
}
|
|
else
|
|
{
|
|
if (brightnessAttribute.AttributeCurrentValue < 50) points = points / 2;
|
|
brightnessAttribute.SetValue(brightnessAttribute.AttributeCurrentValue + points);
|
|
}
|
|
}
|
|
|
|
private void OnBrightnessPointsValueChanged(float value, float prevValues)
|
|
{
|
|
if (menuScroll.m_isOpen)
|
|
{
|
|
ClearOnMenuScrollClosed();
|
|
onMenuScrollClosed = () => { BarkBrightnessChange(value, prevValues); };
|
|
menuScroll.OnClosed += onMenuScrollClosed;
|
|
return;
|
|
}
|
|
else if (DialogueManager.instance.IsConversationActive)
|
|
{
|
|
onMenuScrollClosed = () => { BarkBrightnessChange(value, prevValues); };
|
|
var events = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
|
|
onDialogueEnded = (transform) => { BarkBrightnessChange(value, prevValues); };
|
|
events.conversationEvents.onConversationEnd.AddListener(onDialogueEnded);
|
|
return;
|
|
}
|
|
BarkBrightnessChange(value, prevValues);
|
|
}
|
|
|
|
public void OnMaturityPointsValueChanged(float value, float prevValue)
|
|
{
|
|
DialogueManager.BarkString("Maturity Gained!", Player.Instance.transform);
|
|
PlayMaturityGained();
|
|
}
|
|
|
|
public void BarkBrightnessChange(float value, float prevValues)
|
|
{
|
|
float difference = Mathf.Abs(value - prevValues);
|
|
if (difference < 1f) { }
|
|
else if (value > prevValues) DialogueManager.BarkString("Brightness Points Gained!", Player.Instance.transform);
|
|
else DialogueManager.BarkString("Brightness Points Lost!", Player.Instance.transform);
|
|
ClearOnMenuScrollClosed();
|
|
}
|
|
|
|
private void ClearOnMenuScrollClosed()
|
|
{
|
|
menuScroll.OnClosed -= onMenuScrollClosed;
|
|
onMenuScrollClosed = null;
|
|
if (onDialogueEnded != null)
|
|
{
|
|
var events = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
|
|
events.conversationEvents.onConversationEnd.RemoveListener(onDialogueEnded);
|
|
onDialogueEnded = null;
|
|
}
|
|
}
|
|
|
|
public float GetCurrentFaithValue() { return faithAttribute.AttributeCurrentValue; }
|
|
public void UpdateFaithCurrentValue(int valueChange) { UpdateFaithCurrentValue((float)valueChange); }
|
|
public void UpdateFaithCurrentValue(float valueChange)
|
|
{
|
|
float newVal = faithAttribute.AttributeCurrentValue + valueChange;
|
|
faithAttribute.SetValue(newVal);
|
|
}
|
|
|
|
public void SetInteractableButtonImage(Sprite image)
|
|
{
|
|
if (!defaultInteractionImage) defaultInteractionImage = interactionImage.sprite;
|
|
interactionImage.sprite = image;
|
|
}
|
|
|
|
public void ResetIntaractableButtonImage()
|
|
{
|
|
if (!defaultInteractionImage) defaultInteractionImage = interactionImage.sprite;
|
|
interactionImage.sprite = defaultInteractionImage;
|
|
}
|
|
|
|
public void SetDialogueIntaractableButtonImage()
|
|
{
|
|
if (!defaultInteractionImage) defaultInteractionImage = interactionImage.sprite;
|
|
interactionImage.sprite = dialogueInteractionImage;
|
|
}
|
|
|
|
public void MoveToTransform(Transform t)
|
|
{
|
|
ThirdPersonController._rigidbody.MovePosition(t.position);
|
|
ThirdPersonController._rigidbody.MoveRotation(t.rotation);
|
|
}
|
|
|
|
public void PlaySingleSound(AudioClip clipToPlay, bool destroyAfterPlaying = true)
|
|
{
|
|
if (Time.timeSinceLevelLoad < 0.5f && clipToPlay != null) { }
|
|
if (this.audioSource == null)
|
|
{
|
|
Debug.LogWarning("Player's 'audioSource' is not assigned.");
|
|
return;
|
|
}
|
|
if (clipToPlay == null) return;
|
|
|
|
GameObject audioObjectInstance = Instantiate(this.audioSource, transform.position, transform.rotation);
|
|
AudioSource sourceComponent = audioObjectInstance.GetComponent<AudioSource>();
|
|
|
|
if (sourceComponent != null)
|
|
{
|
|
sourceComponent.PlayOneShot(clipToPlay);
|
|
if (destroyAfterPlaying) Destroy(audioObjectInstance, clipToPlay.length + 0.1f);
|
|
}
|
|
else Destroy(audioObjectInstance);
|
|
}
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class PlayerAttribute
|
|
{
|
|
public string AttributeName;
|
|
public float AttributeCurrentValue;
|
|
public float AttributeMaxValue;
|
|
public float AttributeMinValue = 0;
|
|
public UnityEvent<float, float> OnValueChanged;
|
|
|
|
public void SetValue(PlayerAttribute attribute)
|
|
{
|
|
if (attribute.AttributeName != AttributeName) return;
|
|
AttributeMaxValue = attribute.AttributeMaxValue;
|
|
AttributeMinValue = attribute.AttributeMinValue;
|
|
SetValue(attribute.AttributeCurrentValue);
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
DialogueLua.SetVariable(AttributeName, AttributeCurrentValue);
|
|
}
|
|
|
|
public void SetValue(float value)
|
|
{
|
|
if (value != AttributeCurrentValue)
|
|
{
|
|
value = value > AttributeMaxValue ? AttributeMaxValue : value;
|
|
value = value < AttributeMinValue ? AttributeMinValue : value;
|
|
OnValueChanged?.Invoke(value, AttributeCurrentValue);
|
|
AttributeCurrentValue = value;
|
|
DialogueLua.SetVariable(AttributeName, value);
|
|
}
|
|
}
|
|
|
|
public void ClearValue()
|
|
{
|
|
AttributeCurrentValue = AttributeMinValue;
|
|
}
|
|
}
|
|
} |