mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-16 05:29:36 +00:00
Improved buy/sell Blockly blocks that can take parameters, to support a parameterized global Merchant script.
This commit is contained in:
parent
006b191345
commit
4c0b02931d
|
@ -673,13 +673,17 @@ if (typeof Mythos === "undefined") {
|
|||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendDummyInput()
|
||||
.appendField("Buy from store, code(s)")
|
||||
.appendField(new Blockly.FieldTextInput(""), "CODES")
|
||||
.appendField("at")
|
||||
.appendField(new Blockly.FieldTextInput(""), "MARKUP")
|
||||
.appendField("% mark up");
|
||||
.appendField("Buy items from store")
|
||||
this.appendValueInput('CODE')
|
||||
.appendField('code')
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.setCheck('String');
|
||||
this.appendValueInput('PROFIT')
|
||||
.appendField('store profit %')
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.setCheck('Number');
|
||||
this.setOutput(false);
|
||||
this.setTooltip('Buy items from a store (separate codes by commas)');
|
||||
this.setTooltip('Offer item(s) with the specified store code for sale to player');
|
||||
}
|
||||
};
|
||||
Blockly.Blocks['interaction_sell_to_store'] = {
|
||||
|
@ -689,13 +693,13 @@ if (typeof Mythos === "undefined") {
|
|||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendDummyInput()
|
||||
.appendField("Sell to store, code(s)")
|
||||
.appendField(new Blockly.FieldTextInput(""), "CODES")
|
||||
.appendField("at")
|
||||
.appendField(new Blockly.FieldTextInput(""), "MARKDOWN")
|
||||
.appendField("% mark down");
|
||||
.appendField("Sell items to store");
|
||||
this.appendValueInput('PROFIT')
|
||||
.appendField('store profit %')
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.setCheck('Number');
|
||||
this.setOutput(false);
|
||||
this.setTooltip('Sell items to a store (separate codes by commas)');
|
||||
this.setTooltip('Have player select item(s) to sell (except items that are equipped or have no store code)');
|
||||
}
|
||||
};
|
||||
Blockly.Blocks['interaction_add_player'] = {
|
||||
|
|
|
@ -3556,24 +3556,26 @@ end
|
|||
|
||||
def packBuyFromStore(blk)
|
||||
{
|
||||
assert blk.field.size() == 2
|
||||
assert blk.field[0].@name == 'CODES'
|
||||
assert blk.field[1].@name == 'MARKUP'
|
||||
def codes = blk.field[0].text()
|
||||
def markup = blk.field[1].text().toInteger()
|
||||
assert markup >= 0 && markup <= 100
|
||||
outIndented("buyFromStore(${escapeString(codes)}, ${(int)(markup * 256 / 100)})\n")
|
||||
assert blk.value.size() == 2
|
||||
assert blk.value[0].@name == 'CODE'
|
||||
assert blk.value[1].@name == 'PROFIT'
|
||||
outIndented("buyFromStore(")
|
||||
assert blk.value[0].block.size() == 1
|
||||
packExpr(blk.value[0].block[0])
|
||||
out << (", ")
|
||||
assert blk.value[1].block.size() == 1
|
||||
packExpr(blk.value[1].block[0])
|
||||
out << ")\n"
|
||||
}
|
||||
|
||||
def packSellToStore(blk)
|
||||
{
|
||||
assert blk.field.size() == 2
|
||||
assert blk.field[0].@name == 'CODES'
|
||||
assert blk.field[1].@name == 'MARKDOWN'
|
||||
def codes = blk.field[0].text()
|
||||
def markdown = blk.field[1].text().toInteger()
|
||||
assert markdown >= 0 && markdown <= 100
|
||||
outIndented("sellToStore(${escapeString(codes)}, ${(int)(markdown * 256 / 100)})\n")
|
||||
assert blk.value.size() == 1
|
||||
assert blk.value[0].@name == 'PROFIT'
|
||||
outIndented("sellToStore(")
|
||||
assert blk.value[0].block.size() == 1
|
||||
packExpr(blk.value[0].block[0])
|
||||
out << ")\n"
|
||||
}
|
||||
|
||||
def packAddPlayer(blk)
|
||||
|
|
|
@ -46,7 +46,6 @@ import gamelib
|
|||
predef finalWin
|
||||
predef finishString
|
||||
predef flipToPage1
|
||||
predef fontCmd
|
||||
predef getCharResponse
|
||||
predef getDir
|
||||
predef getGameFlag
|
||||
|
|
|
@ -99,6 +99,7 @@ word mapScripts[MAX_MAP_SCRIPTS]
|
|||
|
||||
// For decimal conversion and display tabbing
|
||||
byte decimalBuf[7]
|
||||
byte fontPosBuf[4]
|
||||
byte tabBuf[5]
|
||||
|
||||
// Animation tracking
|
||||
|
@ -1026,13 +1027,13 @@ end
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Convert byte to 3-char string in decimalBuf, suitable for font engine, e.g. ^T065
|
||||
// (@decimalBuf returned)
|
||||
// (@fontPosBuf returned so as to not disturb decimalBuf)
|
||||
def convert3Dec(n)
|
||||
decimalBuf[0] = 3
|
||||
decimalBuf[1] = '0' + (n / 100); n = n%100
|
||||
decimalBuf[2] = '0' + (n / 10); n = n%10
|
||||
decimalBuf[3] = '0' + n
|
||||
return @decimalBuf
|
||||
fontPosBuf[0] = 3
|
||||
fontPosBuf[1] = '0' + (n / 100); n = n%100
|
||||
fontPosBuf[2] = '0' + (n / 10); n = n%10
|
||||
fontPosBuf[3] = '0' + n
|
||||
return @fontPosBuf
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1345,20 +1346,9 @@ export def setOversizeWindow()
|
|||
frameLoaded = 0 // since we destroyed it
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
export def fontCmd(code, coord)
|
||||
tabBuf[0] = 4 // length
|
||||
tabBuf[1] = code
|
||||
tabBuf[2] = (coord / 100) + '0'
|
||||
tabBuf[3] = ((coord / 10) % 10) + '0'
|
||||
tabBuf[4] = (coord % 10) + '0'
|
||||
rawDisplayStr(@tabBuf)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
export def rightJustifyStr(str, rightX)
|
||||
fontCmd(20, rightX - calcWidth(str)) // 20=Ctrl-T
|
||||
rawDisplayStr(str)
|
||||
rawDisplayf2("^T%D%s", rightX - calcWidth(str), str)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2717,14 +2707,14 @@ export def unbenchPlayer()
|
|||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
export def buyFromStore(storeCode, markupRatio)
|
||||
loadEngine(MOD_STORE)=>store_buyFromStore(storeCode, markupRatio)
|
||||
export def buyFromStore(storeCode, profitRatio)
|
||||
loadEngine(MOD_STORE)=>store_buyFromStore(storeCode, profitRatio)
|
||||
returnFromEngine()
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
export def sellToStore(storeCode, markdownRatio)
|
||||
loadEngine(MOD_STORE)=>store_sellToStore(storeCode, markdownRatio)
|
||||
export def sellToStore(profitRatio)
|
||||
loadEngine(MOD_STORE)=>store_sellToStore(profitRatio)
|
||||
returnFromEngine()
|
||||
end
|
||||
|
||||
|
|
|
@ -98,14 +98,10 @@ end
|
|||
// Display string on a blank screen, with blanking follow-up
|
||||
def _intimate_displayStr(str)
|
||||
word width, i
|
||||
fontCmd(20, 0) // 20 = ctrl-T = horizontal position
|
||||
fontCmd(22, 50) // 22 = ctrl-V = vertical position
|
||||
width = calcWidth(str)
|
||||
rawDisplayStr(str)
|
||||
fontCmd(20, 0) // 20 = ctrl-T = horizontal position
|
||||
fontCmd(22, 50) // 22 = ctrl-V = vertical position
|
||||
rawDisplayStr("\$014") // ctrl-A = foreground color, 4=hi-bit-black
|
||||
for i = (width+spaceWidth-1)/spaceWidth downto 0
|
||||
rawDisplayf1("^T020^V050%s", str) // ctrl-T = horizontal position, ctrl-V = vertical position
|
||||
rawDisplayStr("^T020^V050\$014") // ctrl-A = foreground color, 4=hi-bit-black
|
||||
for i = (width/spaceWidth)+1 downto 0
|
||||
displayChar(' ')
|
||||
next
|
||||
rawDisplayStr("\$017") // ctrl-A = foreground color, 7=hi-bit-white
|
||||
|
|
|
@ -143,6 +143,8 @@ def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)
|
|||
byte itemNum
|
||||
word pFunc, pItem
|
||||
|
||||
printf1("markupRatio=%d\n", markupRatio) // FIXME FOO
|
||||
|
||||
displayBuyTitle(pageNum, nPages)
|
||||
mmgr(HEAP_COLLECT, 0)
|
||||
|
||||
|
@ -405,7 +407,12 @@ def browseItem(num)
|
|||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def _buyFromStore(storeCode, markupRatio)
|
||||
def percentToRatio(pct)
|
||||
return calcMarkup(pct, 656) // Scale 0..100 to 0..255
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def _buyFromStore(storeCode, profitPercent)
|
||||
word pItemTbl, choice
|
||||
byte nItemsOnPage, pageNum, nPages, redisplay
|
||||
|
||||
|
@ -420,7 +427,7 @@ def _buyFromStore(storeCode, markupRatio)
|
|||
redisplay = TRUE
|
||||
while TRUE
|
||||
if redisplay
|
||||
nItemsOnPage = displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)
|
||||
nItemsOnPage = displayBuyPage(pItemTbl, percentToRatio(profitPercent), pageNum, nPages)
|
||||
fin
|
||||
choice = getUpperKey()
|
||||
redisplay = TRUE
|
||||
|
@ -441,7 +448,9 @@ def _buyFromStore(storeCode, markupRatio)
|
|||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def _sellToStore(storeCode, markdownRatio)
|
||||
def _sellToStore(profitPercent)
|
||||
word markupRatio
|
||||
markupRatio = percentToRatio(profitPercent)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue
Block a user