diff --git a/Source/items.cpp b/Source/items.cpp index 82ade202696..0292b0742e3 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -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) { @@ -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; } diff --git a/Source/player.cpp b/Source/player.cpp index 465a2408849..5e43fe126a9 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -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(animWeaponId); + // CreatePlrItems calls AutoEquip which will overwrite the player graphic if required + player._pgfxnum = static_cast(PlayerWeaponGraphic::Unarmed); for (bool &levelVisited : player._pLvlVisited) { levelVisited = false;