/
CharacterPanel.cs
127 lines (114 loc) · 3.91 KB
/
CharacterPanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CharacterPanel : Inventory
{
private static CharacterPanel instance_;
public static CharacterPanel Instance
{
get
{
if (instance_ == null)
{
//Debug.Log()
instance_ = GameObject.Find("CharacterPanel").GetComponent<CharacterPanel>();
}
return instance_;
}
}
private Text propertyText;
public PlayerInfo playerInfo;
public override void Start()
{
base.Start();
propertyText = transform.Find("PropertyPanel/Text").GetComponent<Text>();
PlayerInfo.instance_.OnPlayerInfoChanged += this.OnPlayerInfoChanged;
UpdatePropertytText();
}
/// <summary>
/// Metodos para poner armaduras en la casilla del player
/// </summary>
/// <param name="item"></param>
public void PutOn(Item item)
{
Item outItem = null;
foreach(Slot slot in slotList)
{
EquipmentSlot equipmentSlot = (EquipmentSlot)slot; // transforma en qup slot
if (equipmentSlot.IsRightItem(item))
{
if(equipmentSlot.transform.childCount > 0) // ya tiene armaduras
{
ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent<ItemUI>();
outItem = currentItemUI.Item;
currentItemUI.SetItem(item, 1);
}
else
{
equipmentSlot.StoreItem(item); // asiganr el objeto a la casilla
}
break;
}
}
if(outItem !=null)
Knapsack.Instance.StoreItem(outItem);
UpdatePropertytText();
}
/// <summary>
/// Metodos para remover objeto del playerr
/// </summary>
/// <param name="item"></param>
public void PutOff(Item item)
{
Knapsack.Instance.StoreItem(item);
UpdatePropertytText();
}
void OnPlayerInfoChanged(InfoType type)
{
if (type == InfoType.All || type == InfoType.Level || type == InfoType.MP || type == InfoType.HP || type == InfoType.MP)
{
UpdatePropertytText();
//Debug.Log("update");
}
//type == InfoType.Level|| type == InfoType.MP
}
private void UpdatePropertytText()
{
int strength = 0, intellect = 0, agility = 0, stamina = 0, power = 0;
foreach (EquipmentSlot slot in slotList)
{
if(slot.transform.childCount >0) // si hay obejtos en la casilla
{
Item item = slot.transform.GetChild(0).GetComponent<ItemUI>().Item;
if(item is Equipment)
{
Equipment e = (Equipment)item;
strength += e.Strength;
intellect += e.Intellect;
agility += e.Agility;
stamina += e.Stamina;
}
else if (item is Weapon)
{
power += ((Weapon)item).Damage;
}
}
}
strength += playerInfo.BasicStrength;
intellect += playerInfo.BasicIntellect;
agility += playerInfo.BasicAgility;
stamina += playerInfo.Stamina;
power += playerInfo.Power;
playerInfo.Power = power;
playerInfo.Stamina = stamina;
playerInfo.BasicAgility = agility;
playerInfo.BasicIntellect = intellect;
playerInfo.BasicStrength = strength;
//print(playerInfo.BasicStrength);
//print(playerInfo.BasicIntellect);
//print(playerInfo.BasicAgility);
string text = string.Format("Stength:{0}\nIntellect:{1}\nAgility:{2}\nStamina:{3}\nDamage:{4} ", strength, intellect, agility, stamina, power);
propertyText.text = text;
}
}