-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInventory.h
More file actions
282 lines (257 loc) · 13.2 KB
/
Copy pathInventory.h
File metadata and controls
282 lines (257 loc) · 13.2 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#pragma once
#include "Includes.h"
static UFortResourceItemDefinition* Wood;
static UFortResourceItemDefinition* Stone;
static UFortResourceItemDefinition* Metal;
namespace Inventory {
//Crashes
int GetMaxAmmo(UFortWeaponItemDefinition* ItemDef) {
if (ItemDef) {
auto Stats = ItemDef->GetWeaponStatHandle();
auto DataTable = Stats.DataTable;
if (DataTable && Stats.RowName.ComparisonIndex != 0) {
static UDataTableFunctionLibrary* TableFuncLib = UObject::FindObjectFast<UDataTableFunctionLibrary>("Default__DataTableFunctionLibrary");
FFortBaseWeaponStats* Out = {};
TableFuncLib->GetDataTableRowFromName(DataTable, Stats.RowName, Out);
if (Out) {
return Out->ClipSize;
}
}
}
return 0;
}
void Update(AFortPlayerControllerAthena* PC) {
auto WorldInventory = PC->WorldInventory;
auto QuickBars = PC->QuickBars;
WorldInventory->HandleInventoryLocalUpdate();
PC->HandleWorldInventoryLocalUpdate();
WorldInventory->bRequiresLocalUpdate = true;
PC->OnRep_QuickBar();
QuickBars->OnRep_PrimaryQuickBar();
QuickBars->OnRep_SecondaryQuickBar();
WorldInventory->Inventory.MarkArrayDirty();
}
int GetOpenSlot(AFortPlayerControllerAthena* PC) {
auto Quickbars = PC->QuickBars;
for (int i = 0; i < Quickbars->PrimaryQuickBar.Slots.Num(); i++) {
if (Quickbars->PrimaryQuickBar.Slots[i].Items.Data == nullptr) {
return i;
}
}
return -1;
}
UFortWorldItem* GetItemInInv(AFortPlayerControllerAthena* PC, UFortItemDefinition* Def) {
for (int i = 0; i < PC->WorldInventory->Inventory.ItemInstances.Num(); i++) {
if (PC->WorldInventory->Inventory.ItemInstances[i]->ItemEntry.ItemDefinition == Def) {
return PC->WorldInventory->Inventory.ItemInstances[i];
}
}
return nullptr;
}
FFortItemEntry GetEntryInInv(AFortPlayerControllerAthena* PC, FGuid GUID) {
for (int i = 0; i < PC->WorldInventory->Inventory.ReplicatedEntries.Num(); i++) {
if (PC->WorldInventory->Inventory.ReplicatedEntries[i].ItemGuid == GUID) {
return PC->WorldInventory->Inventory.ReplicatedEntries[i];
}
}
return {};
}
std::pair<EFortQuickBars, int> GetItemSlot(AFortPlayerControllerAthena* PC, FGuid GUID) {
auto Quickbars = PC->QuickBars;
for (int i = 0; i < Quickbars->PrimaryQuickBar.Slots.Num(); i++) {
if (Quickbars->PrimaryQuickBar.Slots[i].Items.Data && Quickbars->PrimaryQuickBar.Slots[i].Items[0] == GUID) {
return std::make_pair(EFortQuickBars::Primary, i);
}
}
for (int i = 0; i < Quickbars->SecondaryQuickBar.Slots.Num(); i++) {
if (Quickbars->SecondaryQuickBar.Slots[i].Items.Data && Quickbars->SecondaryQuickBar.Slots[i].Items[0] == GUID) {
return std::make_pair(EFortQuickBars::Secondary, i);
}
}
return std::make_pair(EFortQuickBars::Max_None, -1);
}
void SpawnPickup(UFortWorldItem* Item, FVector Loc) {
FTransform SpawnTransform = {};
SpawnTransform.Scale3D = { 1,1,1 };
SpawnTransform.Translation = Loc;
AFortPickupAthena* Pickup = SpawnActor<AFortPickupAthena>(Loc, nullptr);
Pickup->PrimaryPickupItemEntry = Item->ItemEntry;
Pickup->OnRep_PrimaryPickupItemEntry();
Pickup->TossPickup(Loc, nullptr, Pickup->PrimaryPickupItemEntry.Count, true);
}
void DropItem(AFortPlayerControllerAthena* PC, FGuid GUID) {
auto Slot = GetItemSlot(PC, GUID);
auto WorldInventory = PC->WorldInventory;
for (int i = 0; i < WorldInventory->Inventory.ItemInstances.Num(); i++) {
if (WorldInventory->Inventory.ItemInstances[i]->ItemEntry.ItemGuid == GUID) {
SpawnPickup(WorldInventory->Inventory.ItemInstances[i], PC->Pawn->K2_GetActorLocation());
WorldInventory->Inventory.ItemInstances.RemoveAt(i);
break;
}
}
for (int i = 0; i < WorldInventory->Inventory.ReplicatedEntries.Num(); i++) {
if (WorldInventory->Inventory.ReplicatedEntries[i].ItemGuid == GUID) {
WorldInventory->Inventory.ReplicatedEntries.RemoveAt(i);
break;
}
}
PC->QuickBars->ServerRemoveItemInternal(GUID, false, true);
if (Slot.first == EFortQuickBars::Primary) {
PC->QuickBars->EmptySlot(Slot.first, Slot.second);
PC->QuickBars->PrimaryQuickBar.Slots[Slot.second].Items.Data = nullptr;
PC->QuickBars->PrimaryQuickBar.Slots[Slot.second].Items.ResetNum();
}
else if (Slot.first == EFortQuickBars::Secondary) {
PC->QuickBars->SecondaryQuickBar.Slots[Slot.second].Items.Data = nullptr;
PC->QuickBars->SecondaryQuickBar.Slots[Slot.second].Items.ResetNum();
}
Update(PC);
PC->QuickBars->ServerActivateSlotInternal(EFortQuickBars::Primary, 0, 0, true);
}
UFortWorldItem* AddItem(AFortPlayerControllerAthena* PC, UFortItemDefinition* ItemDef, int Count = 1, int Slot = -1, EFortQuickBars Quickbar = EFortQuickBars::Primary) {
if (Quickbar == EFortQuickBars::Primary && Slot == -1) {
Slot = GetOpenSlot(PC);
}
auto WorldInventory = PC->WorldInventory;
auto Quickbars = PC->QuickBars;
bool Stack = false;
for (int i = 0; i < WorldInventory->Inventory.ReplicatedEntries.Num(); i++) {
auto Item = WorldInventory->Inventory.ReplicatedEntries[i];
if (Item.ItemDefinition == ItemDef && !Item.ItemDefinition->IsA(UFortWeaponItemDefinition::StaticClass())) {
Count += Item.Count;
WorldInventory->Inventory.ReplicatedEntries.RemoveAt(i);
Stack = true;
break;
}
}
if (Stack) {
for (int i = 0; i < WorldInventory->Inventory.ItemInstances.Num(); i++) {
auto Item = WorldInventory->Inventory.ItemInstances[i];
if (Item->ItemEntry.ItemDefinition == ItemDef) {
WorldInventory->Inventory.ItemInstances.RemoveAt(i);
break;
}
}
}
UFortWorldItem* Item = (UFortWorldItem*)ItemDef->CreateTemporaryItemInstanceBP(Count, 1);
Item->SetOwningControllerForTemporaryItem(PC);
Item->ItemEntry.Count = Count;
WorldInventory->Inventory.ReplicatedEntries.Add(Item->ItemEntry);
WorldInventory->Inventory.ItemInstances.Add(Item);
Quickbars->ServerAddItemInternal(Item->GetItemGuid(), Quickbar, Slot);
Update(PC);
return Item;
}
std::vector<UFortWeaponRangedItemDefinition*> LootPool;
std::vector<UFortWeaponRangedItemDefinition*> Consumables;
std::vector<UFortWeaponRangedItemDefinition*> Ammo;
void SetupLoadout() {
Wood = UObject::FindObject<UFortResourceItemDefinition>("FortResourceItemDefinition WoodItemData.WoodItemData");
Stone = UObject::FindObject<UFortResourceItemDefinition>("FortResourceItemDefinition StoneItemData.StoneItemData");
Metal = UObject::FindObject<UFortResourceItemDefinition>("FortResourceItemDefinition MetalItemData.MetalItemData");
std::vector<std::string> LootPoolStr
{
"FortWeaponRangedItemDefinition WID_Assault_Auto_Athena_C_Ore_T02.WID_Assault_Auto_Athena_C_Ore_T02",
"FortWeaponRangedItemDefinition WID_Assault_Auto_Athena_R_Ore_T03.WID_Assault_Auto_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_SemiAuto_Athena_C_Ore_T02.WID_Assault_SemiAuto_Athena_C_Ore_T02",
"FortWeaponRangedItemDefinition WID_Pistol_AutoHeavy_Athena_C_Ore_T02.WID_Pistol_AutoHeavy_Athena_C_Ore_T02",
"FortWeaponRangedItemDefinition WID_Pistol_SemiAuto_Athena_C_Ore_T02.WID_Pistol_SemiAuto_Athena_C_Ore_T02",
"FortWeaponRangedItemDefinition WID_Pistol_SixShooter_Athena_C_Ore_T02.WID_Pistol_SixShooter_Athena_C_Ore_T02",
"FortWeaponRangedItemDefinition WID_Shotgun_Standard_Athena_C_Ore_T03.WID_Shotgun_Standard_Athena_C_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_Auto_Athena_UC_Ore_T03.WID_Assault_Auto_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_SemiAuto_Athena_UC_Ore_T03.WID_Assault_SemiAuto_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_AutoHeavy_Athena_UC_Ore_T03.WID_Pistol_AutoHeavy_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_Scavenger_Athena_UC_Ore_T03.WID_Pistol_Scavenger_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_SemiAuto_Athena_UC_Ore_T03.WID_Pistol_SemiAuto_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_SixShooter_Athena_UC_Ore_T03.WID_Pistol_SixShooter_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Shotgun_Standard_Athena_UC_Ore_T03.WID_Shotgun_Standard_Athena_UC_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_SemiAuto_Athena_R_Ore_T03.WID_Assault_SemiAuto_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_Surgical_Athena_R_Ore_T03.WID_Assault_Surgical_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_AutoHeavy_Athena_R_Ore_T03.WID_Pistol_AutoHeavy_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_Scavenger_Athena_R_Ore_T03.WID_Pistol_Scavenger_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_SemiAuto_Athena_R_Ore_T03.WID_Pistol_SemiAuto_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_SixShooter_Athena_R_Ore_T03.WID_Pistol_SixShooter_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Shotgun_SemiAuto_Athena_R_Ore_T03.WID_Shotgun_SemiAuto_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Sniper_BoltAction_Scope_Athena_R_Ore_T03.WID_Sniper_BoltAction_Scope_Athena_R_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_AutoHigh_Athena_VR_Ore_T03.WID_Assault_AutoHigh_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_Surgical_Athena_VR_Ore_T03.WID_Assault_Surgical_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Pistol_Scavenger_Athena_VR_Ore_T03.WID_Pistol_Scavenger_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Shotgun_SemiAuto_Athena_VR_Ore_T03.WID_Shotgun_SemiAuto_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Sniper_BoltAction_Scope_Athena_VR_Ore_T03.WID_Sniper_BoltAction_Scope_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Sniper_Standard_Scope_Athena_VR_Ore_T03.WID_Sniper_Standard_Scope_Athena_VR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Assault_AutoHigh_Athena_SR_Ore_T03.WID_Assault_AutoHigh_Athena_SR_Ore_T03",
"FortWeaponRangedItemDefinition WID_Sniper_BoltAction_Scope_Athena_SR_Ore_T03.WID_Sniper_BoltAction_Scope_Athena_SR_Ore_T03",
};
std::vector<std::string> ConsumablesStr{
"FortWeaponRangedItemDefinition Athena_Shields.Athena_Shields",
"FortWeaponRangedItemDefinition Athena_PurpleStuff.Athena_PurpleStuff",
"FortWeaponRangedItemDefinition Athena_Medkit.Athena_Medkit",
"FortWeaponRangedItemDefinition Athena_Bandage.Athena_Bandage"
};
std::vector<std::string> AmmoStr{
"FortAmmoItemDefinition AmmoDataRockets.AmmoDataRockets",
"FortAmmoItemDefinition AthenaAmmoDataShells.AthenaAmmoDataShells",
"FortAmmoItemDefinition AthenaAmmoDataBulletsMedium.AthenaAmmoDataBulletsMedium",
"FortAmmoItemDefinition AthenaAmmoDataBulletsLight.AthenaAmmoDataBulletsLight",
"FortAmmoItemDefinition AthenaAmmoDataBulletsHeavy.AthenaAmmoDataBulletsHeavy"
};
for (std::string Item : LootPoolStr) {
auto Weapon = UObject::FindObject<UFortWeaponRangedItemDefinition>(Item);
if (Weapon) {
LootPool.push_back(Weapon);
}
}
for (std::string Item : ConsumablesStr) {
auto Weapon = UObject::FindObject<UFortWeaponRangedItemDefinition>(Item);
if (Weapon) {
Consumables.push_back(Weapon);
}
}
for (std::string Item : AmmoStr) {
auto Weapon = UObject::FindObject<UFortWeaponRangedItemDefinition>(Item);
if (Weapon) {
Ammo.push_back(Weapon);
}
}
}
void SetupInventory(AFortPlayerControllerAthena* PC) {
auto WorldInventory = PC->WorldInventory;
auto Quickbars = PC->QuickBars;
static auto EditTool = UObject::FindObject<UFortEditToolItemDefinition>("FortEditToolItemDefinition EditTool.EditTool");
static auto Wall = UObject::FindObject<UFortBuildingItemDefinition>("FortBuildingItemDefinition BuildingItemData_Wall.BuildingItemData_Wall");
static auto Floor = UObject::FindObject<UFortBuildingItemDefinition>("FortBuildingItemDefinition BuildingItemData_Floor.BuildingItemData_Floor");
static auto Stair = UObject::FindObject<UFortBuildingItemDefinition>("FortBuildingItemDefinition BuildingItemData_Stair_W.BuildingItemData_Stair_W");
static auto Roof = UObject::FindObject<UFortBuildingItemDefinition>("FortBuildingItemDefinition BuildingItemData_RoofS.BuildingItemData_RoofS");
AddItem(PC, EditTool, 1, 0, EFortQuickBars::Primary);
AddItem(PC, Wall, 1, 0, EFortQuickBars::Secondary);
AddItem(PC, Floor, 1, 1, EFortQuickBars::Secondary);
AddItem(PC, Stair, 1, 2, EFortQuickBars::Secondary);
AddItem(PC, Roof, 1, 3, EFortQuickBars::Secondary);
}
AFortWeapon* EquipItem(AFortPlayerControllerAthena* PC, UFortWorldItem* ItemDef) {
if (PC->Pawn && ItemDef && ItemDef->ItemEntry.ItemDefinition) {
AFortWeapon* Weapon = reinterpret_cast<AFortPlayerPawn*>(PC->Pawn)->EquipWeaponDefinition((UFortWeaponItemDefinition*)ItemDef->ItemEntry.ItemDefinition, ItemDef->ItemEntry.ItemGuid);
if (Weapon) {
/*Weapon->WeaponData = (UFortWeaponItemDefinition*)ItemDef->GetItemDefinitionBP();
Weapon->ItemEntryGuid = ItemDef->GetItemGuid();
Weapon->SetOwner(PC->Pawn);
Weapon->OnRep_ReplicatedWeaponData();
Weapon->OnRep_AmmoCount();
Weapon->ClientGivenTo(PC->Pawn);
reinterpret_cast<AFortPlayerPawnAthena*>(PC->Pawn)->ClientInternalEquipWeapon(Weapon);*/
return Weapon;
}
}
return nullptr;
}
AFortWeapon* EquipInventoryItem(AFortPlayerControllerAthena* PC, FGuid ItemGuid) {
auto WorldInventory = PC->WorldInventory;
for (int i = 0; i < WorldInventory->Inventory.ItemInstances.Num(); i++) {
auto Item = WorldInventory->Inventory.ItemInstances[i];
if (Item && Item->ItemEntry.ItemGuid == ItemGuid) {
return EquipItem(PC, Item);
}
}
return nullptr;
}
}