Poodletooth-iLand/toontown/cogdominium/DistCogdoFlyingGameAI.py

118 lines
4.8 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
2015-03-06 20:46:05 -06:00
from direct.distributed.ClockDelta import *
2015-04-28 02:07:50 -05:00
from toontown.battle import BattleBase
from toontown.building.ElevatorConstants import *
2015-03-03 16:10:12 -06:00
from toontown.cogdominium.DistCogdoGameAI import DistCogdoGameAI
2015-03-06 20:46:05 -06:00
import CogdoFlyingGameGlobals as Globals
2015-03-03 16:10:12 -06:00
class DistCogdoFlyingGameAI(DistCogdoGameAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistCogdoFlyingGameAI")
2015-04-28 02:07:50 -05:00
delayIntro = BattleBase.ELEVATOR_T + ElevatorData[ELEVATOR_FIELD]['openTime']
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __init__(self, air):
DistCogdoGameAI.__init__(self, air)
self.completed = []
self.eagles = {}
self.totalMemos = 0
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def requestAction(self, action, data):
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if not av:
return
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
if action == Globals.AI.GameActions.LandOnWinPlatform:
self.completed.append(avId)
for toon in self.toons:
if toon not in self.completed:
return
self.gameDone()
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
elif action == Globals.AI.GameActions.BladeLost:
self.sendUpdate("toonBladeLost", [avId])
elif action == Globals.AI.GameActions.SetBlades:
self.sendUpdate("toonSetBlades", [avId, data])
elif action == Globals.AI.GameActions.Died:
damage = Globals.AI.SafezoneId2DeathDamage[self.getSafezoneId()]
self.__damage(av, damage)
self.sendUpdate("toonDied", [avId, globalClockDelta.getRealNetworkTime()])
elif action == Globals.AI.GameActions.Spawn:
self.sendUpdate("toonSpawn", [avId, globalClockDelta.getRealNetworkTime()])
elif action == Globals.AI.GameActions.RequestEnterEagleInterest:
if not self.eagles.get(data):
self.eagles[data] = avId
self.sendUpdate("toonSetAsEagleTarget", [avId, data, globalClockDelta.getRealNetworkTime()])
elif action == Globals.AI.GameActions.RequestExitEagleInterest:
if self.eagles.get(data) == avId:
self.eagles[data] = 0
self.sendUpdate("toonClearAsEagleTarget", [avId, data, globalClockDelta.getRealNetworkTime()])
elif action == Globals.AI.GameActions.HitLegalEagle:
damage = Globals.AI.SafezoneId2LegalEagleDamage[self.getSafezoneId()]
self.__damage(av, damage)
elif action == Globals.AI.GameActions.HitMinion:
damage = Globals.AI.SafezoneId2MinionDamage[self.getSafezoneId()]
self.__damage(av, damage)
elif action == Globals.AI.GameActions.HitWhirlwind:
damage = Globals.AI.SafezoneId2WhirlwindDamage[self.getSafezoneId()]
self.__damage(av, damage)
elif action == Globals.AI.GameActions.RanOutOfTimePenalty:
damage = int(20 * self.getDifficulty())
self.__damage(av, damage)
else:
2015-07-05 18:59:25 -05:00
self.notify.warning('Client requested unknown action \'%s\'' %action)
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
def requestPickUp(self, pickupNum, pickupType):
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if not av:
return
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
if pickupType <= len(Globals.Level.GatherableTypes):
self.sendUpdate("pickUp", [avId, pickupNum, globalClockDelta.getRealNetworkTime()])
if pickupType == Globals.Level.GatherableTypes.LaffPowerup:
av.toonUp(int(27 * self.getDifficulty()) + 3)
if pickupType == Globals.Level.GatherableTypes.Memo:
self.totalMemos += 1
else:
2015-07-05 18:59:25 -05:00
self.notify.warning('Client requested unknown pickup \'%s\'' % pickupType)
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
def handleStart(self):
for toon in self.toons:
self.acceptOnce(self.air.getAvatarExitEvent(toon), self.__handleAvExit, [toon])
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __handleAvExit(self, toon):
if self.air:
if toon in self.toons:
self.toons.remove(toon)
self.ignore(self.air.getAvatarExitEvent(toon))
if not self.toons:
self.gameDone(failed=True)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def requestDelete(self):
DistCogdoGameAI.requestDelete(self)
self.ignoreAll()
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __removeToon(self, avId):
if avId not in self.toons:
return
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
self.toons.pop(self.toons.index(avId))
if len(self.toons) == 0:
self.gameDone(failed=True)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __damage(self, av, damage):
av.takeDamage(damage)
if av.getHp() < 1:
self.__removeToon(av.doId)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getTotalMemos(self):
return self.totalMemos
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
from otp.ai.MagicWordGlobal import *
2015-03-26 21:48:23 -05:00
@magicWord(category=CATEGORY_PROGRAMMER)
2015-03-06 20:46:05 -06:00
def endFly():
if hasattr(simbase.air, 'cogdoGame'):
game = simbase.air.cogdoGame
game.requestAction(Globals.AI.GameActions.LandOnWinPlatform, 0)
return 'Finished cogdo flying game!'