add utility functions
This commit is contained in:
17
drops.lisp
17
drops.lisp
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
42
main.lisp
42
main.lisp
@@ -46,18 +46,36 @@
|
||||
:save-runtime-options :accept-runtime-options))
|
||||
|
||||
(comment
|
||||
(defvar foo nil
|
||||
(setf foo (serapeum/bundle:random-elt *chronostory-mobs*)
|
||||
*chronostory-drops*
|
||||
(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*)
|
||||
|
||||
(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)
|
||||
(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)))
|
||||
|
||||
|
||||
(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))))))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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")))
|
||||
|
||||
@@ -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)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user