Skip to content

Commit

Permalink
address #355, fix sync error with scenario finish, small fixes on obj…
Browse files Browse the repository at this point in the history
…ectives
  • Loading branch information
Lurkars committed Aug 7, 2023
1 parent 20ec7ea commit 9bc59ad
Show file tree
Hide file tree
Showing 39 changed files with 408 additions and 243 deletions.
5 changes: 1 addition & 4 deletions data/fh/character/astral.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"stats": [
{
"level": 1,
"health": 8,
"permanentConditions": [
"disarm"
]
"health": 8
},
{
"level": 2,
Expand Down
5 changes: 1 addition & 4 deletions data/fh/character/fist.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"stats": [
{
"level": 1,
"health": 10,
"permanentConditions": [
"regenerate"
]
"health": 10
},
{
"level": 2,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloomhavensecretariat",
"version": "0.71.6",
"version": "0.72.0",
"license": "AGPL3",
"description": "Gloomhaven Secretariat is a Gloomhaven Companion app.",
"homepage": "https://gloomhaven-secretariat.de",
Expand Down
2 changes: 1 addition & 1 deletion scripts/sort/sorter/character-stat.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sortObjectKeys } from './sort-helper.mjs';

export const sortCharacterStat = function (characterStat) {
return sortObjectKeys(characterStat, 'level', 'health', 'permanentConditions');
return sortObjectKeys(characterStat, 'level', 'health');
}
163 changes: 86 additions & 77 deletions src/app/game/businesslogic/EntityManager.ts

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/app/game/businesslogic/RoundManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export class RoundManager {
gameManager.entityManager.entitiesAll(figure, false).forEach((entity) => {
if (settingsManager.settings.applyConditions) {
const killReset = (entity instanceof MonsterEntity || entity instanceof Summon) && entity.dead;
gameManager.entityManager.unapplyConditionsTurn(entity);
gameManager.entityManager.unapplyConditionsAfter(entity);
gameManager.entityManager.unapplyConditionsTurn(entity, figure);
gameManager.entityManager.unapplyConditionsAfter(entity, figure);
if (killReset && !entity.dead) {
const identifier = gameManager.additionalIdentifier(figure, entity);
let counter = gameManager.entityCounter(identifier);
Expand Down Expand Up @@ -265,15 +265,15 @@ export class RoundManager {
gameManager.entityManager.expireConditions(prevSummon);
}
if (settingsManager.settings.applyConditions && (!activeSummon || index > 0)) {
gameManager.entityManager.applyConditionsTurn(prevSummon);
gameManager.entityManager.applyConditionsAfter(prevSummon);
gameManager.entityManager.applyConditionsTurn(prevSummon, figure);
gameManager.entityManager.applyConditionsAfter(prevSummon, figure);
}
})

if (nextSummon) {
nextSummon.active = true;
if (settingsManager.settings.applyConditions) {
gameManager.entityManager.applyConditionsTurn(nextSummon);
gameManager.entityManager.applyConditionsTurn(nextSummon, figure);
}
if (nextSummon.dead) {
this.turn(figure);
Expand Down Expand Up @@ -301,10 +301,10 @@ export class RoundManager {
if (settingsManager.settings.applyConditions) {
if (!(figure instanceof Character) || skipSummons) {
gameManager.entityManager.entitiesAll(figure).forEach((entity) => {
gameManager.entityManager.applyConditionsTurn(entity);
gameManager.entityManager.applyConditionsTurn(entity, figure);
})
} else if (!skipSummons && !figure.summons.some((summon) => summon.active)) {
gameManager.entityManager.applyConditionsTurn(figure);
gameManager.entityManager.applyConditionsTurn(figure, figure);
}
}

Expand All @@ -318,7 +318,7 @@ export class RoundManager {

figure.health += heal;
gameManager.entityManager.addCondition(figure, new Condition(ConditionName.heal, heal), figure.active || false, figure.off || false);
gameManager.entityManager.applyCondition(figure, ConditionName.heal, true);
gameManager.entityManager.applyCondition(figure, figure, ConditionName.heal, true);
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ export class RoundManager {
}

if (settingsManager.settings.applyConditions) {
gameManager.entityManager.applyConditionsAfter(entity);
gameManager.entityManager.applyConditionsAfter(entity, figure);
}
})
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/game/model/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CharacterData } from "./data/CharacterData";
import { GameSummonModel, Summon } from "./Summon";
import { gameManager } from "../businesslogic/GameManager";
import { FigureError, FigureErrorType } from "./data/FigureError";
import { EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { ConditionName, EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { CharacterProgress } from "./CharacterProgress";
import { AttackModifierDeck, GameAttackModifierDeckModel } from "./data/AttackModifier";
import { Identifier } from "./data/Identifier";
Expand Down Expand Up @@ -48,6 +48,7 @@ export class Character extends CharacterData implements Entity, Figure {
health: number;
maxHealth: number;
entityConditions: EntityCondition[] = [];
immunities: ConditionName[] = [];
number: number = 0;
markers: string[] = [];
tags: string[] = [];
Expand Down Expand Up @@ -97,7 +98,7 @@ export class Character extends CharacterData implements Entity, Figure {
}

toModel(): GameCharacterModel {
return new GameCharacterModel(this.name, this.edition, this.marker, this.title, this.initiative, this.experience, this.loot, this.lootCards || [], this.treasures && this.treasures.map((treasure) => '' + treasure) || [], this.exhausted, this.level, this.off, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.markers, this.tags || [], this.identity, this.summons.map((summon) => summon.toModel()), this.progress, this.initiativeVisible, this.attackModifierDeckVisible, this.lootCardsVisible, this.number, this.attackModifierDeck.toModel(), this.donations, this.token, this.tokenValues, this.absent, this.longRest, this.battleGoals, this.battleGoal);
return new GameCharacterModel(this.name, this.edition, this.marker, this.title, this.initiative, this.experience, this.loot, this.lootCards || [], this.treasures && this.treasures.map((treasure) => '' + treasure) || [], this.exhausted, this.level, this.off, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.immunities, this.markers, this.tags || [], this.identity, this.summons.map((summon) => summon.toModel()), this.progress, this.initiativeVisible, this.attackModifierDeckVisible, this.lootCardsVisible, this.number, this.attackModifierDeck.toModel(), this.donations, this.token, this.tokenValues, this.absent, this.longRest, this.battleGoals, this.battleGoal);
}

fromModel(model: GameCharacterModel) {
Expand Down Expand Up @@ -147,6 +148,7 @@ export class Character extends CharacterData implements Entity, Figure {
return condition;
});
}
this.immunities = model.immunities || [];
this.markers = model.markers || this.markers;
this.tags = model.tags || this.tags;
this.identity = model.identity || 0;
Expand Down Expand Up @@ -243,6 +245,7 @@ export class GameCharacterModel {
health: number;
maxHealth: number;
entityConditions: GameEntityConditionModel[];
immunities: ConditionName[] = [];
markers: string[];
tags: string[];
identity: number;
Expand Down Expand Up @@ -277,6 +280,7 @@ export class GameCharacterModel {
health: number,
maxHealth: number,
entityConditions: GameEntityConditionModel[],
immunities: ConditionName[],
markers: string[],
tags: string[],
identity: number,
Expand Down Expand Up @@ -310,6 +314,7 @@ export class GameCharacterModel {
this.health = health;
this.maxHealth = maxHealth;
this.entityConditions = JSON.parse(JSON.stringify(entityConditions));
this.immunities = JSON.parse(JSON.stringify(immunities));
this.markers = JSON.parse(JSON.stringify(markers));
this.tags = JSON.parse(JSON.stringify(tags));
this.identity = identity;
Expand Down
3 changes: 2 additions & 1 deletion src/app/game/model/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gameManager } from "../businesslogic/GameManager";
import { EntityCondition } from "./data/Condition";
import { ConditionName, EntityCondition } from "./data/Condition";
import { GameState } from "./Game";
import { AdditionalIdentifier } from "./data/Identifier";

Expand All @@ -10,6 +10,7 @@ export interface Entity {
level: number;
maxHealth: number | string;
entityConditions: EntityCondition[];
immunities: ConditionName[];
number: number;
markers: string[];
tags: string[];
Expand Down
9 changes: 7 additions & 2 deletions src/app/game/model/MonsterEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { ConditionName, EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { Entity, EntityValueFunction } from "./Entity";
import { FigureError, FigureErrorType } from "./data/FigureError";
import { Monster } from "./Monster";
Expand All @@ -22,6 +22,7 @@ export class MonsterEntity implements Entity {
health: number;
maxHealth: number;
entityConditions: EntityCondition[] = [];
immunities: ConditionName[] = [];
markers: string[] = [];
tags: string[] = [];

Expand Down Expand Up @@ -53,7 +54,7 @@ export class MonsterEntity implements Entity {
}

toModel(): GameMonsterEntityModel {
return new GameMonsterEntityModel(this.number, this.marker, this.type, this.dead, this.summon, this.active, this.off, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.markers, this.tags || []);
return new GameMonsterEntityModel(this.number, this.marker, this.type, this.dead, this.summon, this.active, this.off, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.immunities, this.markers, this.tags || []);
}

fromModel(model: GameMonsterEntityModel) {
Expand All @@ -72,6 +73,7 @@ export class MonsterEntity implements Entity {
return condition;
});
}
this.immunities = model.immunities || [];
this.markers = model.markers || [];
this.tags = model.tags || [];
}
Expand All @@ -90,6 +92,7 @@ export class GameMonsterEntityModel {
health: number;
maxHealth: number;
entityConditions: GameEntityConditionModel[];
immunities: ConditionName[];
markers: string[];
tags: string[];

Expand All @@ -103,6 +106,7 @@ export class GameMonsterEntityModel {
health: number,
maxHealth: number,
entityConditions: GameEntityConditionModel[],
immunities: ConditionName[],
markers: string[],
tags: string[]) {
this.number = number;
Expand All @@ -115,6 +119,7 @@ export class GameMonsterEntityModel {
this.health = health;
this.maxHealth = maxHealth;
this.entityConditions = JSON.parse(JSON.stringify(entityConditions));
this.immunities = JSON.parse(JSON.stringify(immunities));
this.markers = JSON.parse(JSON.stringify(markers));
this.tags = JSON.parse(JSON.stringify(tags));
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/game/model/Objective.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Figure } from "./Figure";
import { Entity } from "./Entity";
import { EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { ConditionName, EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { ScenarioObjectiveIdentifier } from "./data/ObjectiveData";
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -25,6 +25,7 @@ export class Objective implements Entity, Figure {
health: number = 7;
maxHealth: number | string = 7;
entityConditions: EntityCondition[] = [];
immunities: ConditionName[] = [];
markers: string[] = [];
tags: string[] = [];
number: number;
Expand All @@ -45,7 +46,7 @@ export class Objective implements Entity, Figure {
}

toModel(): GameObjectiveModel {
return new GameObjectiveModel(this.uuid || uuidv4(), this.id, this.marker, this.title, this.name, this.escort, this.level, this.exhausted, this.off, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.markers, this.tags || [], this.initiative, this.objectiveId);
return new GameObjectiveModel(this.uuid || uuidv4(), this.id, this.marker, this.title, this.name, this.escort, this.level, this.exhausted, this.off, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.immunities, this.markers, this.tags || [], this.initiative, this.objectiveId);
}

fromModel(model: GameObjectiveModel) {
Expand All @@ -70,6 +71,7 @@ export class Objective implements Entity, Figure {
return condition;
});
}
this.immunities = model.immunities || [];
this.markers = model.markers || this.markers;
this.tags = model.tags || this.tags;
this.initiative = model.initiative
Expand All @@ -93,6 +95,7 @@ export class GameObjectiveModel {
health: number;
maxHealth: number | string;
entityConditions: GameEntityConditionModel[];
immunities: ConditionName[];
markers: string[];
tags: string[];
initiative: number;
Expand All @@ -112,6 +115,7 @@ export class GameObjectiveModel {
health: number,
maxHealth: number | string,
entityConditions: GameEntityConditionModel[],
immunities: ConditionName[],
markers: string[],
tags: string[],
initiative: number,
Expand All @@ -129,6 +133,7 @@ export class GameObjectiveModel {
this.health = health;
this.maxHealth = maxHealth;
this.entityConditions = JSON.parse(JSON.stringify(entityConditions));
this.immunities = JSON.parse(JSON.stringify(immunities));
this.markers = JSON.parse(JSON.stringify(markers));
this.tags = JSON.parse(JSON.stringify(tags));
this.initiative = initiative;
Expand Down
9 changes: 7 additions & 2 deletions src/app/game/model/ObjectiveEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { ConditionName, EntityCondition, GameEntityConditionModel } from "./data/Condition";
import { Entity, EntityValueFunction } from "./Entity";
import { ObjectiveContainer } from "./ObjectiveContainer";

Expand All @@ -19,6 +19,7 @@ export class ObjectiveEntity implements Entity {
health: number;
maxHealth: number;
entityConditions: EntityCondition[] = [];
immunities: ConditionName[] = [];
number: number;
markers: string[] = [];
tags: string[] = [];
Expand All @@ -35,7 +36,7 @@ export class ObjectiveEntity implements Entity {
}

toModel(): GameObjectiveEntityModel {
return new GameObjectiveEntityModel(this.uuid, this.number, this.marker, this.dead, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.markers, this.tags || []);
return new GameObjectiveEntityModel(this.uuid, this.number, this.marker, this.dead, this.active, this.health, this.maxHealth, this.entityConditions.map((condition) => condition.toModel()), this.immunities, this.markers, this.tags || []);
}

fromModel(model: GameObjectiveEntityModel) {
Expand All @@ -52,6 +53,7 @@ export class ObjectiveEntity implements Entity {
return condition;
});
}
this.immunities = model.immunities || [];
this.markers = model.markers || [];
this.tags = model.tags || [];
}
Expand All @@ -68,6 +70,7 @@ export class GameObjectiveEntityModel {
health: number;
maxHealth: number;
entityConditions: GameEntityConditionModel[];
immunities: ConditionName[];
markers: string[];
tags: string[];

Expand All @@ -80,6 +83,7 @@ export class GameObjectiveEntityModel {
health: number,
maxHealth: number,
entityConditions: GameEntityConditionModel[],
immunities: ConditionName[],
markers: string[],
tags: string[]) {
this.uuid = uuid;
Expand All @@ -90,6 +94,7 @@ export class GameObjectiveEntityModel {
this.health = health;
this.maxHealth = maxHealth;
this.entityConditions = JSON.parse(JSON.stringify(entityConditions));
this.immunities = JSON.parse(JSON.stringify(immunities));
this.markers = JSON.parse(JSON.stringify(markers));
this.tags = JSON.parse(JSON.stringify(tags));
}
Expand Down
Loading

0 comments on commit 9bc59ad

Please sign in to comment.