-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkillInventory.cpp
137 lines (106 loc) · 3.09 KB
/
SkillInventory.cpp
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
128
129
130
131
132
133
134
135
136
137
#include "SkillInventory.h"
#include "Inventory.h"
#include "Client.h"
#include "ItemLoaderXML.h"
#include "d3dUtil.h"
#include "Graphics.h"
#include "Player.h"
#include "BitStream.h"
#include "NetworkMessages.h"
#include "Skills.h"
#include "Shop.h"
#include "PlayerModule.h"
SkillInventory::SkillInventory(int x, int y, int colums, float slotSize)
: HudItemContainer(x, y, colums, slotSize)
{
SetHooverInfoPos(XMFLOAT2(-slotSize/2, -110));
SetHooverBkgd("data/textures/white_transparent.png");
mPlayer = nullptr;
mShop = nullptr;
for(int i = 0; i < 8; i++)
AddSlot();
}
SkillInventory::~SkillInventory()
{
}
void SkillInventory::Update(GLib::Input* pInput, float dt)
{
HudItemContainer::Update(pInput, dt);
}
void SkillInventory::Draw(GLib::Graphics* pGraphics)
{
HudItemContainer::Draw(pGraphics);
}
void SkillInventory::AddItem(ItemName name, int level)
{
AddItem(GetItemLoader()->GetItem(ItemKey(name, level)));
}
void SkillInventory::AddItem(HudItem* pItem)
{
// Any free slots?
if(!HasFreeSlots())
return;
Skill* skill = mPlayer->AddSkill(pItem->GetName());
// Pass on the attributes.
// [NOTE] REALLY UGLY [HACK][WARNING].
skill->SetAttributes(pItem->GetAttributes());
skill->SetDescription(pItem->GetDescription());
skill->SetCost(pItem->GetCost());
skill->SetLevel(pItem->GetLevel());
// Send message to server.
SendItemAdded(mPlayer->GetPlayer()->GetId(), pItem->GetName(), pItem->GetLevel());
UpdateItems();
}
void SkillInventory::RemoveItem(HudItem* pItem, bool updateLayout)
{
// Sell item.
mPlayer->RemoveSkill(pItem->GetName());
// Send message to server.
SendItemRemoved(mPlayer->GetPlayer()->GetId(), pItem->GetName(), pItem->GetLevel());
// Free all slots and get the current skills from the player.
if(updateLayout)
UpdateItems();
// Tell the shop that an item was sold.
mShop->InventoryItemRemoved(pItem);
}
void SkillInventory::UpdateItems()
{
// Get the players skills.
std::map<int, Skill*> skillMap = mPlayer->GetSkillMap();
FreeAllSlots();
for(auto iter = skillMap.begin(); iter != skillMap.end(); iter++)
PlaceInFreeSlot((*iter).second);
}
void SkillInventory::OnHoover(const ItemSlot& itemSlot)
{
}
void SkillInventory::OnLeftPress(const ItemSlot& itemSlot)
{
}
void SkillInventory::OnRightPress(ItemSlot& itemSlot)
{
// Don't do anything unless the local player is selected.
if(!GetClient()->IsLocalPlayerSelected() || GetClient()->GetArenaState() == PLAYING_STATE)
return;
// Sell skill.
RemoveItem(itemSlot.item);
Player* player = GetClient()->GetLocalPlayer();
player->SetGold(player->GetGold() + itemSlot.item->GetCost() - 1); // [NOTE][TODO] Hard coded!!!!
// Send message to server.
SendGoldChange(player->GetId(), player->GetGold());
}
string SkillInventory::GetHooverText(HudItem* pItem)
{
char buffer[244];
sprintf(buffer, "Sell value: %i gold\nLevel: %i\n", pItem->GetCost() - 1, pItem->GetLevel()); // [NOTE][TODO] Maybe enough?
return string(buffer + pItem->GetDescription());
}
void SkillInventory::SetPlayer(PlayerModule* pPlayer)
{
mPlayer = pPlayer;
UpdateItems();
}
void SkillInventory::SetShop(Shop* pShop)
{
mShop = pShop;
}