Fairly extensive change to how stats work: get-stat now has a context; if using a skill, it's just that player's stat; otherwise, it's the max stat for anyone in the party.

This commit is contained in:
Martin Haye 2021-09-14 08:24:16 -07:00
parent 9e7606e669
commit 591369b7fb
6 changed files with 25 additions and 53 deletions

View File

@ -140,8 +140,6 @@
<block type="interaction_increase_stat_expr"></block> <block type="interaction_increase_stat_expr"></block>
<block type="interaction_decrease_stat"></block> <block type="interaction_decrease_stat"></block>
<block type="interaction_decrease_stat_expr"></block> <block type="interaction_decrease_stat_expr"></block>
<block type="interaction_set_stat"></block>
<block type="interaction_set_stat_expr"></block>
<block type="interaction_get_flag"></block> <block type="interaction_get_flag"></block>
<block type="interaction_set_flag"></block> <block type="interaction_set_flag"></block>
<block type="interaction_clr_flag"></block> <block type="interaction_clr_flag"></block>

View File

@ -814,36 +814,7 @@ if (typeof Mythos === "undefined") {
.appendField(new Blockly.FieldTextInput(""), "NAME") .appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("stat"); .appendField("stat");
this.setOutput(true, "Number"); this.setOutput(true, "Number");
this.setTooltip('Get player stat'); this.setTooltip('Get best player stat in context');
}
};
Blockly.Blocks['interaction_set_stat'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Set player's")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("stat to")
.appendField(new Blockly.FieldTextInput("0"), "NUMBER");
this.setOutput(false);
this.setTooltip('Set a player stat');
}
};
Blockly.Blocks['interaction_set_stat_expr'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendValueInput("EXPR")
.appendField("Set player's")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("stat to");
this.setOutput(false);
this.setTooltip('Set a player stat by variable amount');
} }
}; };
Blockly.Blocks['interaction_increase_stat'] = { Blockly.Blocks['interaction_increase_stat'] = {

View File

@ -2937,7 +2937,7 @@ class A2PackPartitions
{ {
mapName = mapName.trim().replaceAll(/\s*-\s*[23][dD]\s*/, "") mapName = mapName.trim().replaceAll(/\s*-\s*[23][dD]\s*/, "")
script.block.'**'.each { blk -> script.block.'**'.each { blk ->
if (blk?.@type =~ /^interaction_(increase|decrease|set|get)_stat.*/) { if (blk?.@type =~ /^interaction_(increase|decrease|get)(_party)?_stat.*/) {
def statName = blk.field[0].text().trim().toLowerCase() def statName = blk.field[0].text().trim().toLowerCase()
def getOrSet = blk.@type == "interaction_get_stat" ? "Checked" : "Set" def getOrSet = blk.@type == "interaction_get_stat" ? "Checked" : "Set"
if (!statUses.containsKey(statName)) if (!statUses.containsKey(statName))
@ -5102,8 +5102,6 @@ end
case 'interaction_increase_stat_expr': case 'interaction_increase_stat_expr':
case 'interaction_decrease_stat': case 'interaction_decrease_stat':
case 'interaction_decrease_stat_expr': case 'interaction_decrease_stat_expr':
case 'interaction_set_stat':
case 'interaction_set_stat_expr':
packChangeStat(blk); break packChangeStat(blk); break
case 'interaction_increase_party_stats': case 'interaction_increase_party_stats':
case 'interaction_decrease_party_stats': case 'interaction_decrease_party_stats':
@ -5430,15 +5428,7 @@ end
def amount = blk.field[1].text().toInteger() def amount = blk.field[1].text().toInteger()
assert amount > 0 && amount < 32767 assert amount > 0 && amount < 32767
def stat = nameToStat(name) def stat = nameToStat(name)
variables << "p_player" outIndented("adjustPartyStat($stat, ${blk.@type == 'interaction_increase_party_stats' ? '+' : '-'}$amount)\n")
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) def packPause(blk)
@ -5494,7 +5484,7 @@ end
{ {
def name = getSingle(blk.field, 'NAME').text() def name = getSingle(blk.field, 'NAME').text()
def stat = nameToStat(name) def stat = nameToStat(name)
out << "getStat(global=>p_players, $stat)" out << "getStatInContext($stat)"
} }
def packGetFlag(blk) def packGetFlag(blk)

View File

@ -65,6 +65,7 @@ import gamelib
predef getPos(px, py)#0 predef getPos(px, py)#0
predef getScreenLine(n)#1 predef getScreenLine(n)#1
predef getStat(player, statName)#1 predef getStat(player, statName)#1
predef getStatInContext(statName)#1
predef getStringResponse()#1 predef getStringResponse()#1
predef getUpperKey()#1 predef getUpperKey()#1
predef getYN()#1 predef getYN()#1
@ -182,6 +183,8 @@ import gamelib
byte needRender byte needRender
byte diskLimit byte diskLimit
byte curHeapPct byte curHeapPct
word playerUsing
/////////// Shared string constants ////////////// /////////// Shared string constants //////////////

View File

@ -206,6 +206,8 @@ word recordSeed
export byte diskLimit = 0 export byte diskLimit = 0
export word playerUsing = NULL
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code // Definitions used by assembly code
asm _defs asm _defs
@ -2864,6 +2866,7 @@ def showPlayerSheet(num)#1
setTextCountdown setTextCountdown
fin fin
fin fin
playerUsing = NULL
return 0 return 0
end end
@ -3585,14 +3588,16 @@ export def adjustPartyStat(statName, val)#0
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Get the max value of the stat for any (living) character in the party // Get the max value of the stat for any (living) character in the party.
export def getPartyStat(statName)#1 // Except if a particular player is using a skill or item in which case it's their stat only.
export def getStatInContext(statName)#1
word p_player, val word p_player, val
val = 0 val = 0
when 1 when 1
is streqi(statName, @S_GOLD); return global=>w_gold is streqi(statName, @S_GOLD); return global=>w_gold
is streqi(statName, @S_TIME); return global->b_hour is streqi(statName, @S_TIME); return global->b_hour
is streqi(statName, @S_BANK_BAL); return global=>w_bankBal is streqi(statName, @S_BANK_BAL); return global=>w_bankBal
is playerUsing <> NULL; return getStat(playerUsing, statName)
otherwise otherwise
p_player = global=>p_players p_player = global=>p_players
while p_player while p_player

View File

@ -344,6 +344,7 @@ def doUseSkill(player)#1
rawDisplayf1("\nUse which skill/attr? [A-%c] or [Esc]", nSkills-1+'A') rawDisplayf1("\nUse which skill/attr? [A-%c] or [Esc]", nSkills-1+'A')
sel = getUpperKey() sel = getUpperKey()
if sel >= 'A' and (sel-'A') < nSkills if sel >= 'A' and (sel-'A') < nSkills
playerUsing = player
return skillName[sel-'A'] return skillName[sel-'A']
elsif sel == $1B // esc elsif sel == $1B // esc
break break
@ -390,10 +391,13 @@ def showSkillsMenu(player)#0
byte playerCount byte playerCount
playerCount = countList(global=>p_players) playerCount = countList(global=>p_players)
clearMenuRect() clearMenuRect()
if player=>w_health > 0
if player->b_skillPoints > 0 if player->b_skillPoints > 0
rawDisplayf2("Assign point [A-%c], Undo pt [Ctrl-A - Ctrl-%c], ", nSkills-1+'A', nSkills-1+'A') rawDisplayf2("Assign point [A-%c], Undo pt [Ctrl-A - Ctrl-%c], ", nSkills-1+'A', nSkills-1+'A')
fin fin
rawDisplayStr("\nU)se skill/attr, X:Inventory, ") rawDisplayStr("\nU)se skill/attr, ")
fin
rawDisplayStr("X:Inventory, ")
if playerCount > 1; rawDisplayf1("Player [1-%d], ", playerCount); fin if playerCount > 1; rawDisplayf1("Player [1-%d], ", playerCount); fin
rawDisplayStr("[Esc]") rawDisplayStr("[Esc]")
end end
@ -631,6 +635,7 @@ def doUseItem(player, item)#1
// General 'use' handled by outer engine, because it might involve graphics. // General 'use' handled by outer engine, because it might involve graphics.
// Depluralize the name on the way out, because scripts will match on that. // Depluralize the name on the way out, because scripts will match on that.
isPlural = FALSE isPlural = FALSE
playerUsing = player
return mmgr(HEAP_INTERN, sprintf1("%s", item=>s_name)) return mmgr(HEAP_INTERN, sprintf1("%s", item=>s_name))
end end
@ -885,14 +890,14 @@ def doPlayerSheet(player_num)#1
beep beep
fin fin
else // mode == 'S' else // mode == 'S'
if sel == 'U' if sel == 'U' and player=>w_health > 0
item = doUseSkill(player) item = doUseSkill(player)
if item; return item; fin // Use a skill if item; return item; fin // Use a skill
else else
noRepeatMenu = TRUE noRepeatMenu = TRUE
if sel >= 'A' and (sel-'A' < nSkills) if sel >= 'A' and (sel-'A' < nSkills) and player=>w_health > 0
adjustSkill(player, sel - 'A', 1) adjustSkill(player, sel - 'A', 1)
elsif sel >= 1 and (sel-1 < nSkills) elsif sel >= 1 and (sel-1 < nSkills) and player=>w_health > 0
adjustSkill(player, sel - 1, -1) adjustSkill(player, sel - 1, -1)
else else
beep beep