mud_test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from mudsys import add_cmd
  2. import auxiliary
  3. import storage
  4. # Example auxiliary data class. Holds a single string variable that
  5. # people are allowed to get and set the value of
  6. class ExampleAux:
  7. # Create a new instance of the auxiliary data. If a storage set is supplied,
  8. # read our values from that
  9. def __init__(self, set = None):
  10. if not set:
  11. self.val = "abcxyz"
  12. else:
  13. self.val = set.readString("val")
  14. # copy the variables in this auxiliary data to another auxiliary data
  15. def copyTo(self, to):
  16. to.val = self.val
  17. # create a duplicate of this auxiliary data
  18. def copy(self):
  19. newVal = ExampleAux()
  20. newVal.val = self.val
  21. return newVal
  22. # returns a storage set representation of the auxiliary data
  23. def store(self):
  24. set = storage.StorageSet()
  25. set.storeString("val", self.val)
  26. return set
  27. # allows people to peek at the value stored in their ExampleAux data
  28. def cmd_getaux(ch, cmd, arg):
  29. aux = ch.account.getAuxiliary("example_aux")
  30. ch.send("The val is " + aux.val)
  31. # allows people to set the value stored in their ExampleAux data
  32. def cmd_setaux(ch, cmd, arg):
  33. aux = ch.account.getAuxiliary("example_aux")
  34. aux.val = arg
  35. ch.send("val set to " + arg)
  36. # install our auxiliary data on characters when this module is loaded.
  37. # auxiliary data can also be installed onto rooms and objects. You can install
  38. # auxiliary data onto more than one type of thing by comma-separating them in
  39. # the third argument of this method.
  40. auxiliary.install("example_aux", ExampleAux, "account")
  41. # add in our two commands
  42. add_cmd("getaux", None, cmd_getaux, "admin", False)
  43. add_cmd("setaux", None, cmd_setaux, "admin", False)