def __init__(self, potionGame):
     self.potionGame = potionGame
     DirectFrame.__init__(self, parent = potionGame.dialogs, relief = None)
     self.setPos((-0.5, 0, 0.074999999999999997))
     guiAssets = loader.loadModel('models/minigames/pir_m_gui_pot_textureCard')
     parch = guiAssets.find('**/pir_t_gui_pot_potionIngredients')
     parch.setScale(3.4500000000000002, 1, 3.4500000000000002)
     parch.setPos(0.5, 0, -0.02)
     self.background = parch.copyTo(self)
     self.bQuit = GuiButton(image = (guiAssets.find('**/pir_t_gui_pot_exitIngredients'), guiAssets.find('**/pir_t_gui_pot_exitIngredientsOn'), guiAssets.find('**/pir_t_gui_pot_exitIngredientsOn'), guiAssets.find('**/pir_t_gui_pot_exitIngredients')), scale = (0.29999999999999999, 0.29999999999999999, 0.29999999999999999), command = self.quit)
     self.bQuit.reparentTo(self)
     self.bQuit.setPos(1.673, 0, 0.76700000000000002)
     self.messageText = PLocalizer.PotionGui['InfoText']
     self.message = DirectLabel(parent = self, relief = None, text = self.messageText, text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_shadow = None, pos = (-0.17000000000000001, 0, 0.71999999999999997), textMayChange = 0)
     self.pieces = []
     self.pieceLabels = []
     for color in range(6):
         for level in range(6):
             piece = PotionBoardPiece(self, color, level + 1)
             piece.setPiecePosition(level * 0.112 - 0.27700000000000002, 0.17000000000000001 - color * 0.070900000000000005)
             piece.background.setDepthTest(False)
             piece.background.setDepthWrite(False)
             piece.setScale(0.34999999999999998)
             self.pieces.append(piece)
             piecelabel = DirectLabel(parent = self, relief = None, text = PLocalizer.PotionIngredients[color][level], text_scale = PiratesGuiGlobals.TextScaleMed, text_align = TextNode.ACenter, text_fg = PotionGlobals.TextColor, text_shadow = None, pos = (level * 0.38600000000000001 - 0.45200000000000001, 0, 0.438 - color * 0.245), textMayChange = 0)
             self.message = DirectLabel(parent = self, relief = None, text = PLocalizer.PotionIngredients[color][level], text_scale = PiratesGuiGlobals.TextScaleMed, text_align = TextNode.ACenter, text_fg = PotionGlobals.TextColor, text_shadow = None, pos = (level * 0.38600000000000001 - 0.45200000000000001, 0, 0.438 - color * 0.245), textMayChange = 0)
             self.pieceLabels.append(piecelabel)
         
     
     guiAssets.removeNode()
Exemplo n.º 2
0
 def addNewPiece(self):
     currentRecipe = self.potionGame.currentRecipe
     if self.leftPreviewPiece is None:
         self.leftPreviewPiece = PotionBoardPiece(self,
                                                  recipe=currentRecipe)
         self.rightPreviewPiece = PotionBoardPiece(self,
                                                   recipe=currentRecipe)
         self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
         self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
     self.leftPlayerPiece = self.leftPreviewPiece
     self.rightPlayerPiece = self.rightPreviewPiece
     self.leftPreviewPiece = PotionBoardPiece(
         self, colorSet=self.potionGame.dist.colorSet, recipe=currentRecipe)
     self.rightPreviewPiece = PotionBoardPiece(
         self, colorSet=self.potionGame.dist.colorSet, recipe=currentRecipe)
     self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
     self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
     self.leftPlayerPiece.setY(-5)
     self.leftPlayerPiece.reparentTo(self)
     self.rightPlayerPiece.setY(-5)
     self.rightPlayerPiece.reparentTo(self)
     self.leftPlayerPiece.moveFast = True
     self.rightPlayerPiece.moveFast = True
     self.potionGame.animationList.append(
         Sequence(
             self.leftPlayerPiece.moveToBoard(self.lastLeftCol,
                                              self.numRows - 1),
             Func(self.leftPlayerPiece.setY, 0)))
     self.potionGame.animationList.append(
         Sequence(
             self.rightPlayerPiece.moveToBoard(self.lastRightCol,
                                               self.numRows - 1),
             Func(self.rightPlayerPiece.setY, 0)))
     return
Exemplo n.º 3
0
    def __init__(self, potionGame):
        self.potionGame = potionGame
        DirectFrame.__init__(self, parent=potionGame.dialogs, relief=None)
        self.setPos((-0.5, 0, 0.075))
        guiAssets = loader.loadModel('models/minigames/pir_m_gui_pot_textureCard')
        parch = guiAssets.find('**/pir_t_gui_pot_potionIngredients')
        parch.setScale(3.45, 1, 3.45)
        parch.setPos(0.5, 0, -0.02)
        self.background = parch.copyTo(self)
        self.bQuit = GuiButton(image=(guiAssets.find('**/pir_t_gui_pot_exitIngredients'), guiAssets.find('**/pir_t_gui_pot_exitIngredientsOn'), guiAssets.find('**/pir_t_gui_pot_exitIngredientsOn'), guiAssets.find('**/pir_t_gui_pot_exitIngredients')), scale=(0.3,
                                                                                                                                                                                                                                                                  0.3,
                                                                                                                                                                                                                                                                  0.3), command=self.quit)
        self.bQuit.reparentTo(self)
        self.bQuit.setPos(1.673, 0, 0.767)
        self.messageText = PLocalizer.PotionGui['InfoText']
        self.message = DirectLabel(parent=self, relief=None, text=self.messageText, text_scale=PiratesGuiGlobals.TextScaleTitleSmall, text_align=TextNode.ARight, text_fg=PotionGlobals.TextColor, text_shadow=None, pos=(-0.17, 0, 0.72), textMayChange=0)
        self.pieces = []
        self.pieceLabels = []
        for color in range(6):
            for level in range(6):
                piece = PotionBoardPiece(self, color, level + 1)
                piece.setPiecePosition(level * 0.112 - 0.277, 0.17 - color * 0.0709)
                piece.background.setDepthTest(False)
                piece.background.setDepthWrite(False)
                piece.setScale(0.35)
                self.pieces.append(piece)
                piecelabel = self.message = DirectLabel(parent=self, relief=None, text=PLocalizer.PotionIngredients[color][level], text_scale=PiratesGuiGlobals.TextScaleMed, text_align=TextNode.ACenter, text_fg=PotionGlobals.TextColor, text_shadow=None, pos=(level * 0.386 - 0.452, 0, 0.438 - color * 0.245), textMayChange=0)
                self.pieceLabels.append(piecelabel)

        guiAssets.removeNode()
        return
 def addNewPiece(self):
     currentRecipe = self.potionGame.currentRecipe
     if self.leftPreviewPiece is None:
         self.leftPreviewPiece = PotionBoardPiece(self, recipe = currentRecipe)
         self.rightPreviewPiece = PotionBoardPiece(self, recipe = currentRecipe)
         self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
         self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
     
     self.leftPlayerPiece = self.leftPreviewPiece
     self.rightPlayerPiece = self.rightPreviewPiece
     self.leftPreviewPiece = PotionBoardPiece(self, colorSet = self.potionGame.dist.colorSet, recipe = currentRecipe)
     self.rightPreviewPiece = PotionBoardPiece(self, colorSet = self.potionGame.dist.colorSet, recipe = currentRecipe)
     self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
     self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
     self.leftPlayerPiece.setY(-5)
     self.leftPlayerPiece.reparentTo(self)
     self.rightPlayerPiece.setY(-5)
     self.rightPlayerPiece.reparentTo(self)
     self.leftPlayerPiece.moveFast = True
     self.rightPlayerPiece.moveFast = True
     self.potionGame.animationList.append(Sequence(self.leftPlayerPiece.moveToBoard(self.lastLeftCol, self.numRows - 1), Func(self.leftPlayerPiece.setY, 0)))
     self.potionGame.animationList.append(Sequence(self.rightPlayerPiece.moveToBoard(self.lastRightCol, self.numRows - 1), Func(self.rightPlayerPiece.setY, 0)))
Exemplo n.º 5
0
class PotionGameBoard(DirectFrame):
    __module__ = __name__

    def __init__(self, potionGame):
        self.numColumns = 8
        self.numRows = 10
        DirectFrame.__init__(self, parent=potionGame.background, relief=None)
        cm = CardMaker('card')
        cm.setFrame(0, 0, 1.0, 1.0)
        self.background = self.attachNewNode(cm.generate())
        self.background.setColor(0.2, 0.2, 0.2, 1)
        self.potionGame = potionGame
        self.pieceDropped = False
        self.pieceFlipped = False
        self.pieceNotDropped = False
        self.delayDropped = False
        self.experementMatched = False
        self.experementFailed = False
        self.initBoard()
        return

    def initBoard(self):
        self.boardPieces = []
        ColumnList = range(self.numColumns)
        RowList = range(self.numRows)
        for columnIndex in ColumnList:
            self.boardPieces.append([])
            for rowIndex in RowList:
                self.boardPieces[columnIndex].append(None)

        self.rightPlayerPiece = None
        self.leftPlayerPiece = None
        self.leftPreviewPiece = None
        self.rightPreviewPiece = None
        self.lastLeftCol = 0
        self.lastRightCol = 1
        self.lastDragPos = None
        self.dragPiece = None
        return

    def resetBoard(self):
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.removeNode()
                    del piece

        if self.rightPlayerPiece is not None:
            self.rightPlayerPiece.removeNode()
        if self.leftPlayerPiece is not None:
            self.leftPlayerPiece.removeNode()
        if self.leftPreviewPiece is not None:
            self.leftPreviewPiece.removeNode()
        if self.rightPreviewPiece is not None:
            self.rightPreviewPiece.removeNode()
        del self.rightPlayerPiece
        del self.leftPlayerPiece
        del self.leftPreviewPiece
        del self.rightPreviewPiece
        self.initBoard()
        return

    def jumpLeft(self):
        if self.leftPlayerPiece.column > 0:
            self.leftPlayerPiece.column -= 1
            self.leftPlayerPiece.setBoardPos(self.leftPlayerPiece.column,
                                             self.leftPlayerPiece.row)
            self.rightPlayerPiece.column -= 1
            self.rightPlayerPiece.setBoardPos(self.rightPlayerPiece.column,
                                              self.leftPlayerPiece.row)

    def jumpRight(self):
        if self.rightPlayerPiece.column < self.numColumns - 1:
            self.leftPlayerPiece.column += 1
            self.leftPlayerPiece.setBoardPos(self.leftPlayerPiece.column,
                                             self.leftPlayerPiece.row)
            self.rightPlayerPiece.column += 1
            self.rightPlayerPiece.setBoardPos(self.rightPlayerPiece.column,
                                              self.leftPlayerPiece.row)

    def moveLeft(self):
        if self.leftPlayerPiece.column > 0:
            self.disableInputEvents()
            self.potionGame.animationList.append(
                self.leftPlayerPiece.moveLeft())
            self.potionGame.animationList.append(
                self.rightPlayerPiece.moveLeft())
            self.potionGame.gameFSM.request('Anim')

    def moveRight(self):
        if self.rightPlayerPiece.column < self.numColumns - 1:
            self.disableInputEvents()
            self.potionGame.animationList.append(
                self.leftPlayerPiece.moveRight())
            self.potionGame.animationList.append(
                self.rightPlayerPiece.moveRight())
            self.potionGame.gameFSM.request('Anim')

    def moveUp(self):
        self.disableInputEvents()
        self.potionGame.animationList.append(self.leftPlayerPiece.moveRight())
        self.potionGame.animationList.append(self.rightPlayerPiece.moveLeft())
        temp = self.leftPlayerPiece
        self.leftPlayerPiece = self.rightPlayerPiece
        self.rightPlayerPiece = temp
        self.pieceFlipped = True
        self.potionGame.gameFSM.request('Anim')

    def moveDown(self):
        self.disableInputEvents()
        if self.boardPieces[self.leftPlayerPiece.column][
                self.leftPlayerPiece.row - 1] is None:
            self.boardPieces[self.leftPlayerPiece.column][
                self.leftPlayerPiece.row] = (
                    self.boardPieces[self.rightPlayerPiece.column][
                        self.rightPlayerPiece.row - 1] is None
                    and self).leftPlayerPiece
            self.boardPieces[self.rightPlayerPiece.column][
                self.rightPlayerPiece.row] = self.rightPlayerPiece
            self.checkFall(True)
            self.pieceDropped = True
            self.potionGame.currentRecipe.useTiles(2)
            self.potionGame.gameFSM.request('Anim')
            self.lastLeftCol = self.leftPlayerPiece.column
            self.lastRightCol = self.rightPlayerPiece.column
            self.rightPlayerPiece = None
            self.leftPlayerPiece = None
        else:
            self.pieceNotDropped = True
            self.leftPlayerPiece.setY(-5)
            self.rightPlayerPiece.setY(-5)
            self.potionGame.animationList.append(
                Sequence(
                    Parallel(
                        LerpPosInterval(self.leftPlayerPiece,
                                        duration=0.1,
                                        pos=(self.leftPlayerPiece.getX(),
                                             self.leftPlayerPiece.getY(),
                                             self.leftPlayerPiece.getZ() -
                                             0.05)),
                        LerpPosInterval(self.rightPlayerPiece,
                                        duration=0.1,
                                        pos=(self.rightPlayerPiece.getX(),
                                             self.rightPlayerPiece.getY(),
                                             self.rightPlayerPiece.getZ() -
                                             0.05))),
                    Parallel(
                        LerpPosInterval(self.leftPlayerPiece,
                                        duration=0.1,
                                        pos=(self.leftPlayerPiece.getX(),
                                             self.leftPlayerPiece.getY(),
                                             self.leftPlayerPiece.getZ())),
                        LerpPosInterval(self.rightPlayerPiece,
                                        duration=0.1,
                                        pos=(self.rightPlayerPiece.getX(),
                                             self.rightPlayerPiece.getY(),
                                             self.rightPlayerPiece.getZ()))),
                    Func(self.leftPlayerPiece.setY, 0),
                    Func(self.rightPlayerPiece.setY, 0)))
            self.potionGame.gameFSM.request('Anim')
        return

    def checkFall(self, drop):
        for columnIndex in range(self.numColumns):
            for rowIndex in range(self.numRows - 1):
                if self.boardPieces[columnIndex][rowIndex] is None:
                    filled = False
                    for rowIndex2 in range(rowIndex + 1, self.numRows):
                        if self.boardPieces[columnIndex][
                                rowIndex2] is not None:
                            filled = filled == False and True
                            self.boardPieces[columnIndex][
                                rowIndex] = self.boardPieces[columnIndex][
                                    rowIndex2]
                            self.boardPieces[columnIndex][rowIndex2] = None
                            piece = self.boardPieces[columnIndex][rowIndex]
                            self.potionGame.animationList.append(
                                Sequence(
                                    Func(piece.setY, -5),
                                    piece.moveToBoard(columnIndex, rowIndex),
                                    Func(piece.setY, 0)))

        return

    def showSoulXP(self, Xloc, Zloc, count):
        xpAmt = PotionGlobals.BONUS_XP_AMT[count]
        xpLabel = DirectLabel(parent=aspect2d,
                              relief=None,
                              text='+ ' + str(xpAmt) + ' ' +
                              PLocalizer.PotionGui['XPLabel'],
                              text_scale=PiratesGuiGlobals.TextScaleTitleLarge,
                              text_font=PiratesGlobals.getPirateOutlineFont(),
                              text_align=TextNode.ACenter,
                              text_fg=PiratesGuiGlobals.TextFG1,
                              text_shadow=PiratesGuiGlobals.TextShadow,
                              text_wordwrap=37,
                              pos=(Xloc, 0, Zloc - 0.1),
                              textMayChange=0)
        xpLabel.setTransparency(True)
        xpLabel.stash()
        return Sequence(
            Func(xpLabel.unstash),
            Parallel(
                LerpPosInterval(xpLabel,
                                duration=2.5,
                                pos=(Xloc, 0.0, Zloc + 0.3),
                                blendType='easeOut'),
                LerpColorScaleInterval(xpLabel,
                                       duration=1.5,
                                       colorScale=(1, 1, 1, 0),
                                       blendType='easeIn')),
            Func(xpLabel.removeNode))

    def findGroups(self):
        self.groups = []
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.findConnections(self)

        self.removeList = []
        self.upgradeList = []
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.pendingMatch = False
                    if len(piece.connections) > 0:
                        found = False
                        for group in self.groups:
                            if piece in group:
                                found = True

                        if not found:
                            self.groups.append([])
                            self.addToGroup(self.groups[-1], piece)

        for group in self.groups:
            if len(group) > 2:
                group.sort(reverse=True)
                removePiece = group[0]
                self.removeList.append(removePiece)
                group.remove(removePiece)
                for piece in group:
                    if removePiece in piece.connections:
                        piece.connectionsRemoved += 1

                group.sort(reverse=True)
                removePiece = group[0]
                self.removeList.append(removePiece)
                group.remove(removePiece)
                bonusPieces = 0
                avgX = 0
                avgZ = 0
                for piece in group:
                    if piece.level < 6:
                        self.upgradeList.append(piece)
                        if piece.level == 5:
                            self.potionGame.soulMade = True
                    else:
                        self.removeList.append(piece)
                        bonusPieces += 1
                        avgX += piece.getX(aspect2d)
                        avgZ += piece.getZ(aspect2d)

                if bonusPieces > 0:
                    avgX /= float(len(group))
                    avgZ /= float(len(group))
                    self.potionGame.soulMatch = True
                    self.potionGame.currentRecipe.clearedSouls(bonusPieces + 2)
                    self.potionGame.animationList.append(
                        self.showSoulXP(avgX, avgZ, bonusPieces - 1))
                    self.potionGame.dist.d_claimXPBonus(bonusPieces - 1)

        if len(self.removeList) > 0:
            self.previewGroups = []
            for column in self.boardPieces:
                for piece in column:
                    if piece is not None:
                        piece.previewConnections(self)

            for column in self.boardPieces:
                for piece in column:
                    if piece is not None:
                        if len(piece.pendingConnections) > 0:
                            found = False
                            for group in self.previewGroups:
                                if piece in group:
                                    found = True

                            if not found:
                                self.previewGroups.append([])
                                self.addToPreviewGroup(self.previewGroups[-1],
                                                       piece)

            for group in self.previewGroups:
                if len(group) > 2:
                    for piece in group:
                        piece.pendingMatch = True

            upgradeCount = len(self.upgradeList)
            self.potionGame.currentRecipe.madeIngredients(upgradeCount)
            self.removePieces()
            self.upgradePieces()
        return

    def addToPreviewGroup(self, group, piece):
        group.append(piece)
        for nextPiece in piece.pendingConnections:
            if nextPiece not in group:
                self.addToPreviewGroup(group, nextPiece)

    def addToGroup(self, group, piece):
        group.append(piece)
        for nextPiece in piece.connections:
            if nextPiece not in group:
                self.addToGroup(group, nextPiece)

    def removePieces(self):
        for piece in self.removeList:
            self.boardPieces[piece.column][piece.row] = None
            mergePiece = None
            for adjPiece in piece.connections:
                if adjPiece in self.upgradeList:
                    mergePiece = adjPiece

            if mergePiece is None:
                for adjPiece in piece.connections:
                    for adjadjPiece in adjPiece.connections:
                        if adjadjPiece in self.upgradeList:
                            mergePiece = adjadjPiece

            if mergePiece is not None:
                rotQuat = Quat()
                rotQuat.setHpr((piece.getH(), piece.getP() + 90, piece.getR()))
                outInterval = Parallel(
                    LerpQuatInterval(piece.background,
                                     duration=0.4,
                                     quat=rotQuat,
                                     blendType='easeIn'),
                    piece.moveToBoardSlow(mergePiece.column, mergePiece.row))
            else:
                outInterval = LerpColorInterval(piece.background,
                                                duration=0.6,
                                                color=(1, 1, 1, 0))
            self.potionGame.animationList.append(
                Sequence(Func(piece.setY, 5), outInterval,
                         Func(piece.removeNode), Func(self.kill, piece)))

        return

    def upgradePieces(self):
        for columnIndex in range(self.numColumns):
            for rowIndex in range(self.numRows - 1):
                if self.boardPieces[columnIndex][rowIndex] is None:
                    filled = False
                    for rowIndex2 in range(rowIndex + 1, self.numRows):
                        if self.boardPieces[columnIndex][
                                rowIndex2] is not None:
                            if filled == False:
                                filled = True
                                piece = self.boardPieces[columnIndex][
                                    rowIndex2]
                                if not piece.pendingMatch:
                                    self.boardPieces[columnIndex][
                                        rowIndex] = self.boardPieces[
                                            columnIndex][rowIndex2]
                                    self.boardPieces[columnIndex][
                                        rowIndex2] = None
                                    rotQuat = piece in self.upgradeList and Quat(
                                    )
                                    rotQuat2 = Quat()
                                    rotQuat3 = Quat()
                                    rotQuat.setHpr(
                                        (piece.getH(), piece.getP() + 90,
                                         piece.getR()))
                                    rotQuat2.setHpr(
                                        (piece.getH(), piece.getP() + 270,
                                         piece.getR()))
                                    rotQuat3.setHpr(
                                        (piece.getH(), piece.getP() + 360,
                                         piece.getR()))
                                    self.potionGame.animationList.append(
                                        Sequence(
                                            Func(piece.setY, -10),
                                            LerpQuatInterval(
                                                piece.background,
                                                duration=0.4,
                                                quat=rotQuat,
                                                blendType='easeIn'),
                                            Func(piece.upgrade),
                                            Parallel(
                                                piece.moveToBoardSlow(
                                                    columnIndex, rowIndex),
                                                LerpQuatInterval(
                                                    piece.background,
                                                    duration=0.4,
                                                    quat=rotQuat3,
                                                    startQuat=rotQuat2,
                                                    blendType='easeOut')),
                                            Func(piece.setY, 0)))
                                    self.delayDropped = True
                                    self.upgradeList.remove(piece)
                                else:
                                    self.delayDropped = True
                                    self.potionGame.animationList.append(
                                        Sequence(
                                            Func(piece.setY, -5), Wait(0.5),
                                            piece.moveToBoard(
                                                columnIndex, rowIndex),
                                            Func(piece.setY, 0)))

        for piece in self.upgradeList:
            rotQuat = Quat()
            rotQuat2 = Quat()
            rotQuat3 = Quat()
            rotQuat.setHpr((piece.getH(), piece.getP() + 90, piece.getR()))
            rotQuat2.setHpr((piece.getH(), piece.getP() + 270, piece.getR()))
            rotQuat3.setHpr((piece.getH(), piece.getP() + 360, piece.getR()))
            piece.setY(-10)
            OutSeq = LerpQuatInterval(piece.background,
                                      duration=0.4,
                                      quat=rotQuat3,
                                      startQuat=rotQuat2,
                                      blendType='easeOut')
            self.potionGame.animationList.append(
                Sequence(
                    LerpQuatInterval(piece.background,
                                     duration=0.4,
                                     quat=rotQuat,
                                     blendType='easeIn'), Func(piece.upgrade),
                    OutSeq, Func(piece.setY, 0)))

        return

    def kill(self, piece):
        del piece

    def handleMouseDown(self):
        if base.mouseWatcherNode.hasMouse():
            screenx = base.mouseWatcherNode.getMouseX()
            screeny = base.mouseWatcherNode.getMouseY()
            self.lastDragPos = self.getRelativePoint(render2d,
                                                     (screenx, 0, screeny))
            self.dragDist = 0

    def handleMouseUp(self):
        dragHandled = False
        if self.lastDragPos is not None:
            if base.mouseWatcherNode.hasMouse():
                screenx = base.mouseWatcherNode.getMouseX()
                screeny = base.mouseWatcherNode.getMouseY()
                dragPos = self.getRelativePoint(render2d,
                                                (screenx, 0, screeny))
                self.dragDist += (dragPos - self.lastDragPos).length()
                if self.dragDist < 0.01:
                    if self.dragPiece is not None:
                        self.dragPiece.wrtReparentTo(self)
                        self.potionGame.animationList.append(
                            Sequence(
                                self.dragPiece.moveToBoard(
                                    self.dragPiece.column, self.dragPiece.row),
                                Func(self.dragPiece.setY, 0)))
                        self.dragPiece = None
                    if screenx > 0:
                        if screeny > -0.8:
                            if screenx < 0.88 and screeny < 0.92:
                                self.moveDown()
                        recipePos = self.dragPiece is not None and False and self.potionGame.currentRecipe.getRelativePoint(
                            render2d, (screenx, 0, screeny))
                        neededIngredient = None
                        for ingredient in self.potionGame.currentRecipe.ingredients:
                            if ingredient.hiddenColor == self.dragPiece.colorIndex:
                                neededIngredient = ingredient.hiddenLevel == self.dragPiece.level and not ingredient.completed and ingredient

                        if neededIngredient is not None:
                            for ingredient in self.potionGame.currentRecipe.ingredients:
                                if not ingredient.completed:
                                    if not dragHandled:
                                        ingredientDist = (ingredient.getPos() -
                                                          recipePos).length()
                                        neededIngredient.completed = ingredientDist < 0.2 and True
                                        self.dragPiece.wrtReparentTo(
                                            self.potionGame.currentRecipe)
                                        self.boardPieces[
                                            self.dragPiece.column][
                                                self.dragPiece.row] = None
                                        self.lastDragPos = None
                                        self.potionGame.animationList.append(
                                            Sequence(
                                                self.dragPiece.moveToBoard(
                                                    neededIngredient.column,
                                                    neededIngredient.row),
                                                Func(neededIngredient.setColor,
                                                     self.dragPiece.colorIndex,
                                                     self.dragPiece.level),
                                                Func(self.killDragPiece)))
                                        dragHandled = True
                                        self.experementMatched = True
                                        self.potionGame.gameFSM.request('Anim')

                        else:
                            for ingredient in self.potionGame.currentRecipe.ingredients:
                                if not ingredient.completed:
                                    ingredientDist = (ingredient.getPos() -
                                                      recipePos).length()
                                    if ingredientDist < 0.2:
                                        self.experementFailed = True

                if self.dragPiece is not None and not dragHandled:
                    self.dragPiece.wrtReparentTo(self)
                    self.potionGame.animationList.append(
                        Sequence(
                            self.dragPiece.moveToBoard(self.dragPiece.column,
                                                       self.dragPiece.row),
                            Func(self.dragPiece.setY, 0)))
                    self.potionGame.gameFSM.request('Anim')
                    self.dragPiece = None
                self.lastDragPos = None
        return

    def killDragPiece(self):
        self.dragPiece.removeNode()
        del self.dragPiece
        self.dragPiece = None
        return

    def enableInputEvents(self):
        self.accept('mouse1', self.handleMouseDown)
        self.accept('mouse1-up', self.handleMouseUp)
        self.accept('mouse3', self.moveUp)
        self.accept('space', self.moveUp)
        taskMgr.add(self.handleMouseLoc, 'PotionMinigameMouseInputTask')

    def disableInputEvents(self):
        self.ignore('j')
        self.ignore('l')
        self.ignore('k')
        self.ignore('i')
        self.ignore('mouse1')
        self.ignore('mouse1-up')
        self.ignore('mouse3')
        self.ignore('space')
        taskMgr.remove('PotionMinigameMouseInputTask')

    def handleMouseLoc(self, task):
        if base.mouseWatcherNode.hasMouse():
            screenx = base.mouseWatcherNode.getMouseX()
            screeny = base.mouseWatcherNode.getMouseY()
            localMousePos = self.getRelativePoint(render2d,
                                                  (screenx, 0, screeny))
            if self.lastDragPos is None:
                if self.leftPlayerPiece is not None:
                    if self.rightPlayerPiece is not None and localMousePos[
                            0] < self.leftPlayerPiece.Xpos:
                        self.jumpLeft()
                    localMousePos[
                        0] > self.rightPlayerPiece.Xpos and self.jumpRight()
            elif self.lastDragPos is not None:
                self.dragDist += (localMousePos - self.lastDragPos).length()
                self.lastDragPos = localMousePos
                if self.dragDist > 0.01:
                    globalMousePos = self.dragPiece is not None and self.potionGame.background.getRelativePoint(
                        render2d, (screenx, 0, screeny))
                    self.dragPiece.setPiecePosition(globalMousePos[0],
                                                    globalMousePos[2])
        return Task.cont

    def playerPieceActive(self):
        return self.rightPlayerPiece is not None and self.leftPlayerPiece is not None

    def checkAvailableMoves(self):
        movesLeft = False
        for columnIndex in range(self.numColumns - 1):
            if self.boardPieces[columnIndex][self.numRows - 2] is None:
                movesLeft = self.boardPieces[columnIndex + 1][
                    self.numRows - 2] is None and True

        return movesLeft

    def addNewPiece(self):
        currentRecipe = self.potionGame.currentRecipe
        if self.leftPreviewPiece is None:
            self.leftPreviewPiece = PotionBoardPiece(self,
                                                     recipe=currentRecipe)
            self.rightPreviewPiece = PotionBoardPiece(self,
                                                      recipe=currentRecipe)
            self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
            self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
        self.leftPlayerPiece = self.leftPreviewPiece
        self.rightPlayerPiece = self.rightPreviewPiece
        self.leftPreviewPiece = PotionBoardPiece(
            self, colorSet=self.potionGame.dist.colorSet, recipe=currentRecipe)
        self.rightPreviewPiece = PotionBoardPiece(
            self, colorSet=self.potionGame.dist.colorSet, recipe=currentRecipe)
        self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
        self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
        self.leftPlayerPiece.setY(-5)
        self.leftPlayerPiece.reparentTo(self)
        self.rightPlayerPiece.setY(-5)
        self.rightPlayerPiece.reparentTo(self)
        self.leftPlayerPiece.moveFast = True
        self.rightPlayerPiece.moveFast = True
        self.potionGame.animationList.append(
            Sequence(
                self.leftPlayerPiece.moveToBoard(self.lastLeftCol,
                                                 self.numRows - 1),
                Func(self.leftPlayerPiece.setY, 0)))
        self.potionGame.animationList.append(
            Sequence(
                self.rightPlayerPiece.moveToBoard(self.lastRightCol,
                                                  self.numRows - 1),
                Func(self.rightPlayerPiece.setY, 0)))
        return
Exemplo n.º 6
0
 def loadIngredients(self):
     cm = CardMaker('card')
     cm.setFrame(0, 0.80000000000000004, 0, 0.29999999999999999)
     self.background = self.attachNewNode(cm.generate())
     self.background.setTransparency(True)
     self.background.setColor(0.69999999999999996, 0.69999999999999996, 0.69999999999999996, 0)
     self.islandReq = 0
     if len(self.ingredientData) > 0:
         if False:
             self.nameText = PLocalizer.PotionGui['UnknownRecipeName']
             self.descText = PLocalizer.PotionGui['UnknownRecipe']
             if len(self.ingredients) > 0:
                 for ingredient in self.ingredients:
                     if ingredient.colorIndex > -1:
                         ingredient.setColor(-1, -1)
                         continue
                 
             else:
                 for ingredientData in self.ingredientData:
                     ingredient = PotionBoardPiece(self, -1, -1)
                     ingredient.setHiddenInfo(ingredientData['color'], ingredientData['level'])
                     if ingredientData['color'] > 2:
                         self.islandReq = ingredientData['color']
                     
                     ingredient.showName()
                     self.ingredients.append(ingredient)
                 
         else:
             self.nameText = self.name
             self.descText = self.desc
             if len(self.ingredients) > 0:
                 for ingredient in self.ingredients:
                     if ingredient.colorIndex < 0:
                         ingredient.setColor(ingredientData['color'], ingredientData['level'])
                     
                     if ingredient.colorIndex > 2:
                         self.islandReq = ingredient.colorIndex
                         continue
                 
             else:
                 for ingredientData in self.ingredientData:
                     ingredient = PotionBoardPiece(self, ingredientData['color'], ingredientData['level'])
                     if ingredientData['color'] > 2:
                         self.islandReq = ingredientData['color']
                     
                     ingredient.showName()
                     self.ingredients.append(ingredient)
                 
         for ingredient in self.ingredients:
             ingredient.setCompleted(False)
             ingredient.setBoardPos(0, (5.2999999999999998 - self.ingredients.index(ingredient)) * 1.05)
         
     else:
         self.nameText = self.name
         self.descText = self.desc
         if self.ingredientCount is not None:
             self.ingredientCount.removeNode()
         
         self.ingredientCount = DirectLabel(parent = self.background, relief = None, text = str(self.ingredientsMade), text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.94999999999999996), textMayChange = 1)
         if self.ingredientLabel is not None:
             self.ingredientLabel.removeNode()
         
         self.ingredientLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['IngredientCount'], text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.94999999999999996), textMayChange = 1)
         if self.tileCount is not None:
             self.tileCount.removeNode()
         
         self.tileCount = DirectLabel(parent = self.background, relief = None, text = str(self.tilesUsed), text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.75), textMayChange = 1)
         if self.tileLabel is not None:
             self.tileLabel.removeNode()
         
         self.tileLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['TileCount'], text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.75), textMayChange = 1)
         if self.soulCount is not None:
             self.soulCount.removeNode()
         
         self.soulCount = DirectLabel(parent = self.background, relief = None, text = str(self.soulsCleared), text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.84999999999999998), textMayChange = 1)
         if self.soulLabel is not None:
             self.soulLabel.removeNode()
         
         self.soulLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['SoulCount'], text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.84999999999999998), textMayChange = 1)
     self.leveltext = PLocalizer.PotionGui['LevelLabel'] + str(self.level)
     if self.islandReq > 0:
         self.islandtext = PLocalizer.PotionGui['IslandName' + str(self.islandReq)]
     else:
         self.islandtext = PLocalizer.PotionGui['IslandName']
     if not self.enabled:
         self.levelColor = PiratesGuiGlobals.TextOV6
     elif not self.available:
         self.levelColor = PotionGlobals.TextColorDisabled
     else:
         self.levelColor = PotionGlobals.TextColor
     if not self.available:
         self.islandColor = PiratesGuiGlobals.TextOV6
     elif not self.enabled:
         self.islandColor = PotionGlobals.TextColorDisabled
     else:
         self.islandColor = PotionGlobals.TextColor
     if self.available and self.enabled:
         self.titleColor = PotionGlobals.TextColor
     else:
         self.titleColor = PotionGlobals.TextColorDisabled
     if self.title is not None:
         self.title.removeNode()
     
     self.title = DirectLabel(parent = self.background, relief = None, text = self.nameText, text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ACenter, text_fg = self.titleColor, text_wordwrap = 30, pos = (0.37, 0, 1.23), textMayChange = 0)
     if self.subtitle1 is not None:
         self.subtitle1.removeNode()
     
     self.subtitle1 = DirectLabel(parent = self.background, relief = None, text = self.leveltext, text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ARight, text_fg = self.levelColor, text_wordwrap = 30, pos = (0.34999999999999998, 0, 1.1799999999999999), textMayChange = 0)
     if self.subtitle2 is not None:
         self.subtitle2.removeNode()
     
     self.subtitle2 = DirectLabel(parent = self.background, relief = None, text = self.islandtext, text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ALeft, text_fg = self.islandColor, text_wordwrap = 30, pos = (0.39000000000000001, 0, 1.1799999999999999), textMayChange = 0)
     if self.subtitle3 is not None:
         self.subtitle3.removeNode()
     
     self.subtitle3 = DirectLabel(parent = self.background, relief = None, text = self.descText, text_scale = PiratesGuiGlobals.TextScaleMed, text_align = TextNode.ACenter, text_fg = self.titleColor, text_wordwrap = 30, pos = (0.37, 0, 1.1299999999999999), textMayChange = 0)
     self.stash()
 def loadIngredients(self):
     cm = CardMaker('card')
     cm.setFrame(0, 0.80000000000000004, 0, 0.29999999999999999)
     self.background = self.attachNewNode(cm.generate())
     self.background.setTransparency(True)
     self.background.setColor(0.69999999999999996, 0.69999999999999996, 0.69999999999999996, 0)
     self.islandReq = 0
     if len(self.ingredientData) > 0:
         if False:
             self.nameText = PLocalizer.PotionGui['UnknownRecipeName']
             self.descText = PLocalizer.PotionGui['UnknownRecipe']
             if len(self.ingredients) > 0:
                 for ingredient in self.ingredients:
                     if ingredient.colorIndex > -1:
                         ingredient.setColor(-1, -1)
                         continue
                 
             else:
                 for ingredientData in self.ingredientData:
                     ingredient = PotionBoardPiece(self, -1, -1)
                     ingredient.setHiddenInfo(ingredientData['color'], ingredientData['level'])
                     if ingredientData['color'] > 2:
                         self.islandReq = ingredientData['color']
                     
                     ingredient.showName()
                     self.ingredients.append(ingredient)
                 
         else:
             self.nameText = self.name
             self.descText = self.desc
             if len(self.ingredients) > 0:
                 for ingredient in self.ingredients:
                     if ingredient.colorIndex < 0:
                         ingredient.setColor(ingredientData['color'], ingredientData['level'])
                     
                     if ingredient.colorIndex > 2:
                         self.islandReq = ingredient.colorIndex
                         continue
                 
             else:
                 for ingredientData in self.ingredientData:
                     ingredient = PotionBoardPiece(self, ingredientData['color'], ingredientData['level'])
                     if ingredientData['color'] > 2:
                         self.islandReq = ingredientData['color']
                     
                     ingredient.showName()
                     self.ingredients.append(ingredient)
                 
         for ingredient in self.ingredients:
             ingredient.setCompleted(False)
             ingredient.setBoardPos(0, (5.2999999999999998 - self.ingredients.index(ingredient)) * 1.05)
         
     else:
         self.nameText = self.name
         self.descText = self.desc
         if self.ingredientCount is not None:
             self.ingredientCount.removeNode()
         
         self.ingredientCount = DirectLabel(parent = self.background, relief = None, text = str(self.ingredientsMade), text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.94999999999999996), textMayChange = 1)
         if self.ingredientLabel is not None:
             self.ingredientLabel.removeNode()
         
         self.ingredientLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['IngredientCount'], text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.94999999999999996), textMayChange = 1)
         if self.tileCount is not None:
             self.tileCount.removeNode()
         
         self.tileCount = DirectLabel(parent = self.background, relief = None, text = str(self.tilesUsed), text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.75), textMayChange = 1)
         if self.tileLabel is not None:
             self.tileLabel.removeNode()
         
         self.tileLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['TileCount'], text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.75), textMayChange = 1)
         if self.soulCount is not None:
             self.soulCount.removeNode()
         
         self.soulCount = DirectLabel(parent = self.background, relief = None, text = str(self.soulsCleared), text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_align = TextNode.ARight, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.17000000000000001, 0, 0.84999999999999998), textMayChange = 1)
         if self.soulLabel is not None:
             self.soulLabel.removeNode()
         
         self.soulLabel = DirectLabel(parent = self.background, relief = None, text = PLocalizer.PotionGui['SoulCount'], text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_align = TextNode.ALeft, text_fg = PotionGlobals.TextColor, text_wordwrap = 30, pos = (0.25, 0, 0.84999999999999998), textMayChange = 1)
     self.leveltext = PLocalizer.PotionGui['LevelLabel'] + str(self.level)
     if self.islandReq > 0:
         self.islandtext = PLocalizer.PotionGui['IslandName' + str(self.islandReq)]
     else:
         self.islandtext = PLocalizer.PotionGui['IslandName']
     if not self.enabled:
         self.levelColor = PiratesGuiGlobals.TextOV6
     elif not self.available:
         self.levelColor = PotionGlobals.TextColorDisabled
     else:
         self.levelColor = PotionGlobals.TextColor
     if not self.available:
         self.islandColor = PiratesGuiGlobals.TextOV6
     elif not self.enabled:
         self.islandColor = PotionGlobals.TextColorDisabled
     else:
         self.islandColor = PotionGlobals.TextColor
     if self.available and self.enabled:
         self.titleColor = PotionGlobals.TextColor
     else:
         self.titleColor = PotionGlobals.TextColorDisabled
     if self.title is not None:
         self.title.removeNode()
     
     self.title = DirectLabel(parent = self.background, relief = None, text = self.nameText, text_scale = PiratesGuiGlobals.TextScaleTitleSmall, text_align = TextNode.ACenter, text_fg = self.titleColor, text_wordwrap = 30, pos = (0.37, 0, 1.23), textMayChange = 0)
     if self.subtitle1 is not None:
         self.subtitle1.removeNode()
     
     self.subtitle1 = DirectLabel(parent = self.background, relief = None, text = self.leveltext, text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ARight, text_fg = self.levelColor, text_wordwrap = 30, pos = (0.34999999999999998, 0, 1.1799999999999999), textMayChange = 0)
     if self.subtitle2 is not None:
         self.subtitle2.removeNode()
     
     self.subtitle2 = DirectLabel(parent = self.background, relief = None, text = self.islandtext, text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ALeft, text_fg = self.islandColor, text_wordwrap = 30, pos = (0.39000000000000001, 0, 1.1799999999999999), textMayChange = 0)
     if self.subtitle3 is not None:
         self.subtitle3.removeNode()
     
     self.subtitle3 = DirectLabel(parent = self.background, relief = None, text = self.descText, text_scale = PiratesGuiGlobals.TextScaleMed, text_align = TextNode.ACenter, text_fg = self.titleColor, text_wordwrap = 30, pos = (0.37, 0, 1.1299999999999999), textMayChange = 0)
     self.stash()
class PotionGameBoard(DirectFrame):
    
    def __init__(self, potionGame):
        self.numColumns = 8
        self.numRows = 10
        DirectFrame.__init__(self, parent = potionGame.background, relief = None)
        cm = CardMaker('card')
        cm.setFrame(0, 0, 1.0, 1.0)
        self.background = self.attachNewNode(cm.generate())
        self.background.setColor(0.20000000000000001, 0.20000000000000001, 0.20000000000000001, 1)
        self.potionGame = potionGame
        self.pieceDropped = False
        self.pieceFlipped = False
        self.pieceNotDropped = False
        self.delayDropped = False
        self.experementMatched = False
        self.experementFailed = False
        self.initBoard()

    
    def initBoard(self):
        self.boardPieces = []
        ColumnList = range(self.numColumns)
        RowList = range(self.numRows)
        for columnIndex in ColumnList:
            self.boardPieces.append([])
            for rowIndex in RowList:
                self.boardPieces[columnIndex].append(None)
            
        
        self.rightPlayerPiece = None
        self.leftPlayerPiece = None
        self.leftPreviewPiece = None
        self.rightPreviewPiece = None
        self.lastLeftCol = 0
        self.lastRightCol = 1
        self.lastDragPos = None
        self.dragPiece = None

    
    def resetBoard(self):
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.removeNode()
                    del piece
                    continue
            
        
        if self.rightPlayerPiece is not None:
            self.rightPlayerPiece.removeNode()
        
        if self.leftPlayerPiece is not None:
            self.leftPlayerPiece.removeNode()
        
        if self.leftPreviewPiece is not None:
            self.leftPreviewPiece.removeNode()
        
        if self.rightPreviewPiece is not None:
            self.rightPreviewPiece.removeNode()
        
        del self.rightPlayerPiece
        del self.leftPlayerPiece
        del self.leftPreviewPiece
        del self.rightPreviewPiece
        self.initBoard()

    
    def jumpLeft(self):
        if self.leftPlayerPiece.column > 0:
            self.leftPlayerPiece.column -= 1
            self.leftPlayerPiece.setBoardPos(self.leftPlayerPiece.column, self.leftPlayerPiece.row)
            self.rightPlayerPiece.column -= 1
            self.rightPlayerPiece.setBoardPos(self.rightPlayerPiece.column, self.leftPlayerPiece.row)
        

    
    def jumpRight(self):
        if self.rightPlayerPiece.column < self.numColumns - 1:
            self.leftPlayerPiece.column += 1
            self.leftPlayerPiece.setBoardPos(self.leftPlayerPiece.column, self.leftPlayerPiece.row)
            self.rightPlayerPiece.column += 1
            self.rightPlayerPiece.setBoardPos(self.rightPlayerPiece.column, self.leftPlayerPiece.row)
        

    
    def moveLeft(self):
        if self.leftPlayerPiece.column > 0:
            self.disableInputEvents()
            self.potionGame.animationList.append(self.leftPlayerPiece.moveLeft())
            self.potionGame.animationList.append(self.rightPlayerPiece.moveLeft())
            self.potionGame.gameFSM.request('Anim')
        

    
    def moveRight(self):
        if self.rightPlayerPiece.column < self.numColumns - 1:
            self.disableInputEvents()
            self.potionGame.animationList.append(self.leftPlayerPiece.moveRight())
            self.potionGame.animationList.append(self.rightPlayerPiece.moveRight())
            self.potionGame.gameFSM.request('Anim')
        

    
    def moveUp(self):
        self.disableInputEvents()
        self.potionGame.animationList.append(self.leftPlayerPiece.moveRight())
        self.potionGame.animationList.append(self.rightPlayerPiece.moveLeft())
        temp = self.leftPlayerPiece
        self.leftPlayerPiece = self.rightPlayerPiece
        self.rightPlayerPiece = temp
        self.pieceFlipped = True
        self.potionGame.gameFSM.request('Anim')

    
    def moveDown(self):
        self.disableInputEvents()
        if self.boardPieces[self.leftPlayerPiece.column][self.leftPlayerPiece.row - 1] is None and self.boardPieces[self.rightPlayerPiece.column][self.rightPlayerPiece.row - 1] is None:
            self.boardPieces[self.leftPlayerPiece.column][self.leftPlayerPiece.row] = self.leftPlayerPiece
            self.boardPieces[self.rightPlayerPiece.column][self.rightPlayerPiece.row] = self.rightPlayerPiece
            self.checkFall(True)
            self.pieceDropped = True
            self.potionGame.currentRecipe.useTiles(2)
            self.potionGame.gameFSM.request('Anim')
            self.lastLeftCol = self.leftPlayerPiece.column
            self.lastRightCol = self.rightPlayerPiece.column
            self.rightPlayerPiece = None
            self.leftPlayerPiece = None
        else:
            self.pieceNotDropped = True
            self.leftPlayerPiece.setY(-5)
            self.rightPlayerPiece.setY(-5)
            self.potionGame.animationList.append(Sequence(Parallel(LerpPosInterval(self.leftPlayerPiece, duration = 0.10000000000000001, pos = (self.leftPlayerPiece.getX(), self.leftPlayerPiece.getY(), self.leftPlayerPiece.getZ() - 0.050000000000000003)), LerpPosInterval(self.rightPlayerPiece, duration = 0.10000000000000001, pos = (self.rightPlayerPiece.getX(), self.rightPlayerPiece.getY(), self.rightPlayerPiece.getZ() - 0.050000000000000003))), Parallel(LerpPosInterval(self.leftPlayerPiece, duration = 0.10000000000000001, pos = (self.leftPlayerPiece.getX(), self.leftPlayerPiece.getY(), self.leftPlayerPiece.getZ())), LerpPosInterval(self.rightPlayerPiece, duration = 0.10000000000000001, pos = (self.rightPlayerPiece.getX(), self.rightPlayerPiece.getY(), self.rightPlayerPiece.getZ()))), Func(self.leftPlayerPiece.setY, 0), Func(self.rightPlayerPiece.setY, 0)))
            self.potionGame.gameFSM.request('Anim')

    
    def checkFall(self, drop):
        for columnIndex in range(self.numColumns):
            for rowIndex in range(self.numRows - 1):
                if self.boardPieces[columnIndex][rowIndex] is None:
                    filled = False
                    for rowIndex2 in range(rowIndex + 1, self.numRows):
                        if self.boardPieces[columnIndex][rowIndex2] is not None and filled == False:
                            filled = True
                            self.boardPieces[columnIndex][rowIndex] = self.boardPieces[columnIndex][rowIndex2]
                            self.boardPieces[columnIndex][rowIndex2] = None
                            piece = self.boardPieces[columnIndex][rowIndex]
                            self.potionGame.animationList.append(Sequence(Func(piece.setY, -5), piece.moveToBoard(columnIndex, rowIndex), Func(piece.setY, 0)))
                            continue
                    
            
        

    
    def showSoulXP(self, Xloc, Zloc, count):
        xpAmt = PotionGlobals.BONUS_XP_AMT[count]
        xpLabel = DirectLabel(parent = aspect2d, relief = None, text = '+ ' + str(xpAmt) + ' ' + PLocalizer.PotionGui['XPLabel'], text_scale = PiratesGuiGlobals.TextScaleTitleLarge, text_font = PiratesGlobals.getPirateOutlineFont(), text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG1, text_shadow = PiratesGuiGlobals.TextShadow, text_wordwrap = 37, pos = (Xloc, 0, Zloc - 0.10000000000000001), textMayChange = 0)
        xpLabel.setTransparency(True)
        xpLabel.stash()
        return Sequence(Func(xpLabel.unstash), Parallel(LerpPosInterval(xpLabel, duration = 2.5, pos = (Xloc, 0.0, Zloc + 0.29999999999999999), blendType = 'easeOut'), LerpColorScaleInterval(xpLabel, duration = 1.5, colorScale = (1, 1, 1, 0), blendType = 'easeIn')), Func(xpLabel.removeNode))

    
    def findGroups(self):
        self.groups = []
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.findConnections(self)
                    continue
            
        
        self.removeList = []
        self.upgradeList = []
        for column in self.boardPieces:
            for piece in column:
                if piece is not None:
                    piece.pendingMatch = False
                    if len(piece.connections) > 0:
                        found = False
                        for group in self.groups:
                            if piece in group:
                                found = True
                                continue
                        
                        if not found:
                            self.groups.append([])
                            self.addToGroup(self.groups[-1], piece)
                        
                    
                len(piece.connections) > 0
            
        
        for group in self.groups:
            if len(group) > 2:
                group.sort(reverse = True)
                removePiece = group[0]
                self.removeList.append(removePiece)
                group.remove(removePiece)
                for piece in group:
                    if removePiece in piece.connections:
                        piece.connectionsRemoved += 1
                        continue
                
                group.sort(reverse = True)
                removePiece = group[0]
                self.removeList.append(removePiece)
                group.remove(removePiece)
                bonusPieces = 0
                avgX = 0
                avgZ = 0
                for piece in group:
                    if piece.level < 6:
                        self.upgradeList.append(piece)
                        if piece.level == 5:
                            self.potionGame.soulMade = True
                        
                    piece.level == 5
                    self.removeList.append(piece)
                    bonusPieces += 1
                    avgX += piece.getX(aspect2d)
                    avgZ += piece.getZ(aspect2d)
                
                if bonusPieces > 0:
                    avgX /= float(len(group))
                    avgZ /= float(len(group))
                    self.potionGame.soulMatch = True
                    self.potionGame.currentRecipe.clearedSouls(bonusPieces + 2)
                    self.potionGame.animationList.append(self.showSoulXP(avgX, avgZ, bonusPieces - 1))
                    self.potionGame.dist.d_claimXPBonus(bonusPieces - 1)
                
            bonusPieces > 0
        
        if len(self.removeList) > 0:
            self.previewGroups = []
            for column in self.boardPieces:
                for piece in column:
                    if piece is not None:
                        piece.previewConnections(self)
                        continue
                
            
            for column in self.boardPieces:
                for piece in column:
                    if piece is not None:
                        if len(piece.pendingConnections) > 0:
                            found = False
                            for group in self.previewGroups:
                                if piece in group:
                                    found = True
                                    continue
                            
                            if not found:
                                self.previewGroups.append([])
                                self.addToPreviewGroup(self.previewGroups[-1], piece)
                            
                        
                    len(piece.pendingConnections) > 0
                
            
            for group in self.previewGroups:
                if len(group) > 2:
                    for piece in group:
                        piece.pendingMatch = True
                    
            
            upgradeCount = len(self.upgradeList)
            self.potionGame.currentRecipe.madeIngredients(upgradeCount)
            self.removePieces()
            self.upgradePieces()
        

    
    def addToPreviewGroup(self, group, piece):
        group.append(piece)
        for nextPiece in piece.pendingConnections:
            if nextPiece not in group:
                self.addToPreviewGroup(group, nextPiece)
                continue
        

    
    def addToGroup(self, group, piece):
        group.append(piece)
        for nextPiece in piece.connections:
            if nextPiece not in group:
                self.addToGroup(group, nextPiece)
                continue
        

    
    def removePieces(self):
        for piece in self.removeList:
            self.boardPieces[piece.column][piece.row] = None
            mergePiece = None
            for adjPiece in piece.connections:
                if adjPiece in self.upgradeList:
                    mergePiece = adjPiece
                    continue
            
            if mergePiece is None:
                for adjPiece in piece.connections:
                    for adjadjPiece in adjPiece.connections:
                        if adjadjPiece in self.upgradeList:
                            mergePiece = adjadjPiece
                            continue
                    
                
            
            if mergePiece is not None:
                rotQuat = Quat()
                rotQuat.setHpr((piece.getH(), piece.getP() + 90, piece.getR()))
                outInterval = Parallel(LerpQuatInterval(piece.background, duration = 0.40000000000000002, quat = rotQuat, blendType = 'easeIn'), piece.moveToBoardSlow(mergePiece.column, mergePiece.row))
            else:
                outInterval = LerpColorInterval(piece.background, duration = 0.59999999999999998, color = (1, 1, 1, 0))
            self.potionGame.animationList.append(Sequence(Func(piece.setY, 5), outInterval, Func(piece.removeNode), Func(self.kill, piece)))
        

    
    def upgradePieces(self):
        for columnIndex in range(self.numColumns):
            for rowIndex in range(self.numRows - 1):
                if self.boardPieces[columnIndex][rowIndex] is None:
                    filled = False
                    for rowIndex2 in range(rowIndex + 1, self.numRows):
                        if self.boardPieces[columnIndex][rowIndex2] is not None and filled == False:
                            filled = True
                            piece = self.boardPieces[columnIndex][rowIndex2]
                            if not piece.pendingMatch:
                                self.boardPieces[columnIndex][rowIndex] = self.boardPieces[columnIndex][rowIndex2]
                                self.boardPieces[columnIndex][rowIndex2] = None
                                if piece in self.upgradeList:
                                    rotQuat = Quat()
                                    rotQuat2 = Quat()
                                    rotQuat3 = Quat()
                                    rotQuat.setHpr((piece.getH(), piece.getP() + 90, piece.getR()))
                                    rotQuat2.setHpr((piece.getH(), piece.getP() + 270, piece.getR()))
                                    rotQuat3.setHpr((piece.getH(), piece.getP() + 360, piece.getR()))
                                    self.potionGame.animationList.append(Sequence(Func(piece.setY, -10), LerpQuatInterval(piece.background, duration = 0.40000000000000002, quat = rotQuat, blendType = 'easeIn'), Func(piece.upgrade), Parallel(piece.moveToBoardSlow(columnIndex, rowIndex), LerpQuatInterval(piece.background, duration = 0.40000000000000002, quat = rotQuat3, startQuat = rotQuat2, blendType = 'easeOut')), Func(piece.setY, 0)))
                                    self.delayDropped = True
                                    self.upgradeList.remove(piece)
                                else:
                                    self.delayDropped = True
                                    self.potionGame.animationList.append(Sequence(Func(piece.setY, -5), Wait(0.5), piece.moveToBoard(columnIndex, rowIndex), Func(piece.setY, 0)))
                            
                    
            
        
        for piece in self.upgradeList:
            rotQuat = Quat()
            rotQuat2 = Quat()
            rotQuat3 = Quat()
            rotQuat.setHpr((piece.getH(), piece.getP() + 90, piece.getR()))
            rotQuat2.setHpr((piece.getH(), piece.getP() + 270, piece.getR()))
            rotQuat3.setHpr((piece.getH(), piece.getP() + 360, piece.getR()))
            piece.setY(-10)
            OutSeq = LerpQuatInterval(piece.background, duration = 0.40000000000000002, quat = rotQuat3, startQuat = rotQuat2, blendType = 'easeOut')
            self.potionGame.animationList.append(Sequence(LerpQuatInterval(piece.background, duration = 0.40000000000000002, quat = rotQuat, blendType = 'easeIn'), Func(piece.upgrade), OutSeq, Func(piece.setY, 0)))
        

    
    def kill(self, piece):
        del piece

    
    def handleMouseDown(self):
        if base.mouseWatcherNode.hasMouse():
            screenx = base.mouseWatcherNode.getMouseX()
            screeny = base.mouseWatcherNode.getMouseY()
            self.lastDragPos = self.getRelativePoint(render2d, (screenx, 0, screeny))
            self.dragDist = 0
        

    
    def handleMouseUp(self):
        dragHandled = False
        if self.lastDragPos is not None:
            if base.mouseWatcherNode.hasMouse():
                screenx = base.mouseWatcherNode.getMouseX()
                screeny = base.mouseWatcherNode.getMouseY()
                dragPos = self.getRelativePoint(render2d, (screenx, 0, screeny))
                self.dragDist += (dragPos - self.lastDragPos).length()
                if self.dragDist < 0.01:
                    if self.dragPiece is not None:
                        self.dragPiece.wrtReparentTo(self)
                        self.potionGame.animationList.append(Sequence(self.dragPiece.moveToBoard(self.dragPiece.column, self.dragPiece.row), Func(self.dragPiece.setY, 0)))
                        self.dragPiece = None
                    
                    if screenx > 0 and screeny > -0.80000000000000004 and screenx < 0.88 and screeny < 0.92000000000000004:
                        self.moveDown()
                    
                
                if self.dragPiece is not None:
                    if False:
                        recipePos = self.potionGame.currentRecipe.getRelativePoint(render2d, (screenx, 0, screeny))
                        neededIngredient = None
                        for ingredient in self.potionGame.currentRecipe.ingredients:
                            if ingredient.hiddenColor == self.dragPiece.colorIndex and ingredient.hiddenLevel == self.dragPiece.level and not (ingredient.completed):
                                neededIngredient = ingredient
                                continue
                        
                        if neededIngredient is not None:
                            for ingredient in self.potionGame.currentRecipe.ingredients:
                                if not (ingredient.completed) and not dragHandled:
                                    ingredientDist = (ingredient.getPos() - recipePos).length()
                                    if ingredientDist < 0.20000000000000001:
                                        neededIngredient.completed = True
                                        self.dragPiece.wrtReparentTo(self.potionGame.currentRecipe)
                                        self.boardPieces[self.dragPiece.column][self.dragPiece.row] = None
                                        self.lastDragPos = None
                                        self.potionGame.animationList.append(Sequence(self.dragPiece.moveToBoard(neededIngredient.column, neededIngredient.row), Func(neededIngredient.setColor, self.dragPiece.colorIndex, self.dragPiece.level), Func(self.killDragPiece)))
                                        dragHandled = True
                                        self.experementMatched = True
                                        self.potionGame.gameFSM.request('Anim')
                                    
                                ingredientDist < 0.20000000000000001
                            
                        else:
                            for ingredient in self.potionGame.currentRecipe.ingredients:
                                if not ingredient.completed:
                                    ingredientDist = (ingredient.getPos() - recipePos).length()
                                    if ingredientDist < 0.20000000000000001:
                                        self.experementFailed = True
                                    
                                ingredientDist < 0.20000000000000001
                            
                    
                
                if self.dragPiece is not None and not dragHandled:
                    self.dragPiece.wrtReparentTo(self)
                    self.potionGame.animationList.append(Sequence(self.dragPiece.moveToBoard(self.dragPiece.column, self.dragPiece.row), Func(self.dragPiece.setY, 0)))
                    self.potionGame.gameFSM.request('Anim')
                    self.dragPiece = None
                
                self.lastDragPos = None
            
        

    
    def killDragPiece(self):
        self.dragPiece.removeNode()
        del self.dragPiece
        self.dragPiece = None

    
    def enableInputEvents(self):
        self.accept('mouse1', self.handleMouseDown)
        self.accept('mouse1-up', self.handleMouseUp)
        self.accept('mouse3', self.moveUp)
        self.accept('space', self.moveUp)
        taskMgr.add(self.handleMouseLoc, 'PotionMinigameMouseInputTask')

    
    def disableInputEvents(self):
        self.ignore('j')
        self.ignore('l')
        self.ignore('k')
        self.ignore('i')
        self.ignore('mouse1')
        self.ignore('mouse1-up')
        self.ignore('mouse3')
        self.ignore('space')
        taskMgr.remove('PotionMinigameMouseInputTask')

    
    def handleMouseLoc(self, task):
        if base.mouseWatcherNode.hasMouse():
            screenx = base.mouseWatcherNode.getMouseX()
            screeny = base.mouseWatcherNode.getMouseY()
            localMousePos = self.getRelativePoint(render2d, (screenx, 0, screeny))
            if self.lastDragPos is None and self.leftPlayerPiece is not None and self.rightPlayerPiece is not None:
                if localMousePos[0] < self.leftPlayerPiece.Xpos:
                    self.jumpLeft()
                
                if localMousePos[0] > self.rightPlayerPiece.Xpos:
                    self.jumpRight()
                
            elif self.lastDragPos is not None:
                self.dragDist += (localMousePos - self.lastDragPos).length()
                self.lastDragPos = localMousePos
                if self.dragDist > 0.01 and self.dragPiece is not None:
                    globalMousePos = self.potionGame.background.getRelativePoint(render2d, (screenx, 0, screeny))
                    self.dragPiece.setPiecePosition(globalMousePos[0], globalMousePos[2])
                
            
        
        return Task.cont

    
    def playerPieceActive(self):
        if self.rightPlayerPiece is not None:
            pass
        return self.leftPlayerPiece is not None

    
    def checkAvailableMoves(self):
        movesLeft = False
        for columnIndex in range(self.numColumns - 1):
            if self.boardPieces[columnIndex][self.numRows - 2] is None and self.boardPieces[columnIndex + 1][self.numRows - 2] is None:
                movesLeft = True
                continue
        
        return movesLeft

    
    def addNewPiece(self):
        currentRecipe = self.potionGame.currentRecipe
        if self.leftPreviewPiece is None:
            self.leftPreviewPiece = PotionBoardPiece(self, recipe = currentRecipe)
            self.rightPreviewPiece = PotionBoardPiece(self, recipe = currentRecipe)
            self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
            self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
        
        self.leftPlayerPiece = self.leftPreviewPiece
        self.rightPlayerPiece = self.rightPreviewPiece
        self.leftPreviewPiece = PotionBoardPiece(self, colorSet = self.potionGame.dist.colorSet, recipe = currentRecipe)
        self.rightPreviewPiece = PotionBoardPiece(self, colorSet = self.potionGame.dist.colorSet, recipe = currentRecipe)
        self.leftPreviewPiece.setBoardPos(-4, self.numRows - 1)
        self.rightPreviewPiece.setBoardPos(-3, self.numRows - 1)
        self.leftPlayerPiece.setY(-5)
        self.leftPlayerPiece.reparentTo(self)
        self.rightPlayerPiece.setY(-5)
        self.rightPlayerPiece.reparentTo(self)
        self.leftPlayerPiece.moveFast = True
        self.rightPlayerPiece.moveFast = True
        self.potionGame.animationList.append(Sequence(self.leftPlayerPiece.moveToBoard(self.lastLeftCol, self.numRows - 1), Func(self.leftPlayerPiece.setY, 0)))
        self.potionGame.animationList.append(Sequence(self.rightPlayerPiece.moveToBoard(self.lastRightCol, self.numRows - 1), Func(self.rightPlayerPiece.setY, 0)))