Esempio n. 1
0
    async def _cities(self, *args):
        if len(args) == 0:
            raise commands.CommandError("no country input")
        try:
            country = pn.find_country(args[0])
        except KeyError:
            raise commands.CommandError("invalid country")

        ret = [f"{g.name} ({g.dict['Annual Passengers']})" for g in country.cities]
        return await Navigator(plane, ret, 6, "List of airports in " + country.name + " [{page}/{pgs}]").run(self.ctx)
Esempio n. 2
0
    async def _buyout(self, *args):
        if len(args) == 0:
            raise commands.CommandError("no country input")
        try:
            country = pn.find_country(args[0])
        except KeyError:
            raise commands.CommandError(f"invalid country ``{args[0]}``")

        assert isinstance(country, pn.Country)
        if country.name not in self.user.countries:
            return await plane.send(self.ctx, f"You don't have the license to {country.name}.")

        if len(args) > 1:
            try:
                stop_at = int(args[1])
            except ValueError:
                stop_at = len(country.cities)
        else:
            stop_at = len(country.cities)

        bought, price, total = [], 0, True
        for city in country.cities:
            if sum([g.value for g in bought] + [city.value]) > self.user.credits or len(bought) == stop_at:
                if not bought:
                    return await plane.send(self.ctx, f"You can't afford the biggest airport in {country.name}.")
                total = False
                break

            if city.name not in self.user.cities:
                bought.append(city)
                price += city.value

        if not bought:
            return await plane.send(self.ctx, f"You already own every airport in {country.name}.")

        confirm_text = "every airport" if total else f"the {len(bought)} biggest airports"
        try:
            assert await confirm(
                f"You're buying {confirm_text} in {country.name} for Ȼ{pn.addcomm(price)}.", self.ctx, self.au
            )
        except AssertionError:
            return await plane.send(self.ctx, "Purchase cancelled.")

        for i in bought:
            self.user.cities.append(i.name)
        self.user.credits -= price
        return await succ.send(self.ctx, f"Airports purchased!")
Esempio n. 3
0
    async def _unowned(self, *args):
        if len(args) == 0:
            raise commands.CommandError("no country input")
        try:
            country = pn.find_country(args[0]).name
        except KeyError:
            raise commands.CommandError("invalid country")

        ret = [g for g in pn.cities.values() if g.country == country
               and g.name not in self.user.cities]
        cost = int(sum([g.value for g in ret]))
        ret = [f"{g.name} (Ȼ{pn.addcomm(g.value)})" for g in sorted(ret, key=lambda c: c.value, reverse=True)]

        return await Navigator(
            plane, ret, 6, "Unowned airports in " + country + " [{page}/{pgs}]",
            footer=f"cost of all airports: Ȼ{pn.addcomm(cost)}"
        ).run(self.ctx)
Esempio n. 4
0
    async def _jobs(self, *args):
        if len(args) == 0:
            return await plane.send(self.ctx, "no city input")
        try:
            city = pn.find_city(args[0])
        except KeyError:
            raise commands.CommandError(self.invalid_city(args[0]))

        tm = time.time()
        if tm - city.job_reset >= 900 or len(city.jobs) == 0:
            print(f"generating jobs for {city.name}")
            city.rpj()  # only rpj city when called

        fil = lambda j: j.destination.name in self.user.cities
        fil_str = "J"
        if len(args) > 1 and args[1].lower() == "all":
            fil = lambda j: True
            fil_str = "All j"
        elif len(args) > 1 and args[1].lower() == "to":
            if len(args) == 2:
                raise commands.CommandError("to where?")

            try:
                fil = lambda j: j.destination.country == pn.find_country(args[2].lower()).name
                fil_str = f"{pn.find_country(args[2].lower()).name} j"
            except KeyError:
                try:
                    fil = lambda j: j.destination.name == pn.find_city(args[2].lower()).name
                    fil_str = f"{pn.find_city(args[2].lower()).name} j"
                except KeyError:
                    raise commands.CommandError("invalid location")

        reset = tm // 900 * 900
        if tm - city.job_reset >= 900:
            city.job_reset = reset

        await JobNavigator(
            self, city, fil, fil_str,
            footer=f"new jobs in {self.form_et(((tm // 900 + 1) * 900 - tm) // 60)} min"
        ).run(self.ctx)
Esempio n. 5
0
    async def _country(self, *args):
        if len(args) == 0:
            raise commands.CommandError("Please input a country.")
        if args[0].lower() == "buy":
            if len(args) == 1:
                raise commands.CommandError("no country input")
            args = args[1], args[0], *args[2:]

        try:
            country = pn.find_country(args[0])
        except KeyError:
            raise commands.CommandError("invalid country")

        assert isinstance(country, pn.Country)
        if len(args) > 1 and args[1].lower() == "buy":
            if country.name in self.user.countries:
                raise commands.CommandError("country already owned")

            price = round(country.worth)
            if price > self.user.credits:
                raise commands.CommandError("not enough credits")

            if await confirm(f"You're buying the {country.name} license for Ȼ{pn.addcomm(price)}.", self.ctx, self.au):
                self.user.credits -= price
                self.user.countries.append(country.name)
                return await succ.send(self.ctx, "License purchased!")

            return await plane.send(self.ctx, "Purchase cancelled.")

        owned = len([g for g in pn.cities.values() if g.country == country.name
                     and g.name in self.user.cities])
        return await plane.send(
            self.ctx, country.name, same_line=True,
            fs={"Traffic": pn.suff(sum([g.passengers for g in country.cities])),
                "Cities": f"{len(country.cities)} ({owned} owned)",
                "License Value": f"Ȼ{pn.addcomm(country.worth)}",
                "Owned": ["No", "Yes"][country.name in self.user.countries],
                "Flag": f":flag_{pn.planemojis[country.name]}:"}
        )