add utility functions

This commit is contained in:
2026-01-05 21:22:19 -05:00
parent 3b3ebf8e31
commit 48ba912d52
6 changed files with 57 additions and 19 deletions

View File

@@ -31,7 +31,22 @@
:if-exists :overwrite
:if-does-not-exist :create)))
(defun get-mobs-that-drop-item (item-id &optional (drop-ds (make-drop-data-source)) (mob-ds (make-mob-data-source)))
(loop for drop across (data drop-ds)
when (equal (href drop "ItemID") item-id)
append (loop for mob across (data mob-ds)
when (equal (parse-integer (href mob "mob" "mob_id"))
(href drop "DropperID"))
collect mob)))
(defun get-drops-by-item-name (item-name &optional (ds (make-drop-data-source)))
(loop for drop across (data ds)
when (string-equal (href drop "ItemName") item-name)
collect drop))
(comment
(defvar drops (make-drop-data-source "foo"))
(defvar drops (make-drop-data-source))
(get-drops-by-item-name "Blue Goldrunners")
(data (make-drop-data-source))
(refresh drops)
(reload drops))

View File

@@ -19,8 +19,6 @@
(url (chronostory-item-url item-id))
(data (http-get-json url)))
(sleep 0.3)
(when data
(uiop:println (concatenate 'string "Retrieved id " (write-to-string item-id))))
data)))
(defmethod refresh ((ds item-data-source))

View File

@@ -46,9 +46,27 @@
:save-runtime-options :accept-runtime-options))
(comment
(defvar foo nil
(maybe-pass #'make-spawn-data-source (get-arg "--output" '("/root/lispostory/lispostory" "refresh" "spawns" "--output" "/root/api/chronostory/spawns.json")))
(defvar foo nil)
(setf foo (serapeum/bundle:random-elt *chronostory-mobs*)
*chronostory-drops*
*chronostory-drops*)
(let ((spawns (coerce (gethash "LUDIBRIUM" (data (make-spawn-data-source))) 'list)))
(find-if (lambda (hm) (string-equal (gethash "MobName" hm) "Master Death Teddy")) spawns))
(let* ((mobs (coerce (data(make-mob-data-source)) 'list)))
(filter-map (lambda (hm)
(let ((item-name (string-downcase (gethash "ItemName" hm))))
(when (or
(string-contains-p "orange goldrunners" item-name)
(string-contains-p "blue goldrunners" item-name))
(@ (find-if (lambda (mhm)
(= (parse-integer (@ mhm "mob" "mob_id"))
(gethash "DropperID" hm)))
mobs) "mob" "mob_name"))))
(coerce (data (make-drop-data-source)) 'list)))
(reload-item-data
(filter-map
@@ -60,4 +78,4 @@
(hash-table-keys (aref (@ *chronostory-spawns* :el-nath) 0))
(hash-table-keys (aref *chronostory-drops* 0))))))))
(hash-table-keys (aref *chronostory-drops* 0))))))

View File

@@ -18,8 +18,6 @@
(url (chronostory-mob-url mob-id))
(data (http-get-json url)))
(sleep 0.3)
(when data
(uiop:println (concatenate 'string "Retrieved id " (write-to-string mob-id))))
data))
(defmethod refresh ((ds mob-data-source))

View File

@@ -104,6 +104,13 @@ separate csvs."
:if-does-not-exist :create)
spawn-data))
(defun get-spawns-for-mob (mob-name &optional (ds (make-spawn-data-source)))
(loop :for areas :in (hash-table-values (data ds))
:append (loop :for spawn :across areas
:when (string-equal (@ spawn "Monster") mob-name)
collect spawn)))
(comment
(defvar spawn-ds (make-spawn-data-source))
(refresh spawn-ds))
(data (make-spawn-data-source))
(mapcar (partial #'gethash "MapName") (get-spawns-for-mob "Snail")))

View File

@@ -4,6 +4,8 @@
(in-package :lispostory)
(toggle-pretty-print-hash-table t)
(defun http-get-json (url)
(multiple-value-bind (body status) (drakma:http-request url)
(if (/= status 200)
@@ -36,7 +38,7 @@
(defun maybe-pass (func arg)
"Pass ARG to FUNC if arg is not nil."
(if (equal arg nil)
(if (not (equal arg nil))
(funcall func arg)
(funcall func)))