chore(release): 0.4.0
[risinglegends.git] / src / server / views / dungeons / room.ts
1 import { DUNGEON_TRAVEL_BLOCK } from '../../../shared/constants';
2 import { Dungeon, DungeonPlayer, DungeonRewards, DungeonRoom, DungeonState, DungeonStateSummaryVists } from '../../../shared/dungeon';
3 import { Button, ButtonWithBlock } from '../components/button';
4 import { Details, Title } from '../components/city';
5
6 function renderMovementButtons(room: DungeonRoom): string { 
7   let html: string[] = [];
8   const now = Date.now();
9
10   room.exits.forEach(exit => {
11     html.push(ButtonWithBlock({
12       id: `target-${exit.target_room_id}`,
13       'hx-post': `/city/dungeon/step/${exit.target_room_id}`,
14       'hx-target': '#explore'
15     }, exit.name, now + DUNGEON_TRAVEL_BLOCK));
16   });
17
18   if(room.settings?.end) {
19     html.push(Button({
20       id: `target-exit`,
21       'hx-post': `/city/dungeon/${room.dungeon_id}/complete`,
22       'hx-target': '#modal-wrapper'
23     }, 'Complete Dungeon'));
24   }
25
26   return html.join("\n");
27 }
28
29 export function renderDungeonRoom(room: DungeonRoom, state: DungeonStateSummaryVists): string {
30   // first visit for this room?
31   let desc = room.description;
32   room.settings?.visit?.forEach(visit => {
33     // This ssets the stage for repeat events. 
34     // eventually the description might change if you visit 
35     // a spot MROE than 5 or 6 times
36     if(state[room.id]) {
37       if(visit?.visit_number === state[room.id]) {
38         desc = visit.description;
39       }
40     }
41   });
42
43   let html = `<div class="dungeon-room-description">${desc}</div><div class="dungeon-room-actions">${renderMovementButtons(room)}</div>`;
44
45   return html;
46
47 }
48
49 export function renderDungeon(city: string, dungeon_name: string, room: DungeonRoom, state: DungeonStateSummaryVists): string { 
50   return`
51   ${Title(city)}
52   ${Details(dungeon_name, renderDungeonRoom(room, state))}
53 `;
54 }
55
56 export function dungeonRewards(dungeon: Dungeon, rewards: DungeonRewards, completions: number): string {
57   return `
58 <dialog>
59   <div class="dungeon-rewards">
60     <p>Congratulations on completing the ${dungeon.name} Dungeon!</p>
61     <p>${completions <= 5 ? `${completions}/5 Runs` : `You've exhausted your runs!`}</p>
62     <b>Rewards:</b><br>
63     <b>Exp:</b> ${rewards.exp.toLocaleString()}<br>
64     <b>Gold:</b> ${rewards.gold.toLocaleString()}<br>
65   </div>
66   <div class="actions">
67     <button nav-trigger="#player-info nav a|3" formmethod="dialog" value="cancel" class="green">Exit</button>
68   </div>
69 </dialog>
70   `;
71 }