import { db } from './lib/db';
-import { Fight, Monster, MonsterWithFaction, MonsterForList, FightTrigger } from '../shared/monsters';
+import { Fight, Monster, MonsterWithFaction, MonsterForList, FightTrigger, MonsterVariant, MonsterVariants } from '../shared/monsters';
import { TimePeriod, TimeManager } from '../shared/time';
-import { LocationWithCity } from 'shared/map';
-import { max, random } from 'lodash';
+import { LocationWithCity } from '../shared/map';
+import { random, sample } from 'lodash';
+import { CHANCE_TO_FIGHT_SPECIAL } from '../shared/constants';
const time = new TimeManager();
const chosenLevel = random(monster.minLevel, monster.maxLevel);
// 30% boost per level difference
const modifier = Math.pow(Math.E, (chosenLevel - monster.minLevel)/monster.maxLevel);
+ let variant: MonsterVariant = {
+ name: '',
+ display: '{{name}}',
+ strength: 1,
+ constitution: 1,
+ dexterity: 1,
+ intelligence: 1,
+ exp: 1,
+ gold: 1,
+ maxHp: 1,
+ defence: 1
+ };
+
+ if(monster.maxLevel >= 5 && random(0,100) <= CHANCE_TO_FIGHT_SPECIAL) {
+ variant = sample(MonsterVariants);
+ }
- const res = await db('fight').insert({
+ const monsterData: Omit<Fight, 'id'> = {
player_id: playerId,
- name: monster.name,
- strength: Math.floor(monster.strength * modifier),
- constitution: Math.floor(monster.constitution * modifier),
- dexterity: Math.floor(monster.dexterity * modifier),
- intelligence: Math.floor(monster.intelligence * modifier),
- exp: Math.floor(monster.exp * modifier),
+ variant: variant.name,
+ name: variant.display.replace("{{name}}", monster.name),
+ strength: Math.floor(monster.strength * modifier * variant.strength),
+ constitution: Math.floor(monster.constitution * modifier * variant.constitution),
+ dexterity: Math.floor(monster.dexterity * modifier * variant.dexterity),
+ intelligence: Math.floor(monster.intelligence * modifier * variant.intelligence),
+ exp: Math.floor(monster.exp * modifier * variant.exp),
level: chosenLevel,
- gold: Math.floor(monster.gold * modifier),
- hp: Math.floor(monster.hp * modifier),
- defence: Math.floor(monster.defence * modifier),
- maxHp: Math.floor(monster.maxHp * modifier),
+ gold: Math.floor(monster.gold * modifier * variant.exp),
+ hp: Math.floor(monster.hp * modifier * variant.maxHp),
+ defence: Math.floor(monster.defence * modifier * variant.defence),
+ maxHp: Math.floor(monster.maxHp * modifier * variant.maxHp),
ref_id: monster.id,
fight_trigger: fightTrigger
- }).returning<Fight[]>('*');
+ }
+
+ const res = await db('fight').insert(monsterData)
+ .returning<Fight[]>('*');
return res.pop();
}
export type FightTrigger = 'explore' | 'travel';
-export type Fight = Omit<Monster, 'id' | 'faction_id' | 'location_id' | 'minLevel' | 'maxLevel'> & {
+export type Fight = Omit<Monster, 'id' | 'faction_id' | 'location_id' | 'minLevel' | 'maxLevel' | 'time_period'> & {
id: string;
player_id: string;
+ variant: string;
level: number;
ref_id: number;
fight_trigger: FightTrigger;
maxLevel: number;
fight_trigger: FightTrigger;
}
+
+export type MonsterVariant = {
+ name: string;
+ display: string;
+ strength: number;
+ constitution: number;
+ dexterity: number;
+ intelligence: number;
+ exp: number;
+ gold: number;
+ maxHp: number;
+ defence: number;
+};
+
+export const MonsterVariants: MonsterVariant[] = [
+ {
+ name: 'Brute',
+ display: '{{name}} Brute',
+ strength: 1,
+ constitution: 1,
+ dexterity: 0.6,
+ intelligence: 0.2,
+ exp: 4,
+ gold: 3,
+ maxHp: 2,
+ defence: 3
+ },
+ {
+ name: 'Elder',
+ display: 'Elder {{name}}',
+ strength: 0.8,
+ constitution: 1.2,
+ dexterity: 0.6,
+ intelligence: 1.6,
+ exp: 2,
+ gold: 1,
+ maxHp: 1,
+ defence: 1
+ },
+ {
+ name: 'Skittish',
+ display: 'Skittish {{name}}',
+ strength: 0.8,
+ constitution: 1.2,
+ dexterity: 0.6,
+ intelligence: 1.6,
+ exp: 1,
+ gold: 1.2,
+ maxHp: 1,
+ defence: 0.8
+ }
+];