Poodletooth-iLand/toontown/toon/DistributedNPCGloveAI.py

28 lines
1.2 KiB
Python
Raw Normal View History

from toontown.toonbase import ToontownGlobals
2015-05-25 11:29:48 +00:00
import DistributedNPCToonBaseAI, GloveNPCGlobals, ToonDNA
2015-05-25 11:29:48 +00:00
class DistributedNPCGloveAI(DistributedNPCToonBaseAI.DistributedNPCToonBaseAI):
2015-05-25 11:29:48 +00:00
def changeGlove(self, color):
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
2015-05-11 19:05:59 +00:00
if av is None or not hasattr(av, 'dna'):
return
2015-05-25 11:29:48 +00:00
elif len(ToonDNA.allColorsList) <= color:
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.INVALID_COLOR])
return
2015-05-25 11:29:48 +00: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 11:29:48 +00:00
newDNA = ToonDNA.ToonDNA()
newDNA.makeFromNetString(av.getDNAString())
2015-08-04 19:00:20 +00:00
newDNA.gloveColor = ToonDNA.allColorsList[color]
taskMgr.doMethodLater(1.0, lambda task: av.b_setDNAString(newDNA.makeNetString()), 'transform-%d' % avId)
2015-07-05 23:59:25 +00:00
self.sendUpdate('changeGloveResult', [avId, GloveNPCGlobals.CHANGE_SUCCESSFUL])