Someone else work on this fugly dna shit in OZHoodAI

This commit is contained in:
Loudrob 2015-04-29 18:22:38 -04:00
parent abccde1cfb
commit 2a429014b4
21 changed files with 2707 additions and 630 deletions

View file

@ -485,7 +485,6 @@ from toontown.parties import DistributedPartyValentineJukebox40Activity/AI
from toontown.friends import TTUFriendsManager/UD
from toontown.safezone import DistributedGolfKart/AI
from toontown.safezone import DistributedPicnicBasket/AI
from toontown.safezone import DistributedGameTable/AI
from toontown.distributed import DistributedTimer/AI
from toontown.suit import DistributedBossbotBoss/AI
from toontown.coghq import DistributedCogKart/AI
@ -503,6 +502,7 @@ from toontown.coghq import DistributedGolfSpot/AI
from toontown.minigame import DistributedIceGame/AI
from toontown.minigame import DistributedCogThiefGame/AI
from toontown.minigame import DistributedTwoDGame/AI
from toontown.safezone import DistributedPicnicTable/AI
from toontown.safezone import DistributedChineseCheckers/AI
from toontown.safezone import DistributedCheckers/AI
from toontown.safezone import DistributedFindFour/AI
@ -3151,6 +3151,28 @@ dclass DistributedTwoDGame : DistributedMinigame {
setEveryoneDone() broadcast;
};
dclass DistributedPicnicTable : DistributedNode {
setTableIndex(uint8) required broadcast ram;
fillSlot(uint32, uint8, int16/10, int16/10, int16/10, int16/10, int16/10, int16/10, int16, uint32) broadcast;
emptySlot(uint32, uint8, int16) broadcast;
requestTableState() airecv clsend;
setTableState(uint32 [], uint8) broadcast ram;
setGameZone(uint32, uint8) broadcast;
setIsPlaying(uint8) broadcast ram;
requestJoin(uint8, int16/10, int16/10, int16/10, int16/10, int16/10, int16/10) airecv clsend;
rejectJoin() broadcast;
requestObserve() airecv clsend;
leaveObserve() airecv clsend;
requestGameZone() airecv clsend;
requestPickedGame(uint8) clsend airecv;
requestExit() airecv clsend;
requestZone() clsend airecv;
announceWinner(string, uint32) broadcast;
allowObserve() broadcast;
allowPick() broadcast;
setZone(uint32) broadcast;
};
dclass DistributedChineseCheckers : DistributedNode {
requestExit() clsend airecv;
requestBegin() clsend airecv;

View file

@ -24,7 +24,8 @@ want-parties #t
want-cogdominiums #t
want-lawbot-cogdo #t
want-achievements #f
want-anim-props #f
want-anim-props #t
want-game-tables #t
# Chat:
want-whitelist #f

View file

@ -2,7 +2,7 @@
from pandac.PandaModules import *
hashVal = 3917046557L
hashVal = 1973332971
from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot
@ -22,7 +22,7 @@ from toontown.pets.PetDCImports import *
from toontown.suit import DistributedSuitPlanner, DistributedSuitBase, DistributedSuit, DistributedTutorialSuit, DistributedFactorySuit, DistributedMintSuit, DistributedStageSuit, DistributedSellbotBoss, DistributedCashbotBoss, DistributedCashbotBossGoon, DistributedGoon, DistributedGridGoon, DistributedLawbotBoss, DistributedLawbotBossSuit, DistributedBossbotBoss
from toontown.distributed import ToontownDistrict, ToontownDistrictStats, DistributedTimer
from toontown.effects import DistributedFireworkShow
from toontown.safezone import DistributedTrolley, DistributedPartyGate, DistributedBoat, DistributedButterfly, DistributedMMPiano, DistributedDGFlower, DistributedFishingSpot, SafeZoneManager, DistributedTreasure, DistributedGolfKart, DistributedPicnicBasket, DistributedGameTable, DistributedChineseCheckers, DistributedCheckers, DistributedFindFour
from toontown.safezone import DistributedTrolley, DistributedPartyGate, DistributedBoat, DistributedButterfly, DistributedMMPiano, DistributedDGFlower, DistributedFishingSpot, SafeZoneManager, DistributedTreasure, DistributedGolfKart, DistributedPicnicBasket, DistributedPicnicTable, DistributedChineseCheckers, DistributedCheckers, DistributedFindFour
from toontown.fishing import DistributedFishingPond, DistributedFishingTarget, DistributedPondBingoManager
from toontown.minigame import DistributedMinigame, DistributedMinigameTemplate, DistributedRaceGame, DistributedCannonGame, DistributedPhotoGame, DistributedPatternGame, DistributedRingGame, DistributedTagGame, DistributedMazeGame, DistributedTugOfWarGame, DistributedCatchGame, DistributedDivingGame, DistributedTargetGame, DistributedTravelGame, DistributedPairingGame, DistributedVineGame, DistributedIceGame, DistributedCogThiefGame, DistributedTwoDGame
from toontown.racing import DistributedVehicle, DistributedStartingBlock, DistributedRace, DistributedKartPad, DistributedRacePad, DistributedViewPad, DistributedStartingBlock, DistributedLeaderBoard, DistributedGag, DistributedProjectile

View file

@ -536,6 +536,7 @@ MonthlySchedule = ((7,
#CatalogGardenItem(104, 1),
CatalogToonStatueItem(105, endPoseIndex=108),
CatalogRentalItem(1, 2880, 1000),
CatalogRentalItem(2, 2890, 1000),
#CatalogGardenStarterItem(), # We don't want Gardens yet.
CatalogNametagItem(100),
CatalogNametagItem(0),

View file

@ -130,5 +130,7 @@ def getAllRentalItems():
list = []
for rentalType in (ToontownGlobals.RentalCannon,):
list.append(CatalogRentalItem(rentalType, 2880, 1000))
for rentalType in (ToontownGlobals.RentalGameTable,):
list.append(CatalogRentalItem(rentalType, 2890, 1000))
return list

View file

@ -1,29 +1,29 @@
from direct.controls.ControlManager import CollisionHandlerRayStart
from direct.distributed import DistributedObject
from pandac.PandaModules import *
from toontown.toonbase.ToonBaseGlobal import *
from toontown.toonbase import ToontownGlobals
from direct.distributed.ClockDelta import *
from direct.interval.IntervalGlobal import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *
from direct.task.Task import Task
import math
from pandac.PandaModules import *
from pandac.PandaModules import *
import CannonGlobals
from toontown.effects import DustCloud
from toontown.effects import Splash
from toontown.effects import Wake
from toontown.minigame import CannonGameGlobals
from toontown.minigame import Trajectory
from toontown.nametag.NametagFloat3d import NametagFloat3d
from toontown.toon import ToonHead
from toontown.toonbase import TTLocalizer
from toontown.toonbase import ToontownGlobals
from toontown.toonbase import ToontownGlobals
from toontown.toonbase import ToontownTimer
from toontown.toonbase.ToonBaseGlobal import *
from direct.task.Task import Task
from toontown.minigame import Trajectory
import math
from toontown.toon import ToonHead
from toontown.effects import Splash
from toontown.effects import DustCloud
from toontown.minigame import CannonGameGlobals
import CannonGlobals
from direct.gui.DirectGui import *
from pandac.PandaModules import *
from toontown.toonbase import TTLocalizer
from direct.distributed import DistributedObject
from toontown.effects import Wake
from direct.controls.ControlManager import CollisionHandlerRayStart
from toontown.nametag.NametagFloat3d import NametagFloat3d
from toontown.nametag.Nametag import Nametag
LAND_TIME = 2
WORLD_SCALE = 2.0
@ -258,8 +258,8 @@ class DistributedCannon(DistributedObject.DistributedObject):
base.cr.playGame.getPlace().setState('fishing')
base.localAvatar.setTeleportAvailable(0)
base.localAvatar.collisionsOff()
base.setCellsActive([base.bottomCells[3], base.bottomCells[4]], 0)
base.setCellsActive([base.rightCells[1]], 0)
base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0)
base.setCellsAvailable([base.rightCells[1]], 0)
self.localToonShooting = 1
self.__makeGui()
camera.reparentTo(self.barrel)
@ -267,7 +267,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
self.curPinballScore = 0
self.curPinballMultiplier = 1
self.incrementPinballInfo(0, 0)
if self.avId in self.cr.doId2do:
if self.cr.doId2do.has_key(self.avId):
self.av = self.cr.doId2do[self.avId]
self.acceptOnce(self.av.uniqueName('disable'), self.__avatarGone)
self.av.stopSmooth()
@ -275,8 +275,8 @@ class DistributedCannon(DistributedObject.DistributedObject):
else:
self.notify.warning('Unknown avatar %d in cannon %d' % (self.avId, self.doId))
if wasLocalToon and not self.localToonShooting:
base.setCellsActive([base.bottomCells[3], base.bottomCells[4]], 1)
base.setCellsActive([base.rightCells[1]], 1)
base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1)
base.setCellsAvailable([base.rightCells[1]], 1)
def __avatarGone(self):
self.setMovie(CannonGlobals.CANNON_MOVIE_CLEAR, 0)
@ -411,7 +411,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
self.av.loop('neutral')
self.av.setPlayRate(1.0, 'run')
if hasattr(self.av, 'nametag'):
self.av.nametag.remove(self.toonHead.tag)
self.av.nametag.removeNametag(self.toonHead.tag)
if self.toonHead != None:
self.toonHead.stopBlink()
self.toonHead.stopLookAroundNow()
@ -467,12 +467,11 @@ class DistributedCannon(DistributedObject.DistributedObject):
self.toonHead.setupHead(self.av.style)
self.toonHead.reparentTo(hidden)
tag = NametagFloat3d()
tag.hideNametag()
tag.update()
tag.setContents(Nametag.CSpeech | Nametag.CThought)
tag.setBillboardOffset(0)
tag.setAvatar(self.toonHead)
toon.nametag.add(tag)
tagPath = self.toonHead.attachNewNode(tag.upcastToPandaNode())
toon.nametag.addNametag(tag)
tagPath = self.toonHead.attachNewNode(tag)
tagPath.setPos(0, 0, 1)
self.toonHead.tag = tag
self.__loadToonInCannon()
@ -844,6 +843,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
flyTask.info = info
seqTask = Task.sequence(shootTask, smokeTask, flyTask)
if self.av == base.localAvatar:
print 'disable controls'
base.localAvatar.disableAvatarControls()
taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(avId))
self.acceptOnce(self.uniqueName('stopFlyTask'), self.__stopFlyTask)
@ -865,6 +865,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
def removeAvFromCannon(self):
place = base.cr.playGame.getPlace()
print 'removeAvFromCannon'
self.notify.debug('self.inWater = %s' % self.inWater)
if place:
if not hasattr(place, 'fsm'):
@ -884,7 +885,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
if place and not self.inWater:
place.fsm.request('walk')
self.av.setPlayRate(1.0, 'run')
self.av.nametag.remove(self.toonHead.tag)
self.av.nametag.removeNametag(self.toonHead.tag)
if self.av.getParent().getName() == 'toonOriginChange':
self.av.wrtReparentTo(render)
self.__setToonUpright(self.av)
@ -893,6 +894,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
self.av.startSmooth()
self.av.setScale(1, 1, 1)
if self.av == base.localAvatar:
print 'enable controls'
base.localAvatar.enableAvatarControls()
self.ignore(self.av.uniqueName('disable'))
self.__destroyToonModels()
@ -1160,6 +1162,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
if hitP[2] > ToontownGlobals.EstateWakeWaterHeight:
self.notify.debug('we hit the ground before we hit water')
self.__hitGround(avatar, pos, extraArgs)
print 'but not really'
return
self.inWater = 1
self.notify.debug('hit water')
@ -1242,7 +1245,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
for id in doIds:
t = self.cr.doId2do.get(id)
if t:
pos = t.pos
pos = t.nodePath.getPos()
rad = 10.5
height = 10.0
t_impact = trajectory.checkCollisionWithCylinderSides(pos, rad, height)
@ -1508,7 +1511,7 @@ class DistributedCannon(DistributedObject.DistributedObject):
(0, 1, 5, 4),
(0, 4, 7, 3),
(1, 2, 6, 5)]
for i in xrange(len(vertices)):
for i in range(len(vertices)):
vertex = vertices[i]
vertexWriter.addData3f(vertex[0], vertex[1], vertex[2])
colorWriter.addData4f(*colors[i])
@ -1577,4 +1580,5 @@ class DistributedCannon(DistributedObject.DistributedObject):
def turnOnBumperCollision(self, whatever = 0):
if self.bumperCol:
self.bumperCol.setCollideMask(ToontownGlobals.WallBitmask)# decompiled 0 files: 0 okay, 1 failed, 0 verify failed
self.bumperCol.setCollideMask(ToontownGlobals.WallBitmask)

View file

@ -17,6 +17,8 @@ from DistributedCannonAI import *
from DistributedTargetAI import *
import CannonGlobals
import TableGlobals
class Rental:
def __init__(self, estate):
self.estate = estate
@ -57,7 +59,7 @@ class CannonRental(Rental):
for i in xrange(20):
x = random.randint(100, 300) - 200
y = random.randint(100, 300) - 200
treasure = DistributedTreasureAI.DistributedTreasureAI(self.estate.air, self, 9, x, y, z)
treasure = DistributedTreasureAI.DistributedTreasureAI(self.estate.air, self, 7, x, y, z)
treasure.generateWithRequired(self.estate.zoneId)
self.objects.add(treasure)
doIds.append(treasure.doId)
@ -300,6 +302,8 @@ class DistributedEstateAI(DistributedObjectAI):
if self.rentalType == ToontownGlobals.RentalCannon:
self.rentalHandle = CannonRental(self)
elif self.rentalType == ToontownGlobals.RentalGameTable:
self.rentalHandle = TableRental(self)
else:
self.notify.warning('Unknown rental %s' % self.rentalType)

View file

@ -1,10 +1,15 @@
from toontown.hood import HoodAI
from pandac.PandaModules import *
from toontown.toonbase import ToontownGlobals
from toontown.distributed.DistributedTimerAI import DistributedTimerAI
import string
from toontown.dna.DNAParser import DNAGroup, DNAVisGroup
from toontown.safezone.DistributedPicnicBasketAI import DistributedPicnicBasketAI
from toontown.safezone import DistributedGameTableAI
from toontown.safezone import DistributedPicnicTableAI
from toontown.safezone import DistributedChineseCheckersAI
from toontown.safezone import DistributedCheckersAI
from toontown.hood import ZoneUtil
import random
class OZHoodAI(HoodAI.HoodAI):
@ -31,6 +36,7 @@ class OZHoodAI(HoodAI.HoodAI):
self.timer = DistributedTimerAI(self.air)
self.timer.generateWithRequired(self.zoneId)
def findPicnicTables(self, dnaGroup, zoneId, area, overrideDNAZone=False):
picnicTables = []
if isinstance(dnaGroup, DNAGroup) and ('picnic_table' in dnaGroup.getName()):
@ -74,9 +80,11 @@ class OZHoodAI(HoodAI.HoodAI):
if 'game_table' in childDnaGroup.getName():
pos = childDnaGroup.getPos()
hpr = childDnaGroup.getHpr()
gameTable = DistributedGameTableAI.DistributedGameTableAI(simbase.air)
gameTable.setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2])
gameTable.generateWithRequired(zoneId)
nameInfo = childDnaGroup.getName().split('_')
tableIndex = int(childDnaGroup.parent.getName().split('_')[-1])
gameTable = DistributedPicnicTableAI.DistributedPicnicTableAI(simbase.air, zoneId, nameInfo[2], pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2])
gameTable.setTableIndex(tableIndex)
gameTable.generateOtpObject(simbase.air.districtId, zone, ['setX', 'setY', 'setZ', 'setH', 'setP', 'setR'])
elif isinstance(dnaGroup, DNAVisGroup) and (not overrideDNAZone):
zoneId = ZoneUtil.getTrueZoneId(int(dnaGroup.getName().split(':')[0]), zoneId)
for i in xrange(dnaGroup.getNumChildren()):

View file

@ -95,7 +95,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
x = self.boardNode.find('**/locator*')
self.locatorList = x.getChildren()
tempList = []
for x in xrange(0, 32):
for x in range(0, 32):
self.locatorList[x].setTag('GamePeiceLocator', '%d' % x)
tempList.append(self.locatorList[x].attachNewNode(CollisionNode('picker%d' % x)))
tempList[x].node().addSolid(CollisionSphere(0, 0, 0, 0.39))
@ -451,7 +451,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
def existsLegalJumpsFrom(self, index, peice):
if peice == 'king':
for x in xrange(4):
for x in range(4):
if self.board.squareList[index].getAdjacent()[x] != None and \
self.board.squareList[index].getJumps()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
@ -513,7 +513,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
else:
moveForward = [0, 3]
if peice == 'king':
for x in xrange(4):
for x in range(4):
if firstSquare.getAdjacent()[x] != None:
if self.board.squareList[firstSquare.getAdjacent()[x]].getState() == 0 and secondSquare.getNum() in firstSquare.getAdjacent():
return True
@ -583,7 +583,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
self.playerNum = 1
self.playerColorString = 'white'
isObserve = True
for xx in xrange(32):
for xx in range(32):
for blah in self.locatorList[xx].getChildren():
blah.hide()
if self.locatorList[xx].getChildren().index(blah) != 0:
@ -671,7 +671,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
return
def hideChildren(self, nodeList):
for x in xrange(1, 2):
for x in range(1, 2):
nodeList[x].hide()
def animatePeice(self, tableState, moveList, type, playerColor):
@ -693,7 +693,7 @@ class DistributedCheckers(DistributedNode.DistributedNode):
checkersPeiceTrack = Sequence()
length = len(moveList)
for x in xrange(length - 1):
for x in range(length - 1):
checkersPeiceTrack.append(Parallel(SoundInterval(self.moveSound), ProjectileInterval(gamePeiceForAnimation, endPos=self.locatorList[moveList[x + 1]].getPos(), duration=0.5)))
checkersPeiceTrack.append(Func(gamePeiceForAnimation.removeNode))

View file

@ -1,48 +1,675 @@
from direct.directnotify import DirectNotifyGlobal
# File: D (Python 2.4)
from direct.distributed.DistributedNodeAI import DistributedNodeAI
from direct.distributed.ClockDelta import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.fsm import StateData
from direct.distributed.ClockDelta import *
from toontown.safezone import CheckersBoard
class DistributedCheckersAI(DistributedNodeAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedCheckersAI")
def __init__(self, air, parent, name, x, y, z, h, p, r):
DistributedNodeAI.__init__(self, air)
self.name = name
self.air = air
self.setPos(x, y, z)
self.setHpr(h, p, r)
self.myPos = (x, y, z)
self.myHpr = (h, p, r)
self.board = CheckersBoard.CheckersBoard()
self.parent = self.air.doId2do[parent]
self.parentDo = parent
self.wantStart = []
self.playersPlaying = []
self.playersSitting = 0
self.playersTurn = 1
self.movesMade = 0
self.playerNum = 1
self.hasWon = False
self.playersGamePos = [
None,
None]
self.wantTimer = True
self.timerEnd = 0
self.turnEnd = 0
self.playersObserving = []
self.winLaffPoints = 20
self.movesRequiredToWin = 10
self.zoneId = self.air.allocateZone()
self.generateOtpObject(air.districtId, self.zoneId, optionalFields = [
'setX',
'setY',
'setZ',
'setH',
'setP',
'setR'])
self.parent.setCheckersZoneId(self.zoneId)
self.startingPositions = [
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11],
[
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31]]
self.kingPositions = [
[
31,
30,
29,
28],
[
0,
1,
2,
3]]
self.timerStart = None
self.fsm = ClassicFSM.ClassicFSM('Checkers', [
State.State('waitingToBegin', self.enterWaitingToBegin, self.exitWaitingToBegin, [
'playing']),
State.State('playing', self.enterPlaying, self.exitPlaying, [
'gameOver']),
State.State('gameOver', self.enterGameOver, self.exitGameOver, [
'waitingToBegin'])], 'waitingToBegin', 'waitingToBegin')
self.fsm.enterInitialState()
def requestExit(self):
pass
def announceGenerate(self):
self.parent.setGameDoId(self.doId)
def requestBegin(self):
pass
def getTableDoId(self):
return self.parentDo
def delete(self):
self.fsm.requestFinalState()
self.board.delete()
del self.fsm
DistributedNodeAI.delete(self)
def informGameOfPlayer(self):
self.playersSitting += 1
if self.playersSitting < 2:
self.timerEnd = 0
elif self.playersSitting == 2:
self.timerEnd = globalClock.getRealTime() + 20
self.parent.isAccepting = False
self.parent.sendUpdate('setIsPlaying', [
1])
elif self.playersSitting > 2:
pass
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def informGameOfPlayerLeave(self):
self.playersSitting -= 1
if self.playersSitting < 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
self.timerEnd = 0
self.parent.isAccepting = True
self.parent.sendUpdate('setIsPlaying', [
0])
if self.playersSitting > 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
pass
1
self.timerEnd = 0
if self.timerEnd != 0:
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
else:
self.sendUpdate('setTimer', [
0])
def setGameCountdownTime(self):
self.timerEnd = globalClock.getRealTime() + 10
def setTurnCountdownTime(self):
self.turnEnd = globalClock.getRealTime() + 40
def getTimer(self):
if self.timerEnd != 0:
return 0
else:
return 0
def getTurnTimer(self):
return globalClockDelta.localToNetworkTime(self.turnEnd)
def requestTimer(self):
pass
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def requestMove(self, todo0):
pass
def handlePlayerExit(self, avId):
if avId in self.wantStart:
self.wantStart.remove(avId)
if self.fsm.getCurrentState().getName() == 'playing':
gamePos = self.playersGamePos.index(avId)
self.playersGamePos[gamePos] = None
self.fsm.request('gameOver')
def startBeginTimer(self, todo0, todo1):
pass
def gameStart(self, todo0):
pass
def setTableDoId(self, todo0):
pass
def setGameState(self, todo0, todo1):
pass
def setTimer(self, todo0):
pass
def setTurnTimer(self, todo0):
pass
def sendTurn(self, todo0):
pass
def handleEmptyGame(self):
self.movesMade = 0
self.playersTurn = 1
self.playerNum = 1
self.fsm.request('waitingToBegin')
self.parent.isAccepting = True
def requestWin(self):
avId = self.air.getAvatarIdFromSender()
def distributeLaffPoints(self):
for x in self.parent.seats:
if x != None:
av = self.air.doId2do.get(x)
av.toonUp(self.winLaffPoints)
continue
def enterWaitingToBegin(self):
self.setGameCountdownTime()
self.parent.isAccepting = True
def exitWaitingToBegin(self):
self.turnEnd = 0
def enterPlaying(self):
self.parent.isAccepting = False
for x in self.playersGamePos:
if x != None:
self.playersTurn = self.playersGamePos.index(x)
self.d_sendTurn(self.playersTurn + 1)
break
continue
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
def exitPlaying(self):
pass
def announceWin(self, todo0):
def enterGameOver(self):
self.timerEnd = 0
isAccepting = True
self.parent.handleGameOver()
self.playersObserving = []
self.playersTurn = 1
self.playerNum = 1
self.clearBoard()
self.sendGameState([])
self.movesMade = 0
self.playersGamePos = [
None,
None,
None,
None,
None,
None]
self.parent.isAccepting = True
self.fsm.request('waitingToBegin')
def exitGameOver(self):
pass
def illegalMove(self):
pass
def requestBegin(self):
avId = self.air.getAvatarIdFromSender()
if avId not in self.wantStart:
self.wantStart.append(avId)
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers = numPlayers + 1
continue
if len(self.wantStart) == numPlayers and numPlayers >= 2:
self.d_gameStart(avId)
self.parent.sendIsPlaying()
def d_gameStart(self, avId):
for x in self.playersObserving:
self.sendUpdateToAvatarId(x, 'gameStart', [
255])
zz = 0
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers += 1
self.playersPlaying.append(x)
continue
if numPlayers == 2:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
for x in self.startingPositions[0]:
self.board.setState(x, 1)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
2])
self.playersGamePos[1] = player2
for x in self.startingPositions[1]:
self.board.setState(x, 2)
self.sendGameState([])
self.wantStart = []
self.fsm.request('playing')
self.parent.getTableState()
def d_sendTurn(self, playersTurn):
self.sendUpdate('sendTurn', [
playersTurn])
def advancePlayerTurn(self):
if self.playersTurn == 0:
self.playersTurn = 1
self.playerNum = 2
else:
self.playerNum = 1
self.playersTurn = 0
def requestMove(self, moveList):
if self.checkLegalMoves(moveList) == True:
self.makeMove(moveList)
self.advancePlayerTurn()
self.d_sendTurn(self.playersTurn + 1)
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
else:
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'illegalMove', [])
self.air.writeServerEvent('suspicious', avId, 'has requested an illegal move in Regular checkers - not possible')
def checkLegalMoves(self, moveList):
if self.board.squareList[moveList[0]].getState() >= 3:
moveType = 'king'
else:
moveType = 'normal'
if len(moveList) == 2:
firstSquare = self.board.squareList[moveList[0]]
secondSquare = self.board.squareList[moveList[1]]
if self.checkLegalMove(firstSquare, secondSquare, moveType) == True:
return True
else:
for x in range(len(moveList) - 1):
y = self.checkLegalJump(self.board.getSquare(moveList[x]), self.board.getSquare(moveList[x + 1]), moveType)
if y == False:
return False
else:
return True
return False
elif len(moveList) > 2:
for x in range(len(moveList) - 1):
y = self.checkLegalJump(self.board.getSquare(moveList[x]), self.board.getSquare(moveList[x + 1]), moveType)
if y == False:
return False
continue
return True
def makeMove(self, moveList):
for x in range(len(moveList) - 1):
firstSquare = self.board.squareList[moveList[x]]
secondSquare = self.board.squareList[moveList[x + 1]]
if firstSquare.getNum() in secondSquare.getAdjacent():
break
index = firstSquare.jumps.index(secondSquare.getNum())
self.board.squareList[firstSquare.getAdjacent()[index]].setState(0)
haveMoved = False
squareState = self.board.squareList[moveList[0]].getState()
if squareState <= 2:
piecetype = 'normal'
if squareState == 1:
playerNum = 1
else:
playerNum = 2
else:
piecetype = 'king'
if squareState == 3:
playerNum = 1
else:
playerNum = 2
if piecetype == 'normal':
lastElement = moveList[len(moveList) - 1]
if playerNum == 1:
if lastElement in self.kingPositions[0]:
self.board.squareList[moveList[0]].setState(0)
self.board.squareList[lastElement].setState(3)
haveMoved = True
self.sendGameState(moveList)
elif lastElement in self.kingPositions[1]:
self.board.squareList[moveList[0]].setState(0)
self.board.squareList[lastElement].setState(4)
haveMoved = True
self.sendGameState(moveList)
if haveMoved == False:
spot1 = self.board.squareList[moveList[0]].getState()
self.board.squareList[moveList[0]].setState(0)
self.board.squareList[moveList[len(moveList) - 1]].setState(spot1)
self.sendGameState(moveList)
temp = self.playerNum
self.playerNum = 1
if self.hasWon == True:
return None
if self.hasPeicesAndMoves(1, 3) == False:
self.parent.announceWinner('Checkers', self.playersPlaying[1])
self.fsm.request('gameOver')
self.hasWon = True
return None
self.playerNum = temp
temp = self.playerNum
self.playerNum = 2
if self.hasPeicesAndMoves(2, 4) == False:
self.parent.announceWinner('Checkers', self.playersPlaying[0])
self.fsm.request('gameOver')
self.hasWon = True
return None
self.playerNum = temp
def hasPeicesAndMoves(self, normalNum, kingNum):
for x in self.board.squareList:
if x.getState() == normalNum:
if self.existsLegalMovesFrom(x.getNum(), 'normal') == True:
return True
if self.existsLegalJumpsFrom(x.getNum(), 'normal') == True:
return True
self.existsLegalJumpsFrom(x.getNum(), 'normal') == True
if x.getState() == kingNum:
if self.existsLegalMovesFrom(x.getNum(), 'king') == True:
return True
if self.existsLegalJumpsFrom(x.getNum(), 'king') == True:
return True
self.existsLegalJumpsFrom(x.getNum(), 'king') == True
return False
def getState(self):
return self.fsm.getCurrentState().getName()
def getName(self):
return self.name
def getGameState(self):
return [
self.board.getStates(),
[]]
def sendGameState(self, moveList):
gameState = self.board.getStates()
self.sendUpdate('setGameState', [
gameState,
moveList])
def clearBoard(self):
for x in self.board.squareList:
x.setState(0)
def getPosHpr(self):
return self.posHpr
def existsLegalJumpsFrom(self, index, peice):
if peice == 'king':
for x in range(4):
if self.board.squareList[index].getAdjacent()[x] != None and self.board.squareList[index].getJumps()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
jump = self.board.squareList[self.board.squareList[index].getJumps()[x]]
if adj.getState() == 0:
pass
elif adj.getState() == self.playerNum or adj.getState() == self.playerNum + 2:
pass
elif jump.getState() == 0:
return True
adj.getState() == self.playerNum + 2
return False
elif peice == 'normal':
if self.playerNum == 1:
moveForward = [
1,
2]
elif self.playerNum == 2:
moveForward = [
0,
3]
for x in moveForward:
if self.board.squareList[index].getAdjacent()[x] != None and self.board.squareList[index].getJumps()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
jump = self.board.squareList[self.board.squareList[index].getJumps()[x]]
if adj.getState() == 0:
pass
elif adj.getState() == self.playerNum or adj.getState() == self.playerNum + 2:
pass
elif jump.getState() == 0:
return True
adj.getState() == self.playerNum + 2
return False
def existsLegalMovesFrom(self, index, peice):
if peice == 'king':
for x in self.board.squareList[index].getAdjacent():
if x != None:
if self.board.squareList[x].getState() == 0:
return True
self.board.squareList[x].getState() == 0
return False
elif peice == 'normal':
if self.playerNum == 1:
moveForward = [
1,
2]
elif self.playerNum == 2:
moveForward = [
0,
3]
for x in moveForward:
if self.board.squareList[index].getAdjacent()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
if adj.getState() == 0:
return True
adj.getState() == 0
return False
def existsLegalJumpsFrom(self, index, peice):
if peice == 'king':
for x in range(4):
if self.board.squareList[index].getAdjacent()[x] != None and self.board.squareList[index].getJumps()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
jump = self.board.squareList[self.board.squareList[index].getJumps()[x]]
if adj.getState() == 0:
pass
elif adj.getState() == self.playerNum or adj.getState() == self.playerNum + 2:
pass
elif jump.getState() == 0:
return True
adj.getState() == self.playerNum + 2
return False
elif peice == 'normal':
if self.playerNum == 1:
moveForward = [
1,
2]
elif self.playerNum == 2:
moveForward = [
0,
3]
for x in moveForward:
if self.board.squareList[index].getAdjacent()[x] != None and self.board.squareList[index].getJumps()[x] != None:
adj = self.board.squareList[self.board.squareList[index].getAdjacent()[x]]
jump = self.board.squareList[self.board.squareList[index].getJumps()[x]]
if adj.getState() == 0:
pass
elif adj.getState() == self.playerNum or adj.getState() == self.playerNum + 2:
pass
elif jump.getState() == 0:
return True
adj.getState() == self.playerNum + 2
return False
def checkLegalMove(self, firstSquare, secondSquare, peice):
if self.playerNum == 1:
moveForward = [
1,
2]
else:
moveForward = [
0,
3]
if peice == 'king':
for x in range(4):
if firstSquare.getAdjacent()[x] != None:
if self.board.squareList[firstSquare.getAdjacent()[x]].getState() == 0:
return True
self.board.squareList[firstSquare.getAdjacent()[x]].getState() == 0
return False
elif peice == 'normal':
for x in moveForward:
if firstSquare.getAdjacent()[x] != None:
if self.board.squareList[firstSquare.getAdjacent()[x]].getState() == 0:
return True
self.board.squareList[firstSquare.getAdjacent()[x]].getState() == 0
return False
def checkLegalJump(self, firstSquare, secondSquare, peice):
if self.playerNum == 1:
moveForward = [
1,
2]
opposingPeices = [
2,
4]
else:
moveForward = [
0,
3]
opposingPeices = [
1,
3]
if peice == 'king':
if secondSquare.getNum() in firstSquare.getJumps():
index = firstSquare.getJumps().index(secondSquare.getNum())
if self.board.squareList[firstSquare.getAdjacent()[index]].getState() in opposingPeices:
return True
else:
return False
elif peice == 'normal':
if secondSquare.getNum() in firstSquare.getJumps():
index = firstSquare.getJumps().index(secondSquare.getNum())
if index in moveForward:
if self.board.squareList[firstSquare.getAdjacent()[index]].getState() in opposingPeices:
return True
else:
return False
else:
return False
else:
return False

View file

@ -143,7 +143,7 @@ class DistributedChineseCheckers(DistributedNode.DistributedNode):
x = self.boardNode.find('**/locators')
self.locatorList = x.getChildren()
tempList = []
for x in xrange(0, 121):
for x in range(0, 121):
self.locatorList[x].setTag('GamePeiceLocator', '%d' % x)
tempList.append(self.locatorList[x].attachNewNode(CollisionNode('picker%d' % x)))
tempList[x].node().addSolid(CollisionSphere(0, 0, 0, 0.115))
@ -299,7 +299,7 @@ class DistributedChineseCheckers(DistributedNode.DistributedNode):
def announceSeatPositions(self, playerPos):
self.playerSeats = playerPos
for x in xrange(6):
for x in range(6):
pos = self.table.seats[x].getPos(render)
renderedPeice = loader.loadModel('phase_6/models/golf/checker_marble.bam')
renderedPeice.reparentTo(self.playerTags)
@ -640,7 +640,7 @@ class DistributedChineseCheckers(DistributedNode.DistributedNode):
self.board.setStates(squares)
self.mySquares = []
messenger.send('wakeup')
for x in xrange(121):
for x in range(121):
self.locatorList[x].clearColor()
owner = self.board.squareList[x].getState()
if owner == self.playerNum:
@ -674,7 +674,7 @@ class DistributedChineseCheckers(DistributedNode.DistributedNode):
self.locatorList[moveList[0]].hide()
checkersPeiceTrack = Sequence()
length = len(moveList)
for x in xrange(length - 1):
for x in range(length - 1):
checkersPeiceTrack.append(Parallel(SoundInterval(self.moveSound), ProjectileInterval(gamePeiceForAnimation, endPos=self.locatorList[moveList[x + 1]].getPos(), duration=0.5)))
checkersPeiceTrack.append(Func(gamePeiceForAnimation.removeNode))

View file

@ -1,51 +1,694 @@
from direct.directnotify import DirectNotifyGlobal
# File: D (Python 2.4)
from direct.distributed.DistributedNodeAI import DistributedNodeAI
from direct.distributed.ClockDelta import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.fsm import StateData
from direct.distributed.ClockDelta import *
from toontown.safezone import ChineseCheckersBoard
class DistributedChineseCheckersAI(DistributedNodeAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedChineseCheckersAI")
def __init__(self, air, parent, name, x, y, z, h, p, r):
DistributedNodeAI.__init__(self, air)
self.name = name
self.air = air
self.setPos(x, y, z)
self.setHpr(h, p, r)
self.myPos = (x, y, z)
self.myHpr = (h, p, r)
self.board = ChineseCheckersBoard.ChineseCheckersBoard()
self.parent = self.air.doId2do[parent]
self.parentDo = parent
self.wantStart = []
self.playersPlaying = []
self.playersSitting = 0
self.playersTurn = 1
self.movesMade = 0
self.playersGamePos = [
None,
None,
None,
None,
None,
None]
self.wantTimer = True
self.timerEnd = 0
self.turnEnd = 0
self.playersObserving = []
self.winLaffPoints = 20
self.movesRequiredToWin = 10
self.zoneId = self.air.allocateZone()
self.generateOtpObject(air.districtId, self.zoneId, optionalFields = [
'setX',
'setY',
'setZ',
'setH',
'setP',
'setR'])
self.parent.setCheckersZoneId(self.zoneId)
self.startingPositions = [
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9],
[
10,
11,
12,
13,
23,
24,
25,
35,
36,
46],
[
65,
75,
76,
86,
87,
88,
98,
99,
100,
101],
[
111,
112,
113,
114,
115,
116,
117,
118,
119,
120],
[
74,
84,
85,
95,
96,
97,
107,
108,
109,
110],
[
19,
20,
21,
22,
32,
33,
34,
44,
45,
55]]
self.timerStart = None
self.fsm = ClassicFSM.ClassicFSM('ChineseCheckers', [
State.State('waitingToBegin', self.enterWaitingToBegin, self.exitWaitingToBegin, [
'playing']),
State.State('playing', self.enterPlaying, self.exitPlaying, [
'gameOver']),
State.State('gameOver', self.enterGameOver, self.exitGameOver, [
'waitingToBegin'])], 'waitingToBegin', 'waitingToBegin')
self.fsm.enterInitialState()
def requestExit(self):
pass
def announceGenerate(self):
self.parent.setGameDoId(self.doId)
def requestBegin(self):
pass
def getTableDoId(self):
return self.parentDo
def requestMove(self, todo0):
pass
def requestTimer(self):
pass
def delete(self):
self.fsm.requestFinalState()
self.board.delete()
self.playerSeatPos = None
del self.fsm
DistributedNodeAI.delete(self)
def requestSeatPositions(self):
pass
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'announceSeatPositions', [
self.playerSeatPos])
self.sendUpdateToAvatarId(avId, 'sendTurn', [
self.playersTurn + 1])
def startBeginTimer(self, todo0, todo1):
pass
def informGameOfPlayer(self):
self.playersSitting += 1
if self.playersSitting < 2:
self.timerEnd = 0
elif self.playersSitting == 2:
self.timerEnd = globalClock.getRealTime() + 60
elif self.playersSitting > 2:
pass
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def gameStart(self, todo0):
pass
def informGameOfPlayerLeave(self):
self.playersSitting -= 1
if self.playersSitting < 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
self.timerEnd = 0
if self.playersSitting > 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
pass
1
self.timerEnd = 0
if self.timerEnd != 0:
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
else:
self.sendUpdate('setTimer', [
0])
def setTableDoId(self, todo0):
pass
def setGameCountdownTime(self):
self.timerEnd = globalClock.getRealTime() + 60
def setGameState(self, todo0, todo1):
pass
def setTurnCountdownTime(self):
self.turnEnd = globalClock.getRealTime() + 60
def setTimer(self, todo0):
pass
def getTimer(self):
if self.timerEnd != 0:
return 0
else:
return 0
def setTurnTimer(self, todo0):
pass
def getTurnTimer(self):
return globalClockDelta.localToNetworkTime(self.turnEnd)
def sendTurn(self, todo0):
pass
def requestTimer(self):
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def handlePlayerExit(self, avId):
playerOrder = [
1,
4,
2,
5,
3,
6]
if avId in self.wantStart:
self.wantStart.remove(avId)
playstate = self.fsm.getStateNamed('playing')
if self.fsm.getCurrentState().getName() == 'playing':
gamePos = self.playersGamePos.index(avId)
self.playersGamePos[gamePos] = None
for x in self.board.squareList:
if x.getState() == gamePos + 1:
x.setState(0)
continue
self.sendGameState([])
if self.playersTurn == gamePos:
self.advancePlayerTurn()
self.d_sendTurn(self.playersTurn + 1)
remainingPlayers = 0
for x in self.playersGamePos:
if x != None:
remainingPlayers += 1
continue
if remainingPlayers == 1:
for x in self.playersGamePos:
if x != None:
self.clearBoard()
self.sendGameState([])
if self.movesMade >= self.movesRequiredToWin:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', x)
else:
self.fsm.request('gameOver')
def handleEmptyGame(self):
self.movesMade = 0
self.playersPlaying = []
self.playersTurn = 1
self.fsm.request('waitingToBegin')
def requestWin(self):
avId = self.air.getAvatarIdFromSender()
if avId not in self.playersGamePos:
self.air.writeServerEvent('suspicious', avId, 'Has requested a Chinese Checkers win and is NOT playing! SeatList of the table - %s - PlayersGamePos - %s' % (self.parent.seats, self.playersGamePos))
return None
requestWinGamePos = self.playersGamePos.index(avId) + 1
checkSquares = []
for x in self.board.squareList:
if x.getState() == requestWinGamePos:
checkSquares.append(x.getNum())
continue
if requestWinGamePos == 1:
if checkSquares == self.startingPositions[3]:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
elif requestWinGamePos == 2:
if checkSquares == self.startingPositions[4]:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
elif requestWinGamePos == 3:
if checkSquares == self.startingPositions[5]:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
elif requestWinGamePos == 4:
if checkSquares == self.startingPositions[0]:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
elif requestWinGamePos == 5:
if checkSquares == self.startingPositions[1]:
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
elif requestWinGamePos == 6:
if checkSquares == self.startingPositions[2]:
self.distributeLaffPoints()
self.fsm.request('gameOver')
self.parent.announceWinner('Chinese Checkers', avId)
self.parent = None
def distributeLaffPoints(self):
for x in self.parent.seats:
if x != None:
av = self.air.doId2do.get(x)
av.toonUp(self.winLaffPoints)
continue
def enterWaitingToBegin(self):
self.setGameCountdownTime()
self.parent.isAccepting = True
def exitWaitingToBegin(self):
self.turnEnd = 0
def enterPlaying(self):
self.parent.isAccepting = False
for x in self.playersGamePos:
if x != None:
self.playersTurn = self.playersGamePos.index(x)
self.d_sendTurn(self.playersTurn + 1)
break
continue
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
def exitPlaying(self):
pass
def announceWin(self, todo0):
def enterGameOver(self):
self.timerEnd = 0
isAccepting = True
self.playersObserving = []
self.parent.handleGameOver()
self.playersTurn = 1
self.playersPlaying = []
self.clearBoard()
self.sendGameState([])
self.movesMade = 0
self.playersGamePos = [
None,
None,
None,
None,
None,
None]
self.fsm.request('waitingToBegin')
def exitGameOver(self):
pass
def announceSeatPositions(self, todo0):
pass
def requestBegin(self):
avId = self.air.getAvatarIdFromSender()
if avId not in self.wantStart:
self.wantStart.append(avId)
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers = numPlayers + 1
continue
if len(self.wantStart) == numPlayers and numPlayers >= 2:
self.d_gameStart(avId)
self.parent.sendIsPlaying()
def d_gameStart(self, avId):
for x in self.playersObserving:
self.sendUpdateToAvatarId(x, 'gameStart', [
255])
playerJoinOrder = [
1,
4,
2,
5,
3,
6]
zz = 0
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers += 1
self.playersPlaying.append(x)
continue
if numPlayers == 2:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
for x in self.startingPositions[0]:
self.board.setState(x, 1)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
4])
self.playersGamePos[3] = player2
for x in self.startingPositions[3]:
self.board.setState(x, 4)
elif numPlayers == 3:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
2])
self.playersGamePos[1] = player1
for x in self.startingPositions[1]:
self.board.setState(x, 2)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
4])
self.playersGamePos[3] = player2
for x in self.startingPositions[3]:
self.board.setState(x, 4)
player3 = self.playersPlaying[2]
self.sendUpdateToAvatarId(player3, 'gameStart', [
6])
self.playersGamePos[5] = player3
for x in self.startingPositions[5]:
self.board.setState(x, 6)
elif numPlayers == 4:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
for x in self.startingPositions[0]:
self.board.setState(x, 1)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
4])
self.playersGamePos[3] = player2
for x in self.startingPositions[3]:
self.board.setState(x, 4)
player3 = self.playersPlaying[2]
self.sendUpdateToAvatarId(player3, 'gameStart', [
2])
self.playersGamePos[1] = player3
for x in self.startingPositions[1]:
self.board.setState(x, 2)
player4 = self.playersPlaying[3]
self.sendUpdateToAvatarId(player4, 'gameStart', [
5])
self.playersGamePos[4] = player4
for x in self.startingPositions[4]:
self.board.setState(x, 5)
elif numPlayers == 5:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
for x in self.startingPositions[0]:
self.board.setState(x, 1)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
4])
self.playersGamePos[3] = player2
for x in self.startingPositions[3]:
self.board.setState(x, 4)
player3 = self.playersPlaying[2]
self.sendUpdateToAvatarId(player3, 'gameStart', [
2])
self.playersGamePos[1] = player3
for x in self.startingPositions[1]:
self.board.setState(x, 2)
player4 = self.playersPlaying[3]
self.sendUpdateToAvatarId(player4, 'gameStart', [
5])
self.playersGamePos[4] = player4
for x in self.startingPositions[4]:
self.board.setState(x, 5)
player5 = self.playersPlaying[4]
self.sendUpdateToAvatarId(player5, 'gameStart', [
3])
self.playersGamePos[2] = player5
for x in self.startingPositions[2]:
self.board.setState(x, 3)
elif numPlayers == 6:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
for x in self.startingPositions[0]:
self.board.setState(x, 1)
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
4])
self.playersGamePos[3] = player2
for x in self.startingPositions[3]:
self.board.setState(x, 4)
player3 = self.playersPlaying[2]
self.sendUpdateToAvatarId(player3, 'gameStart', [
2])
self.playersGamePos[1] = player3
for x in self.startingPositions[1]:
self.board.setState(x, 2)
player4 = self.playersPlaying[3]
self.sendUpdateToAvatarId(player4, 'gameStart', [
5])
self.playersGamePos[4] = player4
for x in self.startingPositions[4]:
self.board.setState(x, 5)
player5 = self.playersPlaying[4]
self.sendUpdateToAvatarId(player5, 'gameStart', [
3])
self.playersGamePos[2] = player5
for x in self.startingPositions[2]:
self.board.setState(x, 3)
player6 = self.playersPlaying[5]
self.sendUpdateToAvatarId(player6, 'gameStart', [
6])
self.playersGamePos[5] = player6
for x in self.startingPositions[5]:
self.board.setState(x, 6)
playerSeatPos = [
0,
0,
0,
0,
0,
0]
for x in range(6):
id = self.playersGamePos[x]
if id != None:
playerSeatPos[self.parent.seats.index(id)] = x + 1
continue
self.sendUpdate('announceSeatPositions', [
playerSeatPos])
self.playerSeatPos = playerSeatPos
self.sendGameState([])
self.wantStart = []
self.fsm.request('playing')
self.parent.getTableState()
def d_sendTurn(self, playersTurn):
self.sendUpdate('sendTurn', [
playersTurn])
def advancePlayerTurn(self):
foundNewPlayer = False
while foundNewPlayer == False:
self.playersTurn += 1
if self.playersTurn > 5:
self.playersTurn = 0
if self.playersGamePos[self.playersTurn] != None:
foundNewPlayer = True
continue
def requestMove(self, moveList):
playerOrder = [
1,
4,
2,
5,
3,
6]
if self.checkLegalMoves(moveList) == True:
self.movesMade += 1
self.makeMove(moveList)
self.advancePlayerTurn()
self.d_sendTurn(self.playersTurn + 1)
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
def checkLegalMoves(self, moveList):
if not moveList:
return False
elif self.board.squareList[moveList[0]].getState() == 0:
return False
for x in range(len(moveList) - 1):
y = self.checkLegalMove(self.board.getSquare(moveList[x]), self.board.getSquare(moveList[x + 1]))
if y == False:
return False
continue
return True
def checkLegalMove(self, firstSquare, secondSquare):
if secondSquare.getNum() in firstSquare.getAdjacent():
return True
else:
for x in firstSquare.getAdjacent():
if x == None:
continue
if self.board.squareList[x].getState() == 0:
continue
if self.board.squareList[x].getAdjacent()[firstSquare.getAdjacent().index(x)] == secondSquare.getNum():
return True
continue
return False
def makeMove(self, moveList):
spot1 = self.board.squareList[moveList[0]].getState()
self.board.squareList[moveList[0]].setState(0)
self.board.squareList[moveList[len(moveList) - 1]].setState(spot1)
self.sendGameState(moveList)
def getState(self):
return self.fsm.getCurrentState().getName()
def getName(self):
return self.name
def getGameState(self):
return [
self.board.getStates(),
[]]
def sendGameState(self, moveList):
gameState = self.board.getStates()
self.sendUpdate('setGameState', [
gameState,
moveList])
def clearBoard(self):
for x in self.board.squareList:
x.setState(0)
def getPosHpr(self):
return self.posHpr
def testWin(self):
self.clearBoard()
for x in self.startingPositions[0]:
self.board.squareList[x].setState(4)
self.board.squareList[self.startingPositions[0][len(self.startingPositions[0]) - 1]].setState(0)
self.board.squareList[51].setState(4)
for x in self.startingPositions[3]:
self.board.squareList[x].setState(1)
self.board.squareList[120].setState(0)
self.board.squareList[104].setState(1)
self.sendGameState([])

View file

@ -1,23 +1,20 @@
from pandac.PandaModules import *
from direct.distributed.ClockDelta import *
from direct.task.Task import Task
from direct.interval.IntervalGlobal import *
from TrolleyConstants import *
from direct.gui.DirectGui import *
from toontown.toonbase import TTLocalizer
from direct.distributed import DistributedNode
from direct.distributed.ClockDelta import *
from direct.distributed.ClockDelta import *
from direct.distributed.ClockDelta import globalClockDelta
from ChineseCheckersBoard import ChineseCheckersBoard
from direct.fsm import ClassicFSM, State
from direct.fsm import StateData
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *
from direct.showbase import PythonUtil
from direct.task.Task import Task
from pandac.PandaModules import *
from random import *
from ChineseCheckersBoard import ChineseCheckersBoard
from TrolleyConstants import *
from otp.otpbase import OTPGlobals
from toontown.toonbase import TTLocalizer
from toontown.toonbase import ToontownGlobals
from toontown.toonbase.ToontownTimer import ToontownTimer
from toontown.toonbase import ToontownGlobals
from direct.distributed.ClockDelta import *
from otp.otpbase import OTPGlobals
from direct.showbase import PythonUtil
class DistributedFindFour(DistributedNode.DistributedNode):
@ -28,48 +25,8 @@ class DistributedFindFour(DistributedNode.DistributedNode):
self.reparentTo(render)
self.boardNode = loader.loadModel('phase_6/models/golf/findfour_game.bam')
self.boardNode.reparentTo(self)
self.board = [[0,
0,
0,
0,
0,
0,
0],
[0,
0,
0,
0,
0,
0,
0],
[0,
0,
0,
0,
0,
0,
0],
[0,
0,
0,
0,
0,
0,
0],
[0,
0,
0,
0,
0,
0,
0],
[0,
0,
0,
0,
0,
0,
0]]
self.board = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
self.exitButton = None
self.inGame = False
self.waiting = True
@ -119,7 +76,7 @@ class DistributedFindFour(DistributedNode.DistributedNode):
from direct.fsm import ClassicFSM, State
self.fsm = ClassicFSM.ClassicFSM('ChineseCheckers', [State.State('waitingToBegin', self.enterWaitingToBegin, self.exitWaitingToBegin, ['playing', 'gameOver']), State.State('playing', self.enterPlaying, self.exitPlaying, ['gameOver']), State.State('gameOver', self.enterGameOver, self.exitGameOver, ['waitingToBegin'])], 'waitingToBegin', 'waitingToBegin')
startLoc = self.boardNode.find('**/locators')
self.locatorList = startLoc.getChildren()
self.locatorList = list(startLoc.getChildren())
self.startingPositions = self.locatorList.pop(0)
self.startingPositions = self.startingPositions.getChildren()
instancePiece = self.boardNode.find('**/pieces')
@ -566,7 +523,7 @@ class DistributedFindFour(DistributedNode.DistributedNode):
for x in xrange(41):
self.tieSequence.append(Parallel(LerpColorInterval(self.locatorList[x], 0.15, Vec4(0.5, 0.5, 0.5, 0.5), Vec4(1, 1, 1, 1)), LerpColorInterval(self.locatorList[x], 0.15, Vec4(1, 1, 1, 1), Vec4(0.5, 0.5, 0.5, 0.5))))
whisper = WhisperPopup('This Find Four game has resulted in a Tie!', OTPGlobals.getInterfaceFont(), WTNormal)
whisper = WhisperPopup('This Find Four game has resulted in a Tie!', OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
whisper.manage(base.marginManager)
self.tieSequence.start()
@ -608,6 +565,7 @@ class DistributedFindFour(DistributedNode.DistributedNode):
else:
hasfound = False
while hasfound == False:
from random import *
x = randint(0, 6)
if self.board[0][x] == 0:
self.d_requestMove(x)

View file

@ -1,57 +1,638 @@
from direct.directnotify import DirectNotifyGlobal
# File: D (Python 2.4)
from direct.distributed.DistributedNodeAI import DistributedNodeAI
from direct.distributed.ClockDelta import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.fsm import StateData
from direct.distributed.ClockDelta import *
from direct.interval.IntervalGlobal import *
class DistributedFindFourAI(DistributedNodeAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedFindFourAI")
def __init__(self, air, parent, name, x, y, z, h, p, r):
DistributedNodeAI.__init__(self, air)
self.name = name
self.air = air
self.setPos(x, y, z)
self.setHpr(h, p, r)
self.myPos = (x, y, z)
self.myHpr = (h, p, r)
self.board = [
[
0,
0,
0,
0,
0,
0,
0],
[
0,
0,
0,
0,
0,
0,
0],
[
0,
0,
0,
0,
0,
0,
0],
[
0,
0,
0,
0,
0,
0,
0],
[
0,
0,
0,
0,
0,
0,
0],
[
0,
0,
0,
0,
0,
0,
0]]
self.parent = self.air.doId2do[parent]
self.parentDo = parent
self.wantStart = []
self.playersPlaying = []
self.playersSitting = 0
self.playersTurn = 1
self.movesMade = 0
self.playerNum = 1
self.winDirection = None
self.playersGamePos = [
None,
None]
self.wantTimer = True
self.timerEnd = 0
self.turnEnd = 0
self.playersObserving = []
self.winLaffPoints = 20
self.movesRequiredToWin = 10
self.zoneId = self.air.allocateZone()
self.generateOtpObject(air.districtId, self.zoneId, optionalFields = [
'setX',
'setY',
'setZ',
'setH',
'setP',
'setR'])
self.parent.setCheckersZoneId(self.zoneId)
self.timerStart = None
self.fsm = ClassicFSM.ClassicFSM('Checkers', [
State.State('waitingToBegin', self.enterWaitingToBegin, self.exitWaitingToBegin, [
'playing']),
State.State('playing', self.enterPlaying, self.exitPlaying, [
'gameOver']),
State.State('gameOver', self.enterGameOver, self.exitGameOver, [
'waitingToBegin'])], 'waitingToBegin', 'waitingToBegin')
self.fsm.enterInitialState()
def requestExit(self):
pass
def announceGenerate(self):
self.parent.setGameDoId(self.doId)
def requestBegin(self):
pass
def getTableDoId(self):
return self.parentDo
def requestMove(self, todo0):
pass
def delete(self):
self.fsm.requestFinalState()
self.parent = None
self.parentDo = None
del self.board
del self.fsm
DistributedNodeAI.delete(self)
def informGameOfPlayer(self):
self.playersSitting += 1
if self.playersSitting < 2:
self.timerEnd = 0
elif self.playersSitting == 2:
self.timerEnd = globalClock.getRealTime() + 20
self.parent.isAccepting = False
self.parent.sendUpdate('setIsPlaying', [
1])
elif self.playersSitting > 2:
pass
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def informGameOfPlayerLeave(self):
self.playersSitting -= 1
if self.playersSitting < 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
self.timerEnd = 0
self.parent.isAccepting = True
self.parent.sendUpdate('setIsPlaying', [
0])
if self.playersSitting > 2 and self.fsm.getCurrentState().getName() == 'waitingToBegin':
pass
1
self.timerEnd = 0
if self.timerEnd != 0:
self.sendUpdate('setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
else:
self.sendUpdate('setTimer', [
0])
def setGameCountdownTime(self):
self.timerEnd = globalClock.getRealTime() + 10
def setTurnCountdownTime(self):
self.turnEnd = globalClock.getRealTime() + 25
def getTimer(self):
if self.timerEnd != 0:
return 0
else:
return 0
def getTurnTimer(self):
return globalClockDelta.localToNetworkTime(self.turnEnd)
def requestTimer(self):
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'setTimer', [
globalClockDelta.localToNetworkTime(self.timerEnd)])
def handlePlayerExit(self, avId):
if avId in self.wantStart:
self.wantStart.remove(avId)
if self.fsm.getCurrentState().getName() == 'playing':
gamePos = self.playersGamePos.index(avId)
self.playersGamePos[gamePos] = None
self.fsm.request('gameOver')
def handleEmptyGame(self):
self.movesMade = 0
self.playersPlaying = []
self.playersTurn = 1
self.playerNum = 1
self.fsm.request('waitingToBegin')
self.parent.isAccepting = True
def requestWin(self, pieceNum):
avId = self.air.getAvatarIdFromSender()
playerNum = self.playersGamePos.index(avId) + 1
x = pieceNum[0]
y = pieceNum[1]
if self.checkWin(x, y, playerNum) == True:
self.sendUpdate('announceWinnerPosition', [
x,
y,
self.winDirection,
playerNum])
winnersSequence = Sequence(Wait(5.0), Func(self.fsm.request, 'gameOver'), Func(self.parent.announceWinner, 'Find Four', avId))
winnersSequence.start()
else:
self.sendUpdateToAvatarId(avId, 'illegalMove', [])
def distributeLaffPoints(self):
for x in self.parent.seats:
if x != None:
av = self.air.doId2do.get(x)
av.toonUp(self.winLaffPoints)
continue
def enterWaitingToBegin(self):
self.setGameCountdownTime()
self.parent.isAccepting = True
def exitWaitingToBegin(self):
self.turnEnd = 0
def enterPlaying(self):
self.parent.isAccepting = False
for x in self.playersGamePos:
if x != None:
self.playersTurn = self.playersGamePos.index(x)
self.d_sendTurn(self.playersTurn + 1)
break
continue
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
def exitPlaying(self):
pass
def requestWin(self, todo0):
def enterGameOver(self):
self.timerEnd = 0
isAccepting = True
self.parent.handleGameOver()
self.playersObserving = []
self.playersTurn = 1
self.playerNum = 1
self.playersPlaying = []
self.movesMade = 0
self.playersGamePos = [
None,
None]
self.parent.isAccepting = True
self.fsm.request('waitingToBegin')
def exitGameOver(self):
pass
def startBeginTimer(self, todo0, todo1):
pass
def requestBegin(self):
avId = self.air.getAvatarIdFromSender()
if avId not in self.wantStart:
self.wantStart.append(avId)
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers = numPlayers + 1
continue
if len(self.wantStart) == numPlayers and numPlayers >= 2:
self.d_gameStart(avId)
self.parent.sendIsPlaying()
def setTableDoId(self, todo0):
pass
def d_gameStart(self, avId):
for x in self.playersObserving:
self.sendUpdateToAvatarId(x, 'gameStart', [
255])
zz = 0
numPlayers = 0
for x in self.parent.seats:
if x != None:
numPlayers += 1
self.playersPlaying.append(x)
continue
if numPlayers == 2:
player1 = self.playersPlaying[0]
self.sendUpdateToAvatarId(player1, 'gameStart', [
1])
self.playersGamePos[0] = player1
player2 = self.playersPlaying[1]
self.sendUpdateToAvatarId(player2, 'gameStart', [
2])
self.playersGamePos[1] = player2
self.wantStart = []
self.fsm.request('playing')
self.parent.getTableState()
def setGameState(self, todo0, todo1, todo2, todo3):
pass
def d_sendTurn(self, playersTurn):
self.sendUpdate('sendTurn', [
playersTurn])
def setTimer(self, todo0):
pass
def advancePlayerTurn(self):
if self.playersTurn == 0:
self.playersTurn = 1
self.playerNum = 2
else:
self.playerNum = 1
self.playersTurn = 0
def setTurnTimer(self, todo0):
pass
def requestMove(self, moveColumn):
avId = self.air.getAvatarIdFromSender()
turn = self.playersTurn
if avId in self.playersGamePos:
if self.playersGamePos.index(avId) != self.playersTurn:
pass
if self.board[0][moveColumn] != 0:
self.sendUpdateToAvatarId(avId, 'illegalMove', [])
for x in range(6):
if self.board[x][moveColumn] == 0:
movePos = x
continue
self.board[movePos][moveColumn] = self.playersTurn + 1
if self.checkForTie() == True:
self.sendUpdate('setGameState', [
self.board,
moveColumn,
movePos,
turn])
self.sendUpdate('tie', [])
winnersSequence = Sequence(Wait(8.0), Func(self.fsm.request, 'gameOver'))
winnersSequence.start()
return None
self.movesMade += 1
self.advancePlayerTurn()
self.setTurnCountdownTime()
self.sendUpdate('setTurnTimer', [
globalClockDelta.localToNetworkTime(self.turnEnd)])
self.d_sendTurn(self.playersTurn + 1)
self.sendUpdate('setGameState', [
self.board,
moveColumn,
movePos,
turn])
def gameStart(self, todo0):
pass
def checkForTie(self):
for x in range(7):
if self.board[0][x] == 0:
return False
continue
return True
def sendTurn(self, todo0):
pass
def getState(self):
return self.fsm.getCurrentState().getName()
def announceWin(self, todo0):
pass
def getName(self):
return self.name
def announceWinLocation(self, todo0, todo1, todo2, todo3):
pass
def getGameState(self):
return [
self.board,
0,
0,
0]
def announceWinnerPosition(self, todo0, todo1, todo2, todo3):
pass
def clearBoard(self):
for x in self.board.squareList:
x.setState(0)
def illegalMove(self):
pass
def getPosHpr(self):
return self.posHpr
def tempSetBoardState(self):
self.board = [
[
0,
0,
0,
0,
0,
0,
0],
[
1,
2,
1,
2,
2,
2,
1],
[
2,
2,
1,
2,
1,
2,
1],
[
2,
1,
1,
2,
2,
1,
2],
[
1,
2,
2,
1,
2,
1,
1],
[
1,
2,
1,
2,
1,
2,
1]]
self.sendUpdate('setGameState', [
self.board,
0,
0,
1])
def checkWin(self, rVal, cVal, playerNum):
if self.checkHorizontal(rVal, cVal, playerNum) == True:
self.winDirection = 0
return True
elif self.checkVertical(rVal, cVal, playerNum) == True:
self.winDirection = 1
return True
elif self.checkDiagonal(rVal, cVal, playerNum) == True:
self.winDirection = 2
return True
else:
self.winDirection = None
return False
def checkHorizontal(self, rVal, cVal, playerNum):
if cVal == 3:
for x in range(1, 4):
if self.board[rVal][cVal - x] != playerNum:
break
if self.board[rVal][cVal - x] == playerNum and x == 3:
return True
continue
for x in range(1, 4):
if self.board[rVal][cVal + x] != playerNum:
break
if self.board[rVal][cVal + x] == playerNum and x == 3:
return True
continue
return False
elif cVal == 2:
for x in range(1, 4):
if self.board[rVal][cVal + x] != playerNum:
break
if self.board[rVal][cVal + x] == playerNum and x == 3:
return True
continue
return False
elif cVal == 4:
for x in range(1, 4):
if self.board[rVal][cVal - x] != playerNum:
break
if self.board[rVal][cVal - x] == playerNum and x == 3:
return True
continue
return False
else:
return False
def checkVertical(self, rVal, cVal, playerNum):
if rVal == 2:
for x in range(1, 4):
if self.board[rVal + x][cVal] != playerNum:
break
if self.board[rVal + x][cVal] == playerNum and x == 3:
return True
continue
return False
elif rVal == 3:
for x in range(1, 4):
if self.board[rVal - x][cVal] != playerNum:
break
if self.board[rVal - x][cVal] == playerNum and x == 3:
return True
continue
return False
else:
return False
def checkDiagonal(self, rVal, cVal, playerNum):
if cVal <= 2:
if rVal == 2:
for x in range(1, 4):
if self.board[rVal + x][cVal + x] != playerNum:
break
if self.board[rVal + x][cVal + x] == playerNum and x == 3:
return True
continue
return False
elif rVal == 3:
for x in range(1, 4):
if self.board[rVal - x][cVal + x] != playerNum:
break
if self.board[rVal - x][cVal + x] == playerNum and x == 3:
return True
continue
return False
elif cVal >= 4:
if rVal == 2:
for x in range(1, 4):
if self.board[rVal + x][cVal - x] != playerNum:
break
if self.board[rVal + x][cVal - x] == playerNum and x == 3:
return True
continue
return False
elif rVal == 3:
for x in range(1, 4):
if self.board[rVal - x][cVal - x] != playerNum:
break
if self.board[rVal - x][cVal - x] == playerNum and x == 3:
return True
continue
return False
elif rVal == 3 and rVal == 4 or rVal == 5:
for x in range(1, 4):
if self.board[rVal - x][cVal - x] != playerNum:
break
if self.board[rVal - x][cVal - x] == playerNum and x == 3:
return True
continue
for x in range(1, 4):
if self.board[rVal + x][cVal - x] != playerNum:
break
if self.board[rVal + x][cVal - x] == playerNum and x == 3:
return True
continue
return False
elif rVal == 0 and rVal == 1 or rVal == 2:
for x in range(1, 4):
if self.board[rVal + x][cVal - x] != playerNum:
break
if self.board[rVal + x][cVal - x] == playerNum and x == 3:
return True
continue
for x in range(1, 4):
if self.board[rVal + x][cVal + x] != playerNum:
break
if self.board[rVal + x][cVal + x] == playerNum and x == 3:
return True
continue
return False
return False
def tie(self):
pass

View file

@ -1,291 +0,0 @@
import math
from direct.distributed import DistributedObject
from direct.fsm import ClassicFSM, State
from direct.gui.DirectGui import *
from pandac.PandaModules import *
from toontown.distributed.DelayDelete import *
from toontown.safezone import PicnicGameGlobals
from toontown.safezone.PicnicGameSelectMenu import PicnicGameSelectMenu
from toontown.safezone.PicnicGameTutorial import *
from toontown.toonbase import TTLocalizer
from toontown.toonbase import ToontownGlobals
from toontown.toonbase.ToontownTimer import ToontownTimer
class DistributedGameTable(DistributedObject.DistributedObject):
def __init__(self, cr):
DistributedObject.DistributedObject.__init__(self, cr)
self.tableModelPath = 'phase_6/models/golf/game_table.bam'
self.numSeats = 6
self.__toonTracks = {}
self.gameMenu = None
self.game = None
self.gameDoId = 0
self.timerFunc = None
self.gameWantTimer = False
self.cameraBoardTrack = None
self.tutorial = None
self.fsm = ClassicFSM.ClassicFSM(
'DistributedGameTable',
[
State.State(
'off', self.enterOff, self.exitOff,
['chooseMode', 'observing']
),
State.State(
'chooseMode', self.enterChooseMode, self.exitChooseMode,
['sitting', 'off', 'observing']
),
State.State(
'sitting', self.enterSitting, self.exitSitting,
['off']
),
State.State(
'observing', self.enterObserving, self.exitObserving,
['off']
)
], 'off', 'off')
self.fsm.enterInitialState()
def generate(self):
DistributedObject.DistributedObject.generate(self)
self.picnicTableNode = render.attachNewNode('gameTable')
self.picnicTable = loader.loadModel(self.tableModelPath)
self.picnicTable.reparentTo(self.picnicTableNode)
self.loader = self.cr.playGame.hood.loader
self.picnicTableNode.reparentTo(self.loader.geom)
def announceGenerate(self):
DistributedObject.DistributedObject.announceGenerate(self)
self.tableCloth = self.picnicTable.find('**/basket_locator')
cn = CollisionNode('tableCloth_sphere')
self.tableClothSphereNode = self.tableCloth.attachNewNode(cn)
cs = CollisionSphere(0, 0, -2, 5.5)
self.tableClothSphereNode.node().addSolid(cs)
self.seats = []
self.jumpOffsets = []
self.picnicTableSphereNodes = []
for i in xrange(self.numSeats):
self.seats.append(self.picnicTable.find('**/*seat' + str(i+1)))
self.jumpOffsets.append(self.picnicTable.find('**/*jumpOut' + str(i+1)))
cn = CollisionNode('picnicTable_sphere_%d_%d' % (self.doId, i))
self.picnicTableSphereNodes.append(self.seats[i].attachNewNode(cn))
cs = CollisionSphere(0, 0, 0, 2)
self.picnicTableSphereNodes[i].node().addSolid(cs)
self.clockNode = ToontownTimer()
self.clockNode.setPos(1.16, 0, -0.83)
self.clockNode.setScale(0.3)
self.clockNode.hide()
self.buttonModels = loader.loadModel('phase_3.5/models/gui/inventory_gui.bam')
self.upButton = self.buttonModels.find('**//InventoryButtonUp')
self.downButton = self.buttonModels.find('**/InventoryButtonDown')
self.rolloverButton = self.buttonModels.find('**/InventoryButtonRollover')
self.joinButton = None
self.observeButton = None
self.exitButton = None
self.tutorialButton = None
angle = self.picnicTable.getH()
angle -= 90
radAngle = math.radians(angle)
unitVec = Vec3(math.cos(radAngle), math.sin(radAngle), 0)
unitVec *= 30.0
self.endPos = self.picnicTable.getPos() + unitVec
self.enableCollisions()
def disable(self):
DistributedObject.DistributedObject.disable(self)
self.fsm.request('off')
self.clearToonTracks()
# TODO: Disable choice buttons.
# TODO: Stop sleep tracking.
self.destroyGameMenu()
self.disableCollisions()
del self.gameMenu
if self.cameraBoardTrack:
self.cameraBoardTrack.finish()
del self.cameraBoardTrack
del self.tableClothSphereNode
del self.tableCloth
del self.seats
del self.jumpOffsets
del self.picnicTableSphereNodes
del self.clockNode
self.buttonModels.removeNode()
del self.buttonModels
del self.endPos
del self.loader
self.picnicTable.removeNode()
self.picnicTableNode.removeNode()
def delete(self):
DistributedObject.DistributedObject.delete(self)
del self.fsm
def enableCollisions(self):
for i in xrange(self.numSeats):
event = 'enterpicnicTable_sphere_%d_%d' % (self.doId, i)
self.accept(event, self.handleEnterPicnicTableSphere, [i])
self.picnicTableSphereNodes[i].setCollideMask(ToontownGlobals.WallBitmask)
self.tableClothSphereNode.setCollideMask(ToontownGlobals.WallBitmask)
def disableCollisions(self):
for i in xrange(self.numSeats):
self.ignore('enterpicnicTable_sphere_%d_%d' % (self.doId, i))
for i in xrange(self.numSeats):
self.picnicTableSphereNodes[i].setCollideMask(BitMask32(0))
self.tableClothSphereNode.setCollideMask(BitMask32(0))
def handleEnterPicnicTableSphere(self, i, collEntry):
self.fsm.request('chooseMode')
def enterOff(self):
base.setCellsActive(base.leftCells + base.bottomCells, 0)
def exitOff(self):
base.setCellsActive(base.bottomCells, 0)
def enterChooseMode(self):
self.enableChoiceButtons()
def exitChooseMode(self):
self.disableChoiceButtons()
def enterObserving(self):
pass
def exitObserving(self):
pass
def enterSitting(self):
pass
def exitSitting(self):
self.destroyGameMenu()
def destroyGameMenu(self):
if self.gameMenu:
self.gameMenu.removeButtons()
self.gameMenu.picnicFunction = None
self.gameMenu = None
def setPosHpr(self, x, y, z, h, p, r):
self.picnicTable.setPosHpr(x, y, z, h, p, r)
def storeToonTrack(self, avId, track):
self.clearToonTrack(avId)
self.__toonTracks[avId] = track
def clearToonTrack(self, avId):
oldTrack = self.__toonTracks.get(avId)
if oldTrack:
oldTrack.pause()
cleanupDelayDeletes(oldTrack)
def clearToonTracks(self):
for avId in self.__toonTracks:
self.clearToonTrack(avId)
def showTimer(self):
self.clockNode.stop()
self.clockNode.countdown(self.timeLeft, self.timerFunc)
self.clockNode.show()
def setTimer(self, timerEnd):
self.clockNode.stop()
time = globalClockDelta.networkToLocalTime(timerEnd)
self.timeLeft = int(time - globalClock.getRealTime())
if self.gameWantTimer and (self.game is not None):
self.showTimer()
def setTimerFunc(self, function):
self.timerFunc = function
def allowWalk(self):
base.cr.playGame.getPlace().setState('walk')
def disallowWalk(self):
base.cr.playGame.getPlace().setState('stopped')
def enableChoiceButtons(self):
if (not self.game) or (not self.game.playing):
self.joinButton = DirectButton(
relief=None, text=TTLocalizer.PicnicTableJoinButton,
text_fg=(1, 1, 0.65, 1), text_pos=(0, -0.23), text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1), image_scale=(20, 1, 11),
pos=(0, 0, 0.8), scale=0.15,
command=lambda self=self: self.joinButtonPushed())
else:
self.observeButton = DirectButton(
relief=None, text=TTLocalizer.PicnicTableObserveButton,
text_fg=(1, 1, 0.65, 1), text_pos=(0, -0.23), text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1), image_scale=(20, 1, 11),
pos=(0, 0, 0.6), scale=0.15,
command=lambda self=self: self.observeButtonPushed())
self.exitButton = DirectButton(
relief=None, text=TTLocalizer.PicnicTableCancelButton,
text_fg=(1, 1, 0.65, 1), text_pos=(0, -0.23), text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1), image_scale=(20, 1, 11), pos=(1, 0, 0.6),
scale=0.15, command=lambda self=self: self.cancelButtonPushed())
self.tutorialButton = DirectButton(
relief=None, text=TTLocalizer.PicnicTableTutorial,
text_fg=(1, 1, 0.65, 1), text_pos=(-0.05, -0.13), text_scale=0.55,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1), image_scale=(20, 1, 11), pos=(-1, 0, 0.6),
scale=0.15, command=lambda self=self: self.tutorialButtonPushed())
self.disallowWalk()
def disableChoiceButtons(self):
if self.joinButton:
self.joinButton.destroy()
self.joinButton = None
if self.observeButton:
self.observeButton.destroy()
self.observeButton = None
if self.exitButton:
self.exitButton.destroy()
self.exitButton = None
if self.tutorialButton:
self.tutorialButton.destroy()
self.tutorialButton = None
def joinButtonPushed(self):
pass
def observeButtonPushed(self):
pass
def cancelButtonPushed(self):
self.allowWalk()
self.fsm.request('off')
def tutorialButtonPushed(self):
self.disableChoiceButtons()
self.gameMenu = PicnicGameSelectMenu(
self.tutorialFunction, PicnicGameGlobals.TutorialMenu)
def tutorialFunction(self, gameIndex):
if gameIndex == PicnicGameGlobals.CheckersGameIndex:
self.tutorial = CheckersTutorial(self.tutorialDone)
elif gameIndex == PicnicGameGlobals.ChineseCheckersGameIndex:
self.tutorial = ChineseCheckersTutorial(self.tutorialDone)
else:
self.cancelButtonPushed()
self.destroyGameMenu()
def tutorialDone(self):
self.fsm.request('off')
self.tutorial = None

View file

@ -1,25 +0,0 @@
from direct.distributed import DistributedObjectAI
class DistributedGameTableAI(DistributedObjectAI.DistributedObjectAI):
def __init__(self, air):
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
self.posHpr = (0, 0, 0, 0, 0, 0)
# Required Fields:
def setPosHpr(self, x, y, z, h, p, r):
self.posHpr = (x, y, z, h, p, r)
def getPosHpr(self):
return self.posHpr
# Receive Fields:
def requestJoin(self, seatIndex):
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'rejectJoin', [])
def requestExit(self):
pass

View file

@ -1,3 +1,4 @@
import GameGlobals
from pandac.PandaModules import *
from direct.distributed.ClockDelta import *
from direct.task.Task import Task
@ -7,7 +8,9 @@ from direct.gui.DirectGui import *
from toontown.toonbase import TTLocalizer
from direct.distributed import DistributedNode
from direct.distributed.ClockDelta import globalClockDelta
from toontown.distributed.DelayDelete import *
from ChineseCheckersBoard import ChineseCheckersBoard
from GameGlobals import *
from GameTutorials import *
from GameMenu import GameMenu
from direct.fsm import ClassicFSM, State
@ -17,6 +20,9 @@ from toontown.toonbase.ToontownTimer import ToontownTimer
from toontown.toonbase import ToontownGlobals
from direct.showbase import PythonUtil
from otp.otpbase import OTPGlobals
from toontown.chat.WhisperPopup import WhisperPopup
import random
class DistributedPicnicTable(DistributedNode.DistributedNode):
@ -25,8 +31,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
NodePath.__init__(self, 'DistributedPicnicTable')
DistributedNode.DistributedNode.__init__(self, cr)
self.reparentTo(render)
self.picnicTable = loader.loadModel('phase_6/models/golf/game_table.bam')
self.picnicTable.reparentTo(self)
self.picnicTable = None
self.picnicTableSphereNodes = []
self.numSeats = 6
self.seats = []
@ -67,7 +72,12 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
State.State('sitting', self.enterSitting, self.exitSitting, ['off']),
State.State('observing', self.enterObserving, self.exitObserving, ['off'])], 'off', 'off')
self.fsm.enterInitialState()
for i in xrange(self.numSeats):
def setTableIndex(self, index):
self.picnicTable = render.find('**/game_table_%d' % index)
def announceGenerate(self):
for i in range(self.numSeats):
self.seats.append(self.picnicTable.find('**/*seat%d' % (i + 1)))
self.jumpOffsets.append(self.picnicTable.find('**/*jumpOut%d' % (i + 1)))
@ -78,11 +88,9 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.clockNode.setPos(1.16, 0, -0.83)
self.clockNode.setScale(0.3)
self.clockNode.hide()
return
def announceGenerate(self):
DistributedNode.DistributedNode.announceGenerate(self)
for i in xrange(self.numSeats):
for i in range(self.numSeats):
self.picnicTableSphereNodes.append(self.seats[i].attachNewNode(CollisionNode('picnicTable_sphere_%d_%d' % (self.getDoId(), i))))
self.picnicTableSphereNodes[i].node().addSolid(CollisionSphere(0, 0, 0, 2))
@ -177,14 +185,14 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
def setTableState(self, tableStateList, isplaying):
y = 0
print 'SET TABLE STATE'
print 'SET TABLE STATE', tableStateList, isplaying
if isplaying == 0:
self.isPlaying = False
else:
self.isPlaying = True
for x in tableStateList:
if x != 0:
if x not in self.tableState and x in self.cr.doId2do and x not in self.haveAnimated:
if x not in self.tableState and self.cr.doId2do.has_key(x) and x not in self.haveAnimated:
seatIndex = tableStateList.index(x)
toon = self.cr.doId2do[x]
toon.stopSmooth()
@ -212,17 +220,17 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
if x != None:
numPlayers += 1
print ' GETTING 2', self.gameMenu, numPlayers
#print ' GETTING 2', self.gameMenu, numPlayers
if self.gameMenu:
if numPlayers > 2:
print ' GETTING HERE!!'
self.gameMenu.FindFour.setColor(0.7, 0.7, 0.7, 0.7)
self.gameMenu.FindFour['command'] = self.doNothing
self.gameMenu.findFourText['fg'] = (0.7, 0.7, 0.7, 0.7)
self.gameMenu.Checkers.setColor(0.7, 0.7, 0.7, 0.7)
self.gameMenu.Checkers['command'] = self.doNothing
self.gameMenu.checkersText['fg'] = (0.7, 0.7, 0.7, 0.7)
return
if numPlayers <= 2:
#print ' GETTING HERE!!'
#self.gameMenu.FindFour.setColor(0.7, 0.7, 0.7, 0.7)
#self.gameMenu.FindFour['command'] = self.doNothing
#self.gameMenu.findFourText['fg'] = (0.7, 0.7, 0.7, 0.7)
#self.gameMenu.Checkers.setColor(0.7, 0.7, 0.7, 0.7)
#self.gameMenu.Checkers['command'] = self.doNothing
#self.gameMenu.checkersText['fg'] = (0.7, 0.7, 0.7, 0.7)
return
def setIsPlaying(self, isPlaying):
if isPlaying == 0:
@ -240,8 +248,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
elif winString == 'Checkers':
whisper = WhisperPopup(TTLocalizer.RegularCheckersYouWon, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif winString == 'Find Four':
whisper = WhisperPopup('You won a game of Find Four!', OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif avId in self.cr.doId2do:
whisper = WhisperPopup(TTLocalizer.FindFourYouWon, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif self.cr.doId2do.has_key(avId):
stateString = self.fsm.getCurrentState().getName()
if stateString == 'sitting' or stateString == 'observing':
base.cr.playGame.getPlace().setState('walk')
@ -251,8 +259,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
elif winString == 'Checkers':
whisper = WhisperPopup(av.getName() + TTLocalizer.RegularCheckersGameOf + TTLocalizer.RegularCheckers, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif winString == 'Find Four':
whisper = WhisperPopup(av.getName() + ' has won a game of' + ' Find Four!', OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
if avId in self.cr.doId2do:
whisper = WhisperPopup(av.getName() + TTLocalizer.FindFourGameOf + TTLocalizer.FindFour, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
if self.cr.doId2do.has_key(avId):
toon = self.cr.doId2do[avId]
self.winTrack = Sequence(autoFinish=1)
if self.outTrack.isPlaying():
@ -272,73 +280,74 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.fsm.request('chooseMode')
def enableChoiceButtons(self):
if self.tableState[self.seatBumpForObserve] == None and self.isPlaying == False:
if (not self.game) or (not self.game.playing):
self.joinButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableJoinButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -.23),
text_pos=(0, -0.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(0, 0, 0.8),
scale=0.15,
command=lambda self = self: self.joinButtonPushed())
if self.isPlaying == True:
command=self.joinButtonPushed)
else:
self.observeButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableObserveButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -.23),
text_pos=(0, -0.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(0, 0, 0.6),
scale=0.15,
command=lambda self = self: self.observeButtonPushed())
command=self.observeButtonPushed)
self.exitButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableCancelButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -.23),
text_pos=(0, -0.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(1, 0, 0.6),
scale=0.15,
command=lambda self = self: self.cancelButtonPushed())
command=self.cancelButtonPushed)
self.tutorialButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableTutorial,
text_fg=(1, 1, 0.65, 1),
text_pos=(-.05, -.13),
text_pos=(-0.05, -0.13),
text_scale=0.55,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(-1, 0, 0.6),
scale=0.15,
command=lambda self = self: self.tutorialButtonPushed())
command=self.tutorialButtonPushed)
base.cr.playGame.getPlace().setState('stopped')
return
def tutorialButtonPushed(self):
self.disableChoiceButtons()
self.gameMenu = GameMenu(self.tutorialFunction, 1)
self.tutorialButton.destroy()
self.tutorialButton = None
self.gameMenu = GameMenu(self.tutorialFunction, GameGlobals.TutorialMenu)
return
def tutorialFunction(self, tutVal):
if tutVal == 1:
self.tutorial = ChineseTutorial(self.tutorialDone)
elif tutVal == 2:
if tutVal == GameGlobals.CheckersGameIndex:
self.tutorial = CheckersTutorial(self.tutorialDone)
self.gameMenu.picnicFunction = None
self.gameMenu = None
elif tutVal == GameGlobals.ChineseCheckersGameIndex:
self.tutorial = ChineseTutorial(self.tutorialDone)
elif tutVal == GameGlobals.FindFourGameIndex:
self.tutorial = FindFourTutorial(self.tutorialDone)
else:
self.cancelButtonPushed()
self.destroyGameMenu()
return
def tutorialDone(self):
@ -373,12 +382,16 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
def disableChoiceButtons(self):
if self.joinButton:
self.joinButton.destroy()
self.joinButton = None
if self.observeButton:
self.observeButton.destroy()
self.observeButton = None
if self.exitButton:
self.exitButton.destroy()
self.exitButton = None
if self.tutorialButton:
self.tutorialButton.destroy()
self.tutorialButton = None
def pickFunction(self, gameNum):
if gameNum == 1:
@ -387,11 +400,17 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.sendUpdate('requestPickedGame', [gameNum])
elif gameNum == 3:
self.sendUpdate('requestPickedGame', [gameNum])
elif gameNum == -1:
self.gameMenu.removeButtons()
self.gameMenu.picnicFunction = None
self.gameMenu = None
self.sendUpdate('requestExit', [])
def allowPick(self):
self.gameMenu = GameMenu(self.pickFunction, 2)
def setZone(self, zoneId):
print 'setZone', zoneId, self.fsm.getCurrentState().getName()
if self.fsm.getCurrentState().getName() == 'sitting' or self.fsm.getCurrentState().getName() == 'observing':
if self.tutorial == None:
self.gameZone = base.cr.addInterest(base.localAvatar.defaultShard, zoneId, 'gameBoard')
@ -411,7 +430,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
else:
self.inGame = True
self.seatPos = index
if avId in self.cr.doId2do:
if self.cr.doId2do.has_key(avId):
toon = self.cr.doId2do[avId]
toon.stopSmooth()
toon.wrtReparentTo(self.tableCloth)
@ -436,7 +455,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
return
if avId in self.haveAnimated:
self.haveAnimated.remove(avId)
if avId in self.cr.doId2do:
if self.cr.doId2do.has_key(avId):
if avId == base.localAvatar.getDoId():
if self.gameZone:
base.cr.removeInterest(self.gameZone)
@ -451,13 +470,12 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.outTrack = Sequence(jumpOutTrack)
if base.localAvatar.getDoId() == avId:
self.outTrack.append(Func(self.__enableCollisions))
self.outTrack.append(Func(self.allowToWalk))
self.outTrack.append(Func(self.allowToWalk))
self.fsm.request('off')
val = self.jumpOffsets[index].getPos(render)
self.outTrack.append(Func(toon.setPos, val))
self.outTrack.append(Func(toon.startSmooth))
self.outTrack.append(Func(toon.startSmooth))
self.outTrack.start()
return
def stopToWalk(self):
base.cr.playGame.getPlace().setState('stopped')
@ -466,44 +484,37 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
base.cr.playGame.getPlace().setState('walk')
def moveCamera(self, seatIndex):
self.oldCameraPos = camera.getPos()
self.oldCameraHpr = camera.getHpr()
camera.wrtReparentTo(self.picnicTable)
heading = PythonUtil.fitDestAngle2Src(camera.getH(), 90)
if seatIndex < 3:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(0, -90, 0))
elif camera.getH() < 0:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(-180, -90, 0))
else:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(180, -90, 0))
self.cameraBoardTrack.start()
localAvatar.stopUpdateSmartCamera()
camera.reparentTo(self)
camera.iPosHpr()
camera.setZ(17)
camera.setP(-90)
def moveCameraBack(self):
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.5, self.oldCameraPos, self.oldCameraHpr)
self.cameraBoardTrack.start()
localAvatar.startUpdateSmartCamera()
def __enableCollisions(self):
for i in xrange(self.numSeats):
for i in range(self.numSeats):
self.accept('enterpicnicTable_sphere_%d_%d' % (self.getDoId(), i), self.handleEnterPicnicTableSphere, [i])
self.picnicTableSphereNodes[i].setCollideMask(ToontownGlobals.WallBitmask)
self.tableclothSphereNode.setCollideMask(ToontownGlobals.WallBitmask)
def __disableCollisions(self):
for i in xrange(self.numSeats):
for i in range(self.numSeats):
self.ignore('enterpicnicTable_sphere_%d_%d' % (self.getDoId(), i))
self.ignore('enterPicnicTableOK_%d_%d' % (self.getDoId(), i))
for i in xrange(self.numSeats):
for i in range(self.numSeats):
self.picnicTableSphereNodes[i].setCollideMask(BitMask32(0))
self.tableclothSphereNode.setCollideMask(BitMask32(0))
def enterOff(self):
base.setCellsActive(base.leftCells + base.bottomCells, 0)
base.setCellsAvailable(base.leftCells + base.bottomCells, 0)
def exitOff(self):
base.setCellsActive(base.bottomCells, 0)
base.setCellsAvailable(base.bottomCells, 0)
def enterChooseMode(self):
self.winTrack = Sequence(autoFinish=1)
@ -527,8 +538,13 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
pass
def exitSitting(self):
self.gameMenu = None
return
self.destroyGameMenu()
def destroyGameMenu(self):
if self.gameMenu:
self.gameMenu.removeButtons()
self.gameMenu.picnicFunction = None
self.gameMenu = None
def setGameZone(self, zoneId, gamestate):
self.gameZone = base.cr.addInterest(base.localAvatar.defaultShard, zoneId, 'gameBoard')
@ -551,7 +567,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
image_scale=(20, 1, 11),
pos=(0.92, 0, 0.4),
scale=0.15,
command=lambda self = self: self.stopObserveButtonPushed())
command=self.stopObserveButtonPushed)
return
def stopObserveButtonPushed(self):
@ -644,7 +660,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
keyList.append(key)
for key in keyList:
if key in self.__toonTracks:
if self.__toonTracks.has_key(key):
self.clearToonTrack(key)
def doNothing(self):

View file

@ -1,60 +1,344 @@
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedNodeAI import DistributedNodeAI
from direct.distributed.ClockDelta import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.fsm import StateData
from toontown.safezone import DistributedChineseCheckersAI
from toontown.safezone import DistributedCheckersAI
from toontown.safezone import DistributedFindFourAI
from toontown.safezone import GameGlobals
class DistributedPicnicTableAI(DistributedNodeAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPicnicTableAI")
def __init__(self, air, zone, name, x, y, z, h, p, r):
DistributedNodeAI.__init__(self, air)
self.name = name
self.zoneId = zone
self.air = air
self.seats = [
None,
None,
None,
None,
None,
None]
self.setPos(x, y, z)
self.setHpr(h, p, r)
self.playersSitting = 0
self.playerIdList = []
self.checkersZoneId = None
self.observers = []
self.allowPickers = []
self.hasPicked = False
self.game = None
self.gameDoId = None
self.isAccepting = True
def fillSlot(self, todo0, todo1, todo2, todo3, todo4, todo5, todo6, todo7, todo8, todo9):
def announceGenerate(self):
pass
def emptySlot(self, todo0, todo1, todo2):
pass
def delete(self):
DistributedNodeAI.delete(self)
self.game = None
self.gameDoId = None
def setGameDoId(self, doId):
self.gameDoId = doId
self.game = self.air.doId2do.get(doId)
def requestTableState(self):
pass
avId = self.air.getAvatarIdFromSender()
self.getTableState()
def setTableState(self, todo0, todo1):
pass
def getTableState(self):
tableStateList = []
for x in self.seats:
if x == None:
tableStateList.append(0)
continue
tableStateList.append(x)
def setGameZone(self, todo0, todo1):
pass
if self.game and self.game.fsm.getCurrentState().getName() == 'playing':
self.sendUpdate('setTableState', [
tableStateList,
1])
else:
self.sendUpdate('setTableState', [
tableStateList,
0])
def setIsPlaying(self, todo0):
pass
def sendIsPlaying(self):
if self.game.fsm.getCurrentState().getName() == 'playing':
self.sendUpdate('setIsPlaying', [
1])
else:
self.sendUpdate('setIsPlaying', [
0])
def requestJoin(self, todo0, todo1, todo2, todo3, todo4, todo5, todo6):
pass
def announceWinner(self, gameName, avId):
self.sendUpdate('announceWinner', [
gameName,
avId])
self.gameDoId = None
self.game = None
def rejectJoin(self):
pass
def requestJoin(self, si, x, y, z, h, p, r):
avId = self.air.getAvatarIdFromSender()
if self.findAvatar(avId) != None:
self.notify.warning('Ignoring multiple requests from %s to board.' % avId)
return None
def requestObserve(self):
pass
av = self.air.doId2do.get(avId)
if av:
if av.hp > 0 and self.isAccepting and self.seats[si] == None:
self.notify.debug('accepting boarder %d' % avId)
self.acceptBoarder(avId, si, x, y, z, h, p, r)
else:
self.notify.debug('rejecting boarder %d' % avId)
self.sendUpdateToAvatarId(avId, 'rejectJoin', [])
else:
self.notify.warning('avid: %s does not exist, but tried to board a picnicTable' % avId)
def leaveObserve(self):
pass
def acceptBoarder(self, avId, seatIndex, x, y, z, h, p, r):
self.notify.debug('acceptBoarder %d' % avId)
if self.findAvatar(avId) != None:
return None
isEmpty = True
for xx in self.seats:
if xx != None:
isEmpty = False
break
continue
def requestGameZone(self):
pass
if isEmpty == True or self.hasPicked == False:
self.sendUpdateToAvatarId(avId, 'allowPick', [])
self.allowPickers.append(avId)
def requestPickedGame(self, todo0):
pass
if self.hasPicked == True:
self.sendUpdateToAvatarId(avId, 'setZone', [
self.game.zoneId])
def requestExit(self):
pass
self.seats[seatIndex] = avId
self.acceptOnce(self.air.getAvatarExitEvent(avId), self._DistributedPicnicTableAI__handleUnexpectedExit, extraArgs = [
avId])
self.timeOfBoarding = globalClock.getRealTime()
if self.game:
self.game.informGameOfPlayer()
self.sendUpdate('fillSlot', [
avId,
seatIndex,
x,
y,
z,
h,
p,
r,
globalClockDelta.localToNetworkTime(self.timeOfBoarding),
self.doId])
self.getTableState()
def requestPickedGame(self, gameNum):
avId = self.air.getAvatarIdFromSender()
if self.hasPicked == False and avId in self.allowPickers:
self.hasPicked = True
numPickers = len(self.allowPickers)
self.allowPickers = []
self.pickGame(gameNum)
if self.game:
for x in range(numPickers):
self.game.informGameOfPlayer()
def pickGame(self, gameNum):
if self.game:
return
x = 0
for x in self.seats:
if x != None:
x += 1
continue
if gameNum == GameGlobals.ChineseCheckersGameIndex:
if simbase.config.GetBool('want-chinese', 1):
self.game = DistributedChineseCheckersAI.DistributedChineseCheckersAI(self.air, self.doId, 'chinese', self.getX(), self.getY(), self.getZ() + 2.8300000000000001, self.getH(), self.getP(), self.getR())
self.sendUpdate('setZone', [
self.game.zoneId])
elif gameNum == GameGlobals.CheckersGameIndex:
if x <= 2:
if simbase.config.GetBool('want-checkers', 1):
self.game = DistributedCheckersAI.DistributedCheckersAI(self.air, self.doId, 'checkers', self.getX(), self.getY(), self.getZ() + 2.8300000000000001, self.getH(), self.getP(), self.getR())
self.sendUpdate('setZone', [
self.game.zoneId])
elif gameNum == GameGlobals.FindFourGameIndex:
if x <= 2:
if simbase.config.GetBool('want-findfour', 1):
self.game = DistributedFindFourAI.DistributedFindFourAI(self.air, self.doId, 'findFour', self.getX(), self.getY(), self.getZ() + 2.8300000000000001, self.getH(), self.getP(), self.getR())
self.sendUpdate('setZone', [
self.game.zoneId])
def requestZone(self):
pass
if not self.game:
return
avId = self.air.getAvatarIdFromSender()
self.sendUpdateToAvatarId(avId, 'setZone', [
self.game.zoneId])
def announceWinner(self, todo0, todo1):
pass
def requestGameZone(self):
if self.hasPicked == True:
avId = self.air.getAvatarIdFromSender()
if self.game:
self.game.playersObserving.append(avId)
def allowObserve(self):
pass
self.observers.append(avId)
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.handleObserverExit, extraArgs = [
avId])
if self.game:
if self.game.fsm.getCurrentState().getName() == 'playing':
self.sendUpdateToAvatarId(avId, 'setGameZone', [
self.checkersZoneId,
1])
else:
self.sendUpdateToAvatarId(avId, 'setGameZone', [
self.checkersZoneId,
0])
def allowPick(self):
pass
def leaveObserve(self):
avId = self.air.getAvatarIdFromSender()
if self.game:
if avId in self.game.playersObserving:
self.game.playersObserving.remove(avId)
def setZone(self, todo0):
pass
def handleObserverExit(self, avId):
if self.game and avId in self.game.playersObserving:
if self.game:
self.game.playersObserving.remove(avId)
self.ignore(self.air.getAvatarExitEvent(avId))
def requestExit(self):
self.notify.debug('requestExit')
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if av:
if self.countFullSeats() > 0:
self.acceptExiter(avId)
else:
self.notify.debug('Player tried to exit after AI already kicked everyone out')
else:
self.notify.warning('avId: %s does not exist, but tried to exit picnicTable' % avId)
def acceptExiter(self, avId):
seatIndex = self.findAvatar(avId)
if seatIndex == None:
if avId in self.observers:
self.sendUpdateToAvatarId(avId, 'emptySlot', [
avId,
255,
globalClockDelta.getRealNetworkTime()])
else:
self.seats[seatIndex] = None
self.ignore(self.air.getAvatarExitEvent(avId))
self.sendUpdate('emptySlot', [
avId,
seatIndex,
globalClockDelta.getRealNetworkTime()])
self.getTableState()
numActive = 0
for x in self.seats:
if x != None:
numActive = numActive + 1
continue
if self.game:
self.game.informGameOfPlayerLeave()
self.game.handlePlayerExit(avId)
if numActive == 0:
self.isAccepting = True
if self.game:
self.game.handleEmptyGame()
self.game.requestDelete()
self.game = None
self.hasPicked = False
def _DistributedPicnicTableAI__handleUnexpectedExit(self, avId):
self.notify.warning('Avatar: ' + str(avId) + ' has exited unexpectedly')
seatIndex = self.findAvatar(avId)
if seatIndex == None:
pass
self.seats[seatIndex] = None
self.ignore(self.air.getAvatarExitEvent(avId))
if self.game:
self.game.informGameOfPlayerLeave()
self.game.handlePlayerExit(avId)
self.hasPicked = False
self.getTableState()
numActive = 0
for x in self.seats:
if x != None:
numActive = numActive + 1
continue
if numActive == 0 and self.game:
simbase.air.deallocateZone(self.game.zoneId)
self.game.requestDelete()
self.game = None
self.gameDoId = None
def informGameOfPlayerExit(self, avId):
self.game.handlePlayerExit(avId)
def handleGameOver(self):
for x in self.observers:
self.acceptExiter(x)
self.observers.remove(x)
if self.game:
self.game.playersObserving = []
for x in self.seats:
if x != None:
self.acceptExiter(x)
continue
self.game = None
self.gameDoId = None
self.hasPicked = False
def findAvatar(self, avId):
for i in range(len(self.seats)):
if self.seats[i] == avId:
return i
continue
def countFullSeats(self):
avCounter = 0
for i in self.seats:
if i:
avCounter += 1
continue
return avCounter
def findAvailableSeat(self):
for i in range(len(self.seats)):
if self.seats[i] == None:
return i
continue
def setCheckersZoneId(self, zoneId):
self.checkersZoneId = zoneId
def setTableIndex(self, index):
self._tableIndex = index
def getTableIndex(self):
return self._tableIndex

View file

@ -0,0 +1,5 @@
TutorialMenu = 1
GameMenu = 1
CheckersGameIndex = 0
ChineseCheckersGameIndex = 1
FindFourGameIndex = 2

View file

@ -0,0 +1,160 @@
from pandac.PandaModules import *
from direct.distributed.ClockDelta import *
from direct.task.Task import Task
from direct.interval.IntervalGlobal import *
from TrolleyConstants import *
from direct.gui.DirectGui import *
from toontown.toonbase import TTLocalizer
from toontown.toonbase import ToontownGlobals
from toontown.safezone import GameGlobals
class GameMenu(DirectFrame):
def __init__(self, picnicFunction, menuType):
self.picnicFunction = picnicFunction
DirectFrame.__init__(
self,
pos=(0.0, 0.0, 0.85),
image_color=ToontownGlobals.GlobalDialogColor,
image_scale=(1.8, 0.9, 0.13),
text='',
text_scale=0.05)
self.buttonModels = loader.loadModel('phase_3.5/models/gui/inventory_gui.bam')
self.upButton = self.buttonModels.find('**//InventoryButtonUp')
self.downButton = self.buttonModels.find('**/InventoryButtonDown')
self.rolloverButton = self.buttonModels.find('**/InventoryButtonRollover')
self['image'] = DGG.getDefaultDialogGeom()
if menuType == GameGlobals.TutorialMenu:
self.title = DirectLabel(
self,
relief=None,
text=TTLocalizer.PicnicTableMenuTutorial,
text_pos=(0.0, -0.038),
text_fg=(1, 0, 0, 1),
text_scale=0.09,
text_font=ToontownGlobals.getSignFont(),
text_shadow=(1, 1, 1, 1))
else:
self.title = DirectLabel(
self,
relief=None,
text=TTLocalizer.PicnicTableMenuSelect,
text_pos=(0.0, -0.04),
text_fg=(1, 0, 0, 1),
text_scale=0.09,
text_font=ToontownGlobals.getSignFont(),
text_shadow=(1, 1, 1, 1))
self.selectionButtons = loader.loadModel('phase_6/models/golf/picnic_game_menu.bam')
btn1 = self.selectionButtons.find('**/Btn1')
btn2 = self.selectionButtons.find('**/Btn2')
btn3 = self.selectionButtons.find('**/Btn3')
self.ChineseCheckers = DirectButton(
self,
image=(btn1.find('**/checkersBtnUp'), btn1.find('**/checkersBtnDn'), btn1.find('**/checkersBtnHi'), btn1.find('**/checkersBtnUp')),
scale=0.36,
relief=0,
pos=(0, 0, -0.7),
command=self.chineseCheckersSelected)
self.Checkers = DirectButton(
self,
image=(btn2.find('**/regular_checkersBtnUp'), btn2.find('**/regular_checkersBtnDn'), btn2.find('**/regular_checkersBtnHi'), btn2.find('**/regular_checkersBtnUp')),
scale=0.36,
relief=0,
pos=(0.8, 0, -0.7),
command=self.checkersSelected)
self.FindFour = DirectButton(
self,
image=(btn3.find('**/findfourBtnUp'), btn3.find('**/findfourBtnDn'), btn3.find('**/findfourBtnHi'), btn3.find('**/findfourBtnUp')),
scale=0.36,
relief=0,
pos=(-0.8, 0, -0.7),
command=self.findFourSelected)
if not base.config.GetBool('want-checkers', 1):
self.Checkers['command'] = self.doNothing()
self.Checkers.setColor(0.7, 0.7, 0.7, 0.7)
if not base.config.GetBool('want-chinese-checkers', 1):
self.ChineseCheckers['command'] = self.doNothing()
self.ChineseCheckers.setColor(0.7, 0.7, 0.7, 0.7)
if not base.config.GetBool('want-find-four', 1):
self.FindFour['command'] = self.doNothing()
self.FindFour.setColor(0.7, 0.7, 0.7, 0.7)
self.chineseText = OnscreenText(
text='Chinese Checkers',
pos=(0, 0.56, -0.8),
scale=0.15,
fg=Vec4(1, 1, 1, 1),
align=TextNode.ACenter,
font=ToontownGlobals.getMinnieFont(),
wordwrap=7,
shadow=(0, 0, 0, 0.8),
shadowOffset=(-0.1, -0.1),
mayChange=True)
self.chineseText.setR(-8)
self.checkersText = OnscreenText(
text='Checkers',
pos=(0.81, -.1, -0.8),
scale=0.15,
fg=Vec4(1, 1, 1, 1),
align=TextNode.ACenter,
font=ToontownGlobals.getMinnieFont(),
wordwrap=7,
shadow=(0, 0, 0, 0.8),
shadowOffset=(0.1, -0.1),
mayChange=True)
self.findFourText = OnscreenText(
text='Find Four',
pos=(-0.81, -.08, -0.8),
scale=0.15,
fg=Vec4(1, 1, 1, 1),
align=TextNode.ACenter,
font=ToontownGlobals.getMinnieFont(),
wordwrap=8,
shadow=(0, 0, 0, 0.8),
shadowOffset=(-0.1, -0.1),
mayChange=True)
self.exitButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableCancelButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -0.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(0, 0, -0.4),
scale=0.15,
command=lambda self=self: self.cancelButtonPushed())
self.findFourText.setR(-8)
self.checkersText.setR(8)
def delete(self):
self.removeButtons()
def removeButtons(self):
self.ChineseCheckers.destroy()
self.Checkers.destroy()
self.FindFour.destroy()
self.chineseText.destroy()
self.checkersText.destroy()
self.findFourText.destroy()
self.exitButton.destroy()
DirectFrame.destroy(self)
def checkersSelected(self):
self.picnicFunction(GameGlobals.CheckersGameIndex)
self.picnicFunction = lambda gameIndex: None
def chineseCheckersSelected(self):
self.picnicFunction(GameGlobals.ChineseCheckersGameIndex)
self.picnicFunction = lambda gameIndex: None
def findFourSelected(self):
self.picnicFunction(GameGlobals.FindFourGameIndex)
self.picnicFunction = lambda gameIndex: None
def cancelButtonPushed(self):
self.picnicFunction(-1)
self.picnicFunction = lambda gameIndex: None
def doNothing(self):
pass

View file

@ -20,7 +20,7 @@ class ChineseTutorial(DirectFrame, FSM.FSM):
self.accept('stoppedAsleep', self.handleQuit)
self['image'] = DGG.getDefaultDialogGeom()
self.title = DirectLabel(self, relief=None, text='', text_pos=(0.0, 0.4), text_fg=(1, 0, 0, 1), text_scale=0.13, text_font=ToontownGlobals.getSignFont())
images = loader.loadModel('phase_6/models/golf/checker_tutorial')
images = loader.loadModel('phase_6/models/golf/checker_tutorial.bam')
images.setTransparency(1)
self.iPage1 = images.find('**/tutorialPage1*')
self.iPage1.reparentTo(aspect2d)
@ -138,7 +138,7 @@ class CheckersTutorial(DirectFrame, FSM.FSM):
self.accept('stoppedAsleep', self.handleQuit)
self['image'] = DGG.getDefaultDialogGeom()
self.title = DirectLabel(self, relief=None, text='', text_pos=(0.0, 0.4), text_fg=(1, 0, 0, 1), text_scale=0.13, text_font=ToontownGlobals.getSignFont())
images = loader.loadModel('phase_6/models/golf/regularchecker_tutorial')
images = loader.loadModel('phase_6/models/golf/regularchecker_tutorial.bam')
images.setTransparency(1)
self.iPage1 = images.find('**/tutorialPage1*')
self.iPage1.reparentTo(aspect2d)
@ -170,12 +170,12 @@ class CheckersTutorial(DirectFrame, FSM.FSM):
self.bNext = DirectButton(self, image=(gui.find('**/Horiz_Arrow_UP'),
gui.find('**/Horiz_Arrow_DN'),
gui.find('**/Horiz_Arrow_Rllvr'),
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), relief=None, text=TTLocalizer.ChineseTutorialNext, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.1), pos=(0.35, -0.3, -0.33), command=self.requestNext)
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), relief=None, text=TTLocalizer.ChineseTutorialNext, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.08), pos=(0.35, -0.3, -0.38), command=self.requestNext)
self.bPrev = DirectButton(self, image=(gui.find('**/Horiz_Arrow_UP'),
gui.find('**/Horiz_Arrow_DN'),
gui.find('**/Horiz_Arrow_Rllvr'),
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), image_scale=(-1.0, 1.0, 1.0), relief=None, text=TTLocalizer.ChineseTutorialPrev, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.1), pos=(-0.35, -0.3, -0.33), command=self.requestPrev)
self.bQuit = DirectButton(self, image=(buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr')), relief=None, text=TTLocalizer.ChineseTutorialDone, text_scale=0.05, text_pos=(0.0, -0.1), pos=(0.0, -0.3, -0.33), command=self.handleQuit)
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), image_scale=(-1.0, 1.0, 1.0), relief=None, text=TTLocalizer.ChineseTutorialPrev, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.08), pos=(-0.35, -0.3, -0.38), command=self.requestPrev)
self.bQuit = DirectButton(self, image=(buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr')), relief=None, text=TTLocalizer.ChineseTutorialDone, text_scale=0.05, text_pos=(0.0, -0.1), pos=(0.0, -0.3, -0.38), command=self.handleQuit)
self.bQuit.hide()
buttons.removeNode()
gui.removeNode()
@ -257,3 +257,80 @@ class CheckersTutorial(DirectFrame, FSM.FSM):
if task != None:
task.done
return
class FindFourTutorial(DirectFrame, FSM.FSM):
def __init__(self, doneFunction, doneEvent = None, callback = None):
FSM.FSM.__init__(self, 'FindFourTutorial')
self.doneFunction = doneFunction
base.localAvatar.startSleepWatch(self.handleQuit)
self.doneEvent = doneEvent
self.callback = callback
self.setStateArray(['Page1', 'Page2', 'Quit'])
base.localAvatar.startSleepWatch(self.handleQuit)
DirectFrame.__init__(self, pos=(-0.7, 0.0, 0.0), image_color=ToontownGlobals.GlobalDialogColor, image_scale=(1.0, 1.5, 1.0), text='', text_scale=0.06)
self.accept('stoppedAsleep', self.handleQuit)
self['image'] = DGG.getDefaultDialogGeom()
self.title = DirectLabel(self, relief=None, text='', text_pos=(0.0, 0.4), text_fg=(1, 0, 0, 1), text_scale=0.13, text_font=ToontownGlobals.getSignFont())
buttons = loader.loadModel('phase_3/models/gui/dialog_box_buttons_gui')
gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui')
self.bNext = DirectButton(self, image=(gui.find('**/Horiz_Arrow_UP'),
gui.find('**/Horiz_Arrow_DN'),
gui.find('**/Horiz_Arrow_Rllvr'),
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), relief=None, text=TTLocalizer.ChineseTutorialNext, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.1), pos=(0.35, -0.3, -0.33), command=self.requestNext)
self.bPrev = DirectButton(self, image=(gui.find('**/Horiz_Arrow_UP'),
gui.find('**/Horiz_Arrow_DN'),
gui.find('**/Horiz_Arrow_Rllvr'),
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(1, 1, 1, 0.5), image_scale=(-1.0, 1.0, 1.0), relief=None, text=TTLocalizer.ChineseTutorialPrev, text3_fg=Vec4(0, 0, 0, 0.5), text_scale=0.05, text_pos=(0.0, -0.1), pos=(-0.35, -0.3, -0.33), command=self.requestPrev)
self.bQuit = DirectButton(self, image=(buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr')), relief=None, text=TTLocalizer.ChineseTutorialDone, text_scale=0.05, text_pos=(0.0, -0.1), pos=(0.0, -0.3, -0.33), command=self.handleQuit)
self.bQuit.hide()
buttons.removeNode()
gui.removeNode()
self.request('Page1')
return
def __del__(self):
self.cleanup()
def enterPage1(self, *args):
self.bNext.show()
self.title['text'] = (TTLocalizer.ChineseTutorialTitle1,)
self['text'] = TTLocalizer.FindFourPage1
self['text_pos'] = (0.0, 0.23)
self['text_wordwrap'] = 13.5
self.bPrev['state'] = DGG.DISABLED
self.bPrev.hide()
self.bNext['state'] = DGG.NORMAL
def exitPage1(self, *args):
self.bPrev['state'] = DGG.NORMAL
def enterPage2(self, *args):
self.bPrev.show()
self.title['text'] = (TTLocalizer.ChineseTutorialTitle2,)
self['text'] = TTLocalizer.FindFourPage2
self['text_pos'] = (0.0, 0.28)
self['text_wordwrap'] = 12.5
self.bNext['state'] = DGG.DISABLED
self.bNext.hide()
self.bQuit.show()
def exitPage2(self, *args):
self.bQuit.hide()
def enterQuit(self, *args):
self.bNext.destroy()
self.bPrev.destroy()
self.bQuit.destroy()
DirectFrame.destroy(self)
def exitQuit(self, *args):
pass
def handleQuit(self, task = None):
base.cr.playGame.getPlace().setState('walk')
self.forceTransition('Quit')
self.doneFunction()
if task != None:
task.done
return