Poodletooth-iLand/toontown/estate/DistributedTreasureChest.py

73 lines
2.8 KiB
Python
Raw Normal View History

2015-05-11 19:05:59 +00:00
from direct.distributed.DistributedObject import DistributedObject
2015-05-11 14:54:45 +00:00
from pandac.PandaModules import *
from toontown.fishing import FishSellGUI
from toontown.toonbase import ToontownGlobals, TTLocalizer
import TreasureChestGlobals
2015-05-11 19:05:59 +00:00
class DistributedTreasureChest(DistributedObject):
2015-05-11 14:54:45 +00:00
def __init__(self, cr):
2015-05-11 19:05:59 +00:00
DistributedObject.__init__(self, cr)
2015-05-11 14:54:45 +00:00
self.cr = cr
self.createModel(45, -165.75, 0.025, 30)
2015-05-11 14:54:45 +00:00
self.initCollisions()
def delete(self):
2015-05-11 14:54:45 +00:00
self.ignore('enter' + self.cSphereNode.getName())
self.cSphereNodePath.removeNode()
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 19:05:59 +00:00
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)
2015-05-11 19:05:59 +00:00
2015-05-11 14:54:45 +00:00
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')
2015-05-11 19:05:59 +00:00
2015-05-11 14:54:45 +00:00
def handleSaleDone(self, sell):
self.destroyFishGui()
base.setCellsActive(base.bottomCells, 1)
base.cr.playGame.getPlace().setState('walk')
self.sendUpdate('completeSale', [sell])
2015-05-11 19:05:59 +00:00
2015-05-11 14:54:45 +00:00
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:
2015-05-11 19:05:59 +00:00
base.localAvatar.setSystemMessage(0, TTLocalizer.STOREOWNER_NOFISH)