53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using game;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class Buffs : IPersistent
|
||
|
{
|
||
|
private List<DataBuff> _buffs;
|
||
|
|
||
|
public void Load(DataGame data)
|
||
|
{
|
||
|
_buffs = data.buffs.buffs;
|
||
|
}
|
||
|
|
||
|
public void Save(DataGame data)
|
||
|
{
|
||
|
data.buffs.buffs = _buffs;
|
||
|
}
|
||
|
|
||
|
public int GetLevel(EnumBuffType buffType)
|
||
|
{
|
||
|
foreach (DataBuff buff in _buffs)
|
||
|
{
|
||
|
if (buff.type == buffType)
|
||
|
return (int)buff.level;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
public void UpgradeLevel(EnumBuffType type)
|
||
|
{
|
||
|
bool found = false;
|
||
|
for (var i = 0; i < _buffs.Count; i++)
|
||
|
{
|
||
|
if (_buffs[i].type == type)
|
||
|
{
|
||
|
if (GameSettings.Buffs.TryGet(type, out Buff buff))
|
||
|
{
|
||
|
var nextLevel = (uint)Math.Min(_buffs[i].level + 1, buff.MaxLevel);
|
||
|
_buffs[i] = new DataBuff { type = type, level = nextLevel};
|
||
|
found = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!found)
|
||
|
{
|
||
|
_buffs.Add( new DataBuff { type = type, level = 1});
|
||
|
}
|
||
|
}
|
||
|
}
|