Skip to content

Commit

Permalink
In multiplayer randomly drop unique quest reward or magic item of sam…
Browse files Browse the repository at this point in the history
…e type
  • Loading branch information
obligaron authored and AJenbo committed May 31, 2023
1 parent 4ce6413 commit 571e770
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
21 changes: 16 additions & 5 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,7 @@ void SetupItem(Item &item)
item._iIdentified = false;
}

Item *SpawnUnique(_unique_items uid, Point position, bool sendmsg /*= true*/)
Item *SpawnUnique(_unique_items uid, Point position, std::optional<int> level /*= std::nullopt*/, bool sendmsg /*= true*/)
{
if (ActiveItemCount >= MAXITEMS)
return nullptr;
Expand All @@ -3219,9 +3219,20 @@ Item *SpawnUnique(_unique_items uid, Point position, bool sendmsg /*= true*/)
while (AllItemsList[idx].iItemId != UniqueItems[uid].UIItemId)
idx++;

GetItemAttrs(item, static_cast<_item_indexes>(idx), curlv);
GetUniqueItem(*MyPlayer, item, uid);
SetupItem(item);
if (gbIsMultiplayer) {
if (level)
curlv = *level;
const ItemData &uniqueItemData = AllItemsList[idx];
_item_indexes idx = GetItemIndexForDroppableItem(false, [&uniqueItemData](const ItemData &item) {
return item.itype == uniqueItemData.itype || (uniqueItemData.itype == ItemType::Amulet && item.itype == ItemType::Ring);
});
SetupAllItems(*MyPlayer, item, idx, AdvanceRndSeed(), curlv * 2, 15, true, false, false);
}
if (!gbIsMultiplayer || item._iMagical == ITEM_QUALITY_UNIQUE) {
GetItemAttrs(item, static_cast<_item_indexes>(idx), curlv);
GetUniqueItem(*MyPlayer, item, uid);
SetupItem(item);
}

if (sendmsg)
NetSendCmdPItem(false, CMD_SPAWNITEM, item.position, item);
Expand All @@ -3238,7 +3249,7 @@ void SpawnItem(Monster &monster, Point position, bool sendmsg, bool spawn /*= fa
bool dropBrain = Quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE && Quests[Q_MUSHROOM]._qvar1 == QS_MUSHGIVEN;

if (dropsSpecialTreasure && !UseMultiplayerQuests()) {
Item *uniqueItem = SpawnUnique(static_cast<_unique_items>(monster.data().treasure & T_MASK), position, false);
Item *uniqueItem = SpawnUnique(static_cast<_unique_items>(monster.data().treasure & T_MASK), position, std::nullopt, false);
if (uniqueItem != nullptr && sendmsg)
NetSendCmdPItem(false, CMD_DROPITEM, uniqueItem->position, *uniqueItem);
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ uint8_t PlaceItemInWorld(Item &&item, WorldTilePosition position);
Point GetSuperItemLoc(Point position);
void GetItemAttrs(Item &item, _item_indexes itemData, int lvl);
void SetupItem(Item &item);
Item *SpawnUnique(_unique_items uid, Point position, bool sendmsg = true);
Item *SpawnUnique(_unique_items uid, Point position, std::optional<int> level = std::nullopt, bool sendmsg = true);
void SpawnItem(Monster &monster, Point position, bool sendmsg, bool spawn = false);
void CreateRndItem(Point position, bool onlygood, bool sendmsg, bool delta);
void CreateRndUseful(Point position, bool sendmsg);
Expand Down
10 changes: 5 additions & 5 deletions Source/towners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void TalkToBarOwner(Player &player, Towner &barOwner)
bannerQuest._qactive = QUEST_DONE;
bannerQuest._qvar1 = 3;
NetSendCmdQuest(true, bannerQuest);
SpawnUnique(UITEM_HARCREST, barOwner.position + Direction::SouthWest);
SpawnUnique(UITEM_HARCREST, barOwner.position + Direction::SouthWest, bannerQuest._qlevel);
InitQTextMsg(TEXT_BANNER3);
return;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ void TalkToBlackSmith(Player &player, Towner &blackSmith)
if (Quests[Q_ROCK]._qvar2 == 1 && RemoveInventoryItemById(player, IDI_ROCK)) {
Quests[Q_ROCK]._qactive = QUEST_DONE;
NetSendCmdQuest(true, Quests[Q_ROCK]);
SpawnUnique(UITEM_INFRARING, blackSmith.position + Direction::SouthWest);
SpawnUnique(UITEM_INFRARING, blackSmith.position + Direction::SouthWest, Quests[Q_ROCK]._qlevel);
InitQTextMsg(TEXT_INFRA7);
return;
}
Expand All @@ -413,7 +413,7 @@ void TalkToBlackSmith(Player &player, Towner &blackSmith)
if (Quests[Q_ANVIL]._qvar2 == 1 && RemoveInventoryItemById(player, IDI_ANVIL)) {
Quests[Q_ANVIL]._qactive = QUEST_DONE;
NetSendCmdQuest(true, Quests[Q_ANVIL]);
SpawnUnique(UITEM_GRISWOLD, blackSmith.position + Direction::SouthWest);
SpawnUnique(UITEM_GRISWOLD, blackSmith.position + Direction::SouthWest, Quests[Q_ANVIL]._qlevel);
InitQTextMsg(TEXT_ANVIL7);
return;
}
Expand Down Expand Up @@ -511,7 +511,7 @@ void TalkToHealer(Player &player, Towner &healer)
if (poisonWater._qactive == QUEST_DONE && poisonWater._qvar1 != 2) {
poisonWater._qvar1 = 2;
InitQTextMsg(TEXT_POISON5);
SpawnUnique(UITEM_TRING, healer.position + Direction::SouthWest);
SpawnUnique(UITEM_TRING, healer.position + Direction::SouthWest, poisonWater._qlevel);
NetSendCmdQuest(true, poisonWater);
return;
}
Expand Down Expand Up @@ -670,7 +670,7 @@ void TalkToCowFarmer(Player &player, Towner &cowFarmer)
auto &quest = Quests[Q_JERSEY];

if (RemoveInventoryItemById(player, IDI_BROWNSUIT)) {
SpawnUnique(UITEM_BOVINE, cowFarmer.position + Direction::SouthEast);
SpawnUnique(UITEM_BOVINE, cowFarmer.position + Direction::SouthEast, quest._qlevel);
InitQTextMsg(TEXT_JERSEY8);
quest._qactive = QUEST_DONE;
UpdateCowFarmerAnimAfterQuestComplete();
Expand Down

0 comments on commit 571e770

Please sign in to comment.