aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Pouar <pouar@pouar.net>2020-08-10 19:34:51 -0500
committerGravatar Pouar <pouar@pouar.net>2020-08-10 20:35:03 -0500
commit98094460c51ad9013c883b74d3a7004bb2ceef5c (patch)
treecae04888a16e9e58c31556e020df4233b5c5de75
parentrefactor (diff)
api change
add the character using the item as an argument to yadfa:use-script instead of just the character the user is using it on. While I'm at it, add a missing method for the messing laser
-rw-r--r--core/classes.lisp6
-rw-r--r--core/libexec/functions.lisp2
-rw-r--r--data/epilog/items.lisp12
-rw-r--r--data/items/consumable.lisp116
-rw-r--r--data/items/diaper.lisp4
-rw-r--r--data/items/misc.lisp10
-rw-r--r--data/items/weapons.lisp15
7 files changed, 84 insertions, 81 deletions
diff --git a/core/classes.lisp b/core/classes.lisp
index 5be3ea1..a9b1d13 100644
--- a/core/classes.lisp
+++ b/core/classes.lisp
@@ -244,9 +244,9 @@
:initform nil))
(:report (lambda (condition stream)
(format stream "~s has no ~s method defined" (slot-value condition 'item) 'use-script))))
-(defgeneric use-script (item user)
- (:documentation "Function that runs when @var{ITEM} is used on @var{USER}. @var{ITEM} is the instance of the item and @var{USER} is the user you're using it on.")
- (:method ((item item) (user base-character))
+(defgeneric use-script (item user target)
+ (:documentation "Function that runs when @var{USER} uses @var{ITEM} on @var{TARGET}. @var{ITEM} is the instance of the item and @var{USER} and @var{TARGET} are instances of base-character")
+ (:method ((item item) (user base-character) (target base-character))
(error 'unusable-item :item item)))
(defgeneric wield-script (item user)
(:documentation "Function that runs when @var{USER} is wielding @var{ITEM}. @var{ITEM} is the instance of the item and @var{USER} is the user you're using it on.")
diff --git a/core/libexec/functions.lisp b/core/libexec/functions.lisp
index 295cd6c..608e135 100644
--- a/core/libexec/functions.lisp
+++ b/core/libexec/functions.lisp
@@ -1982,7 +1982,7 @@
(when (consumablep item)
(a:deletef (the list (inventory-of user)) item)))
(write-line "You can't do that with that item"))
- (handler-case (progn (setf ret (use-script item target))
+ (handler-case (progn (setf ret (use-script item user target))
(when (consumablep item)
(a:deletef (the list (inventory-of user)) item)))
(unusable-item ()
diff --git a/data/epilog/items.lisp b/data/epilog/items.lisp
index e2b8e4b..d18d883 100644
--- a/data/epilog/items.lisp
+++ b/data/epilog/items.lisp
@@ -1,6 +1,6 @@
;;;; -*- mode: Common-Lisp; sly-buffer-package: "yadfa-items"; coding: utf-8-unix; -*-
(in-package :yadfa-items)
-(defmethod use-script ((item enemy-catcher) (target yadfa-enemies:catchable-enemy))
+(defmethod use-script ((item enemy-catcher) (user base-character) (target yadfa-enemies:catchable-enemy))
(cond
((>= (list-length (contained-enemies-of item)) (contained-enemies-max-length-of item))
(f:fmt t (name-of item) " can't hold anymore enemies" #\Newline #\Newline))
@@ -73,13 +73,13 @@
(write-line (yadfa-enemies:change-class-text i))
(collect (change-class i (get (class-name i) 'yadfa-enemies:change-class-target))))))
(format t "No enemies in there to adopt"))))))))
-(defmethod use-script ((item enemy-catcher) (target yadfa-enemies:ghost))
+(defmethod use-script ((item enemy-catcher) (user base-character) (target yadfa-enemies:ghost))
(f:fmt t "You failed to catch " (name-of target) #\Newline #\Newline)
(cond ((eq (device-health-of item) t) nil)
((<= (device-health-of item) 1)
(alexandria:deletef (inventory-of (player-of *game*)) item :count 1))
(t (decf (device-health-of item)))))
-(defmethod use-script ((item ghost-catcher) (target yadfa-enemies:ghost))
+(defmethod use-script ((item ghost-catcher) (user base-character) (target yadfa-enemies:ghost))
(cond
((>= (list-length (contained-enemies-of item)) (contained-enemies-max-length-of item))
(f:fmt t (name-of item) " can't hold anymore enemies" #\Newline #\Newline))
@@ -103,8 +103,8 @@
(push target (contained-enemies-of item)))))
(defunassert yadfa-battle-commands:catch-enemy (&optional (target 'yadfa-enemies:catchable-enemy) (item 'enemy-catcher))
- (item type-specifier
- target (or unsigned-byte type-specifier))
+ (item type-specifier
+ target (or unsigned-byte type-specifier))
"Catches an enemy using. @var{ITEM} which is a type specifier. @var{TARGET} is an index or type specifier of an enemy in battle or a type specifier"
(let ((selected-item (find item (inventory-of (player-of *game*))
:test (lambda (type-specifier obj)
@@ -130,7 +130,7 @@
:item selected-item
:selected-target selected-target)))
(defunassert yadfa-world-commands:loot-caught-enemies (&optional item)
- (item (or null unsigned-byte type-specifier))
+ (item (or null unsigned-byte type-specifier))
"Loots the enemies you caught. @var{ITEM} is either a type specifier or an unsiged-byte of the item. Don't specify if you want to loot the enemies of all items"
(cond ((null item)
(iter (for item in (inventory-of *game*))
diff --git a/data/items/consumable.lisp b/data/items/consumable.lisp
index 932d454..a88fecc 100644
--- a/data/items/consumable.lisp
+++ b/data/items/consumable.lisp
@@ -6,50 +6,50 @@
:description "A baby bottle filled with milk. Fills up your health and your bladder."
:value 50
:consumable t))
-(defmethod use-script ((item bottle-of-milk) (user base-character))
- (incf (bladder/contents-of user) 100)
- (if (> (health-of user) 0)
- (progn (format t "~a regained health~%" (name-of user))
- (incf (health-of user) 20))
- (format t "You make the unconscious ~a suckle on the ~a like a sleeping infant~%" (name-of user) (name-of item))))
+(defmethod use-script ((item bottle-of-milk) (user base-character) (target base-character))
+ (incf (bladder/contents-of target) 100)
+ (if (> (health-of target) 0)
+ (progn (format t "~a regained health~%" (name-of target))
+ (incf (health-of target) 20))
+ (f:fmt t (name-of user) " makes the unconscious " (name-of target) " suckle on the " (name-of item) " like a sleeping infant" #\Newline)))
(defclass mutagen (consumable)
((element-types :initarg :element-types :accessor element-types-of)))
-(defmethod use-script ((item mutagen) (user base-character))
+(defmethod use-script ((item mutagen) (user base-character) (target base-character))
(let* ((types (mapcar 'coerce-element-type (element-types-of item)))
- (old (mapcar 'coerce-element-type (element-types-of user)))
+ (old (mapcar 'coerce-element-type (element-types-of target)))
(new (union old types :key 'type-of :test 'eq))
(difference (set-difference new old :key 'type-of :test 'eq)))
(if difference
(flet ((format-type (type)
- (f:fmt t (name-of user) " gained the " (:esc
- (let* ((class (class-of type))
- (name (name-of class)))
- (if name (:fmt (:a name))
- (:fmt (:s (class-name class))))))
+ (f:fmt t (name-of target) " gained the " (:esc
+ (let* ((class (class-of type))
+ (name (name-of class)))
+ (if name (:fmt (:a name))
+ (:fmt (:s (class-name class))))))
" type" #\Newline)))
- (setf (element-types-of user) new)
+ (setf (element-types-of target) new)
(iter (for i in difference)
(format-type i)))
- (f:fmt t "It had no effect on " (name-of user) #\Newline))))
+ (f:fmt t "It had no effect on " (name-of target) #\Newline))))
(defclass antimutagen (consumable)
((element-types :initarg :element-types :accessor element-types-of)))
-(defmethod use-script ((item antimutagen) (user base-character))
+(defmethod use-script ((item antimutagen) (user base-character) (target base-character))
(let* ((types (mapcar 'coerce-element-type (element-types-of item)))
- (old (mapcar 'coerce-element-type (element-types-of user)))
+ (old (mapcar 'coerce-element-type (element-types-of target)))
(new (set-difference old types :key 'type-of :test 'eq))
(difference (set-difference old new :key 'type-of :test 'eq)))
(if difference
(flet ((format-type (type)
- (f:fmt t (name-of user) " lost the " (:esc
- (let* ((class (class-of type))
- (name (name-of class)))
- (if name (:fmt (:a name))
- (:fmt (:s (class-name class))))))
+ (f:fmt t (name-of target) " lost the " (:esc
+ (let* ((class (class-of type))
+ (name (name-of class)))
+ (if name (:fmt (:a name))
+ (:fmt (:s (class-name class))))))
" type" #\Newline)))
- (setf (element-types-of user) new)
+ (setf (element-types-of target) new)
(iter (for i in difference)
(format-type i)))
- (f:fmt t "It had no effect on " (name-of user) #\Newline))))
+ (f:fmt t "It had no effect on " (name-of target) #\Newline))))
(defclass monster-energy-drink (consumable) ()
(:default-initargs
:name "Monster Energy Drink"
@@ -61,27 +61,27 @@
(when (<= (health-of target) 0)
(format t "Does ~a look conscious enough to use that?~%" (name-of target))
t))
-(defmethod use-script ((item monster-energy-drink) (user base-character))
+(defmethod use-script ((item monster-energy-drink) (user base-character) (target base-character))
(declare (ignore item))
- (incf (bladder/contents-of user) 175)
- (incf (energy-of user) 20))
+ (incf (bladder/contents-of target) 175)
+ (incf (energy-of target) 20))
(defclass spiked-bottle-of-milk (consumable) ()
(:default-initargs
:name "Spiked Bottle of milk"
:description "A baby bottle filled with laxatives and diuretics. Fills up your bladder and bowels really quickly."
:value 50
:consumable t))
-(defmethod use-script ((item spiked-bottle-of-milk) (user base-character))
- (when (<= (health-of user) 0)
- (format t "You make the unconscious ~a suckle on the ~a like a sleeping infant~%" (name-of user) (name-of item)))
- (setf (bladder/contents-of user)
- (if (< (bladder/contents-of user) (bladder/need-to-potty-limit-of user))
- (- (bladder/maximum-limit-of user) (* (bladder/fill-rate-of user) 5))
- (+ (bladder/contents-of user) (bladder/potty-dance-limit-of user))))
- (setf (bowels/contents-of user)
- (if (< (bowels/contents-of user) (bowels/need-to-potty-limit-of user))
- (- (bowels/maximum-limit-of user) (* (bowels/fill-rate-of user) 5))
- (+ (bowels/contents-of user) (bowels/potty-dance-limit-of user)))))
+(defmethod use-script ((item spiked-bottle-of-milk) (user base-character) (target base-character))
+ (when (<= (health-of target) 0)
+ (f:fmt t (name-of user) " makes the unconscious " (name-of target) " suckle on the " (name-of item) " like a sleeping infant" #\Newline))
+ (setf (bladder/contents-of target)
+ (if (< (bladder/contents-of target) (bladder/need-to-potty-limit-of target))
+ (- (bladder/maximum-limit-of target) (* (bladder/fill-rate-of target) 5))
+ (+ (bladder/contents-of target) (bladder/potty-dance-limit-of target))))
+ (setf (bowels/contents-of target)
+ (if (< (bowels/contents-of target) (bowels/need-to-potty-limit-of target))
+ (- (bowels/maximum-limit-of target) (* (bowels/fill-rate-of target) 5))
+ (+ (bowels/contents-of target) (bowels/potty-dance-limit-of target)))))
(defclass consious-mixin (item) ())
(defmethod cant-use-p ((item consious-mixin) (user base-character) (target base-character) action &key &allow-other-keys)
(declare (ignorable item user action))
@@ -97,9 +97,9 @@
:description "Heals 20 HP"
:value 50
:consumable t))
-(defmethod use-script ((item potion) (user base-character))
+(defmethod use-script ((item potion) (user base-character) (target base-character))
(declare (ignore item))
- (incf (health-of user) 20))
+ (incf (health-of target) 20))
(defclass revive (consumable) ()
(:default-initargs
:name "Revive"
@@ -111,28 +111,28 @@
(when (> (health-of target) 0)
(format t "Does ~a look unconscious to you?~%" (name-of target))
t))
-(defmethod use-script ((item revive) (user base-character))
+(defmethod use-script ((item revive) (user base-character) (target base-character))
(declare (ignore item))
- (incf (health-of user) 20))
+ (incf (health-of target) 20))
(defclass cannibal-corp-meat (consious-mixin consumable) ()
(:default-initargs
:name "\"CANNIBAL CORP.\" Brand Meat"
:description "Just like in the music video. Heals 50 HP."
:value 75
:consumable t))
-(defmethod use-script ((item cannibal-corp-meat) (user base-character))
+(defmethod use-script ((item cannibal-corp-meat) (user base-character) (target base-character))
(declare (ignore item))
- (incf (bowels/contents-of user) 50)
- (incf (health-of user) 50))
+ (incf (bowels/contents-of target) 50)
+ (incf (health-of target) 50))
(defclass maximum-tomato (consious-mixin consumable) ()
(:default-initargs
:name "Maximum Tomato"
:description "Restores Full HP"
:value 50
:consumable t))
-(defmethod use-script ((item maximum-tomato) (user base-character))
+(defmethod use-script ((item maximum-tomato) (user base-character) (target base-character))
(declare (ignore item))
- (setf (health-of user) (calculate-stat user :health)))
+ (setf (health-of target) (calculate-stat target :health)))
(defclass holy-hand-grenade (consumable) ()
(:default-initargs
:name "Holy Hand Grenade of Antioch"
@@ -144,23 +144,23 @@
(unless *battle*
(write-line "You can only use that in battle")
t))
-(defmethod use-script ((item holy-hand-grenade) (user base-character))
+(defmethod use-script ((item holy-hand-grenade) (user base-character) (target base-character))
(declare (ignore item))
- (if (or (and (typep user 'team-member) (cdr (team-of *game*)))
- (and (typep user 'enemy) (cdr (enemies-of *battle*))))
+ (if (or (and (typep target 'team-member) (cdr (team-of *game*)))
+ (and (typep target 'enemy) (cdr (enemies-of *battle*))))
(progn
- (format t "~a: One, Two, Five~%" (name-of user))
- (format t "~a: Three ~a~%" (name-of (if (typep user 'team-member)
- (or (second (member user (team-of *game*)))
+ (format t "~a: One, Two, Five~%" (name-of target))
+ (format t "~a: Three ~a~%" (name-of (if (typep target 'team-member)
+ (or (second (member target (team-of *game*)))
(player-of *game*))
- (or (second (member user (enemies-of *battle*)))
+ (or (second (member target (enemies-of *battle*)))
(first (enemies-of *battle*)))))
- (if (malep user) "Sir" "Ma'am"))
- (format t "~a: Three!!!" (name-of user)))
- (format t "~a: One, Two, Five, I mean Three!!!" (name-of user)))
+ (if (malep target) "Sir" "Ma'am"))
+ (format t "~a: Three!!!" (name-of target)))
+ (format t "~a: One, Two, Five, I mean Three!!!" (name-of target)))
(write-line " *throws hand grenade*")
(write-line "*BOOM*")
- (iter (for i in (if (typep user 'team-member)
+ (iter (for i in (if (typep target 'team-member)
(enemies-of *battle*)
(team-of *game*)))
(decf (health-of i) 120)))
diff --git a/data/items/diaper.lisp b/data/items/diaper.lisp
index 1f3d045..6d47285 100644
--- a/data/items/diaper.lisp
+++ b/data/items/diaper.lisp
@@ -42,10 +42,10 @@
(defclass diaper-package-mixin (item)
((diaper :type symbol
:initarg :diaper)))
-(defmethod use-script ((item diaper-package-mixin) (user base-character))
+(defmethod use-script ((item diaper-package-mixin) (user base-character) (target base-character))
(format t "You tear open the package and dump all the diapers out of it.~%")
(iter (for i from 1 to 20)
- (push (make-instance (slot-value item 'diaper)) (inventory-of user))))
+ (push (make-instance (slot-value item 'diaper)) (inventory-of target))))
(defclass generic-diapers (yadfa:diaper undies) ()
(:default-initargs
:sogginess-capacity 100
diff --git a/data/items/misc.lisp b/data/items/misc.lisp
index badcc5b..9f23494 100644
--- a/data/items/misc.lisp
+++ b/data/items/misc.lisp
@@ -31,7 +31,7 @@
:tossable nil
:sellable nil
:description "So you're playing Pokémon and you're making your secret base. Then you're like “Damn, I wish I could take this awesome base with me” or “I wish I could create my own decorations for this base instead of only being able to use what Nintendo provides me”. While Pouar can't do anything about Pokémon, he can create a similar feature for this game without these limitations. So here it is, the Pocket Map Machine"))
-(defmethod use-script ((item pocket-map-machine) (user base-character))
+(defmethod use-script ((item pocket-map-machine) (user base-character) (target base-character))
(declare (ignore user))
(move-to-pocket-map item))
(defclass warp-device (item) ()
@@ -40,8 +40,8 @@
:tossable nil
:sellable nil
:description "This device can be used to summon a warp pipe to take you to the secret underground"))
-(defmethod use-script ((item warp-device) (user base-character))
- (declare (ignore item user))
+(defmethod use-script ((item warp-device) (user base-character) (target base-character))
+ (declare (ignore item user target))
(move-to-secret-underground))
(defclass macguffin (item) ()
(:default-initargs
@@ -53,8 +53,8 @@
(:default-initargs
:name "Itemfinder"
:description "Returns T anytime a hidden item is nearby. It is based on Pouar's ability to detect whatever he has to say is offensive or not. It uses the same algorithm, is about as effective, and has about as many happy customers. Also, if you wrap the function in a not function, it becomes the same algorithm SJWs use to decide whatever they hear is offensive or not."))
-(defmethod use-script ((item itemfinder) (user base-character))
- (declare (ignore item user)))
+(defmethod use-script ((item itemfinder) (user base-character) (target base-character))
+ (declare (ignore item user target)))
(defclass shine-star (item) ()
(:default-initargs
:name "Shine Star"
diff --git a/data/items/weapons.lisp b/data/items/weapons.lisp
index 47f64fc..4b3b8cd 100644
--- a/data/items/weapons.lisp
+++ b/data/items/weapons.lisp
@@ -3,10 +3,10 @@
(defclass ammo-box-mixin (item)
((ammo :type symbol
:initarg :ammo)))
-(defmethod use-script ((item ammo-box-mixin) (user base-character))
- (format t "You open the box and dump all the ammunition out of it.~%")
+(defmethod use-script ((item ammo-box-mixin) (user base-character) (target base-character))
+ (f:fmt t (name-of user) " open the box and dump all the ammunition out of it." #\Newline)
(iter (for i from 1 to 6)
- (push (make-instance (slot-value item 'ammo)) (inventory-of user))))
+ (push (make-instance (slot-value item 'ammo)) (inventory-of target))))
(defclass 7.62×39mm (ammo) ()
(:default-initargs
:name "7.62x39mm Rounds"
@@ -121,9 +121,12 @@
:name "Messing Laser"
:description "Causes enemies to mess themselves"
:values 8000))
-(defmethod attack ((target bowels-character) (user base-character) (weapon messing-laser))
+(defmethod attack ((target base-character) (user base-character) (weapon messing-laser))
+ (f:fmt t (name-of user) " fires " (if (malep user) "his" "her") " laser at " (name-of target) #\Newline)
+ (use-script weapon user target))
+(defmethod use-script ((weapon messing-laser) (user base-character) (target base-character))
+ (f:fmt t "It has no effect on " (name-of target) #\Newline))
+(defmethod use-script ((weapon messing-laser) (user base-character) (target bowels-character))
(f:fmt t (name-of target) " squats down and starts blorting " (if (malep target) "himself" "herself") " uncontrollably." #\Newline)
(mess :force-fill-amount (bowels/maximum-limit-of target))
(set-status-condition 'yadfa-status-conditions:messing target))
-(defmethod attack ((target base-character) (user base-character) (weapon messing-laser))
- (f:fmt t "It has no effect on " (name-of target) #\Newline))