Ejemplo n.º 1
0
 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     ship = Ship.load(name=params.group(6))
     if ship is None:
         message.alert("No Ship called: %s" % (params.group(6),))
         return
     
     scan = p.scan("P")
     if scan is None:
         message.reply("No planet scans available on %s:%s:%s" % (p.x,p.y,p.z,))
         return
     
     planetscan = scan.planetscan
     tick=scan.tick
     res_m=planetscan.res_metal
     res_c=planetscan.res_crystal
     res_e=planetscan.res_eonium
     prod_res=planetscan.prod_res
     rand_id=scan.pa_id
     
     cost_m=ship.metal
     cost_c=ship.crystal
     cost_e=ship.eonium
     total_cost=ship.total_cost
     
     class_factory_table = {'Fighter': 'factory_usage_light', 'Corvette': 'factory_usage_light', 'Frigate': 'factory_usage_medium',
                            'Destroyer': 'factory_usage_medium', 'Cruiser': 'factory_usage_heavy', 'Battleship': 'factory_usage_heavy'}
     prod_modifier_table = {'None': 0.0, 'Low': 0.33, 'Medium': 0.66, 'High': 1.0}
     
     capped_number = min(res_m/cost_m, res_c/cost_c, res_e/cost_e)
     overflow = res_m+res_c+res_e-(capped_number*(cost_m+cost_c+cost_e))
     buildable = capped_number + ((overflow*.95)/total_cost)
     
     reply="Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,rand_id,tick)
     reply+=" can purchase %s: %s"%(ship.name,int(buildable))
     
     for gov in PA.options("govs"):
         bonus = PA.getfloat(gov, "prodcost")
         if bonus == 0:
             continue
         reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable/(1+bonus)))
     
     factory_usage=getattr(planetscan,class_factory_table[ship.class_])
     if prod_res > 0 and factory_usage != "None":
         max_prod_modifier=prod_modifier_table[factory_usage]
         buildable_from_prod = buildable + max_prod_modifier*prod_res/total_cost
         reply+=" Counting %s res in prod at %s usage:" % (self.num2short(prod_res),factory_usage)
         reply+=" %s"%(int(buildable_from_prod))
         
         for gov in PA.options("govs"):
             bonus = PA.getfloat(gov, "prodcost")
             if bonus == 0:
                 continue
             reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable_from_prod/(1+bonus)))
     
     message.reply(reply)
Ejemplo n.º 2
0
Archivo: maps.py Proyecto: munin/merlin
 def caprate(self, attacker=None):
     maxcap = PA.getfloat("roids", "maxcap")
     mincap = PA.getfloat("roids", "mincap")
     if not attacker or not self.value:
         return maxcap
     modifier = (float(self.value) / float(attacker.value)) ** 0.5
     return max(mincap, min(maxcap * modifier, maxcap))
Ejemplo n.º 3
0
    def execute(self, message, user, params):

        num, name, factories = params.group(1, 2, 3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        num = self.short2num(num)
        factories = int(factories)

        race = ship.race[:3].lower()
        race = "etd" if race == "eit" else race

        gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m = self.govre.match(p)
            if m and not gov:
                gov = m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        m = ship.metal
        c = ship.crystal
        e = ship.eonium
        bonus = 1 + pop / 100.0
        if gov:
            m *= (1 + PA.getfloat(gov, "prodcost"))
            c *= (1 + PA.getfloat(gov, "prodcost"))
            e *= (1 + PA.getfloat(gov, "prodcost"))
            bonus += PA.getfloat(gov, "prodtime")
        if race:
            bonus += PA.getfloat(race, "prodtime")
        cost = floor(m) + floor(c) + floor(e)
        print cost

        ticks = self.calc_ticks(cost, num, bonus, factories)

        reply = "It will take %s ticks to build %s %s (%s)" % (
            ticks, self.num2short(num), ship.name,
            self.num2short(
                num * ship.total_cost / PA.getint("numbers", "ship_value")))
        reply += " using %s factories" % (factories, ) if factories > 1 else ""
        reply += " with a" if race or gov else ""
        reply += " %s" % (PA.get(gov, "name"), ) if gov else ""
        reply += " %s" % (PA.get(race, "name"), ) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population" % (pop, ) if pop else ""
        message.reply(reply)
Ejemplo n.º 4
0
 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     ship = Ship.load(name=params.group(6))
     if ship is None:
         message.alert("No Ship called: %s" % (params.group(6),))
         return
     
     scan = p.scan("P")
     if scan is None:
         message.reply("No planet scans available on %s:%s:%s" % (p.x,p.y,p.z,))
         return
     
     planetscan = scan.planetscan
     tick=scan.tick
     res_m=planetscan.res_metal
     res_c=planetscan.res_crystal
     res_e=planetscan.res_eonium
     prod_res=planetscan.prod_res
     rand_id=scan.pa_id
     
     cost_m=ship.metal
     cost_c=ship.crystal
     cost_e=ship.eonium
     total_cost=ship.total_cost
     
     class_factory_table = {'Fighter': 'factory_usage_light', 'Corvette': 'factory_usage_light', 'Frigate': 'factory_usage_medium',
                            'Destroyer': 'factory_usage_medium', 'Cruiser': 'factory_usage_heavy', 'Battleship': 'factory_usage_heavy'}
     prod_modifier_table = {'None': 0, 'Low': 33, 'Medium': 66, 'High': 100}
     
     capped_number=min(res_m/cost_m, res_c/cost_c, res_e/cost_e)
     overflow=res_m+res_c+res_e-(capped_number*(cost_m+cost_c+cost_e))
     buildable = capped_number + ((overflow*.95)/total_cost)
     
     demo = 1/(1+PA.getfloat("demo","prodcost"))
     total = 1/(1+PA.getfloat("total","prodcost"))
     reply="Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,rand_id,tick)
     reply+=" can purchase %s: %s | Demo: %s | Total: %s"%(ship.name,int(buildable),int(buildable*demo),int(buildable*total))
     
     if prod_res > 0:
         factory_usage=getattr(planetscan,class_factory_table[ship.class_])
         max_prod_modifier=prod_modifier_table[factory_usage]
         buildable_from_prod = buildable + max_prod_modifier*(prod_res)/100/total_cost
         reply+=" Counting %d res in prod at %s usage:" % (prod_res,factory_usage)
         reply+=" %s | Demo: %s | Total: %s "%(int(buildable_from_prod), int(buildable_from_prod*demo),int(buildable*total))
     
     message.reply(reply)
Ejemplo n.º 5
0
Archivo: rprod.py Proyecto: JDD/merlin
    def execute(self, message, user, params):
        
        name, ticks, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        ticks = int(ticks)
        factories = int(factories)

        race = ship.race[:3].lower()
        race = "etd" if race == "eit" else race

        gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        m = ship.metal
        c = ship.crystal
        e = ship.eonium
        bonus = 1 + pop/100.0
        if gov:
            m *= (1+PA.getfloat(gov,"prodcost"))
            c *= (1+PA.getfloat(gov,"prodcost"))
            e *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")
        cost = floor(m)+floor(c)+floor(e)

        res = int(self.revprod(ticks, factories, bonus))
        ships = int(res / cost)

        reply = "You can build %s %s (%s) in %d ticks" % (self.num2short(ships), ship.name, self.num2short(ships*ship.total_cost//PA.getint("numbers", "ship_value")), ticks)
        reply += " using %s factories" % (factories,) if factories > 1 else ""
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
Ejemplo n.º 6
0
def bashcap(context, target, attr):
    present = getattr(target, attr)
    if not isinstance(target, Planet) or attr not in (
            "value",
            "score",
            "size",
    ):
        return intcomma(present)
    attacker = context['user'].planet
    if not attacker:
        return intcomma(present)

    if attr == "size":
        ret = '<span title="%s XP/roid * %s roids (%s%%) = %s XP">%s</span>'
        return ret % (
            round(attacker.bravery(target), 2),
            target.maxcap(attacker),
            round(target.caprate(attacker), 2),
            intcomma(attacker.calc_xp(target)),
            intcomma(present),
        )
    else:
        ret = '<span class="%s" title="%s%%">%s</span>'
        limit = PA.getfloat("bash", attr)
        fraction = 1.0 * present / getattr(attacker, attr)
        return ret % (
            "white" if fraction >= limit else "orange",
            round(fraction * 100, 2),
            intcomma(present),
        )
Ejemplo n.º 7
0
    def execute(self, message, user, params):

        roids, cost, bonus = params.groups()
        roids, cost, bonus = int(roids), self.short2num(cost), int(bonus or 0)
        mining = PA.getint("roids", "mining")

        if roids == 0:
            message.reply("Another NewDawn landing, eh?")
            return

        mining = mining * ((float(bonus) + 100) / 100)

        ticks = (cost * PA.getint("numbers", "ship_value")) // (roids * mining)
        reply = "Capping %s roids at %s value with %s%% bonus will repay in %s ticks (%s days)" % (
            roids, self.num2short(cost), bonus, int(ticks), int(ticks / 24))

        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue
            ticks_b = ticks * (1 + bonus)
            reply += " %s: %s ticks (%s days)" % (PA.get(
                gov, "name"), int(ticks_b), int(ticks_b / 24))

        message.reply(reply)
Ejemplo n.º 8
0
Archivo: cost.py Proyecto: munin/merlin
 def execute(self, message, user, params):
     
     num, name = params.groups()
     
     ship = Ship.load(name=name)
     if ship is None:
         message.alert("No Ship called: %s" % (name,))
         return
     
     num = self.short2num(num)
     reply="Buying %s %s will cost %s metal, %s crystal and %s eonium."%(num,ship.name,
             self.num2short(ship.metal*num),
             self.num2short(ship.crystal*num),
             self.num2short(ship.eonium*num))
     
     for gov in PA.options("govs"):
         bonus = PA.getfloat(gov, "prodcost")
         if bonus == 0:
             continue
         
         reply += " %s: %s metal, %s crystal and %s eonium."%(
                     PA.get(gov, "name"),
                     self.num2short(ship.metal*(1+bonus)*num),
                     self.num2short(ship.crystal*(1+bonus)*num),
                     self.num2short(ship.eonium*(1+bonus)*num))
     
     reply+=" It will add %s value"%(self.num2short(ship.total_cost*num/100),)
     message.reply(reply)
Ejemplo n.º 9
0
    def execute(self, message, user, params):

        num, name = params.groups()

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("No Ship called: %s" % (name, ))
            return

        num = self.short2num(num)
        reply = "Buying %s %s (%s) will cost %s metal, %s crystal and %s eonium." % (
            num, ship.name,
            self.num2short(
                ship.total_cost * num // PA.getint("numbers", "ship_value")),
            self.num2short(ship.metal * num), self.num2short(
                ship.crystal * num), self.num2short(ship.eonium * num))

        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue

            reply += " %s: %s metal, %s crystal and %s eonium." % (
                PA.get(gov, "name"),
                self.num2short(floor(ship.metal * (1 + bonus)) * num),
                self.num2short(floor(ship.crystal * (1 + bonus)) * num),
                self.num2short(floor(ship.eonium * (1 + bonus)) * num))

        reply += " It will add %s value" % (self.num2short(
            ship.total_cost * num *
            (1.0 / PA.getint("numbers", "ship_value") -
             1.0 / PA.getint("numbers", "res_value"))), )
        message.reply(reply)
Ejemplo n.º 10
0
Archivo: roidcost.py Proyecto: JDD/DLR
    def execute(self, message, user, params):

        roids, cost, bonus = params.groups()
        roids, cost, bonus = int(roids), self.short2num(cost), int(bonus or 0)
        mining = PA.getint("roids", "mining")

        if roids == 0:
            message.reply("Another NewDawn landing, eh?")
            return

        mining = mining * ((float(bonus) + 100) / 100)

        ticks = (cost * PA.getint("numbers", "ship_value")) / (roids * mining)
        reply = "Capping %s roids at %s value with %s%% bonus will repay in %s ticks (%s days)" % (
            roids,
            self.num2short(cost),
            bonus,
            int(ticks),
            int(ticks / 24),
        )

        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue
            ticks_b = ticks * (1 + bonus)
            reply += " %s: %s ticks (%s days)" % (PA.get(gov, "name"), int(ticks_b), int(ticks_b / 24))

        message.reply(reply)
Ejemplo n.º 11
0
Archivo: prod.py Proyecto: munin/merlin
    def execute(self, message, user, params):
        
        num, name, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        num = self.short2num(num)
        factories = int(factories)

        race = gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1).lower()
                continue
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        cost = ship.total_cost
        bonus = 1 + pop/100.0
        if gov:
            cost *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")

        ticks = self.calc_ticks(cost, num, bonus, factories)

        reply = "It will take %s ticks to build %s %s (%s)" % (ticks, self.num2short(num), ship.name, self.num2short(num*ship.total_cost/100))
        reply += " using %s factories" % (factories,) if factories > 1 else ""
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
Ejemplo n.º 12
0
    def execute(self, message, user, params):
        
        name, ticks, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        ticks = int(ticks)
        factories = int(factories)

        race = gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1).lower()
                continue
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        cost = ship.total_cost
        bonus = 1 + pop/100.0
        if gov:
            cost *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")

        res = int(self.revprod(ticks, factories, bonus))
        ships = int(res / cost)

        reply = "You can build %s %s (%s) in %d ticks" % (self.num2short(ships), ship.name, self.num2short(ships*ship.total_cost/100), ticks)
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
Ejemplo n.º 13
0
    def execute(self, message, user, params):

        num, name, attacker = params.groups()
        attacker = (attacker or "t1").lower()

        num = self.short2num(num)
        ship = Ship.load(name=name)
        if ship is not None:
            pass
        elif "asteroids".rfind(name.lower()) > -1:
            ship = Ship(name="Asteroids",
                        class_="Roids",
                        armor=50,
                        total_cost=PA.getint("numbers", "roid_value") *
                        PA.getint("numbers", "ship_value"))
        elif "constructions".rfind(name.lower()) > -1:
            ship = Ship(name="Constructions",
                        class_="Struct",
                        armor=500,
                        total_cost=PA.getint("numbers", "cons_value") *
                        PA.getint("numbers", "ship_value"))
        else:
            message.alert("No Ship called: %s" % (name, ))
            return
        efficiency = PA.getfloat("teffs", attacker.lower())
        attacker_class = getattr(Ship, attacker)
        attackers = session.query(Ship).filter(attacker_class == ship.class_)
        if attackers.count() == 0:
            message.reply("%s are not hit by anything as that category (%s)" %
                          (ship.name, attacker))
            return
        if ship.class_ == "Roids":
            reply = "Capturing"
        elif ship.class_ == "Struct":
            reply = "Destroying"
        else:
            reply = "Stopping"
        reply += " %s %s (%s) as %s requires " % (
            num, ship.name,
            self.num2short(num * ship.total_cost /
                           PA.getint("numbers", "ship_value")), attacker)
        for attacker in attackers:
            if attacker.type.lower() == "emp":
                needed = int((math.ceil(
                    num / (float(100 - ship.empres) / 100) / attacker.guns)) /
                             efficiency)
            else:
                needed = int(
                    (math.ceil(float(ship.armor * num) / attacker.damage)) /
                    efficiency)
            reply += "%s: %s (%s) " % (attacker.name, needed,
                                       self.num2short(
                                           attacker.total_cost * needed /
                                           PA.getint("numbers", "ship_value")))
        message.reply(reply)
Ejemplo n.º 14
0
    def execute(self, message, user, params):

        num, name, target = params.groups()
        target = target or "t1"

        ship = Ship.load(name=name)
        num = self.short2num(num)
        if ship is None:
            message.alert("No Ship called: %s" % (name,))
            return
        efficiency = PA.getfloat("teffs", target.lower())
        target_class = getattr(ship, target)
        if ship.damage:
            total_damage = ship.damage * num
        if ship.t1 == "Roids":
            killed = total_damage / 50
            message.reply(
                "%s %s (%s) will capture Asteroid: %s (%s)"
                % (num, ship.name, self.num2short(num * ship.total_cost / 100), killed, self.num2short(killed * 200))
            )
            return
        if ship.t1 == "Struct":
            killed = total_damage / 500
            message.reply(
                "%s %s (%s) will destroy Structure: %s (%s)"
                % (num, ship.name, self.num2short(num * ship.total_cost / 100), killed, self.num2short(killed * 1500))
            )
            return
        targets = session.query(Ship).filter(Ship.class_ == target_class)
        if targets.count() == 0:
            message.reply("%s does not have any targets in that category (%s)" % (ship.name, target))
            return
        reply = "%s %s (%s) hitting %s will " % (
            num,
            ship.name,
            self.num2short(num * ship.total_cost / 100),
            target_class,
        )
        if ship.type.lower() == "norm" or ship.type.lower() == "cloak":
            reply += "destroy "
        elif ship.type.lower() == "emp":
            reply += "hug "
        elif ship.type.lower() == "steal":
            reply += "steal "
        else:
            raise Exception("Erroneous type %s" % (ship.type,))
        for target in targets:
            if ship.type.lower() == "emp":
                killed = int(efficiency * ship.guns * num * float(100 - target.empres) / 100)
            else:
                killed = int(efficiency * total_damage / target.armor)
            reply += "%s: %s (%s) " % (target.name, killed, self.num2short(target.total_cost * killed / 100))
        message.reply(reply)
Ejemplo n.º 15
0
    def execute(self, message, user, params):
        
        roids=int(params.group(1))
        ticks=int(params.group(2))
        bonus=int(params.group(3) or 0)
        mining = PA.getint("roids","mining")

        mining = mining *(float(bonus+100)/100)

        cost=self.num2short(ticks*roids*mining/100)
        reply="In %s ticks (%s days) %s roids with %s%% bonus will mine %s value" % (ticks,ticks/24,roids,bonus,cost)

        cost=self.num2short(ticks*roids*mining/100*(1/(1+PA.getfloat("feud","prodcost"))))
        reply+=" Feudalism: %s value" % (cost)

        message.reply(reply)
Ejemplo n.º 16
0
    def execute(self, message, user, params):
        
        roids, cost, bonus = params.groups()
        roids, cost, bonus = int(roids), self.short2num(cost), int(bonus or 0)
        mining = PA.getint("roids","mining")

        if roids == 0:
            message.reply("Another NewDawn landing, eh?")
            return

        mining=mining * ((float(bonus)+100)/100)

        repay=int((cost*100)/(roids*mining))

        reply="Capping %s roids at %s value with %s%% bonus will repay in %s ticks (%s days)" % (roids,self.num2short(cost),bonus,repay,repay/24)

        repay = int((cost*100)/(roids*mining*(1/(1+PA.getfloat("feud","prodcost")))))
        reply+=" Feudalism: %s ticks (%s days)" % (repay,repay/24)

        message.reply(reply)
Ejemplo n.º 17
0
    def execute(self, message, user, params):
        
        roids=int(params.group(1))
        ticks=int(params.group(2))
        bonus=int(params.group(3) or 0)
        mining = PA.getint("roids","mining")

        mining = mining *(float(bonus+100)/100)

        value = ticks*roids*mining/100
        reply = "In %s ticks (%s days) %s roids with %s%% bonus will mine %s value" % (ticks,ticks/24,roids,bonus,self.num2short(value))
        
        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue
            value_b = value/(1+bonus)
            reply += " %s: %s value" % (PA.get(gov, "name"), self.num2short(value_b))
        
        message.reply(reply)
Ejemplo n.º 18
0
 def execute(self, message, user, params):
     
     num, name = params.groups()
     
     ship = Ship.load(name=name)
     if ship is None:
         message.alert("No Ship called: %s" % (name,))
         return
     
     feud = PA.getfloat("feud","prodcost")
     num = self.short2num(num)
     reply="Buying %s %s will cost %s metal, %s crystal and %s eonium."%(num,ship.name,
             self.num2short(ship.metal*num),
             self.num2short(ship.crystal*num),
             self.num2short(ship.eonium*num))
     reply+=" Feudalism: %s metal, %s crystal and %s eonium."%(
             self.num2short(ship.metal*(1+feud)*num),
             self.num2short(ship.crystal*(1+feud)*num),
             self.num2short(ship.eonium*(1+feud)*num))
     reply+=" It will add %s value"%(self.num2short(ship.total_cost*num/100),)
     message.reply(reply)
Ejemplo n.º 19
0
    def execute(self, message, user, params):

        roids = int(params.group(1))
        ticks = int(params.group(2))
        bonus = int(params.group(3) or 0)
        mining = PA.getint("roids", "mining")

        mining = mining * (float(bonus + 100) / 100)

        value = ticks * roids * mining / PA.getint("numbers", "ship_value")
        reply = "In %s ticks (%s days) %s roids with %s%% bonus will mine %s value" % (
            ticks, ticks // 24, roids, bonus, self.num2short(value))

        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue
            value_b = value / (1 + bonus)
            reply += " %s: %s value" % (PA.get(
                gov, "name"), self.num2short(value_b))

        message.reply(reply)
Ejemplo n.º 20
0
def bashcap(context, target, attr):
    present = getattr(target, attr)
    if not isinstance(target, Planet) or attr not in ("value", "score", "size"):
        return intcomma(present)
    attacker = context["user"].planet
    if not attacker:
        return intcomma(present)

    if attr == "size":
        ret = '<span title="%s XP/roid * %s roids (%s%%) = %s XP">%s</span>'
        return ret % (
            round(attacker.bravery(target), 2),
            target.maxcap(attacker),
            round(target.caprate(attacker), 2),
            intcomma(attacker.calc_xp(target)),
            intcomma(present),
        )
    else:
        ret = '<span class="%s" title="%s%%">%s</span>'
        limit = PA.getfloat("bash", attr)
        fraction = 1.0 * present / getattr(attacker, attr)
        return ret % ("white" if fraction >= limit else "orange", round(fraction * 100, 2), intcomma(present))
Ejemplo n.º 21
0
Archivo: stop.py Proyecto: munin/merlin
 def execute(self, message, user, params):
     
     num, name, attacker = params.groups()
     attacker = (attacker or "t1").lower()
     
     num = self.short2num(num)
     ship = Ship.load(name=name)
     if ship is not None:
         pass
     elif "asteroids".rfind(name.lower()) > -1:
         ship = Ship(name="Asteroids",class_="Roids",armor=50,total_cost=PA.getint("numbers", "roid_value")*100)
     elif "constructions".rfind(name.lower()) > -1:
         ship = Ship(name="Constructions",class_="Struct",armor=500,total_cost=PA.getint("numbers", "cons_value")*100)
     else:
         message.alert("No Ship called: %s" % (name,))
         return
     efficiency = PA.getfloat("teffs",attacker.lower())
     attacker_class = getattr(Ship, attacker)
     attackers = session.query(Ship).filter(attacker_class == ship.class_)
     if attackers.count() == 0:
         message.reply("%s are not hit by anything as that category (%s)" % (ship.name,attacker))
         return
     if ship.class_ == "Roids":
         reply="Capturing"
     elif ship.class_ == "Struct":
         reply="Destroying"
     else:
         reply="Stopping"
     reply+=" %s %s (%s) as %s requires " % (num, ship.name,self.num2short(num*ship.total_cost/100),attacker)
     for attacker in attackers:
         if attacker.type.lower() == "emp" :
             needed=int((math.ceil(num/(float(100-ship.empres)/100)/attacker.guns))/efficiency)
         else:
             needed=int((math.ceil(float(ship.armor*num)/attacker.damage))/efficiency)
         reply+="%s: %s (%s) " % (attacker.name,needed,self.num2short(attacker.total_cost*needed/100))
     message.reply(reply)
Ejemplo n.º 22
0
 def execute(self, message, user, params):
     
     if len(params.groups()) < 3:
         planet = self.get_user_planet(user)
     else:
         planet = Planet.load(*params.group(1,3,5))
         if planet is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
     
     message.reply("%s:%s:%s can be hit by planets with value %d or below or score %d or below"%(planet.x,planet.y,planet.z,int(planet.value/PA.getfloat("bash","value")),int(planet.score/PA.getfloat("bash","score"))))
Ejemplo n.º 23
0
    def execute(self, message, user, params):

        p = Planet.load(*params.group(1, 3, 5))
        if p is None:
            message.reply("No planet with coords %s:%s:%s found" %
                          params.group(1, 3, 5))
            return
        ship = Ship.load(name=params.group(6))
        if ship is None:
            message.alert("No Ship called: %s" % (params.group(6), ))
            return

        scan = p.scan("P")
        if scan is None:
            message.reply("No planet scans available on %s:%s:%s" % (
                p.x,
                p.y,
                p.z,
            ))
            return

        planetscan = scan.planetscan
        tick = scan.tick
        res_m = planetscan.res_metal
        res_c = planetscan.res_crystal
        res_e = planetscan.res_eonium
        prod_res = planetscan.prod_res
        rand_id = scan.pa_id

        cost_m = ship.metal
        cost_c = ship.crystal
        cost_e = ship.eonium
        total_cost = ship.total_cost

        class_factory_table = {
            'Fighter': 'factory_usage_light',
            'Corvette': 'factory_usage_light',
            'Frigate': 'factory_usage_medium',
            'Destroyer': 'factory_usage_medium',
            'Cruiser': 'factory_usage_heavy',
            'Battleship': 'factory_usage_heavy'
        }
        prod_modifier_table = {
            'None': 0.0,
            'Low': 0.33,
            'Medium': 0.66,
            'High': 1.0
        }

        capped_number = min(res_m / cost_m, res_c / cost_c, res_e / cost_e)
        overflow = res_m + res_c + res_e - (capped_number *
                                            (cost_m + cost_c + cost_e))
        buildable = capped_number + ((overflow * .95) / total_cost)

        reply = "Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (
            p.x, p.y, p.z, rand_id, tick)
        reply += " can purchase %s: %s" % (ship.name, int(buildable))

        for gov in PA.options("govs"):
            bonus = PA.getfloat(gov, "prodcost")
            if bonus == 0:
                continue
            reply += " | %s: %s" % (PA.get(
                gov, "name"), int(buildable / (1 + bonus)))

        factory_usage = getattr(planetscan, class_factory_table[ship.class_])
        if prod_res > 0 and factory_usage != "None":
            max_prod_modifier = prod_modifier_table[factory_usage]
            buildable_from_prod = buildable + max_prod_modifier * prod_res / total_cost
            reply += " Counting %s res in prod at %s usage:" % (
                self.num2short(prod_res), factory_usage)
            reply += " %s" % (int(buildable_from_prod))

            for gov in PA.options("govs"):
                bonus = PA.getfloat(gov, "prodcost")
                if bonus == 0:
                    continue
                reply += " | %s: %s" % (PA.get(
                    gov, "name"), int(buildable_from_prod / (1 + bonus)))

        message.reply(reply)
Ejemplo n.º 24
0
    def execute(self, message, user, params):

        alliance = Alliance()
        race = None
        size_mod = None
        size = None
        value_mod = None
        value = None
        bash = False
        attacker = user.planet
        cluster = None

        params = params.group(1).split()

        for p in params:
            m = self.bashre.match(p)
            if m and not bash:
                bash = True
                continue
            m = self.clusterre.match(p)
            if m and not cluster:
                cluster = int(m.group(1))
            m = self.racere.match(p)
            if m and not race:
                race = m.group(1)
                continue
            m = self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod = m.group(1) or '>'
                size = m.group(2)
                continue
            m = self.rangere.match(p)
            if m and not value:
                value_mod = m.group(1) or '<'
                value = m.group(2)
                continue
            m = self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(
                    1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" %
                                  (m.group(1), ))
                    return
                continue

        maxcap = PA.getfloat("roids", "maxcap")
        mincap = PA.getfloat("roids", "mincap")
        modifier = (cast(Planet.value,
                         Float).op("/")(float(attacker.value))).op("^")(0.5)
        caprate = func.float8larger(
            mincap, func.float8smaller(modifier.op("*")(maxcap), maxcap))
        maxcap = cast(func.floor(cast(Planet.size, Float).op("*")(caprate)),
                      Integer)

        bravery = (func.float8larger(
            0.0,
            (func.float8smaller(
                2.0,
                cast(Planet.value, Float).op("/")(float(attacker.value))) -
             0.1) * (func.float8smaller(
                 2.0,
                 cast(Planet.score, Float).op("/")(float(attacker.score))) -
                     0.2))).op("*")(10.0)
        xp_gain = cast(func.floor(maxcap.op("*")(bravery)), Integer)

        Q = session.query(Planet, Intel, xp_gain.label("xp_gain"))
        if alliance.id:
            Q = Q.join(Planet.intel)
            Q = Q.filter(Intel.alliance == alliance)
        else:
            Q = Q.outerjoin(Planet.intel)
            if alliance.name:
                Q = Q.filter(Intel.alliance == None)
        Q = Q.filter(Planet.active == True)
        if race:
            Q = Q.filter(Planet.race.ilike(race))
        if size:
            Q = Q.filter(Planet.size.op(size_mod)(size))
        if value:
            Q = Q.filter(Planet.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(
                or_(
                    Planet.value.op(">")(attacker.value *
                                         PA.getfloat("bash", "value")),
                    Planet.score.op(">")(attacker.score *
                                         PA.getfloat("bash", "score"))))
        if cluster:
            Q = Q.filter(Planet.x == cluster)
        Q = Q.order_by(desc("xp_gain"))
        Q = Q.order_by(desc(Planet.idle))
        Q = Q.order_by(desc(Planet.value))
        result = Q[:6]

        if len(result) < 1:
            reply = "No"
            if race:
                reply += " %s" % (race, )
            reply += " planets"
            if alliance.name:
                reply += " in intel matching Alliance: %s" % (alliance.name, )
            else:
                reply += " matching"
            if size:
                reply += " Size %s %s" % (size_mod, size)
            if value:
                reply += " Value %s %s" % (value_mod, value)
            message.reply(reply)
            return

        replies = []
        for planet, intel, xp_gain in result[:5]:
            reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z,
                                       planet.race)
            reply += " Value: %s Size: %s Scoregain: %d" % (
                planet.value, planet.size,
                xp_gain * PA.getint("numbers", "xp_value"))
            if intel:
                if intel.nick:
                    reply += " Nick: %s" % (intel.nick, )
                if not alliance.name and intel.alliance:
                    reply += " Alliance: %s" % (intel.alliance.name, )
            replies.append(reply)
        if len(result) > 5:
            replies[
                -1] += " (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 25
0
 def execute(self, message, planet):
     message.reply("%s:%s:%s can be hit by planets with value %d or below or score %d or below"%(planet.x,planet.y,planet.z,int(planet.value/PA.getfloat("bash","value")),int(planet.score/PA.getfloat("bash","score"))))
Ejemplo n.º 26
0
    def execute(self, message, user, params):
        
        planet = Planet.load(*params.group(1,3,5))
        if planet is None:
            message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
            return

        tick=Updates.load().current_tick()

        pscan = planet.scan("P")
        if pscan is None:
            message.reply("No Planet Scans of %s:%s:%s found"%(planet.x,planet.y,planet.z))
            return
        else:
            p_age = tick - pscan.tick
            pscan = pscan.planetscan

        dscan = planet.scan("D")
        if dscan is None:
            message.reply("No Development Scans of %s:%s:%s found"%(planet.x,planet.y,planet.z))
            return
        else:
            d_age = tick - dscan.tick
            dscan = dscan.devscan

        # Get government info from pa.cfg and intel
        gov_bonus = 0
        gov = "Unknown"
        gov_alert_max = 0.00
        gov_alert_min = 0.00
        int_gov = planet.intel.gov
        if int_gov is not None:
            int_gov = int_gov[0].lower()
        for gcode in PA.options("govs"):
            gov_alert = PA.getfloat(gcode, "alert")
            if int_gov and int_gov == gcode[0]:
                gov = PA.get(gcode, "name")
                gov_bonus = gov_alert
            if gov_alert > gov_alert_max:
                gov_alert_max = gov_alert
            if gov_alert < gov_alert_min:
                gov_alert_min = gov_alert


        alert_min = int((50+5*min(pscan.guards/(planet.size+1),15))*(1+dscan.security_centre*0.0275 + (gov_bonus if gov != "Unknown" else gov_alert_min) + 0.0))
        alert_max = int((50+5*min(pscan.guards/(planet.size+1),15))*(1+dscan.security_centre*0.0275 + (gov_bonus if gov != "Unknown" else gov_alert_max) + 0.5))

        message.reply("Planet: %s:%s:%s  Government: %s  Alert: %s-%s  (Scan Age P:%s D:%s)" % (planet.x, planet.y, planet.z, gov, alert_min, alert_max, p_age, d_age))
        if params.group(6):
            agents = int(params.group(6))
            max_res = user.planet.resources_per_agent(planet)
            message.reply("Results:   EF: %d roids (%dXP) AD: %d agents (%dXP) SGD: %d guards (%dXP) H:SD: %1.2f%% RP (%dXP) WDM: %d ship value (%dXP)" % (agents //3, 
                     self.xpcalc(agents,1), agents, self.xpcalc(agents,2), agents*10, self.xpcalc(agents,3), agents*0.25, self.xpcalc(agents,4), 
                     agents*(min(50+10*planet.value//user.planet.value, 100)), self.xpcalc(agents,5)))
            message.reply("           IB: %d amps+dists (%dXP) H: %d buildings (%dXP) H:RT: %dM %dC %dE (%dXP) GS: %d ticks (%dXP)" % (agents//15, self.xpcalc(agents,6),
                     agents//20, self.xpcalc(agents,7), min(max_res, pscan.res_metal//10), min(max_res, pscan.res_crystal//10), min(max_res, pscan.res_eonium//10),
                     self.xpcalc(agents,8), agents//5, self.xpcalc(agents,9)))

            # If stealth is supplied, calculate the probability of success.
            if params.group(7):
                stealth = int(params.group(7))
                stealth = stealth - 5 - int(agents/2)
                t=8-alert_min
                prob = 100*(t+stealth)//(t+alert_max)
                if prob < 0:
                    prob = 0
                elif prob > 100:
                    prob = 100

                growth = PA.getint(user.planet.race.lower(), "sgrowth")
                from math import ceil
                message.reply("New stealth: %s  Success rate: %s%%  Recovery time: %d ticks" % (stealth, prob, ceil((5.0+int(agents/2))/growth)))
Ejemplo n.º 27
0
 def execute(self, request, user, params=""):
     
     Q = session.query(Planet, Intel.nick, Alliance.name)
     Q = Q.outerjoin(Planet.intel)
     Q = Q.outerjoin(Intel.alliance)
     Q = Q.join(Planet.galaxy)
     Q = Q.filter(Planet.active == True)
     
     query = False
     
     page = 1
     
     search = {
                 "ruler" : "", "planet" : "", "galaxy" : "", "nick" : "", "alliance" : "",
                 "ter" : 'checked="checked"', "cat" : 'checked="checked"', "xan" : 'checked="checked"', "zik" : 'checked="checked"', "etd" : 'checked="checked"',
                 "sizemin" : "", "sizemax" : "", "valuemin" : "", "valuemax" : "", "scoremin" : "", "scoremax" : "", "x" : "",
                 "galsizemin" : "", "galsizemax" : "", "galvaluemin" : "", "galvaluemax" : "", "galscoremin" : "", "galscoremax" : "", "planets" : "",
                 "bash" : "" if params else 'checked="checked"',
                 "rankmin" : "", "rankmax" : "", "galrankmin" : "", "galrankmax" : "",
                 "ratiomin" : "", "ratiomax" : "", "galratiomin" : "", "galratiomax" : "",
                 "order1" : "", "order1o" : "", "order2" : "", "order2o" : "",
              }
     
     intfilts = {
                 "score" : Planet.score,
                 "value" : Planet.value,
                 "size" : Planet.size,
                 "xp" : Planet.xp,
                 "galscore" : Galaxy.score,
                 "galreal_score" : Galaxy.real_score,
                 "galvalue" : Galaxy.value,
                 "galsize" : Galaxy.size,
                 "galxp" : Galaxy.xp,
                 "idle" : Planet.idle,
                 "x" : Planet.x,
                 "y" : Planet.y,
                 "planets" : Galaxy.members,
                 "totalroundroids" : Planet.totalroundroids,
                 "totallostroids" : Planet.totallostroids,
                 "ticksroiding" : Planet.ticksroiding,
                 "ticksroided" : Planet.ticksroided,
                 "tickroids" : Planet.tickroids,
                 }
     
     floatfilts = {
                 "ratio" : Planet.ratio,
                 "galratio" : Galaxy.ratio,
                 "avroids" : Planet.avroids,
                 }
     
     rankfilts = {
                 "rank" : Planet.score_rank,
                 "valuerank" : Planet.value_rank,
                 "sizerank" : Planet.size_rank,
                 "xprank" : Planet.xp_rank,
                 "galrank" : Galaxy.score_rank,
                 "galrealrank" : Galaxy.real_score_rank,
                 "galvaluerank" : Galaxy.value_rank,
                 "galsizerank" : Galaxy.size_rank,
                 "galxprank" : Galaxy.xp_rank,
                 }
     
     filters = {}
     filters.update(intfilts)
     filters.update(floatfilts)
     filters.update(rankfilts)
     
     order = {
                 "xyz"   : (Planet.x, Planet.y, Planet.z,),
                 "score_growth" : Planet.score_growth,
                 "value_growth" : Planet.value_growth,
                 "size_growth"  : Planet.size_growth,
                 "xp_growth"    : Planet.xp_growth,
                 "score_growth_pc" : Planet.score_growth_pc,
                 "value_growth_pc" : Planet.value_growth_pc,
                 "size_growth_pc"  : Planet.size_growth_pc,
                 "xp_growth_pc"    : Planet.xp_growth_pc,
                 "galscore_growth" : Galaxy.score_growth,
                 "galreal_score_growth" : Galaxy.real_score_growth,
                 "galvalue_growth" : Galaxy.value_growth,
                 "galsize_growth"  : Galaxy.size_growth,
                 "galxp_growth"    : Galaxy.xp_growth,
                 "galscore_growth_pc" : Galaxy.score_growth_pc,
                 "galreal_score_growth_pc" : Galaxy.real_score_growth_pc,
                 "galvalue_growth_pc" : Galaxy.value_growth_pc,
                 "galsize_growth_pc"  : Galaxy.size_growth_pc,
                 "galxp_growth_pc"    : Galaxy.xp_growth_pc,
                 }
     
     order.update(filters)
     orders = []
     
     wordfilts = {
                 "ruler" : Planet.rulername,
                 "planet" : Planet.planetname,
                 "galaxy" : Galaxy.name,
                 }
     
     if request.POST.get("search"):
         r = request.POST
         search = "/search/"
         
         for word in wordfilts.keys() + ["nick", "alliance"]:
             filt = (r.get(word) or "").strip()
             if not filt:
                 continue
             search += "%s:%s/" %(word,filt,)
         
         for filt in filters.keys():
             one = (r.get("min"+filt) or "").strip()
             two = (r.get("max"+filt) or "").strip()
             if not one and not two:
                 continue
             
             if one and one == two:
                 search += "%s:%s/" %(filt,one,)
             elif one and not two:
                 search += "%s:%s|/" %(filt,one,)
             elif two and not one:
                 search += "%s:|%s/" %(filt,two,)
             elif one and two:
                 search += "%s:%s|%s/" %(filt,one,two,)
         
         races = []
         for race in PA.options("races"):
             if (r.get(race) or "").strip():
                 races.append(race)
         if len(races) != len(PA.options("races")):
             search += "race:%s/" %("|".join(races),)
         
         if (r.get("bash") or "").strip():
             search += "bash/"
         
         o1 = (r.get("order1") or "").strip()
         o1o = (r.get("order1o") or "").strip()
         o2 = (r.get("order2") or "").strip()
         o2o = (r.get("order2o") or "").strip()
         if o1 not in order:
             o1, o1o = o2, o2o
         if o1 in order and (o1 == o2 or o2 not in order):
             if o1 == "score" and o1o == "desc":
                 pass
             else:
                 o1o = "^" if o1o == "asc" else "_"
                 search += "order:%s%s/" %(o1o,o1,)
         elif o1 in order and o2 in order:
             o1o = "^" if o1o == "asc" else "_"
             o2o = "^" if o2o == "asc" else "_"
             search += "order:%s%s|%s%s/" %(o1o,o1,o2o,o2,)
         
         return HttpResponseRedirect(search)
     
     for param in params.lower().split("/"):
         if param == "bash" and user.planet is not None:
             Q = Q.filter(or_(Planet.value.op(">")(user.planet.value*PA.getfloat("bash","value")),
                              Planet.score.op(">")(user.planet.score*PA.getfloat("bash","score"))))
             Q = Q.filter(Planet.x < 200)
             search[param] = 'checked="checked"'
             continue
         
         arg, sep, val = param.partition(":")
         if not (arg and val):
             continue
         
         if arg in filters:
             one, two = "", ""
             if "|" not in val:
                 one, two = val, val
             elif val[-1] == "|":
                 one, two = val[:-1], ""
             elif val[0] == "|":
                 one, two = "", val[1:]
             elif "|" in val:
                 one, two = val.split("|",1)
             else:
                 continue
             
             try:
                 if one:
                     one = float(one) if arg in floatfilts else int(one)
                 if two:
                     two = float(two) if arg in floatfilts else int(two)
             except ValueError:
                 continue
             
             if one and one == two:
                 Q = Q.filter(filters[arg] == one)
             elif one and not two:
                 Q = Q.filter(filters[arg] <= one) if arg in rankfilts else Q.filter(filters[arg] >= one)
             elif two and not one:
                 Q = Q.filter(filters[arg] >= two) if arg in rankfilts else Q.filter(filters[arg] <= two)
             elif one and two:
                 Q = Q.filter(filters[arg].between(min(one,two), max(one,two)))
             else:
                 continue
             
             search[arg+"min"], search[arg+"max"] = one, two
             query = True
         
         elif arg in wordfilts:
             Q = Q.filter(wordfilts[arg].ilike("%"+val+"%"))
             search[arg] = val
             query = True
         
         elif arg == "nick" and getattr(user, "is_" + Config.get("Arthur", "intel"))():
             Q = Q.filter(Intel.nick.ilike("%"+val+"%"))
             search["nick"] = val
             query = True
         
         elif arg == "alliance" and getattr(user, "is_" + Config.get("Arthur", "intel"))():
             if val[0] == "!":
                 val = val[1:]
                 inv = True
             else:
                 inv = False
             alliance = Alliance.load(val)
             if alliance:
                 Q = Q.filter(Intel.alliance == alliance) if not inv else Q.filter(Intel.alliance != alliance)
                 search["alliance"] = ["","!"][inv] + alliance.name
                 query = True
         
         elif arg == "race":
             races = []
             for race in val.split("|"):
                 if race in PA.options("races") and race not in races:
                     races.append(Planet.race.ilike(race))
                     search[race] = True
             if len(races):
                 Q = Q.filter(or_(*races))
                 for race in PA.options("races"):
                     search[race] = 'checked="checked"' if search[race] is True else ""
                 query = True
         
         elif arg == "order":
             for sort in val.split("|"):
                 if sort[0] == "^":
                     f = asc
                 elif sort[0] == "_":
                     f = desc
                 else:
                     continue
                 if sort[1:] in order:
                     orders.append((f, sort[1:],))
                     query = True
         
         elif arg == "page" and val.isdigit():
             page = int(val)
     
     if len(orders) < 1:
         orders.append((desc, "score",))
     if len(orders) < 2:
         orders.append((desc, "score",))
     search["order1"] = orders[0][1]
     search["order1o"] = orders[0][0].__name__
     search["order2"] = orders[1][1]
     search["order2o"] = orders[1][0].__name__
     for d, os in orders:
         if type(order[os]) is tuple:
             for o in order[os]:
                 Q = Q.order_by(d(o))
         else:
             Q = Q.order_by(d(order[os]))
     
     showsort = True if search["order1"] not in ("xyz","size","value","score","ratio","xp",
                                                 "size_growth","value_growth","score_growth",
                                                 "size_growth_pc","value_growth_pc","score_growth_pc",) else False
     
     count = Q.count()
     pages = count//50 + int(count%50 > 0)
     pages = range(1, 1+pages)
     
     offset = (page - 1)*50
     Q = Q.limit(50).offset(offset)
     
     results = Q.all() if query else None
     
     return render("search.tpl", request, planets=results, sort=search["order1"],
                             showsort=showsort, s=search, params=params,
                             offset=offset, pages=pages, page=page)
Ejemplo n.º 28
0
    def execute(self, message, user, params):
        
        alliance=Alliance()
        race=None
        size_mod=None
        size=None
        value_mod=None
        value=None
        bash=False
        attacker=None
        cluster=None

        params=params.group(1).split()

        for p in params:
            m=self.bashre.match(p)
            if m and not bash:
                bash=True
                attacker = self.get_user_planet(user)
                continue
            m=self.clusterre.match(p)
            if m and not cluster:
                cluster=int(m.group(1))
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1)
                continue
            m=self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod=m.group(1) or '>'
                size=m.group(2)
                continue
            m=self.rangere.match(p)
            if m and not value:
                value_mod=m.group(1) or '<'
                value=m.group(2)
                continue
            m=self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" % (m.group(1),))
                    return
                continue

        Q = session.query(Planet, Intel)
        if alliance.id:
            Q = Q.join(Planet.intel)
            Q = Q.filter(Intel.alliance == alliance)
        else:
            Q = Q.outerjoin(Planet.intel)
            if alliance.name:
                Q = Q.filter(Intel.alliance == None)
        Q = Q.filter(Planet.active == True)
        Q = Q.filter(Planet.x < 200)
        if race:
            Q = Q.filter(Planet.race.ilike(race))
        if size:
            Q = Q.filter(Planet.size.op(size_mod)(size))
        if value:
            Q = Q.filter(Planet.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(or_(Planet.value.op(">")(attacker.value*PA.getfloat("bash","value")),
                             Planet.score.op(">")(attacker.score*PA.getfloat("bash","score"))))
        if cluster:
            Q = Q.filter(Planet.x == cluster)
        Q = Q.order_by(desc(Planet.idle))
        Q = Q.order_by(desc(Planet.value))
        result = Q[:6]
        
        if len(result) < 1:
            reply="No"
            if race:
                reply+=" %s"%(race,)
            reply+=" planets"
            if alliance.name:
                reply+=" in intel matching Alliance: %s"%(alliance.name,)
            else:
                reply+=" matching"
            if size:
                reply+=" Size %s %s" % (size_mod,size)
            if value:
                reply+=" Value %s %s" % (value_mod,value)
            message.reply(reply)
            return
        
        replies = []
        for planet, intel in result[:5]:
            reply="%s:%s:%s (%s)" % (planet.x,planet.y,planet.z,planet.race)
            reply+=" Value: %s Size: %s Idle: %s" % (planet.value,planet.size, planet.idle)
            if intel:
                if intel.nick:
                    reply+=" Nick: %s" % (intel.nick,)
                if not alliance.name and intel.alliance:
                    reply+=" Alliance: %s" % (intel.alliance.name,)
            replies.append(reply)
        if len(result) > 5:
            replies[-1]+=" (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 29
0
 def execute(self, message, planet):
     message.reply(
         "%s:%s:%s can be hit by planets with value %d or below or score %d or below"
         % (planet.x, planet.y, planet.z,
            int(planet.value / PA.getfloat("bash", "value")),
            int(planet.score / PA.getfloat("bash", "score"))))
Ejemplo n.º 30
0
    def execute(self, message, user, params):

        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.alert("No planet with coords %s:%s:%s" %
                          params.group(1, 3, 5))
            return

        tick = Updates.load().current_tick()

        pscan = planet.scan("P")
        if pscan is None:
            message.reply("No Planet Scans of %s:%s:%s found" %
                          (planet.x, planet.y, planet.z))
            return
        else:
            p_age = tick - pscan.tick
            pscan = pscan.planetscan

        dscan = planet.scan("D")
        if dscan is None:
            message.reply("No Development Scans of %s:%s:%s found" %
                          (planet.x, planet.y, planet.z))
            return
        else:
            d_age = tick - dscan.tick
            dscan = dscan.devscan

        # Get government info from pa.cfg and intel
        gov_bonus = 0
        gov = "Unknown"
        gov_alert_max = 0.00
        gov_alert_min = 0.00
        int_gov = planet.intel.gov
        if int_gov is not None:
            int_gov = int_gov[0].lower()
        for gcode in PA.options("govs"):
            gov_alert = PA.getfloat(gcode, "alert")
            if int_gov and int_gov == gcode[0]:
                gov = PA.get(gcode, "name")
                gov_bonus = gov_alert
            if gov_alert > gov_alert_max:
                gov_alert_max = gov_alert
            if gov_alert < gov_alert_min:
                gov_alert_min = gov_alert

        alert_min = int(
            (50 + 5 * min(pscan.guards / (planet.size + 1), 15)) *
            (1 + dscan.security_centre * 2 / dscan.total +
             (gov_bonus if gov != "Unknown" else gov_alert_min) + 0.0))
        alert_max = int(
            (50 + 5 * min(pscan.guards / (planet.size + 1), 15)) *
            (1 + dscan.security_centre * 2 / dscan.total +
             (gov_bonus if gov != "Unknown" else gov_alert_max) + 0.5))

        message.reply(
            "Planet: %s:%s:%s  Government: %s  Alert: %s-%s  (Scan Age P:%s D:%s)"
            % (planet.x, planet.y, planet.z, gov, alert_min, alert_max, p_age,
               d_age))
        if params.group(6):
            agents = int(params.group(6))
            max_res = user.planet.resources_per_agent(planet)
            message.reply(
                "Results:   EF: %d roids (%dXP) AD: %d agents (%dXP) SGD: %d guards (%dXP) H:SD: %1.2f%% RP (%dXP) WDM: %d ship value (%dXP)"
                % (agents / 3, self.xpcalc(agents, 1), agents,
                   self.xpcalc(agents, 2), agents * 10, self.xpcalc(agents, 3),
                   agents * 0.25, self.xpcalc(agents, 4), agents *
                   (min(50 + 10 * planet.value / user.planet.value, 100)),
                   self.xpcalc(agents, 5)))
            message.reply(
                "           IB: %d amps+dists (%dXP) H: %d buildings (%dXP) H:RT: %dM %dC %dE (%dXP) GS: %d ticks (%dXP)"
                % (agents / 15, self.xpcalc(agents, 6), agents / 20,
                   self.xpcalc(agents, 7), min(max_res, pscan.res_metal / 10),
                   min(max_res, pscan.res_crystal / 10),
                   min(max_res, pscan.res_eonium / 10), self.xpcalc(
                       agents, 8), agents / 5, self.xpcalc(agents, 9)))

            # If stealth is supplied, calculate the probability of success.
            if params.group(7):
                stealth = int(params.group(7))
                stealth = stealth - 5 - int(agents / 2)
                t = 8 - alert_min
                prob = 100 * (t + stealth) / (t + alert_max)
                if prob < 0:
                    prob = 0
                elif prob > 100:
                    prob = 100

                growth = PA.getint(user.planet.race.lower(), "sgrowth")
                from math import ceil
                message.reply(
                    "New stealth: %s  Success rate: %s%%  Recovery time: %d ticks"
                    % (stealth, prob, ceil((5.0 + int(agents / 2)) / growth)))
Ejemplo n.º 31
0
    def execute(self, message, user, params):
        
        alliance=Alliance()
        race=None
        size_mod=None
        size=None
        value_mod=None
        value=None
        bash=False
        attacker=None
        cluster=None

        params=params.group(1).split()

        for p in params:
            m=self.bashre.match(p)
            if m and not bash:
                bash=True
                attacker = self.get_user_planet(user)
                continue
            m=self.clusterre.match(p)
            if m and not cluster:
                cluster=int(m.group(1))
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1)
                continue
            m=self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod=m.group(1) or '>'
                size=m.group(2)
                continue
            m=self.rangere.match(p)
            if m and not value:
                value_mod=m.group(1) or '<'
                value=m.group(2)
                continue
            m=self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" % (m.group(1),))
                    return
                continue

        tick = Updates.current_tick()
        target = aliased(Planet)
        target_intel = aliased(Intel)
        owner = aliased(Planet)
        owner_intel = aliased(Intel)
        
        Q = session.query(owner, owner_intel).distinct()
        Q = Q.join((FleetScan.owner, owner))
        Q = Q.join((FleetScan.target, target))
        Q = Q.join((target.intel, target_intel))
        Q = Q.filter(target_intel.alliance == Alliance.load(Config.get("Alliance","name")))
        Q = Q.filter(FleetScan.landing_tick > tick)
        Q = Q.filter(FleetScan.mission == "Attack")
        if alliance.id:
            Q = Q.join((owner.intel, owner_intel))
            Q = Q.filter(owner_intel.alliance == alliance)
        else:
            Q = Q.outerjoin((owner.intel, owner_intel))
            if alliance.name:
                Q = Q.filter(owner_intel.alliance == None)
        Q = Q.filter(owner.active == True)
        if race:
            Q = Q.filter(owner.race.ilike(race))
        if size:
            Q = Q.filter(owner.size.op(size_mod)(size))
        if value:
            Q = Q.filter(owner.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(or_(owner.value.op(">")(attacker.value*PA.getfloat("bash","value")),
                             owner.score.op(">")(attacker.score*PA.getfloat("bash","score"))))
        if cluster:
            Q = Q.filter(owner.x == cluster)
        Q = Q.order_by(desc(owner.size))
        Q = Q.order_by(desc(owner.value))
        result = Q[:6]
        
        if len(result) < 1:
            reply="No"
            if race:
                reply+=" %s"%(race,)
            reply+=" planets attacking %s" % (Config.get("Alliance","name"),)
            if alliance.name:
                reply+=" in intel matching Alliance: %s"%(alliance.name,)
            else:
                reply+=" matching"
            if size:
                reply+=" Size %s %s" % (size_mod,size)
            if value:
                reply+=" Value %s %s" % (value_mod,value)
            message.reply(reply)
            return
        
        replies = []
        for planet, intel in result[:5]:
            reply="%s:%s:%s (%s)" % (planet.x,planet.y,planet.z,planet.race)
            reply+=" Value: %s Size: %s" % (planet.value,planet.size)
            if intel:
                if intel.nick:
                    reply+=" Nick: %s" % (intel.nick,)
                if not alliance.name and intel.alliance:
                    reply+=" Alliance: %s" % (intel.alliance.name,)
            Q = session.query(FleetScan, Intel.nick).distinct()
            Q = Q.join(FleetScan.target)
            Q = Q.outerjoin(Planet.intel)
            Q = Q.filter(FleetScan.owner == planet)
            Q = Q.filter(FleetScan.landing_tick > tick)
            Q = Q.filter(FleetScan.mission == "Attack")
            result2 = Q.all()
            if len(result2):
                reply+=" Hitting: "
                prev=[]
                for fleet, nick in result2:
                    prev.append((nick or 'Unknown') + " (%s, lands: %s)"% (fleet.fleet_size,fleet.landing_tick))
                reply+=', '.join(prev)
            replies.append(reply)
        if len(result) > 5:
            replies[-1]+=" (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 32
0
    def execute(self, request, user, params=""):

        Q = session.query(Planet, Intel.nick, Alliance.name)
        Q = Q.outerjoin(Planet.intel)
        Q = Q.outerjoin(Intel.alliance)
        Q = Q.join(Planet.galaxy)
        Q = Q.filter(Planet.active == True)

        query = False

        page = 1

        search = {
            "ruler": "",
            "planet": "",
            "galaxy": "",
            "nick": "",
            "alliance": "",
            "ter": 'checked="checked"',
            "cat": 'checked="checked"',
            "xan": 'checked="checked"',
            "zik": 'checked="checked"',
            "etd": 'checked="checked"',
            "sizemin": "",
            "sizemax": "",
            "valuemin": "",
            "valuemax": "",
            "scoremin": "",
            "scoremax": "",
            "x": "",
            "galsizemin": "",
            "galsizemax": "",
            "galvaluemin": "",
            "galvaluemax": "",
            "galscoremin": "",
            "galscoremax": "",
            "planets": "",
            "bash": "" if params else 'checked="checked"',
            "rankmin": "",
            "rankmax": "",
            "galrankmin": "",
            "galrankmax": "",
            "ratiomin": "",
            "ratiomax": "",
            "galratiomin": "",
            "galratiomax": "",
            "order1": "",
            "order1o": "",
            "order2": "",
            "order2o": "",
        }

        intfilts = {
            "score": Planet.score,
            "value": Planet.value,
            "size": Planet.size,
            "xp": Planet.xp,
            "galscore": Galaxy.score,
            "galreal_score": Galaxy.real_score,
            "galvalue": Galaxy.value,
            "galsize": Galaxy.size,
            "galxp": Galaxy.xp,
            "idle": Planet.idle,
            "x": Planet.x,
            "y": Planet.y,
            "planets": Galaxy.members,
            "totalroundroids": Planet.totalroundroids,
            "totallostroids": Planet.totallostroids,
            "ticksroiding": Planet.ticksroiding,
            "ticksroided": Planet.ticksroided,
            "tickroids": Planet.tickroids,
        }

        floatfilts = {
            "ratio": Planet.ratio,
            "galratio": Galaxy.ratio,
            "avroids": Planet.avroids,
        }

        rankfilts = {
            "rank": Planet.score_rank,
            "valuerank": Planet.value_rank,
            "sizerank": Planet.size_rank,
            "xprank": Planet.xp_rank,
            "galrank": Galaxy.score_rank,
            "galrealrank": Galaxy.real_score_rank,
            "galvaluerank": Galaxy.value_rank,
            "galsizerank": Galaxy.size_rank,
            "galxprank": Galaxy.xp_rank,
        }

        filters = {}
        filters.update(intfilts)
        filters.update(floatfilts)
        filters.update(rankfilts)

        order = {
            "xyz": (
                Planet.x,
                Planet.y,
                Planet.z,
            ),
            "score_growth": Planet.score_growth,
            "value_growth": Planet.value_growth,
            "size_growth": Planet.size_growth,
            "xp_growth": Planet.xp_growth,
            "score_growth_pc": Planet.score_growth_pc,
            "value_growth_pc": Planet.value_growth_pc,
            "size_growth_pc": Planet.size_growth_pc,
            "xp_growth_pc": Planet.xp_growth_pc,
            "galscore_growth": Galaxy.score_growth,
            "galreal_score_growth": Galaxy.real_score_growth,
            "galvalue_growth": Galaxy.value_growth,
            "galsize_growth": Galaxy.size_growth,
            "galxp_growth": Galaxy.xp_growth,
            "galscore_growth_pc": Galaxy.score_growth_pc,
            "galreal_score_growth_pc": Galaxy.real_score_growth_pc,
            "galvalue_growth_pc": Galaxy.value_growth_pc,
            "galsize_growth_pc": Galaxy.size_growth_pc,
            "galxp_growth_pc": Galaxy.xp_growth_pc,
        }

        order.update(filters)
        orders = []

        wordfilts = {
            "ruler": Planet.rulername,
            "planet": Planet.planetname,
            "galaxy": Galaxy.name,
        }

        if request.REQUEST.get("search"):
            r = request.REQUEST
            search = "/search/"

            for word in wordfilts.keys() + ["nick", "alliance"]:
                filt = (r.get(word) or "").strip()
                if not filt:
                    continue
                search += "%s:%s/" % (
                    word,
                    filt,
                )

            for filt in filters.keys():
                one = (r.get("min" + filt) or "").strip()
                two = (r.get("max" + filt) or "").strip()
                if not one and not two:
                    continue

                if one and one == two:
                    search += "%s:%s/" % (
                        filt,
                        one,
                    )
                elif one and not two:
                    search += "%s:%s|/" % (
                        filt,
                        one,
                    )
                elif two and not one:
                    search += "%s:|%s/" % (
                        filt,
                        two,
                    )
                elif one and two:
                    search += "%s:%s|%s/" % (
                        filt,
                        one,
                        two,
                    )

            races = []
            for race in PA.options("races"):
                if (r.get(race) or "").strip():
                    races.append(race)
            if len(races) != len(PA.options("races")):
                search += "race:%s/" % ("|".join(races), )

            if (r.get("bash") or "").strip():
                search += "bash/"

            o1 = (r.get("order1") or "").strip()
            o1o = (r.get("order1o") or "").strip()
            o2 = (r.get("order2") or "").strip()
            o2o = (r.get("order2o") or "").strip()
            if o1 not in order:
                o1, o1o = o2, o2o
            if o1 in order and (o1 == o2 or o2 not in order):
                if o1 == "score" and o1o == "desc":
                    pass
                else:
                    o1o = "^" if o1o == "asc" else "_"
                    search += "order:%s%s/" % (
                        o1o,
                        o1,
                    )
            elif o1 in order and o2 in order:
                o1o = "^" if o1o == "asc" else "_"
                o2o = "^" if o2o == "asc" else "_"
                search += "order:%s%s|%s%s/" % (
                    o1o,
                    o1,
                    o2o,
                    o2,
                )

            return HttpResponseRedirect(search)

        for param in params.lower().split("/"):
            if param == "bash" and user.planet is not None:
                Q = Q.filter(
                    or_(
                        Planet.value.op(">")(user.planet.value *
                                             PA.getfloat("bash", "value")),
                        Planet.score.op(">")(user.planet.score *
                                             PA.getfloat("bash", "score"))))
                Q = Q.filter(Planet.x < 200)
                search[param] = 'checked="checked"'
                continue

            arg, sep, val = param.partition(":")
            if not (arg and val):
                continue

            if arg in filters:
                one, two = "", ""
                if "|" not in val:
                    one, two = val, val
                elif val[-1] == "|":
                    one, two = val[:-1], ""
                elif val[0] == "|":
                    one, two = "", val[1:]
                elif "|" in val:
                    one, two = val.split("|", 1)
                else:
                    continue

                try:
                    if one:
                        one = float(one) if arg in floatfilts else int(one)
                    if two:
                        two = float(two) if arg in floatfilts else int(two)
                except ValueError:
                    continue

                if one and one == two:
                    Q = Q.filter(filters[arg] == one)
                elif one and not two:
                    Q = Q.filter(
                        filters[arg] <= one) if arg in rankfilts else Q.filter(
                            filters[arg] >= one)
                elif two and not one:
                    Q = Q.filter(
                        filters[arg] >= two) if arg in rankfilts else Q.filter(
                            filters[arg] <= two)
                elif one and two:
                    Q = Q.filter(filters[arg].between(min(one, two),
                                                      max(one, two)))
                else:
                    continue

                search[arg + "min"], search[arg + "max"] = one, two
                query = True

            elif arg in wordfilts:
                Q = Q.filter(wordfilts[arg].ilike("%" + val + "%"))
                search[arg] = val
                query = True

            elif arg == "nick" and getattr(
                    user, "is_" + Config.get("Arthur", "intel"))():
                Q = Q.filter(Intel.nick.ilike("%" + val + "%"))
                search["nick"] = val
                query = True

            elif arg == "alliance" and getattr(
                    user, "is_" + Config.get("Arthur", "intel"))():
                if val[0] == "!":
                    val = val[1:]
                    inv = True
                else:
                    inv = False
                alliance = Alliance.load(val)
                if alliance:
                    Q = Q.filter(
                        Intel.alliance == alliance) if not inv else Q.filter(
                            Intel.alliance != alliance)
                    search["alliance"] = ["", "!"][inv] + alliance.name
                    query = True

            elif arg == "race":
                races = []
                for race in val.split("|"):
                    if race in PA.options("races") and race not in races:
                        races.append(Planet.race.ilike(race))
                        search[race] = True
                if len(races):
                    Q = Q.filter(or_(*races))
                    for race in PA.options("races"):
                        search[race] = 'checked="checked"' if search[
                            race] is True else ""
                    query = True

            elif arg == "order":
                for sort in val.split("|"):
                    if sort[0] == "^":
                        f = asc
                    elif sort[0] == "_":
                        f = desc
                    else:
                        continue
                    if sort[1:] in order:
                        orders.append((
                            f,
                            sort[1:],
                        ))
                        query = True

            elif arg == "page" and val.isdigit():
                page = int(val)

        if len(orders) < 1:
            orders.append((
                desc,
                "score",
            ))
        if len(orders) < 2:
            orders.append((
                desc,
                "score",
            ))
        search["order1"] = orders[0][1]
        search["order1o"] = orders[0][0].__name__
        search["order2"] = orders[1][1]
        search["order2o"] = orders[1][0].__name__
        for d, os in orders:
            if type(order[os]) is tuple:
                for o in order[os]:
                    Q = Q.order_by(d(o))
            else:
                Q = Q.order_by(d(order[os]))

        showsort = True if search["order1"] not in (
            "xyz",
            "size",
            "value",
            "score",
            "ratio",
            "xp",
            "size_growth",
            "value_growth",
            "score_growth",
            "size_growth_pc",
            "value_growth_pc",
            "score_growth_pc",
        ) else False

        count = Q.count()
        pages = count / 50 + int(count % 50 > 0)
        pages = range(1, 1 + pages)

        offset = (page - 1) * 50
        Q = Q.limit(50).offset(offset)

        results = Q.all() if query else None

        return render("search.tpl",
                      request,
                      planets=results,
                      sort=search["order1"],
                      showsort=showsort,
                      s=search,
                      params=params,
                      offset=offset,
                      pages=pages,
                      page=page)
Ejemplo n.º 33
0
 def execute(self, message, planet):
     message.reply("%s:%s:%s can hit planets with value %d or above or score %d or above"%(planet.x,planet.y,planet.z,int(planet.value*PA.getfloat("bash","value")),int(planet.score*PA.getfloat("bash","score"))))
Ejemplo n.º 34
0
    def execute(self, message, user, params):
        
        alliance=Alliance()
        race=None
        size_mod=None
        size=None
        value_mod=None
        value=None
        bash=False
        attacker=user.planet
        cluster=None

        params=params.group(1).split()

        for p in params:
            m=self.bashre.match(p)
            if m and not bash:
                bash=True
                continue
            m=self.clusterre.match(p)
            if m and not cluster:
                cluster=int(m.group(1))
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1)
                continue
            m=self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod=m.group(1) or '>'
                size=m.group(2)
                continue
            m=self.rangere.match(p)
            if m and not value:
                value_mod=m.group(1) or '<'
                value=m.group(2)
                continue
            m=self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" % (m.group(1),))
                    return
                continue

        maxcap = PA.getfloat("roids","maxcap")
        mincap = PA.getfloat("roids","mincap")
        modifier = (cast(Planet.value,Float).op("/")(float(attacker.value))).op("^")(0.5)
        caprate = func.float8larger(mincap,func.float8smaller(modifier.op("*")(maxcap),maxcap))
        maxcap = cast(func.floor(cast(Planet.size,Float).op("*")(caprate)),Integer)
        
        bravery = (func.float8larger(0.0,( func.float8smaller(2.0, cast(Planet.value,Float).op("/")(float(attacker.value)))-0.1) * (func.float8smaller(2.0, cast(Planet.score,Float).op("/")(float(attacker.score)))-0.2))).op("*")(10.0)
        xp_gain = cast(func.floor(maxcap.op("*")(bravery)),Integer)
        
        Q = session.query(Planet, Intel, xp_gain.label("xp_gain"))
        if alliance.id:
            Q = Q.join(Planet.intel)
            Q = Q.filter(Intel.alliance == alliance)
        else:
            Q = Q.outerjoin(Planet.intel)
            if alliance.name:
                Q = Q.filter(Intel.alliance == None)
        Q = Q.filter(Planet.active == True)
        if race:
            Q = Q.filter(Planet.race.ilike(race))
        if size:
            Q = Q.filter(Planet.size.op(size_mod)(size))
        if value:
            Q = Q.filter(Planet.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(or_(Planet.value.op(">")(attacker.value*PA.getfloat("bash","value")),
                             Planet.score.op(">")(attacker.score*PA.getfloat("bash","score"))))
        if cluster:
            Q = Q.filter(Planet.x == cluster)
        Q = Q.order_by(desc("xp_gain"))
        Q = Q.order_by(desc(Planet.idle))
        Q = Q.order_by(desc(Planet.value))
        result = Q[:6]
        
        if len(result) < 1:
            reply="No"
            if race:
                reply+=" %s"%(race,)
            reply+=" planets"
            if alliance.name:
                reply+=" in intel matching Alliance: %s"%(alliance.name,)
            else:
                reply+=" matching"
            if size:
                reply+=" Size %s %s" % (size_mod,size)
            if value:
                reply+=" Value %s %s" % (value_mod,value)
            message.reply(reply)
            return
        
        replies = []
        for planet, intel, xp_gain in result[:5]:
            reply="%s:%s:%s (%s)" % (planet.x,planet.y,planet.z,planet.race)
            reply+=" Value: %s Size: %s Scoregain: %d" % (planet.value,planet.size, xp_gain*60)
            if intel:
                if intel.nick:
                    reply+=" Nick: %s" % (intel.nick,)
                if not alliance.name and intel.alliance:
                    reply+=" Alliance: %s" % (intel.alliance.name,)
            replies.append(reply)
        if len(result) > 5:
            replies[-1]+=" (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 35
0
    def execute(self, message, user, params):

        num, name, target = params.groups()
        target = (target or "t1").lower()

        ship = Ship.load(name=name)
        num = self.short2num(num)
        if ship is None:
            message.alert("No Ship called: %s" % (name, ))
            return
        efficiency = PA.getfloat("teffs", target.lower())
        target_class = getattr(ship, target)
        if ship.damage:
            total_damage = ship.damage * num
        if ship.t1 == "Roids":
            killed = total_damage // 50
            message.reply("%s %s (%s) will capture Asteroid: %s (%s)" % (
                num,
                ship.name,
                self.num2short(num * ship.total_cost //
                               PA.getint("numbers", "ship_value")),
                killed,
                self.num2short(killed * PA.getint("numbers", "roid_value")),
            ))
            return
        if ship.t1 == "Resources":
            killed = total_damage * 50
            message.reply("%s %s (%s) will capture Resource: %s (%s)" % (
                num,
                ship.name,
                self.num2short(num * ship.total_cost //
                               PA.getint("numbers", "ship_value")),
                self.num2short(killed),
                self.num2short(killed // PA.getint("numbers", "res_value")),
            ))
            return
        if ship.t1[:6] == "Struct":
            killed = total_damage // 500
            message.reply("%s %s (%s) will destroy Structure: %s (%s)" % (
                num,
                ship.name,
                self.num2short(num * ship.total_cost //
                               PA.getint("numbers", "ship_value")),
                killed,
                self.num2short(killed * PA.getint("numbers", "cons_value")),
            ))
            return
        targets = session.query(Ship).filter(Ship.class_ == target_class)
        if targets.count() == 0:
            message.reply(
                "%s does not have any targets in that category (%s)" %
                (ship.name, target))
            return
        reply = "%s %s (%s) hitting %s will " % (
            num, ship.name,
            self.num2short(num * ship.total_cost //
                           PA.getint("numbers", "ship_value")), target_class)
        if ship.type.lower()[:4] == "norm" or ship.type.lower() == 'cloak':
            reply += "destroy "
        elif ship.type.lower() == "emp":
            reply += "hug "
        elif ship.type.lower() == "steal":
            reply += "steal "
        else:
            raise Exception("Erroneous type %s" % (ship.type, ))
        for target in targets:
            if ship.type.lower() == "emp":
                killed = int(efficiency * ship.guns * num *
                             float(100 - target.empres) / 100)
            else:
                killed = int(efficiency * total_damage / target.armor)
            reply += "%s: %s (%s) " % (target.name, killed,
                                       self.num2short(
                                           target.total_cost * killed //
                                           PA.getint("numbers", "ship_value")))
        message.reply(reply)
Ejemplo n.º 36
0
    def execute(self, message, user, params):

        alliance = Alliance()
        race = None
        size_mod = None
        size = None
        value_mod = None
        value = None
        bash = False
        attacker = None
        cluster = None

        params = params.group(1).split()

        for p in params:
            m = self.bashre.match(p)
            if m and not bash:
                bash = True
                attacker = self.get_user_planet(user)
                continue
            m = self.clusterre.match(p)
            if m and not cluster:
                cluster = int(m.group(1))
            m = self.racere.match(p)
            if m and not race:
                race = m.group(1)
                continue
            m = self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod = m.group(1) or '>'
                size = m.group(2)
                continue
            m = self.rangere.match(p)
            if m and not value:
                value_mod = m.group(1) or '<'
                value = m.group(2)
                continue
            m = self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(
                    1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" %
                                  (m.group(1), ))
                    return
                continue

        tick = Updates.current_tick()
        target = aliased(Planet)
        target_intel = aliased(Intel)
        owner = aliased(Planet)
        owner_intel = aliased(Intel)

        Q = session.query(owner, owner_intel).distinct()
        Q = Q.join((FleetScan.owner, owner))
        Q = Q.join((FleetScan.target, target))
        Q = Q.join((target.intel, target_intel))
        Q = Q.filter(target_intel.alliance == Alliance.load(
            Config.get("Alliance", "name")))
        Q = Q.filter(FleetScan.landing_tick > tick)
        Q = Q.filter(FleetScan.mission == "Attack")
        if alliance.id:
            Q = Q.join((owner.intel, owner_intel))
            Q = Q.filter(owner_intel.alliance == alliance)
        else:
            Q = Q.outerjoin((owner.intel, owner_intel))
            if alliance.name:
                Q = Q.filter(owner_intel.alliance == None)
        Q = Q.filter(owner.active == True)
        if race:
            Q = Q.filter(owner.race.ilike(race))
        if size:
            Q = Q.filter(owner.size.op(size_mod)(size))
        if value:
            Q = Q.filter(owner.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(
                or_(
                    owner.value.op(">")(attacker.value *
                                        PA.getfloat("bash", "value")),
                    owner.score.op(">")(attacker.score *
                                        PA.getfloat("bash", "score"))))
        if cluster:
            Q = Q.filter(owner.x == cluster)
        Q = Q.order_by(desc(owner.size))
        Q = Q.order_by(desc(owner.value))
        result = Q[:6]

        if len(result) < 1:
            reply = "No"
            if race:
                reply += " %s" % (race, )
            reply += " planets attacking %s" % (Config.get("Alliance",
                                                           "name"), )
            if alliance.name:
                reply += " in intel matching Alliance: %s" % (alliance.name, )
            else:
                reply += " matching"
            if size:
                reply += " Size %s %s" % (size_mod, size)
            if value:
                reply += " Value %s %s" % (value_mod, value)
            message.reply(reply)
            return

        replies = []
        for planet, intel in result[:5]:
            reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z,
                                       planet.race)
            reply += " Value: %s Size: %s" % (planet.value, planet.size)
            if intel:
                if intel.nick:
                    reply += " Nick: %s" % (intel.nick, )
                if not alliance.name and intel.alliance:
                    reply += " Alliance: %s" % (intel.alliance.name, )
            Q = session.query(FleetScan, Intel.nick).distinct()
            Q = Q.join(FleetScan.target)
            Q = Q.outerjoin(Planet.intel)
            Q = Q.filter(FleetScan.owner == planet)
            Q = Q.filter(FleetScan.landing_tick > tick)
            Q = Q.filter(FleetScan.mission == "Attack")
            result2 = Q.all()
            if len(result2):
                reply += " Hitting: "
                prev = []
                for fleet, nick in result2:
                    prev.append((nick or 'Unknown') + " (%s, lands: %s)" %
                                (fleet.fleet_size, fleet.landing_tick))
                reply += ', '.join(prev)
            replies.append(reply)
        if len(result) > 5:
            replies[
                -1] += " (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 37
0
    def execute(self, message, user, params):

        alliance = Alliance()
        race = None
        size_mod = None
        size = None
        value_mod = None
        value = None
        bash = False
        attacker = None
        cluster = None

        params = params.group(1).split()

        for p in params:
            m = self.bashre.match(p)
            if m and not bash:
                bash = True
                attacker = self.get_user_planet(user)
                continue
            m = self.clusterre.match(p)
            if m and not cluster:
                cluster = int(m.group(1))
            m = self.racere.match(p)
            if m and not race:
                race = m.group(1)
                continue
            m = self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod = m.group(1) or '>'
                size = m.group(2)
                continue
            m = self.rangere.match(p)
            if m and not value:
                value_mod = m.group(1) or '<'
                value = m.group(2)
                continue
            m = self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(
                    1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" %
                                  (m.group(1), ))
                    return
                continue

        Q = session.query(Planet, Intel)
        if alliance.id:
            Q = Q.join(Planet.intel)
            Q = Q.filter(Intel.alliance == alliance)
        else:
            Q = Q.outerjoin(Planet.intel)
            if alliance.name:
                Q = Q.filter(Intel.alliance == None)
        Q = Q.filter(Planet.active == True)
        Q = Q.filter(Planet.x < 200)
        if race:
            Q = Q.filter(Planet.race.ilike(race))
        if size:
            Q = Q.filter(Planet.size.op(size_mod)(size))
        if value:
            Q = Q.filter(Planet.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(
                or_(
                    Planet.value.op(">")(attacker.value *
                                         PA.getfloat("bash", "value")),
                    Planet.score.op(">")(attacker.score *
                                         PA.getfloat("bash", "score"))))
        if cluster:
            Q = Q.filter(Planet.x == cluster)
        Q = Q.order_by(desc(Planet.idle))
        Q = Q.order_by(desc(Planet.value))
        result = Q[:6]

        if len(result) < 1:
            reply = "No"
            if race:
                reply += " %s" % (race, )
            reply += " planets"
            if alliance.name:
                reply += " in intel matching Alliance: %s" % (alliance.name, )
            else:
                reply += " matching"
            if size:
                reply += " Size %s %s" % (size_mod, size)
            if value:
                reply += " Value %s %s" % (value_mod, value)
            message.reply(reply)
            return

        replies = []
        for planet, intel in result[:5]:
            reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z,
                                       planet.race)
            reply += " Value: %s Size: %s Idle: %s" % (
                planet.value, planet.size, planet.idle)
            if intel:
                if intel.nick:
                    reply += " Nick: %s" % (intel.nick, )
                if not alliance.name and intel.alliance:
                    reply += " Alliance: %s" % (intel.alliance.name, )
            replies.append(reply)
        if len(result) > 5:
            replies[
                -1] += " (Too many results to list, please refine your search)"
        message.reply("\n".join(replies))
Ejemplo n.º 38
0
 def execute(self, message, planet):
     message.reply(
         "%s:%s:%s can hit planets with value %d or above or score %d or above"
         % (planet.x, planet.y, planet.z,
            int(planet.value * PA.getfloat("bash", "value")),
            int(planet.score * PA.getfloat("bash", "score"))))
Ejemplo n.º 39
0
    def execute(self, message, user, params):

        alliance = Alliance()
        race = None
        size_mod = None
        size = None
        value_mod = None
        value = None
        bash = False
        attacker = user.planet
        cluster = None
        limit = 5

        params = params.group(1).split()

        for p in params:
            m = self.bashre.match(p)
            if m and not bash:
                bash = True
                continue
            m = self.clusterre.match(p)
            if m and not cluster:
                cluster = int(m.group(1))
            m = self.racere.match(p)
            if m and not race:
                race = m.group(1)
                continue
            m = self.rangere.match(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod = m.group(1) or '>'
                size = m.group(2)
                continue
            m = self.rangere.match(p)
            if m and not value:
                value_mod = m.group(1) or '<'
                value = m.group(2)
                continue
            m = self.alliancere.match(p)
            if m and not alliance.name and not self.clusterre.match(p):
                alliance = Alliance(name="Unknown") if m.group(
                    1).lower() == "unknown" else Alliance.load(m.group(1))
                if alliance is None:
                    message.reply("No alliance matching '%s' found" %
                                  (m.group(1), ))
                    return
                continue
            if p[:4] == "lots" and user.is_admin():
                limit = int(p[4:])

        maxcap = PA.getfloat("roids", "maxcap")
        mincap = PA.getfloat("roids", "mincap")
        modifier = (cast(Planet.value,
                         Float).op("/")(float(attacker.value))).op("^")(0.5)
        caprate = func.greatest(mincap,
                                func.least(modifier.op("*")(maxcap), maxcap))
        maxcap = cast(func.floor(cast(Planet.size, Float).op("*")(caprate)),
                      Integer)

        Q = session.query(Planet, Intel, maxcap.label("maxcap"))
        if alliance.id:
            Q = Q.join(Planet.intel)
            Q = Q.filter(Intel.alliance == alliance)
        else:
            Q = Q.outerjoin(Planet.intel)
            if alliance.name:
                Q = Q.filter(Intel.alliance == None)
        Q = Q.filter(Planet.active == True)
        if race:
            Q = Q.filter(Planet.race.ilike(race))
        if size:
            Q = Q.filter(Planet.size.op(size_mod)(size))
        if value:
            Q = Q.filter(Planet.value.op(value_mod)(value))
        if bash:
            Q = Q.filter(
                or_(
                    Planet.value.op(">")(attacker.value *
                                         PA.getfloat("bash", "value")),
                    Planet.score.op(">")(attacker.score *
                                         PA.getfloat("bash", "score"))))
        if cluster:
            Q = Q.filter(Planet.x == cluster)
        Q = Q.order_by(desc("maxcap"))
        Q = Q.order_by(desc(Planet.size))
        Q = Q.order_by(desc(Planet.value))
        result = Q[:(limit + 1)]

        if len(result) < 1:
            reply = "No"
            if race:
                reply += " %s" % (race, )
            reply += " planets"
            if alliance.name:
                reply += " in intel matching Alliance: %s" % (alliance.name, )
            else:
                reply += " matching"
            if size:
                reply += " Size %s %s" % (size_mod, size)
            if value:
                reply += " Value %s %s" % (value_mod, value)
            message.reply(reply)
            return

        replies = []
        for planet, intel, maxcap in result[:limit]:
            reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z,
                                       planet.race)
            reply += " Value: %s Size: %s MaxCap: %s" % (planet.value,
                                                         planet.size, maxcap)
            if intel:
                if intel.nick:
                    reply += " Nick: %s" % (intel.nick, )
                if not alliance.name and intel.alliance:
                    reply += " Alliance: %s" % (intel.alliance.name, )
            replies.append(reply)
            print(len(replies))
            if len(replies) == 5:
                message.reply("\n".join(replies))
                replies = []
                sleep(3)
        if len(result) > limit:
            replies.append(
                "(Too many results to list, please refine your search)")
        message.reply("\n".join(replies))