Refactor character attributes system; replace individual attributes with a dictionary-based approach for better scalability and maintainability
This commit is contained in:
@@ -13,12 +13,12 @@ namespace Systems
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
character.attributes.OnHealthChanged += OnHealthChanged;
|
||||
character.attributes.Subscribe(Attribute.Health, OnHealthChanged);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
character.attributes.OnHealthChanged -= OnHealthChanged;
|
||||
character.attributes.Unsubscribe(Attribute.Health, OnHealthChanged);
|
||||
}
|
||||
|
||||
private void OnHealthChanged(float newHealth)
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using Interfaces;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
using Attribute = Data.Attribute;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace Systems
|
||||
|
||||
public void Die(GameObject killer = null)
|
||||
{
|
||||
GameManager.Instance.Player.attributes.ModifyExperience(expReward);
|
||||
GameManager.Instance.Player.attributes.Modify(Attribute.Experience, expReward);
|
||||
GameManager.Instance.AddCoins(coinReward);
|
||||
|
||||
OnAnyEnemyKilled?.Invoke(killer ?? GameManager.Instance.Player.gameObject, gameObject);
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using Data;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
using Attribute = Data.Attribute;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -19,15 +20,15 @@ namespace Systems
|
||||
|
||||
private void Start()
|
||||
{
|
||||
character.attributes.SetHealth(initialHealth);
|
||||
character.attributes.Set(Attribute.Health, initialHealth);
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage, GameObject attacker = null)
|
||||
{
|
||||
lastAttacker = attacker;
|
||||
|
||||
var effectiveDamage = Math.Max(damage - character.attributes.Armor, 1);
|
||||
character.attributes.ModifyHealth(-effectiveDamage);
|
||||
var effectiveDamage = Math.Max(damage - character.attributes.Get(Attribute.Armor), 1);
|
||||
character.attributes.Modify(Attribute.Health, -effectiveDamage);
|
||||
|
||||
if (damageSound)
|
||||
{
|
||||
|
@@ -3,6 +3,7 @@ using Data;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Attribute = Data.Attribute;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -43,7 +44,7 @@ namespace Systems
|
||||
{
|
||||
if (!rb) return;
|
||||
|
||||
var velocity = new Vector2(movementInput.x, movementInput.y).normalized * character.attributes.MoveSpeed;
|
||||
var velocity = new Vector2(movementInput.x, movementInput.y).normalized * character.attributes.Get(Attribute.MoveSpeed);
|
||||
rb.linearVelocity = velocity;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user