pets: Fix PetObserve
This commit is contained in:
parent
6ba9b959c9
commit
07b548a237
|
|
@ -1,108 +1,125 @@
|
||||||
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 = {
|
||||||
|
1: OP.YES,
|
||||||
2: OP.NO,
|
2: OP.NO,
|
||||||
3: OP.SOOTHE,
|
3: OP.SOOTHE,
|
||||||
100: OP.HI,
|
100: OP.HI,
|
||||||
|
|
@ -188,13 +205,18 @@ _scPhrase2petPhrase = {1: OP.YES,
|
||||||
21002: OP.STAY,
|
21002: OP.STAY,
|
||||||
21003: OP.PRAISE,
|
21003: OP.PRAISE,
|
||||||
21004: OP.PRAISE,
|
21004: OP.PRAISE,
|
||||||
21005: 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