Correct for PEP8 compliance. Add contrib entry to README.
This commit is contained in:
parent
011ba18d5b
commit
0fb7d13d63
2 changed files with 116 additions and 106 deletions
|
|
@ -19,6 +19,8 @@ things you want from here into your game folder and change them there.
|
|||
for any game. Allows safe trading of any godds (including coin)
|
||||
* CharGen (Griatch 2011) - A simple Character creator for OOC mode.
|
||||
Meant as a starting point for a more fleshed-out system.
|
||||
* Clothing (BattleJenkins 2017) - A layered clothing system with
|
||||
slots for different types of garments auto-showing in description.
|
||||
* Custom gametime (Griatch, vlgeoff 2017) - Implements Evennia's
|
||||
gametime module but for custom game world-specific calendars.
|
||||
* Dice (Griatch 2012) - A fully featured dice rolling system.
|
||||
|
|
|
|||
|
|
@ -63,13 +63,13 @@ with which to test the system:
|
|||
|
||||
@create a pretty shirt : evennia.contrib.clothing.Clothing
|
||||
@set shirt/clothing_type = 'top'
|
||||
|
||||
"""
|
||||
|
||||
from evennia import DefaultObject
|
||||
from evennia import DefaultCharacter
|
||||
from evennia import default_cmds
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
from evennia.utils import search
|
||||
from evennia.utils import list_to_string
|
||||
from evennia.utils import evtable
|
||||
|
||||
|
|
@ -77,13 +77,14 @@ from evennia.utils import evtable
|
|||
# Maximum character length of 'wear style' strings, or None for unlimited.
|
||||
WEARSTYLE_MAXLENGTH = 50
|
||||
# The order in which clothing types appear on the description. Untyped clothing goes last.
|
||||
CLOTHING_TYPE_ORDER = ['hat','jewelry','top','undershirt','gloves','fullbody','bottom','underpants','socks','shoes','accessory']
|
||||
CLOTHING_TYPE_ORDER = ['hat', 'jewelry', 'top', 'undershirt', 'gloves', 'fullbody', 'bottom',
|
||||
'underpants', 'socks', 'shoes', 'accessory']
|
||||
# The maximum number of each type of clothes that can be worn. Unlimited if untyped or not specified.
|
||||
CLOTHING_TYPE_LIMIT = {
|
||||
'hat':1,
|
||||
'gloves':1,
|
||||
'socks':1,
|
||||
'shoes':1
|
||||
'hat': 1,
|
||||
'gloves': 1,
|
||||
'socks': 1,
|
||||
'shoes': 1
|
||||
}
|
||||
# The maximum number of clothing items that can be worn, or None for unlimited.
|
||||
CLOTHING_OVERALL_LIMIT = 20
|
||||
|
|
@ -92,19 +93,16 @@ CLOTHING_OVERALL_LIMIT = 20
|
|||
# on that auto-covers it - for example, it's perfectly possible to have your underpants
|
||||
# showing if you put them on after your pants!
|
||||
CLOTHING_TYPE_AUTOCOVER = {
|
||||
'top':['undershirt'],
|
||||
'bottom':['underpants'],
|
||||
'fullbody':['undershirt','underpants'],
|
||||
'shoes':['socks']
|
||||
'top': ['undershirt'],
|
||||
'bottom': ['underpants'],
|
||||
'fullbody': ['undershirt', 'underpants'],
|
||||
'shoes': ['socks']
|
||||
}
|
||||
# Types of clothes that can't be used to cover other clothes.
|
||||
CLOTHING_TYPE_CANT_COVER_WITH = ['jewelry']
|
||||
|
||||
"""
|
||||
----------------------------------------------------------------------------
|
||||
HELPER FUNCTIONS START HERE
|
||||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
# HELPER FUNCTIONS START HERE
|
||||
|
||||
def order_clothes_list(clothes_list):
|
||||
"""
|
||||
|
|
@ -133,6 +131,7 @@ def order_clothes_list(clothes_list):
|
|||
ordered_clothes_list.insert(0, clothes)
|
||||
return ordered_clothes_list
|
||||
|
||||
|
||||
def get_worn_clothes(character, exclude_covered=False):
|
||||
"""
|
||||
Get a list of clothes worn by a given character.
|
||||
|
|
@ -153,7 +152,7 @@ def get_worn_clothes(character, exclude_covered=False):
|
|||
clothes_list = []
|
||||
for thing in character.contents:
|
||||
# If uncovered or not excluding covered items
|
||||
if not thing.db.covered_by or exclude_covered == False:
|
||||
if not thing.db.covered_by or exclude_covered is False:
|
||||
# If 'worn' is True, add to the list
|
||||
if thing.db.worn:
|
||||
clothes_list.append(thing)
|
||||
|
|
@ -161,6 +160,7 @@ def get_worn_clothes(character, exclude_covered=False):
|
|||
ordered_clothes_list = order_clothes_list(clothes_list)
|
||||
return ordered_clothes_list
|
||||
|
||||
|
||||
def clothing_type_count(clothes_list):
|
||||
"""
|
||||
Returns a dictionary of the number of each clothing type
|
||||
|
|
@ -186,6 +186,7 @@ def clothing_type_count(clothes_list):
|
|||
types_count[type] += 1
|
||||
return types_count
|
||||
|
||||
|
||||
def single_type_count(clothes_list, type):
|
||||
"""
|
||||
Returns an integer value of the number of a given type of clothing in a list.
|
||||
|
|
@ -205,6 +206,7 @@ def single_type_count(clothes_list, type):
|
|||
type_count += 1
|
||||
return type_count
|
||||
|
||||
|
||||
class Clothing(DefaultObject):
|
||||
|
||||
def wear(self, wearer, wearstyle, quiet=False):
|
||||
|
|
@ -230,7 +232,8 @@ class Clothing(DefaultObject):
|
|||
to_cover = []
|
||||
if self.db.clothing_type and self.db.clothing_type in CLOTHING_TYPE_AUTOCOVER:
|
||||
for garment in get_worn_clothes(wearer):
|
||||
if garment.db.clothing_type and garment.db.clothing_type in CLOTHING_TYPE_AUTOCOVER[self.db.clothing_type]:
|
||||
if garment.db.clothing_type and garment.db.clothing_type \
|
||||
in CLOTHING_TYPE_AUTOCOVER[self.db.clothing_type]:
|
||||
to_cover.append(garment)
|
||||
garment.db.covered_by = self
|
||||
# Return if quiet
|
||||
|
|
@ -238,7 +241,7 @@ class Clothing(DefaultObject):
|
|||
return
|
||||
# Echo a message to the room
|
||||
message = "%s puts on %s" % (wearer, self.name)
|
||||
if not wearstyle == True:
|
||||
if wearstyle is not True:
|
||||
message = "%s wears %s %s" % (wearer, self.name, wearstyle)
|
||||
if to_cover:
|
||||
message = message + ", covering %s" % list_to_string(to_cover)
|
||||
|
|
@ -278,6 +281,7 @@ class Clothing(DefaultObject):
|
|||
"""
|
||||
self.db.worn = False
|
||||
|
||||
|
||||
class ClothedCharacter(DefaultCharacter):
|
||||
"""
|
||||
Character that displays worn clothing when looked at. You can also
|
||||
|
|
@ -309,7 +313,7 @@ class ClothedCharacter(DefaultCharacter):
|
|||
# Append worn, uncovered clothing to the description
|
||||
for garment in clothes_list:
|
||||
# If 'worn' is True, just append the name
|
||||
if garment.db.worn == True:
|
||||
if garment.db.worn is True:
|
||||
worn_string_list.append(garment.name)
|
||||
# Otherwise, append the name and the string value of 'worn'
|
||||
elif garment.db.worn:
|
||||
|
|
@ -323,36 +327,8 @@ class ClothedCharacter(DefaultCharacter):
|
|||
string += "|/|/%s is not wearing anything." % self
|
||||
return string
|
||||
|
||||
"""
|
||||
----------------------------------------------------------------------------
|
||||
COMMANDS START HERE
|
||||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
class ClothedCharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
"""
|
||||
Command set for clothing, including new versions of 'give' and 'drop'
|
||||
that take worn and covered clothing into account, as well as a new
|
||||
version of 'inventory' that differentiates between carried and worn
|
||||
items.
|
||||
"""
|
||||
key = "DefaultCharacter"
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
"""
|
||||
Populates the cmdset
|
||||
"""
|
||||
super(ClothedCharacterCmdSet, self).at_cmdset_creation()
|
||||
#
|
||||
# any commands you add below will overload the default ones.
|
||||
#
|
||||
self.add(CmdWear())
|
||||
self.add(CmdRemove())
|
||||
self.add(CmdCover())
|
||||
self.add(CmdUncover())
|
||||
self.add(CmdGive())
|
||||
self.add(CmdDrop())
|
||||
self.add(CmdInventory())
|
||||
# COMMANDS START HERE
|
||||
|
||||
class CmdWear(MuxCommand):
|
||||
"""
|
||||
|
|
@ -414,6 +390,7 @@ class CmdWear(MuxCommand):
|
|||
wearstyle = wearstring
|
||||
clothing.wear(self.caller, wearstyle)
|
||||
|
||||
|
||||
class CmdRemove(MuxCommand):
|
||||
"""
|
||||
Takes off an item of clothing.
|
||||
|
|
@ -444,6 +421,7 @@ class CmdRemove(MuxCommand):
|
|||
return
|
||||
clothing.remove(self.caller)
|
||||
|
||||
|
||||
class CmdCover(MuxCommand):
|
||||
"""
|
||||
Covers a worn item of clothing with another you're holding or wearing.
|
||||
|
|
@ -497,10 +475,11 @@ class CmdCover(MuxCommand):
|
|||
self.caller.msg("%s is already covered by %s." % (cover_with.name, to_cover.db.covered_by.name))
|
||||
return
|
||||
if not cover_with.db.worn:
|
||||
cover_with.wear(self.caller, True) #Put on the item to cover with if it's not on already
|
||||
cover_with.wear(self.caller, True) # Put on the item to cover with if it's not on already
|
||||
self.caller.location.msg_contents("%s covers %s with %s." % (self.caller, to_cover.name, cover_with.name))
|
||||
to_cover.db.covered_by = cover_with
|
||||
|
||||
|
||||
class CmdUncover(MuxCommand):
|
||||
"""
|
||||
Reveals a worn item of clothing that's currently covered up.
|
||||
|
|
@ -542,6 +521,7 @@ class CmdUncover(MuxCommand):
|
|||
self.caller.location.msg_contents("%s uncovers %s." % (self.caller, to_uncover.name))
|
||||
to_uncover.db.covered_by = None
|
||||
|
||||
|
||||
class CmdDrop(MuxCommand):
|
||||
"""
|
||||
drop something
|
||||
|
|
@ -590,6 +570,7 @@ class CmdDrop(MuxCommand):
|
|||
# Call the object script's at_drop() method.
|
||||
obj.at_drop(caller)
|
||||
|
||||
|
||||
class CmdGive(MuxCommand):
|
||||
"""
|
||||
give away something to someone
|
||||
|
|
@ -638,6 +619,7 @@ class CmdGive(MuxCommand):
|
|||
# Call the object script's at_give() method.
|
||||
to_give.at_give(caller, target)
|
||||
|
||||
|
||||
class CmdInventory(MuxCommand):
|
||||
"""
|
||||
view inventory
|
||||
|
|
@ -679,3 +661,29 @@ class CmdInventory(MuxCommand):
|
|||
wear_table.add_row("|CNothing.|n", "")
|
||||
string += "|/|wYou are wearing:\n%s" % wear_table
|
||||
self.caller.msg(string)
|
||||
|
||||
|
||||
class ClothedCharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
"""
|
||||
Command set for clothing, including new versions of 'give' and 'drop'
|
||||
that take worn and covered clothing into account, as well as a new
|
||||
version of 'inventory' that differentiates between carried and worn
|
||||
items.
|
||||
"""
|
||||
key = "DefaultCharacter"
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
"""
|
||||
Populates the cmdset
|
||||
"""
|
||||
super(ClothedCharacterCmdSet, self).at_cmdset_creation()
|
||||
#
|
||||
# any commands you add below will overload the default ones.
|
||||
#
|
||||
self.add(CmdWear())
|
||||
self.add(CmdRemove())
|
||||
self.add(CmdCover())
|
||||
self.add(CmdUncover())
|
||||
self.add(CmdGive())
|
||||
self.add(CmdDrop())
|
||||
self.add(CmdInventory())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue