From a1b996ea498c1310fcd35caf5d51f4fab2593de7 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 25 May 2015 12:31:46 +0300 Subject: [PATCH] DANIEL: Tag game --- toontown/minigame/DistributedTagGame.py | 31 ++++-- toontown/minigame/DistributedTagGameAI.py | 20 ++-- toontown/minigame/TagGameGlobals.py | 105 +++++++++++++++++++- toontown/minigame/TagTreasurePlannerAI.py | 27 +---- toontown/safezone/BRSafeZoneLoader.py | 9 +- toontown/safezone/RegenTreasurePlannerAI.py | 3 +- toontown/safezone/SnowUtil.py | 10 ++ 7 files changed, 155 insertions(+), 50 deletions(-) create mode 100644 toontown/safezone/SnowUtil.py diff --git a/toontown/minigame/DistributedTagGame.py b/toontown/minigame/DistributedTagGame.py index 8ec567ca..39ddbc0f 100755 --- a/toontown/minigame/DistributedTagGame.py +++ b/toontown/minigame/DistributedTagGame.py @@ -4,12 +4,11 @@ from DistributedMinigame import * from direct.interval.IntervalGlobal import * from direct.fsm import ClassicFSM, State from direct.fsm import State -from toontown.safezone import Walk +from toontown.safezone import Walk, SnowUtil from toontown.toonbase import ToontownTimer from direct.gui import OnscreenText import MinigameAvatarScorePanel from direct.distributed import DistributedSmoothNode -import random from toontown.toonbase import ToontownGlobals from toontown.toonbase import TTLocalizer from otp.otpbase import OTPGlobals @@ -27,10 +26,6 @@ class DistributedTagGame(DistributedMinigame): self.addChildGameFSM(self.gameFSM) self.walkStateData = Walk.Walk('walkDone') self.scorePanels = [] - self.initialPositions = ((0, 10, 0, 180, 0, 0), - (10, 0, 0, 90, 0, 0), - (0, -10, 0, 0, 0, 0), - (-10, 0, 0, -90, 0, 0)) base.localAvatar.isIt = 0 self.modelCount = 4 @@ -48,15 +43,19 @@ class DistributedTagGame(DistributedMinigame): DistributedMinigame.load(self) self.itText = OnscreenText.OnscreenText('itText', fg=(0.95, 0.95, 0.65, 1), scale=0.14, font=ToontownGlobals.getSignFont(), pos=(0.0, -0.8), wordwrap=15, mayChange=1) self.itText.hide() - self.sky = loader.loadModel('phase_3.5/models/props/TT_sky') - self.groundList = ['phase_4/models/minigames/tag_arena', 'phase_6/models/neighborhoods/minnies_melody_land', 'phase_8/models/neighborhoods/the_burrrgh' 'phase_8/models/neighborhoods/daisys_garden'] - self.groundRandom = random.choice(self.groundList) - self.ground = self.groundRandom + safezoneId = self.getSafezoneId() + self.sky = loader.loadModel(TagGameGlobals.getSky(safezoneId)) + self.ground = loader.loadModel(TagGameGlobals.getGround(safezoneId)) self.music = base.loadMusic('phase_4/audio/bgm/MG_toontag.ogg') self.tagSfx = base.loadSfx('phase_4/audio/sfx/MG_Tag_C.ogg') self.itPointer = loader.loadModel('phase_4/models/minigames/bboard-pointer') self.tracks = [] + self.initialPositions = TagGameGlobals.getDropPoints(safezoneId) self.IT = None + + if TagGameGlobals.isSnowHood(safezoneId): + self.snow, self.snowRender = SnowUtil.createSnow(self.ground) + return def unload(self): @@ -77,6 +76,14 @@ class DistributedTagGame(DistributedMinigame): del self.itText self.removeChildGameFSM(self.gameFSM) del self.gameFSM + self.destroySnow() + + def destroySnow(self): + if hasattr(self, 'snow'): + self.snow.cleanup() + self.snowRender.removeNode() + del self.snow + del self.snowRender def onstage(self): self.notify.debug('onstage') @@ -94,6 +101,10 @@ class DistributedTagGame(DistributedMinigame): NametagGlobals.setWant2dNametags(True) DistributedSmoothNode.activateSmoothing(1, 1) self.IT = None + + if hasattr(self, 'snow'): + self.snow.start(camera, self.snowRender) + return def offstage(self): diff --git a/toontown/minigame/DistributedTagGameAI.py b/toontown/minigame/DistributedTagGameAI.py index dc3abdee..ed2845e7 100755 --- a/toontown/minigame/DistributedTagGameAI.py +++ b/toontown/minigame/DistributedTagGameAI.py @@ -3,6 +3,7 @@ from TagTreasurePlannerAI import * from direct.fsm import ClassicFSM, State from direct.fsm import State from direct.task import Task +from toontown.safezone import TreasureGlobals import random import TagGameGlobals @@ -19,6 +20,7 @@ class DistributedTagGameAI(DistributedMinigameAI): self.addChildGameFSM(self.gameFSM) self.treasureScores = {} self.itAvId = None + self.healAmount = 3 self.tagBack = 1 return @@ -60,11 +62,15 @@ class DistributedTagGameAI(DistributedMinigameAI): self.notify.debug('enterPlay') self.b_setIt(random.choice(self.avIdList)) taskMgr.doMethodLater(self.DURATION, self.timerExpired, self.taskName('gameTimer')) - self.tagTreasurePlanner = TagTreasurePlannerAI(self.zoneId, self, self.treasureGrabCallback) - self.tagTreasurePlanner.placeRandomTreasure() - self.tagTreasurePlanner.placeRandomTreasure() - self.tagTreasurePlanner.placeRandomTreasure() - self.tagTreasurePlanner.placeRandomTreasure() + + safezoneId = self.getSafezoneId() + + if safezoneId in TreasureGlobals.SafeZoneTreasureSpawns: + treasureType, self.healAmount, spawnPoints, spawnRate, maxTreasures = TreasureGlobals.SafeZoneTreasureSpawns[safezoneId] + else: + treasureType, self.healAmount = TreasureGlobals.TreasureTT, 3 + + self.tagTreasurePlanner = TagTreasurePlannerAI(self.zoneId, self, self.treasureGrabCallback, treasureType, TagGameGlobals.getTreasurePoints(safezoneId)) self.tagTreasurePlanner.start() def timerExpired(self, task): @@ -91,7 +97,7 @@ class DistributedTagGameAI(DistributedMinigameAI): if avId not in self.avIdList: self.air.writeServerEvent('suspicious', avId, 'TagGameAI.treasureGrabCallback non-player avId') return - self.treasureScores[avId] += 2 + self.treasureScores[avId] += self.healAmount self.notify.debug('treasureGrabCallback: ' + str(avId) + ' grabbed a treasure, new score: ' + str(self.treasureScores[avId])) self.scoreDict[avId] = self.treasureScores[avId] treasureScoreParams = [] @@ -129,4 +135,4 @@ class DistributedTagGameAI(DistributedMinigameAI): self.sendUpdate('setIt', [avId]) def setIt(self, avId): - self.itAvId = avId + self.itAvId = avId \ No newline at end of file diff --git a/toontown/minigame/TagGameGlobals.py b/toontown/minigame/TagGameGlobals.py index b8bca79e..43854d55 100755 --- a/toontown/minigame/TagGameGlobals.py +++ b/toontown/minigame/TagGameGlobals.py @@ -1 +1,104 @@ -DURATION = 60 +from toontown.toonbase import ToontownGlobals + +DURATION = 90 +DEFAULT_SKY = 'phase_3.5/models/props/TT_sky' +DEFAULT_GROUND = 'phase_4/models/minigames/tag_arena' + +DEFAULT_TREASURE_POINTS = [ + (0, 0, 0.1), + (5, 20, 0.1), + (0, 40, 0.1), + (-5, -20, 0.1), + (0, -40, 0.1), + (20, 0, 0.1), + (40, 5, 0.1), + (-20, -5, 0.1), + (-40, 0, 0.1), + (22, 20, 0.1), + (-20, 22, 0.1), + (20, -20, 0.1), + (-25, -20, 0.1), + (20, 40, 0.1), + (20, -44, 0.1), + (-24, 40, 0.1), + (-20, -40, 0.1)] + +DEFAULT_DROP_POINTS = ( + (0, 10, 0.25, 180, 0, 0), + (10, 0, 0.25, 90, 0, 0), + (0, -10, 0.25, 0, 0, 0), + (-10, 0, 0.25, -90, 0, 0) +) + +SKY = { + ToontownGlobals.TheBrrrgh: 'phase_3.5/models/props/BR_sky' +} + +GROUND = { + ToontownGlobals.TheBrrrgh: 'phase_8/models/minigames/tag_arena_BR', + ToontownGlobals.DaisyGardens: 'phase_8/models/minigames/tag_arena_DG' +} + +TREASURE_POINTS = { + ToontownGlobals.TheBrrrgh: [ + (-27, -30.7, 10.4), + (0.2, -33.6, 2.5), + (-60.9, -36.6, 2.7), + (-59.3, -9.04, 0.31), + (-78.4, 2.7, 4.2), + (-37.8, 2.1, 3.7), + (-28.6, 35.8, 11.6), + (7.7, 5.8, 2.4), + (41.5, -30.1, 14.2), + (37.8, 32.1, 11.7), + (2.8, 51.1, 3), + (-16.8, 0.6, 2.2), + (-72.4, 37.7, 5) + ], + ToontownGlobals.DaisyGardens: [ + (21.3, 27.6, 0.025), + (30.4, -8.4, 0.025), + (0.5, -36.3, 0.025), + (-34.9, -10.4, 0.025), + (-35.3, -34.3, 0.025), + (-33.3, -54, 0.025), + (41.6, -39.4, 0.025), + (19.0, -41.2, 0.025), + (0.5, 61.3, 0.025), + (-24.4, 52.1, 0.025), + (-49.9, 24.2, 0.025), + (-43.8, 8.4, 0.025) + ] +} + +DROP_POINTS = { + ToontownGlobals.TheBrrrgh: ( + (-30.4, 37.5, 11.1, 2006, 0, 0), + (34.7, -21.5, 12.5, 1875, 0, 0), + (-31.9, -29.4, 10, 1774), + (-74.1, -30.5, 5.3, 1720) + ), + ToontownGlobals.DaisyGardens: ( + (38.6, -55.1, 0.025, 396, 0, 0), + (3.1, 54, 0.025, 898, 0, 0), + (-37.8, -49.4, 0.025, 685, 0, 0), + (-55.9, 21, 0.025, 608, 0, 0) + ) +} + +SNOW_HOODS = [ToontownGlobals.TheBrrrgh] + +def getSky(safezoneId): + return SKY.get(safezoneId, DEFAULT_SKY) + +def getGround(safezoneId): + return GROUND.get(safezoneId, DEFAULT_GROUND) + +def getTreasurePoints(safezoneId): + return TREASURE_POINTS.get(safezoneId, DEFAULT_TREASURE_POINTS) + +def getDropPoints(safezoneId): + return DROP_POINTS.get(safezoneId, DEFAULT_DROP_POINTS) + +def isSnowHood(safezoneId): + return safezoneId in SNOW_HOODS \ No newline at end of file diff --git a/toontown/minigame/TagTreasurePlannerAI.py b/toontown/minigame/TagTreasurePlannerAI.py index e216daa0..689b2917 100755 --- a/toontown/minigame/TagTreasurePlannerAI.py +++ b/toontown/minigame/TagTreasurePlannerAI.py @@ -1,36 +1,17 @@ from direct.directnotify import DirectNotifyGlobal -from toontown.toonbase.ToontownGlobals import * from toontown.safezone import RegenTreasurePlannerAI -from toontown.safezone import TreasureGlobals class TagTreasurePlannerAI(RegenTreasurePlannerAI.RegenTreasurePlannerAI): notify = DirectNotifyGlobal.directNotify.newCategory('TagTreasurePlannerAI') - def __init__(self, zoneId, game, callback): + def __init__(self, zoneId, game, callback, treasureType, spawnPoints): self.numPlayers = 0 self.game = game - RegenTreasurePlannerAI.RegenTreasurePlannerAI.__init__(self, zoneId, TreasureGlobals.TreasureTT, 'TagTreasurePlanner-' + str(zoneId), 3, 4, callback) - return None + self.spawnPoints = spawnPoints + RegenTreasurePlannerAI.RegenTreasurePlannerAI.__init__(self, zoneId, treasureType, 'TagTreasurePlanner-' + str(zoneId), 3, 6, callback) def initSpawnPoints(self): - self.spawnPoints = [(0, 0, 0.1), - (5, 20, 0.1), - (0, 40, 0.1), - (-5, -20, 0.1), - (0, -40, 0.1), - (20, 0, 0.1), - (40, 5, 0.1), - (-20, -5, 0.1), - (-40, 0, 0.1), - (22, 20, 0.1), - (-20, 22, 0.1), - (20, -20, 0.1), - (-25, -20, 0.1), - (20, 40, 0.1), - (20, -44, 0.1), - (-24, 40, 0.1), - (-20, -40, 0.1)] return self.spawnPoints def validAvatar(self, treasure, av): - return av.doId != self.game.itAvId + return av.doId != self.game.itAvId \ No newline at end of file diff --git a/toontown/safezone/BRSafeZoneLoader.py b/toontown/safezone/BRSafeZoneLoader.py index fbae63be..73446629 100755 --- a/toontown/safezone/BRSafeZoneLoader.py +++ b/toontown/safezone/BRSafeZoneLoader.py @@ -1,7 +1,6 @@ -from toontown.battle import BattleParticles from toontown.safezone import BRPlayground from toontown.safezone import SafeZoneLoader - +import SnowUtil class BRSafeZoneLoader(SafeZoneLoader.SafeZoneLoader): def __init__(self, hood, parentFSM, doneEvent): @@ -17,11 +16,7 @@ class BRSafeZoneLoader(SafeZoneLoader.SafeZoneLoader): self.windSound = map(base.loadSfx, ['phase_8/audio/sfx/SZ_TB_wind_1.ogg', 'phase_8/audio/sfx/SZ_TB_wind_2.ogg', 'phase_8/audio/sfx/SZ_TB_wind_3.ogg']) - self.snow = BattleParticles.loadParticleFile('snowdisk.ptf') - self.snow.setPos(0, 0, 5) - self.snowRender = self.geom.attachNewNode('snowRender') - self.snowRender.setDepthWrite(0) - self.snowRender.setBin('fixed', 1) + self.snow, self.snowRender = SnowUtil.createSnow(self.geom) def unload(self): SafeZoneLoader.SafeZoneLoader.unload(self) diff --git a/toontown/safezone/RegenTreasurePlannerAI.py b/toontown/safezone/RegenTreasurePlannerAI.py index a3aa4dc0..ae812999 100755 --- a/toontown/safezone/RegenTreasurePlannerAI.py +++ b/toontown/safezone/RegenTreasurePlannerAI.py @@ -35,10 +35,9 @@ class RegenTreasurePlannerAI(TreasurePlannerAI.TreasurePlannerAI): return Task.done def placeRandomTreasure(self): - self.notify.debug('Placing a Treasure...') spawnPointIndex = self.nthEmptyIndex(random.randrange(self.countEmptySpawnPoints())) self.placeTreasure(spawnPointIndex) def preSpawnTreasures(self): for i in xrange(self.maxTreasures): - self.placeRandomTreasure() + self.placeRandomTreasure() \ No newline at end of file diff --git a/toontown/safezone/SnowUtil.py b/toontown/safezone/SnowUtil.py new file mode 100644 index 00000000..2c8dcc5a --- /dev/null +++ b/toontown/safezone/SnowUtil.py @@ -0,0 +1,10 @@ +from toontown.battle import BattleParticles + +def createSnow(geom): + snow = BattleParticles.loadParticleFile('snowdisk.ptf') + snow.setPos(0, 0, 5) + snowRender = geom.attachNewNode('snowRender') + snowRender.setDepthWrite(0) + snowRender.setBin('fixed', 1) + + return snow, snowRender \ No newline at end of file