61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public partial class AttributeSubmodule : SubmoduleBase<CharacterBase>
|
|
{
|
|
public AttributeGroup attributeGroup;
|
|
|
|
public bool Has(string attributeName) => attributeGroup.current.ContainsKey(attributeName);
|
|
public float Get(string attributeName, float defaultValue) => attributeGroup.current.GetValueOrDefault(attributeName, defaultValue);
|
|
|
|
public float this[string attributeName]
|
|
{
|
|
get => attributeGroup.current.GetValueOrDefault(attributeName, attributeName.Contains("Multiplier") ? 1 : 0);
|
|
set => attributeGroup.current[attributeName] = value;
|
|
}
|
|
|
|
public AttributeSubmodule(CharacterBase character) : base(character)
|
|
{
|
|
Initialize(character.attributeData);
|
|
}
|
|
|
|
public AttributeSubmodule(CharacterBase character, AttributeData attributeData) : base(character)
|
|
{
|
|
Initialize(attributeData);
|
|
}
|
|
|
|
private void Initialize(AttributeData attributeData)
|
|
{
|
|
attributeGroup = new AttributeGroup(attributeData.originalAttributes);
|
|
attributeGroup.SetUpEndowments(attributeData.runtimeAttributes);
|
|
}
|
|
|
|
public void RefreshAttribute(string attributeName)
|
|
{
|
|
attributeGroup.ResetAttribute(attributeName);
|
|
|
|
float numeric = 0;
|
|
float pAccumulation = 0;
|
|
float pMultiplication = 1;
|
|
|
|
if (owner is Player player)
|
|
{
|
|
player.inventorySc.ApplyAttributeChange(attributeName, ref numeric, ref pAccumulation, ref pMultiplication);
|
|
}
|
|
|
|
owner.buffSm.ApplyAttributeChange(attributeName, ref numeric, ref pAccumulation, ref pMultiplication);
|
|
attributeGroup.ModifyAttribute(attributeName, numeric, pAccumulation, pMultiplication);
|
|
}
|
|
|
|
public void RefreshAllAttributes()
|
|
{
|
|
foreach (var attributeName in attributeGroup.original.Keys)
|
|
{
|
|
RefreshAttribute(attributeName);
|
|
}
|
|
}
|
|
}
|
|
}
|