예제 #1
0
파일: tick.py 프로젝트: berten/merlin
 def tick(self, message, user, params):
     tick = Updates.load(params.group(1)) or Updates.current_tick()
     if isinstance(tick, Updates): # We have that tick
         message.reply(str(tick))
     elif tick == 0:               # We don't have any ticks
         ticktime = GameSetup.getint("round_start_time") + (int(params.group(1))-1)*GameSetup.getint("tick_speed")
         tdiff = int(ticktime - time.time())
         tdelta = abs(tdiff / 86400)
         retstr  = " %sd" % tdelta if tdelta else ""
         tdelta = (tdiff % 86400) / 3600
         retstr += " %sh" % tdelta if tdelta else ""
         tdelta = (tdiff % 3600) / 60
         retstr += " %sm" % tdelta if tdelta else ""
         retstr = "Tick %s %s expected to happen%s%s%s - %s" % (params.group(1), "is" if tdiff >= 0 else "was", " in" if tdiff >= 0 else "", retstr, " ago" if tdiff < 0 else "", datetime.utcfromtimestamp(float(ticktime)).strftime("%a %d/%m %H:%M UTC"))
         message.reply(retstr)
     else:                         # We have some ticks, but not that one
         diff = int(params.group(1)) - tick
         now = datetime.utcnow()
         tick_speed = GameSetup.getint("tick_speed")
         tdiff = timedelta(seconds=tick_speed*diff)-timedelta(minutes=now.minute%(tick_speed/60))
         retstr  = "%sd " % abs(tdiff.days) if tdiff.days else ""
         retstr += "%sh " % abs(tdiff.seconds/3600) if tdiff.seconds/3600 else ""
         retstr += "%sm " % abs(tdiff.seconds%3600/60) if tdiff.seconds%3600/60 else ""
             
         if diff == 1:
             retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
         elif diff > 1:
             retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr)
         elif diff <= 0:
             retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (params.group(1), -diff, retstr)
         
         ticktime = now + tdiff
         retstr += " - %s)" % (ticktime.strftime("%a %d/%m %H:%M UTC"),)
         message.reply(retstr)
예제 #2
0
파일: tick.py 프로젝트: JohnCashmore/merlin
 def tick(self, message, user, params):
     tick = Updates.load(params.group(1)) or Updates.current_tick()
     if tick is None:
         message.reply("Ticks haven't started yet, go back to masturbating.")
     elif isinstance(tick, Updates):
         message.reply(str(tick))
     else:
         diff = int(params.group(1)) - tick
         now = datetime.utcnow()
         tick_length = PA.getint("numbers", "tick_length")
         tdiff = timedelta(seconds=tick_length*diff)-timedelta(minutes=now.minute%(tick_length/60))
         seconds = 0
         retstr  = "%sd " % abs(tdiff.days) if tdiff.days else ""
         retstr += "%sh " % abs(tdiff.seconds/3600) if tdiff.seconds/3600 else ""
         retstr += "%sm " % abs(tdiff.seconds%3600/60) if tdiff.seconds%3600/60 else ""
             
         if diff == 1:
             retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
         elif diff > 1:
             retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr)
         elif diff <= 0:
             retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (params.group(1), -diff, retstr)
         
         time = now + tdiff
         retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"),)
         message.reply(retstr)
예제 #3
0
    def tick(self, message, user, params):
        tick = Updates.load(params.group(1)) or Updates.current_tick()
        if tick is None:
            message.reply("Ticks haven't started yet, go back to masturbating.")
        elif isinstance(tick, Updates):
            message.reply(str(tick))
        else:
            diff = int(params.group(1)) - tick
            now = datetime.utcnow()
            tick_length = PA.getint("numbers", "tick_length")
            tdiff = timedelta(seconds=tick_length * diff) - timedelta(minutes=now.minute % (tick_length / 60))
            seconds = 0
            retstr = "%sd " % abs(tdiff.days) if tdiff.days else ""
            retstr += "%sh " % abs(tdiff.seconds / 3600) if tdiff.seconds / 3600 else ""
            retstr += "%sm " % abs(tdiff.seconds % 3600 / 60) if tdiff.seconds % 3600 / 60 else ""

            if diff == 1:
                retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
            elif diff > 1:
                retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr)
            elif diff <= 0:
                retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (
                    params.group(1),
                    -diff,
                    retstr,
                )

            time = now + tdiff
            retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"),)
            message.reply(retstr)
예제 #4
0
 def current(self, message, user, params):
     tick = Updates.load()
     if tick is None:
         message.reply(
             "Ticks haven't started yet, go back to masturbating.")
     else:
         message.reply(str(tick))
예제 #5
0
 def tick(self, message, user, params):
     tick = Updates.load(params.group(1)) or Updates.current_tick()
     if tick is None:
         message.reply("Ticks haven't started yet, go back to masturbating.")
     elif isinstance(tick, Updates):
         message.reply(str(tick))
     else:
         diff = int(params.group(1)) - tick
         now = datetime.utcnow()
         seconds = 0
         retstr = ""
         if diff > 0:
             
             if diff > 24:
                 days = (diff-1)/24
                 seconds += days*24*60*60
                 retstr += "%sd " % (days,)
             
             if diff > 1:
                 hours = (diff-1)%24
                 seconds += hours*60*60
                 retstr += "%sh " % (hours,)
             
             mins = 60 - now.minute
             seconds += mins *60
             retstr += "%sm" % (mins,)
             
             if diff == 1:
                 retstr = "Next tick is %s (in %s" % (params.group(1), retstr,)
             else:
                 retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr,)
         
         elif diff < 0:
             
             if diff < -23:
                 days = (-diff)/24
                 seconds -= days*24*60*60
                 retstr += "%sd " % (days,)
                 
             if diff < -1:
                 hours = (-diff)%24
                 seconds -= hours*60*60
                 retstr += "%sh " % (hours,)
                 
             mins = now.minute
             seconds -= mins*60
             retstr += "%sm" % (mins,)
             
             if diff == -1:
                 retstr = "Last tick was %s (%s ago" % (params.group(1), retstr,)
             else:
                 retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (params.group(1), -diff, retstr,)
         
         time = now + timedelta(seconds=seconds)
         retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"),)
         message.reply(retstr)
예제 #6
0
파일: tick.py 프로젝트: berten/merlin
 def current(self, message, user, params):
     tick = Updates.load()
     if tick is None:
         if time.time() > GameSetup.getint("round_start_time"):
             tdiff = abs(int(GameSetup.getint("round_start_time") - time.time())) / GameSetup.getint("tick_speed") + 1
             message.reply("It *should* be tick %s, but I'm not ticking. Did someone forget to press the magic button?" % tdiff)
             if tdiff > 1:
                 admin_msg("It should be tick %s, but I'm not ticking!" % tdiff)
         else:
             message.reply("Ticks haven't started yet, go back to masturbating.")
     else:
         message.reply(str(tick))
예제 #7
0
def base_context(request):
    context = {"name"   : Config.get("Alliance", "name"),
               "slogan" : Config.get("Alliance", "name"),
               "tick"   : Updates.current_tick(),
               "update" : Updates.load(),
               }
    if getattr(request, "user", None) is not None:
        context["user"] = request.user
        context["menu"] = menu.generate(request.user)
    if getattr(request, "session", None) is not None:
        slogan, count = Slogan.search("")
        if slogan is not None:
            context["slogan"] = str(slogan)
    return context
예제 #8
0
파일: context.py 프로젝트: wanshot/merlin
def base_context(request):
    context = {
        "name": Config.get("Alliance", "name"),
        "slogan": Config.get("Alliance", "name"),
        "tick": Updates.current_tick(),
        "update": Updates.load(),
        "graphs": Config.get("Misc", "graphing") != "disabled",
    }
    if getattr(request, "user", None) is not None:
        context["user"] = request.user
        context["menu"] = menu.generate(request.user)
    if getattr(request, "session", None) is not None:
        slogan, count = Slogan.search("")
        if slogan is not None:
            context["slogan"] = str(slogan)
    return context
예제 #9
0
def base_context(request):
    context = {"name"   : Config.get("Alliance", "name"),
               "slogan" : Config.get("Alliance", "name"),
               "tick"   : Updates.current_tick(),
               "update" : Updates.load(),
               "graphs" : Config.get("Misc", "graphing") != "disabled",
               }
    if getattr(request, "user", None) is not None:
        context["user"] = request.user
        context["menu"] = menu.generate(request.user)
    if getattr(request, "session", None) is not None:
        slogan, count = Slogan.search("")
        if slogan is not None:
            context["slogan"] = str(slogan)
    if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"):
        context["fluxurl"] = "<br><br><a href=\"%s\">Forum</a>" % (Config.get("FluxBB", "url"))
    return context
예제 #10
0
파일: tick.py 프로젝트: berten/merlin
 def current(self, message, user, params):
     tick = Updates.load()
     if tick is None:
         if time.time() > GameSetup.getint("round_start_time"):
             tdiff = abs(
                 int(GameSetup.getint("round_start_time") -
                     time.time())) / GameSetup.getint("tick_speed") + 1
             message.reply(
                 "It *should* be tick %s, but I'm not ticking. Did someone forget to press the magic button?"
                 % tdiff)
             if tdiff > 1:
                 admin_msg("It should be tick %s, but I'm not ticking!" %
                           tdiff)
         else:
             message.reply(
                 "Ticks haven't started yet, go back to masturbating.")
     else:
         message.reply(str(tick))
예제 #11
0
파일: tick.py 프로젝트: berten/merlin
    def tick(self, message, user, params):
        tick = Updates.load(params.group(1)) or Updates.current_tick()
        if isinstance(tick, Updates):  # We have that tick
            message.reply(str(tick))
        elif tick == 0:  # We don't have any ticks
            ticktime = GameSetup.getint("round_start_time") + (
                int(params.group(1)) - 1) * GameSetup.getint("tick_speed")
            tdiff = int(ticktime - time.time())
            tdelta = abs(tdiff / 86400)
            retstr = " %sd" % tdelta if tdelta else ""
            tdelta = (tdiff % 86400) / 3600
            retstr += " %sh" % tdelta if tdelta else ""
            tdelta = (tdiff % 3600) / 60
            retstr += " %sm" % tdelta if tdelta else ""
            retstr = "Tick %s %s expected to happen%s%s%s - %s" % (
                params.group(1), "is" if tdiff >= 0 else "was", " in"
                if tdiff >= 0 else "", retstr, " ago" if tdiff < 0 else "",
                datetime.utcfromtimestamp(
                    float(ticktime)).strftime("%a %d/%m %H:%M UTC"))
            message.reply(retstr)
        else:  # We have some ticks, but not that one
            diff = int(params.group(1)) - tick
            now = datetime.utcnow()
            tick_speed = GameSetup.getint("tick_speed")
            tdiff = timedelta(seconds=tick_speed * diff) - timedelta(
                minutes=now.minute % (tick_speed / 60))
            retstr = "%sd " % abs(tdiff.days) if tdiff.days else ""
            retstr += "%sh " % abs(tdiff.seconds /
                                   3600) if tdiff.seconds / 3600 else ""
            retstr += "%sm " % abs(tdiff.seconds % 3600 /
                                   60) if tdiff.seconds % 3600 / 60 else ""

            if diff == 1:
                retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
            elif diff > 1:
                retstr = "Tick %s is expected to happen in %s ticks (in %s" % (
                    params.group(1), diff, retstr)
            elif diff <= 0:
                retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (
                    params.group(1), -diff, retstr)

            ticktime = now + tdiff
            retstr += " - %s)" % (ticktime.strftime("%a %d/%m %H:%M UTC"), )
            message.reply(retstr)
예제 #12
0
def base_context(request):
    context = {
        "name": Config.get("Alliance", "name"),
        "slogan": Config.get("Alliance", "name"),
        "tick": Updates.current_tick(),
        "update": Updates.load(),
        "graphs": Config.get("Misc", "graphing") != "disabled",
    }
    if getattr(request, "user", None) is not None:
        context["user"] = request.user
        context["menu"] = menu.generate(request.user)
    if getattr(request, "session", None) is not None:
        slogan, count = Slogan.search("")
        if slogan is not None:
            context["slogan"] = str(slogan)
    if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"):
        context["fluxurl"] = "<br><br><a href=\"%s\">Forum</a>" % (Config.get(
            "FluxBB", "url"))
    return context
예제 #13
0
    def execute(self, message, alliance=None, race=None, sortby="score"):
        planet = aliased(Planet)
        planet_intel = aliased(Intel)

        Q = session.query(planet.x, planet.y, planet.z, planet.score,
                          planet.value, planet.size, planet.xp, planet.race,
                          planet_intel.nick)
        Q = Q.join((planet.intel, planet_intel))
        if alliance:
            Q = Q.filter(planet_intel.alliance == alliance)
        if race:
            Q = Q.filter(planet.race == race)
        Q = Q.group_by(planet.x, planet.y, planet.z, planet.score,
                       planet.value, planet.size, planet.xp, planet.race,
                       planet_intel.nick)
        if sortby == "xp":
            Q = Q.order_by(asc(planet.xp))
        elif sortby == "size":
            Q = Q.order_by(asc(planet.size))
        elif sortby == "value":
            Q = Q.order_by(asc(planet.value))
        else:
            Q = Q.order_by(asc(planet.score))
        result = Q.all()

        reply = "Bottom%s planets" % (" " + race if race is not None else "")
        if alliance:
            reply += " in %s" % (alliance.name, )
        reply += " by %s:\n" % (sortby)
        prev = []
        if alliance:
            i = alliance.members  # Not set for some reason... It should be.
        else:
            i = Updates.load().planets
        for x, y, z, score, value, size, xp, race, nick in result[:10]:
            i -= 1
            line = "#%s - %s:%s:%s (%s) - Score: %s Value: %s Size: %s XP: %s" % (
                i, x, y, z, race, score, value, size, xp)
            if nick:
                line = "%s Nick: %s" % (line, nick)
            prev.append(line)
        message.reply(reply + "\n".join(prev))
예제 #14
0
파일: last10.py 프로젝트: JDD/merlin
    def execute(self, message, alliance=None, race=None, sortby="score"):
        planet = aliased(Planet)
        planet_intel = aliased(Intel)
        

        Q = session.query(planet.x, planet.y, planet.z, planet.score, planet.value, planet.size, planet.xp, planet.race, planet_intel.nick)
        Q = Q.join((planet.intel, planet_intel))
        if alliance:
            Q = Q.filter(planet_intel.alliance == alliance)
        if race:
            Q = Q.filter(planet.race == race)
        Q = Q.group_by(planet.x, planet.y, planet.z, planet.score, planet.value, planet.size, planet.xp, planet.race, planet_intel.nick)
        if sortby == "xp":
            Q = Q.order_by(asc(planet.xp))
        elif sortby == "size":
            Q = Q.order_by(asc(planet.size))
        elif sortby == "value":
            Q = Q.order_by(asc(planet.value))
        else:
            Q = Q.order_by(asc(planet.score))
        result = Q.all()
        
        reply = "Bottom%s planets" % (" "+race if race is not None else "")
        if alliance:
            reply+=" in %s"%(alliance.name,)
        reply+=" by %s:\n"%(sortby)
        prev = []
        if alliance:
            i = alliance.members # Not set for some reason... It should be.
        else:
            i = Updates.load().planets
        for x, y, z, score, value, size, xp, race, nick in result[:10]:
            i-=1
            line = "#%s - %s:%s:%s (%s) - Score: %s Value: %s Size: %s XP: %s"%(i,x,y,z,race,score,value,size,xp)
            if nick:
                line = "%s Nick: %s"%(line,nick)
            prev.append(line)
        message.reply(reply+"\n".join(prev))
예제 #15
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

        gov_bonus = 0
        gov = "Unknown"
        if planet.intel.gov is not None:
            if planet.intel.gov[0].lower() == "c":
                gov = "Corporatism"
                gov_bonus = -0.05
            if planet.intel.gov[0].lower() == "d":
                gov = "Democracy"
                gov_bonus = -0.10
            if planet.intel.gov[0].lower() == "n":
                gov = "Nationalism"
                gov_bonus = 0.25
            if planet.intel.gov[0].lower() == "s":
                gov = "Socialism"
                gov_bonus = 0.00
            if planet.intel.gov[0].lower() == "t":
                gov = "Totalitarianism"
                gov_bonus = 0.10

        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 -0.10) + 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 +0.25) + 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:   SD: %1.1f%% (%dXP) NC: %d%% (%dXP) EF: %d roids (%dXP) S: %d ships (%dXP) SGP: %d guards (%dXP)"
                % (0.5 * agents, self.xpcalc(agents, 1), agents,
                   self.xpcalc(agents, 2), agents / 3, self.xpcalc(
                       agents, 3), agents, self.xpcalc(
                           agents, 4), 10 * agents, self.xpcalc(agents, 5)))
            message.reply(
                "           IB: %d amps+dists (%dXP) RT: %dM %dC %dE (%dXP) H: %d buildings (%dXP)"
                % (agents / 15, self.xpcalc(
                    agents, 6), min(max_res, pscan.res_metal / 10),
                   min(max_res, pscan.res_crystal / 10),
                   min(max_res, pscan.res_eonium / 10), self.xpcalc(
                       agents, 7), agents / 20, self.xpcalc(agents, 8)))

            if params.group(7):
                stealth = int(params.group(7))
                stealth = stealth - 5 - int(agents / 2)
                t = 19 - alert_min
                prob = 100 * (t + stealth) / (t + alert_max)
                if prob < 0:
                    prob = 0
                elif prob > 100:
                    prob = 100

                race = user.planet.race
                if race == "Ter":
                    growth = 6
                elif race == "Cat":
                    growth = 10
                elif race == "Xan":
                    growth = 4
                elif race == "Zik":
                    growth = 6
                elif race == "Etd":
                    growth = 6
                from math import ceil
                message.reply(
                    "New stealth: %s  Success rate: %s%%  Recovery time: %1.1f ticks"
                    % (stealth, prob, ceil((5 + int(agents / 2)) / growth)))
예제 #16
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)))
예제 #17
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

        gov_bonus = 0
        gov = "Unknown"
        if planet.intel.gov is not None:
            if planet.intel.gov[0].lower() == "c":
                gov = "Corporatism"
                gov_bonus = -0.05
            if planet.intel.gov[0].lower() == "d":
                gov = "Democracy"
                gov_bonus = -0.10
            if planet.intel.gov[0].lower() == "n":
                gov = "Nationalism"
                gov_bonus = 0.25
            if planet.intel.gov[0].lower() == "s":
                gov = "Socialism"
                gov_bonus = 0.00
            if planet.intel.gov[0].lower() == "t":
                gov = "Totalitarianism"
                gov_bonus = 0.10


        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 -0.10) + 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 +0.25) + 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:   SD: %1.1f%% (%dXP) NC: %d%% (%dXP) EF: %d roids (%dXP) S: %d ships (%dXP) SGP: %d guards (%dXP)" % (0.5*agents, self.xpcalc(agents,1),
                     agents, self.xpcalc(agents,2), agents/3, self.xpcalc(agents,3), agents, self.xpcalc(agents,4), 10*agents, self.xpcalc(agents,5)))
            message.reply("           IB: %d amps+dists (%dXP) RT: %dM %dC %dE (%dXP) H: %d buildings (%dXP)" % (agents/15, self.xpcalc(agents,6),
                     min(max_res, pscan.res_metal/10), min(max_res, pscan.res_crystal/10), min(max_res, pscan.res_eonium/10), self.xpcalc(agents,7), agents/20, self.xpcalc(agents,8)))

            if params.group(7):
                stealth = int(params.group(7))
                stealth = stealth - 5 - int(agents/2)
                t=19-alert_min
                prob = 100*(t+stealth)/(t+alert_max)
                if prob < 0:
                    prob = 0
                elif prob > 100:
                    prob = 100

                race = user.planet.race
                if race == "Ter":
                    growth = 6
                elif race == "Cat":
                    growth = 10
                elif race == "Xan":
                    growth = 4
                elif race == "Zik":
                    growth = 6
                elif race == "Etd":
                    growth = 6
                from math import ceil
                message.reply("New stealth: %s  Success rate: %s%%  Recovery time: %1.1f ticks" % (stealth, prob, ceil((5+int(agents/2))/growth)))
예제 #18
0
    def tick(self, message, user, params):
        tick = Updates.load(params.group(1)) or Updates.current_tick()
        if tick is None:
            message.reply(
                "Ticks haven't started yet, go back to masturbating.")
        elif isinstance(tick, Updates):
            message.reply(str(tick))
        else:
            diff = int(params.group(1)) - tick
            now = datetime.utcnow()
            seconds = 0
            retstr = ""
            if diff > 0:

                if diff > 24:
                    days = (diff - 1) / 24
                    seconds += days * 24 * 60 * 60
                    retstr += "%sd " % (days, )

                if diff > 1:
                    hours = (diff - 1) % 24
                    seconds += hours * 60 * 60
                    retstr += "%sh " % (hours, )

                mins = 60 - now.minute
                seconds += mins * 60
                retstr += "%sm" % (mins, )

                if diff == 1:
                    retstr = "Next tick is %s (in %s" % (
                        params.group(1),
                        retstr,
                    )
                else:
                    retstr = "Tick %s is expected to happen in %s ticks (in %s" % (
                        params.group(1),
                        diff,
                        retstr,
                    )

            elif diff < 0:

                if diff < -23:
                    days = (-diff) / 24
                    seconds -= days * 24 * 60 * 60
                    retstr += "%sd " % (days, )

                if diff < -1:
                    hours = (-diff) % 24
                    seconds -= hours * 60 * 60
                    retstr += "%sh " % (hours, )

                mins = now.minute
                seconds -= mins * 60
                retstr += "%sm" % (mins, )

                if diff == -1:
                    retstr = "Last tick was %s (%s ago" % (
                        params.group(1),
                        retstr,
                    )
                else:
                    retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (
                        params.group(1),
                        -diff,
                        retstr,
                    )

            time = now + timedelta(seconds=seconds)
            retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"), )
            message.reply(retstr)
예제 #19
0
 def current(self, message, user, params):
     tick = Updates.load()
     if tick is None:
         message.reply("Ticks haven't started yet, go back to masturbating.")
     else:
         message.reply(str(tick))
예제 #20
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)))