Skip to content

Commit

Permalink
refactor(Core/Loot): Simplify GetFishLoot with for loop and merge Get… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitzunu authored Jan 20, 2025
1 parent c72ac10 commit 847d215
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
53 changes: 14 additions & 39 deletions src/server/game/Entities/GameObject/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,50 +1001,25 @@ void GameObject::Delete()
AddObjectToRemoveList();
}

void GameObject::GetFishLoot(Loot* fishloot, Player* loot_owner)
void GameObject::GetFishLoot(Loot* fishLoot, Player* lootOwner, bool junk /*= false*/)
{
fishloot->clear();
fishLoot->clear();

uint32 zone, subzone;
uint32 defaultzone = 1;
GetZoneAndAreaId(zone, subzone);
uint32 zone, area;
uint32 defaultZone = 1;
GetZoneAndAreaId(zone, area);

// if subzone loot exist use it
fishloot->FillLoot(subzone, LootTemplates_Fishing, loot_owner, true, true);

// isLooted() returns true here if player is e.g. not eligible for any loot due to conditions
if (fishloot->empty() || fishloot->isLooted()) //use this becase if zone or subzone has set LOOT_MODE_JUNK_FISH,Even if no normal drop, fishloot->FillLoot return true. it wrong.
{
//subzone no result,use zone loot
fishloot->FillLoot(zone, LootTemplates_Fishing, loot_owner, true, true);
//use zone 1 as default, somewhere fishing got nothing,becase subzone and zone not set, like Off the coast of Storm Peaks.
// isLooted() returns true here if player is e.g. not eligible for any loot due to conditions
if (fishloot->empty() || fishloot->isLooted())
fishloot->FillLoot(defaultzone, LootTemplates_Fishing, loot_owner, true, true);
}
}

void GameObject::GetFishLootJunk(Loot* fishloot, Player* loot_owner)
{
fishloot->clear();

uint32 zone, subzone;
uint32 defaultzone = 1;
GetZoneAndAreaId(zone, subzone);

// if subzone loot exist use it
fishloot->FillLoot(subzone, LootTemplates_Fishing, loot_owner, true, true, LOOT_MODE_JUNK_FISH);

// isLooted() returns true here if player is e.g. not eligible for any loot due to conditions
if (fishloot->empty() || fishloot->isLooted()) //use this becase if zone or subzone has normal mask drop, then fishloot->FillLoot return true.
uint16 lootMode = junk ? LOOT_MODE_JUNK_FISH : LOOT_MODE_DEFAULT;
// Check to fill loot in the order area - zone - defaultZone.
// This is because area and zone is not set in some places, like Off the coast of Storm Peaks.
uint32 lootZones[] = { area, zone, defaultZone };
for (uint32 fillZone : lootZones)
{
//use zone loot
fishloot->FillLoot(zone, LootTemplates_Fishing, loot_owner, true, true, LOOT_MODE_JUNK_FISH);
fishLoot->FillLoot(fillZone, LootTemplates_Fishing, lootOwner, true, true, lootMode);

// isLooted() returns true here if player is e.g. not eligible for any loot due to conditions
if (fishloot->empty() || fishloot->isLooted())
//use zone 1 as default
fishloot->FillLoot(defaultzone, LootTemplates_Fishing, loot_owner, true, true, LOOT_MODE_JUNK_FISH);
// If the loot is filled and the loot is eligible, then we break out of the loop.
if (!fishLoot->empty() && !fishLoot->isLooted())
break;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/server/game/Entities/GameObject/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Mov
void Refresh();
void DespawnOrUnsummon(Milliseconds delay = 0ms, Seconds forcedRespawnTime = 0s);
void Delete();
void GetFishLoot(Loot* loot, Player* loot_owner);
void GetFishLootJunk(Loot* loot, Player* loot_owner);
void GetFishLoot(Loot* fishLoot, Player* lootOwner, bool junk = false);
[[nodiscard]] GameobjectTypes GetGoType() const { return GameobjectTypes(GetByteValue(GAMEOBJECT_BYTES_1, 1)); }
void SetGoType(GameobjectTypes type) { SetByteValue(GAMEOBJECT_BYTES_1, 1, type); }
[[nodiscard]] GOState GetGoState() const { return GOState(GetByteValue(GAMEOBJECT_BYTES_1, 0)); }
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7885,7 +7885,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type)
if (loot_type == LOOT_FISHING)
go->GetFishLoot(loot, this);
else if (loot_type == LOOT_FISHING_JUNK)
go->GetFishLootJunk(loot, this);
go->GetFishLoot(loot, this, true);

if (go->GetGOInfo()->type == GAMEOBJECT_TYPE_CHEST && go->GetGOInfo()->chest.groupLootRules)
{
Expand Down

0 comments on commit 847d215

Please sign in to comment.