Skip to content

Commit 702fdcb

Browse files
committed
working on items
1 parent 9a4c203 commit 702fdcb

6 files changed

Lines changed: 41 additions & 22 deletions

File tree

Plugins/InventoryFramework/Source/InventoryFramework/Private/IFInventoryComponent.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,22 @@ void UIFInventoryComponent::RemoveItem(uint8 InIndex)
346346
return;
347347
}
348348
//remove from backend
349+
OnItemRemoved(InventoryItems[InIndex].Item, InIndex);
349350
if (InventoryItems[InIndex].Item)
350351
InventoryItems[InIndex].Item->MarkPendingKill();
351352

352353
InventoryItems[InIndex].Item = nullptr;
353-
OnServerItemRemoved(InIndex);
354354
ClientRemoveItem(InIndex);
355355
}
356356
void UIFInventoryComponent::ServerRemoveItem_Implementation(uint8 InIndex)
357357
{
358+
OnServerItemRemoved(InventoryItems[InIndex].Item, InIndex);
358359
InventoryItems[InIndex].Item->OnServerItemRemoved(InIndex);
359360
if (InventoryItems[InIndex].Item)
360361
InventoryItems[InIndex].Item->MarkPendingKill();
361362

362363
InventoryItems[InIndex].Item = nullptr;
363-
OnServerItemRemoved(InIndex);
364+
364365
ClientRemoveItem(InIndex);
365366
}
366367
bool UIFInventoryComponent::ServerRemoveItem_Validate(uint8 InIndex)
@@ -370,11 +371,12 @@ bool UIFInventoryComponent::ServerRemoveItem_Validate(uint8 InIndex)
370371
void UIFInventoryComponent::ClientRemoveItem_Implementation(uint8 InIndex)
371372
{
372373
InventoryItems[InIndex].Item->OnItemRemoved(InIndex);
374+
OnItemRemoved(InventoryItems[InIndex].Item, InIndex);
373375
if (InventoryItems[InIndex].Item)
374376
InventoryItems[InIndex].Item->MarkPendingKill();
375377

376378
InventoryItems[InIndex].Item = nullptr;
377-
OnItemRemoved(InIndex);
379+
378380
}
379381
void UIFInventoryComponent::OnItemLoadedFreeSlot(TSoftClassPtr<class UIFItemBase> InItem)
380382
{
@@ -399,9 +401,9 @@ void UIFInventoryComponent::OnItemLoaded(TSoftClassPtr<class UIFItemBase> InItem
399401
void UIFInventoryComponent::ClientSendJsonData_Implementation(const FString& Data)
400402
{
401403
FIFItemData Item = JsonToItem(Data);
404+
Item.Item->ClientPostItemDeserializeFromJson();
402405
if (Item.Item)
403406
{
404-
Item.Item->PostItemLoad();
405407
Item.Item->OnItemAdded(Item.Index);
406408

407409
InventoryItems[Item.Index] = Item;
@@ -445,6 +447,7 @@ TSharedPtr<FJsonObject> UIFInventoryComponent::ItemToJson(FIFItemData* Item)
445447
TSharedPtr<FJsonObject> UObj = MakeShareable(new FJsonObject());
446448
if (Item->Item)
447449
{
450+
Item->Item->PreItemSerializeToJson();
448451
FJsonUOSerialize::UObjectToJsonObject(Item->Item->GetClass(), Item->Item, UObj.ToSharedRef());
449452
//UObj = Item->Item->SaveToJson();
450453
}
@@ -490,6 +493,6 @@ FIFItemData UIFInventoryComponent::JsonToItem(const FString& JsonString)
490493
FIFItemData Item;
491494
Item.Index = idx;
492495
Item.Item = Cast<UIFItemBase>(OutObj);
493-
496+
494497
return Item;
495498
}

Plugins/InventoryFramework/Source/InventoryFramework/Public/IFInventoryComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ class INVENTORYFRAMEWORK_API UIFInventoryComponent : public UActorComponent
202202

203203
virtual void OnItemAdded(UIFItemBase* Item, uint8 LocalIndex) {};
204204
virtual void OnItemChanged(UIFItemBase* Item, uint8 LocalIndex) {};
205-
virtual void OnItemRemoved(uint8 LocalIndex) {};
205+
virtual void OnItemRemoved(UIFItemBase* Item, uint8 LocalIndex) {};
206206

207207
//these function are called on server.
208208
virtual void OnServerItemAdded(UIFItemBase* Item, uint8 LocalIndex) {};
209209
virtual void OnServerItemChanged(UIFItemBase* Item, uint8 LocalIndex) {};
210-
virtual void OnServerItemRemoved(uint8 LocalIndex) {};
210+
virtual void OnServerItemRemoved(UIFItemBase* Item, uint8 LocalIndex) {};
211211

212212
void RemoveItem(uint8 InIndex);
213213
UFUNCTION(Server, Reliable, WithValidation)

Plugins/InventoryFramework/Source/InventoryFramework/Public/IFItemBase.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class INVENTORYFRAMEWORK_API UIFItemBase : public UObject
3636

3737
bool CallRemoteFunction(UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack) override;
3838

39+
/*
40+
Called just fater NewObject<> On server or in standalone.
41+
*/
3942
virtual void OnServerItemLoaded() {};
4043

4144
/*
@@ -98,10 +101,10 @@ class INVENTORYFRAMEWORK_API UIFItemBase : public UObject
98101
*/
99102
virtual void OnServerItemRemovedEquipment(uint8 LocalIndex) {};
100103

101-
104+
virtual void PreItemSerializeToJson() {};
102105
virtual void PreItemLoad() {};
103106

104-
virtual void PostItemLoad() {};
107+
virtual void ClientPostItemDeserializeFromJson() {};
105108
static UIFItemBase* LoadFromJSON() { return nullptr; }
106109

107110
};

Source/ActionRPGGame/Private/Weapons/ARItemWeapon.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ UARMagazineUpgradeItem* UARItemWeapon::RemoveMagazineUpgrade()
7070
bool UARItemWeapon::SpawnAbility()
7171
{
7272
bool bSpawned = false;
73-
73+
74+
if (AbilityInstance)
75+
return true;
76+
7477
AARCharacter* Character = nullptr;
7578
if (UIFInventoryComponent* InventoryComp = Cast<UIFInventoryComponent>(GetOuter()))
7679
{
@@ -93,12 +96,24 @@ bool UARItemWeapon::SpawnAbility()
9396
{
9497
AbilityInstance = NewObject<UARWeaponAbilityBase>(Character, ABClass);
9598
AbilityInstance->GetAttributes()->CopyFromStruct(FARGunAttributesItem::StaticStruct(), &GeneratedAttributes);
99+
if (MagazineModification)
100+
{
101+
AbilityInstance->AddMagazineUpgrade(MagazineModification);
102+
}
96103
bSpawned = true;
97104
}
98105

99106
return bSpawned;
100107
}
101-
108+
void UARItemWeapon::OnServerItemLoaded()
109+
{
110+
/*
111+
1. Generate Weapon Stats here.
112+
2. Add random perks (weapon)
113+
3. Add random attributes to give (Character).
114+
4. Add random effects to give (Character).
115+
*/
116+
}
102117
void UARItemWeapon::OnItemAdded(uint8 LocalIndex)
103118
{
104119
SpawnAbility();
@@ -120,7 +135,6 @@ void UARItemWeapon::OnServerItemRemoved(uint8 LocalIndex)
120135

121136
void UARItemWeapon::OnItemAddedEquipment(uint8 LocalIndex)
122137
{
123-
124138
};
125139
void UARItemWeapon::OnItemChangedEquipment(uint8 LocalIndex)
126140
{
@@ -139,16 +153,8 @@ void UARItemWeapon::OnServerItemRemovedEquipment(uint8 LocalIndex)
139153
{
140154
};
141155

142-
void UARItemWeapon::PostItemLoad()
156+
void UARItemWeapon::ClientPostItemDeserializeFromJson()
143157
{
144-
if (SpawnAbility())
145-
{
146-
AbilityInstance->GetAttributes()->CopyFromStruct(FARGunAttributesItem::StaticStruct(), &GeneratedAttributes);
147-
if (MagazineModification)
148-
{
149-
AbilityInstance->AddMagazineUpgrade(MagazineModification);
150-
}
151-
}
152158
}
153159

154160
TArray<FARItemTooltipData> UARItemWeapon::GetTooltipData()

Source/ActionRPGGame/Public/Weapons/ARItemWeapon.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ACTIONRPGGAME_API UARItemWeapon : public UARItemBase
4848
UPROPERTY(BlueprintReadOnly, Transient, Category = "Ability")
4949
UARWeaponAbilityBase* AbilityInstance;
5050

51+
//possibly replace with struct containing identical fields.
52+
//so it can be easier serialized and saved.
5153
UPROPERTY(BlueprintReadOnly, SaveGame, Category = "Ability")
5254
class UARMagazineUpgradeItem* MagazineModification;
5355

@@ -63,6 +65,8 @@ class ACTIONRPGGAME_API UARItemWeapon : public UARItemBase
6365

6466
bool SpawnAbility();
6567

68+
virtual void OnServerItemLoaded() override;
69+
6670
virtual void OnItemAdded(uint8 LocalIndex) override;
6771
virtual void OnItemRemoved(uint8 LocalIndex) override;
6872

@@ -78,7 +82,7 @@ class ACTIONRPGGAME_API UARItemWeapon : public UARItemBase
7882
virtual void OnServerItemChangedEquipment(uint8 LocalIndex) override;
7983
virtual void OnServerItemRemovedEquipment(uint8 LocalIndex) override;
8084

81-
virtual void PostItemLoad();
85+
virtual void ClientPostItemDeserializeFromJson();
8286

8387
virtual TArray<FARItemTooltipData> GetTooltipData() override;
8488

Source/ActionRPGGame/Public/Weapons/ARMagazineUpgradeItem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ACTIONRPGGAME_API UARMagazineUpgradeItem : public UARWeaponUpgradeItem
2020
*/
2121
UPROPERTY(EditAnywhere, SaveGame)
2222
float MagazineUpgradeValue;
23+
24+
UPROPERTY(EditAnywhere)
25+
EGAAttributeMod ModType;
2326
/*
2427
Effect template
2528
*/

0 commit comments

Comments
 (0)