diff --git a/Assets/Character Stats/CharacterStat.cs b/Assets/Character Stats/CharacterStat.cs index 489eb3e8..7db75416 100644 --- a/Assets/Character Stats/CharacterStat.cs +++ b/Assets/Character Stats/CharacterStat.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using UnityEngine.Events; namespace Kryz.CharacterStats @@ -57,6 +58,11 @@ namespace Kryz.CharacterStats return false; } + public virtual bool HasModifiersFromSource(object source) + { + return StatModifiers.Any(mod => mod.Source == source); + } + public virtual bool RemoveAllModifiersFromSource(object source) { int numRemovals = statModifiers.RemoveAll(mod => mod.Source == source); diff --git a/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs b/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs index 661824b9..9ae88e9b 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs +++ b/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs @@ -51,5 +51,10 @@ namespace Kryz.CharacterStats.Examples } return false; } + + public EquipmentSlot[] GetCurrentSlots() + { + return equipmentSlots; + } } } diff --git a/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs b/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs index 60247165..b156613f 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs +++ b/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs @@ -32,6 +32,8 @@ namespace Kryz.CharacterStats.Examples CharacterData characterData = new CharacterData(); string characterDataKey; + List statsCollection = new List(); + protected override void Awake() { player = GetComponentInParent(); @@ -45,6 +47,12 @@ namespace Kryz.CharacterStats.Examples base.Awake(); + statsCollection.Add(Strength); + statsCollection.Add(Agility); + statsCollection.Add(Intelligence); + statsCollection.Add(Spirit); + statsCollection.Add(Vitality); + if (!photonView.IsMine) return; if (GameStatePersistenceManager.Instance.HasDataForKey(characterDataKey)) @@ -93,11 +101,20 @@ namespace Kryz.CharacterStats.Examples equipmentPanel.OnItemRightClickedEvent.AddListener(UnequipFromEquipPanel); + RefreshCurrentEquipmentStats(); + level.OnLevelUpEvent.AddListener(OnLevelUp); level.OnExperienceChanged.AddListener(OnExperienceChanged); experienceOnNPCDeath.Response.AddListener(level.GainExperience); UpdateLevelOnOthers(); + + statPanel.UpdateStatValues(); + } + private void Start() + { + if (photonView.IsMine) + onUpdateStatValues.Invoke(); } private void OnExperienceChanged() @@ -235,5 +252,24 @@ namespace Kryz.CharacterStats.Examples onUpdateStatValues.Invoke(); } + + EquipmentSlot[] slots; + public void RefreshCurrentEquipmentStats() + { + slots = equipmentPanel.GetCurrentSlots(); + for (int i = 0; i < slots.Length; i++) + { + if (slots[i].Item == null) continue; + + for (int j = 0; j < statsCollection.Count; j++) + { + if (statsCollection[j].HasModifiersFromSource(slots[i].Item)) + { + break; + } + } + ((EquippableItem)slots[i].Item).Equip(this); + } + } } } diff --git a/Assets/Scripts/Health.cs b/Assets/Scripts/Health.cs index 65a7f03c..c16f56e2 100644 --- a/Assets/Scripts/Health.cs +++ b/Assets/Scripts/Health.cs @@ -7,7 +7,7 @@ using UnityEngine.Events; public class Health : Resource { - CharacterStats character; + protected CharacterStats character; public UnityEvent onMaxHealthChanged = new UnityEvent(); public UnityEvent onDeath = new UnityEvent(); @@ -15,7 +15,7 @@ public class Health : Resource [HideInInspector] public PhotonView photonView; - private void Awake() + protected virtual void Awake() { character = GetComponent(); photonView = GetComponent(); @@ -62,7 +62,7 @@ public class Health : Resource return base.GetMaxValue(); } - public void CalculateMaxValueBasedOnStat() + public virtual void CalculateMaxValueBasedOnStat() { maxValue = baseMaxValue + character.Vitality.Value * 10f; diff --git a/Assets/Scripts/PlayerResources.meta b/Assets/Scripts/PlayerResources.meta new file mode 100644 index 00000000..3b6a8106 --- /dev/null +++ b/Assets/Scripts/PlayerResources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 251d95c5c649ac648841385a5648c1a8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerResources/PlayerHealth.cs b/Assets/Scripts/PlayerResources/PlayerHealth.cs new file mode 100644 index 00000000..5ddf858a --- /dev/null +++ b/Assets/Scripts/PlayerResources/PlayerHealth.cs @@ -0,0 +1,23 @@ +using Kryz.CharacterStats.Examples; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerHealth : Health +{ + protected override void Awake() + { + base.Awake(); + } + + /*public override void CalculateMaxValueBasedOnStat() + { + maxValue = baseMaxValue + character.Vitality.Value * 10f; + + maxValue *= ((((PlayerCharacterStats)character).level.currentLevel - 1) * 0.2f); + + CalculateRegenValueBasedOnStat(); + + onMaxHealthChanged.Invoke(maxValue); + }*/ +} diff --git a/Assets/Scripts/PlayerResources/PlayerHealth.cs.meta b/Assets/Scripts/PlayerResources/PlayerHealth.cs.meta new file mode 100644 index 00000000..89209244 --- /dev/null +++ b/Assets/Scripts/PlayerResources/PlayerHealth.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e27fb8d81ab0d814ca4415089c513fe3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: