Scriptum/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs

120 lines
2.8 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public struct IndexValuePair<T>
{
[SerializeField] public int Key;
[SerializeField] public T Value;
public IndexValuePair(int key, T value)
{
Key = key;
Value = value;
}
}
2022-11-24 03:03:30 +01:00
[System.Serializable]
public struct IndexValuePair<V, T>
{
[SerializeField] public V Key;
[SerializeField] public T Value;
public IndexValuePair(V key, T value)
{
Key = key;
Value = value;
}
}
[System.Serializable]
[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")]
public class Chest
{
public int id;
public int Id
{
get { return id; }
set { id = value; }
}
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string description;
public string Description
{
get { return description; }
set { description = value; }
}
public GameObject chestModel;
public GameObject ChestModel
{
get { return chestModel; }
set { chestModel = value; }
}
public ChestTypeEnum ChestType;
2022-11-24 03:03:30 +01:00
public List<IndexValuePair<EquippableItem>> Content = new List<IndexValuePair<EquippableItem>>();
public Chest() { }
public Chest(Chest _chest)
{
this.Name = _chest.Name;
this.Description = _chest.Description;
this.ChestModel = _chest.ChestModel;
this.ChestType = _chest.ChestType;
this.Content = _chest.Content;
}
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type)
{
this.Name = _name;
this.Description = _description;
this.ChestModel = _chestModel;
this.ChestType = _type;
}
2022-11-24 03:03:30 +01:00
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type, List<IndexValuePair<int, EquippableItem>> _content)
{
this.Name = _name;
this.Description = _description;
this.ChestModel = _chestModel;
this.ChestType = _type;
SetContent(_content);
}
2022-11-24 03:03:30 +01:00
public void SetContent(List<IndexValuePair<int, EquippableItem>> _content)
{
Content.Clear();
2022-11-24 03:03:30 +01:00
foreach (IndexValuePair<int, EquippableItem> element in _content)
{
2022-11-24 03:03:30 +01:00
Content.Add(new IndexValuePair<EquippableItem>(element.Key, element.Value));
}
}
2022-11-24 03:03:30 +01:00
public List<IndexValuePair<int, EquippableItem>> GetContent()
{
2022-11-24 03:03:30 +01:00
List<IndexValuePair<int, EquippableItem>> castedContent = new List<IndexValuePair<int, EquippableItem>>();
2022-11-24 03:03:30 +01:00
foreach (IndexValuePair<EquippableItem> element in Content)
{
2022-11-24 03:03:30 +01:00
castedContent.Add(new IndexValuePair<int, EquippableItem>(element.Key, element.Value));
}
return castedContent;
}
}