pets: Fix PetObserve
This commit is contained in:
parent
6ba9b959c9
commit
07b548a237
|
|
@ -1,108 +1,125 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from toontown.pets import PetTricks
|
||||
from enum import IntEnum
|
||||
|
||||
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):
|
||||
return 'PetObserve-%s' % zoneId
|
||||
|
||||
|
||||
def send(zoneIds, petObserve):
|
||||
if petObserve.isValid():
|
||||
#notify.debug('sending pet observe %s to %s' % (petObserve, zoneIds))
|
||||
if type(zoneIds) not in (list, tuple):
|
||||
zoneIds = [zoneIds]
|
||||
for zoneId in zoneIds:
|
||||
messenger.send(getEventName(zoneId), [petObserve])
|
||||
|
||||
|
||||
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)
|
||||
Actions = IntEnum('Actions', ('FEED', 'SCRATCH', 'ATTENDED_START', 'ATTENDED_STOP', 'ATTENDING_START', 'ATTENDING_STOP', 'CHANGE_ZONE', 'LOGOUT', 'GARDEN'), start=0)
|
||||
# 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)
|
||||
# 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:
|
||||
|
||||
# base class for all pet observes
|
||||
def isValid(self):
|
||||
# override this and return zero to prevent observe from being
|
||||
# sent to pets
|
||||
return 1
|
||||
|
||||
def isForgettable(self):
|
||||
# override this and return non-zero to enable Pets to forget
|
||||
# this observation
|
||||
return 0
|
||||
|
||||
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)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s()' % self.__class__.__name__
|
||||
|
||||
|
||||
class PetActionObserve(PetObserve):
|
||||
|
||||
def __init__(self, action, avId, data = None):
|
||||
"""An avatar or pet has done something that pets should take note of."""
|
||||
def __init__(self, action, avId, data=None):
|
||||
self.action = action
|
||||
self.avId = avId
|
||||
self.data = data
|
||||
|
||||
def getAction(self):
|
||||
return self.action
|
||||
|
||||
def getAvId(self):
|
||||
return self.avId
|
||||
|
||||
def getData(self):
|
||||
return self.data
|
||||
|
||||
def _influence(self, petBrain):
|
||||
petBrain._handleActionObserve(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):
|
||||
|
||||
"""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):
|
||||
self.petPhrase = petPhrase
|
||||
self.avId = avId
|
||||
|
||||
def getPetPhrase(self):
|
||||
return self.petPhrase
|
||||
|
||||
def getAvId(self):
|
||||
return self.avId
|
||||
|
||||
def isForgettable(self):
|
||||
return 1
|
||||
|
||||
def _influence(self, petBrain):
|
||||
petBrain._handlePhraseObserve(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):
|
||||
|
||||
# avatar said something in SpeedChat
|
||||
def __init__(self, msgId, petPhrase, avId):
|
||||
self.msgId = msgId
|
||||
PetPhraseObserve.__init__(self, petPhrase, avId)
|
||||
|
||||
def isValid(self):
|
||||
return self.petPhrase is not None
|
||||
|
||||
|
||||
class TrickRequestObserve(PetPhraseObserve):
|
||||
|
||||
# avatar requested that we do a trick
|
||||
def __init__(self, trickId, avId):
|
||||
self.trickId = trickId
|
||||
PetPhraseObserve.__init__(self, Phrases.DO_TRICK, avId)
|
||||
|
||||
def isForgettable(self):
|
||||
# this would just be annoying
|
||||
return 0
|
||||
|
||||
def getTrickId(self):
|
||||
return self.trickId
|
||||
|
||||
|
||||
OP = Phrases
|
||||
_scPhrase2petPhrase = {1: OP.YES,
|
||||
_scPhrase2petPhrase = {
|
||||
1: OP.YES,
|
||||
2: OP.NO,
|
||||
3: OP.SOOTHE,
|
||||
100: OP.HI,
|
||||
|
|
@ -188,13 +205,18 @@ _scPhrase2petPhrase = {1: OP.YES,
|
|||
21002: OP.STAY,
|
||||
21003: OP.PRAISE,
|
||||
21004: OP.PRAISE,
|
||||
21005: OP.PRAISE}
|
||||
21005: OP.PRAISE,
|
||||
}
|
||||
# add the trick phrases
|
||||
for scId in PetTricks.ScId2trickId:
|
||||
_scPhrase2petPhrase[scId] = OP.DO_TRICK
|
||||
|
||||
del OP
|
||||
|
||||
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)
|
||||
if phrase == Phrases.DO_TRICK:
|
||||
trickId = PetTricks.ScId2trickId[msgId]
|
||||
|
|
|
|||
Loading…
Reference in New Issue