diff --git a/assets/cubyz/blocks/amber_ore.zig.zon b/assets/cubyz/blocks/amber_ore.zig.zon index 253565f57f..0191096771 100644 --- a/assets/cubyz/blocks/amber_ore.zig.zon +++ b/assets/cubyz/blocks/amber_ore.zig.zon @@ -13,7 +13,8 @@ .textureRoughness = 0.1, .modifiers = .{ .{ - .id = "light", + .id = "base_stat", + .targetProperty = "swingSpeed", .strength = 0.5, .restriction = .{ .id = .encased, diff --git a/assets/cubyz/blocks/branch/baobab.zig.zon b/assets/cubyz/blocks/branch/baobab.zig.zon index 0c196783d1..48f384dd1f 100644 --- a/assets/cubyz/blocks/branch/baobab.zig.zon +++ b/assets/cubyz/blocks/branch/baobab.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/birch.zig.zon b/assets/cubyz/blocks/branch/birch.zig.zon index 367be25250..d127daf2d2 100644 --- a/assets/cubyz/blocks/branch/birch.zig.zon +++ b/assets/cubyz/blocks/branch/birch.zig.zon @@ -23,7 +23,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/bolete.zig.zon b/assets/cubyz/blocks/branch/bolete.zig.zon index 5a38006fcf..7033bc2da3 100644 --- a/assets/cubyz/blocks/branch/bolete.zig.zon +++ b/assets/cubyz/blocks/branch/bolete.zig.zon @@ -17,7 +17,8 @@ .textureRoughness = 0.5, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/cirrus.zig.zon b/assets/cubyz/blocks/branch/cirrus.zig.zon index 4150b41cbe..75331b6d75 100644 --- a/assets/cubyz/blocks/branch/cirrus.zig.zon +++ b/assets/cubyz/blocks/branch/cirrus.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "light", + .id = "base_stat", + .targetProperty = "swingSpeed", .strength = 0.15, }, }, diff --git a/assets/cubyz/blocks/branch/glimmergill.zig.zon b/assets/cubyz/blocks/branch/glimmergill.zig.zon index 867a421e1e..900a6c7e1a 100644 --- a/assets/cubyz/blocks/branch/glimmergill.zig.zon +++ b/assets/cubyz/blocks/branch/glimmergill.zig.zon @@ -17,7 +17,8 @@ .textureRoughness = 0.5, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.50, }, }, diff --git a/assets/cubyz/blocks/branch/mahogany.zig.zon b/assets/cubyz/blocks/branch/mahogany.zig.zon index 90e5d3d444..2a07c943ff 100644 --- a/assets/cubyz/blocks/branch/mahogany.zig.zon +++ b/assets/cubyz/blocks/branch/mahogany.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/oak.zig.zon b/assets/cubyz/blocks/branch/oak.zig.zon index 9a1b9f2a56..4beda72298 100644 --- a/assets/cubyz/blocks/branch/oak.zig.zon +++ b/assets/cubyz/blocks/branch/oak.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/palm.zig.zon b/assets/cubyz/blocks/branch/palm.zig.zon index 197a87f8c6..a8715f77bc 100644 --- a/assets/cubyz/blocks/branch/palm.zig.zon +++ b/assets/cubyz/blocks/branch/palm.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/pine.zig.zon b/assets/cubyz/blocks/branch/pine.zig.zon index b833b9f90f..9e1565d357 100644 --- a/assets/cubyz/blocks/branch/pine.zig.zon +++ b/assets/cubyz/blocks/branch/pine.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/toadstool.zig.zon b/assets/cubyz/blocks/branch/toadstool.zig.zon index e921d4d3c5..e67b45f808 100644 --- a/assets/cubyz/blocks/branch/toadstool.zig.zon +++ b/assets/cubyz/blocks/branch/toadstool.zig.zon @@ -17,7 +17,8 @@ .textureRoughness = 0.5, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/branch/willow.zig.zon b/assets/cubyz/blocks/branch/willow.zig.zon index 216fd33191..32b6eac167 100644 --- a/assets/cubyz/blocks/branch/willow.zig.zon +++ b/assets/cubyz/blocks/branch/willow.zig.zon @@ -20,7 +20,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.45, }, }, diff --git a/assets/cubyz/blocks/diamond_ore.zig.zon b/assets/cubyz/blocks/diamond_ore.zig.zon index 212f2570ed..a6dbbe9b0b 100644 --- a/assets/cubyz/blocks/diamond_ore.zig.zon +++ b/assets/cubyz/blocks/diamond_ore.zig.zon @@ -25,8 +25,9 @@ .textureRoughness = 0.1, .modifiers = .{ .{ - .id = "fragile", - .strength = 0.5, + .id = "base_stat", + .targetProperty = "maxDurability", + .strength = -0.5, .restriction = .{ .id = .not, .child = .{ @@ -37,7 +38,8 @@ }, }, .{ - .id = "powerful", + .id = "base_stat", + .targetProperty = "damage", .strength = 0.5, .restriction = .{ .id = .encased, diff --git a/assets/cubyz/blocks/jade_ore.zig.zon b/assets/cubyz/blocks/jade_ore.zig.zon index cd1738c504..0452b16b92 100644 --- a/assets/cubyz/blocks/jade_ore.zig.zon +++ b/assets/cubyz/blocks/jade_ore.zig.zon @@ -13,7 +13,8 @@ .textureRoughness = 0.1, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 1.5, .restriction = .{ .id = .encased, diff --git a/assets/cubyz/blocks/obsidian.zig.zon b/assets/cubyz/blocks/obsidian.zig.zon index 4ece98fa0a..c150c6161b 100644 --- a/assets/cubyz/blocks/obsidian.zig.zon +++ b/assets/cubyz/blocks/obsidian.zig.zon @@ -15,8 +15,9 @@ .textureRoughness = 0.1, .modifiers = .{ .{ - .id = "fragile", - .strength = 0.33, + .id = "base_stat", + .targetProperty = "maxDurability", + .strength = -0.33, }, }, }, diff --git a/assets/cubyz/blocks/planks/baobab.zig.zon b/assets/cubyz/blocks/planks/baobab.zig.zon index 4054ff863a..034761b6bc 100644 --- a/assets/cubyz/blocks/planks/baobab.zig.zon +++ b/assets/cubyz/blocks/planks/baobab.zig.zon @@ -8,7 +8,8 @@ .swingSpeed = 4.2, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/birch.zig.zon b/assets/cubyz/blocks/planks/birch.zig.zon index b8c08dd578..8646308ca2 100644 --- a/assets/cubyz/blocks/planks/birch.zig.zon +++ b/assets/cubyz/blocks/planks/birch.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/cirrus.zig.zon b/assets/cubyz/blocks/planks/cirrus.zig.zon index f178d20555..5b09b82c7c 100644 --- a/assets/cubyz/blocks/planks/cirrus.zig.zon +++ b/assets/cubyz/blocks/planks/cirrus.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "light", + .id = "base_stat", + .targetProperty = "swingSpeed", .strength = 0.1, }, }, diff --git a/assets/cubyz/blocks/planks/mahogany.zig.zon b/assets/cubyz/blocks/planks/mahogany.zig.zon index d0ba112a94..9b5a9fdd31 100644 --- a/assets/cubyz/blocks/planks/mahogany.zig.zon +++ b/assets/cubyz/blocks/planks/mahogany.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/oak.zig.zon b/assets/cubyz/blocks/planks/oak.zig.zon index d005b075f9..64aa86665b 100644 --- a/assets/cubyz/blocks/planks/oak.zig.zon +++ b/assets/cubyz/blocks/planks/oak.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/palm.zig.zon b/assets/cubyz/blocks/planks/palm.zig.zon index 7b77bf8a44..8c307f0671 100644 --- a/assets/cubyz/blocks/planks/palm.zig.zon +++ b/assets/cubyz/blocks/planks/palm.zig.zon @@ -8,7 +8,8 @@ .swingSpeed = 5.2, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/pine.zig.zon b/assets/cubyz/blocks/planks/pine.zig.zon index f33e3e67fb..61a08d0263 100644 --- a/assets/cubyz/blocks/planks/pine.zig.zon +++ b/assets/cubyz/blocks/planks/pine.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/planks/willow.zig.zon b/assets/cubyz/blocks/planks/willow.zig.zon index a575a29583..636e98d48c 100644 --- a/assets/cubyz/blocks/planks/willow.zig.zon +++ b/assets/cubyz/blocks/planks/willow.zig.zon @@ -9,7 +9,8 @@ .textureRoughness = 0.7, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.4, }, }, diff --git a/assets/cubyz/blocks/ruby_ore.zig.zon b/assets/cubyz/blocks/ruby_ore.zig.zon index 6f87fa442a..b63f17d063 100644 --- a/assets/cubyz/blocks/ruby_ore.zig.zon +++ b/assets/cubyz/blocks/ruby_ore.zig.zon @@ -13,8 +13,9 @@ .textureRoughness = 0.1, .modifiers = .{ .{ - .id = "fragile", - .strength = 0.45, + .id = "base_stat", + .targetProperty = "maxDurability", + .strength = -0.45, .restriction = .{ .id = .not, .child = .{ diff --git a/assets/cubyz/blocks/sandstone/_defaults.zig.zon b/assets/cubyz/blocks/sandstone/_defaults.zig.zon index 6a1a570d13..cdd0d851d9 100644 --- a/assets/cubyz/blocks/sandstone/_defaults.zig.zon +++ b/assets/cubyz/blocks/sandstone/_defaults.zig.zon @@ -14,8 +14,9 @@ .textureRoughness = 0.9, .modifiers = .{ .{ - .id = "fragile", - .strength = 0.20, + .id = "base_stat", + .targetProperty = "maxDurability", + .strength = -0.20, .restriction = .{ .id = .not, .child = .{ diff --git a/assets/cubyz/blocks/voidstone/_defaults.zig.zon b/assets/cubyz/blocks/voidstone/_defaults.zig.zon index 4397bb26ff..dc01ab4327 100644 --- a/assets/cubyz/blocks/voidstone/_defaults.zig.zon +++ b/assets/cubyz/blocks/voidstone/_defaults.zig.zon @@ -15,7 +15,8 @@ .textureRoughness = 0.4, .modifiers = .{ .{ - .id = "durable", + .id = "base_stat", + .targetProperty = "maxDurability", .strength = 0.1, }, .{ diff --git a/src/items.zig b/src/items.zig index e2faaea9ec..60ad5d2659 100644 --- a/src/items.zig +++ b/src/items.zig @@ -800,13 +800,13 @@ pub const ProceduralItemType = struct { // MARK: ProceduralItemType pixelSourcesOverlay: [16][16]u8, }; -const ProceduralItemProperty = enum { - damage, - maxDurability, +pub const ProceduralItemProperty = enum(u8) { + damage = 0, + maxDurability = 1, /// how long it takes before the next swing happens - swingSpeed, + swingSpeed = 2, - fn fromString(string: []const u8) ?ProceduralItemProperty { + pub fn fromString(string: []const u8) ?ProceduralItemProperty { return std.meta.stringToEnum(ProceduralItemProperty, string) orelse { std.log.err("Couldn't find procedural Item property {s}.", .{string}); return null; diff --git a/src/proceduralItem/modifiers/_list.zig b/src/proceduralItem/modifiers/_list.zig index 2d05043d6f..cadaddeb09 100644 --- a/src/proceduralItem/modifiers/_list.zig +++ b/src/proceduralItem/modifiers/_list.zig @@ -1,9 +1,4 @@ pub const bad_at = @import("bad_at.zig"); -pub const durable = @import("durable.zig"); -pub const fragile = @import("fragile.zig"); pub const good_at = @import("good_at.zig"); -pub const heavy = @import("heavy.zig"); -pub const light = @import("light.zig"); -pub const powerful = @import("powerful.zig"); pub const single_use = @import("single_use.zig"); -pub const weak = @import("weak.zig"); +pub const base_stat = @import("base_stat.zig"); diff --git a/src/proceduralItem/modifiers/base_stat.zig b/src/proceduralItem/modifiers/base_stat.zig new file mode 100644 index 0000000000..85bff52da8 --- /dev/null +++ b/src/proceduralItem/modifiers/base_stat.zig @@ -0,0 +1,54 @@ +const std = @import("std"); + +const main = @import("main"); +const ProceduralItem = main.items.ProceduralItem; + +pub const Data = packed struct(u128) { strength: f32, targetProperty: main.items.ProceduralItemProperty, pad: u88 = undefined }; + +pub const priority = 1; + +fn getModifierName(data: Data) []const u8 { + if (data.strength >= 0) { + switch (data.targetProperty) { + .damage => return "#f84a00**Powerful**", + .maxDurability => return "#500090**Durable**", + .swingSpeed => return "#9fffde**Light**", + } + } else { + switch (data.targetProperty) { + .damage => return "#fcb5e3**Weak**", + .maxDurability => return "#ccddff**Fragile**", + .swingSpeed => return "#ffcc30**Heavy**", + } + } +} + +pub fn loadData(zon: main.ZonElement) Data { + return .{ + .strength = zon.get(f32, "strength") orelse 0, + .targetProperty = main.items.ProceduralItemProperty.fromString(zon.get([]const u8, "targetProperty") orelse "missing .targetProperty field") orelse blk: { + std.log.err("replacing with .damage", .{}); + break :blk .damage; + }, + }; +} + +pub fn combineModifiers(data1: Data, data2: Data) ?Data { + if (data1.targetProperty != data2.targetProperty) return null; + return .{ + .strength = std.math.hypot(data1.strength, data2.strength), + .targetProperty = data1.targetProperty, + }; +} + +pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { + proceduralItem.setProperty(data.targetProperty, proceduralItem.getProperty(data.targetProperty)*(1 + data.strength)); +} + +pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { + if (data.strength >= 0) { + outString.print("{s} #808080(#30ca64+**{d:.0}% #808080{})", .{getModifierName(data), data.strength*100, data.targetProperty}); + } else { + outString.print("{s} #808080(#fd3535**{d:.0}% #808080{})", .{getModifierName(data), data.strength*100, data.targetProperty}); + } +} diff --git a/src/proceduralItem/modifiers/durable.zig b/src/proceduralItem/modifiers/durable.zig deleted file mode 100644 index a491af6a55..0000000000 --- a/src/proceduralItem/modifiers/durable.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = @max(0, zon.get(f32, "strength") orelse 0)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = std.math.hypot(data1.strength, data2.strength)}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.maxDurability, proceduralItem.getProperty(.maxDurability)*(1 + data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#500090**Durable**#808080 *Increases durability by **{d:.0}%", .{data.strength*100}); -} diff --git a/src/proceduralItem/modifiers/fragile.zig b/src/proceduralItem/modifiers/fragile.zig deleted file mode 100644 index 2450f40109..0000000000 --- a/src/proceduralItem/modifiers/fragile.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = std.math.clamp(zon.get(f32, "strength") orelse 0, 0, 1)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = 1.0 - 1.0/(1.0 + std.math.hypot(1.0/(1.0 - data1.strength) - 1.0, 1.0/(1.0 - data2.strength) - 1.0))}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.maxDurability, proceduralItem.getProperty(.maxDurability)*(1 - data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#ccddff**Fragile**#808080 *Decreases durability by **{d:.0}%", .{data.strength*100}); -} diff --git a/src/proceduralItem/modifiers/heavy.zig b/src/proceduralItem/modifiers/heavy.zig deleted file mode 100644 index 033a12cb46..0000000000 --- a/src/proceduralItem/modifiers/heavy.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = @max(0, zon.get(f32, "strength") orelse 0)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = 1.0 - 1.0/(1.0 + std.math.hypot(1.0/(1.0 - data1.strength) - 1.0, 1.0/(1.0 - data2.strength) - 1.0))}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.swingSpeed, proceduralItem.getProperty(.swingSpeed)*(1 - data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#ffcc30**Heavy**#808080 *Decreases swing speed by **{d:.0}%", .{data.strength*100}); -} diff --git a/src/proceduralItem/modifiers/light.zig b/src/proceduralItem/modifiers/light.zig deleted file mode 100644 index 319e0bc787..0000000000 --- a/src/proceduralItem/modifiers/light.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = std.math.clamp(zon.get(f32, "strength") orelse 0, 0, 1)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = std.math.hypot(data1.strength, data2.strength)}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.swingSpeed, proceduralItem.getProperty(.swingSpeed)*(1 + data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#9fffde**Light**#808080 *Increases swing speed by **{d:.0}%", .{data.strength*100}); -} diff --git a/src/proceduralItem/modifiers/powerful.zig b/src/proceduralItem/modifiers/powerful.zig deleted file mode 100644 index 96b5330356..0000000000 --- a/src/proceduralItem/modifiers/powerful.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = @max(0, zon.get(f32, "strength") orelse 0)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = std.math.hypot(data1.strength, data2.strength)}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.damage, proceduralItem.getProperty(.damage)*(1 + data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#f84a00**Powerful**#808080 *Increases damage by **{d:.0}%", .{data.strength*100}); -} diff --git a/src/proceduralItem/modifiers/weak.zig b/src/proceduralItem/modifiers/weak.zig deleted file mode 100644 index 6290f5aa22..0000000000 --- a/src/proceduralItem/modifiers/weak.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -const main = @import("main"); -const ProceduralItem = main.items.ProceduralItem; - -pub const Data = packed struct(u128) { strength: f32, pad: u96 = undefined }; - -pub const priority = 1; - -pub fn loadData(zon: main.ZonElement) Data { - return .{.strength = std.math.clamp(zon.get(f32, "strength") orelse 0, 0, 1)}; -} - -pub fn combineModifiers(data1: Data, data2: Data) ?Data { - return .{.strength = 1.0 - 1.0/(1.0 + std.math.hypot(1.0/(1.0 - data1.strength) - 1.0, 1.0/(1.0 - data2.strength) - 1.0))}; -} - -pub fn changeProceduralItemParameters(proceduralItem: *ProceduralItem, data: Data) void { - proceduralItem.setProperty(.damage, proceduralItem.getProperty(.damage)*(1 - data.strength)); -} - -pub fn printTooltip(outString: *main.ListManaged(u8), data: Data) void { - outString.print("#fcb5e3**Weak**#808080 *Decreases damage by **{d:.0}%", .{data.strength*100}); -}