mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-02-20 21:29:13 +00:00
Adding buy/sell store logic.
This commit is contained in:
parent
47d86a3dca
commit
ff1e31cd44
@ -119,20 +119,24 @@
|
||||
<block type="interaction_give_item"></block>
|
||||
<block type="interaction_take_item"></block>
|
||||
<block type="interaction_has_item"></block>
|
||||
<block type="interaction_get_stat"></block>
|
||||
<block type="interaction_increase_stat"></block>
|
||||
<block type="interaction_decrease_stat"></block>
|
||||
<block type="interaction_get_flag"></block>
|
||||
<block type="interaction_set_flag"></block>
|
||||
<block type="interaction_clr_flag"></block>
|
||||
<block type="interaction_pause"></block>
|
||||
<block type="interaction_buy_from_store"></block>
|
||||
<block type="interaction_sell_to_store"></block>
|
||||
</category>
|
||||
<category name="Party">
|
||||
<block type="interaction_add_player"></block>
|
||||
<block type="interaction_remove_player"></block>
|
||||
<block type="interaction_has_player"></block>
|
||||
<block type="interaction_bench_player"></block>
|
||||
<block type="interaction_unbench_player"></block>
|
||||
<block type="interaction_get_stat"></block>
|
||||
<block type="interaction_increase_stat"></block>
|
||||
<block type="interaction_decrease_stat"></block>
|
||||
<block type="interaction_increase_party_stats"></block>
|
||||
<block type="interaction_decrease_party_stats"></block>
|
||||
<block type="interaction_get_flag"></block>
|
||||
<block type="interaction_set_flag"></block>
|
||||
<block type="interaction_clr_flag"></block>
|
||||
<block type="interaction_pause"></block>
|
||||
</category>
|
||||
<category id="customTypes" name="Custom Types">
|
||||
</category>
|
||||
|
@ -666,6 +666,38 @@ if (typeof Mythos === "undefined") {
|
||||
this.setTooltip('Check if player has a given item');
|
||||
}
|
||||
};
|
||||
Blockly.Blocks['interaction_buy_from_store'] = {
|
||||
init: function () {
|
||||
this.setHelpUrl(Mythos.helpUrl);
|
||||
this.setColour(54);
|
||||
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");
|
||||
this.setOutput(false);
|
||||
this.setTooltip('Buy items from a store (separate codes by commas)');
|
||||
}
|
||||
};
|
||||
Blockly.Blocks['interaction_sell_to_store'] = {
|
||||
init: function () {
|
||||
this.setHelpUrl(Mythos.helpUrl);
|
||||
this.setColour(54);
|
||||
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");
|
||||
this.setOutput(false);
|
||||
this.setTooltip('Sell items to a store (separate codes by commas)');
|
||||
}
|
||||
};
|
||||
Blockly.Blocks['interaction_add_player'] = {
|
||||
init: function () {
|
||||
this.setHelpUrl(Mythos.helpUrl);
|
||||
|
@ -3516,6 +3516,28 @@ end
|
||||
outIndented("takeItemFromPlayer(@global=>p_players, ${escapeString(name)})\n")
|
||||
}
|
||||
|
||||
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)}, $markup)\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)}, $markdown)\n")
|
||||
}
|
||||
|
||||
def packAddPlayer(blk)
|
||||
{
|
||||
def name = getSingle(blk.field, 'NAME').text().trim()
|
||||
@ -3762,6 +3784,12 @@ end
|
||||
case 'interaction_has_item':
|
||||
packHasItem(blk)
|
||||
break
|
||||
case 'interaction_buy_from_store':
|
||||
packBuyFromStore(blk)
|
||||
break
|
||||
case 'interaction_sell_to_store':
|
||||
packSellToStore(blk)
|
||||
break
|
||||
case 'interaction_has_player':
|
||||
packHasPlayer(blk)
|
||||
break
|
||||
|
@ -226,6 +226,49 @@ asm swapTile // params: fromX, fromY, toX, toY
|
||||
jmp $6024
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Multiply 16 bit number by 8-bit ratio, and drop lower 8 bits of result. In effect this scales
|
||||
// num by the approximate ratio 0=0% .. 128=50% .. 255=99%
|
||||
export asm mulRatio // params: num, ratio
|
||||
+asmPlasm 2
|
||||
.ratio = evalStkL
|
||||
.numL = evalStkL+1
|
||||
.numH = evalStkH+1
|
||||
.numHH = tmp
|
||||
.accLL = tmp+1
|
||||
.accL = pTmp
|
||||
.accH = pTmp+1
|
||||
lda .ratio,x ; save ratio
|
||||
ldy #0
|
||||
sty .numHH ; zero what will become upper 8 bits of num
|
||||
sty .accLL ; clear accumulation area
|
||||
sty .accL
|
||||
sty .accH
|
||||
ldy #8 ; loop over 8 bits of ratio
|
||||
- lsr ; get next bit
|
||||
bcc + ; skip add if clear
|
||||
pha
|
||||
clc
|
||||
lda .numL,x ; 24-bit add
|
||||
adc .accLL
|
||||
sta .accLL
|
||||
lda .numH,x
|
||||
adc .accL
|
||||
sta .accL
|
||||
lda .numHH
|
||||
adc .accH
|
||||
sta .accH
|
||||
pla
|
||||
+ asl .numL,x ; shift number up
|
||||
rol .numH,x
|
||||
rol .numHH
|
||||
dey ; and loop again
|
||||
bne -
|
||||
ldy .accH ; final result in Y/A
|
||||
lda .accL
|
||||
rts
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
export asm memcpy // params: pSrc, pDst, len. Non-overlapping only!
|
||||
+asmPlasm 3
|
||||
@ -2614,6 +2657,23 @@ export def unbenchPlayer()
|
||||
returnFromEngine()
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Calculate markup on a price, where ratio is an 8.8 fixed-point number. Some approx ratios:
|
||||
// $0000 = 0%
|
||||
// $0026 = 15%
|
||||
// $0080 = 50%
|
||||
// $0100 = 100%
|
||||
// $0180 = 150%
|
||||
def calcMarkup(price, ratio)
|
||||
word markup
|
||||
markup = 0
|
||||
while ratio > 255
|
||||
markup = markup + price
|
||||
ratio = ratio - 256
|
||||
loop
|
||||
return markup + mulRatio(price, ratio)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def startGame(ask)
|
||||
word p_module
|
||||
|
Loading…
x
Reference in New Issue
Block a user