pets: Fix PetObserve
This commit is contained in:
parent
6ba9b959c9
commit
07b548a237
|
|
@ -1,200 +1,222 @@
|
||||||
from direct.directnotify import DirectNotifyGlobal
|
from direct.directnotify import DirectNotifyGlobal
|
||||||
from toontown.pets import PetTricks
|
from toontown.pets import PetTricks
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory('PetObserve')
|
notify = DirectNotifyGlobal.directNotify.newCategory('PetObserve')
|
||||||
|
|
||||||
|
"""
|
||||||
|
PetObserve
|
||||||
|
A PetObserve is something that pets should be able to observe. Examples
|
||||||
|
are things that avatars say, the fact that an avatar or pet is paying
|
||||||
|
attention to the pet, sounds, etc. PetObserves serve the function of the
|
||||||
|
senses, the eyes, ears, etc. of the pets.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# PetObserves are broadcast to all pets in a zone, or listening to that
|
||||||
|
# zone's event
|
||||||
def getEventName(zoneId):
|
def getEventName(zoneId):
|
||||||
return 'PetObserve-%s' % zoneId
|
return 'PetObserve-%s' % zoneId
|
||||||
|
|
||||||
|
|
||||||
def send(zoneIds, petObserve):
|
def send(zoneIds, petObserve):
|
||||||
if petObserve.isValid():
|
if petObserve.isValid():
|
||||||
|
#notify.debug('sending pet observe %s to %s' % (petObserve, zoneIds))
|
||||||
if type(zoneIds) not in (list, tuple):
|
if type(zoneIds) not in (list, tuple):
|
||||||
zoneIds = [zoneIds]
|
zoneIds = [zoneIds]
|
||||||
for zoneId in zoneIds:
|
for zoneId in zoneIds:
|
||||||
messenger.send(getEventName(zoneId), [petObserve])
|
messenger.send(getEventName(zoneId), [petObserve])
|
||||||
|
|
||||||
|
# spoken messages that pets understand; speedchat phrases map to one of these
|
||||||
Phrases = IntEnum('Phrases', ('HI', 'BYE', 'YES', 'NO', 'SOOTHE', 'PRAISE', 'CRITICISM', 'HAPPY', 'SAD', 'ANGRY', 'HURRY', 'QUESTION', 'FRIENDLY', 'LETS_PLAY', 'COME', 'FOLLOW_ME', 'STAY', 'NEED_LAFF', 'NEED_GAGS', 'NEED_JB', 'GO_AWAY', 'DO_TRICK'), start=0)
|
Phrases = IntEnum('Phrases', ('HI', 'BYE', 'YES', 'NO', 'SOOTHE', 'PRAISE', 'CRITICISM', 'HAPPY',
|
||||||
Actions = IntEnum('Actions', ('FEED', 'SCRATCH', 'ATTENDED_START', 'ATTENDED_STOP', 'ATTENDING_START', 'ATTENDING_STOP', 'CHANGE_ZONE', 'LOGOUT', 'GARDEN'), start=0)
|
'SAD', 'ANGRY', 'HURRY', 'QUESTION', 'FRIENDLY', 'LETS_PLAY',
|
||||||
|
'COME', 'FOLLOW_ME', 'STAY', 'NEED_LAFF', 'NEED_GAGS', 'NEED_JB',
|
||||||
|
'GO_AWAY', 'DO_TRICK',
|
||||||
|
), start=0)
|
||||||
|
# actions of other avatars that the pet can observe
|
||||||
|
Actions = IntEnum('Actions', ('FEED', 'SCRATCH',
|
||||||
|
'ATTENDED_START', 'ATTENDED_STOP',
|
||||||
|
'ATTENDING_START', 'ATTENDING_STOP',
|
||||||
|
'CHANGE_ZONE', 'LOGOUT',
|
||||||
|
'GARDEN'
|
||||||
|
), start=0)
|
||||||
|
|
||||||
class PetObserve:
|
class PetObserve:
|
||||||
|
# base class for all pet observes
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
|
# override this and return zero to prevent observe from being
|
||||||
|
# sent to pets
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def isForgettable(self):
|
def isForgettable(self):
|
||||||
|
# override this and return non-zero to enable Pets to forget
|
||||||
|
# this observation
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def _influence(self, petBrain):
|
def _influence(self, petBrain):
|
||||||
|
# override this and call the appropriate observe handler on the
|
||||||
|
# pet brain. This is here to avoid a fugly type-switch in the brain.
|
||||||
petBrain._handleGenericObserve(self)
|
petBrain._handleGenericObserve(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s()' % self.__class__.__name__
|
return '%s()' % self.__class__.__name__
|
||||||
|
|
||||||
|
|
||||||
class PetActionObserve(PetObserve):
|
class PetActionObserve(PetObserve):
|
||||||
|
"""An avatar or pet has done something that pets should take note of."""
|
||||||
def __init__(self, action, avId, data = None):
|
def __init__(self, action, avId, data=None):
|
||||||
self.action = action
|
self.action = action
|
||||||
self.avId = avId
|
self.avId = avId
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def getAction(self):
|
def getAction(self):
|
||||||
return self.action
|
return self.action
|
||||||
|
|
||||||
def getAvId(self):
|
def getAvId(self):
|
||||||
return self.avId
|
return self.avId
|
||||||
|
|
||||||
def getData(self):
|
def getData(self):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def _influence(self, petBrain):
|
def _influence(self, petBrain):
|
||||||
petBrain._handleActionObserve(self)
|
petBrain._handleActionObserve(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(%s,%s)' % (self.__class__.__name__, Actions.getString(self.action), self.avId)
|
return '%s(%s,%s)' % (
|
||||||
|
self.__class__.__name__,
|
||||||
|
Actions(self.action).name, self.avId)
|
||||||
|
|
||||||
class PetPhraseObserve(PetObserve):
|
class PetPhraseObserve(PetObserve):
|
||||||
|
"""An avatar is 'communicating' in a way that can be expressed with a
|
||||||
|
PetPhrase. This could be pressing a button on a pet panel, or saying
|
||||||
|
something in SpeedChat, etc."""
|
||||||
def __init__(self, petPhrase, avId):
|
def __init__(self, petPhrase, avId):
|
||||||
self.petPhrase = petPhrase
|
self.petPhrase = petPhrase
|
||||||
self.avId = avId
|
self.avId = avId
|
||||||
|
|
||||||
def getPetPhrase(self):
|
def getPetPhrase(self):
|
||||||
return self.petPhrase
|
return self.petPhrase
|
||||||
|
|
||||||
def getAvId(self):
|
def getAvId(self):
|
||||||
return self.avId
|
return self.avId
|
||||||
|
|
||||||
def isForgettable(self):
|
def isForgettable(self):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def _influence(self, petBrain):
|
def _influence(self, petBrain):
|
||||||
petBrain._handlePhraseObserve(self)
|
petBrain._handlePhraseObserve(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(%s,%s)' % (self.__class__.__name__, Phrases.getString(self.petPhrase), self.avId)
|
return '%s(%s,%s)' % (
|
||||||
|
self.__class__.__name__,
|
||||||
|
Phrases(self.petPhrase).name, self.avId)
|
||||||
|
|
||||||
class SCObserve(PetPhraseObserve):
|
class SCObserve(PetPhraseObserve):
|
||||||
|
# avatar said something in SpeedChat
|
||||||
def __init__(self, msgId, petPhrase, avId):
|
def __init__(self, msgId, petPhrase, avId):
|
||||||
self.msgId = msgId
|
self.msgId = msgId
|
||||||
PetPhraseObserve.__init__(self, petPhrase, avId)
|
PetPhraseObserve.__init__(self, petPhrase, avId)
|
||||||
|
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
return self.petPhrase is not None
|
return self.petPhrase is not None
|
||||||
|
|
||||||
|
|
||||||
class TrickRequestObserve(PetPhraseObserve):
|
class TrickRequestObserve(PetPhraseObserve):
|
||||||
|
# avatar requested that we do a trick
|
||||||
def __init__(self, trickId, avId):
|
def __init__(self, trickId, avId):
|
||||||
self.trickId = trickId
|
self.trickId = trickId
|
||||||
PetPhraseObserve.__init__(self, Phrases.DO_TRICK, avId)
|
PetPhraseObserve.__init__(self, Phrases.DO_TRICK, avId)
|
||||||
|
|
||||||
def isForgettable(self):
|
def isForgettable(self):
|
||||||
|
# this would just be annoying
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def getTrickId(self):
|
def getTrickId(self):
|
||||||
return self.trickId
|
return self.trickId
|
||||||
|
|
||||||
|
|
||||||
OP = Phrases
|
OP = Phrases
|
||||||
_scPhrase2petPhrase = {1: OP.YES,
|
_scPhrase2petPhrase = {
|
||||||
2: OP.NO,
|
1: OP.YES,
|
||||||
3: OP.SOOTHE,
|
2: OP.NO,
|
||||||
100: OP.HI,
|
3: OP.SOOTHE,
|
||||||
101: OP.HI,
|
100: OP.HI,
|
||||||
102: OP.HI,
|
101: OP.HI,
|
||||||
103: OP.HI,
|
102: OP.HI,
|
||||||
104: OP.HI,
|
103: OP.HI,
|
||||||
105: OP.HI,
|
104: OP.HI,
|
||||||
107: OP.HI,
|
105: OP.HI,
|
||||||
108: OP.HI,
|
107: OP.HI,
|
||||||
200: OP.BYE,
|
108: OP.HI,
|
||||||
201: OP.BYE,
|
200: OP.BYE,
|
||||||
202: OP.BYE,
|
201: OP.BYE,
|
||||||
203: OP.BYE,
|
202: OP.BYE,
|
||||||
204: OP.BYE,
|
203: OP.BYE,
|
||||||
205: OP.BYE,
|
204: OP.BYE,
|
||||||
206: OP.BYE,
|
205: OP.BYE,
|
||||||
207: OP.BYE,
|
206: OP.BYE,
|
||||||
300: OP.HAPPY,
|
207: OP.BYE,
|
||||||
301: OP.HAPPY,
|
300: OP.HAPPY,
|
||||||
302: OP.HAPPY,
|
301: OP.HAPPY,
|
||||||
303: OP.HAPPY,
|
302: OP.HAPPY,
|
||||||
304: OP.HAPPY,
|
303: OP.HAPPY,
|
||||||
305: OP.HAPPY,
|
304: OP.HAPPY,
|
||||||
306: OP.HAPPY,
|
305: OP.HAPPY,
|
||||||
307: OP.HAPPY,
|
306: OP.HAPPY,
|
||||||
308: OP.HAPPY,
|
307: OP.HAPPY,
|
||||||
309: OP.HAPPY,
|
308: OP.HAPPY,
|
||||||
310: OP.HAPPY,
|
309: OP.HAPPY,
|
||||||
311: OP.HAPPY,
|
310: OP.HAPPY,
|
||||||
312: OP.HAPPY,
|
311: OP.HAPPY,
|
||||||
313: OP.HAPPY,
|
312: OP.HAPPY,
|
||||||
314: OP.HAPPY,
|
313: OP.HAPPY,
|
||||||
315: OP.HAPPY,
|
314: OP.HAPPY,
|
||||||
400: OP.SAD,
|
315: OP.HAPPY,
|
||||||
401: OP.SAD,
|
400: OP.SAD,
|
||||||
402: OP.SAD,
|
401: OP.SAD,
|
||||||
403: OP.SAD,
|
402: OP.SAD,
|
||||||
404: OP.SAD,
|
403: OP.SAD,
|
||||||
405: OP.SAD,
|
404: OP.SAD,
|
||||||
406: OP.SAD,
|
405: OP.SAD,
|
||||||
407: OP.NO,
|
406: OP.SAD,
|
||||||
410: OP.NEED_LAFF,
|
407: OP.NO,
|
||||||
500: OP.FRIENDLY,
|
410: OP.NEED_LAFF,
|
||||||
505: OP.PRAISE,
|
500: OP.FRIENDLY,
|
||||||
506: OP.HAPPY,
|
505: OP.PRAISE,
|
||||||
507: OP.FRIENDLY,
|
506: OP.HAPPY,
|
||||||
508: OP.FRIENDLY,
|
507: OP.FRIENDLY,
|
||||||
509: OP.FRIENDLY,
|
508: OP.FRIENDLY,
|
||||||
510: OP.QUESTION,
|
509: OP.FRIENDLY,
|
||||||
511: OP.QUESTION,
|
510: OP.QUESTION,
|
||||||
513: OP.QUESTION,
|
511: OP.QUESTION,
|
||||||
514: OP.NEED_LAFF,
|
513: OP.QUESTION,
|
||||||
600: OP.PRAISE,
|
514: OP.NEED_LAFF,
|
||||||
601: OP.PRAISE,
|
600: OP.PRAISE,
|
||||||
602: OP.PRAISE,
|
601: OP.PRAISE,
|
||||||
603: OP.PRAISE,
|
602: OP.PRAISE,
|
||||||
700: OP.PRAISE,
|
603: OP.PRAISE,
|
||||||
701: OP.PRAISE,
|
700: OP.PRAISE,
|
||||||
900: OP.CRITICISM,
|
701: OP.PRAISE,
|
||||||
901: OP.CRITICISM,
|
900: OP.CRITICISM,
|
||||||
902: OP.CRITICISM,
|
901: OP.CRITICISM,
|
||||||
903: OP.CRITICISM,
|
902: OP.CRITICISM,
|
||||||
904: OP.CRITICISM,
|
903: OP.CRITICISM,
|
||||||
905: OP.CRITICISM,
|
904: OP.CRITICISM,
|
||||||
1006: OP.FOLLOW_ME,
|
905: OP.CRITICISM,
|
||||||
1007: OP.STAY,
|
1006: OP.FOLLOW_ME,
|
||||||
1010: OP.STAY,
|
1007: OP.STAY,
|
||||||
1015: OP.STAY,
|
1010: OP.STAY,
|
||||||
1201: OP.CRITICISM,
|
1015: OP.STAY,
|
||||||
1300: OP.NEED_LAFF,
|
1201: OP.CRITICISM,
|
||||||
1400: OP.HURRY,
|
1300: OP.NEED_LAFF,
|
||||||
1404: OP.PRAISE,
|
1400: OP.HURRY,
|
||||||
1405: OP.PRAISE,
|
1404: OP.PRAISE,
|
||||||
1413: OP.NEED_GAGS,
|
1405: OP.PRAISE,
|
||||||
1414: OP.NEED_LAFF,
|
1413: OP.NEED_GAGS,
|
||||||
1601: OP.NEED_JB,
|
1414: OP.NEED_LAFF,
|
||||||
1603: OP.HURRY,
|
1601: OP.NEED_JB,
|
||||||
1605: OP.LETS_PLAY,
|
1603: OP.HURRY,
|
||||||
1606: OP.LETS_PLAY,
|
1605: OP.LETS_PLAY,
|
||||||
21000: OP.COME,
|
1606: OP.LETS_PLAY,
|
||||||
21001: OP.COME,
|
21000: OP.COME,
|
||||||
21002: OP.STAY,
|
21001: OP.COME,
|
||||||
21003: OP.PRAISE,
|
21002: OP.STAY,
|
||||||
21004: OP.PRAISE,
|
21003: OP.PRAISE,
|
||||||
21005: OP.PRAISE}
|
21004: OP.PRAISE,
|
||||||
|
21005: OP.PRAISE,
|
||||||
|
}
|
||||||
|
# add the trick phrases
|
||||||
for scId in PetTricks.ScId2trickId:
|
for scId in PetTricks.ScId2trickId:
|
||||||
_scPhrase2petPhrase[scId] = OP.DO_TRICK
|
_scPhrase2petPhrase[scId] = OP.DO_TRICK
|
||||||
|
|
||||||
del OP
|
del OP
|
||||||
|
|
||||||
def getSCObserve(msgId, speakerDoId):
|
def getSCObserve(msgId, speakerDoId):
|
||||||
|
# given a speedchat msgId, returns the appropriate Observe object
|
||||||
|
|
||||||
|
# If the speedchat phrase doesn't have any PetPhrase equivalent,
|
||||||
|
# this will return None for the phrase.
|
||||||
phrase = _scPhrase2petPhrase.get(msgId)
|
phrase = _scPhrase2petPhrase.get(msgId)
|
||||||
if phrase == Phrases.DO_TRICK:
|
if phrase == Phrases.DO_TRICK:
|
||||||
trickId = PetTricks.ScId2trickId[msgId]
|
trickId = PetTricks.ScId2trickId[msgId]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue