Skip to content

Commit

Permalink
fix: UI: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kiedtl committed Sep 4, 2023
1 parent 98e5225 commit 529bba2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/combat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ATTACKER_CORRUPT_BONUS: isize = 10;
const ATTACKER_FEAR_NBONUS: isize = 10;
const ATTACKER_HELD_NBONUS: isize = 20;
const ATTACKER_STUN_NBONUS: isize = 15;
const ATTACKER_CONCENTRATE_NBONUS: isize = 100;

const DEFENDER_UNLIT_BONUS: isize = 5;
const DEFENDER_ESHIELD_BONUS: isize = 7; // (per wall, so +7..49)
Expand All @@ -38,6 +39,7 @@ const DEFENDER_ENRAGED_NBONUS: isize = 10;
const DEFENDER_RECUPERATE_NBONUS: isize = 10;
const DEFENDER_HELD_NBONUS: isize = 10;
const DEFENDER_STUN_NBONUS: isize = 15;
const DEFENDER_CONCENTRATE_NBONUS: isize = 100;

pub const WeaponDamageInfo = struct {
total: usize,
Expand Down Expand Up @@ -119,6 +121,7 @@ pub fn chanceOfMeleeLanding(attacker: *const Mob, defender: ?*const Mob) usize {
chance -= if (attacker.hasStatus(.Fear)) ATTACKER_FEAR_NBONUS else 0;
chance -= if (attacker.hasStatus(.Held)) ATTACKER_HELD_NBONUS else 0;
chance -= if (attacker.hasStatus(.Debil)) ATTACKER_STUN_NBONUS else 0;
chance -= if (attacker.hasStatus(.RingConcentration)) ATTACKER_CONCENTRATE_NBONUS else 0;

return @intCast(usize, math.clamp(chance, 0, 100));
}
Expand All @@ -138,6 +141,7 @@ pub fn chanceOfAttackEvaded(defender: *const Mob, attacker: ?*const Mob) usize {
chance -= if (defender.hasStatus(.Debil)) DEFENDER_STUN_NBONUS else 0;
chance -= if (defender.hasStatus(.Recuperate)) DEFENDER_RECUPERATE_NBONUS else 0;
chance -= if (defender.hasStatus(.Enraged)) DEFENDER_ENRAGED_NBONUS else 0;
chance -= if (defender.hasStatus(.RingConcentration)) DEFENDER_CONCENTRATE_NBONUS else 0;

return @intCast(usize, math.clamp(chance, 0, 100));
}
Expand Down
12 changes: 4 additions & 8 deletions src/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,10 @@ pub const Stat = enum {
.Martial, .Spikes, .Conjuration, .Potential => value > 0,
};
}

pub fn showMobStatFancy(self: Stat, stat_val_raw: isize, stat_val_real: isize) bool {
return self != .Speed and @intCast(usize, math.clamp(stat_val_raw, 0, 100)) != stat_val_real;
}
};

pub const Mob = struct { // {{{
Expand Down Expand Up @@ -4091,14 +4095,6 @@ pub const Mob = struct { // {{{
val = @divTrunc(val * 50, 100);
};
},
.Melee => {
if (self.hasStatus(.RingConcentration))
val -= 100;
},
.Evade => {
if (self.hasStatus(.RingConcentration))
val -= 100;
},
else => {},
}

Expand Down
6 changes: 3 additions & 3 deletions src/ui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2559,12 +2559,12 @@ pub fn drawPlayerInfoScreen() void {
const stat_val_raw = state.player.stat(stat);
const stat_val = utils.SignedFormatter{ .v = stat_val_raw };
const stat_val_real = switch (stat) {
.Melee => combat.chanceOfMeleeLanding(state.player, null),
.Evade => combat.chanceOfAttackEvaded(state.player, null),
.Melee => @intCast(isize, combat.chanceOfMeleeLanding(state.player, null)),
.Evade => @intCast(isize, combat.chanceOfAttackEvaded(state.player, null)),
else => stat_val_raw,
};
if (stat.showMobStat(stat_val_raw)) {
if (@intCast(usize, math.clamp(stat_val_raw, 0, 100)) != stat_val_real) {
if (stat.showMobStatFancy(stat_val_raw, stat_val_real)) {
const c = if (@intCast(isize, stat_val_real) < stat_val_raw) @as(u21, 'r') else 'b';
iy += pinfo_win.right.drawTextAtf(0, iy, "$c{s: <11}$. {: >5}{s: >1} $g(${u}{}{s}$g)$.\n", .{ stat.string(), stat_val, stat.formatAfter(), c, stat_val_real, stat.formatAfter() }, .{});
} else {
Expand Down

0 comments on commit 529bba2

Please sign in to comment.