예제 #1
0
def battle_start(request):
    char_id = request._char_id
    b = UnionBattle(char_id)

    response = UnionBattleStartResponse()
    response.ret = 0
    response.record.MergeFrom(b.start_battle())
    return pack_msg(response)
예제 #2
0
def get_records(request):
    char_id = request._char_id
    b = UnionBattle(char_id)

    response = UnionBattleRecordGetResponse()
    response.ret = 0
    records = b.get_records()
    for r in records:
        msg_r = response.records.add()
        msg_r.MergeFromString(r)

    return pack_msg(response)
예제 #3
0
def clean(signum):
    logger = Logger("clean_union.log")
    logger.write("Start")

    try:
        UnionBattle.cron_job()
        Member.cron_job()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Clean Union Complete.")
    finally:
        logger.close()
예제 #4
0
def clean(signum):
    logger = Logger("clean_union.log")
    logger.write("Start")

    try:
        UnionBattle.cron_job()
        Member.cron_job()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Clean Union Complete.")
    finally:
        logger.close()
예제 #5
0
    def checkin(self):
        # 签到
        from core.union.union import Union
        from core.union.battle import UnionBattle

        if not self.mongo_union_member.joined:
            raise SanguoException(errormsg.INVALID_OPERATE, self.char_id,
                                  "Union Checkin", "not join union")

        if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount:
            raise SanguoException(errormsg.UNION_CHECKIN_REACH_MAX_TIMES,
                                  self.char_id, "Union Checkin",
                                  "reached max times")

        try:
            c = UNION_CHECKIN[self.mongo_union_member.checkin_times + 1]
        except KeyError:
            raise SanguoException(
                errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id,
                "Union Checkin",
                "reached max times. UNION_CHECKIN KeyError: {0}".format(
                    self.mongo_union_member.checkin_times + 1))

        if c.cost_type == 1:
            needs = {'gold': -c.cost_value}
        else:
            needs = {'sycee': -c.cost_value}

        resources = Resource(self.char_id, "Union Checkin")
        with resources.check(**needs):
            self.mongo_union_member.checkin_times += 1
            self.mongo_union_member.last_checkin_timestamp = arrow.utcnow(
            ).timestamp

            self.add_coin(c.got_coin, send_notify=False)
            self.add_contribute_points(c.got_contributes, send_notify=False)
            self.mongo_union_member.save()
        self.send_personal_notify()

        Union(self.char_id).add_contribute_points(c.got_contributes)

        UnionBattle(self.char_id).send_notify()
        doc = MongoUnion._get_collection().find_one(
            {'_id': self.mongo_union_member.joined}, {'owner': 1})
        owner = doc['owner']
        UnionBattle(owner).send_notify()

        drop = make_standard_drop_from_template()
        drop['union_coin'] = c.got_coin
        drop['union_contribute_points'] = c.got_contributes
        return standard_drop_to_attachment_protomsg(drop)
예제 #6
0
    def make_basic_information(self):
        from core.union.battle import UnionBattle
        msg = protomsg.UnionBasicInformation()
        msg.id = self.mongo_union.id
        msg.name = self.mongo_union.name
        msg.bulletin = self.mongo_union.bulletin
        msg.level = self.mongo_union.level
        msg.contribute_points = self.mongo_union.contribute_points
        msg.next_contribute_points = self.next_level_contribute_points_needs
        msg.current_member_amount = self.current_member_amount
        msg.max_member_amount = self.max_member_amount
        msg.rank = UnionBattle(self.char_id, self.union_id).get_order()

        return msg
예제 #7
0
def send_notify(char_id):
    from core.union.battle import UnionBattle
    from core.union.boss import UnionBoss
    from core.union.store import UnionStore
    from core.union.union import Union, UnionList, UnionOwner
    from core.union.member import Member

    # 工会列表
    UnionList.send_list_notify(char_id)
    # 个人信息
    Member(char_id).send_personal_notify()

    u = Union(char_id)
    # UnionNotify
    u.send_notify()
    if isinstance(u, UnionOwner):
        # 会长才能看见的申请者列表
        u.send_apply_list_notify()

    # 商店
    UnionStore(char_id).send_notify()
    # 工会战
    UnionBattle(char_id).send_notify()
예제 #8
0
def get_battle_board(request):
    char_id = request._char_id
    b = UnionBattle(char_id)
    return pack_msg(b.make_board_msg())