Poodletooth-iLand/toontown/toon/DistributedNPCGloveAI.py

28 lines
1.2 KiB
Python
Raw Normal View History

from toontown.toonbase import ToontownGlobals
2015-05-25 06:29:48 -05:00
import DistributedNPCToonBaseAI, GloveNPCGlobals, ToonDNA
2015-05-25 06:29:48 -05:00
class DistributedNPCGloveAI(DistributedNPCToonBaseAI.DistributedNPCToonBaseAI):
2015-05-25 06:29:48 -05:00
def changeGlove(self, color):
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
2015-05-11 14:05:59 -05: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])
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])
return
av.takeMoney(ToontownGlobals.GloveCost)
2015-05-25 06:29:48 -05:00
newDNA = ToonDNA.ToonDNA()
newDNA.makeFromNetString(av.getDNAString())
newDNA.gloveColor = color
taskMgr.doMethodLater(1.0, lambda task: av.b_setDNAString(newDNA.makeNetString()), 'transform-%d' % avId)
2015-07-05 18:59:25 -05:00
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.CHANGE_SUCCESSFUL])