This document explains the new mechanics introduced in the WP_SaberCanBlock
function, which adds more granular control over the saber blocking system in Jedi Knight II.
In the base game, Blue and Yellow saber styles were almost useless against a Level 3 Defense, but these changes aim to make things more balanced and configurable.
The updated code introduces three new console variables that allow for dynamic adjustment of block chances (that were hardcoded in BaseJK) for a Level 3 Saber Defend skill.
g_blockchancer
: Controls the chance to block a Red (Level 3) saber attack.
g_blockchancey
: Controls the chance to block a Yellow (Level 2) saber attack.
g_blockchanceb
: Controls the chance to block a Blue (Level 1) saber attack.
The core logic for blocking with a Level 3 defense now relies on a random dice roll. A random number from 1 to 10 is generated. If the number is less than or equal to the Cvar's value, the block fails. The mod now ensures that the Cvar value is always between 0 and 10, preventing unexpected behavior.
Chance of Blocking = 10 - (Cvar value) 10
The g_disablerandomparries
Cvar acts as a global toggle. If set to 1
, all random chance checks are bypassed, and the only-angle-based blocking logic is used, where only the g_blockfactor
Cvar determines if a block is successful for a Level 3 defender.
Cvar Value (g_blockchanceX) | Chance of Failure | Chance of Blocking | BaseJK Style(s) |
---|---|---|---|
0 | 0% | 100% | Yellow, Blue |
1 | 10% | 90% | |
2 | 20% | 80% | Red |
3 | 30% | 70% | |
4 | 40% | 60% | |
5 | 50% | 50% | |
6 | 60% | 40% | |
7 | 70% | 30% | |
8 | 80% | 20% | |
9 | 90% | 10% | |
10 | 100% | 0% |
g_blockfactor
)
The new code introduces a configurable g_blockfactor
Cvar. This variable determines the angle within which a player can successfully block an attack. The value is a cosine, and a lower value corresponds to a wider, more forgiving angle. The specific angle can be calculated using the inverse cosine (arc-cosine) of the blockFactor
.
Angle in degrees = arccos(blockFactor)
Enter a blockFactor value (0 to 1) to calculate the angle.
g_blockfactor
value results in a wider block angle, making it easier to block attacks.
g_blockfactor
value results in a narrower block angle, making it harder to block attacks.
g_blockfactor
, which is clamped between 0.0f
and 1.0f
. Invalid values revert to the base game's block factor of 0.05f
.
0.6f
for Level 2 and 0.9f
for Level 1.
0.25f
, making them harder to block.
The angle is measured from the center of the player's view direction. For example, a blockFactor
of 0.0
allows blocking in a full ±90° cone, while a blockFactor
of 1.0
only allows blocking if the attack is perfectly centered.
g_blockfactor
= 0.0: An attack can be blocked if it's within a ±90° cone from the player's forward view.
g_blockfactor
= 0.05: An attack can be blocked if it's within a ±87° cone. This is the original Jedi Knight block factor. (BaseJK)
g_blockfactor
= 0.6: An attack can be blocked if it's within a ±53° cone. This is the hardcoded angle for a Level 2 Saber Defend skill.
g_blockfactor
= 0.9: An attack can be blocked if it's within a ±26° cone. This is the hardcoded angle for a Level 1 Saber Defend skill.
g_blockfactor
= 1.0: An attack can be blocked if it's within a ±0° cone, requiring the attack to be perfectly centered.
The function also contains several checks that will cause a block to fail immediately, regardless of skill level or Cvar settings:
blockFactor
.The following table and analysis highlight the key differences between the original Jedi Knight II blocking code and the changes introduced in this mod.
The base game code for WP_SaberCanBlock
uses a series of conditional checks with hardcoded values:
20%
chance of failure.50%
chance of failure.~7.5%
chance of failure.blockFactor
is fixed based on the player's Saber Defend skill level.
0.05f
0.6f
0.9f
blockFactor
is reduced against thrown sabers and regular saber attacks.
g_blockchancer
(for Red attacks)g_blockchancey
(for Yellow attacks)g_blockchanceb
(for Blue attacks)g_disablerandomparries
Cvar can bypass the random chance mechanic entirely.
blockFactor
for a Level 3 defender is no longer a fixed value but is controlled by the new g_blockfactor
Cvar.
Feature | Base Game Logic | Mod Logic |
---|---|---|
Block Chance | Hardcoded random checks. | Controlled by g_blockchancer , g_blockchancey , and g_blockchanceb for Level 3 defenders. |
Block Angle | Hardcoded blockFactor values. |
g_blockfactor Cvar controls the angle for Level 3 defenders. |
Flexibility | Very low flexibility. | High flexibility. Admins can fine-tune chance and angle. |
Randomness Toggle | No global toggle. | g_disablerandomparries Cvar allows for a purely angle-based block system. |