utils.py 918 B

12345678910111213141516171819202122232425262728293031323334
  1. from evennia.prototypes import spawner
  2. def has_tag(obj, key, category):
  3. return obj.tags.get(key=key, category=category) != None;
  4. def fmt_light(message):
  5. return "|r\u2600|y {} |r\u2600|n".format(message)
  6. def fmt_dark(message):
  7. return "|w\u2600|=h {} |w\u2600|n".format(message)
  8. def toggle_effect(obj, effect):
  9. if has_tag(obj, effect, "effect"):
  10. obj.tags.remove(effect, category="effect")
  11. else:
  12. obj.tags.add(effect, category="effect")
  13. def has_effect(obj, effect):
  14. return has_tag(obj, effect, "effect")
  15. def has_effect_in(obj, effects):
  16. return any(True for effect in effects if has_tag(obj, effect, "effect"))
  17. def indefinite_article(name):
  18. """Return the right english indefinite article for given name."""
  19. the_vowels = ["a","e","i","o","u"]
  20. value = ""
  21. if name[0].lower() in the_vowels:
  22. value = "an"
  23. else:
  24. value = "a"
  25. return value