Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Character} from './Character';
import {Skill} from './Skill';
import {list, object, serializable} from 'serializr';
import {cmp, contains, moveItem} from '../../lib/Helpers';
import {randomizeItem} from '../../lib/Helpers';
import {CharacterStatus} from './CharacterStatus';
type AllyOrEnemy = Character;
export class Battler<
TAlly extends AllyOrEnemy = AllyOrEnemy,
TEnemy extends AllyOrEnemy = AllyOrEnemy
> {
@serializable @observable turn: number = 0;
@serializable @observable turnActorIndex: number = 0;
@serializable(list(object(Character))) @observable enemies: TEnemy[] = [];
@serializable(list(object(Character))) @observable deceasedEnemies: TEnemy[] = [];
// No need to serialize since it's automated by quest behavior
@observable public allies: TAlly[] = null;
@observable private enemySource: TEnemy[] = null;
@observable public inBattle: boolean = false;
@computed get turnActorOrder (): AllyOrEnemy[] {
return [...this.allies, ...this.enemies]
.sort((a, b) => cmp(a.stats.speed, b.stats.speed));
}
@computed get turnActor () {
return this.turnActorOrder[this.turnActorIndex];
}
@serializable isEscapable?: boolean = true;
@serializable(object(QuestMap))
map: QuestMap;
@serializable(object(QuestObjective))
objective: QuestObjective = new QuestObjective();
@serializable(list(object(Item)))
rewards: Item[] = [];
@serializable(list(object(Hero)))
@observable
party: Hero[] = [];
@serializable(list(object(Hero)))
@observable
deceased: Hero[] = [];
// Data that changes throughout a quest
@serializable @observable status: QuestStatus = QuestStatus.Idle;
@serializable @observable light: number = 100;
@serializable(list(object(Item))) @observable items: Item[] = [];
@serializable @observable previousRoomId: MapLocationId = null;
@serializable @observable currentRoomId: MapLocationId = null;
@computed get lightPercentage () {
return cap(this.light / 100, 0, 1);
}
@computed get previousRoom () {
return this.map.rooms.find((room) => room.id === this.previousRoomId);
hasMany: function hasMany(model) {
return list(object(model));
},
belongsTo: function belongsTo(model) {
import {identifier, list, object, serializable} from 'serializr';
import {v4 as uuid} from 'uuid';
import {Item} from './Item';
import {TurnStats} from './Stats';
import {observable} from 'mobx';
export type CurioId = string;
export class Curio {
@serializable(identifier()) id: CurioId = uuid();
@serializable name: string = '';
@serializable(object(TurnStats)) buff: TurnStats = null;
@serializable(list(object(Item))) @observable items: Item[] = [];
@serializable @observable hasBeenInteractedWith: boolean = false;
@serializable replaceQuirk: boolean;
}
@serializable(date()) @observable dateOfLastSave: Date = new Date();
@serializable @observable selectedQuestId?: QuestId;
@serializable @observable gold: number = 0;
@observable debt: number = 0;
@computed get goldAfterDebt () { return this.gold - this.debt; }
@serializable(object(EstateEvent))
@observable
estateEvent = nullEstateEvent;
@serializable(list(object(Hero)))
@observable
coach: Hero[] = [];
@serializable(list(object(Hero)))
@observable
roster: Hero[] = [];
@serializable(list(object(Hero)))
@observable
graveyard: Hero[] = [];
@serializable(list(object(Quest)))
@observable
quests: Quest[] = [];
@serializable(list(object(Item)))
@observable
items: Item[] = [];
@serializable(list(object(Dungeon)))
function list(s) {
return serializr_1.list(object(s));
}
function map(s) {
var Action = createSimpleSchema({
type: primitive(),
payload: custom(
(value) => value === undefined ? SKIP : toJS(value),
(value) => value
),
});
var Milestone = createSimpleSchema({
chapterId: primitive(),
index: primitive(),
});
class TutorialState {
@serializable @observable currentChapterId;
@serializable(list(object(Action))) @observable actions = [];
@serializable(list(object(Milestone))) @observable milestones = [];
static create({ chapters }) {
const state = new TutorialState();
state.currentChapterId = chapters[0].id;
return state;
}
}
export default TutorialState;
);
}
@computed get flaws () {
return Object.freeze(
this.quirks.filter((q) => !q.isDisease && q.isNegative)
);
}
@computed get diseases () {
return Object.freeze(
this.quirks.filter((q) => q.isDisease)
);
}
@serializable(list(object(Item)))
@observable
items: Item[] = [];
@serializable @observable hunger: number = 0;
@serializable @observable classInfoStatsScale = 1;
@serializable @observable buffSourceName: string;
@serializable(object(TurnStats))
@observable
buff: TurnStats;
@serializable(map(object(TurnStats)))
@observable
dots = new Map();
function list(s: any) {
return _list(object(s))
}