Persist equipment through scenes
equipment is persistent on scene change, and stats stay updated. still missing item persistence through sessions.
This commit is contained in:
parent
d12942bff4
commit
8ce897c3aa
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
namespace Kryz.CharacterStats
|
namespace Kryz.CharacterStats
|
||||||
@ -57,6 +58,11 @@ namespace Kryz.CharacterStats
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool HasModifiersFromSource(object source)
|
||||||
|
{
|
||||||
|
return StatModifiers.Any(mod => mod.Source == source);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool RemoveAllModifiersFromSource(object source)
|
public virtual bool RemoveAllModifiersFromSource(object source)
|
||||||
{
|
{
|
||||||
int numRemovals = statModifiers.RemoveAll(mod => mod.Source == source);
|
int numRemovals = statModifiers.RemoveAll(mod => mod.Source == source);
|
||||||
|
@ -51,5 +51,10 @@ namespace Kryz.CharacterStats.Examples
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EquipmentSlot[] GetCurrentSlots()
|
||||||
|
{
|
||||||
|
return equipmentSlots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ namespace Kryz.CharacterStats.Examples
|
|||||||
CharacterData characterData = new CharacterData();
|
CharacterData characterData = new CharacterData();
|
||||||
string characterDataKey;
|
string characterDataKey;
|
||||||
|
|
||||||
|
List<CharacterStat> statsCollection = new List<CharacterStat>();
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
player = GetComponentInParent<RiftPlayer>();
|
player = GetComponentInParent<RiftPlayer>();
|
||||||
@ -45,6 +47,12 @@ namespace Kryz.CharacterStats.Examples
|
|||||||
|
|
||||||
base.Awake();
|
base.Awake();
|
||||||
|
|
||||||
|
statsCollection.Add(Strength);
|
||||||
|
statsCollection.Add(Agility);
|
||||||
|
statsCollection.Add(Intelligence);
|
||||||
|
statsCollection.Add(Spirit);
|
||||||
|
statsCollection.Add(Vitality);
|
||||||
|
|
||||||
if (!photonView.IsMine) return;
|
if (!photonView.IsMine) return;
|
||||||
|
|
||||||
if (GameStatePersistenceManager.Instance.HasDataForKey(characterDataKey))
|
if (GameStatePersistenceManager.Instance.HasDataForKey(characterDataKey))
|
||||||
@ -93,11 +101,20 @@ namespace Kryz.CharacterStats.Examples
|
|||||||
|
|
||||||
equipmentPanel.OnItemRightClickedEvent.AddListener(UnequipFromEquipPanel);
|
equipmentPanel.OnItemRightClickedEvent.AddListener(UnequipFromEquipPanel);
|
||||||
|
|
||||||
|
RefreshCurrentEquipmentStats();
|
||||||
|
|
||||||
level.OnLevelUpEvent.AddListener(OnLevelUp);
|
level.OnLevelUpEvent.AddListener(OnLevelUp);
|
||||||
level.OnExperienceChanged.AddListener(OnExperienceChanged);
|
level.OnExperienceChanged.AddListener(OnExperienceChanged);
|
||||||
experienceOnNPCDeath.Response.AddListener(level.GainExperience);
|
experienceOnNPCDeath.Response.AddListener(level.GainExperience);
|
||||||
|
|
||||||
UpdateLevelOnOthers();
|
UpdateLevelOnOthers();
|
||||||
|
|
||||||
|
statPanel.UpdateStatValues();
|
||||||
|
}
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
if (photonView.IsMine)
|
||||||
|
onUpdateStatValues.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExperienceChanged()
|
private void OnExperienceChanged()
|
||||||
@ -235,5 +252,24 @@ namespace Kryz.CharacterStats.Examples
|
|||||||
|
|
||||||
onUpdateStatValues.Invoke();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ using UnityEngine.Events;
|
|||||||
|
|
||||||
public class Health : Resource
|
public class Health : Resource
|
||||||
{
|
{
|
||||||
CharacterStats character;
|
protected CharacterStats character;
|
||||||
|
|
||||||
public UnityEvent<float> onMaxHealthChanged = new UnityEvent<float>();
|
public UnityEvent<float> onMaxHealthChanged = new UnityEvent<float>();
|
||||||
public UnityEvent onDeath = new UnityEvent();
|
public UnityEvent onDeath = new UnityEvent();
|
||||||
@ -15,7 +15,7 @@ public class Health : Resource
|
|||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public PhotonView photonView;
|
public PhotonView photonView;
|
||||||
|
|
||||||
private void Awake()
|
protected virtual void Awake()
|
||||||
{
|
{
|
||||||
character = GetComponent<CharacterStats>();
|
character = GetComponent<CharacterStats>();
|
||||||
photonView = GetComponent<PhotonView>();
|
photonView = GetComponent<PhotonView>();
|
||||||
@ -62,7 +62,7 @@ public class Health : Resource
|
|||||||
return base.GetMaxValue();
|
return base.GetMaxValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CalculateMaxValueBasedOnStat()
|
public virtual void CalculateMaxValueBasedOnStat()
|
||||||
{
|
{
|
||||||
maxValue = baseMaxValue + character.Vitality.Value * 10f;
|
maxValue = baseMaxValue + character.Vitality.Value * 10f;
|
||||||
|
|
||||||
|
8
Assets/Scripts/PlayerResources.meta
Normal file
8
Assets/Scripts/PlayerResources.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 251d95c5c649ac648841385a5648c1a8
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
23
Assets/Scripts/PlayerResources/PlayerHealth.cs
Normal file
23
Assets/Scripts/PlayerResources/PlayerHealth.cs
Normal file
@ -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);
|
||||||
|
}*/
|
||||||
|
}
|
11
Assets/Scripts/PlayerResources/PlayerHealth.cs.meta
Normal file
11
Assets/Scripts/PlayerResources/PlayerHealth.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e27fb8d81ab0d814ca4415089c513fe3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user