Apply charisma bonus for buying/selling at stores.

This commit is contained in:
Martin Haye 2021-08-15 09:11:24 -07:00
parent 0baee6e4e5
commit e2bf2ccfb1

View File

@ -33,6 +33,7 @@ word pageItems[MAX_PAGE_ITEMS]
word pagePrices[MAX_PAGE_ITEMS] word pagePrices[MAX_PAGE_ITEMS]
byte playerNum, playerCount byte playerNum, playerCount
word pPlayer word pPlayer
word charmRatio
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code // Definitions used by assembly code
@ -115,7 +116,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1 def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1
byte numOnPage byte numOnPage
word pItemNum, pItem word pItemNum, pItem, price
// Clear stuff from previous page // Clear stuff from previous page
heapCollect() heapCollect()
@ -129,7 +130,9 @@ def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1
pItem=>w_count = pItem=>w_storeAmount pItem=>w_count = pItem=>w_storeAmount
fin fin
pageItems[numOnPage] = pItem pageItems[numOnPage] = pItem
pagePrices[numOnPage] = max(1, pItem=>w_price + addRatio(pItem=>w_price, markupRatio)) price = max(1, pItem=>w_price + addRatio(pItem=>w_price, markupRatio))
price = max(1, price - addRatio(price, charmRatio))
pagePrices[numOnPage] = price
displayItemLine(numOnPage) displayItemLine(numOnPage)
pItemNum = pItemNum + 2 pItemNum = pItemNum + 2
next next
@ -243,14 +246,21 @@ def browseItem(num)#0
loop loop
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
def setPlayer(num)#0
playerNum = num
pPlayer = index(global=>p_players, playerNum)
// Charisma discounts 3% per point when buying from a merchant; adds 3% when selling to merchant
charmRatio = percentToRatio(pPlayer->b_charisma * 3)
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def storeSetup()#0 def storeSetup()#0
loadExtraModules() loadExtraModules()
setBigWindow() setBigWindow()
playerCount = countList(global=>p_players) playerCount = countList(global=>p_players)
playerNum = 0 setPlayer(0)
pPlayer = index(global=>p_players, playerNum)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -278,8 +288,7 @@ def _buyFromStore(storeCode, profitPercent)#1
elsif choice == '>' and pageNum+1 < nPages elsif choice == '>' and pageNum+1 < nPages
pageNum++ pageNum++
elsif choice >= '1' and (choice-'1') < playerCount and (choice-'1') <> playerNum elsif choice >= '1' and (choice-'1') < playerCount and (choice-'1') <> playerNum
playerNum = choice - '1' setPlayer(choice - '1')
pPlayer = index(global=>p_players, playerNum)
elsif choice >= 'A' and (choice-'A' < nItemsOnPage) elsif choice >= 'A' and (choice-'A' < nItemsOnPage)
browseItem(choice-'A') browseItem(choice-'A')
elsif choice == $1B // Esc elsif choice == $1B // Esc
@ -311,6 +320,7 @@ def iterateSellables(skipItems, markdownRatio)#1
fin fin
if ok if ok
price = max(0, pItem=>w_price - addRatio(pItem=>w_price, markdownRatio)) price = max(0, pItem=>w_price - addRatio(pItem=>w_price, markdownRatio))
price = price + addRatio(price, charmRatio)
if !price; ok = FALSE; fin if !price; ok = FALSE; fin
fin fin
if ok if ok
@ -400,8 +410,7 @@ def _sellToStore(profitPercent)#1
elsif choice == '>' and pageNum+1 < nPages elsif choice == '>' and pageNum+1 < nPages
pageNum++ pageNum++
elsif choice >= '1' and (choice-'1') < playerCount and (choice-'1') <> playerNum elsif choice >= '1' and (choice-'1') < playerCount and (choice-'1') <> playerNum
playerNum = choice - '1' setPlayer(choice - '1')
pPlayer = index(global=>p_players, playerNum)
totalItems = iterateSellables(9999, 0) totalItems = iterateSellables(9999, 0)
elsif choice >= 'A' and (choice-'A' < nItemsOnPage) elsif choice >= 'A' and (choice-'A' < nItemsOnPage)
sellItem(choice-'A') sellItem(choice-'A')