62 lines
1.7 KiB
Zig
62 lines
1.7 KiB
Zig
// zig fmt: off
|
|
const std = @import("std");
|
|
const Api = @import("artifacts-api");
|
|
const Artificer = @import("./root.zig");
|
|
|
|
const Goal = @This();
|
|
|
|
slot: Api.Character.Equipment.SlotId,
|
|
item: Api.Store.Id,
|
|
quantity: u64 = 1,
|
|
|
|
pub fn tick(self: *Goal, goal_id: Artificer.GoalId, artificer: *Artificer) void {
|
|
const store = artificer.server.store;
|
|
const character = store.characters.get(artificer.character).?;
|
|
|
|
const equipment_slot = character.equipment.slots.get(self.slot);
|
|
if (equipment_slot.item) |equiped_item|{
|
|
if (equiped_item == self.item and !self.slot.canHoldManyItems()) {
|
|
artificer.removeGoal(goal_id);
|
|
} else {
|
|
artificer.queued_actions.appendAssumeCapacity(.{
|
|
.goal = goal_id,
|
|
.action = .{
|
|
.unequip = .{
|
|
.slot = self.slot,
|
|
.quantity = self.quantity
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
artificer.queued_actions.appendAssumeCapacity(.{
|
|
.goal = goal_id,
|
|
.action = .{
|
|
.equip = .{
|
|
.slot = self.slot,
|
|
.item = self.item,
|
|
.quantity = self.quantity
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
pub fn requirements(self: Goal, artificer: *Artificer) Artificer.Requirements {
|
|
_ = artificer;
|
|
|
|
var reqs: Artificer.Requirements = .{};
|
|
reqs.items.addAssumeCapacity(self.item, self.quantity);
|
|
|
|
return reqs;
|
|
}
|
|
|
|
pub fn onActionCompleted(self: *Goal, goal_id: Artificer.GoalId, artificer: *Artificer, result: Artificer.ActionResult) void {
|
|
_ = self;
|
|
|
|
if (result == .equip) {
|
|
artificer.removeGoal(goal_id);
|
|
}
|
|
}
|