From b8bed2377f894d1c424e809fe0a1894c38851c78 Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 6 Sep 2023 13:16:29 -0400 Subject: [PATCH] feat: monster variants Introduced Elder, Skittish, and Brute monster variants. These adjust the stats/rewards of the monsters further. --- public/assets/css/game.css | 14 +++++++++- src/server/monster.ts | 51 ++++++++++++++++++++++++----------- src/server/views/fight.ts | 2 +- src/shared/constants.ts | 2 ++ src/shared/monsters.ts | 55 +++++++++++++++++++++++++++++++++++++- 5 files changed, 106 insertions(+), 18 deletions(-) diff --git a/public/assets/css/game.css b/public/assets/css/game.css index da277db..898b78a 100644 --- a/public/assets/css/game.css +++ b/public/assets/css/game.css @@ -441,9 +441,21 @@ nav.filter-result.active { width: 70%; margin: 0 auto 1rem; } -#defender-name { +.monster-identifier { text-align: left; } +#defender-name { + font-weight: bold; +} +.Elder #defender-name { + color: #2b2b2b; +} +.Skittish #defender-name { + color: #8700ff; +} +.Brute #defender-name { + color: #a91313; +} #fight-results { margin-top: 1rem; } diff --git a/src/server/monster.ts b/src/server/monster.ts index 54a49db..a0b7aac 100644 --- a/src/server/monster.ts +++ b/src/server/monster.ts @@ -1,8 +1,9 @@ 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(); @@ -67,23 +68,43 @@ export async function createFight(playerId: string, monster: Monster, fightTrigg 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 = { 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('*'); + } + + const res = await db('fight').insert(monsterData) + .returning('*'); return res.pop(); } diff --git a/src/server/views/fight.ts b/src/server/views/fight.ts index b89f32e..c66cdbd 100644 --- a/src/server/views/fight.ts +++ b/src/server/views/fight.ts @@ -79,7 +79,7 @@ export function renderFight(monster: Fight, results: string = '', displayFightAc
-
${monster.name}, level ${monster.level}
+
${monster.name}, level ${monster.level}
${hpPercent}% - ${monster.hp} / ${monster.maxHp}
diff --git a/src/shared/constants.ts b/src/shared/constants.ts index fae88bf..c95c80d 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -1,3 +1,5 @@ export const FIGHT_ATTACK_DELAY = 1500; export const STEP_DELAY = 2000; export const ALERT_DISPLAY_LENGTH = 3000; +// this is displayed as a percentage out of 100 +export const CHANCE_TO_FIGHT_SPECIAL = 100; diff --git a/src/shared/monsters.ts b/src/shared/monsters.ts index f5147ff..c7f8700 100644 --- a/src/shared/monsters.ts +++ b/src/shared/monsters.ts @@ -27,9 +27,10 @@ export type MonsterForList = { export type FightTrigger = 'explore' | 'travel'; -export type Fight = Omit & { +export type Fight = Omit & { id: string; player_id: string; + variant: string; level: number; ref_id: number; fight_trigger: FightTrigger; @@ -49,3 +50,55 @@ export type MonsterForFight = { 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 + } +]; -- 2.25.1