2015-03-07 09:01:47 -06:00
|
|
|
from toontown.toonbase import ToontownGlobals
|
2015-05-25 06:29:48 -05:00
|
|
|
import DistributedNPCToonBaseAI, GloveNPCGlobals, ToonDNA
|
2015-03-07 09:01:47 -06:00
|
|
|
|
2015-05-25 06:29:48 -05:00
|
|
|
class DistributedNPCGloveAI(DistributedNPCToonBaseAI.DistributedNPCToonBaseAI):
|
2015-03-07 09:01:47 -06:00
|
|
|
|
2015-05-25 06:29:48 -05:00
|
|
|
def changeGlove(self, color):
|
2015-03-07 09:01:47 -06:00
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
av = self.air.doId2do.get(avId)
|
2015-05-11 14:05:59 -05:00
|
|
|
|
2015-03-07 09:01:47 -06:00
|
|
|
if av is None or not hasattr(av, 'dna'):
|
|
|
|
return
|
2015-05-25 06:29:48 -05:00
|
|
|
elif len(ToonDNA.allColorsList) <= color:
|
|
|
|
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.INVALID_COLOR])
|
2015-03-07 09:01:47 -06:00
|
|
|
return
|
2015-05-25 06:29:48 -05:00
|
|
|
elif av.dna.gloveColor == color:
|
|
|
|
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.SAME_COLOR])
|
|
|
|
return
|
|
|
|
elif av.getTotalMoney() < ToontownGlobals.GloveCost:
|
|
|
|
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.NOT_ENOUGH_MONEY])
|
2015-03-07 09:01:47 -06:00
|
|
|
return
|
|
|
|
|
|
|
|
av.takeMoney(ToontownGlobals.GloveCost)
|
2015-05-25 06:29:48 -05:00
|
|
|
newDNA = ToonDNA.ToonDNA()
|
2015-03-07 09:01:47 -06:00
|
|
|
newDNA.makeFromNetString(av.getDNAString())
|
|
|
|
newDNA.gloveColor = color
|
|
|
|
taskMgr.doMethodLater(1.0, lambda task: av.b_setDNAString(newDNA.makeNetString()), 'transform-%d' % avId)
|
2015-05-25 06:29:48 -05:00
|
|
|
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.CHANGE_SUCCESSFUL])
|