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-exists :overwrite
:if-does-not-exist :create))) :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 (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) (refresh drops)
(reload drops)) (reload drops))

View File

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

View File

@@ -46,18 +46,36 @@
:save-runtime-options :accept-runtime-options)) :save-runtime-options :accept-runtime-options))
(comment (comment
(defvar foo nil (maybe-pass #'make-spawn-data-source (get-arg "--output" '("/root/lispostory/lispostory" "refresh" "spawns" "--output" "/root/api/chronostory/spawns.json")))
(setf foo (serapeum/bundle:random-elt *chronostory-mobs*) (defvar foo nil)
*chronostory-drops* (setf foo (serapeum/bundle:random-elt *chronostory-mobs*)
*chronostory-drops*)
(reload-item-data (let ((spawns (coerce (gethash "LUDIBRIUM" (data (make-spawn-data-source))) 'list)))
(filter-map (find-if (lambda (hm) (string-equal (gethash "MobName" hm) "Master Death Teddy")) spawns))
(lambda (m)
(when (= (parse-integer (gethash "DROPPERID" m)) (let* ((mobs (coerce (data(make-mob-data-source)) 'list)))
(parse-integer (href foo "mob" "mob_id"))) (filter-map (lambda (hm)
(gethash "ITEMNAME" m)) (let ((item-name (string-downcase (gethash "ItemName" hm))))
(coerce *chronostory-drops* 'list) (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)))
(hash-table-keys (aref (@ *chronostory-spawns* :el-nath) 0))
(hash-table-keys (aref *chronostory-drops* 0)))))))) (reload-item-data
(filter-map
(lambda (m)
(when (= (parse-integer (gethash "DROPPERID" m))
(parse-integer (href foo "mob" "mob_id")))
(gethash "ITEMNAME" m))
(coerce *chronostory-drops* 'list)
(hash-table-keys (aref (@ *chronostory-spawns* :el-nath) 0))
(hash-table-keys (aref *chronostory-drops* 0))))))

View File

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

View File

@@ -104,6 +104,13 @@ separate csvs."
:if-does-not-exist :create) :if-does-not-exist :create)
spawn-data)) 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 (comment
(defvar spawn-ds (make-spawn-data-source)) (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) (in-package :lispostory)
(toggle-pretty-print-hash-table t)
(defun http-get-json (url) (defun http-get-json (url)
(multiple-value-bind (body status) (drakma:http-request url) (multiple-value-bind (body status) (drakma:http-request url)
(if (/= status 200) (if (/= status 200)
@@ -36,7 +38,7 @@
(defun maybe-pass (func arg) (defun maybe-pass (func arg)
"Pass ARG to FUNC if arg is not nil." "Pass ARG to FUNC if arg is not nil."
(if (equal arg nil) (if (not (equal arg nil))
(funcall func arg) (funcall func arg)
(funcall func))) (funcall func)))