Skip to content

Commit

Permalink
Use generic code to create starting items for new characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ephphatha committed Sep 17, 2023
1 parent 68dacb6 commit 00aa5ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 88 deletions.
95 changes: 23 additions & 72 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2972,6 +2972,17 @@ void SetPlrHandGoldCurs(Item &gold)
gold._iCurs = GetGoldCursor(gold._ivalue);
}

namespace {
void CreateStartingItem(Player &player, _item_indexes itemData)
{
Item item;
InitializeItem(item, itemData);
GenerateNewSeed(item);
item.updateRequiredStatsCacheForPlayer(player);
AutoEquip(player, item) || AutoPlaceItemInBelt(player, item, true) || AutoPlaceItemInInventory(player, item, true);
}
} // namespace

void CreatePlrItems(Player &player)
{
for (auto &item : player.InvBody) {
Expand All @@ -2994,88 +3005,28 @@ void CreatePlrItems(Player &player)

switch (player._pClass) {
case HeroClass::Warrior:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], IDI_WARRIOR);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);

InitializeItem(player.InvBody[INVLOC_HAND_RIGHT], IDI_WARRSHLD);
GenerateNewSeed(player.InvBody[INVLOC_HAND_RIGHT]);
player.InvBody[INVLOC_HAND_RIGHT].updateRequiredStatsCacheForPlayer(player);

{
Item club;
InitializeItem(club, IDI_WARRCLUB);
GenerateNewSeed(club);
club.updateRequiredStatsCacheForPlayer(player);
AutoPlaceItemInInventory(player, club, true);
}

InitializeItem(player.SpdList[0], IDI_HEAL);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], IDI_HEAL);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { IDI_WARRIOR, IDI_WARRSHLD, IDI_WARRCLUB, IDI_HEAL, IDI_HEAL })
CreateStartingItem(player, itemData);
break;
case HeroClass::Rogue:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], IDI_ROGUE);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);

InitializeItem(player.SpdList[0], IDI_HEAL);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], IDI_HEAL);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { IDI_ROGUE, IDI_HEAL, IDI_HEAL })
CreateStartingItem(player, itemData);
break;
case HeroClass::Sorcerer:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], gbIsHellfire ? IDI_SORCERER : IDI_SORCERER_DIABLO);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);

InitializeItem(player.SpdList[0], gbIsHellfire ? IDI_HEAL : IDI_MANA);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], gbIsHellfire ? IDI_HEAL : IDI_MANA);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { gbIsHellfire ? IDI_SORCERER : IDI_SORCERER_DIABLO, gbIsHellfire ? IDI_HEAL : IDI_MANA, gbIsHellfire ? IDI_HEAL : IDI_MANA })
CreateStartingItem(player, itemData);
break;

case HeroClass::Monk:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], IDI_SHORTSTAFF);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);
InitializeItem(player.SpdList[0], IDI_HEAL);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], IDI_HEAL);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { IDI_SHORTSTAFF, IDI_HEAL, IDI_HEAL })
CreateStartingItem(player, itemData);
break;
case HeroClass::Bard:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], IDI_BARDSWORD);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);

InitializeItem(player.InvBody[INVLOC_HAND_RIGHT], IDI_BARDDAGGER);
GenerateNewSeed(player.InvBody[INVLOC_HAND_RIGHT]);
player.InvBody[INVLOC_HAND_RIGHT].updateRequiredStatsCacheForPlayer(player);
InitializeItem(player.SpdList[0], IDI_HEAL);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], IDI_HEAL);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { IDI_BARDSWORD, IDI_BARDDAGGER, IDI_HEAL, IDI_HEAL })
CreateStartingItem(player, itemData);
break;
case HeroClass::Barbarian:
InitializeItem(player.InvBody[INVLOC_HAND_LEFT], IDI_BARBARIAN);
GenerateNewSeed(player.InvBody[INVLOC_HAND_LEFT]);
player.InvBody[INVLOC_HAND_LEFT].updateRequiredStatsCacheForPlayer(player);

InitializeItem(player.InvBody[INVLOC_HAND_RIGHT], IDI_WARRSHLD);
GenerateNewSeed(player.InvBody[INVLOC_HAND_RIGHT]);
player.InvBody[INVLOC_HAND_RIGHT].updateRequiredStatsCacheForPlayer(player);
InitializeItem(player.SpdList[0], IDI_HEAL);
GenerateNewSeed(player.SpdList[0]);

InitializeItem(player.SpdList[1], IDI_HEAL);
GenerateNewSeed(player.SpdList[1]);
for (_item_indexes itemData : { IDI_BARBARIAN, IDI_WARRSHLD, IDI_HEAL, IDI_HEAL })
CreateStartingItem(player, itemData);
break;
}

Expand Down
18 changes: 2 additions & 16 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,22 +2336,8 @@ void CreatePlayer(Player &player, HeroClass c)
// Initializing the hotkey bindings to no selection
std::fill(player._pSplHotKey, player._pSplHotKey + NumHotkeys, SpellID::Invalid);

PlayerWeaponGraphic animWeaponId = PlayerWeaponGraphic::Unarmed;
switch (c) {
case HeroClass::Warrior:
case HeroClass::Bard:
case HeroClass::Barbarian:
animWeaponId = PlayerWeaponGraphic::SwordShield;
break;
case HeroClass::Rogue:
animWeaponId = PlayerWeaponGraphic::Bow;
break;
case HeroClass::Sorcerer:
case HeroClass::Monk:
animWeaponId = PlayerWeaponGraphic::Staff;
break;
}
player._pgfxnum = static_cast<uint8_t>(animWeaponId);
// CreatePlrItems calls AutoEquip which will overwrite the player graphic if required
player._pgfxnum = static_cast<uint8_t>(PlayerWeaponGraphic::Unarmed);

for (bool &levelVisited : player._pLvlVisited) {
levelVisited = false;
Expand Down

0 comments on commit 00aa5ee

Please sign in to comment.