2015-05-12 00:06:23 -05:00
|
|
|
from direct.distributed import ClockDelta
|
2015-05-11 11:21:07 -05:00
|
|
|
from toontown.toonbase import ToontownGlobals
|
2015-05-12 00:06:23 -05:00
|
|
|
from DistributedNPCToonBaseAI import DistributedNPCToonBaseAI
|
|
|
|
from pandac.PandaModules import *
|
|
|
|
from toontown.toonbase import TTLocalizer
|
|
|
|
from direct.task import Task
|
|
|
|
import LaffRestockGlobals
|
|
|
|
from toontown.toon import NPCToons
|
2015-05-11 11:21:07 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
class DistributedNPCLaffRestockAI(DistributedNPCToonBaseAI):
|
2015-05-11 11:21:07 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def __init__(self, air, npcId):
|
|
|
|
DistributedNPCToonBaseAI.__init__(self, air, npcId)
|
|
|
|
self.givesQuests = 0
|
|
|
|
self.busy = 0
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def delete(self):
|
|
|
|
taskMgr.remove(self.uniqueName('clearMovie'))
|
|
|
|
self.ignoreAll()
|
|
|
|
DistributedNPCToonBaseAI.delete(self)
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def d_setMovie(self, avId, flag, extraArgs=[]):
|
|
|
|
self.sendUpdate('setMovie', [flag,
|
|
|
|
self.npcId,
|
|
|
|
avId,
|
|
|
|
extraArgs,
|
|
|
|
ClockDelta.globalClockDelta.getRealNetworkTime()])
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def avatarEnter(self):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
if avId not in self.air.doId2do:
|
|
|
|
self.notify.warning('Avatar: %s not found' % avId)
|
2015-05-11 11:21:07 -05:00
|
|
|
return
|
2015-05-12 00:06:23 -05:00
|
|
|
if self.isBusy():
|
|
|
|
self.freeAvatar(avId)
|
|
|
|
return
|
|
|
|
av = self.air.doId2do[avId]
|
|
|
|
self.busy = avId
|
|
|
|
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.__handleUnexpectedExit, extraArgs=[avId])
|
|
|
|
laff = av.getMaxHp() - av.getHp()
|
2015-05-11 11:21:07 -05:00
|
|
|
cost = laff * ToontownGlobals.CostPerLaffRestock
|
2015-05-12 00:06:23 -05:00
|
|
|
if laff <= 0:
|
|
|
|
self.d_setMovie(avId, LaffRestockGlobals.FullLaff)
|
|
|
|
self.sendClearMovie(None)
|
|
|
|
elif cost > av.getTotalMoney():
|
|
|
|
self.d_setMovie(avId, LaffRestockGlobals.NoMoney)
|
|
|
|
self.sendClearMovie(None)
|
|
|
|
else:
|
|
|
|
self.d_setMovie(avId, NPCToons.SELL_MOVIE_START)
|
|
|
|
taskMgr.doMethodLater(LaffRestockGlobals.LAFFCLERK_TIMER, self.sendTimeoutMovie, self.uniqueName('clearMovie'))
|
|
|
|
DistributedNPCToonBaseAI.avatarEnter(self)
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def transactionDone(self):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
if self.busy != avId:
|
|
|
|
self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.transactionDone busy with %s' % self.busy)
|
|
|
|
self.notify.warning('somebody called transactionDone that I was not busy with! avId: %s' % avId)
|
2015-05-11 11:21:07 -05:00
|
|
|
return
|
2015-05-12 00:06:23 -05:00
|
|
|
av = simbase.air.doId2do.get(avId)
|
|
|
|
if av:
|
|
|
|
self.d_setMovie(avId, NPCToons.SELL_MOVIE_COMPLETE, [])
|
|
|
|
self.sendClearMovie(None)
|
|
|
|
return
|
|
|
|
|
|
|
|
def __handleUnexpectedExit(self, avId):
|
|
|
|
self.notify.warning('avatar:' + str(avId) + ' has exited unexpectedly')
|
|
|
|
self.notify.warning('not busy with avId: %s, busy: %s ' % (avId, self.busy))
|
|
|
|
taskMgr.remove(self.uniqueName('clearMovie'))
|
|
|
|
self.sendClearMovie(None)
|
|
|
|
return
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-05-12 00:06:23 -05:00
|
|
|
def sendTimeoutMovie(self, task):
|
|
|
|
self.d_setMovie(self.busy, NPCToons.SELL_MOVIE_TIMEOUT)
|
|
|
|
self.sendClearMovie(None)
|
|
|
|
return Task.done
|
|
|
|
|
|
|
|
def sendClearMovie(self, task):
|
|
|
|
self.ignore(self.air.getAvatarExitEvent(self.busy))
|
|
|
|
taskMgr.remove(self.uniqueName('clearMovie'))
|
|
|
|
self.busy = 0
|
|
|
|
self.d_setMovie(0, NPCToons.SELL_MOVIE_CLEAR)
|
|
|
|
return Task.done
|
|
|
|
|
2015-05-12 03:10:49 -05:00
|
|
|
def restock(self, avId, laff, cost):
|
2015-05-12 00:06:23 -05:00
|
|
|
sendAvId = self.air.getAvatarIdFromSender()
|
|
|
|
if self.busy != avId:
|
|
|
|
self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.restock busy with %s' % self.busy)
|
|
|
|
self.notify.warning('somebody called restock that I was not busy with! avId: %s' % avId)
|
|
|
|
return
|
|
|
|
av = simbase.air.doId2do.get(avId)
|
|
|
|
if av:
|
2015-05-22 22:47:35 -05:00
|
|
|
if av.getMaxHp() < (av.getHp() + laff):
|
|
|
|
movieType = NPCToons.SELL_MOVIE_CHEATER
|
|
|
|
self.air.writeServerEvent('suspicious', avId, 'DistributedNPCLaffRestockAI.restock invalid restock')
|
|
|
|
self.notify.warning('somebody tried to buy an invalid hp restock! avId: %s' % avId)
|
|
|
|
else:
|
|
|
|
movieType = NPCToons.SELL_MOVIE_COMPLETE
|
|
|
|
av.takeMoney(cost)
|
|
|
|
av.b_setHp(av.getHp() + laff)
|