From: xangelo Date: Tue, 5 Sep 2023 18:12:51 +0000 (-0400) Subject: fix: min/max level definitions for monsters X-Git-Tag: v0.3.3~4 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=bedec85a722b974beedd92ff86f07494048b11a5;p=risinglegends.git fix: min/max level definitions for monsters There was some confusion over types and whether or not we needed to included faction data with monsters (We don't). This should sort out that mess and give us a clearer definition for monsters. --- diff --git a/src/server/api.ts b/src/server/api.ts index 355bd04..7428e79 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -166,24 +166,29 @@ app.post('/chat', authEndpoint, async (req: Request, res: Response) => { let message: Message; if(msg.startsWith('/server lmnop')) { - if(msg === '/server lmnop refresh-monsters') { - await createMonsters(); - message = broadcastMessage('server', 'Monster refresh!'); - } - else if(msg === '/server lmnop refresh-cities') { - await createAllCitiesAndLocations(); - message = broadcastMessage('server', 'Cities, Locations, and Paths refreshed!'); - } - else if(msg === '/server lmnop refresh-shops') { - await createShopItems(); - await createShopEquipment(); - message = broadcastMessage('server', 'Refresh shop items'); - } - else { - const str = msg.split('/server lmnop ')[1]; - if(str) { - message = broadcastMessage('server', str); + try { + if(msg === '/server lmnop refresh-monsters') { + await createMonsters(); + message = broadcastMessage('server', 'Monster refresh!'); + } + else if(msg === '/server lmnop refresh-cities') { + await createAllCitiesAndLocations(); + message = broadcastMessage('server', 'Cities, Locations, and Paths refreshed!'); + } + else if(msg === '/server lmnop refresh-shops') { + await createShopItems(); + await createShopEquipment(); + message = broadcastMessage('server', 'Refresh shop items'); } + else { + const str = msg.split('/server lmnop ')[1]; + if(str) { + message = broadcastMessage('server', str); + } + } + } + catch(e) { + io.to(cache.get(`socket:${req.player.id}`)).emit('chat', renderChatMessage(broadcastMessage('server', e.message))); } } else if(msg === '/online') { @@ -326,18 +331,9 @@ app.get('/player/explore', authEndpoint, async (req: Request, res: Response) => } if(fight) { - const data: MonsterForFight = { - id: fight.id, - hp: fight.hp, - maxHp: fight.maxHp, - name: fight.name, - level: fight.level, - fight_trigger: fight.fight_trigger - }; const location = await getMonsterLocation(fight.ref_id); - - res.send(renderPlayerBar(req.player) + renderFightPreRound(data, true, location, closestTown)); + res.send(renderPlayerBar(req.player) + renderFightPreRound(fight, true, location, closestTown)); } else { if(travelPlan) { @@ -605,7 +601,7 @@ app.post('/fight/turn', authEndpoint, async (req: Request, res: Response) => { } cache[fightBlockKey] = Date.now() + CONSTANT.FIGHT_ATTACK_DELAY; - const monster = await loadMonsterWithFaction(req.player.id); + const monster = await loadMonsterFromFight(req.player.id); if(!monster) { res.send(Alert.ErrorAlert('Not in a fight')); @@ -675,17 +671,7 @@ app.post('/fight', fightRateLimiter, authEndpoint, async (req: Request, res: Res const fight = await createFight(req.player.id, monster, fightTrigger); const location = await getService(monster.location_id); - - const data: MonsterForFight = { - id: fight.id, - hp: fight.hp, - maxHp: fight.maxHp, - name: fight.name, - level: fight.level, - fight_trigger: fight.fight_trigger - }; - - res.send(renderFightPreRound(data, true, location, location.city_id)); + res.send(renderFightPreRound(fight, true, location, location.city_id)); }); app.post('/travel/step', authEndpoint, async (req: Request, res: Response) => { @@ -764,17 +750,9 @@ app.post('/travel/return-to-source', authEndpoint, async (req: Request, res: Res const fight = await loadMonsterFromFight(req.player.id); if(fight) { // go to the fight screen - const data: MonsterForFight = { - id: fight.id, - hp: fight.hp, - maxHp: fight.maxHp, - name: fight.name, - level: fight.level, - fight_trigger: fight.fight_trigger - }; const location = await getMonsterLocation(fight.ref_id); - res.send(renderPlayerBar(req.player) + renderFightPreRound(data, true, location, req.player.city_id)); + res.send(renderPlayerBar(req.player) + renderFightPreRound(fight, true, location, req.player.city_id)); } else { const [city, locations, paths] = await Promise.all([ diff --git a/src/server/fight.ts b/src/server/fight.ts index c1bdc45..ab7b2c6 100644 --- a/src/server/fight.ts +++ b/src/server/fight.ts @@ -6,7 +6,7 @@ import { updatePlayer } from './player'; import { getEquippedItems, updateAp } from './inventory'; import { EquippedItemDetails } from '../shared/equipped'; import { EquipmentSlot } from '../shared/inventory'; -import { MonsterWithFaction, MonsterForFight } from '../shared/monsters'; +import { MonsterWithFaction, MonsterForFight, Fight } from '../shared/monsters'; import { getPlayerSkillsAsObject, updatePlayerSkills } from './skills'; import { SkillID, Skills } from '../shared/skills'; import { Request, Response } from 'express'; @@ -35,7 +35,7 @@ function exponentialExp(exp: number, monsterLevel: number, playerLevel: number): return Math.floor(finalExp); } -export async function fightRound(player: Player, monster: MonsterWithFaction, data: {action: 'attack' | 'cast' | 'flee', target: 'head' | 'body' | 'arms' | 'legs'}) { +export async function fightRound(player: Player, monster: Fight, data: {action: 'attack' | 'cast' | 'flee', target: 'head' | 'body' | 'arms' | 'legs'}) { const playerSkills = await getPlayerSkillsAsObject(player.id); const roundData: FightRound = { monster, @@ -195,7 +195,8 @@ export async function fightRound(player: Player, monster: MonsterWithFaction, d return { id: monster.id, name: monster.name, - level: monster.minLevel, + minLevel: monster.minLevel, + maxLevel: monster.maxLevel, hp: monster.hp, maxHp: monster.maxHp, fight_trigger: 'explore' diff --git a/src/server/monster.ts b/src/server/monster.ts index 18c1243..54a49db 100644 --- a/src/server/monster.ts +++ b/src/server/monster.ts @@ -42,7 +42,8 @@ export async function loadMonsterFromFight(player_id: string): Promise { export async function loadMonsterWithFaction(player_id: string): Promise { const res = await db.raw(` select - f.*, fa.id as faction_id, fa.name as faction_name + f.*, fa.id as faction_id, fa.name as faction_name, + m.minLevel, m.maxLevel from fight f join monsters m on f.ref_id = m.id left outer join factions fa on m.faction_id = fa.id diff --git a/src/server/views/fight.ts b/src/server/views/fight.ts index f09ab41..b3ba986 100644 --- a/src/server/views/fight.ts +++ b/src/server/views/fight.ts @@ -1,6 +1,6 @@ import { FightRound } from "shared/fight"; import { LocationWithCity } from "shared/map"; -import { MonsterForFight } from "../../shared/monsters"; +import { Fight, MonsterForFight } from "../../shared/monsters"; import { Button, ButtonWithBlock } from "./components/button"; export function renderRoundDetails(roundData: FightRound): string { @@ -69,7 +69,7 @@ function AttackButton(blockTime?: number): string { } } -export function renderFight(monster: MonsterForFight, results: string = '', displayFightActions: boolean = true, blockTime: number = 0) { +export function renderFight(monster: Fight, results: string = '', displayFightActions: boolean = true, blockTime: number = 0) { const hpPercent = Math.floor((monster.hp / monster.maxHp) * 100); let html = ` @@ -105,7 +105,7 @@ export function renderFight(monster: MonsterForFight, results: string = '', disp return html; } -export function renderFightPreRound(monster: MonsterForFight, displayFightActions: boolean = true, location: LocationWithCity, closestTown: number) { +export function renderFightPreRound(monster: Fight, displayFightActions: boolean = true, location: LocationWithCity, closestTown: number) { const hpPercent = Math.floor((monster.hp / monster.maxHp) * 100); let html = ` diff --git a/src/server/views/monster-selector.ts b/src/server/views/monster-selector.ts index 03d6197..0fc5e5b 100644 --- a/src/server/views/monster-selector.ts +++ b/src/server/views/monster-selector.ts @@ -23,7 +23,7 @@ export function renderMonsterSelector(monsters: Monster[] | MonsterForFight[], a diff --git a/src/shared/fight.ts b/src/shared/fight.ts index d0f7b97..22f0ed9 100644 --- a/src/shared/fight.ts +++ b/src/shared/fight.ts @@ -1,4 +1,4 @@ -import {FightTrigger, MonsterWithFaction} from "./monsters" +import {Fight, FightTrigger, MonsterWithFaction} from "./monsters" import {Player} from "./player" export type FightReward = { @@ -8,7 +8,7 @@ export type FightReward = { } export type FightRound = { - monster: MonsterWithFaction, + monster: Fight, player: Player, fightTrigger: FightTrigger, winner: 'player' | 'monster' | 'in-progress', diff --git a/src/shared/monsters.ts b/src/shared/monsters.ts index 91c0dfa..f5147ff 100644 --- a/src/shared/monsters.ts +++ b/src/shared/monsters.ts @@ -45,6 +45,7 @@ export type MonsterForFight = { hp: number; maxHp: number; name: string; - level: number; + minLevel: number; + maxLevel: number; fight_trigger: FightTrigger; }