Esempio n. 1
0
def get_joined_union(request):
    char_id = int(request.POST['char_id'])

    union = Union(char_id)
    if isinstance(union, UnionDummy):
        data = None
    else:
        m = Member(char_id)
        data = {
            'char_id': char_id,
            'union': union.union_id,
            'union_owner': union.mongo_union.owner,
            'union_name': union.mongo_union.name,
            'union_bulletin': union.mongo_union.bulletin,
            'union_level': union.mongo_union.level,
            'union_contribute_points': union.mongo_union.contribute_points,
            'union_score': union.mongo_union.score,
            'member_coin': m.mongo_union_member.coin,
            'member_contribute_points': m.mongo_union_member.contribute_points,
            'member_position': m.mongo_union_member.position,
            'member_checkin_times': m.mongo_union_member.checkin_times,
            'member_buy_buff_times': m.mongo_union_member.buy_buff_times,
            'member_boss_times': m.mongo_union_member.boss_times
        }

    return {'ret': 0, 'data': data}
Esempio n. 2
0
    def create(self, name):
        if len(name) > UNION_NAME_MAX_LENGTH:
            raise SanguoException(
                errormsg.UNION_NAME_TOO_LONG, self.char_id, "Union Create",
                "name too long: {0}".format(name.encode('utf-8')))

        if MongoUnion.objects.filter(name=name).count() > 0:
            raise SanguoException(
                errormsg.UNION_NAME_ALREADY_EXIST, self.char_id,
                "Union Create",
                "name already exist: {0}".format(name.encode('utf-8')))

        resource = Resource(self.char_id, "Union Create")

        with resource.check(sycee=-UNION_CREATE_NEEDS_SYCEE):
            new_id = id_generator('union')[0]
            mu = MongoUnion(id=new_id)
            mu.owner = self.char_id
            mu.name = name
            mu.bulletin = UNION_DEFAULT_DES
            mu.level = 1
            mu.contribute_points = 0
            mu.score = get_battle_init_score()
            mu.save()
            Member(self.char_id).join_union(new_id)

        send_notify(self.char_id)
Esempio n. 3
0
def checkin(request):
    char_id = request._char_id
    drop_msg = Member(char_id).checkin()

    response = UnionCheckinResponse()
    response.ret = 0
    response.drop.MergeFrom(drop_msg)
    return pack_msg(response)
Esempio n. 4
0
    def refuse_join(self, char_id):
        # 拒绝
        from core.union.member import Member
        m = Member(char_id)
        if self.union_id in m.mongo_union_member.applied:
            m.mongo_union_member.applied.remove(self.union_id)
            m.mongo_union_member.save()

        self.send_apply_list_notify()
        UnionList.send_list_notify(char_id)
Esempio n. 5
0
    def kick_member(self, member_id):
        # 踢人
        from core.union.member import Member
        if not self.is_member(member_id):
            raise SanguoException(
                errormsg.INVALID_OPERATE, self.char_id, "Union Kick Member",
                "char {0} is not member of union {1}".format(
                    member_id, self.union_id))

        Member(member_id).quit_union()
        self.send_notify()
        Union(member_id, self.union_id).send_notify()
Esempio n. 6
0
    def send_notify(self, to_owner=False):
        from core.union.member import Member
        msg = protomsg.UnionNotify()
        msg.in_union = True
        msg.union.MergeFrom(self.make_basic_information())
        msg.leader = self.mongo_union.owner

        for mid in self.member_list:
            msg_member = msg.members.add()
            msg_member.MergeFrom(Member(mid).make_member_message())

        if to_owner:
            char_id = self.mongo_union.owner
        else:
            char_id = self.char_id
        publish_to_char(char_id, pack_msg(msg))
Esempio n. 7
0
    def add_member(self, char_id):
        # 添加成员
        from core.union.member import Member
        if self.current_member_amount >= self.max_member_amount:
            raise SanguoException(
                errormsg.UNION_CANNOT_JOIN_FULL, self.char_id,
                "Union add member",
                "full. {0} >= {1}".format(self.current_member_amount,
                                          self.max_member_amount))

        if not isinstance(Union(char_id), UnionDummy):
            raise SanguoException(errormsg.UNION_CANNOT_AGREE_JOIN,
                                  self.char_id, "Union Apply Join",
                                  "char {0} already in union".format(char_id))

        Member(char_id).join_union(self.union_id)
        self.send_notify()
        Union(char_id).send_notify()
        UnionList.send_list_notify(char_id)
Esempio n. 8
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()
Esempio n. 9
0
    def after_battle(self, boss_id, damage, kill=False):
        # 每次打完给予奖励
        member = Member(self.char_id)
        boss = UNION_BOSS[boss_id]
        contribute_points = int(
            float(damage) / boss.hp * boss.contribute_points)
        lowest = 1
        highest = int(boss.contribute_points * 0.05)
        if contribute_points < lowest:
            contribute_points = lowest
        if contribute_points > highest:
            contribute_points = highest

        coin = 9 + contribute_points

        member.add_coin(coin, send_notify=False)
        member.add_contribute_points(contribute_points, send_notify=True)
        if not kill:
            self.union.add_contribute_points(contribute_points)

        drop = make_standard_drop_from_template()
        drop['union_coin'] = coin
        drop['union_contribute_points'] = contribute_points
        return standard_drop_to_attachment_protomsg(drop)
Esempio n. 10
0
def cmd(request):
    req = request._proto
    char_id = request._char_id

    if req.action == 2:
        print "Unsupported"
        return HttpResponse('', content_type='text/plain')

    drop = make_standard_drop_from_template()
    if req.tp == 1:
        drop['exp'] = req.param
    elif req.tp == 2:
        drop['official_exp'] = req.param
    elif req.tp == 3:
        drop['gold'] = req.param
    elif req.tp == 4:
        drop['sycee'] = req.param

    elif req.tp == 5:
        if req.param not in EQUIPMENTS:
            return HttpResponse('', content_type='text/plain')
        drop['equipments'].append((req.param, 1, 1))

    elif req.tp == 6:
        if req.param not in GEMS:
            return HttpResponse('', content_type='text/plain')
        drop['gems'].append((req.param, 1))

    elif req.tp == 7:
        if req.param not in HEROS:
            return HttpResponse('', content_type='text/plain')
        drop['heros'].append((req.param, 1))

    elif req.tp == 8:
        if req.param not in STUFFS:
            return HttpResponse('', content_type='text/plain')
        drop['stuffs'].append((req.param, 1))

    elif req.tp == 9:
        if req.param not in HEROS:
            return HttpResponse('', content_type='text/plain')
        drop['souls'].append((req.param, 1))

    elif req.tp == 10:
        drop['purchase_got'] = req.param
        drop['purchase_actual_got'] = req.param

    elif req.tp == 12:
        if req.param not in HORSE:
            return HttpResponse('', content_type='text/plain')
        drop['horses'].append((req.param, 1))

    elif req.tp == 13:
        Member(char_id).add_coin(req.param)

    resource = Resource(char_id, "CMD",
                        "tp: {0}, param: {1}".format(req.tp, req.param))
    standard_drop = resource.add(**drop)
    print standard_drop

    if req.tp == 11:
        fo = FunctionOpen(char_id)
        fo._open_all()
        fo.send_notify()

    return HttpResponse('', content_type='text/plain')
Esempio n. 11
0
 def __init__(self, char_id):
     super(UnionStore, self).__init__(char_id)
     self.member = Member(char_id)
Esempio n. 12
0
def apply_join(request):
    req = request._proto
    char_id = request._char_id

    Member(char_id).apply_union(req.id)
    return None
Esempio n. 13
0
 def quit(self):
     # 主动退出
     from core.union.member import Member
     Member(self.char_id).quit_union()
     Union(self.char_id).send_notify()
Esempio n. 14
0
 def __init__(self, char_id):
     super(UnionBoss, self).__init__(char_id)
     if isinstance(self.union, UnionBase):
         self.load_data()
         self.member = Member(self.char_id)
Esempio n. 15
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item
        from core.horse import Horse
        from core.union.member import Member

        update_settings = {}
        update_settings['purchase_notify'] = kwargs.get(
            'purchase_notify', True)
        update_settings['as_vip_exp'] = kwargs.get('as_vip_exp', True)

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data[
                'official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'],
                        sycee=data['sycee'],
                        exp=data['exp'],
                        official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        update_settings=update_settings)

        union_coin = kwargs.get('union_coin', 0)
        union_contribute_points = kwargs.get('union_contribute_points', 0)
        if union_coin or union_contribute_points:
            m = Member(self.char_id)
            m.add_coin(union_coin, send_notify=False)
            m.add_contribute_points(union_contribute_points)

        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult

        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])

        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)

        if data['gems']:
            item.gem_add(data['gems'])

        if data['stuffs']:
            item.stuff_add(data['stuffs'])

        if data['horses']:
            horse = Horse(self.char_id)
            for _id, _amount in data['horses']:
                for i in range(_amount):
                    horse.add(_id)

        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])

            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data