Poodletooth-iLand/otp/ai/MagicWordManager.py

44 lines
1.4 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed import DistributedObject
from otp.ai.MagicWordGlobal import *
lastClickedNametag = None
class MagicWordManager(DistributedObject.DistributedObject):
notify = DirectNotifyGlobal.directNotify.newCategory('MagicWordManager')
neverDisable = 1
def generate(self):
DistributedObject.DistributedObject.generate(self)
self.accept('magicWord', self.handleMagicWord)
def disable(self):
self.ignore('magicWord')
DistributedObject.DistributedObject.disable(self)
def handleMagicWord(self, magicWord):
2015-08-13 15:06:19 -05:00
if not base.localAvatar.isAdmin():
return
2015-03-03 16:10:12 -06:00
if magicWord.startswith('~~'):
if lastClickedNametag == None:
target = base.localAvatar
else:
target = lastClickedNametag
magicWord = magicWord[2:]
if magicWord.startswith('~'):
target = base.localAvatar
magicWord = magicWord[1:]
targetId = target.doId
self.sendUpdate('sendMagicWord', [magicWord, targetId])
2015-08-13 15:06:19 -05:00
2015-03-03 16:10:12 -06:00
if target == base.localAvatar:
response = spellbook.process(base.localAvatar, target, magicWord)
if response:
self.sendMagicWordResponse(response)
def sendMagicWordResponse(self, response):
self.notify.info(response)
base.localAvatar.setSystemMessage(0, 'Spellbook: ' + str(response))