Skip to content

Commit 0fab271

Browse files
committed
Fix end_turn reaction activable bug
1 parent 5e7afec commit 0fab271

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/repository/repository.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ export abstract class Repository<T> {
2929
* @param id - The unique identifier of the item to invalidate in the cache.
3030
*/
3131
protected async invalidateCache(id: string) {
32-
if ((process.env.USE_REDIS ?? 'true') == 'true') {
32+
if ((process.env.USE_REDIS ?? 'true') == 'true')
3333
await redis!.del(`${this.modelName}:${id}`);
34-
}
3534
}
3635

3736
/**
@@ -41,9 +40,9 @@ export abstract class Repository<T> {
4140
* @returns The item if found in the cache; otherwise, null.
4241
*/
4342
async getById(id: string, noCache: boolean = false): Promise<T | null> {
44-
if ((process.env.USE_REDIS ?? 'true') != 'true' || noCache) {
43+
if ((process.env.USE_REDIS ?? 'true') != 'true' || noCache)
4544
return null;
46-
}
45+
4746
// Check if the object is in cache
4847
const item = await redis!.get(`${this.modelName}:${id}`);
4948
if (item) {

src/repository/repository_factory.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ export class RepositoryFactory {
2323
* Creates a repository for `Session` entities with Sequelize.
2424
* @returns A `SequelizeRepository` instance for `Session`.
2525
*/
26-
sessionRepository = (): Repository<Session> => new SequelizeRepository(Session, [Monster, HistoryMessage, EntityTurn], 1);
26+
sessionRepository = (): Repository<Session> => new SequelizeRepository(Session, [Monster, HistoryMessage, EntityTurn], 30);
2727

2828
/**
2929
* Creates a repository for `Monster` entities with Sequelize.
3030
* @returns A `SequelizeRepository` instance for `Monster`.
3131
*/
32-
monsterRepository = (): Repository<Monster> => new SequelizeRepository(Monster, [MonsterSkill, Session], 5);
32+
monsterRepository = (): Repository<Monster> => new SequelizeRepository(Monster, [MonsterSkill, Session], 30);
3333

3434
/**
3535
* Creates a repository for `EntityTurn` entities with Sequelize.
3636
* @returns A `SequelizeRepository` instance for `EntityTurn`.
3737
*/
38-
entityTurnRepository = (): Repository<EntityTurn> => new SequelizeRepository(EntityTurn, [Session], 10);
38+
entityTurnRepository = (): Repository<EntityTurn> => new SequelizeRepository(EntityTurn, [Session], 30);
3939

4040
/**
4141
* Creates a repository for `MonsterSkill` entities with Sequelize.
4242
* @returns A `SequelizeRepository` instance for `MonsterSkill`.
4343
*/
44-
monsterSkillRepository = (): Repository<MonsterSkill> => new SequelizeRepository(MonsterSkill, [Monster], 3);
44+
monsterSkillRepository = (): Repository<MonsterSkill> => new SequelizeRepository(MonsterSkill, [Monster], 30);
4545

4646
/**
4747
* Creates a repository for `HistoryMessage` entities with Sequelize.
@@ -59,13 +59,13 @@ export class RepositoryFactory {
5959
* Creates a repository for `Character` entities with Firestore.
6060
* @returns A `FirestoreRepository` instance for `Character`.
6161
*/
62-
characterRepository = (): Repository<Character> => new FirestoreRepository('characters', Character.fromJSON, 15);
62+
characterRepository = (): Repository<Character> => new FirestoreRepository('characters', Character.fromJSON, 60);
6363

6464
/**
6565
* Creates a repository for `NPC` entities with Firestore.
6666
* @returns A `FirestoreRepository` instance for `NPC`.
6767
*/
68-
npcRepository = (): Repository<NPC> => new FirestoreRepository('npcs', NPC.fromJSON, 15);
68+
npcRepository = (): Repository<NPC> => new FirestoreRepository('npcs', NPC.fromJSON, 60);
6969

7070
/**
7171
* Creates a repository for `Enchantment` entities with Firestore.

src/service/turn_service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export async function postponeTurnService(req: IAugmentedRequest, res: Response)
2828

2929
export async function endTurnService(req: IAugmentedRequest, res: Response) {
3030

31+
// Set the reaction of the new playing entity to activatable
32+
updateEntity(req.session!, req.session!.sortedTurns[0].entityUID, { isReactionActivable: true });
33+
3134
// Push the current entity to the end of the turns list
3235
req.session!.sortedTurns[0].turnIndex = req.session!.entityTurns.length;
3336
for (const turn of req.session!.sortedTurns)
3437
turn.turnIndex -= 1;
3538

36-
// Set the reaction of the new playing entity to activatable
37-
updateEntity(req.session!, req.session!.sortedTurns[0].entityUID, { isReactionActivable: true });
38-
3939
// Update session in the database
4040
req.session?.entityTurns.forEach(it => entityTurnRepository.update(it.id, { turnIndex: it.turnIndex }));
4141
return res.status(200).json({ message: `Turn of entity ${req.entity?._name} has ended successfully!` });

0 commit comments

Comments
 (0)