コード例 #1
0
    def robocop(self, message, scantype, pa_id, x, y, z, names):
        nicks = []
        reply = "%s on %s:%s:%s " % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        )
        reply += Config.get("URL", "viewscan") % (pa_id, )

        for name in names.split(","):
            user = User.load(name)
            for nick in CUT.get_user_nicks(name):
                nicks.append(nick)
                message.privmsg(self.url(reply, user), nick)

        reply = "%s on %s:%s:%s " % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        )
        reply += "delivered to: "
        reply += ", ".join(nicks) if not Config.getboolean(
            "Misc", "anonscans") else "Anon"
        from Hooks.scans.request import request
        message.privmsg(reply, request().scanchan())
コード例 #2
0
ファイル: afford.py プロジェクト: Hardware-Hacks/merlin
 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)
コード例 #3
0
ファイル: scan.py プロジェクト: JDD/merlin
 def planet(self, message, user, params):
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     
     # List of last 10 scans
     if params.group(6) == "o":
         scans = planet.scans.filter_by(scantype=self.type).order_by(desc(Scan.id))[:10]
         if len(scans) < 1:
             message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
             return
         prev = []
         for scan in scans:
             prev.append("(pt%s %s)" % (scan.tick, scan.pa_id,))
         reply = "Last 10 %s Scans on %s:%s:%s "%(PA.get(self.type,"name"),planet.x,planet.y,planet.z) + " ".join(prev)
         message.reply(reply)
         return
     
     # Latest scan
     scan = planet.scan(self.type)
     if scan is None:
         message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
         return
     
     # Link to scan
     if params.group(7) == "l":
         reply = "%s on %s:%s:%s " % (scan.type,planet.x,planet.y,planet.z,)
         reply+= self.url(scan.link, user)
         message.reply(reply)
         return
     
     # Display the scan
     message.reply(self.url(str(scan), user))
コード例 #4
0
ファイル: prod.py プロジェクト: wanshot/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 = 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)
コード例 #5
0
ファイル: scan.py プロジェクト: davesherratt/merlin
    def planet(self, message, user, params):
        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.reply("No planet with coords %s:%s:%s found" %
                          params.group(1, 3, 5))
            return

        # List of last 10 scans
        if params.group(6) == "o":
            scans = planet.scans.filter_by(scantype=self.type).order_by(
                desc(Scan.id))[:10]
            if len(scans) < 1:
                message.reply(
                    "No %s Scans of %s:%s:%s found" %
                    (PA.get(self.type, "name"), planet.x, planet.y, planet.z))
                return
            prev = []
            for scan in scans:
                prev.append("(pt%s %s)" % (
                    scan.tick,
                    scan.pa_id,
                ))
            reply = "Last 10 %s Scans on %s:%s:%s " % (PA.get(
                self.type,
                "name"), planet.x, planet.y, planet.z) + " ".join(prev)
            message.reply(reply)
            return

        # Latest scan
        scan = planet.scan(self.type)
        if scan is None:
            message.reply(
                "No %s Scans of %s:%s:%s found" %
                (PA.get(self.type, "name"), planet.x, planet.y, planet.z))
            return

        # Link to scan
        if params.group(7) == "l":
            reply = "%s on %s:%s:%s " % (
                scan.type,
                planet.x,
                planet.y,
                planet.z,
            )
            reply += self.url(scan.link, user)
            message.reply(reply)
            return

        # Display the scan
        message.reply(self.url(str(scan), user))
コード例 #6
0
ファイル: scans.py プロジェクト: JDD/DLR
 def robocop(self, message, scantype, pa_id, x, y, z, names):
     nicks = []
     [nicks.extend(nick) for nick in [CUT.list_user_nicks(name) for name in names.split(",")]]
     
     reply = "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     reply+= Config.get("URL","viewscan") % (pa_id,)
     for nick in nicks:
         message.privmsg(reply, nick)
     
     reply = "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     reply+= "delivered to: "
     reply+= ", ".join(nicks)
     from Hooks.scans.request import request
     message.privmsg(reply, request().scanchan())
コード例 #7
0
ファイル: rprod.py プロジェクト: 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)
コード例 #8
0
ファイル: scans.py プロジェクト: berten/merlin
    def robocop(self,
                message,
                scantype,
                pa_id,
                x,
                y,
                z,
                names,
                scanner,
                reqs,
                old=False):
        nicks = []
        reply = "Old " if old else ""
        reply += "%s on %s:%s:%s " % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        )
        if ("showscanner" in Config.options("Misc")
                and Config.getboolean("Misc", "showscanner")
                and scanner != 'None'):
            reply += "from %s " % (User.load(id=scanner).name) if User.load(
                id=scanner) not in (None, 'None') else ""
        reply += Config.get("URL", "viewscan") % (pa_id, )
        if old:
            reply += " !request cancel %s if this is suitable." % (reqs)

        for name in names.split(","):
            user = User.load(name)
            for nick in CUT.get_user_nicks(name):
                nicks.append(nick)
                message.privmsg(self.url(reply, user), nick)

        if not old:
            reply = "[-%s] %s on %s:%s:%s " % (
                reqs,
                PA.get(scantype, "name"),
                x,
                y,
                z,
            )
            reply += "delivered to: "
            reply += ", ".join(nicks) if not Config.getboolean(
                "Misc", "anonscans") else "Anon"
            if Config.getboolean("Misc", "showurls"):
                reply += " (%s)" % (Config.get("URL", "viewscan") % (pa_id, ))
            from Hooks.scans.request import request
            message.privmsg(reply, request().scanchan())
コード例 #9
0
ファイル: scan.py プロジェクト: Go3Media/merlin
 def execute(self, message, user, params):
     
     # Planet
     if len(params.groups()) > 1:
         planet = Planet.load(*params.group(1,3,5))
         if planet is None:
             message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
             return
         
         # List of last 10 scans
         if params.group(6) == "o":
             scans = planet.scans.filter_by(scantype=self.type).order_by(desc(Scan.id))[:10]
             if len(scans) < 1:
                 message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
                 return
             prev = []
             for scan in scans:
                 prev.append("(pt%s %s)" % (scan.tick, scan.pa_id,))
             reply = "Last 10 %s Scans on %s:%s:%s "%(PA.get(self.type,"name"),planet.x,planet.y,planet.z) + " ".join(prev)
             message.reply(reply)
             return
         
         # Latest scan
         scan = planet.scan(self.type)
         if scan is None:
             message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
             return
         
         # Link to scan
         if params.group(7) == "l":
             reply = "%s on %s:%s:%s " % (PA.get(self.type,"name"),planet.x,planet.y,planet.z,)
             reply+= Config.get("URL","viewscan") % (scan.pa_id,)
             message.reply(reply)
             return
         
         # Display the scan
         message.reply(str(scan))
     
     # ID
     else:
         Q = session.query(Scan)
         Q = Q.filter(Scan.pa_id.ilike("%"+params.group(1)+"%"))
         Q = Q.order_by(desc(Scan.id))
         scan = Q.first()
         if scan is None:
             message.reply("No Scans matching ID '%s'"%(params.group(1),))
             return
         # Display the scan
         message.reply(str(scan))
コード例 #10
0
ファイル: cost.py プロジェクト: 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)
コード例 #11
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)
コード例 #12
0
ファイル: roidcost.py プロジェクト: 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)
コード例 #13
0
ファイル: maps.py プロジェクト: munin/merlin
 def link(self):
     return Config.get("URL", "reqscan") % (
         PA.get(self.scantype, "type"),
         self.target.x,
         self.target.y,
         self.target.z,
     )
コード例 #14
0
ファイル: scans.py プロジェクト: Hardware-Hacks/merlin
 def robocop(self, message, scantype, pa_id, x, y, z, names):
     nicks = []
     reply = "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     reply+= Config.get("URL","viewscan") % (pa_id,)
     
     for name in names.split(","):
         user = User.load(name)
         for nick in CUT.get_user_nicks(name):
             nicks.append(nick)
             message.privmsg(self.url(reply, user), nick)
     
     reply = "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     reply+= "delivered to: "
     reply+= ", ".join(nicks) if not Config.getboolean("Misc", "anonscans") else "Anon"
     from Hooks.scans.request import request
     message.privmsg(reply, request().scanchan())
コード例 #15
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)
コード例 #16
0
ファイル: prod.py プロジェクト: 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)
コード例 #17
0
ファイル: rprod.py プロジェクト: Go3Media/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 = 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)
コード例 #18
0
ファイル: scans.py プロジェクト: JDD/merlin
 def robocop(self, message, scantype, pa_id, x, y, z, names, scanner, reqs, old=False):
     nicks = []
     reply = "Old " if old else ""
     reply += "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     if ("showscanner" in Config.options("Misc") and Config.getboolean("Misc", "showscanner") and scanner != 'None'):
         reply+= "from %s " % (User.load(id=scanner).name) if User.load(id=scanner) not in (None, 'None') else ""
     reply += Config.get("URL","viewscan") % (pa_id,)
     if old:
         reply += " !request cancel %s if this is suitable." % (reqs)
     
     for name in names.split(","):
         user = User.load(name)
         for nick in CUT.get_user_nicks(name):
             nicks.append(nick)
             message.privmsg(self.url(reply, user), nick)
     
     if not old:
         reply = "[-%s] %s on %s:%s:%s " % (reqs,PA.get(scantype,"name"),x,y,z,)
         reply+= "delivered to: "
         reply+= ", ".join(nicks) if not Config.getboolean("Misc", "anonscans") else "Anon"
         if Config.getboolean("Misc", "showurls"):
             reply += " (%s)" % (Config.get("URL","viewscan") % (pa_id,))
         from Hooks.scans.request import request
         message.privmsg(reply, request().scanchan())
コード例 #19
0
ファイル: roidsave.py プロジェクト: munin/merlin
    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)
コード例 #20
0
ファイル: maps.py プロジェクト: Go3Media/merlin
 def __str__(self):
     p = self.planet
     ph = p.history(self.tick)
     
     head = "%s on %s:%s:%s " % (PA.get(self.scantype,"name"),p.x,p.y,p.z,)
     if self.scantype in ("P","D","J","N",):
         id_tick = "(id: %s, pt: %s)" % (self.pa_id,self.tick,)
     if self.scantype in ("U","A",):
         vdiff = p.value-ph.value if ph else None
         id_age_value = "(id: %s, age: %s, value diff: %s)" % (self.pa_id,Updates.current_tick()-self.tick,vdiff)
     
     if self.scantype in ("P",):
         return head + id_tick + str(self.planetscan)
     if self.scantype in ("D",):
         return head + id_tick + str(self.devscan)
     if self.scantype in ("U","A",):
         return head + id_age_value + " " + " | ".join(map(str,self.units))
     if self.scantype == "J":
         return head + id_tick + " " + " | ".join(map(str,self.fleets))
     if self.scantype == "N":
         return head + Config.get("URL","viewscan") % (self.pa_id,)
コード例 #21
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)
コード例 #22
0
ファイル: request.py プロジェクト: liam-wiltshire/merlin
    def execute(self, message, user, params):
        tick = Updates.current_tick()
        # Galaxy Scan
        if params.group(5) is None:

            #            Access Control:
            #            Uncomment this and change "group" to the lowest group that can request galscans.
            #            if not user.is_group():
            #                message.alert("Insufficient access for galaxy scans.")
            #                return

            galaxy = Galaxy.load(*params.group(1, 3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" % params.group(1, 3))
                return
            planets = galaxy.planets
            galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans")
        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
            planets = [planet]
            galscan = False

        # Scan Quota
        if Config.has_section("ScanQuota"):
            opts = Config.options("ScanQuota")
            q = []
            for o in opts:
                if int(o) >= user.access:
                    q.append(int(o))
            if q:
                ScanQuota = Config.getint("ScanQuota", str(min(q)))
                reqs = (
                    session.query(Request.id)
                    .filter(Request.requester_id == user.id)
                    .filter(Request.tick == tick)
                    .count()
                )
                if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota:
                    message.reply(
                        "This request will exceed your scan quota for this tick (%d scans remaining). "
                        % (ScanQuota - reqs)
                        + "Try searching with !planet, !dev, !unit, !news, !jgp, !au."
                    )
                    return

        dists = int(params.group(7) or 0)
        galdists = []

        mergescans = (not galscan) and (
            Config.has_option("Misc", "maxscans")
            and len(planets) * len(params.group(6)) > Config.getint("Misc", "maxscans")
        )

        for planet in planets:
            if galscan or mergescans:
                galdists.append(planet.intel.dists if planet.intel else 0)
                if len(galdists) < len(planets):
                    continue
            types = 0
            for scantype in params.group(6).upper():
                # Reject requests for incoming scans
                if not PA.getboolean(scantype, "request"):
                    message.alert("%s scans cannot be requested." % (PA.get(scantype, "name")))
                    continue
                types += 1
                if galscan or mergescans:
                    # Request the scans
                    for i in range(len(planets)):
                        request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans)
                    # Inform the requester
                    if galscan and (message.get_chan() != self.scanchan()):
                        message.reply(
                            "Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request."
                            % (request.type, planet.x, planet.y, request.id - len(planets) + 1, request.id)
                        )
                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scantype, "expire"):
                        message.reply(
                            "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable."
                            % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id)
                        )
                        # Cancel requests with a 0-tick old scan, if required
                        if request.tick == scan.tick:
                            req0age = (
                                Config.getint("Misc", "req0agej")
                                if request.scantype == "J"
                                else Config.getint("Misc", "req0age")
                            )
                            if req0age == 1:
                                Q = (
                                    session.query(Request)
                                    .filter(Request.tick == request.tick)
                                    .filter(Request.planet_id == request.planet_id)
                                )
                                Q = Q.filter(Request.scantype == request.scantype).filter(
                                    Request.requester_id == request.requester_id
                                )
                                if Q.count() == 1:
                                    request.active = False
                                    message.reply(
                                        "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request."
                                        % (request.id)
                                    )
                                    message.privmsg(
                                        "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                    )
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg(
                                    "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                )

                    # Tell the scanners
                    requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
                    if galscan:
                        message.privmsg(
                            "[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) "
                            % (
                                request.id - len(planets) + 1,
                                request.id,
                                requester,
                                request.type,
                                planet.x,
                                planet.y,
                                max(galdists),
                                "/r:%s" % dists if dists > 0 else "",
                            )
                            + Config.get("URL", "reqgscan") % (planet.x, planet.y),
                            self.scanchan(),
                        )
                else:
                    request = self.request(message, user, planet, scantype, dists)
                    if message.get_chan() != self.scanchan():
                        message.reply(
                            "Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request."
                            % (request.type, planet.x, planet.y, planet.z, request.id)
                        )

                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scan.scantype, "expire"):
                        message.reply(
                            "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable."
                            % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id)
                        )
                        # Cancel requests with a 0-tick old scan, if required
                        if request.tick == scan.tick:
                            req0age = (
                                Config.getint("Misc", "req0agej")
                                if request.scantype == "J"
                                else Config.getint("Misc", "req0age")
                            )
                            if req0age == 1:
                                Q = (
                                    session.query(Request)
                                    .filter(Request.tick == request.tick)
                                    .filter(Request.planet_id == request.planet_id)
                                )
                                Q = Q.filter(Request.scantype == request.scantype).filter(
                                    Request.requester_id == request.requester_id
                                )
                                if Q.count() == 1:
                                    request.active = False
                                    message.reply(
                                        "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request."
                                        % (request.id)
                                    )
                                    message.privmsg(
                                        "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                    )
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg(
                                    "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                )

            if mergescans:
                message.reply(
                    "Requested %d scans. !request cancel %s:%s to cancel the request."
                    % (len(planets) * types, request.id - len(planets) * types + 1, request.id)
                )
                message.privmsg(
                    "[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details "
                    % (
                        request.id - len(planets) * types + 1,
                        request.id,
                        requester,
                        len(planets) * types,
                        params.group(6).upper(),
                        max(galdists),
                        "/r:%s" % dists if dists > 0 else "",
                    ),
                    self.scanchan(),
                )
        session.commit()
コード例 #23
0
ファイル: maps.py プロジェクト: munin/merlin
 def type(self):
     return PA.get(self.scantype, "name")
コード例 #24
0
ファイル: request.py プロジェクト: Go3Media/merlin
 def execute(self, message, user, params):
     
     if params.group(1).lower() == "cancel":
         request = Request.load(params.group(2))
         return
     
     planet = Planet.load(*params.group(2,4,6))
     if planet is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(2,4,6))
         return
     
     scan = params.group(1).upper()
     
     request = Request(target=planet, scantype=scan)
     request.dists = int(params.group(7) or 0)
     user.requests.append(request)
     session.commit()
     
     dists_intel = planet.intel.dists if planet.intel else 0
     dists_request = request.dists
     
     message.reply("Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (PA.get(scan, "name"), planet.x, planet.y, planet.z, request.id,))
     self.request(message, request.id, user.name, scan, planet.x, planet.y, planet.z, dists_intel, dists_request)
     return
コード例 #25
0
ファイル: request.py プロジェクト: Go3Media/merlin
 def request(self, message, id, name, scan, x,y,z, dists_intel, dists_request):
     scannerchan = Config.get("Channels", "scans") if "scans" in Config.options("Channels") else Config.get("Channels", "home")
     message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s/r:%s) " % (id, name, PA.get(scan, "name"), x,y,z, dists_intel, dists_request,) + Config.get("URL", "reqscan") % (PA.get(scan, "type"),x,y,z,), scannerchan)
コード例 #26
0
ファイル: parser.py プロジェクト: liam-wiltshire/merlin
                scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
            return

        if planet is None:
            scanlog("No planet found. Check the bot is ticking. Scan will be tried again at next tick.")
            return
        
        scanlog("%s %s:%s:%s" %(PA.get(scantype,"name"), x,y,z,))
        
        parser = {
                  "P": self.parse_P,
                  "D": self.parse_D,
                  "U": self.parse_U,
                  "A": self.parse_U,
                  "J": self.parse_J,
                  "N": self.parse_N,
                 }.get(scantype)
        if parser is not None:
            parser(scan_id, scan, page)
        
        Q = session.query(Request)
        Q = Q.filter(Request.scantype==scantype)
        Q = Q.filter(Request.target==planet)
コード例 #27
0
ファイル: scans.py プロジェクト: Go3Media/merlin
 def robocop(self, message, scantype, pa_id, x, y, z, names):
     reply = "%s on %s:%s:%s " % (PA.get(scantype,"name"),x,y,z,)
     reply+= Config.get("URL","viewscan") % (pa_id,)
     for name in names.split(","):
         for nick in CUT.list_user_nicks(name):
             message.privmsg(reply, nick)
コード例 #28
0
ファイル: afford.py プロジェクト: wanshot/merlin
    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)
コード例 #29
0
ファイル: parser.py プロジェクト: munin/merlin
     print "Scan %s may already exist" %(pa_id,)
     print e.__str__()
     return
 
 parser = {
           "P": self.parse_P,
           "D": self.parse_D,
           "U": self.parse_U,
           "A": self.parse_U,
           "J": self.parse_J,
           "N": self.parse_N,
          }.get(scantype)
 if parser is not None:
     parser(scan_id, scan, page)
 
 print PA.get(scantype,"name"), "%s:%s:%s" % (x,y,z,)
 
 Q = session.query(Request)
 Q = Q.filter(Request.scantype==scantype)
 Q = Q.filter(Request.target==planet)
 Q = Q.filter(Request.scan==None)
 Q = Q.filter(Request.active==True)
 result = Q.all()
 
 users = []
 for request in result:
     request.scan_id = scan_id
     request.active = False
     users.append(request.user.name)
 session.commit()
 
コード例 #30
0
ファイル: covop.py プロジェクト: d7415/merlin
    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)))
コード例 #31
0
ファイル: parser.py プロジェクト: berten/merlin
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return

        if planet is None:
            scanlog(
                "No planet found. Check the bot is ticking. Scan will be tried again at next tick."
            )
            return

        scanlog("%s %s:%s:%s" % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        ))

        parser = {
            "P": self.parse_P,
            "D": self.parse_D,
            "U": self.parse_U,
            "A": self.parse_U,
            "J": self.parse_J,
            "N": self.parse_N,
        }.get(scantype)
        if parser is not None:
            parser(scan_id, scan, page)
コード例 #32
0
import sys
import urllib2
from sqlalchemy.sql import text
from Core.config import Config
from Core.paconf import PA
from Core.db import true, false, session
from Core.maps import Ship

useragent = "Merlin (Python-urllib/%s); Alliance/%s; BotNick/%s; Admin/%s" % (
    urllib2.__version__, Config.get("Alliance", "name"),
    Config.get("Connection", "nick"), Config.items("Admins")[0][0])

regex = r'^<tr class="('
races = []
for race in PA.options("races"):
    races.append(PA.get(race, "name"))
regex += "|".join(races)
regex += ')">.+?>([^<]+)</td>'  # race & name
regex += r'<td>(\w+)</td>'  # class
regex += r'(?:<td>(\w\w|\-)</td>)?' * 3  # t1,t2,t3
regex += r'<td>(\w+)</td>'  # type
regex += r'.+?(\d+|\-)</td>' * 8  # some numbers
regex += r'.+?</tr>$'  # end of the line
sre = re.compile(regex, re.I | re.M)

mapping = {
    "Fi": "Fighter",
    "Co": "Corvette",
    "Fr": "Frigate",
    "De": "Destroyer",
    "Cr": "Cruiser",
コード例 #33
0
ファイル: covop.py プロジェクト: berten/merlin
    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)))
コード例 #34
0
ファイル: shipstats.py プロジェクト: TBBTNut/merlin
import re
import sys
import urllib2
from sqlalchemy.sql import text
from Core.config import Config
from Core.paconf import PA
from Core.db import true, false, session
from Core.maps import Ship

useragent = "Merlin (Python-urllib/%s); Alliance/%s; BotNick/%s; Admin/%s" % (urllib2.__version__, Config.get("Alliance", "name"), 
                                                                              Config.get("Connection", "nick"), Config.items("Admins")[0][0])

regex = r'^<tr class="('
races = []
for race in PA.options("races"):
    races.append(PA.get(race, "name"))
regex += "|".join(races)
regex += ')">.+?>([^<]+)</td>' # race & name
regex += r'<td>(\w+)</td>' # class
regex += r'(?:<td>(\w\w|\-)</td>)?'*3 # t1,t2,t3
regex += r'<td>(\w+)</td>' # type
regex += r'.+?(\d+|\-)</td>'*8 # some numbers
regex += r'.+?</tr>$' # end of the line
sre = re.compile(regex,re.I|re.M)

mapping = { "Fi": "Fighter",
            "Co": "Corvette",
            "Fr": "Frigate",
            "De": "Destroyer",
            "Cr": "Cruiser",
            "Bs": "Battleship",
コード例 #35
0
    def execute(self, message, user, params):
        tick = Updates.current_tick()
        # Galaxy Scan
        if params.group(5) is None:

#            Access Control:
#            Uncomment this and change "group" to the lowest group that can request galscans.
#            if not user.is_group():
#                message.alert("Insufficient access for galaxy scans.")
#                return

            galaxy = Galaxy.load(*params.group(1,3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" % params.group(1,3))
                return
            planets = galaxy.planets
            galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans")
        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
            planets = [planet]
            galscan = False

        # Scan Quota
        if Config.has_section("ScanQuota"):
            opts = Config.options("ScanQuota") 
            q = []
            for o in opts:
                if int(o) >= user.access:
                    q.append(int(o))
            if q:
                ScanQuota = Config.getint("ScanQuota", str(min(q)))
                reqs = session.query(Request.id).filter(Request.requester_id == user.id).filter(Request.tick == tick).count()
                if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota:
                    message.reply("This request will exceed your scan quota for this tick (%d scans remaining). " % (ScanQuota - reqs) +\
                                  "Try searching with !planet, !dev, !unit, !news, !jgp, !au.")
                    return

        dists = int(params.group(7) or 0)
        galdists = []

        mergescans = (not galscan) and (Config.has_option("Misc", "maxscans") and len(planets)*len(params.group(6)) > Config.getint("Misc", "maxscans"))

        for planet in planets:
            if galscan or mergescans:
                galdists.append(planet.intel.dists if planet.intel else 0)
                if len(galdists) < len(planets):
                    continue
            types = 0
            for scantype in params.group(6).upper():
                # Reject requests for incoming scans
                if not PA.getboolean(scantype, "request"):
                    message.alert("%s scans cannot be requested." % (PA.get(scantype, "name")))
                    continue
                types += 1
                if galscan or mergescans:
                    # Request the scans
                    for i in range(len(planets)):
                        request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans)
                    # Inform the requester    
                    if galscan and (message.get_chan() != self.scanchan()):
                        message.reply("Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request." % (request.type, planet.x, planet.y, 
                                                                                                                             request.id-len(planets)+1, request.id))
                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scantype,"expire"):
                        message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (
                                                                        scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,))
                        # Cancel requests with a 0-tick old scan, if required
                        if (request.tick == scan.tick):
                            req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age")
                            if req0age == 1:
                               Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id)
                               Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id)
                               if Q.count() == 1:
                                   request.active = False
                                   message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id))
                                   message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())

                    # Tell the scanners
                    requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
                    if galscan:
                        message.privmsg("[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) " % (request.id-len(planets)+1, request.id, requester, 
                                        request.type, planet.x, planet.y, max(galdists), 
                                        "/r:%s" % dists if dists > 0 else "") + Config.get("URL", "reqgscan") % (planet.x, planet.y) , self.scanchan())
                else:
                    request = self.request(message, user, planet, scantype, dists)
                    if message.get_chan() != self.scanchan():
                        message.reply("Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (request.type, planet.x, planet.y, planet.z, request.id,))

                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scan.scantype,"expire"):
                        message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (
                                                                        scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,))
                        # Cancel requests with a 0-tick old scan, if required
                        if (request.tick == scan.tick):
                            req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age")
                            if req0age == 1:
                               Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id)
                               Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id)
                               if Q.count() == 1:
                                   request.active = False
                                   message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id))
                                   message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())

            if mergescans:
                message.reply("Requested %d scans. !request cancel %s:%s to cancel the request." % (len(planets) * types, request.id-len(planets)*types+1, request.id))
                message.privmsg("[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details " % (request.id-len(planets)*types+1, request.id, 
                                requester, len(planets)*types, params.group(6).upper(), max(galdists), "/r:%s" % dists if dists > 0 else ""), self.scanchan())
        session.commit()