Exemplo n.º 1
0
    def __format__(self, spec):
        if self.is_infinite():
            return self.sign + "∞"

        value = self
        rounded = value

        dSpec = DecimalSpec.parse(spec)

        fractional = dSpec.fractional
        dSpec.fractional = None

        accuracy = dSpec.accuracy
        dSpec.accuracy = None

        precision = 2
        if dSpec.precision is not None:
            precision = int(dSpec.precision)

        if (Decimal("10") ** -(precision + 1)) < abs(value) < Decimal("1e10") or value == 0:
            dSpec.type = "f"
            dSpec.precision = None
            if fractional:
                try:
                    denom = int(fractional[1])
                except IndexError:
                    denom = 8
                rounded = roundFraction(value, denom)
            else:
                rounded = round(value, precision)
        else:
            dSpec.type = "e"
            dSpec.precision = str(precision)

        numspec = str(dSpec)
        if fractional:
            whole = rounded.to_integral_value(ROUND_DOWN)
            rawwhole = fixZeroes(whole._rawvalue)
            formatted = format(rawwhole, numspec)
            part = abs(whole - rounded)
            fraction = formatFraction(part)
            if fraction:
                if formatted == "0":
                    formatted = ""
                formatted += fraction
        else:
            rawvalue = fixZeroes(rounded._rawvalue)
            formatted = format(rawvalue, numspec)

        if dSpec.type == "f":
            if accuracy:
                try:
                    roundamount = int(accuracy[1])
                except IndexError:
                    roundamount = 0
                small, big = minmax(rounded, value)
                printacc = round((abs(small / big) * 100), roundamount)
                formatted += f" (~{printacc}% accurate)"

        return formatted
Exemplo n.º 2
0
    def __init__(self, userdata1, userdata2):
        smallUserdata, bigUserdata = utils.minmax(userdata1, userdata2)
        self.big = PersonStats(bigUserdata)
        self.small = PersonStats(smallUserdata)
        self.multiplier = self.big.height / self.small.height

        bigToSmallUserdata = userdb.User()
        bigToSmallUserdata.height = bigUserdata.height * self.small.viewscale
        self.bigToSmall = PersonStats(bigToSmallUserdata)

        smallToBigUserdata = userdb.User()
        smallToBigUserdata.height = smallUserdata.height * self.big.viewscale
        self.smallToBig = PersonStats(smallToBigUserdata)

        viewangle = calcViewAngle(self.small.height, self.big.height)
        self.lookangle = abs(viewangle)
        self.lookdirection = "up" if viewangle >= 0 else "down"
Exemplo n.º 3
0
    def __init__(self, userdata1, userdata2):
        self._viewer, self._viewed = minmax(userdata1, userdata2)

        self.viewer = PersonStats(self._viewer)
        self.viewed = PersonStats(self._viewed)

        self.viewertovieweddata = copy(self._viewer)
        self.viewedtoviewerdata = copy(self._viewed)

        if self.viewer.height == 0 and self.viewed.height == 0:
            self.multiplier = Decimal(1)
        else:
            self.multiplier = self.viewed.height / self.viewer.height

        self.viewedtoviewer = PersonStats(self.viewedtoviewerdata)
        self.viewertoviewed = PersonStats(self.viewertovieweddata)

        self.footlabel = "Paw" if self.viewed.pawtoggle else "Foot"
        self.hairlabel = "Fur" if self.viewed.furtoggle else "Hair"

        viewangle = calcViewAngle(self.viewer.height, self.viewed.height)
        self.lookangle = abs(viewangle)
        self.lookdirection = "up" if viewangle >= 0 else "down"
Exemplo n.º 4
0
    def __init__(self, userdata1, userdata2):
        smallUserdata, bigUserdata = utils.minmax(userdata1, userdata2)
        self.big = PersonStats(bigUserdata)
        self.small = PersonStats(smallUserdata)

        bigToSmallUserdata = copy(bigUserdata)
        smallToBigUserdata = copy(smallUserdata)

        if bigUserdata.height == 0 and smallUserdata.height == 0:
            self.multiplier = Decimal(1)
        else:
            self.multiplier = bigUserdata.height / smallUserdata.height
            bigToSmallUserdata.height = bigUserdata.height * smallUserdata.viewscale
            smallToBigUserdata.height = smallUserdata.height * bigUserdata.viewscale

        self.bigToSmall = PersonStats(bigToSmallUserdata)
        self.smallToBig = PersonStats(smallToBigUserdata)

        self.footlabel = "Foot/Paw" if bigUserdata.pawtoggle or smallUserdata.pawtoggle else "Foot"
        self.hairlabel = "Hair/Fur" if bigUserdata.furtoggle or smallUserdata.furtoggle else "Hair"

        viewangle = calcViewAngle(smallUserdata.height, bigUserdata.height)
        self.lookangle = abs(viewangle)
        self.lookdirection = "up" if viewangle >= 0 else "down"
Exemplo n.º 5
0
    async def _run_event(self, event: Event, playerpool: Dict[str,
                                                              Player]) -> dict:
        """Runs an event, returning the string describing what happened and an image."""
        if event.tributes > len(playerpool):
            raise GametimeError("Not enough players to run this event!")
        players = event.get_players(playerpool)

        eventtext = event.fillin(players)
        deaths = []

        logger.log(ROYALE, "[EVENT] " + eventtext)

        def player_by_id(pid):
            return self.players[players.getByIndex(pid - 1).name]

        if event.elims is not None:
            for i in event.elims:
                player_by_id(i).dead = True
                deaths.append(player_by_id(i))

        if event.perps is not None:
            for i in event.perps:
                player_by_id(i).elims += 1

        if event.gives is not None:
            for i, s in event.gives:
                player_by_id(i).give_item(s)

        if event.removes is not None:
            for i, s in event.removes:
                player_by_id(i).remove_item(s)

        if event.clears is not None:
            for i in event.clears:
                player_by_id(i).clear_inventory()

        if event.giveattrs is not None:
            for i, s in event.giveattrs:
                player_by_id(i).give_attribute(s)

        if event.removeattrs is not None:
            for i, s in event.removeattrs:
                player_by_id(i).remove_attribute(s)

        if event.setsizes is not None:
            for i, d in event.setsizes:
                player_by_id(i).height = SV(d)

        if event.sizes is not None:
            for i, d in event.sizes:
                player_by_id(i).change_height(d)

        if event.setsizeranges is not None:
            for i, d1, d2 in event.setsizeranges:
                small, large = minmax(d1, d2)
                d = randRangeLog(small, large)
                player_by_id(i).height = SV(d)

        if event.sizeranges is not None:
            for i, d1, d2 in event.sizeranges:
                da = randRangeLog(d1.amount, d2.amount)
                if d1.changetype == "add":
                    ds = "+"
                elif d1.changetype == "multiply":
                    ds = "x"
                else:
                    raise ThisShouldNeverHappenException
                do = ds + da
                d = Diff(do, changetype=d1.changetype, amount=da)
                player_by_id(i).change_height(d)

        if len(players) == 0:
            eventimage = None
        else:
            eventimage = merge_images(
                [await self.players[p].get_image() for p in players])

        return RunnableEvent(text=eventtext,
                             image=eventimage,
                             players=players,
                             deaths=deaths)
Exemplo n.º 6
0
def test_minmax_same():
    assert utils.minmax(20, 20) == (20, 20)
Exemplo n.º 7
0
def test_minmax_incorrect():
    assert utils.minmax(20, 10) == (10, 20)
Exemplo n.º 8
0
def test_minmax_correct():
    assert utils.minmax(10, 20) == (10, 20)