From 0308b56ac462604b67db0bee803247a008af4ff0 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 27 Jul 2015 18:05:58 +0300 Subject: [PATCH] Don't tell me I forgot to push the actual crates --- dependencies/config/release/dev.prc | 7 +- toontown/estate/DistributedRewardCrate.py | 88 +++++++++++++++ toontown/estate/DistributedRewardCrateAI.py | 117 ++++++++++++++++++++ 3 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 toontown/estate/DistributedRewardCrate.py create mode 100644 toontown/estate/DistributedRewardCrateAI.py diff --git a/dependencies/config/release/dev.prc b/dependencies/config/release/dev.prc index 24e4b9e1..cf415b71 100644 --- a/dependencies/config/release/dev.prc +++ b/dependencies/config/release/dev.prc @@ -40,4 +40,9 @@ want-instant-parties #t want-instant-delivery #t cogdo-pop-factor 1.5 cogdo-ratio 0.5 -default-directnotify-level info \ No newline at end of file +default-directnotify-level info + +# Crates: +dont-destroy-crates #t +get-key-reward-always #t +get-crate-reward-always #t \ No newline at end of file diff --git a/toontown/estate/DistributedRewardCrate.py b/toontown/estate/DistributedRewardCrate.py new file mode 100644 index 00000000..8f6119c5 --- /dev/null +++ b/toontown/estate/DistributedRewardCrate.py @@ -0,0 +1,88 @@ +from direct.interval.IntervalGlobal import * +from toontown.effects import DustCloud +from toontown.toonbase import ToontownGlobals, TTLocalizer +from toontown.toontowngui import TTDialog +from toontown.quest import Quests +from DistributedFurnitureItem import DistributedFurnitureItem + +class DistributedRewardCrate(DistributedFurnitureItem): + + def __init__(self, cr): + DistributedFurnitureItem.__init__(self, cr) + self.dialog = None + + def loadModel(self): + model = DistributedFurnitureItem.loadModel(self) + cSphere = CollisionSphere(0.0, 0.0, 1.0, 2.25) + cSphere.setTangible(0) + colNode = CollisionNode('Crate-%s' % self.doId) + colNode.addSolid(cSphere) + cSpherePath = model.attachNewNode(colNode) + cSpherePath.setCollideMask(ToontownGlobals.WallBitmask) + self.accept('enterCrate-%s' % self.doId, self.__enterSphere) + return model + + def disable(self): + self.ignoreAll() + DistributedFurnitureItem.disable(self) + + def destroyDialog(self): + if self.dialog: + self.dialog.destroy() + self.dialog = None + + def showDialog(self, text): + base.cr.playGame.getPlace().setState('stopped') + self.dialog = TTDialog.TTDialog(style=TTDialog.Acknowledge, text=text, text_wordwrap=15, fadeScreen=1, command=self.__destroyDialog) + + def __destroyDialog(self, arg): + self.destroyDialog() + base.cr.playGame.getPlace().setState('walk') + + def __enterSphere(self, collisionEntry): + if base.localAvatar.doId != self.furnitureMgr.ownerId: + self.useKeyResponse(ToontownGlobals.CRATE_NOT_OWNER, 0) + return + elif not base.localAvatar.getCrateKeys(): + self.useKeyResponse(ToontownGlobals.CRATE_NO_KEYS, 0) + return + + base.cr.playGame.getPlace().setState('stopped') + self.dialog = TTDialog.TTDialog(style=TTDialog.TwoChoice, text=TTLocalizer.CrateAskToUse, fadeScreen=1, command=self.__handleDialogResponse) + + def __handleDialogResponse(self, response): + self.destroyDialog() + + if response < 0: + base.cr.playGame.getPlace().setState('walk') + return + + self.sendUpdate('requestKeyUsage') + + def useKeyResponse(self, responseCode, amount): + if responseCode == ToontownGlobals.CRATE_NOT_OWNER: + self.showDialog(TTLocalizer.CrateNotOwner) + return + elif responseCode == ToontownGlobals.CRATE_NO_KEYS: + self.showDialog(TTLocalizer.CrateNoKeys) + return + elif responseCode == ToontownGlobals.CRATE_BEANS: + self.showDialog(TTLocalizer.CrateBeanPrize % amount) + elif responseCode == ToontownGlobals.CRATE_BUFFS: + buff = Quests.RewardDict[amount] + + self.showDialog(TTLocalizer.CrateBuffPrize % buff[0](amount, buff[1:]).getString()) + elif responseCode == ToontownGlobals.CRATE_NAMETAGS: + self.showDialog(TTLocalizer.CrateNametagPrize) + elif responseCode == ToontownGlobals.CRATE_EMOTES: + self.showDialog(TTLocalizer.CrateEmotePrize) + elif responseCode == ToontownGlobals.CRATE_CLOTHING: + self.showDialog(TTLocalizer.CrateClothingPrize) + elif responseCode == ToontownGlobals.CRATE_ACCESSORIES: + self.showDialog(TTLocalizer.CrateAccessoryPrize) + + dustCloud = DustCloud.DustCloud(fBillboard=0, wantSound=1) + dustCloud.setBillboardAxis(2.0) + dustCloud.setScale(0.6) + dustCloud.createTrack() + Sequence(Func(dustCloud.reparentTo, render), Func(dustCloud.setPos, self.getPos()), dustCloud.track, Func(dustCloud.detachNode), Func(dustCloud.destroy)).start() \ No newline at end of file diff --git a/toontown/estate/DistributedRewardCrateAI.py b/toontown/estate/DistributedRewardCrateAI.py new file mode 100644 index 00000000..f4ac172c --- /dev/null +++ b/toontown/estate/DistributedRewardCrateAI.py @@ -0,0 +1,117 @@ +from toontown.catalog import CatalogAccessoryItem, CatalogClothingItem, CatalogNametagItem, CatalogEmoteItem +from toontown.catalog.CatalogAccessoryItemGlobals import * +from toontown.toonbase import ToontownGlobals, TTLocalizer +from toontown.toon import ToonDNA +from toontown.quest import Quests +from DistributedFurnitureItemAI import DistributedFurnitureItemAI +import random, time + +RANDOM_PRIZES = [ToontownGlobals.CRATE_BEANS] * 10 + [ToontownGlobals.CRATE_BUFFS] * 5 + [ToontownGlobals.CRATE_NAMETAGS] * 10 + [ToontownGlobals.CRATE_EMOTES] * 10 + [ToontownGlobals.CRATE_CLOTHING] * 30 + [ToontownGlobals.CRATE_ACCESSORIES] * 35 + +class DistributedRewardCrateAI(DistributedFurnitureItemAI): + + def __init__(self, air, furnitureMgr, item): + DistributedFurnitureItemAI.__init__(self, air, furnitureMgr, item) + + def requestKeyUsage(self): + avId = self.air.getAvatarIdFromSender() + av = self.air.doId2do.get(avId) + + if not av: + return + + if avId != self.furnitureMgr.ownerId: + self.sendUpdateToAvatarId(avId, 'useKeyResponse', [ToontownGlobals.CRATE_NOT_OWNER, 0]) + return + elif not av.getCrateKeys(): + self.sendUpdateToAvatarId(avId, 'useKeyResponse', [ToontownGlobals.CRATE_NO_KEYS, 0]) + return + + av.removeCrateKeys(1) + self.choosePrize(av) + + if not config.GetBool('dont-destroy-crate', False): + self.furnitureMgr.deleteItemFromRoom(self.doId, False) + + def choosePrize(self, av, tryNumber = 0): + if tryNumber == 10: + self.giveBeans(av) + return + + prizeType = random.choice(RANDOM_PRIZES) + + if prizeType == ToontownGlobals.CRATE_BEANS: + self.giveBeans(av) + elif prizeType == ToontownGlobals.CRATE_BUFFS: + buffId = random.choice(Quests.BuffRewardIds) + buff = Quests.RewardDict[buffId] + + buff[0](buffId, buff[1:]).sendRewardAI(av) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_BUFFS, buffId]) + elif prizeType == ToontownGlobals.CRATE_NAMETAGS: + allNametags = xrange(len(TTLocalizer.NametagFonts)) + playerNametags = av.nametagStyles + remainingNametags = [nametag for nametag in allNametags if nametag not in playerNametags] + + if not remainingNametags: + self.choosePrize(av, tryNumber + 1) + return + + nametag = random.choice(remainingNametags) + item = CatalogNametagItem.CatalogNametagItem(nametag, 0) + + if item.reachedPurchaseLimit(av): + return + + self.addToOrder(av, item) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_NAMETAGS, 0]) + elif prizeType == ToontownGlobals.CRATE_EMOTES: + playerEmotes = av.emoteAccess + remainingEmotes = [i for i, access in enumerate(playerEmotes) if not access] + + if not remainingEmotes: + self.choosePrize(av, tryNumber + 1) + return + + emote = random.choice(remainingEmotes) + item = CatalogEmoteItem.CatalogEmoteItem(emote, 0) + + if item.reachedPurchaseLimit(av): + self.choosePrize(av, tryNumber + 1) + return + + self.addToOrder(av, item) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_EMOTES, 0]) + elif prizeType == ToontownGlobals.CRATE_CLOTHING: + clothing = CatalogClothingItem.ClothingTypes.keys() + random.shuffle(clothing) + + for id in clothing: + item = CatalogClothingItem.CatalogClothingItem(id, 0) + + if not item.notOfferedTo(av) and not item.reachedPurchaseLimit(av): + self.addToOrder(av, item) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_CLOTHING, 0]) + return + elif prizeType == ToontownGlobals.CRATE_ACCESSORIES: + accessories = AccessoryTypes.keys() + random.shuffle(accessories) + + for id in accessories: + item = CatalogAccessoryItem.CatalogAccessoryItem(id, 0) + + if not item.reachedPurchaseLimit(av): + self.addToOrder(av, item) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_ACCESSORIES, 0]) + return + + def addToOrder(self, av, item): + item.deliveryDate = int(time.time() / 60. + .5) + av.onOrder.append(item) + av.b_setDeliverySchedule(av.onOrder) + + def giveBeans(self, av): + beans = random.randint(1, 15) * 100 + + av.addMoney(beans) + self.sendUpdateToAvatarId(av.doId, 'useKeyResponse', [ToontownGlobals.CRATE_BEANS, beans]) \ No newline at end of file