Beispiel #1
0
 def __str__(self):
     return "{}(id={}, {}级,{}),{}年{},{}金币,{}银币,{}点券,{}行动力,{}军令,{}攻击令,{}城防值,状态:{}".format(
         self.m_szUserName, self.m_nId, self.m_nLevel, self.m_szNation,
         self.m_nYear, self.m_szSeason,
         GlobalFunc.get_short_readable(self.m_nGold),
         GlobalFunc.get_short_readable(self.m_nCopper),
         GlobalFunc.get_short_readable(self.m_nTickets), self.m_nCurActive,
         self.m_nToken, self.m_nAttToken, self.m_nCityHp,
         self.m_nArrestState)
Beispiel #2
0
 def accept_by_tower_id(self, tower):
     url = "/root/festaval!acceptByTowerId.action"
     data = {"towerId": tower["id"]}
     result = self.post_xml(url, data, "选择宝塔")
     if result and result.m_bSucceed:
         self.info("选择宝塔[{}],要求:{}宝石,奖励:{}宝石 {}筑造石".format(
             tower["name"],
             GlobalFunc.get_short_readable(int(tower["baoshi"])),
             GlobalFunc.get_short_readable(int(tower["reward"])),
             tower["rewardbuildingstone"]))
Beispiel #3
0
 def visit_champion(self):
     url = "/root/mainCity!visitChampion.action"
     result = self.get_protocol_mgr().get_xml(url, "恭贺")
     if result and result.m_bSucceed:
         self.info("恭贺,获得点券+{}".format(
             GlobalFunc.get_short_readable(
                 (int)(result.m_objResult["tickets"]))))
Beispiel #4
0
 def do_refine_bin_tie_factory(self, copper, active, mode):
     url = "/root/refine!doRefineBintieFactory.action"
     data = {"mode": mode}
     result = self.get_protocol_mgr().post_xml(url, data, "炼制")
     if result and result.m_bSucceed:
         self.add_task_finish_num(10, 1)
         reward_info = RewardInfo()
         reward_info.handle_info(result.m_objResult["rewardinfo"])
         self.info("消耗{}银币、{}行动力炼制,获得{}".format(
             GlobalFunc.get_short_readable(copper), active, reward_info))
Beispiel #5
0
 def right_army(self):
     url = "/root/mainCity!rightArmy.action"
     result = self.get_protocol_mgr().get_xml(url, "征义兵")
     if result and result.m_bSucceed:
         self.m_objUser.m_nRightCd = int(
             result.m_objResult.get("rightcd", "0"))
         self.m_objUser.m_nRightNum = int(
             result.m_objResult.get("rightnum", "0"))
         forces = int(result.m_objResult.get("forces", "0"))
         self.info("征义兵,获得兵力+{},剩余{}次征义兵".format(
             GlobalFunc.get_short_readable(forces),
             self.m_objUser.m_nRightNum))
Beispiel #6
0
 def get_upgrade_info(self, show=False):
     url = "/root/equip!getUpgradeInfo.action"
     result = self.get_protocol_mgr().get_xml(url, "套装")
     if result and result.m_bSucceed:
         self.m_nMagic = int(result.m_objResult["magic"])
         self.m_nMoliStone = int(result.m_objResult.get("molistone", "0"))
         self.m_nTicketNumber = int(result.m_objResult["ticketnumber"])
         self.m_nMaxTaoZhuangLv = int(result.m_objResult["taozhuang"]["maxtaozhuanglv"])
         dict_info = dict()
         dict_info["套装"] = result.m_objResult["playerequipdto"]
         self.info("魔力值:{},磨砺石:{},点券:{}".format(self.m_nMagic, self.m_nMoliStone, GlobalFunc.get_short_readable(self.m_nTicketNumber)))
         if show:
             for equipdto in dict_info["套装"]:
                 power = equipdto["powerstr"].split(";")
                 self.info("套装[id={} name={} general={} 强攻({}/{}) 强防({}/{})]".format(equipdto["composite"], equipdto["equipname"], equipdto["generalname"], power[0], equipdto["attfull"], power[1], equipdto["deffull"]))
         return dict_info
Beispiel #7
0
 def impose(self, force, cost=0):
     url = "/root/mainCity!impose.action"
     desc = "征收"
     if force:
         url = "/root/mainCity!forceImpose.action"
         desc = "花费{}金币强征".format(cost)
     result = self.get_protocol_mgr().get_xml(url, desc)
     if result and result.m_bSucceed:
         use_gold = False
         if force:
             use_gold = True
             self.add_task_finish_num(2, 1)
         self.add_task_finish_num(1, 1)
         msg = "{},获得银币+{}".format(
             desc,
             GlobalFunc.get_short_readable(
                 int(result.m_objResult["cooperdis"])))
         gold_dis = result.m_objResult["golddis"]
         if gold_dis != "0":
             msg += ",金币+{}".format(gold_dis)
             use_gold = True
         self.info(msg, use_gold)
Beispiel #8
0
 def draught(self, percent):
     need_forces = self.m_objUser.m_nMaxForces * percent
     if self.m_objUser.m_nForces < need_forces:
         forces = need_forces - self.m_objUser.m_nForces
         need_copper = int(forces / 2)
         copper = need_copper - self.m_objUser.m_nCopper
         if copper > 0:
             # 版本更新后,导致银币兑换比例变大了
             # import math
             # exchange_num = int(math.ceil(float(copper) / 5000000.0))
             # misc_mgr = self.get_service_factory().get_misc_mgr()
             # while exchange_num > 0:
             #     exchange_num -= 1
             #     misc_mgr.get_tickets_reward_by_name("银币", 10)
             misc_mgr = self.get_service_factory().get_misc_mgr()
             while need_copper > self.m_objUser.m_nCopper:
                 misc_mgr.get_tickets_reward_by_name("银币", 1)
         url = "/root/mainCity!draught.action"
         data = {"forceNum": int(forces)}
         result = self.get_protocol_mgr().post_xml(url, data, "征兵")
         if result and result.m_bSucceed:
             self.info("征兵,兵力+{}".format(
                 GlobalFunc.get_short_readable(int(forces))))
Beispiel #9
0
 def get_available_tickets(self):
     return GlobalFunc.get_available("tickets", self.m_objUser.m_nTickets)
Beispiel #10
0
 def get_available_copper(self):
     return GlobalFunc.get_available("copper", self.m_objUser.m_nCopper)
Beispiel #11
0
 def get_available_gold(self):
     return GlobalFunc.get_available(
         "gold", self.m_objUser.m_nGold + self.m_objUser.m_nRechargeGold)
Beispiel #12
0
    def run(self):
        if self.m_objUser.m_nCurActive > config["active"]["reserve"]:
            active_mgr = self.m_objServiceFactory.get_active_mgr()
            misc_mgr = self.m_objServiceFactory.get_misc_mgr()
            equip_mgr = self.m_objServiceFactory.get_equip_mgr()
            for v in config["active"]["sort"]:
                active_config = config["active"][v]
                if not active_config["enable"]:
                    continue

                if v == "royalty":
                    info = active_mgr.royalty_weave_info2()
                    if info is None:
                        return self.next_half_hour()

                    if info["消耗行动力"] > self.m_objUser.m_nCurActive:
                        return self.next_half_hour()

                    if info["布匹"] < info["布匹上限"]:
                        if active_config["do_high"] and info["剩余高效次数"] > 0:
                            active_mgr.royalty_weave2(info["消耗行动力"], 1)
                            return self.immediate()

                        if active_config["do_tired"] and info["剩余极限次数"] > 0:
                            active_mgr.royalty_weave2(info["消耗行动力"], 1)
                            return self.immediate()

                        if active_config[
                                "finish_task"] and not self.is_finish_task(
                                    12) and info["剩余极限次数"] > 0:
                            active_mgr.royalty_weave2(info["消耗行动力"], 1)
                            return self.immediate()

                    refresh_list = active_config["list"]
                    convert_cost = active_config["cost"]
                    if info["布匹"] >= active_config["limit"]["limit"]:
                        refresh_list = active_config["limit"]["list"]
                        convert_cost = active_config["limit"]["cost"]
                    has_trader = info["商人"] in refresh_list
                    if not has_trader and info["刷新商人费用"] <= active_config[
                            "refresh"]:
                        active_mgr.refresh_royalty_weave_new(info["刷新商人费用"])
                        return self.immediate()

                    if has_trader:
                        reward = info["换购商品"].get_reward(0)
                        if reward is not None:
                            for cost in convert_cost:
                                if cost["type"] == reward.type and cost[
                                        "lv"] == reward.lv and cost[
                                            "num"] == reward.num:
                                    if info["换购消耗布匹"] <= cost[
                                            "needweavenum"] and info[
                                                "换购消耗布匹"] <= info["布匹"]:
                                        active_mgr.convert_royalty_weave_new2(
                                            info["换购消耗布匹"])
                                    break

                elif v == "refine":
                    info = active_mgr.get_refine_info()
                    if info is None:
                        return self.next_half_hour()

                    if not info["可精炼工人"]:
                        return self.one_minute()

                    if info["消耗余料"] > info["当前余料"]:
                        # return self.next_half_hour()
                        continue

                    if info["消耗行动力"] > self.m_objUser.m_nCurActive:
                        return self.next_half_hour()

                    if info["消耗银币"] > self.get_available_copper():
                        misc_mgr.get_tickets_reward_by_name("银币", 1)

                    if info["升级单个工人消耗金币"] <= active_config["refresh_refiner"][
                            "per_cost"]:
                        info["工人们"] = sorted(info["工人们"],
                                             key=lambda value: value["id"],
                                             reverse=True)
                        sn = ""
                        for var in info["工人们"]:
                            sn += var["id"]
                        if sn in active_config["refresh_refiner"]["list"]:
                            index = active_config["refresh_refiner"]["list"][
                                sn]
                            active_mgr.refresh_one_refiner(
                                info["工人们"][index], info["升级单个工人消耗金币"])
                        active_mgr.refine(info["消耗银币"], info["消耗行动力"])
                        return self.immediate()

                    if active_config["do_high"] and info["剩余高效次数"] > 0:
                        active_mgr.refine(info["消耗银币"], info["消耗行动力"])
                        return self.immediate()

                    if active_config["do_tired"] and info["剩余极限次数"] > 0:
                        active_mgr.refine(info["消耗银币"], info["消耗行动力"])
                        return self.immediate()

                    if active_config[
                            "finish_task"] and not self.is_finish_task(9):
                        active_mgr.refine(info["消耗银币"], info["消耗行动力"])
                        return self.immediate()

                elif v == "refine_bin_tie":
                    info = active_mgr.get_refine_bin_tie_factory()
                    if info is None:
                        return self.next_half_hour()

                    if info["消耗行动力"] > self.m_objUser.m_nCurActive:
                        return self.next_half_hour()

                    if info["消耗银币"] > self.get_available_copper():
                        misc_mgr.get_tickets_reward_by_name("银币", 1)

                    war_chariot_info = equip_mgr.get_war_chariot_info()
                    if war_chariot_info is None:
                        continue

                    mode = active_config["mode"]
                    if war_chariot_info["当前等级"] >= 100:
                        mode = 1

                    if active_config["do_high"] and info["剩余高效次数"] > 0:
                        active_mgr.do_refine_bin_tie_factory(
                            info["消耗银币"], info["消耗行动力"], mode)
                        return self.immediate()

                    if active_config["do_tired"] and info["剩余极限次数"] > 0:
                        active_mgr.do_refine_bin_tie_factory(
                            info["消耗银币"], info["消耗行动力"], mode)
                        return self.immediate()

                    if active_config[
                            "finish_task"] and not self.is_finish_task(10):
                        active_mgr.do_refine_bin_tie_factory(
                            info["消耗银币"], info["消耗行动力"], mode)
                        return self.immediate()

                elif v == "caravan":
                    info = active_mgr.get_western_trade_info()
                    if info is None:
                        return self.next_half_hour()

                    if info["进入下一站"]:
                        active_mgr.next_place()

                    if "事件" in info:
                        self.handle_event(info)
                        return self.immediate()

                    info["商人们"] = sorted(info["商人们"],
                                         key=lambda value: value["active"])
                    for trader in info["商人们"]:
                        trader_active = int(trader["active"])
                        if trader_active > active_config["limit"][
                                "active"] or trader_active > self.m_objUser.m_nCurActive:
                            continue
                        cost = trader["cost"].split(":")
                        real_cost = int(cost[1])
                        if cost[0] == "gold":
                            if real_cost <= active_config["limit"][
                                    "gold"] and real_cost <= self.get_available_gold(
                                    ):
                                info = active_mgr.western_trade(
                                    trader["id"], {
                                        "金币": real_cost,
                                        "行动力": trader_active
                                    })
                                self.handle_event(info)
                                return self.immediate()
                        elif cost[0] == "copper":
                            if real_cost <= active_config["limit"]["copper"]:
                                if real_cost > self.get_available_copper():
                                    misc_mgr.get_tickets_reward_by_name(
                                        "银币", 1)
                                info = active_mgr.western_trade(
                                    trader, {
                                        "银币":
                                        GlobalFunc.get_short_readable(
                                            real_cost),
                                        "行动力":
                                        trader_active
                                    })
                                self.handle_event(info)
                                return self.immediate()

                    if self.m_objUser.m_nCurActive > active_config["limit"][
                            "max_reserve"]:
                        for trader in info["商人们"]:
                            trader_active = int(trader["active"])
                            if trader_active > self.m_objUser.m_nCurActive:
                                continue
                            cost = trader["cost"].split(":")
                            real_cost = int(cost[1])
                            if cost[0] == "gold":
                                if real_cost <= active_config["limit"][
                                        "gold"] and real_cost <= self.get_available_gold(
                                        ):
                                    info = active_mgr.western_trade(
                                        trader["id"], {
                                            "金币": real_cost,
                                            "行动力": trader_active
                                        })
                                    self.handle_event(info)
                                    return self.immediate()
                            elif cost[0] == "copper":
                                if real_cost <= active_config["limit"][
                                        "copper"]:
                                    if real_cost > self.get_available_copper():
                                        misc_mgr.get_tickets_reward_by_name(
                                            "银币", 1)
                                    info = active_mgr.western_trade(
                                        trader, {
                                            "银币":
                                            GlobalFunc.get_short_readable(
                                                real_cost),
                                            "行动力":
                                            trader_active
                                        })
                                    self.handle_event(info)
                                    return self.immediate()

        return self.next_half_hour()
Beispiel #13
0
 def __str__(self):
     return "{}(lv.{})+{}".format(self.itemname, self.lv,
                                  GlobalFunc.get_short_readable(self.num))