Poodletooth-iLand/otp/avatar/DistributedPlayer.py

357 lines
13 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.showbase import PythonUtil
from direct.task import Task
from panda3d.core import *
2015-03-03 16:10:12 -06:00
import string
import time
from otp.ai.MagicWordGlobal import *
2015-05-30 11:28:28 -05:00
from otp.avatar import Avatar, PlayerBase, DistributedAvatar
2015-03-03 16:10:12 -06:00
from otp.avatar.Avatar import teleportNotify
2015-05-30 11:28:28 -05:00
from otp.chat import ChatGarbler, TalkAssistant
2015-03-03 16:10:12 -06:00
from otp.distributed.TelemetryLimited import TelemetryLimited
2015-05-30 11:28:28 -05:00
from otp.otpbase import OTPGlobals, OTPLocalizer
2015-03-03 16:10:12 -06:00
from otp.speedchat import SCDecoders
2015-06-24 12:19:10 -05:00
from otp.nametag.NametagConstants import *
from otp.margins.WhisperPopup import WhisperPopup
2015-03-03 16:10:12 -06:00
class DistributedPlayer(DistributedAvatar.DistributedAvatar, PlayerBase.PlayerBase, TelemetryLimited):
2015-05-30 11:28:28 -05:00
chatGarbler = ChatGarbler.ChatGarbler({'default': OTPLocalizer.ChatGarblerDefault})
2015-03-03 16:10:12 -06:00
def __init__(self, cr):
try:
self.DistributedPlayer_initialized
except:
self.DistributedPlayer_initialized = 1
DistributedAvatar.DistributedAvatar.__init__(self, cr)
TelemetryLimited.__init__(self)
self.__teleportAvailable = 0
self.inventory = None
self.experience = None
self.friendsList = []
self._districtWeAreGeneratedOn = None
self.DISLid = 0
self.adminAccess = 0
self.autoRun = 0
self.lastTeleportQuery = time.time()
@staticmethod
def GetPlayerGenerateEvent():
return 'DistributedPlayerGenerateEvent'
@staticmethod
def GetPlayerNetworkDeleteEvent():
return 'DistributedPlayerNetworkDeleteEvent'
@staticmethod
def GetPlayerDeleteEvent():
return 'DistributedPlayerDeleteEvent'
def networkDelete(self):
DistributedAvatar.DistributedAvatar.networkDelete(self)
messenger.send(self.GetPlayerNetworkDeleteEvent(), [self])
def disable(self):
DistributedAvatar.DistributedAvatar.disable(self)
messenger.send(self.GetPlayerDeleteEvent(), [self])
def delete(self):
try:
self.DistributedPlayer_deleted
except:
self.DistributedPlayer_deleted = 1
del self.experience
if self.inventory:
self.inventory.unload()
del self.inventory
DistributedAvatar.DistributedAvatar.delete(self)
def generate(self):
DistributedAvatar.DistributedAvatar.generate(self)
def announceGenerate(self):
DistributedAvatar.DistributedAvatar.announceGenerate(self)
messenger.send(self.GetPlayerGenerateEvent(), [self])
def setLocation(self, parentId, zoneId):
DistributedAvatar.DistributedAvatar.setLocation(self, parentId, zoneId)
if not (parentId in (0, None) and zoneId in (0, None)):
if not self.cr._isValidPlayerLocation(parentId, zoneId):
self.cr.disableDoId(self.doId)
self.cr.deleteObject(self.doId)
return None
def isGeneratedOnDistrict(self, districtId = None):
return True # fix for the task button
if districtId is None:
return self._districtWeAreGeneratedOn is not None
else:
return self._districtWeAreGeneratedOn == districtId
return
def getArrivedOnDistrictEvent(self, districtId = None):
if districtId is None:
return 'arrivedOnDistrict'
else:
return 'arrivedOnDistrict-%s' % districtId
return
def arrivedOnDistrict(self, districtId):
curFrameTime = globalClock.getFrameTime()
if hasattr(self, 'frameTimeWeArrivedOnDistrict') and curFrameTime == self.frameTimeWeArrivedOnDistrict:
if districtId == 0 and self._districtWeAreGeneratedOn:
self.notify.warning('ignoring arrivedOnDistrict 0, since arrivedOnDistrict %d occured on the same frame' % self._districtWeAreGeneratedOn)
return
self._districtWeAreGeneratedOn = districtId
self.frameTimeWeArrivedOnDistrict = globalClock.getFrameTime()
messenger.send(self.getArrivedOnDistrictEvent(districtId))
messenger.send(self.getArrivedOnDistrictEvent())
def setLeftDistrict(self):
self._districtWeAreGeneratedOn = None
return
def hasParentingRules(self):
if self is localAvatar:
return True
2015-06-24 12:19:10 -05:00
def setSystemMessage(self, aboutId, chatString, whisperType = WhisperPopup.WTSystem):
2015-03-03 16:10:12 -06:00
self.displayWhisper(aboutId, chatString, whisperType)
def displayWhisper(self, fromId, chatString, whisperType):
print 'Whisper type %s from %s: %s' % (whisperType, fromId, chatString)
2015-04-23 12:55:47 -05:00
def whisperSCTo(self, msgIndex, sendToId):
2015-03-03 16:10:12 -06:00
messenger.send('wakeup')
base.cr.ttsFriendsManager.d_whisperSCTo(sendToId, msgIndex)
2015-03-03 16:10:12 -06:00
def setWhisperSCFrom(self, fromId, msgIndex):
handle = base.cr.identifyAvatar(fromId)
2015-04-07 13:43:25 -05:00
if handle == None or base.localAvatar.isIgnored(fromId):
2015-03-03 16:10:12 -06:00
return
chatString = SCDecoders.decodeSCStaticTextMsg(msgIndex)
if chatString:
2015-06-24 12:19:10 -05:00
self.displayWhisper(fromId, chatString, WhisperPopup.WTNormal)
2015-03-03 16:10:12 -06:00
return
2015-04-23 12:55:47 -05:00
def whisperSCCustomTo(self, msgIndex, sendToId):
2015-03-03 16:10:12 -06:00
messenger.send('wakeup')
base.cr.ttsFriendsManager.d_whisperSCCustomTo(sendToId, msgIndex)
2015-03-03 16:10:12 -06:00
def _isValidWhisperSource(self, source):
return True
def setWhisperSCCustomFrom(self, fromId, msgIndex):
handle = base.cr.identifyAvatar(fromId)
if handle == None:
return
if not self._isValidWhisperSource(handle):
self.notify.warning('displayWhisper from non-toon %s' % fromId)
return
2015-04-07 13:43:25 -05:00
if base.localAvatar.isIgnored(fromId):
2015-03-03 16:10:12 -06:00
return
chatString = SCDecoders.decodeSCCustomMsg(msgIndex)
if chatString:
2015-06-24 12:19:10 -05:00
self.displayWhisper(fromId, chatString, WhisperPopup.WTNormal)
2015-03-03 16:10:12 -06:00
2015-04-23 12:55:47 -05:00
def whisperSCEmoteTo(self, emoteId, sendToId):
2015-03-03 16:10:12 -06:00
messenger.send('wakeup')
base.cr.ttsFriendsManager.d_whisperSCEmoteTo(sendToId, emoteId)
2015-03-03 16:10:12 -06:00
def setWhisperSCEmoteFrom(self, fromId, emoteId):
handle = base.cr.identifyAvatar(fromId)
2015-04-07 13:43:25 -05:00
if handle == None or base.localAvatar.isIgnored(fromId):
2015-03-03 16:10:12 -06:00
return
chatString = SCDecoders.decodeSCEmoteWhisperMsg(emoteId, handle.getName())
if chatString:
2015-06-24 12:19:10 -05:00
self.displayWhisper(fromId, chatString, WhisperPopup.WTEmote)
2015-03-03 16:10:12 -06:00
return
def setChatAbsolute(self, chatString, chatFlags, dialogue = None, interrupt = 1, quiet = 0):
DistributedAvatar.DistributedAvatar.setChatAbsolute(self, chatString, chatFlags, dialogue, interrupt)
if not quiet:
pass
2015-05-30 12:46:06 -05:00
def setTalk(self, chat):
2015-05-30 13:50:36 -05:00
if not base.cr.chatAgent.verifyMessage(chat):
2015-05-24 11:04:49 -05:00
return
2015-05-30 12:46:06 -05:00
if base.localAvatar.isIgnored(self.doId):
2015-04-07 13:43:25 -05:00
return
2015-05-30 14:02:08 -05:00
if not self.understandable:
chat = self.chatGarbler.garble(self, len(chat.split(' ')))
2015-05-30 14:02:08 -05:00
elif base.whiteList and self.understandable < 2:
2015-05-30 13:50:36 -05:00
chat = base.whiteList.processThroughAll(chat, self, self.chatGarbler)
2015-05-30 12:46:06 -05:00
self.displayTalk(chat)
2015-03-03 16:10:12 -06:00
2015-05-30 12:46:06 -05:00
def setTalkWhisper(self, avId, chat):
2015-05-30 13:50:36 -05:00
if not base.cr.chatAgent.verifyMessage(chat):
2015-05-24 11:04:49 -05:00
return
2015-05-30 12:46:06 -05:00
if base.localAvatar.isIgnored(avId):
2015-04-07 13:43:25 -05:00
return
if not self.understandable:
chat = self.chatGarbler.garble(self, len(chat.split(' ')))
elif base.whiteList and self.understandable < 2:
2015-06-04 11:24:47 -05:00
chat = base.whiteList.processThroughAll(chat, self.chatGarbler)
2015-05-30 12:46:06 -05:00
self.displayTalkWhisper(avId, chat)
2015-03-03 16:10:12 -06:00
2015-05-30 12:46:06 -05:00
def displayTalk(self, chat):
print 'Talk: %s' % chat
def displayTalkWhisper(self, avId, chat):
print 'TalkWhisper from %s: %s' % (avId, chat)
2015-03-03 16:10:12 -06:00
def b_setSC(self, msgIndex):
self.setSC(msgIndex)
self.d_setSC(msgIndex)
def d_setSC(self, msgIndex):
messenger.send('wakeup')
self.sendUpdate('setSC', [msgIndex])
def setSC(self, msgIndex):
2015-04-07 13:43:25 -05:00
if base.localAvatar.isIgnored(self.doId):
2015-03-03 16:10:12 -06:00
return
chatString = SCDecoders.decodeSCStaticTextMsg(msgIndex)
if chatString:
self.setChatAbsolute(chatString, CFSpeech | CFQuicktalker | CFTimeout, quiet=1)
def b_setSCCustom(self, msgIndex):
self.setSCCustom(msgIndex)
self.d_setSCCustom(msgIndex)
def d_setSCCustom(self, msgIndex):
messenger.send('wakeup')
self.sendUpdate('setSCCustom', [msgIndex])
def setSCCustom(self, msgIndex):
2015-04-07 13:43:25 -05:00
if base.localAvatar.isIgnored(self.doId):
2015-03-03 16:10:12 -06:00
return
chatString = SCDecoders.decodeSCCustomMsg(msgIndex)
if chatString:
self.setChatAbsolute(chatString, CFSpeech | CFQuicktalker | CFTimeout)
def b_setSCEmote(self, emoteId):
self.b_setEmoteState(emoteId, animMultiplier=self.animMultiplier)
def d_friendsNotify(self, avId, status):
self.sendUpdate('friendsNotify', [avId, status])
def friendsNotify(self, avId, status):
avatar = base.cr.identifyFriend(avId)
if avatar != None:
if status == 1:
self.setSystemMessage(avId, OTPLocalizer.WhisperNoLongerFriend % avatar.getName())
elif status == 2:
self.setSystemMessage(avId, OTPLocalizer.WhisperNowSpecialFriend % avatar.getName())
return
def d_teleportQuery(self, requesterId, sendToId = None):
lastQuery = self.lastTeleportQuery
currentQuery = time.time()
if currentQuery - lastQuery < 0.1: # Oh boy! We found a skid!
self.cr.stopReaderPollTask()
self.cr.lostConnection()
self.lastTeleportQuery = time.time()
base.cr.ttsFriendsManager.d_teleportQuery(sendToId)
2015-03-03 16:10:12 -06:00
def teleportQuery(self, requesterId):
2015-04-23 17:18:16 -05:00
avatar = base.cr.identifyFriend(requesterId)
2015-04-23 17:18:16 -05:00
if avatar is None:
self.d_teleportResponse(self.doId, 0, 0, 0, 0, sendToId=requesterId)
elif base.localAvatar.isIgnored(requesterId):
self.d_teleportResponse(self.doId, 2, 0, 0, 0, sendToId=requesterId)
elif hasattr(base, 'distributedParty') and ((base.distributedParty.partyInfo.isPrivate and requesterId not in base.distributedParty.inviteeIds) or base.distributedParty.isPartyEnding):
self.d_teleportResponse(self.doId, 0, 0, 0, 0, sendToId=requesterId)
elif self.__teleportAvailable and not self.ghostMode:
self.setSystemMessage(requesterId, OTPLocalizer.WhisperComingToVisit % avatar.getName())
messenger.send('teleportQuery', [avatar, self])
else:
2015-05-31 06:24:17 -05:00
self.setSystemMessage(requesterId, OTPLocalizer.WhisperFailedVisit % avatar.getName())
2015-04-23 17:18:16 -05:00
self.d_teleportResponse(self.doId, 0, 0, 0, 0, sendToId=requesterId)
2015-03-03 16:10:12 -06:00
def d_teleportResponse(self, avId, available, shardId, hoodId, zoneId, sendToId):
teleportNotify.debug('sending teleportResponse%s' % ((avId, available,
shardId, hoodId, zoneId, sendToId),)
)
base.cr.ttsFriendsManager.d_teleportResponse(sendToId, available,
2015-03-03 16:10:12 -06:00
shardId, hoodId, zoneId
)
def teleportResponse(self, avId, available, shardId, hoodId, zoneId):
teleportNotify.debug('received teleportResponse%s' % ((avId, available,
shardId, hoodId, zoneId),)
)
messenger.send('teleportResponse', [avId, available, shardId, hoodId, zoneId])
def d_teleportGiveup(self, requesterId, sendToId):
teleportNotify.debug('sending teleportGiveup(%s) to %s' % (requesterId, sendToId))
base.cr.ttsFriendsManager.d_teleportGiveup(sendToId)
2015-03-03 16:10:12 -06:00
def teleportGiveup(self, requesterId):
teleportNotify.debug('received teleportGiveup(%s)' % (requesterId,))
avatar = base.cr.identifyAvatar(requesterId)
if not self._isValidWhisperSource(avatar):
self.notify.warning('teleportGiveup from non-toon %s' % requesterId)
return
if avatar is not None:
self.setSystemMessage(requesterId,
OTPLocalizer.WhisperGiveupVisit % avatar.getName()
)
def b_teleportGreeting(self, avId):
if hasattr(self, 'ghostMode') and self.ghostMode:
return
self.d_teleportGreeting(avId)
self.teleportGreeting(avId)
def d_teleportGreeting(self, avId):
self.sendUpdate('teleportGreeting', [avId])
def teleportGreeting(self, avId):
avatar = base.cr.getDo(avId)
if isinstance(avatar, Avatar.Avatar):
self.setChatAbsolute(OTPLocalizer.TeleportGreeting % avatar.getName(), CFSpeech | CFTimeout)
elif avatar is not None:
self.notify.warning('got teleportGreeting from %s referencing non-toon %s' % (self.doId, avId))
return
def setTeleportAvailable(self, available):
self.__teleportAvailable = available
def getTeleportAvailable(self):
return self.__teleportAvailable
def getFriendsList(self):
return self.friendsList
def setFriendsList(self, friendsList):
self.friendsList = friendsList
messenger.send('friendsListChanged')
Avatar.reconsiderAllUnderstandable()
def setDISLid(self, id):
self.DISLid = id
def setAdminAccess(self, access):
self.adminAccess = access
2015-06-02 12:07:50 -05:00
self.considerUnderstandable()
2015-03-03 16:10:12 -06:00
def getAdminAccess(self):
return self.adminAccess
2015-06-02 12:07:50 -05:00
def isAdmin(self):
return self.adminAccess >= MINIMUM_MAGICWORD_ACCESS
2015-03-03 16:10:12 -06:00
def setAutoRun(self, value):
self.autoRun = value
def getAutoRun(self):
return self.autoRun