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 committed Dec 17, 2022
1 parent 96c7b15 commit ab5d1da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
20 changes: 15 additions & 5 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,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 @@ -2974,9 +2974,19 @@ 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 || FlipCoin(4)) {
GetItemAttrs(item, static_cast<_item_indexes>(idx), curlv);
GetUniqueItem(*MyPlayer, item, uid);
SetupItem(item);
} else {
if (level)
curlv = *level;
const ItemData &uniqueItemData = AllItemsList[idx];
_item_indexes idx = GetItemIndexForDroppableItem(false, [&uniqueItemData](const ItemData &item) {
return item.itype == uniqueItemData.itype;
});
SetupAllItems(*MyPlayer, item, idx, AdvanceRndSeed(), curlv * 2, 15, true, false, false);
}

if (sendmsg)
NetSendCmdPItem(false, CMD_SPAWNITEM, item.position, item);
Expand All @@ -2992,7 +3002,7 @@ void SpawnItem(Monster &monster, Point position, bool sendmsg)
bool dropsSpecialTreasure = (monster.data().treasure & T_UNIQ) != 0;

if (dropsSpecialTreasure && !gbIsMultiplayer) {
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 @@ -496,7 +496,7 @@ int AllocateItem();
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);
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 @@ -335,7 +335,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 @@ -383,7 +383,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 @@ -404,7 +404,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 @@ -494,7 +494,7 @@ void TalkToHealer(Player &player, Towner &healer)
if (Quests[Q_PWATER]._qactive == QUEST_DONE && Quests[Q_PWATER]._qvar1 != 2) {
Quests[Q_PWATER]._qvar1 = 2;
InitQTextMsg(TEXT_POISON5);
SpawnUnique(UITEM_TRING, healer.position + Direction::SouthWest);
SpawnUnique(UITEM_TRING, healer.position + Direction::SouthWest, Quests[Q_PWATER]._qlevel);
NetSendCmdQuest(true, Quests[Q_PWATER]);
return;
}
Expand Down Expand Up @@ -652,7 +652,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;
auto curFrame = cowFarmer._tAnimFrame;
Expand Down

0 comments on commit ab5d1da

Please sign in to comment.