Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Core/Loot): Simplify GetFishLoot with for loop and merge Get… #21217

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading