fix: add block timer for casting and clear after fight
authorxangelo <me@xangelo.ca>
Thu, 24 Aug 2023 17:53:27 +0000 (13:53 -0400)
committerxangelo <me@xangelo.ca>
Thu, 24 Aug 2023 17:53:27 +0000 (13:53 -0400)
src/server/api.ts
src/server/views/fight.ts

index 359c07e85b6193e66e7330b05ab8e342cf14bcc5..d9f67abc902cc611118d2871b29b19937306a4dc 100644 (file)
@@ -863,6 +863,10 @@ app.post('/fight/turn', authEndpoint, async (req: AuthRequest, res: Response) =>
     cache[fightBlockKey]
   );
 
+  if(fightData.roundData.winner !== 'in-progress') {
+    delete cache[fightBlockKey];
+  }
+
   if(fightData.monsters.length && monster.fight_trigger === 'explore') {
     html += renderMonsterSelector(fightData.monsters, monster.ref_id);
   }
index 02f595b32892cd91eadaae98437adb5c3886d186..06ebcdb170d8971288de6ae765fd9fbba57e8812 100644 (file)
@@ -34,6 +34,24 @@ export function renderRoundDetails(roundData: FightRound): string {
   return html.join("\n");
 }
 
+function CastButton(blockTime?: number): string {
+  const attrs = {
+      id: 'cast-button',
+      type: 'submit', 
+      class: ['fight-action', 'red'],
+      name: 'action',
+      value: 'cast'
+  };
+
+  if(blockTime) {
+    return ButtonWithBlock(attrs, 'Cast', blockTime);
+  }
+  else {
+    return Button(attrs, 'Cast');
+  }
+
+}
+
 function AttackButton(blockTime?: number): string {
   const attrs = {
       id: 'attack-button',
@@ -75,7 +93,7 @@ export function renderFight(monster: MonsterForFight, results: string = '', disp
           <option value="legs">Legs</option>
         </select>
         ${AttackButton(blockTime)}
-        <button type="submit" class="fight-action red" name="action" value="cast">Cast</button>
+        ${CastButton(blockTime)}
         <button type="submit" class="fight-action" name="action" value="flee">Flee</button>
       </form>
       `: ''}
@@ -118,7 +136,7 @@ export function renderFightPreRound(monster: MonsterForFight,  displayFightActio
           <option value="legs">Legs</option>
         </select>
         ${AttackButton()}
-        <button type="submit" class="fight-action red" name="action" value="cast">Cast</button>
+        ${CastButton()}
         <button type="submit" class="fight-action" name="action" value="flee">Flee</button>
       </form>
       `: ''}