summaryrefslogtreecommitdiff
path: root/src/queries.lisp
blob: 07a8d5fda439746089672cd46c149bd7d628ef07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
;;;; queries.lisp -- query the database

(in-package :dnd)

(defun all-heroes ()
  (db:store-objects-with-class 'hero))

(defun all-players ()
  (db:store-objects-with-class 'player))

(defun player-quests (player)
  "Return all quests in which one of player's heroes is engaged."
  (remove nil (mapcar #'quest (player-heroes player))))

(defun player-adventures (player)
  "Return a list of adventures one of the players' heroes is involved in."
  (mapcar #'adventure (player-quests player) ))

(defun adventure-heros (adventure &key (activep t))
  "All the heros actively involved in this ADVENTURE. If ACTIVEP, then
only the active quest(s) are considered, otherwise all quests are considered."
  (remove-duplicates
   (mapcan #'heroes-on-quest
           (if activep
               (remove-if-not #'quest-startedp (quests-in-adventure adventure))
               (quests-in-adventure adventure)))))

(defun fetch-comrades (player &key (activep t))
  "Returns all the heroes in any one of the player's adventures. If
ACTIVEP, then only heroes involved in active quests are returned."
  (remove-duplicates
   (loop :for adventure :in (player-adventures player)
         :nconc (adventure-heros adventure :activep activep))))

(defun all-adventures ()
  (db:store-objects-with-class 'adventure))

(defun adventures-visible-by (player)
  (declare (ignore player))
  (all-adventures))