|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
using SiegeSong;
|
|
|
|
|
|
|
|
|
|
namespace SiegeSong
|
|
|
|
|
{
|
|
|
|
|
public class StatisticsManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Statistics Stats;
|
|
|
|
|
|
|
|
|
|
public InventoryManager InventoryManager;
|
|
|
|
|
public WorldObject LootWorldObject;
|
|
|
|
|
public AudioSource AudioSource;
|
|
|
|
|
|
|
|
|
|
public ThreatAwareness Awareness;
|
|
|
|
|
public FactionManager FactionManager;
|
|
|
|
|
public HUDManager HUDManager;
|
|
|
|
|
|
|
|
|
|
private float criticalBlowMultiplier = 10.0f;
|
|
|
|
|
private float momentumToDamageMultiplier = 0.2f;
|
|
|
|
|
private float partialProtectionMultiplier = 0.5f;
|
|
|
|
|
private float fullProtectionMultiplier = 0.75f;
|
|
|
|
|
private int defaultSkillValue = 5;
|
|
|
|
|
private int defaultAttributeValue = 10;
|
|
|
|
|
|
|
|
|
|
public void ReceiveCriticalBlow(float damage, float momentum, AparrelSlot slot, DamageType damageType)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReceiveStagger(bool canHitUnbalance = true)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.OffBalance && canHitUnbalance)
|
|
|
|
|
Stats.Fallen = true;
|
|
|
|
|
|
|
|
|
|
if (Stats.Staggered)
|
|
|
|
|
{
|
|
|
|
|
if (canHitUnbalance)
|
|
|
|
|
Stats.OffBalance = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Stats.Staggered = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReceiveHit(int baseDamage, float momentum, int skillValue, ProtectionLevel protection, DamageType damageType, AparrelSlot slot, UnityEvent weaponHitEvent, UnityEvent gripHitEvent)
|
|
|
|
|
{
|
|
|
|
|
var damage = 0.0f;
|
|
|
|
|
switch (protection)
|
|
|
|
|
{
|
|
|
|
|
case ProtectionLevel.Unprotected:
|
|
|
|
|
damage = (int)((float)baseDamage * (momentum * momentumToDamageMultiplier) * (Stats.OffBalance ? criticalBlowMultiplier : 1));
|
|
|
|
|
if (Stats.OffBalance)
|
|
|
|
|
ReceiveCriticalBlow(damage, momentum, slot, damageType);
|
|
|
|
|
if (weaponHitEvent != null)
|
|
|
|
|
weaponHitEvent.Invoke();
|
|
|
|
|
break;
|
|
|
|
|
case ProtectionLevel.Partial:
|
|
|
|
|
damage = (int)((float)partialProtectionMultiplier * (baseDamage + momentum * momentumToDamageMultiplier));
|
|
|
|
|
break;
|
|
|
|
|
case ProtectionLevel.Full:
|
|
|
|
|
damage = (int)((float)fullProtectionMultiplier * (baseDamage + momentum * momentumToDamageMultiplier));
|
|
|
|
|
if (damage > Stats.Health)
|
|
|
|
|
damage = Stats.Health - 1.0f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Stats.Health -= damage;
|
|
|
|
|
if (Stats.Health <= 0)
|
|
|
|
|
Kill();
|
|
|
|
|
if (Stats.Stamina <= 0)
|
|
|
|
|
ReceiveStagger(false);
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatusUI()
|
|
|
|
|
{
|
|
|
|
|
if (HUDManager != null)
|
|
|
|
|
{
|
|
|
|
|
HUDManager.HealthDisplayValue = Stats.Health;
|
|
|
|
|
HUDManager.StaminaDisplayValue = Stats.Stamina;
|
|
|
|
|
HUDManager.MagicDisplayValue = Stats.Magic;
|
|
|
|
|
HUDManager.DisplayUIGroup(HUDGroup.StatBarArea);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExpendStamina(float amount, bool increment = false)
|
|
|
|
|
{
|
|
|
|
|
if (!increment)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.Stamina > amount)
|
|
|
|
|
{
|
|
|
|
|
Stats.Stamina -= amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (amount < 0)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.StaminaTemporarilyRemovedIncrements.Contains(-(int)amount))
|
|
|
|
|
Stats.StaminaTemporarilyRemovedIncrements.Remove(-(int)amount);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Stats.StaminaTemporarilyRemovedIncrements.Add((int)amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearStaminaIncrements()
|
|
|
|
|
{
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
Stats.StaminaTemporarilyRemovedIncrements.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearMagicIncrements()
|
|
|
|
|
{
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
Stats.MagicTemporarilyRemovedIncrements.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearHealthIncrements()
|
|
|
|
|
{
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
Stats.HealthTemporarilyRemovedIncrements.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExpendMagic(int amount, bool increment = false)
|
|
|
|
|
{
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
if (!increment)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.Magic > amount)
|
|
|
|
|
{
|
|
|
|
|
Stats.Magic -= amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (amount < 0)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.MagicTemporarilyRemovedIncrements.Contains(-amount))
|
|
|
|
|
Stats.MagicTemporarilyRemovedIncrements.Remove(-amount);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Stats.MagicTemporarilyRemovedIncrements.Add(amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Kill()
|
|
|
|
|
{
|
|
|
|
|
Stats.Alive = false;
|
|
|
|
|
LootWorldObject.Name = $"{Stats.FirstName} {Stats.LastName}";
|
|
|
|
|
LootWorldObject.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitializeStats()
|
|
|
|
|
{
|
|
|
|
|
if (Stats == null)
|
|
|
|
|
Stats = new Statistics();
|
|
|
|
|
if (Stats.SkillValueCategories == null)
|
|
|
|
|
Stats.SkillValueCategories = new Dictionary<int, Dictionary<int, int>>();
|
|
|
|
|
if (Stats.Attributes == null)
|
|
|
|
|
Stats.Attributes = new Dictionary<int, int>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Stats.RespectForActor == null)
|
|
|
|
|
Stats.RespectForActor = new Dictionary<int, int>();
|
|
|
|
|
if (Stats.AdmirationForActor == null)
|
|
|
|
|
Stats.AdmirationForActor = new Dictionary<int, int>();
|
|
|
|
|
if (Stats.SuspicionOfActor == null)
|
|
|
|
|
Stats.SuspicionOfActor = new Dictionary<int, int>();
|
|
|
|
|
|
|
|
|
|
if (Stats.FactionRank == null)
|
|
|
|
|
Stats.FactionRank = new Dictionary<int, int>();
|
|
|
|
|
if (Stats.RegionalBounty == null)
|
|
|
|
|
Stats.RegionalBounty = new Dictionary<int, int>();
|
|
|
|
|
if (Stats.RegionalFame == null)
|
|
|
|
|
Stats.RegionalFame = new Dictionary<int, int>();
|
|
|
|
|
|
|
|
|
|
if (Stats.QuestStates == null)
|
|
|
|
|
Stats.QuestStates = new Dictionary<int, int>();
|
|
|
|
|
|
|
|
|
|
if (Stats.Blendshapes == null)
|
|
|
|
|
Stats.Blendshapes = new Dictionary<string, float>();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i != 4)
|
|
|
|
|
{
|
|
|
|
|
var initializedSkills = new Dictionary<int, int>();
|
|
|
|
|
for (var j = 0; j < 9; j++)
|
|
|
|
|
{
|
|
|
|
|
if (!initializedSkills.ContainsKey(j))
|
|
|
|
|
initializedSkills.Add(j, defaultSkillValue);
|
|
|
|
|
else
|
|
|
|
|
initializedSkills[j] = defaultSkillValue;
|
|
|
|
|
}
|
|
|
|
|
if (!Stats.SkillValueCategories.ContainsKey(i))
|
|
|
|
|
Stats.SkillValueCategories.Add(i, initializedSkills);
|
|
|
|
|
else
|
|
|
|
|
Stats.SkillValueCategories[i] = initializedSkills;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (var j = 0; j < 9; j++)
|
|
|
|
|
{
|
|
|
|
|
if (!Stats.Attributes.ContainsKey(j))
|
|
|
|
|
Stats.Attributes.Add(j, defaultAttributeValue);
|
|
|
|
|
else
|
|
|
|
|
Stats.Attributes[j] = defaultAttributeValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
InitializeStats();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Stats.CanHealH)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.Health < Stats.MaxHealth)
|
|
|
|
|
Stats.Health += Stats.HealthRecoveryRate;
|
|
|
|
|
else
|
|
|
|
|
Stats.Health = (float)Stats.MaxHealth;
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
}
|
|
|
|
|
if (Stats.CanHealS && Stats.Stamina < Stats.MaxStamina)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.Stamina < Stats.MaxStamina)
|
|
|
|
|
Stats.Stamina += Stats.StaminaRecoveryRate;
|
|
|
|
|
else
|
|
|
|
|
Stats.Stamina = (float)Stats.MaxStamina;
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
}
|
|
|
|
|
if (Stats.CanHealM && Stats.Magic < Stats.MaxMagic)
|
|
|
|
|
{
|
|
|
|
|
if (Stats.Magic < Stats.MaxMagic)
|
|
|
|
|
Stats.Magic += Stats.MagicRecoveryRate;
|
|
|
|
|
else
|
|
|
|
|
Stats.Magic = (float)Stats.MaxMagic;
|
|
|
|
|
updateStatusUI();
|
|
|
|
|
}
|
|
|
|
|
Stats.LocationX = gameObject.transform.position.x;
|
|
|
|
|
Stats.LocationY = gameObject.transform.position.y;
|
|
|
|
|
Stats.LocationZ = gameObject.transform.position.z;
|
|
|
|
|
Stats.RotationX = gameObject.transform.eulerAngles.x;
|
|
|
|
|
Stats.RotationY = gameObject.transform.eulerAngles.y;
|
|
|
|
|
Stats.RotationZ = gameObject.transform.eulerAngles.z;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|