@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE .
SUCH DAMAGE .
Portions of this software are copyright © 2023 The FreeType
Portions of this software are copyright <EFBFBD> 2023 The FreeType
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
All rights reserved .
All rights reserved .
*/
*/
@ -67,8 +67,9 @@ const std::vector<std::weak_ptr<Item>>&Merchant::GetShopItems(ITCategory categor
return sortedItems [ category ] ;
return sortedItems [ category ] ;
}
}
Merchant & Merchant : : AddMerchant ( Chapter chapter ) {
Merchant & Merchant : : AddMerchant ( Chapter chapter , std : : string_view keyName ) {
merchants [ chapter ] . push_back ( { } ) ;
merchants [ chapter ] . push_back ( { } ) ;
merchants [ chapter ] . back ( ) . keyName = keyName ;
return merchants [ chapter ] . back ( ) ;
return merchants [ chapter ] . back ( ) ;
}
}
@ -103,7 +104,7 @@ void Merchant::Initialize(){
utils : : datafile & chapterMerchantInfo = DATA [ " Merchant " ] [ std : : format ( " Chapter {} " , chapter ) ] ;
utils : : datafile & chapterMerchantInfo = DATA [ " Merchant " ] [ std : : format ( " Chapter {} " , chapter ) ] ;
for ( auto & [ key , size ] : chapterMerchantInfo ) {
for ( auto & [ key , size ] : chapterMerchantInfo ) {
utils : : datafile & data = chapterMerchantInfo . GetProperty ( key ) ;
utils : : datafile & data = chapterMerchantInfo . GetProperty ( key ) ;
Merchant & newMerchant = AddMerchant ( chapter ) ;
Merchant & newMerchant = AddMerchant ( chapter , key ) ;
for ( int itemNumber = 1 ; auto & [ key , size ] : data ) {
for ( int itemNumber = 1 ; auto & [ key , size ] : data ) {
if ( key = = " DisplayName " ) newMerchant . displayName = data [ key ] . GetString ( ) ;
if ( key = = " DisplayName " ) newMerchant . displayName = data [ key ] . GetString ( ) ;
else
else
@ -127,6 +128,7 @@ void Merchant::Initialize(){
}
}
merchantCount + + ;
merchantCount + + ;
}
}
if ( merchantCount = = 0 ) ERR ( std : : format ( " WARNING! No merchants available for Chapter {}! " , chapter ) ) ;
std : : cout < < std : : format ( " Added {} merchants to Chapter {} " , merchantCount , chapter ) < < std : : endl ;
std : : cout < < std : : format ( " Added {} merchants to Chapter {} " , merchantCount , chapter ) < < std : : endl ;
}
}
Merchant : : RandomizeTravelingMerchant ( ) ;
Merchant : : RandomizeTravelingMerchant ( ) ;
@ -210,12 +212,29 @@ void Merchant::SellItem(std::weak_ptr<Item>item,uint32_t amt){
} ;
} ;
void Merchant : : RandomizeTravelingMerchant ( ) {
void Merchant : : RandomizeTravelingMerchant ( ) {
travelingMerchant = GetRandomMerchant ( game - > GetCurrentChapter ( ) ) ;
SetTravelingMerchant ( const_cast < Merchant & > ( GetRandomMerchant ( game - > GetCurrentChapter ( ) ) ) . GetKeyName ( ) ) ;
for ( auto & [ key , items ] : ITEM_CATEGORIES ) {
Menu : : MerchantInventorySlotsUpdated ( key ) ;
}
UpdateSortedItemsList ( ) ;
} ;
} ;
Merchant & Merchant : : GetCurrentTravelingMerchant ( ) {
Merchant & Merchant : : GetCurrentTravelingMerchant ( ) {
return travelingMerchant ;
return travelingMerchant ;
} ;
} ;
std : : string_view Merchant : : GetKeyName ( ) const {
return keyName ;
}
void Merchant : : SetTravelingMerchant ( std : : string_view key ) {
for ( auto & [ merchantKey , merchantList ] : merchants ) {
auto it = std : : find_if ( merchantList . begin ( ) , merchantList . end ( ) , [ & ] ( const Merchant & merchant ) { return merchant . GetKeyName ( ) = = key ; } ) ;
if ( it ! = merchantList . end ( ) ) {
travelingMerchant = * it ;
for ( auto & [ key , items ] : ITEM_CATEGORIES ) {
Menu : : MerchantInventorySlotsUpdated ( key ) ;
}
UpdateSortedItemsList ( ) ;
return ;
}
}
std : : cout < < std : : format ( " WARNING! Could not set traveling merchant with key {}! " , std : : string ( key ) ) < < std : : endl ;
std : : cout < < " Falling back to a randomized merchant. " < < std : : endl ;
RandomizeTravelingMerchant ( ) ;
}