Exemplo n.º 1
0
    def create_table_data(self,
                          fellow_id,
                          is_major,
                          camp_id,
                          on_troop,
                          way_type=WAY_UNKNOWN,
                          way_others=''):
        yield self._load()

        time_now = int(time())  #datetime2string()
        gsattrib = GSAttribute(self.cid, GSFellowMgr._table)
        res_err = yield gsattrib.new(cid=self.cid,
                                     fellow_id=fellow_id,
                                     level=1,
                                     exp=0,
                                     advanced_level=0,
                                     on_troop=on_troop,
                                     is_major=is_major,
                                     camp_id=camp_id,
                                     deleted=0,
                                     create_time=time_now,
                                     update_time=time_now,
                                     del_time=0)
        if res_err:
            log.error(
                'GSBagEquipMgr create table data error. res_err: {0}.'.format(
                    res_err))
            defer.returnValue((UNKNOWN_ERROR, None))

        self.__gsattribs[gsattrib.attrib_id] = gsattrib
        # 创建玩家角色时初始化阵容等信息
        if is_major:
            self.initialize(gsattrib)

        conf = get_fellow_by_fid(fellow_id)
        if conf:
            # 判断图鉴
            yield self.user.atlaslist_mgr.new_atlaslist(
                CATEGORY_TYPE_FELLOW, conf['Camp'], conf['Quality'], fellow_id)
            if conf['Quality'] >= QUALITY_PURPLE:
                yield self.user.goodwill_mgr.create_table_data(fellow_id)
            # add syslog
            syslogger(LOG_FELLOW_GET, self.cid, self.user.level,
                      self.user.vip_level, self.user.alliance_id,
                      gsattrib.attrib_id, fellow_id, conf['QualityLevel'],
                      conf['Star'], way_type, way_others)
        defer.returnValue((NO_ERROR, gsattrib))
Exemplo n.º 2
0
    def create_table_data(self, item_type, item_id, item_num, time_now):
        gsattrib = GSAttribute(self.cid, GSBagEquipshardMgr._table)
        res_err = yield gsattrib.new(cid=self.cid,
                                     item_type=item_type,
                                     item_id=item_id,
                                     item_num=item_num,
                                     deleted=0,
                                     create_time=time_now,
                                     update_time=time_now,
                                     del_time=0,
                                     aux_data='')
        if res_err:
            log.error('GSBagEquipshardMgr create table data error. ')
            defer.returnValue((UNKNOWN_ERROR, None))

        self.__gsattribs[gsattrib.attrib_id] = gsattrib
        defer.returnValue((NO_ERROR, gsattrib))
Exemplo n.º 3
0
    def create_table_data(self, fellow_id):
        gsattrib = yield self.get_fellow(fellow_id)
        if gsattrib:
            defer.returnValue((NO_ERROR, gsattrib))

        gsattrib = GSAttribute(self.cid, GSGoodwillMgr._table)
        res_err = yield gsattrib.new(cid=self.cid,
                                     fellow_id=fellow_id,
                                     goodwill_exp=0,
                                     goodwill_level=0,
                                     last_gift=0)
        if res_err:
            log.error('GSGoodwillMgr create table data error. ')
            defer.returnValue((UNKNOWN_ERROR, None))

        self.__goodwills[gsattrib.fellow_id] = gsattrib

        if self.last_fellow_id == 0:
            self.last_fellow_id = fellow_id

        defer.returnValue((NO_ERROR, gsattrib))
Exemplo n.º 4
0
    def addItem(self,
                add_item_type,
                add_item_id,
                add_count,
                partial_add=False
                ):  #Return item inst if succeed, else return None.

        if add_count > BAG_MAX_PILE:
            log.warn('Exp3404361 Add count > max pile. Add count :', add_count)
            defer.returnValue(None)

        gs_att_find = GSAttribute(self.__cid, self._tbl_name, 0,
                                  self._item_field_set)
        gs_att_find.updateGSAttribute(False, {
            'item_type': add_item_type,
            'item_id': add_item_id,
            'count': add_count
        })
        target_item = GSBagItem(gs_att_find)

        found_pos = bisect.bisect_left(self.__list, target_item)
        found_item = None
        log.debug('Find pos {0}'.format(found_pos))

        find_same = False
        if found_pos < 0 or found_pos >= len(self.__list):
            find_same = False
        else:
            found_item = self.__list[found_pos]
            if target_item.isSame(found_item):
                find_same = True
            else:
                find_same = False

        if find_same:
            leftmost = self.findLeftmostSameOne(found_pos)
            found_item = self.__list[leftmost]
            log.debug('Leftmost pos {0}'.format(leftmost))
            add_count = self.dispatchAddCount(
                leftmost, add_count, BAG_MAX_PILE
            )  #Try to dispath add count on existed (one or several ) items!

            count_sum = found_item.count + add_count
            if count_sum <= BAG_MAX_PILE:
                #Fully pile, just modify existing item's count.
                found_item.setItemCount(count_sum)
                defer.returnValue(found_item)
            else:
                if not partial_add:
                    #Add fail! Not allow partial pile!
                    pass
                else:
                    #Partial pile, ajust their count.
                    found_item.setItemCount(BAG_MAX_PILE)
                    add_count = count_sum - BAG_MAX_PILE

        if len(self.__list) >= self.__capacity:
            log.debug('[ GSBag::addItem ] Bag is full!  Cur capacity:',
                      self.__capacity, ' partial_add:', partial_add)
            defer.returnValue(None)

        log.debug(
            '[ GSBag::addItem ] Need create item via cs. cid {0}, type {1}, id {2}, count {3}'
            .format(self.__cid, add_item_type, add_item_id, add_count))
        try:
            new_item = yield self.createItemViaCS(add_item_type, add_item_id,
                                                  add_count)
        except Exception as e:
            log.exception()
            defer.returnValue(None)

        if not new_item:
            log.error(
                'Exp39303873 create item via cs fail ! cid {0}, item {1}, {2}'.
                format(self.__cid, add_item_type, add_item_id))
            defer.returnValue(None)

        bisect.insort_left(self.__list, new_item)

        defer.returnValue(new_item)