2015-03-03 16:10:12 -06:00
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
|
|
|
from toontown.estate.DistributedFurnitureItemAI import DistributedFurnitureItemAI
|
2015-04-08 06:51:59 -05:00
|
|
|
from direct.distributed.ClockDelta import *
|
|
|
|
import BankGlobals
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
class DistributedBankAI(DistributedFurnitureItemAI):
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedBankAI")
|
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
def __init__(self, air, furnitureMgr, item):
|
|
|
|
DistributedFurnitureItemAI.__init__(self, air, furnitureMgr, item)
|
|
|
|
self.avId = None
|
|
|
|
self.movie = BankGlobals.BANK_MOVIE_CLEAR
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def avatarEnter(self):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
2015-04-08 06:51:59 -05:00
|
|
|
if not self.avId:
|
|
|
|
if not self.furnitureMgr.ownerId:
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_NO_OWNER, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
return
|
|
|
|
elif self.furnitureMgr.ownerId != avId:
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_NOT_OWNER, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
return
|
2015-03-03 16:10:12 -06:00
|
|
|
else:
|
2015-04-08 06:51:59 -05:00
|
|
|
self.avId = avId
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_GUI, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if avId == self.avId:
|
|
|
|
self.air.writeServerEvent('suspicious', avId=avId, issue='Tried to use bank while already using it!')
|
|
|
|
self.sendUpdateToAvatarId(avId, 'freeAvatar', [])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def freeAvatar(self):
|
2015-04-08 06:51:59 -05:00
|
|
|
pass
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
def setMovie(self, mode, avId, time):
|
|
|
|
self.movie = mode
|
|
|
|
if self.movie != BankGlobals.BANK_MOVIE_CLEAR:
|
|
|
|
taskMgr.doMethodLater(2.0, self.clearMovie, 'clear-movie-%d' % self.getDoId())
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
def clearMovie(self, task):
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_CLEAR, 0, globalClockDelta.getRealNetworkTime())
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
def b_setMovie(self, mode, avId, time):
|
|
|
|
self.setMovie(mode, avId, time)
|
|
|
|
self.d_setMovie(mode, avId, time)
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
def d_setMovie(self, mode, avId, time):
|
|
|
|
self.sendUpdate('setMovie', [mode, avId, time])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def transferMoney(self, amount):
|
2015-04-08 06:51:59 -05:00
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
if avId != self.avId:
|
|
|
|
self.air.writeServerEvent('suspicious', avId=avId, issue='Tried to transfer money while not using a bank!')
|
|
|
|
return
|
|
|
|
av = self.air.doId2do.get(avId)
|
2015-03-03 16:10:12 -06:00
|
|
|
if not av:
|
2015-04-08 06:51:59 -05:00
|
|
|
self.air.writeServerEvent('suspicious', avId=avId, issue='Tried to transfer money while not on the AI!')
|
2015-03-03 16:10:12 -06:00
|
|
|
return
|
2015-04-08 06:51:59 -05:00
|
|
|
if amount == 0: # No transfer needed.
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_NO_OP, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
elif amount > 0:
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_DEPOSIT, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
if av.money < amount:
|
|
|
|
self.air.writeServerEvent('suspicious', avId=avId, issue='Toon tried to deposit more money than they have!')
|
|
|
|
else:
|
|
|
|
av.b_setMoney(av.money - amount)
|
|
|
|
av.b_setBankMoney(av.bankMoney + amount)
|
|
|
|
else:
|
|
|
|
self.b_setMovie(BankGlobals.BANK_MOVIE_WITHDRAW, avId, globalClockDelta.getRealNetworkTime())
|
|
|
|
if av.bankMoney + amount < 0:
|
|
|
|
self.air.writeServerEvent('suspicious', avId=avId, issue='Toon tried to withdraw more money than they have!')
|
|
|
|
else:
|
2015-08-24 23:16:13 -05:00
|
|
|
av.b_setMoney(av.money - amount)
|
|
|
|
av.b_setBankMoney(av.bankMoney + amount)
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-04-08 06:51:59 -05:00
|
|
|
self.avId = None
|