Exemplo n.º 1
0
    def inputButtonClicked(self):
        text = self.inputScores.toPlainText().strip()
        if text == "":
            return

        try:
            b64 = bytes(text, encoding='utf8')
            decoded = scores_decode(b64).decode('utf-8')
            scores = json.loads(decoded)
        except:
            errorDialog(self, "Error", message="Failed to decode high scores")
            return

        scores_msg = "The string you added contains the following scores:<br><br>"
        scores_msg += "<br>".join(['%s (%s)' % (x[0], x[1]) for x in scores])
        scores_msg += "<br><br>"
        scores_msg += "Are you sure you want to add them to your high scores?"

        proceed = yesNoDialog(self, "Add scores?", message=scores_msg)
        if not proceed:
            return

        for name, score in scores:
            config.add_highscore(name, score)

        infoDialog(self, "Success", "Scores added successfully")
Exemplo n.º 2
0
    def allButtonClicked(self):
        proceed = yesNoDialog(
            self,
            "Are you sure?",
            message="Are you sure you want to destroy all planets for {0:,}? "
            "All planets except for the one you are currently "
            "on will cease to exist, and all tradeable items "
            "that currrently exist on those planets will be "
            "shipped to your warehouse.".format(self.all_planets_cost))
        if not proceed:
            return

        self.accepted = True
        planets_to_destroy = [
            p for p in self.state.planets
            if id(p) != id(self.state.current_planet)
        ]

        planets_to_destroy = self.handlePlanetResistance(planets_to_destroy)
        if not planets_to_destroy:
            return

        for p in planets_to_destroy:
            self.state.warehouse.add_all_items(p.items)

        self.state.planets = [
            p for p in self.state.planets if p not in planets_to_destroy
        ]
        self.final_price = self.all_planets_cost

        self.close()

        infoDialog(self.parent,
                   "Success",
                   message="Your destruction of all planets is complete.")
    def introduceNewItem(self, itemname):
        quantity = self.parent.state.items.items[itemname].quantity
        rand_quantity = random.randrange(*const.ITEM_SAMPLE_QUANTITY_RANGE)
        planet = self.parent.state.current_planet

        if quantity <= rand_quantity:
            rand_quantity = max(1, int(quantity / 2))

        msg = (
            "{0} has never been seen on {1}, and you will have to persuade them "
            "that it is worth buying. If you provide a free sample of {2} {0}, "
            "this may help your cause.<br><br>Provide a free sample of "
            "{2} {0}?".format(itemname, planet.full_name, rand_quantity))

        proceed = yesNoDialog(self, "Provide sample?", message=msg)
        if not proceed:
            return

        if itemname in planet.samples_today:
            errorDialog(
                self,
                "Already sampled today",
                message="%s has already sampled %s today, try again on "
                "a different day" % (planet.full_name, itemname))
            return

        planet.samples_today.append(itemname)

        # Add new items to planet-- we might remove them in a sec, but this
        # also handles deleteing them from the player's items, so, meh
        planet.items.add_items(itemname, self.parent.state.items,
                               rand_quantity)
        self.parent.updatePlayerItemsLabel()
        self.update()

        successful = random.randrange(0,
                                      100) < const.ITEM_SAMPLE_SUCCESS_PERCENT
        if successful:
            # Sample succesful, update planet item browser to show new item we added
            self.parent.planetItemBrowser.update()

            # Reset item's value history
            item = planet.items.items[itemname]
            item.value_history = [item.value]

            title = "Good news!"
            msg = ("Your sample achieved its intended purpose! "
                   "%s is now actively trading in %s." %
                   (planet.full_name, itemname))
        else:
            # Sample unsuccessful, delete items from planet
            planet.items.remove_items(itemname, rand_quantity)
            title = "Bad news!"
            msg = (
                "Your sample was not well received, and %s has decided not to "
                "trade in %s." % (planet.full_name, itemname))

        infoDialog(self, title, message=msg)
Exemplo n.º 4
0
 def advanceDay(self):
     if self.state.next_day():
         # Days remaining
         self.runRandomNotifications()
         self.state.update_planet_item_prices()
         self.infoBar.update()
         self.planetItemBrowser.update()
     else:
         # No days remaining
         infoDialog(self, "Game complete", message="Time is up!")
         self.checkHighScore()
         self.reset()
    def dayButtonClicked(self):
        if self.parent.state.next_day():
            # Days remaining
            self.parent.infoBar.update()
            self.parent.planetItemBrowser.update()
        else:
            # No days remaining
            infoDialog(self, "Game complete", message="You are done")

            self.checkHighScore()

            self.parent.reset()
Exemplo n.º 6
0
    def use(self, parent):
        if not yesNoDialog(
                parent,
                "Are you sure?",
                message="Are you sure want to increase your capacity?"):
            return False

        parent.state.capacity += const.CAPACITY_INCREASE
        parent.infoBar.update()

        infoDialog(parent,
                   "Success",
                   message="Capacity successfully increased. "
                   "New capacity is %d" % parent.state.capacity)
        return True
Exemplo n.º 7
0
    def use(self, parent):
        if not yesNoDialog(
                parent,
                "Are you sure?",
                message="Are you sure want to buy the long range scanner?"):
            return False

        parent.state.scanner_unlocked = True
        #To Do add in long range ui in parent.infoBar.update()
        parent.infoBar.update()
        #To Do change radiologist
        infoDialog(parent,
                   "Success",
                   message="Long Range Scanner unlocked,"
                   "assign a crew member with the Radiology skill to it.")

        return True
Exemplo n.º 8
0
    def use(self, parent):
        if not yesNoDialog(
                parent,
                "Are you sure?",
                message="Are you sure you want to buy a %s" % self.name):
            return

        num_new = random.randrange(*const.PLANET_DISCOVERY_RANGE)
        parent.state.expand_planets(num_new)

        new_names = [p.full_name for p in parent.state.planets[-num_new:]]
        name_listing = '<br>'.join(new_names)

        infoDialog(
            parent, "%d new planets with intelligent life have "
            "been discovered!<br><br>%s" % (num_new, name_listing))

        parent.infoBar.update()
        parent.locationBrowser.update()
        return True
    def selectButtonClicked(self):
        selectedRow = self.table.currentRow()
        if selectedRow < 0:
            errorDialog(self,
                        message="Please select a planet to travel to first!")
            return

        planet = self.parent.state.planets[selectedRow]

        if self.parent.state.current_planet.full_name == planet.full_name:
            errorDialog(self,
                        message="You are currently on %s, you cannot "
                        "destroy a planet that you are on" % planet.full_name)
            return

        proceed = yesNoDialog(self,
                              "Are you sure?",
                              message="Are you sure you want to destroy the "
                              "planet {0}? {0} will cease to exist, and "
                              "all tradeable items that currrently exist "
                              "on {0} will be shipped to your "
                              "warehouse.".format(planet.full_name))
        if not proceed:
            return

        self.parent.state.warehouse.add_all_items(planet.items)
        del self.parent.state.planets[selectedRow]

        self.parent.infoBar.update()
        self.parent.locationBrowser.update()
        self.parent.warehouseItemBrowser.update()
        self.parent.infoBar.update()
        self.close()
        self.accepted = True

        infoDialog(self.parent,
                   "Success",
                   message="Your destruction of %s is complete." %
                   planet.full_name)
Exemplo n.º 10
0
    def handlePlanetResistance(self, planets_to_destroy):
        successful = True
        resisting_planet = self.checkForResistingPlanet(planets_to_destroy)
        if resisting_planet is None:
            return planets_to_destroy

        resisting_planet.resists_destruction = True

        msg = (
            "Planet {0} is resisting destruction! A battle fleet from {0} has been "
            +
            "dispatched, and is prepared to defend the planet if you try to destroy it. "
            +
            "You must defeat them if you want to continue with the destruction of {0}. "
        ).format(resisting_planet.full_name)

        if self.state.battle_level == 0:
            msg += "<br><br>Since you have no battle fleet, your chances of victory are slim. "

        msg += "<br><br>Do you want to fight?"

        proceed = yesNoDialog(self, "Planet is resisting!", msg)
        if not proceed:
            infoDialog(
                self.parent,
                "Chickened out!",
                message="You have declined to fight %s. They win, this time." %
                resisting_planet.full_name)

            # Remove resisting planet from list of planets to destroy
            return [
                p for p in planets_to_destroy if id(p) != id(resisting_planet)
            ]

        if self.state.battle_won():
            infoDialog(self.parent,
                       "Victory!",
                       message="You have defeated %s!" %
                       resisting_planet.full_name)
        else:
            infoDialog(self.parent,
                       "Defeat!",
                       message="You have been defeated in battle by %s."
                       "<br><br><br>You are dead :(" %
                       resisting_planet.full_name)
            planets_to_destroy = None
            self.died = True
            self.close()
            return []

        return planets_to_destroy
Exemplo n.º 11
0
    def runRandomNotifications(self):
        if self.pending_price_anomaly is not None:
            planet, itemname, increase = self.pending_price_anomaly
            self.pending_price_anomaly = None

            if random.randint(0, 100) <= const.TRADING_TIP_ACCURACY_PERCENTAGE:
                if itemname in planet.items.items:
                    item = planet.items.items[itemname]

                    self.temporary_price_change = (planet, itemname,
                                                   item.value)
                    old_value = item.value
                    if increase:
                        # Increase price by 100-500%
                        change_percentage = random.randint(200, 500)
                        item.value += int((float(item.value) / 100.0) *
                                          float(change_percentage))
                    else:
                        # Decrease price by 70-90%
                        change_percentage = random.randint(80, 95)
                        item.value -= int((float(item.value) / 100.0) *
                                          float(change_percentage))

                    if planet is self.state.current_planet:
                        infoDialog(
                            self, "Rumour was true!",
                            "The rumour you heard about %s was true!<br><br>%s prices are %s."
                            % (itemname, itemname, "through the roof"
                               if increase else "at an all-time low"))
            else:
                if planet is self.state.current_planet:
                    infoDialog(
                        self, "Rumour was false",
                        "The rumour you heard about %s on %s was false!" %
                        (itemname, planet.full_name))

            return

        if self.temporary_price_change is not None:
            planet, itemname, old_value = self.temporary_price_change
            self.temporary_price_change = None

            if itemname in planet.items.items:
                planet.items.items[itemname].value = old_value

        if random.randint(0, 100) > const.CHANCE_TRADING_TIP_PERCENTAGE:
            # Nothing to do this time
            return

        # Pick a random planet
        planet = random.choice(self.state.planets)

        # Pick a random item on that planet
        itemname = random.choice(list(planet.items.items.keys()))
        item = planet.items.items[itemname]

        # Will the price increase or decrease?
        increase = random.randint(0, 100) >= 50

        adj = random.choice(["very", "extremely", "unreasonably", "unusually"])
        descriptor = "expensive" if increase else "cheap"

        msg = ("You hear a rumour that %s will be %s %s on %s tomorrow!" %
               (itemname, adj, descriptor, planet.full_name))

        infoDialog(self, "Rumour overheard!", msg)
        self.pending_price_anomaly = (planet, itemname, increase)
    def travelToPlanet(self, planetname):
        if self.parent.state.current_planet.full_name == planetname:
            errorDialog(self, message="You are already on %s!" % planetname)
            return

        if self.parent.state.money < self.parent.state.travel_cost:
            errorDialog(self,
                        message="You don't have enough money! (%d required)" %
                        self.parent.state.travel_cost)
            return

        accepted = yesNoDialog(
            self, "Travel",
            "Travel to {0}?<br><br>(cost is {1:,}, you have {2:,})".format(
                planetname, self.parent.state.travel_cost,
                self.parent.state.money))
        if not accepted:
            return

        self.parent.state.money -= self.parent.state.travel_cost

        if random.randint(
                0,
                100) <= self.parent.state.chance_of_being_robbed_in_transit():
            accepted = yesNoDialog(
                self, "Attacked by pirates!",
                "You have encountered a pirate fleet while travelling " +
                "between planets!<br><br>Your battle fleet must defeat them if "
                +
                "you want to continue.<br><br>If you do not fight, then the only other "
                +
                "option is surrender; you will not die, but you may lose some of "
                + "your money and resources.<br><br>Do you want to fight?")
            if accepted:
                if self.parent.state.battle_won():
                    infoDialog(
                        self, "Battle won!",
                        "You have defeated the pirate fleet, " +
                        "and can continue with your travels.")
                else:
                    infoDialog(
                        self, "Battle lost!",
                        "You have been defeated by the pirate fleet." +
                        "<br><br>You are dead.")
                    self.parent.reset()
                    return
            else:
                if (self.parent.state.items.count()
                        == 0) or (random.randint(0, 100) >= 80):
                    # take 95-99% percent of players money
                    percent_to_take = random.randint(95, 99)
                    money_to_take = (float(self.parent.state.money) /
                                     100.0) * percent_to_take
                    self.parent.state.money -= int(money_to_take)

                self.parent.state.items.remove_all_items()
                self.parent.playerItemBrowser.update()
                self.parent.infoBar.update()

                infoDialog(
                    self, "Surrender",
                    "You decide not to fight the pirate fleet. " +
                    "<br><br>The pirates spare your life, but they rob you of everything you've got!"
                )

        self.parent.state.change_current_planet(planetname)
        self.parent.advanceDay()

        currentRow = self.table.currentRow()
        self.update()
        self.table.selectRow(currentRow)

        self.parent.planetItemBrowser.update()
        self.parent.infoBar.update()