Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor item service #326

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/api/inventory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { Inventory, InventoryModel } from '@/models/inventory';
import { Inventory, InventoryModel } from "@/models/inventory";

function dbErr(e) {
throw new Error(`Fail in inventory: ${e}`);
}

export async function getHarksFromItems(charId: string) {
try {
return await InventoryModel.fullHarks(charId);
} catch (e) {
dbErr(e);
}
}
export async function getItems(charId: string) {
try {
return await InventoryModel.getItems(charId);
Expand All @@ -22,7 +15,7 @@ export async function getItems(charId: string) {
type HandleItemParams = {
charId: string;
itemId: string;
}
};

export async function putOnItem({ charId, itemId }: HandleItemParams) {
return InventoryModel.putOnItem(charId, itemId);
Expand All @@ -39,7 +32,7 @@ export async function removeItem({ charId, itemId }: HandleItemParams) {
type AddItemParams = {
charId: string;
itemCode: string;
}
};

export async function addItem({ charId, itemCode }: AddItemParams) {
return InventoryModel.addItem(charId, itemCode);
Expand Down
6 changes: 3 additions & 3 deletions src/arena/BattleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ function getTargetKeyboard(charId: string, game: Game, action: string) {
return game.players.alivePlayers
.filter((target) => {
if (orderType === 'enemy') {
return !game.isPlayersAlly(player, target);
return !player.isAlly(target);
}
if (orderType === 'team') {
return game.isPlayersAlly(player, target);
return player.isAlly(target);
}
if (orderType === 'teamExceptSelf') {
return game.isPlayersAlly(player, target) && player.id !== target.id;
return player.isAlly(target, false);
}

return !orders.some((order) => target.id === order.target && action === order.action);
Expand Down
Loading
Loading