Added ability to increase or decrease a stat for all party members.

This commit is contained in:
Martin Haye 2017-02-24 08:49:12 -08:00
parent e2b5ccf375
commit 6dee0388b1
4 changed files with 61 additions and 9 deletions

View File

@ -127,6 +127,8 @@
<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>

View File

@ -771,6 +771,36 @@ if (typeof Mythos === "undefined") {
this.setTooltip('Decrease stat of player');
}
};
Blockly.Blocks['interaction_increase_party_stats'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Increase entire party's")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("stats by")
.appendField(new Blockly.FieldTextInput("0"), "AMOUNT");
this.setOutput(false);
this.setTooltip('Increase stat of every party member');
}
};
Blockly.Blocks['interaction_decrease_party_stats'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Decrease entire party's")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("stats by")
.appendField(new Blockly.FieldTextInput("0"), "AMOUNT");
this.setOutput(false);
this.setTooltip('Decrease stat of every party member');
}
};
Blockly.Blocks['interaction_get_flag'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);

View File

@ -3416,6 +3416,9 @@ end
case 'interaction_increase_stat':
case 'interaction_decrease_stat':
packChangeStat(blk); break
case 'interaction_increase_party_stats':
case 'interaction_decrease_party_stats':
packChangePartyStats(blk); break
case 'interaction_set_flag':
case 'interaction_clr_flag':
packChangeFlag(blk); break
@ -3556,7 +3559,27 @@ end
assert amount > 0 && amount < 32767
def stat = nameToStat(name)
outIndented(
"setStat($stat, getStat($stat) ${blk.@type == 'interaction_increase_stat' ? '+' : '-'} $amount)\n")
"setStat(global=>p_players, $stat, getStat(global=>p_players, $stat) ${blk.@type == 'interaction_increase_stat' ? '+' : '-'} $amount)\n")
}
def packChangePartyStats(blk)
{
assert blk.field.size() == 2
assert blk.field[0].@name == 'NAME'
assert blk.field[1].@name == 'AMOUNT'
def name = blk.field[0].text()
def amount = blk.field[1].text().toInteger()
assert amount > 0 && amount < 32767
def stat = nameToStat(name)
variables << "p_player"
outIndented("p_player = global=>p_players\n")
outIndented("while p_player\n")
++indent
outIndented(
"setStat(p_player, $stat, getStat(p_player, $stat) ${blk.@type == 'interaction_increase_party_stats' ? '+' : '-'} $amount)\n")
outIndented("p_player = p_player=>p_nextObj\n")
--indent
outIndented("loop\n")
}
def packPause(blk)
@ -3612,7 +3635,7 @@ end
{
def name = getSingle(blk.field, 'NAME').text()
def stat = nameToStat(name)
out << "getStat($stat)"
out << "getStat(global=>p_players, $stat)"
}
def packGetFlag(blk)

View File

@ -51,7 +51,7 @@ export word global // the global heap object, from which all live objects must
///////////////////////////////////////////////////////////////////////////////////////////////////
// Predefined functions, for circular calls or out-of-order calls
predef setWindow2, initCmds, nextAnimFrame, checkEncounter, doCombat, clearPortrait, showMapName
predef doRender, playerDeath, startGame, showAnimFrame, finalWin
predef doRender, playerDeath, startGame, showAnimFrame, finalWin, showParty
///////////////////////////////////////////////////////////////////////////////////////////////////
// Global variables
@ -1093,6 +1093,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Read a single char from the keyboard, and intern it (as a string) to the heap.
export def getCharResponse()
if needShowParty; showParty(); fin
^$200 = 1
^$201 = getUpperKey()
return mmgr(HEAP_INTERN, $200)
@ -2517,9 +2518,7 @@ export def partyHasPlayer(playerName)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def getStat(statName)
word player
player = global=>p_players // default to first player
export def getStat(player, statName)
when statName
is @S_INTELLIGENCE; return player->b_intelligence
is @S_STRENGTH; return player->b_strength
@ -2545,9 +2544,7 @@ def clampByte(val)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def setStat(statName, val)
word player
player = global=>p_players // default to first player
export def setStat(player, statName, val)
when statName
is @S_INTELLIGENCE; player->b_intelligence = clampByte(val); break
is @S_STRENGTH; player->b_strength = clampByte(val); break