コード例 #1
0
def BuyItem_ByID(ItemID):
    ItemID = int(ItemID)
    ItemPrice = gameItems.GetItemPrice_ByID(ItemID)
    ItemCount = gameItems.GetItemCount_ByID(ItemID)
    ItemIsUnlocker = gameItems.GetItemIsUnlocker_ByID(ItemID)
    BuySucefully = False

    if ItemIsUnlocker:  # -- Buy Unlocker Items
        if not ItemCount >= 1:
            # -- Increase Item Count -- #
            gameItems.IncreaseItemCount_ByID(ItemID)

            # -- Create Item Object -- #
            gameItems.CreateItemObject(ItemID)

            BuySucefully = True

    else:  # -- Buy Common Items -- #
        gameItems.IncreaseItemCount_ByID(ItemID)

        # -- Create Item Object -- #
        gameItems.CreateItemObject(ItemID)

        BuySucefully = True

    if BuySucefully:
        # -- Subtract the Money -- #
        IncomingLog.AddMessageText(utils.FormatNumber(-ItemPrice, 2), True, (250, 150, 150), -ItemPrice)

        # -- Add Item to the Item View on Game Screen -- #
        GameScreen.ItemsView.AddItem(str(ItemID))
    else:
        # -- Subtract the Money -- #
        IncomingLog.AddMessageText(gameMain.DefaultCnt.Get_RegKey("/strings/window/store/cant_buy_item"), False, (250, 150, 150))
        sound.PlaySound("/hit_2.wav", 0.5)
コード例 #2
0
def Update():
    global DownBar_BuyPanelYOffset
    global DownBar_BuyPanelAnimEnabled
    global DownBar_BuyPanelYOffsetAdder
    global BuyAmout
    global LastItemIDSelected
    global SelectedItemPrice
    global SelectedItemID
    global LastClickedItem

    if ListItems.LastItemClicked != "null":
        if LastClickedItem != ListItems.LastItemClicked:
            DownBar_BuyPanelAnimEnabled = True
            DownBar_BuyPanelYOffset = 0
            LastClickedItem = ListItems.LastItemClicked

        # -- Set Item Price and ID -- #
        SelectedItemID = ListItems.LastItemOrderID
        SelectedItemPrice = gameItems.GetItemPrice_ByID(SelectedItemID)

    # -- Set the Buy Button Location -- #
    BuyButton.Set_X(WindowObject.WindowRectangle[2] - BuyButton.Rectangle[2] - 5)
    BuyButton.Set_Y(WindowObject.WindowRectangle[3] - BuyButton.Rectangle[3] - DownBar_BuyPanelYOffset + 5)

    # -- Set the Buy Button Collision -- #
    BuyButton.Set_ColisionX(WindowObject.WindowRectangle[0] + BuyButton.Rectangle[0])
    BuyButton.Set_ColisionY(WindowObject.WindowRectangle[1] + BuyButton.Rectangle[1] + BuyButton.Rectangle[3])

    # -- Update Buy Button -- #
    if BuyButton.ButtonState == 2:
        if save.Current_Money >= SelectedItemPrice:  # -- If you can buy the Item -- #
            BuyItem_ByID(SelectedItemID)

        else:  # -- Notify that you can't buy that item
            IncomingLog.AddMessageText(gameMain.DefaultCnt.Get_RegKey("/strings/window/store/cant_buy_item"), False, (250, 150, 150))
            gameMain.DefaultCnt.PlaySound("/hit_2.wav", 0.5)

    # -- Update the Items List -- #
    ListItems.Set_W(DrawnSurface.get_width())
    ListItems.Set_H(DrawnSurface.get_height())
    ListItems.ColisionXOffset = WindowObject.WindowRectangle[0]
    ListItems.ColisionYOffset = WindowObject.WindowRectangle[1] + 20

    # -- Update Buy Panel Animation -- #
    if DownBar_BuyPanelAnimEnabled:
        DownBar_BuyPanelYOffsetAdder += 1
        DownBar_BuyPanelYOffset += DownBar_BuyPanelYOffsetAdder

        if DownBar_BuyPanelYOffset >= 30:
            DownBar_BuyPanelYOffset = 30
            DownBar_BuyPanelAnimEnabled = False
            DownBar_BuyPanelYOffsetAdder = 0