I’ve created a weapon class that can be Wielded and Unwielded, with implementation similar to wearables. I’ve got it working so far, but I’d like to have it noted in the player’s inventory when an item is so equipped and I’m not sure where to add this.
Code so far:
DefineTAction(Wield)
;
VerbRule(Wield)
('wield'|'equip'|'ready') singleDobj
: VerbProduction
action = Wield
verbPhrase = 'wield/wielding (what)'
missingQ = 'what do you want to wield'
;
modify Thing
isWeapon = nil
wieldedBy = nil
makeWielded(stat) { wieldedBy = stat; }
directlyWielding = (contents.subset({ obj: obj.wieldedBy == self}))
isWieldedBy(obj)
{
return (location == obj ? wieldedBy == obj : location != nil && location.isWieldedBy(obj));
}
myWieldingLister = wieldingLister
dobjFor(Wield)
{
preCond = [objHeld]
verify()
{
if(!isWeapon)
illogical(cannotWieldMsg);
if(wornBy == gActor)
illogical(alreadyWieldedMsg);
}
action() {makeWielded(gActor); }
report()
{
DMsg(okay wield, 'Okay, {i}{\'m} now wielding {1}. ', gActionListStr);
}
}
cannotWieldMsg = '{The subj dobj} isn\'t something you can wield. '
isUnreadyable = (isWeapon)
dobjFor(Unready)
{
verify()
{
if (wieldedBy != gActor)
illogicalNow(notWieldedMsg);
if (!isUnreadyable)
illogical(cannotUnreadyMsg);
}
check()
{
checkRoomToHold();
}
action() { makeWielded(nil); }
report()
{
DMsg(okay unready, 'Okay, {I}{\'m} no longer wielding {1}. ', gActionListStr);
}
}
cannotUnreadyMsg = 'You cannot unwield {the subj dobj}.'
notWieldedMsg = BMsg(not wielded, '{I}{\'m} not wielding {the dobj}. ')
alreadyWieldedMsg = 'You\'re already wielding {the subj dobj}.'
dobjFor(Drop)
{
preCond = [objNotWorn]
verify()
{
/* I can't drop something I'm not holding */
if(!isDirectlyIn(gActor))
illogicalNow(notHoldingMsg);
/*
* Even if something is directly in me, I can't drop it if it's
* fixed in place (since it's then presumably a part of me).
*/
else if(isFixed)
illogical(partOfYouMsg);
/*
* And I can't drop something that game code has deemed to be not
* droppable for some other reason.
*/
else if(!isDroppable)
illogical(cannotDropMsg);
logical;
}
action()
{
actionMoveInto(gActor.location.dropLocation);
makeWielded(nil);
}
report()
{
DMsg(report drop, 'Dropped. |{I} drop{s/?ed} {1}. ', gActionListStr);
}
}
;
DefineTAction(Unready)
;
VerbRule(Unready)
('unequip'|'unready'|'remove') singleDobj
: VerbProduction
action = Unready
verbPhrase = 'unready/unreadying (what)'
missingQ = 'what do you want to unready'
;
wieldingLister: ItemLister
/* is the object listed in an inventory list? */
listed(obj) { return obj.inventoryListed && !obj.isHidden; }
;
class Weapon: Thing
isWeapon = true
combatFactor = 0
;