Mass and weight for objects¶
# inside your mygame/typeclasses/objects.py class Object(DefaultObject): # [...] def get_mass(self): mass = self.attributes.get('mass', 1) # Default objects have 1 unit mass. return mass + sum(obj.get_mass() for obj in self.contents)
get_massdefinition to the objects you want to sum up the masses for is done with
mass[[Attributes]] of the objects.
Characters and rooms¶
You can add a
get_mass definition to characters and rooms, also.
If you were in a one metric-ton elevator with four other friends also wearing armor and carrying gold bricks, you might wonder if this elevator’s going to move, and how fast.
@set elevator/mass=1000000, we’re
@set me/mass=85000and our armor is
@set gold bar/mass=12400then step into the elevator and see
Elevator weight and contents should not exceed 3 metric tons.Are we safe? Maybe not if you consider dynamic loading. But at rest:
# Elevator object knows when it checks itself: if self.get_mass() < 3000000: pass # Elevator functions as normal. else: pass # Danger! Alarm sounds, cable snaps, elevator stops...
Example of listing mass of items in your inventory:
class CmdInventory(MuxCommand): """ view inventory Usage: inventory inv Switches: /weight to display all available channels. Shows your inventory: carrying, wielding, wearing, obscuring. """ key = "inventory" aliases = ["inv", "i"] locks = "cmd:all()" def func(self): "check inventory" items = self.caller.contents if not items: string = "You are not carrying anything." else: table = prettytable.PrettyTable(["name", "desc"]) table.header = False table.border = False for item in items: second = item.get_mass() \ if 'weight' in self.switches else item.db.desc table.add_row(["%s" % item.get_display_name(self.caller.sessions), second and second or ""]) string = "|wYou are carrying:\n%s" % table self.caller.msg(string)