Skip to content

Commit

Permalink
Calculate and show expiration dates for quipment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Nov 3, 2023
1 parent 679a725 commit f38e6b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/commands/quip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ async function asyncHandler(
let user = await userFromMessage(message);
let settings = user?.profiles[0] ? await loadProfile(user.profiles[0].dbid) : null;
let profile = user?.profiles[0] ? loadFullProfile(user.profiles[0].dbid) : null;
let dnum = 0;
if (!user || !profile) {
sendAndCache(message, "Sorry, I couldn't find an associated profile for your user.")
return;
}
else {
dnum = (user.profiles[0].updatedAt as Date).getTime() / 1000;
}
if (crewman?.length) {
crewman = crewman.toLowerCase().trim();
}
Expand Down Expand Up @@ -63,6 +67,9 @@ async function asyncHandler(
return crew.symbol === crew.symbol
}) as Definitions.BotCrew;
crew = JSON.parse(JSON.stringify(crew));
if (dnum)
crew.kwipment_expirations = (crew.kwipment_expiration.map(kw => new Date((dnum+kw[1]) * 1000))?.filter(chk => !!chk) ?? []) as Date[];

crew.name = matched?.name ?? crew.name;
crew.bigbook_tier = matched?.bigbook_tier;
crew.date_added = new Date(crew.date_added);
Expand Down Expand Up @@ -123,9 +130,12 @@ async function asyncHandler(
if (can.kwipment_items?.length) {
if (!!crewman) {
embeds.push(embed);
let e = 0;
for (let quip of can.kwipment_items) {
let b = getItemBonuses(quip as EquipmentItem).bonuses as Definitions.Skills;

let exp = (can.kwipment_expirations && can.kwipment_expiration.length > e) ? toTimestamp(can.kwipment_expirations[e]) : "N/A";
e++;

embed = new EmbedBuilder()
.setTitle(`${quip.name}`)
.setDescription(quip.flavor)
Expand All @@ -147,6 +157,11 @@ async function asyncHandler(
value: `${quip.duration} h`,
inline: true
},
{
name: "Expires On",
value: `${exp}`,
inline: true
},
{
name: "Equippable By",
value: `${rarityLabels[(quip.max_rarity_requirement ?? 1) - 1]} crew`,
Expand All @@ -163,12 +178,16 @@ async function asyncHandler(
}
}
else {
let e = 0;
for (let quip of can.kwipment_items) {
let exp = (can.kwipment_expirations && can.kwipment_expiration.length > e) ? toTimestamp(can.kwipment_expirations[e]) : "N/A";
e++;

let b = getItemBonuses(quip as EquipmentItem).bonuses as Definitions.Skills;

embed = embed.addFields({
name: quip.name,
value: ((quip.rarity ? '⭐'.repeat(quip.rarity ?? 0) : '')) + formatSkillsStatsWithEmotes(message, b) + `\nDuration: ${quip.duration} h` +
value: ((quip.rarity ? '⭐'.repeat(quip.rarity ?? 0) : '')) + formatSkillsStatsWithEmotes(message, b) + `\nDuration: ${quip.duration} h (Expires on ${exp})` +
((!!quip.traits_requirement?.length) ? `\nTraits: ${quip.traits_requirement?.map(t => appelate(t)).join(` ${quip.traits_requirement_operator} `)}` : '') +
`\nEquippable by ${rarityLabels[(quip.max_rarity_requirement ?? 1) - 1]} crew`

Expand Down
3 changes: 2 additions & 1 deletion src/datacore/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ export interface Player {
equipment: number[][] | number[]

kwipment: number[][];
kwipment_expiration: number[];
kwipment_expiration: number[][];
kwipment_items?: Definitions.Item[];
kwipment_expirations?: Date[];
q_bits: number

icon: Icon
Expand Down

0 comments on commit f38e6b8

Please sign in to comment.