Virtual Item System

Submitted by Reaver on Fri, 2009-12-04 05:00

Righto, this is my amazing "Virtual Inventory System". I'll briefly explain how it works. Basically an inventory is saved on a player via list`inventory in the format ITEM_NAME TYPE AMOUNT|ITEM_NAME TYPE AMOUNT

A type is a number, as seen in the bottom most item database variable (1_General)

1 is the number type of the object, and GENERAL is the general item type.

This allows one to &list`inventory me=Nuka_Cola 1 100
to create 100 Nuka Cola's as type Food.

This is great for atmosphere, and reducing MUSH clutter. As

&list`inventory me=Cake 1 100
Allows you to make cake, as the same type as Nuka Cola, without needing to change anything in the database. Simply editing an inventory string and adding in the new item is enough to make it exist. The only modifications really ever needed to the system database is when adding a new item type. Item types can be anything, but are usually used with code to identify an item for a purpose (As will be seen with the Comsys code I will soon post.)

I will also be dropping in a +look command very shortly for desc'd objects.

Right now the system's virtual inventory is +inv, +take , +give =, +drop

====== Main Code

@create Item System
@create Item Database
@link Item Database=Item System
@set Item System=VD:[num(Item Database)]
@set Item System = WIZARD
@set Item System = !no_command
&CMD`DROP Item System=$+drop *:@pemit %#=[switch([t(setr(G,grab(setr(I,default(%@/list`inventory,)),%0*,|)))][t(sign([extract(%qG,3,1)]))],11,You drop [capstr_all(edit(first(%qG),_,%b))].[oemit(%L/%@,[name(%@)] drops [capstr_all(edit(first(%qG),_,%b))])][attrib_set(%@/list`inventory,u(fun`submass,%qI,extract(%qG,1,2),1))][attrib_set(%L/list`inventory,u(fun`addmass,[default(%L/list`inventory,)],[extract(%qG,1,2)],1))],I don't see that in your inventory.)]
&CMD`GET Item System=$+get *:@pemit %#=[switch([t(setr(G,grab(setr(I,default(%L/list`inventory,)),%0*,|)))][t(sign([extract(%qG,3,1)]))],11,You take [capstr_all(edit(first(%qG),_,%b))].[oemit(%L/%@,[name(%@)] takes [capstr_all(edit(first(%qG),_,%b))])][attrib_set(%L/list`inventory,u(fun`submass,%qI,extract(%qG,1,2),1))][attrib_set(%@/list`inventory,u(fun`addmass,[default(%@/list`inventory,)],[extract(%qG,1,2)],1))],I don't see that here.)]
&CMD`GIVE Item System=$+give *=*:@pemit %#=[switch([t(setr(G,grab(setr(I,default(%@/list`inventory,)),%1*,|)))][t(sign([extract(%qG,3,1)]))][hastype(setr(p,pmatch(%0)),PLAYER)],111,You give [setr(R,capstr_all(edit(first(%qG),_,%b)))] to [name(%qP)].[oemit(%L/%@ %qP,[name(%@)] gives %qR to [name(%qP)])][pemit(%qP,[name(%@)] gives you a %qR.)][attrib_set(%@/list`inventory,u(fun`submass,%qI,extract(%qG,1,2),1))][attrib_set(%qP/list`inventory,u(fun`addmass,[default(%qP/list`inventory,)],[extract(%qG,1,2)],1))],110,That's not a player.,I don't see that in your inventory.)]
&CMD`INV Item System=$^i(?\:n|nv|nve|nven|nvent|nvento|nventor|nventory)?$:@pemit %#=[u(format`inventory)]
&CMD`+INV Item System=$^\+i(?\:n|nv|nve|nven|nvent|nvento|nventor|nventory)?$:@pemit %#=[u(format`inventory)]
@set Item System/CMD`INV=regexp
@set Item System/CMD`+INV=regexp
@DESCRIBE Item System=Thing
&FORMAT`INVENTORY Item System=[ansi(hx,[center([ansi(hw,<%b[ansi(hg,[name(%#)]'s Inventory)]%b>)],78,=,=)]%r[repeat(-,78)])]%r[table([iter([default(%#/list`inventory,)],[space(8)]<[last(%i0)]x>%b[ansi(hy,[edit([capstr([lcstr([first(%i0)])])],_,%b)])]%b%b,|,|)],38,78,|,%b)]%r[ansi(hx,[rjust([ansi(hw,<%b[ansi(hg,At #\% carrying capacity.)]%b>)],73,-)]-----[if(t(lcon(%#)),%r[ansi(hg,OOC Objects:)]%r[iter(lcon(%#),[ansi(hg,[name(%i0)])]%b[ansi(hy,<%i0>)],%b,%r)]%r,%r)][rjust([ansi(hw,<%b[ansi(hg,[default(%#/Cash,0)] Dollars)]%b>)],78,=)])]
&FUN`ADDMASS Item System=localize(switch(t(setr(0,match(%0,%1%b*,|))),1,replace(%0,%q0,replace(setr(1,extract(%0,%q0,1,|)),3,add(last(%q1),%2)),|),0,setunion(%0,%1%b%2,|),ERROR AT ADDMASS))
&FUN`ITEMRES Item System=[default(%vd/[extract([grab(%0,%1*,|)],2,1)]_%2,Data Trash)]
&FUN`SUBMASS Item System=localize(switch(sign(last(setr(0,replace(setr(1,extract(%0,setr(2,match(%0,%1%b*,|)),1,|)),3,sub(last(%q1),%2))))),1,replace(%0,%q2,%q0,|),setdiff(%0,grab(%0,%1%b*,|),|,|)))
&GLOB`CAPSTR_ALL Item System=iter(%0,capstr(lcstr(%i0)))
&GLOB`DEFEXTR Item System=localize(if(t(setr(0,extract(%0,%1,%2,%3))),%q0,%4))
&GLOB`ISPOS Item System=gt(%0,0)
&GLOB`PLURAL Item System=if(gt(%0,1),%1s)
&GLOB`VOWEL Item System=t(match(A E I O U,left(%0,1)))
@startup Item System=@dol [lattr(me/GLOB`*)]=@function [after(##,GLOB`)]=me,##
&1_General Item Database=Food
@tel Item Database=Item System
@restart Item System
th [ansi(hg,Please drop Item System into the Master Room now\, please.)]

=========== This code is for rooms, to display items within the room.

[if(t(v(list`inventory)),[ansi(hw,Contents:)]%b[iter(v(list`inventory),<[extract(%i0,3,1)]x>%b[edit(first(%i0),_,%b)],|,%b-%b)]%r)]

An easy way to implement this, is to make a room parent (Or ancestor) with
@descformat #1111=%0%r%r[if(t(v(list`inventory)),[ansi(hw,Contents:)]%b[iter(v(list`inventory),<[extract(%i0,3,1)]x>%b[edit(first(%i0),_,%b)],|,%b-%b)]%r)]

where #1111 is the dbref of the room.