Skip to content

Commit

Permalink
feat(weapons): refining ability
Browse files Browse the repository at this point in the history
  • Loading branch information
KeziahMoselle committed Mar 5, 2023
1 parent 5dc819b commit 2695d3e
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/components/AbilityThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function AbilityThumbnail({
</div>

{children || (
<span className="mt-1 text-sm text-center leading-none">
<span className="mt-1 text-xs text-center leading-none">
{ability.name}
</span>
)}
Expand Down
31 changes: 31 additions & 0 deletions src/components/WeaponInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,37 @@ export function SingleWeapon({
{weapon.weapon_ability_link
.sort((a, b) => a.slot_number - b.slot_number)
.filter((ability) => ability.ability_level === abilityLevel)
.slice(0, 3)
.map((ability) => (
<Ability
key={ability.ability_id}
href={`/ability/weapon/${slug(ability.weapon_ability.name)}-${
ability.weapon_ability.ability_id
}`}
name={ability.weapon_ability.name}
description={ability.weapon_ability.description}
imagePathBase={ability.weapon_ability.image_path_base}
level={ability.ability_level}
maxLevel={15}
/>
))}

{weapon.weapon_ability_link
.sort((a, b) => a.slot_number - b.slot_number)
.filter((ability) => ability.ability_level === abilityLevel)
.slice(3, 4).length > 0 && (
<Lines
className="mb-2 mt-8"
containerClass="justify-center"
svgClass="w-96 xl:w-42"
>
<h2 className="text-2xl">Refining Ability</h2>
</Lines>
)}
{weapon.weapon_ability_link
.sort((a, b) => a.slot_number - b.slot_number)
.filter((ability) => ability.ability_level === abilityLevel)
.slice(3, 4)
.map((ability) => (
<Ability
key={ability.ability_id}
Expand Down
59 changes: 49 additions & 10 deletions src/components/pages/weapons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ export function WeaponsTable({
)}
</div>
),
customFilterAndSearch: (term, weapon) =>
weapon.name.toLowerCase().includes(term?.toLowerCase()),
},
{
field: "weapon_stat[0].hp",
Expand Down Expand Up @@ -568,19 +570,57 @@ export function WeaponsTable({
{(weapon.weapon_ability_link?.[2]?.weapon_ability && (
<AbilityThumbnail
ability={weapon.weapon_ability_link[2].weapon_ability}
>
<span className="inline-block mt-1 text-xs text-center leading-none w-28">
{
weapon.weapon_ability_link[2].weapon_ability.name.split(
"Barrier:"
)[1]
}
</span>
</AbilityThumbnail>
/>
)) || <span className="text-beige-dark">N/A</span>}
</>
),
},
{
field: "weapon_ability_link[3].weapon_ability.name",
title: "Refining Ability",
cellStyle: {
textAlign: "center",
},
lookup: abilitiesLookup,
customFilterAndSearch: (term, weapon) => {
if (term.length === 0) return true;
return term.includes(
weapon.weapon_ability_link?.[3]?.weapon_ability.name
);
},
render: (weapon) => {
const isValued = VALUED_WEAPONS[valuedWeaponType]
.filter(
(valuedAbility) => valuedAbility.type === VALUED_TYPES.ABILITY
)
.find((valuedAbility) =>
weapon.weapon_ability_link[3].weapon_ability.name.includes(
valuedAbility.value
)
);

if (weapon.name.includes("horn")) {
console.log(
weapon.weapon_ability_link?.[3]?.weapon_ability?.name
);
}

return (
<div
className={classNames(
"relative flex flex-col justify-center items-center",
isValued ? "text-green-300" : ""
)}
>
{(weapon.weapon_ability_link[3] && (
<AbilityThumbnail
ability={weapon.weapon_ability_link[3].weapon_ability}
/>
)) || <span className="text-beige-dark">N/A</span>}
</div>
);
},
},
{
field: "weapon_skill_link[0].weapon_skill.cooldown_time",
title: "Cooldown Skill 1",
Expand Down Expand Up @@ -702,7 +742,6 @@ export function WeaponsTable({
]}
options={{
actionsColumnIndex: -1,
grouping: true,
searchFieldAlignment: "right",
filtering: true,
pageSize: 25,
Expand Down
231 changes: 122 additions & 109 deletions src/models/weapon.ts
Original file line number Diff line number Diff line change
@@ -1,119 +1,132 @@
import prisma from "@libs/prisma";
import alterWeaponToAddCostume from "@utils/alterWeaponToAddCostume";
import { env } from "env";

export async function getAllWeapons() {
const weapons = await prisma.dump.weapon.findMany({
orderBy: {
release_time: "desc",
},
where: {
evolution_order: 2,
is_ex_weapon: false,
},
distinct: "evolution_group_id",
include: {
weapon_stat: {
orderBy: {
level: "desc",
},
take: 1,
},
weapon_ability_link: {
where: {
ability_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_ability: true,
},
},
weapon_skill_link: {
where: {
skill_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_skill: true,
},
},
},
});
const weapons = await prisma.dump.weapon.findMany({
orderBy: {
release_time: "desc",
},
where: {
evolution_order: 2,
is_ex_weapon: false,
},
distinct: "evolution_group_id",
include: {
weapon_stat: {
orderBy: {
level: "desc",
},
take: 1,
},
weapon_ability_link: {
where: {
OR: [
{
slot_number: 4,
},
{
ability_level: 15,
},
],
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_ability: true,
},
},
weapon_skill_link: {
where: {
skill_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_skill: true,
},
},
},
});

const exWeapons = await prisma.dump.weapon.findMany({
orderBy: {
release_time: "desc",
},
where: {
evolution_order: {
gt: 10,
},
is_ex_weapon: true,
},
distinct: "evolution_group_id",
include: {
weapon_stat: {
orderBy: {
level: "desc",
},
take: 1,
},
weapon_ability_link: {
where: {
ability_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_ability: true,
},
},
weapon_skill_link: {
where: {
skill_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_skill: true,
},
},
},
});
const exWeapons = await prisma.dump.weapon.findMany({
orderBy: {
release_time: "desc",
},
where: {
evolution_order: {
gt: 10,
},
is_ex_weapon: true,
},
distinct: "evolution_group_id",
include: {
weapon_stat: {
orderBy: {
level: "desc",
},
take: 1,
},
weapon_ability_link: {
where: {
OR: [
{
slot_number: 4,
},
{
ability_level: 15,
},
],
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_ability: true,
},
},
weapon_skill_link: {
where: {
skill_level: 15,
},
orderBy: {
slot_number: "asc",
},
include: {
weapon_skill: true,
},
},
},
});

const allWeapons = [...weapons, ...exWeapons];
allWeapons.sort(
// @ts-expect-error date sorting.
(a, b) => new Date(b.release_time) - new Date(a.release_time)
);
const allWeapons = [...weapons, ...exWeapons];
allWeapons.sort(
// @ts-expect-error date sorting.
(a, b) => new Date(b.release_time) - new Date(a.release_time)
);

for (const weapon of allWeapons) {
await alterWeaponToAddCostume(weapon)
}
for (const weapon of allWeapons) {
await alterWeaponToAddCostume(weapon);
}

const abilitiesLookupData = await prisma.dump.weapon_ability.findMany({
orderBy: {
name: "asc",
},
select: {
name: true,
},
distinct: ["name"],
});
const abilitiesLookupData = await prisma.dump.weapon_ability.findMany({
orderBy: {
name: "asc",
},
select: {
name: true,
},
distinct: ["name"],
});

const abilitiesLookup = abilitiesLookupData.reduce((acc, current) => {
acc[current.name] = current.name;
return acc;
}, {});
const abilitiesLookup = abilitiesLookupData.reduce((acc, current) => {
acc[current.name] = current.name;
return acc;
}, {});

return {
weapons: allWeapons,
abilitiesLookup,
}
}
return {
weapons: allWeapons,
abilitiesLookup,
};
}

0 comments on commit 2695d3e

Please sign in to comment.