From f52fca79e21090c2cfc91d612b33c1d10a2470e7 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sun, 28 Jun 2020 18:48:47 -0700 Subject: [PATCH] Rework SecExp battle wound system --- js/003-data/gameVariableData.js | 4 -- src/Mods/SecExp/attackHandler.tw | 34 ----------- src/Mods/SecExp/attackReport.tw | 35 ++++++----- src/Mods/SecExp/js/secExp.js | 69 +++++++++++++++++++++ src/Mods/SecExp/rebellionHandler.tw | 1 + src/Mods/SecExp/rebellionReport.tw | 94 +++++++++++------------------ 6 files changed, 125 insertions(+), 112 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 6ae89e11698..98b66a44388 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -545,10 +545,6 @@ App.Data.resetOnNGPlus = { PCvictories: 0, PClosses: 0, - /* buildings */ - woundType: 0, - /* 0:no wound, 1:mute, 2:blind, 3:amputee, 4<:health */ - reminderEntry: "", reminderWeek: "", lastWeeksCashIncome: {}, diff --git a/src/Mods/SecExp/attackHandler.tw b/src/Mods/SecExp/attackHandler.tw index 3b5a7102d83..21134caec5f 100644 --- a/src/Mods/SecExp/attackHandler.tw +++ b/src/Mods/SecExp/attackHandler.tw @@ -314,23 +314,6 @@ <<set _mercMod -= 0.2>> <<set _SFMod -= 0.2>> <<set _enemyMod += 0.2>> - <<set $woundType = random(1,10)>> - <<set _i = $slaveIndices[$Bodyguard.ID]>> - <<if $woundType == 1>> - <<set $slaves[_i].voice = 0>> - <<run healthDamage($slaves[$i], 60)>> - <<elseif $woundType == 2>> - <<run eyeSurgery($slaves[_i], "both", "blind"), healthDamage($slaves[$i], 30)>> - <<elseif $woundType == 3>> - <<run removeLimbs($slaves[_i], "all")>> - <<run healthDamage($slaves[$i], 80)>> - <<elseif $woundType >= 4>> - <<if $slaves[_i].health.health >= -60>> - <<run healthDamage($slaves[$i], 30)>> - <<else>> - <<run healthDamage($slaves[$i], -90 - $slaves[$i].health.health)>> - <</if>> - <</if>> <</if>> /* 60% chance of getting combat skill if not already have it */ <<if $Bodyguard.skill.combat == 0 && random(1,100) <= 60>> @@ -439,23 +422,6 @@ <<set _mercMod -= 0.2>> <<set _SFMod -= 0.2>> <<set _enemyMod += 0.2>> - <<set $woundType = random(1,10)>> - <<set _i = $slaveIndices[$HeadGirl.ID]>> - <<if $woundType == 1>> - <<set $slaves[_i].voice = 0>> - <<run healthDamage($slaves[$i], 60)>> - <<elseif $woundType == 2>> - <<set eyeSurgery($slaves[_i], "both", "blind"), healthDamage($slaves[$i], 30)>> - <<elseif $woundType == 3>> - <<run removeLimbs($slaves[_i], "all")>> - <<run healthDamage($slaves[$i], 80)>> - <<elseif $woundType >= 4>> - <<if $slaves[_i].health.health >= -60>> - <<run healthDamage($slaves[$i], 30)>> - <<else>> - <<run healthDamage($slaves[$i], -90 - $slaves[$i].health.health)>> - <</if>> - <</if>> <</if>> /* 60% chance of getting combat skill if not already have it */ <<if $HeadGirl.skill.combat == 0 && random(1,100) <= 60>> diff --git a/src/Mods/SecExp/attackReport.tw b/src/Mods/SecExp/attackReport.tw index 3d92154f759..65d8d802a2d 100644 --- a/src/Mods/SecExp/attackReport.tw +++ b/src/Mods/SecExp/attackReport.tw @@ -945,15 +945,18 @@ <<if $gainedCombat == 1>> During the battle, $he had to fight for $his life, giving $him experience in modern combat. $He is now proficient with modern firearms and hand to hand combat. <</if>> - <<if $woundType != 0>> + <<if $leaderWounded == 1>> Unfortunately, @@.red;$he sustained major injuries.@@ - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> A stray bullet hit $his neck. While $he fortunately avoided fatal hemorrhaging, $his vocal cords were irreparably damaged. - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> Some shrapnel found $his eyes as their final target, blinding $him permanently. - <<elseif $woundType == 3>> - A grenade landed close to $him, rendering $him a quadruple amputee. - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + A grenade landed close to $him, and $his badly mangled legs had to be amputated. + <<elseif _woundType == "arm">> + A shrapnel blast mangled one of $his arms, which had to be amputated. + <<elseif _woundType == "flesh">> While gravely wounded, it seems $he will be able to fully recover, given enough time. <</if>> Your troops were greatly affected by the loss of their leader. @@ -1079,15 +1082,18 @@ <<if $gainedCombat == 1>> During the battle, $he had to fight for $his life, giving $him experience in modern combat. $He is now proficient with modern firearms and hand to hand combat. <</if>> - <<if $woundType != 0>> - Unfortunately, @@.red;$he sustained severe injuries.@@ - <<if $woundType == 1>> + <<if $leaderWounded == 1>> + Unfortunately, @@.red;$he sustained major injuries.@@ + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> A stray bullet hit $his neck. While $he fortunately avoided fatal hemorrhaging, $his vocal cords were irreparably damaged. - <<elseif $woundType == 2>> - Some shrapnel found $his eyes as final their target, blinding $him permanently. - <<elseif $woundType == 3>> - A grenade landed close to $him, rendering $him a quadruple amputee. - <<elseif $woundType >= 4>> + <<elseif _woundType == "eyes">> + Some shrapnel found $his eyes as their final target, blinding $him permanently. + <<elseif _woundType == "legs">> + A grenade landed close to $him, and $his badly mangled legs had to be amputated. + <<elseif _woundType == "arm">> + A shrapnel blast mangled one of $his arms, which had to be amputated. + <<elseif _woundType == "flesh">> While gravely wounded, it seems $he will be able to fully recover, given enough time. <</if>> Your troops were greatly affected by the loss of their leader. @@ -1500,7 +1506,6 @@ <<run delete $bribeCost>> <<set $leaderWounded = 0>> <<set $gainedWarfare = 0>> -<<set $woundType = 0>> <<set $tacticsSuccessful = 0>> <<set $attackType = "none">> <<set $chosenTactic = "none">> diff --git a/src/Mods/SecExp/js/secExp.js b/src/Mods/SecExp/js/secExp.js index 25d6d41a695..d58a4381715 100644 --- a/src/Mods/SecExp/js/secExp.js +++ b/src/Mods/SecExp/js/secExp.js @@ -904,3 +904,72 @@ App.SecExp.Manpower = { return this.employedMerc + this.employedMilitia + this.employedSlave; } }; + +App.SecExp.inflictBattleWound = (function() { + /** @typedef {object} Wound + * @property {number} weight + * @property {function(App.Entity.SlaveState):boolean} allowed + * @property {function(App.Entity.SlaveState):void} effects + */ + /** @type { Object<string, Wound> } */ + const wounds = { + eyes: { + weight: 10, + allowed: (s) => canSee(s), + effects: (s) => { clampedDamage(s, 30); eyeSurgery(s, "both", "blind"); } + }, + voice: { + weight: 10, + allowed: (s) => canTalk(s), + effects: (s) => { clampedDamage(s, 60); s.voice = 0; } + }, + legs: { + weight: 5, + allowed: (s) => hasAnyNaturalLegs(s), + effects: (s) => { clampedDamage(s, 80); removeLimbs(s, "left leg"); removeLimbs(s, "right leg"); } + }, + arm: { + weight: 5, + allowed: (s) => hasAnyNaturalArms(s), + effects: (s) => { clampedDamage(s, 60); removeLimbs(s, jsEither(["left arm", "right arm"])); } + }, + flesh: { + weight: 70, + allowed: () => true, + effects: (s) => { clampedDamage(s, 30); } + } + // TODO: add more wound types? destroy prosthetics? + }; + + /** Inflicts a large amount of damage upon a slave without killing them (i.e. leaving their health total above -90) + * @param {App.Entity.SlaveState} slave + * @param {number} magnitude + */ + function clampedDamage(slave, magnitude) { + if ((slave.health.health - magnitude) > -90) { + healthDamage(slave, magnitude); + } else { + healthDamage(slave, 90 + slave.health.health); + } + } + + /** Inflicts a wound upon a slave during a battle. Returns the wound type from the wound table (see above) so it can be described. + * @param {App.Entity.SlaveState} slave + * @returns {string} + */ + function doWound(slave) { + let woundHash = {}; + for (const w of Object.keys(wounds)) { + if (wounds[w].allowed(slave)) { + woundHash[w] = wounds[w].weight; + } + } + /** @type {string} */ + // @ts-ignore - FIXME: hashChoice has bad JSDoc + const wound = hashChoice(woundHash); + wounds[wound].effects(slave); + return wound; + } + + return doWound; +})(); diff --git a/src/Mods/SecExp/rebellionHandler.tw b/src/Mods/SecExp/rebellionHandler.tw index ae14f8f02cc..2682d53b923 100644 --- a/src/Mods/SecExp/rebellionHandler.tw +++ b/src/Mods/SecExp/rebellionHandler.tw @@ -137,6 +137,7 @@ <</if>> <<set _armyMod = Math.trunc(_armyMod)>> +<<set _rebellingSlaves = 0, _rebellingMilitia = 0, _rebellingMercs = 0>> <<if $slaveRebellion == 1>> <<set _rebellingSlaves = 1>> <<set _unit = App.SecExp.getIrregularUnit("Slaves", $attackTroops, $attackEquip)>> diff --git a/src/Mods/SecExp/rebellionReport.tw b/src/Mods/SecExp/rebellionReport.tw index 47661795c5a..17917286519 100644 --- a/src/Mods/SecExp/rebellionReport.tw +++ b/src/Mods/SecExp/rebellionReport.tw @@ -603,23 +603,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, -90 - $Concubine.health.health)>> - <</if>> <</if>> <</if>> <</if>> @@ -664,23 +658,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> During one of the assaults your Bodyguard was hit. - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> - A splinter pierced _his2 throat, severing _his2 vocal cords. - <<set $Bodyguard.voice = 0>> - <<elseif $woundType == 2>> - A splinter hit _his2 face, severely damaging _his2 eyes. - <<run eyeSurgery($Bodyguard, "both", "blind")>> - <<elseif $woundType == 3>> - An explosion near _him2 caused the loss of all _his2 limbs. - <<run removeLimbs($Bodyguard, "all")>> - <<elseif $woundType >= 4>> - A stray shot severely wounded _him2. - <<if $Bodyguard.health.health >= -60>> - <<run healthDamage($Bodyguard, 30)>> - <<else>> - <<run healthDamage($Bodyguard, $Bodyguard.health.health + 90)>> - <</if>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> + A splinter pierced $his throat, severing $his vocal cords. + <<elseif _woundType == "eyes">> + A splinter hit $his face, severely damaging $his eyes. + <<elseif _woundType == "legs">> + An explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + An explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> + A stray shot severely wounded $him. <</if>> <</if>> The damage to the structure will be @@.red;costly to repair.@@ @@ -772,23 +760,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, $Concubine.health.health + 90)>> - <</if>> <</if>> <</if>> <</if>> @@ -881,23 +863,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, -90 - $Concubine.health.health)>> - <</if>> <</if>> <</if>> <</if>> -- GitLab