hellbound/Assets/Scripts/Game/Settings/BuffSettings.cs

32 lines
957 B
C#
Raw Normal View History

2021-11-26 11:16:25 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using game;
public class BuffSettings
{
private readonly List<Buff> _loadedBuffs = null;
public BuffSettings(ConfGameBuffs config)
{
_loadedBuffs = new List<Buff>(config.buffs.Count);
for (int i = 0; i < config.buffs.Count; i++)
{
var buffConfig = config.buffs[i];
if (_loadedBuffs.Contains(b => b.Type == buffConfig.buffType))
throw new InvalidOperationException($"The {nameof(config)} contains a duplicate buff.");
_loadedBuffs.Add(new Buff(buffConfig));
}
Log.Debug($"BuffSettings.Constructor: uploaded successfully {_loadedBuffs.Count}");
}
public bool TryGet(EnumBuffType type, out Buff value)
{
value = _loadedBuffs.FirstOrDefault(b => b.Type == type);
return value != null;
}
}