2015-05-11 14:54:45 +00:00
|
|
|
from direct.distributed import DistributedObject
|
|
|
|
from pandac.PandaModules import *
|
|
|
|
from toontown.fishing import FishSellGUI
|
|
|
|
from toontown.toonbase import ToontownGlobals, TTLocalizer
|
|
|
|
import TreasureChestGlobals
|
|
|
|
|
|
|
|
class DistributedTreasureChest(DistributedObject.DistributedObject):
|
|
|
|
|
|
|
|
def __init__(self, cr):
|
|
|
|
DistributedObject.DistributedObject.__init__(self, cr)
|
|
|
|
self.cr = cr
|
2015-05-11 15:11:35 +00:00
|
|
|
self.createModel(45, -165.75, 0.025, 30)
|
2015-05-11 14:54:45 +00:00
|
|
|
self.initCollisions()
|
|
|
|
|
2015-05-11 16:18:42 +00:00
|
|
|
def delete(self):
|
2015-05-11 14:54:45 +00:00
|
|
|
self.ignore('enter' + self.cSphereNode.getName())
|
|
|
|
self.cSphereNodePath.removeNode()
|
2015-05-11 16:18:42 +00:00
|
|
|
self.model.removeNode()
|
2015-05-11 14:54:45 +00:00
|
|
|
self.destroyFishGui()
|
|
|
|
del self.cSphere
|
|
|
|
del self.cSphereNode
|
|
|
|
del self.cSphereNodePath
|
|
|
|
del self.model
|
2015-05-11 16:18:42 +00:00
|
|
|
DistributedObject.DistributedObject.delete(self)
|
2015-05-11 14:54:45 +00:00
|
|
|
|
|
|
|
def destroyFishGui(self):
|
|
|
|
self.ignore('treasureChestSell')
|
|
|
|
|
|
|
|
if hasattr(self, 'fishGui'):
|
|
|
|
self.fishGui.destroy()
|
|
|
|
del self.fishGui
|
|
|
|
|
|
|
|
def createModel(self, x, y, z, h):
|
|
|
|
self.model = loader.loadModel('phase_4/models/minigames/treasure_chest.bam')
|
|
|
|
self.model.reparentTo(render)
|
|
|
|
self.model.setScale(1.5)
|
|
|
|
self.model.setPos(x, y, z)
|
|
|
|
self.model.setH(h)
|
|
|
|
|
|
|
|
def initCollisions(self):
|
|
|
|
self.cSphere = CollisionTube(0.0, 1.0, 0.0, 0.0, 1.0, 5.0, ToontownGlobals.TreasureChestSphereRadius)
|
|
|
|
self.cSphere.setTangible(0)
|
|
|
|
self.cSphereNode = CollisionNode('cSphereNode')
|
|
|
|
self.cSphereNode.addSolid(self.cSphere)
|
|
|
|
self.cSphereNodePath = self.model.attachNewNode(self.cSphereNode)
|
|
|
|
self.cSphereNodePath.hide()
|
|
|
|
self.cSphereNode.setCollideMask(ToontownGlobals.WallBitmask)
|
|
|
|
self.accept('enter' + self.cSphereNode.getName(), self.handleCollisionSphereEnter)
|
|
|
|
|
|
|
|
def handleCollisionSphereEnter(self, collEntry):
|
|
|
|
if not base.localAvatar.fishTank.getFish():
|
|
|
|
base.localAvatar.setSystemMessage(0, TTLocalizer.STOREOWNER_NOFISH)
|
|
|
|
return
|
|
|
|
|
|
|
|
base.setCellsActive(base.bottomCells, 0)
|
|
|
|
base.cr.playGame.getPlace().setState('stopped')
|
|
|
|
self.acceptOnce('treasureChestSell', self.handleSaleDone)
|
|
|
|
self.fishGui = FishSellGUI.FishSellGUI('treasureChestSell')
|
|
|
|
|
|
|
|
def handleSaleDone(self, sell):
|
|
|
|
self.destroyFishGui()
|
|
|
|
base.setCellsActive(base.bottomCells, 1)
|
|
|
|
base.cr.playGame.getPlace().setState('walk')
|
|
|
|
self.sendUpdate('completeSale', [sell])
|
|
|
|
|
|
|
|
def completeSaleResult(self, state, numFish, maxFish):
|
|
|
|
if state == TreasureChestGlobals.TROPHY:
|
|
|
|
base.localAvatar.setSystemMessage(0, TTLocalizer.STOREOWNER_TROPHY % (numFish, maxFish))
|
|
|
|
elif state == TreasureChestGlobals.COMPLETE:
|
|
|
|
base.localAvatar.setSystemMessage(0, TTLocalizer.STOREOWNER_THANKSFISH)
|
|
|
|
elif state == TreasureChestGlobals.NONE:
|
|
|
|
base.localAvatar.setSystemMessage(0, TTLocalizer.STOREOWNER_NOFISH)
|