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

feat: use product in battle #90

Merged
merged 14 commits into from
Oct 16, 2024
Merged
1 change: 0 additions & 1 deletion src/achievements/achievements.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class AchievementsService {
HttpStatus.BAD_REQUEST,
);
}
console.log(user);
if (achievement.checkRequirement(user)) {
if (user.achievements[achievementId]) return user;
user.achievements[achievementId] = true;
Expand Down
71 changes: 71 additions & 0 deletions src/lab/craftable_item.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { EProduct } from "../market/market.const";

export enum ECRAFTABLE_ITEM {
BOOSTER_ATTACK_1 = "BOOSTER_ATTACK_1",
BOOSTER_DEFENSE_1 = "BOOSTER_DEFENSE_1",
HEALTH_POTION_SMALL = "HEALTH_POTION_SMALL",
}

export type PvpEffect = {
healthPoints?: number;
protection?: number;
damage?: number;
criticalChance?: number;
evasion?: number;
accuracy?: number;
};

export type CraftableItem = {
itemId: ECRAFTABLE_ITEM;
requirements: {
[key in EProduct]?: number;
};
pvpEffect: PvpEffect;
duration: number;
};

export const CRAFTABLE_ITEMS: Record<ECRAFTABLE_ITEM, CraftableItem> = {
// Total ~361$
// User miss an attack of ~15 by using the item but gain 10 attack in 3 round
// 4 rounds without potion 4*15 = 60 damage
// 4 rounds with potion 3*25 = 75 damage
[ECRAFTABLE_ITEM.BOOSTER_ATTACK_1]: {
itemId: ECRAFTABLE_ITEM.BOOSTER_ATTACK_1,
requirements: {
[EProduct.POWDER]: 3,
[EProduct.PILL]: 1,
},
pvpEffect: {
damage: 10,
criticalChance: 3,
},
duration: 3,
},
// Total ~325$
// user will absorb 21 damage so 1.4 attack that's why it's a bit more expensive than the health potion
[ECRAFTABLE_ITEM.BOOSTER_DEFENSE_1]: {
itemId: ECRAFTABLE_ITEM.BOOSTER_DEFENSE_1,
requirements: {
[EProduct.HERB]: 10,
[EProduct.MUSHROOM]: 5,
},
pvpEffect: {
protection: 7,
evasion: 3,
},
duration: 3,
},
// Total ~276$
// Based on normal attack of 15 user will actually gain 10 hp
[ECRAFTABLE_ITEM.HEALTH_POTION_SMALL]: {
itemId: ECRAFTABLE_ITEM.HEALTH_POTION_SMALL,
requirements: {
[EProduct.HERB]: 10,
[EProduct.ACID]: 3,
},
pvpEffect: {
healthPoints: 25,
},
duration: 1,
},
};
11 changes: 11 additions & 0 deletions src/lab/dto/craft-item.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsEnum, IsNumber, Min } from 'class-validator';
import { ECRAFTABLE_ITEM } from '../craftable_item.const';

export class CraftItemDto {
@IsEnum(ECRAFTABLE_ITEM)
itemId: ECRAFTABLE_ITEM;

@IsNumber()
@Min(1)
quantity: number;
}
9 changes: 9 additions & 0 deletions src/lab/lab.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Auth } from '../decorators/auth.decorator';
import { AuthTokenData } from '../config/types';
import { GetAuthToken } from '../decorators/get-auth-token.decorator';
import { BuyLabDto } from './dto/buy-lab.dto';
import { CraftItemDto } from './dto/craft-item.dto';

@Auth()
@Controller('labs')
Expand Down Expand Up @@ -48,4 +49,12 @@ export class LabController {
) {
return this.labService.collectLabProduction(user.id, plotId);
}

@Post('/craft-item')
craftItem(
@GetAuthToken() user: AuthTokenData,
@Body() body: CraftItemDto,
) {
return this.labService.craftItem(user.id, body.itemId, body.quantity);
}
}
8 changes: 4 additions & 4 deletions src/lab/lab.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { LabService } from './lab.service';
import { LabController } from './lab.controller';
import { UserModule } from '../user/user.module';
import { Module } from "@nestjs/common";
import { LabService } from "./lab.service";
import { LabController } from "./lab.controller";
import { UserModule } from "../user/user.module";

@Module({
imports: [UserModule],
Expand Down
Loading