rogged/libs/combat/combat.zig
NotAShelf 22ab6fc6eb
combat: rewrite in Zig; add basic damage types and weapon archetypes
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic8055a1cf6bdad1aca13673ea171b4b46a6a6964
2026-04-05 20:29:12 +03:00

84 lines
1.9 KiB
Zig

const c = @import("c.zig");
const event = @import("event.zig");
const fx = @import("effects.zig");
const atk = @import("attack.zig");
comptime {
_ = @import("c.zig");
_ = @import("event.zig");
_ = @import("effects.zig");
_ = @import("attack.zig");
}
export fn combat_get_last_message() [*c]const u8 {
return event.last.message;
}
export fn combat_get_last_damage() c_int {
return event.last.damage;
}
export fn combat_was_player_damage() c_int {
return event.last.is_player_damage;
}
export fn combat_was_critical() c_int {
return event.last.is_critical;
}
export fn combat_was_dodged() c_int {
return event.last.was_dodged;
}
export fn combat_was_blocked() c_int {
return event.last.was_blocked;
}
export fn combat_get_block_amount() c_int {
return event.last.block_amount;
}
export fn combat_get_applied_effect() c.StatusEffectType {
return event.last.applied_effect;
}
export fn combat_reset_event() void {
event.reset();
}
export fn combat_has_effect(
effects: [*c]const c.StatusEffect,
count: c_int,
effect_type: c.StatusEffectType,
) c_int {
if (effects == null) return 0;
return if (fx.has(effects, count, effect_type)) 1 else 0;
}
export fn combat_apply_effect(
effects: [*c]c.StatusEffect,
count: [*c]c_int,
effect_type: c.StatusEffectType,
duration: c_int,
intensity: c_int,
) void {
if (effects == null or count == null) return;
if (effect_type == c.EFFECT_NONE) return;
fx.apply(effects, count, effect_type, duration, intensity);
}
export fn combat_tick_effects(p: [*c]c.Player) c_int {
return fx.tickPlayer(p);
}
export fn combat_tick_enemy_effects(e: [*c]c.Enemy) c_int {
return fx.tickEnemy(e);
}
export fn combat_player_attack(p: [*c]c.Player, e: [*c]c.Enemy) void {
atk.playerAttack(p, e);
}
export fn combat_enemy_attack(e: [*c]c.Enemy, p: [*c]c.Player) void {
atk.enemyAttack(e, p);
}