2022-06-05 16:51:08 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
public class EquipmentManager : BaseWarehouseController
|
|
|
|
{
|
|
|
|
public static int MAX_ITEMS = 0;
|
|
|
|
|
|
|
|
[SerializeField] public EquippableItem _helmet;
|
|
|
|
[SerializeField] public EquippableItem _chest;
|
|
|
|
[SerializeField] public EquippableItem _boots;
|
|
|
|
[SerializeField] public EquippableItem _weapon;
|
|
|
|
[SerializeField] public EquippableItem _potion_one;
|
|
|
|
[SerializeField] public EquippableItem _potion_two;
|
|
|
|
[SerializeField] public EquippableItem _potion_three;
|
|
|
|
[SerializeField] public EquippableItem _potion_four;
|
|
|
|
[SerializeField] public EquippableItem _potion_five;
|
|
|
|
|
|
|
|
public static EquipmentManager Instance;
|
|
|
|
|
|
|
|
Dictionary<int, Item> equipment;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if(Instance == null)
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
|
|
|
|
equipment = new Dictionary<int, Item>() {
|
|
|
|
{ 0, _helmet },
|
|
|
|
{ 1, _chest },
|
|
|
|
{ 2, _boots },
|
|
|
|
{ 3, _weapon },
|
|
|
|
{ 4, _potion_one },
|
|
|
|
{ 5, _potion_two },
|
|
|
|
{ 6, _potion_three },
|
|
|
|
{ 7, _potion_four },
|
|
|
|
{ 8, _potion_five }
|
|
|
|
};
|
|
|
|
}else if (Instance != this)
|
|
|
|
{
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetupPanel()
|
|
|
|
{
|
|
|
|
if(this.dynamicPanel)
|
|
|
|
{
|
|
|
|
this.dynamicPanel.GetComponent<EquipmentPanelController>().Setup(gameObject, equipment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle in Manager items local list
|
|
|
|
public override void SetItemOnPosition(int _keyPosition, Item _item)
|
|
|
|
{
|
|
|
|
// in qeuippment panel its case where we drop drop on empty slot
|
|
|
|
|
|
|
|
if(_item == null) // if we move eg. form chest to eq Drop work on Eq Panel where dropitemSlot.Item is Null
|
|
|
|
return;
|
|
|
|
|
|
|
|
_keyPosition = MapItemTypeToSlotNumber((EquippableItem)_item);
|
|
|
|
this.equipment[_keyPosition] = _item;
|
|
|
|
|
|
|
|
this.ApplyEquipmentObject(true, (EquippableItem)_item);
|
|
|
|
|
|
|
|
base.SetItemOnPosition(_keyPosition, _item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from Manager items local list
|
|
|
|
public override void RemoveItemFromPosition(int _keyPosition)
|
|
|
|
{
|
|
|
|
this.equipment.Remove(_keyPosition);
|
|
|
|
|
|
|
|
this.ApplyEquipmentObject(_keyPosition);
|
|
|
|
|
|
|
|
base.RemoveItemFromPosition(_keyPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function decide in which slot item should be handled
|
|
|
|
* Mach item to dictionary key based on items equippment type
|
|
|
|
* return: dictionary key
|
|
|
|
*/
|
|
|
|
private int MapItemTypeToSlotNumber(EquippableItem _item)
|
|
|
|
{
|
|
|
|
int key=-1;
|
|
|
|
|
|
|
|
if(_item == null)
|
|
|
|
{
|
|
|
|
Debug.LogError("Ten item w ogóle nie powinien być rozpatrywany jako dodany do ekwipunku - nigdy nie był typu EquippableItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(_item.EquipmentType)
|
|
|
|
{
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Helmet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 0;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Chest:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 1;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Boots:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 2;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Weapon:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 3;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Potion:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 4;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Bracelet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 5;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Necklet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
key = 6;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Ring:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
if(!equipment.ContainsKey(7) || equipment[7] == null)
|
|
|
|
{
|
|
|
|
key = 7;
|
|
|
|
}
|
|
|
|
if(!equipment.ContainsKey(8) || equipment[8] == null)
|
|
|
|
{
|
|
|
|
key = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Debug.Log("Can't mach number to item type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* applu EquippableItem to be able to see actual equipment status - mapped with 'qeuipment' Dictioanry which is not showed in amnager panel :/
|
|
|
|
*/
|
|
|
|
public void ApplyEquipmentObject(bool put, EquippableItem _item = null)
|
|
|
|
{
|
|
|
|
switch(_item.EquipmentType)
|
|
|
|
{
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Helmet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_helmet = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Chest:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_chest = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Boots:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_boots = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Weapon:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_weapon = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Potion:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_potion_one = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Bracelet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_potion_two = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Necklet:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
_potion_three = put ? _item : null;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-06 21:34:17 +01:00
|
|
|
case EquipmentTypeEnum.Ring:
|
2022-06-05 16:51:08 +02:00
|
|
|
{
|
|
|
|
if(!equipment.ContainsKey(7) || equipment[7] == null)
|
|
|
|
{
|
|
|
|
_potion_four = put ? _item : null;
|
|
|
|
}
|
|
|
|
if(!equipment.ContainsKey(8) || equipment[8] == null)
|
|
|
|
{
|
|
|
|
_potion_five = put ? _item : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Debug.Log("Can't mach number to item type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ApplyEquipmentObject(int _keyPosition)
|
|
|
|
{
|
|
|
|
switch(_keyPosition)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
_helmet = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
_chest = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
_boots = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
_weapon = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
_potion_one = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
_potion_two = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
_potion_three = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
_potion_four = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
_potion_five = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|