From 46e7a352b630de34334846801f2dad5c5ae5cfed Mon Sep 17 00:00:00 2001 From: Open Toontown Date: Sat, 2 Nov 2019 21:22:48 -0400 Subject: [PATCH] general: loads to a connecting screen! --- etc/Configrc.prc | 3 + libtoontown/__init__.py | 4 + libtoontown/pets/CPetBrain.py | 35 ++++++++ libtoontown/pets/CPetChase.py | 81 +++++++++++++++++++ libtoontown/pets/CPetFlee.py | 66 +++++++++++++++ libtoontown/pets/__init__.py | 0 otp/ai/MagicWordManager.py | 2 +- otp/otpbase/ObjectCount.py | 48 +++++++++++ otp/otpbase/PythonUtil.py | 36 +++++++++ toontown/ai/CrashedLeaderBoardDecorator.py | 3 +- toontown/ai/HalloweenHolidayDecorator.py | 3 +- toontown/ai/HolidayDecorator.py | 3 +- toontown/coghq/DinerStatusIndicator.py | 4 +- .../distributed/ToontownClientRepository.py | 2 +- toontown/minigame/SwingVine.py | 2 +- toontown/minigame/VineBat.py | 2 +- toontown/minigame/VineSpider.py | 2 +- toontown/minigame/VoteResultsTrolleyPanel.py | 2 +- .../parties/DistributedPartyCannonActivity.py | 2 +- toontown/quest/QuestParser.py | 10 +-- toontown/suit/DistributedBossbotBoss.py | 3 +- toontown/toon/DistributedNPCPartyPerson.py | 3 +- toontown/uberdog/DistributedPartyManager.py | 2 +- 23 files changed, 295 insertions(+), 23 deletions(-) create mode 100644 libtoontown/__init__.py create mode 100644 libtoontown/pets/CPetBrain.py create mode 100644 libtoontown/pets/CPetChase.py create mode 100644 libtoontown/pets/CPetFlee.py create mode 100644 libtoontown/pets/__init__.py create mode 100644 otp/otpbase/ObjectCount.py diff --git a/etc/Configrc.prc b/etc/Configrc.prc index 52371e6..2fdc8ad 100644 --- a/etc/Configrc.prc +++ b/etc/Configrc.prc @@ -97,3 +97,6 @@ audio-music-active #t audio-master-sfx-volume 1 audio-master-music-volume 1 server-type prod + +# TEMP +fake-playtoken dev diff --git a/libtoontown/__init__.py b/libtoontown/__init__.py new file mode 100644 index 0000000..ceb1915 --- /dev/null +++ b/libtoontown/__init__.py @@ -0,0 +1,4 @@ +from libpandadna import * +from pets.CPetBrain import CPetBrain +from pets.CPetChase import CPetChase +from pets.CPetFlee import CPetFlee diff --git a/libtoontown/pets/CPetBrain.py b/libtoontown/pets/CPetBrain.py new file mode 100644 index 0000000..73c811c --- /dev/null +++ b/libtoontown/pets/CPetBrain.py @@ -0,0 +1,35 @@ +import math + +from direct.directnotify import DirectNotifyGlobal +from panda3d.core import * + + +class CPetBrain: + notify = DirectNotifyGlobal.directNotify.newCategory('CPetBrain') + + def __init__(self): + pass + + @staticmethod + def isAttendingUs(pathA, pathB): + v4 = pathB.getPos(pathA) + pathAB = ((v4[1] * v4[1]) + (v4[0] * v4[0]) + (v4[2] * v4[2])) + if not (pathAB > 100.0): + return True + + v6 = pathA.getPos(pathB) + pathAA = ((v6[1] * v6[1]) + (v6[0] * v6[0]) + (v6[2] * v6[2])) + if pathAA == 0.0: + v6 = Vec3(0, 0, 0) + else: + pathAB = pathAA - 1.0 + if pathAB >= 9.999999949504854e-13 or pathAB <= -9.999999949504854e-13: + pathAD = 1.0 / math.sqrt(pathAA) + v6 *= pathAD + + v8 = Vec3.forward() + pathAC = ((v8[1] * v6[1]) + (v8[0] * v6[0]) + (v8[2] * v6[2])) + if pathAC < 0.8: + return True + else: + return False diff --git a/libtoontown/pets/CPetChase.py b/libtoontown/pets/CPetChase.py new file mode 100644 index 0000000..8b42a7d --- /dev/null +++ b/libtoontown/pets/CPetChase.py @@ -0,0 +1,81 @@ +import math + +from direct.directnotify import DirectNotifyGlobal +from direct.showbase.PythonUtil import reduceAngle +from panda3d.core import * + +from libotp import * + + +class CPetChase(CImpulse): + notify = DirectNotifyGlobal.directNotify.newCategory('CPetChase') + + def __init__(self, target=None, minDist=None, moveAngle=None): + CImpulse.__init__(self) + self.target = target + if minDist is None: + minDist = 5.0 + self.minDist = minDist + if moveAngle is None: + moveAngle = 20.0 + self.moveAngle = moveAngle + self.lookAtNode = NodePath('lookatNode') + self.lookAtNode.hide() + self.vel = None + self.rotVel = None + + def setTarget(self, target): + self.target = target + + def getTarget(self): + return self.target + + def setMinDist(self, minDist): + self.minDist = minDist + + def destroy(self): + self.lookAtNode.removeNode() + del self.lookAtNode + del self.target + del self.vel + del self.rotVel + + def setMover(self, mover): + CImpulse.setMover(self, mover) + self.lookAtNode.reparentTo(self.nodePath) + self.vel = self.VecType(0) + self.rotVel = self.VecType(0) + + def process(self, dt): + CImpulse.process(self, dt) + me = self.nodePath + target = self.target + targetPos = target.getPos(me) + x = targetPos[0] + y = targetPos[1] + distance = math.sqrt(x * x + y * y) + self.lookAtNode.lookAt(target) + relH = reduceAngle(self.lookAtNode.getH(me)) + epsilon = 0.005 + rotSpeed = self.mover.getRotSpeed() + if relH < -epsilon: + vH = -rotSpeed + elif relH > epsilon: + vH = rotSpeed + else: + vH = 0 + if abs(vH * dt) > abs(relH): + vH = relH / dt + if distance > self.minDist and abs(relH) < self.moveAngle: + vForward = self.mover.getFwdSpeed() + else: + vForward = 0 + distanceLeft = distance - self.minDist + if distance > self.minDist and vForward * dt > distanceLeft: + vForward = distanceLeft / dt + if vForward: + self.vel.setY(vForward) + self.mover.addShove(self.vel) + if vH: + self.rotVel.setX(vH) + self.mover.addRotShove(self.rotVel) diff --git a/libtoontown/pets/CPetFlee.py b/libtoontown/pets/CPetFlee.py new file mode 100644 index 0000000..bd62804 --- /dev/null +++ b/libtoontown/pets/CPetFlee.py @@ -0,0 +1,66 @@ +from direct.directnotify import DirectNotifyGlobal +from direct.showbase.PythonUtil import reduceAngle +from panda3d.core import * + +from libotp import * + + +class CPetFlee(CImpulse): + notify = DirectNotifyGlobal.directNotify.newCategory('CPetFlee') + + def __init__(self, chaser=None, maxDist=50.0, moveAngle=20.0): + CImpulse.__init__(self) + self.chaser = chaser + self.maxDist = maxDist + self.moveAngle = moveAngle + self.lookAtNode = NodePath('lookatNode') + self.lookAtNode.hide() + self.vel = None + self.rotVel = None + + def destroy(self): + self.lookAtNode.removeNode() + del self.lookAtNode + del self.chaser + del self.vel + del self.rotVel + + def setChaser(self, chaser): + self.chaser = chaser + + def _setMover(self, mover): + CImpulse._setMover(self, mover) + self.lookAtNode.reparentTo(self.nodePath) + self.vel = self.VecType(0) + self.rotVel = self.VecType(0) + + def _process(self, dt): + CImpulse._process(self, dt) + me = self.nodePath + chaser = self.chaser + chaserPos = chaser.getPos(me) + chaserPos.setZ(0) + distance = self.VecType(chaserPos).length() + self.lookAtNode.lookAt(chaser) + relH = reduceAngle(self.lookAtNode.getH(me) + 180.0) + epsilon = 0.005 + rotSpeed = self.mover.getRotSpeed() + if relH < -epsilon: + vH = -rotSpeed + elif relH > epsilon: + vH = rotSpeed + else: + vH = 0 + if abs(vH * dt) > abs(relH): + vH = relH / dt + if distance < self.maxDist and abs(relH) < self.moveAngle: + vForward = self.mover.getFwdSpeed() + else: + vForward = 0 + distanceLeft = self.maxDist - distance + if distanceLeft > 0.0 and vForward * dt > distanceLeft: + vForward = distanceLeft / dt + self.vel.setY(vForward) + self.rotVel.setX(vH) + self.mover.addShove(self.vel) + self.mover.addRotShove(self.rotVel) diff --git a/libtoontown/pets/__init__.py b/libtoontown/pets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/otp/ai/MagicWordManager.py b/otp/ai/MagicWordManager.py index 6a38b76..134940d 100644 --- a/otp/ai/MagicWordManager.py +++ b/otp/ai/MagicWordManager.py @@ -3,7 +3,7 @@ from direct.showbase import GarbageReport, ContainerReport, MessengerLeakDetecto from direct.distributed import DistributedObject from direct.directnotify import DirectNotifyGlobal from direct.showbase.InputStateGlobal import inputState -from direct.showbase.ObjectCount import ObjectCount +from otp.otpbase.ObjectCount import ObjectCount from direct.task import Task from direct.task.TaskProfiler import TaskProfiler from otp.avatar import Avatar diff --git a/otp/otpbase/ObjectCount.py b/otp/otpbase/ObjectCount.py new file mode 100644 index 0000000..94bdf55 --- /dev/null +++ b/otp/otpbase/ObjectCount.py @@ -0,0 +1,48 @@ +from direct.showbase.Job import Job +import gc + +class ObjectCount(Job): + """ logs a count of the number of each type of object found in gc.get_objects() """ + def __init__(self, name, immediate=False, doneCallback=None): + Job.__init__(self, name) + self._doneCallback = doneCallback + jobMgr.add(self) + if immediate: + jobMgr.finish(self) + + def destroy(self): + self._doneCallback = None + Job.destroy(self) + + def finished(self): + if self._doneCallback: + self._doneCallback(self) + self.destroy() + + def run(self): + objs = gc.get_objects() + yield None + type2count = {} + for obj in objs: + tn = safeTypeName(obj) + type2count.setdefault(tn, 0) + type2count[tn] += 1 + yield None + # prevent garbage cycle + del objs + yield None + count2type = invertDictLossless(type2count) + yield None + counts = count2type.keys() + yield None + counts.sort() + yield None + counts.reverse() + yield None + print '===== ObjectCount: \'%s\' =====' % (self.getJobName()) + for count in counts: + types = count2type[count] + for type in types: + print '%s: %s' % (count, type) + yield None + yield Job.Done diff --git a/otp/otpbase/PythonUtil.py b/otp/otpbase/PythonUtil.py index 758dcaf..f7dcf7e 100644 --- a/otp/otpbase/PythonUtil.py +++ b/otp/otpbase/PythonUtil.py @@ -1,3 +1,5 @@ +import __builtin__ + # class 'decorator' that records the stack at the time of creation # be careful with this, it creates a StackTrace, and that can take a # lot of CPU @@ -19,3 +21,37 @@ def recordCreationStack(cls): cls.getCreationStackTraceCompactStr = getCreationStackTraceCompactStr cls.printCreationStackTrace = printCreationStackTrace return cls + +def pdir(obj, str = None, width = None, + fTruncate = 1, lineWidth = 75, wantPrivate = 0): + # Remove redundant class entries + uniqueLineage = [] + for l in getClassLineage(obj): + if type(l) == types.ClassType: + if l in uniqueLineage: + break + uniqueLineage.append(l) + # Pretty print out directory info + uniqueLineage.reverse() + for obj in uniqueLineage: + _pdir(obj, str, width, fTruncate, lineWidth, wantPrivate) + print + +def quantize(value, divisor): + # returns new value that is multiple of (1. / divisor) + return float(int(value * int(divisor))) / int(divisor) + +def quantizeVec(vec, divisor): + # in-place + vec[0] = quantize(vec[0], divisor) + vec[1] = quantize(vec[1], divisor) + vec[2] = quantize(vec[2], divisor) + +def isClient(): + if hasattr(__builtin__, 'simbase') and not hasattr(__builtin__, 'base'): + return False + return True + + +__builtin__.pdir = pdir +__builtin__.isClient = isClient diff --git a/toontown/ai/CrashedLeaderBoardDecorator.py b/toontown/ai/CrashedLeaderBoardDecorator.py index 7a592c4..7b636eb 100644 --- a/toontown/ai/CrashedLeaderBoardDecorator.py +++ b/toontown/ai/CrashedLeaderBoardDecorator.py @@ -3,7 +3,8 @@ from direct.distributed.ClockDelta import * from direct.interval.IntervalGlobal import * import HolidayDecorator from toontown.toonbase import ToontownGlobals -from pandac.PandaModules import Vec4, loadDNAFile, CSDefault, TransformState, NodePath, TransparencyAttrib +from pandac.PandaModules import Vec4, CSDefault, TransformState, NodePath, TransparencyAttrib +from libtoontown import loadDNAFile from toontown.hood import GSHood class CrashedLeaderBoardDecorator(HolidayDecorator.HolidayDecorator): diff --git a/toontown/ai/HalloweenHolidayDecorator.py b/toontown/ai/HalloweenHolidayDecorator.py index 1a71cdd..b7513c2 100644 --- a/toontown/ai/HalloweenHolidayDecorator.py +++ b/toontown/ai/HalloweenHolidayDecorator.py @@ -6,7 +6,8 @@ from toontown.toonbase import ToontownGlobals from toontown.safezone import Playground from toontown.town import Street from toontown.estate import Estate -from pandac.PandaModules import Vec4, loadDNAFile, CSDefault, TransformState, NodePath, TransparencyAttrib +from pandac.PandaModules import Vec4, CSDefault, TransformState, NodePath, TransparencyAttrib +from libtoontown import loadDNAFile class HalloweenHolidayDecorator(HolidayDecorator.HolidayDecorator): notify = DirectNotifyGlobal.directNotify.newCategory('HalloweenHolidayDecorator') diff --git a/toontown/ai/HolidayDecorator.py b/toontown/ai/HolidayDecorator.py index 0f162d2..1ec59ec 100644 --- a/toontown/ai/HolidayDecorator.py +++ b/toontown/ai/HolidayDecorator.py @@ -1,6 +1,7 @@ from toontown.toonbase import ToontownGlobals from direct.interval.IntervalGlobal import Parallel, Sequence, Func, Wait -from pandac.PandaModules import Vec4, loadDNAFile, CSDefault, TransformState, NodePath, TransparencyAttrib +from pandac.PandaModules import Vec4, CSDefault, TransformState, NodePath, TransparencyAttrib +from libtoontown import loadDNAFile class HolidayDecorator: diff --git a/toontown/coghq/DinerStatusIndicator.py b/toontown/coghq/DinerStatusIndicator.py index 9715d16..15ff9c3 100644 --- a/toontown/coghq/DinerStatusIndicator.py +++ b/toontown/coghq/DinerStatusIndicator.py @@ -3,10 +3,10 @@ from direct.fsm import FSM from direct.gui.DirectGui import DirectFrame, DGG from direct.interval.IntervalGlobal import LerpScaleInterval, LerpColorScaleInterval, Parallel, Sequence, Wait -class DinerStatusIndicator(NodePath.NodePath, FSM.FSM): +class DinerStatusIndicator(NodePath, FSM.FSM): def __init__(self, parent, pos = None, scale = None): - NodePath.NodePath.__init__(self, 'DinerStatusIndicator') + NodePath.__init__(self, 'DinerStatusIndicator') if parent: self.reparentTo(parent) if pos: diff --git a/toontown/distributed/ToontownClientRepository.py b/toontown/distributed/ToontownClientRepository.py index cc6b011..6992d44 100644 --- a/toontown/distributed/ToontownClientRepository.py +++ b/toontown/distributed/ToontownClientRepository.py @@ -86,7 +86,7 @@ class ToontownClientRepository(OTPClientRepository.OTPClientRepository): self.toons = {} if self.http.getVerifySsl() != HTTPClient.VSNoVerify: self.http.setVerifySsl(HTTPClient.VSNoDateCheck) - prepareAvatar(self.http) + #prepareAvatar(self.http) self.__forbidCheesyEffects = 0 self.friendManager = None self.speedchatRelay = None diff --git a/toontown/minigame/SwingVine.py b/toontown/minigame/SwingVine.py index 3da2244..cd9010f 100644 --- a/toontown/minigame/SwingVine.py +++ b/toontown/minigame/SwingVine.py @@ -9,7 +9,7 @@ from toontown.toonbase import ToontownGlobals import VineGameGlobals import VineSpider -class SwingVine(NodePath.NodePath): +class SwingVine(NodePath): notify = DirectNotifyGlobal.directNotify.newCategory('SwingVine') defaultNormal = Vec3(1, 0, 0) SwingAnimPeriod = 6.0 diff --git a/toontown/minigame/VineBat.py b/toontown/minigame/VineBat.py index ff08aea..e5425b7 100644 --- a/toontown/minigame/VineBat.py +++ b/toontown/minigame/VineBat.py @@ -5,7 +5,7 @@ from pandac.PandaModules import * import VineGameGlobals from direct.interval.SoundInterval import SoundInterval -class VineBat(NodePath.NodePath, DirectObject): +class VineBat(NodePath, DirectObject): notify = DirectNotifyGlobal.directNotify.newCategory('VineBat') notify.setDebug(True) RADIUS = 1.7 diff --git a/toontown/minigame/VineSpider.py b/toontown/minigame/VineSpider.py index 0dc6bee..87a2b3d 100644 --- a/toontown/minigame/VineSpider.py +++ b/toontown/minigame/VineSpider.py @@ -4,7 +4,7 @@ from direct.directnotify import DirectNotifyGlobal from pandac.PandaModules import * import VineGameGlobals -class VineSpider(NodePath.NodePath, DirectObject): +class VineSpider(NodePath, DirectObject): RADIUS = 1.7 def __init__(self): diff --git a/toontown/minigame/VoteResultsTrolleyPanel.py b/toontown/minigame/VoteResultsTrolleyPanel.py index f878787..7d4a570 100644 --- a/toontown/minigame/VoteResultsTrolleyPanel.py +++ b/toontown/minigame/VoteResultsTrolleyPanel.py @@ -5,7 +5,7 @@ from pandac.PandaModules import Point3, TextNode, Vec4 from toontown.minigame import TravelGameGlobals from toontown.toonbase import TTLocalizer from direct.interval.IntervalGlobal import Parallel, Sequence, LerpFunc, Func, Wait, SoundInterval -from direct.showbase.PythonUtil import pdir +from otp.otpbase.PythonUtil import pdir class VoteResultsTrolleyPanel(DirectFrame): notify = DirectNotifyGlobal.directNotify.newCategory('VoteResultsTrolleyPanel') diff --git a/toontown/parties/DistributedPartyCannonActivity.py b/toontown/parties/DistributedPartyCannonActivity.py index 80b1b0e..86f418e 100644 --- a/toontown/parties/DistributedPartyCannonActivity.py +++ b/toontown/parties/DistributedPartyCannonActivity.py @@ -2,7 +2,7 @@ import math from pandac.PandaModules import * from direct.distributed.ClockDelta import * from direct.interval.IntervalGlobal import * -from direct.showbase.PythonUtil import quantizeVec +from otp.otpbase.PythonUtil import quantizeVec from direct.task.Task import Task from toontown.toontowngui import TTDialog from toontown.toonbase.ToonBaseGlobal import * diff --git a/toontown/quest/QuestParser.py b/toontown/quest/QuestParser.py index 44e58a6..8e97172 100644 --- a/toontown/quest/QuestParser.py +++ b/toontown/quest/QuestParser.py @@ -4,7 +4,6 @@ import tokenize import copy from direct.interval.IntervalGlobal import * from direct.directnotify import DirectNotifyGlobal -from direct.showbase import AppRunnerGlobal from pandac.PandaModules import * from direct.showbase import DirectObject import BlinkingArrows @@ -1067,13 +1066,8 @@ class NPCMoviePlayer(DirectObject.DirectObject): searchPath = DSearchPath() -if AppRunnerGlobal.appRunner: - searchPath.appendDirectory(Filename.expandFrom('$TT_3_ROOT/phase_3/etc')) -else: - searchPath.appendDirectory(Filename('phase_3/etc')) - searchPath.appendDirectory(Filename.fromOsSpecific(os.path.expandvars('$TOONTOWN/src/quest'))) - searchPath.appendDirectory(Filename.fromOsSpecific('toontown/src/quest')) - searchPath.appendDirectory(Filename('.')) +if __debug__: + searchPath.appendDirectory(Filename('resources/phase_3/etc')) scriptFile = Filename('QuestScripts.txt') found = vfs.resolveFilename(scriptFile, searchPath) if not found: diff --git a/toontown/suit/DistributedBossbotBoss.py b/toontown/suit/DistributedBossbotBoss.py index d9d1189..db9af37 100644 --- a/toontown/suit/DistributedBossbotBoss.py +++ b/toontown/suit/DistributedBossbotBoss.py @@ -1,6 +1,7 @@ import math import random -from pandac.PandaModules import NametagGroup, CFSpeech, VBase3, CollisionPlane, CollisionNode, CollisionSphere, CollisionTube, NodePath, Plane, Vec3, Vec2, Point3, BitMask32, CollisionHandlerEvent, TextureStage, VBase4, BoundingSphere +from pandac.PandaModules import VBase3, CollisionPlane, CollisionNode, CollisionSphere, CollisionTube, NodePath, Plane, Vec3, Vec2, Point3, BitMask32, CollisionHandlerEvent, TextureStage, VBase4, BoundingSphere +from libotp import NametagGroup, CFSpeech from direct.interval.IntervalGlobal import Sequence, Wait, Func, LerpHprInterval, Parallel, LerpPosInterval, Track, ActorInterval, ParallelEndTogether, LerpFunctionInterval, LerpScaleInterval, LerpPosHprInterval, SoundInterval from direct.task import Task from direct.fsm import FSM diff --git a/toontown/toon/DistributedNPCPartyPerson.py b/toontown/toon/DistributedNPCPartyPerson.py index d84c9d9..3575515 100644 --- a/toontown/toon/DistributedNPCPartyPerson.py +++ b/toontown/toon/DistributedNPCPartyPerson.py @@ -4,7 +4,8 @@ from toontown.toon import NPCToons from toontown.toonbase import TTLocalizer from direct.task.Task import Task from direct.distributed import ClockDelta -from pandac.PandaModules import CFSpeech, CFTimeout, Point3 +from pandac.PandaModules import Point3 +from libotp import CFSpeech, CFTimeout from toontown.toontowngui import TTDialog from otp.otpbase import OTPLocalizer from toontown.parties import PartyGlobals diff --git a/toontown/uberdog/DistributedPartyManager.py b/toontown/uberdog/DistributedPartyManager.py index c6c1467..80e1642 100644 --- a/toontown/uberdog/DistributedPartyManager.py +++ b/toontown/uberdog/DistributedPartyManager.py @@ -1,6 +1,6 @@ from direct.distributed.DistributedObject import DistributedObject from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal -from pandac.PandaModules import CFSpeech, CFTimeout +from libotp import CFSpeech, CFTimeout from toontown.toonbase import ToontownGlobals from toontown.toonbase import TTLocalizer from toontown.toon import ToonDNA