Skip to content

Commit

Permalink
More weapon compatibility, improved outcome chance readout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Sep 12, 2023
1 parent 8f9c40b commit 6989fed
Show file tree
Hide file tree
Showing 91 changed files with 1,068 additions and 7 deletions.
20 changes: 15 additions & 5 deletions Source/ThingGenerator/Outcome/OutcomeUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,21 @@ static void Log(string msg)
bool canPen = Rand.Chance(chanceToPen);
Log($"Random will pen outcome: {canPen}");

// Cap chance to pen to make percentage calculations work.
chanceToPen = Mathf.Clamp01(chanceToPen);

// Calculate kill chance based on lethality and settings.
bool preventKill = Core.Settings.ExecutionsOnFriendliesAreNotLethal && (victim.IsColonist || victim.IsSlaveOfColony || victim.IsPrisonerOfColony || victim.Faction == Faction.OfPlayerSilentFail);
bool attemptKill = Rand.Chance(lethality);
Log($"Prevent kill: {preventKill}");
Log($"Attempt kill: {attemptKill}");
Log($"Attempt kill: {attemptKill} (from random lethality chance)");

// Cap lethality to 100% because otherwise it messes up percentage calculations.
lethality = Mathf.Clamp01(lethality);

float preventKillCoef = preventKill ? 0f : 1f;
if (report != null)
report.KillChance = preventKill ? 0f : chanceToPen * lethality;
report.KillChance = preventKillCoef * chanceToPen * lethality; // Absolute chance to kill.

var outcome = ExecutionOutcome.Nothing;
if (canPen && !preventKill && attemptKill)
Expand All @@ -165,13 +172,16 @@ static void Log(string msg)
}

Log("Moving on to down or injure...");

float downChance = RemapClamped(4, 20, 0.2f, 0.9f, attackerMeleeSkill);
Log(canPen ? $"Chance to down, based on melee skill of {attackerMeleeSkill:N1}: {downChance:P1}" : "Cannot down, pen chance failed. Will damage.");
if (report != null)
{
report.DownChance = (1f - lethality) * downChance * chanceToPen;
report.InjureChance = (1f - lethality) * (1f - downChance);
report.DownChance = (1 - report.KillChance) * chanceToPen * downChance;
report.InjureChance = 1 - report.KillChance - report.DownChance;

float sum = report.KillChance + report.DownChance + report.InjureChance;
if (Math.Abs(sum - 1f) > 0.001f)
Core.Error($"Bad percentage calculation ({sum})! Please tell the developer he is an idiot.");
}

if (outcome == ExecutionOutcome.Nothing && canPen && Rand.Chance(downChance))
Expand Down
15 changes: 13 additions & 2 deletions Source/ThingGenerator/UI/Dialog_TweakEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ public override void DoWindowContents(Rect inRect)
string MakeName(ModTweakContainer container)
{
int total = container.Reports.Count();
int withFallback = 0;
int done = 0;
foreach (var rep in container.Reports)
{
var tweak = TweakDataManager.TryGetTweak(rep.Weapon, container.Mod);
if (tweak != null)
done++;

var any = TweakDataManager.TryGetTweak(rep.Weapon);
if (any != null)
withFallback++;
}

string color = "red";
Expand All @@ -153,7 +158,7 @@ string MakeName(ModTweakContainer container)
color = done >= total ? "green" : "yellow";
}

return $"<color={color}>{container.Mod.Name} ({done}/{total})</color>";
return $"<color={color}>{container.Mod.Name} ({done}/{withFallback}/{total})</color>";
}

var source = TweakDataManager.GetTweaksReportForActiveMods();
Expand Down Expand Up @@ -237,6 +242,7 @@ where tweak is not null
{
bool hasTweak = TweakDataManager.TryGetTweak(def, Mod) != null;
bool hasFallback = false;
ModContentPack fallbackRetexMod = null;
if (!hasTweak)
{
// Find fallback tweak.
Expand All @@ -249,12 +255,17 @@ where tweak is not null
var fallback = TweakDataManager.TryGetTweak(def, retex.mod);
if (fallback != null)
{
fallbackRetexMod = retex.mod;
hasFallback = true;
break;
}
}
}
list.Add(new FloatMenuOption($"<color={(hasTweak ? "#97ff87" : hasFallback ? "#fff082" : "#ff828a")}>{def.LabelCap}</color> ", () =>

string additional = "";
if (fallbackRetexMod != null)
additional = $" [Fllbk: {fallbackRetexMod.Name}]";
list.Add(new FloatMenuOption($"<color={(hasTweak ? "#97ff87" : hasFallback ? "#fff082" : "#ff828a")}>{def.LabelCap}{additional}</color> ", () =>
{
Def = def;
ResetBuffers();
Expand Down
9 changes: 9 additions & 0 deletions WeaponTweakData/AP_ImaginaryKnife_alexispopcorn.mime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"TextureModID": "alexispopcorn.mime",
"ItemDefName": "AP_ImaginaryKnife",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"HandsMode": 1,
"BladeEnd": 0.214103922,
"MeleeWeaponType": 48
}
7 changes: 7 additions & 0 deletions WeaponTweakData/AP_ImaginaryMace_alexispopcorn.mime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"TextureModID": "alexispopcorn.mime",
"ItemDefName": "AP_ImaginaryMace",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"MeleeWeaponType": 9
}
7 changes: 7 additions & 0 deletions WeaponTweakData/AP_ImaginarySword_alexispopcorn.mime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"TextureModID": "alexispopcorn.mime",
"ItemDefName": "AP_ImaginarySword",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"MeleeWeaponType": 6
}
13 changes: 13 additions & 0 deletions WeaponTweakData/ARR_Falchion_aelanna.arimreborn.core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"TextureModID": "aelanna.arimreborn.core",
"ItemDefName": "ARR_Falchion",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.288142949,
"OffY": -0.0234535038,
"ScaleX": 1.2,
"ScaleY": 1.2,
"BladeStart": 0.120115519,
"BladeEnd": 0.793566465,
"MeleeWeaponType": 6
}
11 changes: 11 additions & 0 deletions WeaponTweakData/ARR_Knife_aelanna.arimreborn.core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"TextureModID": "aelanna.arimreborn.core",
"ItemDefName": "ARR_Knife",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.194328964,
"HandsMode": 1,
"BladeStart": 0.1167651,
"BladeEnd": 0.532227457,
"MeleeWeaponType": 48
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TextureModID": "aelanna.arimreborn.classesandjobs",
"ItemDefName": "ARR_RelicWeapon_Bravura",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.311597049,
"ScaleX": 1.5,
"ScaleY": 1.5,
"BladeStart": 0.428361565,
"BladeEnd": 0.9577416,
"MeleeWeaponType": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TextureModID": "aelanna.arimreborn.classesandjobs",
"ItemDefName": "ARR_RelicWeapon_GaeBolg",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.3484522,
"ScaleX": 2.1,
"ScaleY": 2.1,
"BladeStart": 0.347949773,
"BladeEnd": 1.3296473,
"MeleeWeaponType": 4
}
11 changes: 11 additions & 0 deletions WeaponTweakData/ARR_Spear_aelanna.arimreborn.core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"TextureModID": "aelanna.arimreborn.core",
"ItemDefName": "ARR_Spear",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.3451023,
"Rotation": 45.0,
"BladeStart": 0.559031367,
"BladeEnd": 1.01469994,
"MeleeWeaponType": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"TextureModID": "aelanna.arimreborn.classesandjobs",
"ItemDefName": "ARR_Weapon_Lancer_Basic",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.5595339,
"Rotation": 45.0,
"ScaleX": 1.5,
"ScaleY": 1.5,
"BladeStart": 0.0665071,
"BladeEnd": 1.54072893,
"MeleeWeaponType": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TextureModID": "aelanna.arimreborn.classesandjobs",
"ItemDefName": "ARR_Weapon_Marauder_Basic",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.32164824,
"ScaleX": 1.3,
"ScaleY": 1.3,
"BladeStart": 0.535577834,
"BladeEnd": 0.9543912,
"MeleeWeaponType": 2
}
14 changes: 14 additions & 0 deletions WeaponTweakData/ARR_Zweihander_aelanna.arimreborn.core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TextureModID": "aelanna.arimreborn.core",
"ItemDefName": "ARR_Zweihander",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.459018946,
"OffY": -0.0301546454,
"Rotation": 45.0,
"ScaleX": 1.25,
"ScaleY": 1.25,
"BladeStart": 0.146919459,
"BladeEnd": 1.20567894,
"MeleeWeaponType": 6
}
14 changes: 14 additions & 0 deletions WeaponTweakData/BMT_ChunkIce_biomesteam.biomescaverns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_ChunkIce",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.2052863,
"OffY": -0.0200278573,
"Rotation": -55.0,
"ScaleX": 0.7,
"ScaleY": 0.7,
"BladeStart": 0.09832443,
"BladeEnd": 0.553959966,
"MeleeWeaponType": 8
}
14 changes: 14 additions & 0 deletions WeaponTweakData/BMT_ChunkSand_biomesteam.biomescaverns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_ChunkSand",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.2052863,
"OffY": -0.0200278573,
"Rotation": -55.0,
"ScaleX": 0.7,
"ScaleY": 0.7,
"BladeStart": 0.09832443,
"BladeEnd": 0.553959966,
"MeleeWeaponType": 8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_CrystalMantisClaw",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.22531414,
"OffY": -0.117664136,
"Rotation": 60.0,
"BladeStart": 0.128366426,
"BladeEnd": 0.463834435,
"MeleeWeaponType": 2,
"TrailTint": {
"r": 0.372108966,
"g": 0.8105257,
"b": 0.9641976,
"a": 1.0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_CrystalMantisScythe",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.137692,
"OffY": -0.0250349343,
"BladeStart": 0.376212269,
"BladeEnd": 0.611540139,
"MeleeWeaponType": 2,
"TrailTint": {
"r": 0.372108966,
"g": 0.8105257,
"b": 0.9641976,
"a": 1.0
}
}
13 changes: 13 additions & 0 deletions WeaponTweakData/BMT_FungalMantisClaw_biomesteam.biomescaverns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_FungalMantisClaw",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": -0.232824862,
"OffY": 0.0250347182,
"Rotation": -24.449,
"FlipX": true,
"BladeStart": 0.128366426,
"BladeEnd": 0.62906456,
"MeleeWeaponType": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"TextureModID": "biomesteam.biomescaverns",
"ItemDefName": "BMT_FungalMantisScythe",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.137692,
"OffY": -0.0250349343,
"BladeStart": 0.376212269,
"BladeEnd": 0.611540139,
"MeleeWeaponType": 2,
"TrailTint": {
"r": 0.9,
"g": 0.689215,
"b": 0.109555632,
"a": 1.0
}
}
13 changes: 13 additions & 0 deletions WeaponTweakData/Bast_CeratokHorn_scurvyez.bastyon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"TextureModID": "scurvyez.bastyon",
"ItemDefName": "Bast_CeratokHorn",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.172741264,
"OffY": -0.0175244212,
"Rotation": 5.0,
"FlipY": true,
"BladeStart": 0.08831071,
"BladeEnd": 0.5189111,
"MeleeWeaponType": 2
}
14 changes: 14 additions & 0 deletions WeaponTweakData/ChunkAurelianStone_vanillaexpanded.vtexe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TextureModID": "vanillaexpanded.vtexe",
"ItemDefName": "ChunkAurelianStone",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.1627267,
"OffY": -0.0475664437,
"Rotation": 145.0,
"ScaleX": 0.6,
"ScaleY": 0.6,
"BladeStart": 0.07078587,
"BladeEnd": 0.446309984,
"MeleeWeaponType": 8
}
14 changes: 14 additions & 0 deletions WeaponTweakData/EM_ChunkBasalt_vanillaexpanded.vtexe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TextureModID": "vanillaexpanded.vtexe",
"ItemDefName": "EM_ChunkBasalt",
"ItemType": "ThingDef",
"ItemTypeNamespace": "Verse",
"OffX": 0.1627267,
"OffY": -0.0475664437,
"Rotation": 145.0,
"ScaleX": 0.6,
"ScaleY": 0.6,
"BladeStart": 0.07078587,
"BladeEnd": 0.446309984,
"MeleeWeaponType": 8
}
Loading

0 comments on commit 6989fed

Please sign in to comment.