def getExAttrIDByDropConfig(self, exAttrID, exAttrRate, lower, upper, isPrimaryDrop, dropCoefficient):
     '''
                 根据掉落配置随出一个extraAttribute的Id
     @param exAttrID: 配置中附加属性id
     @param exAttrRate: 配置中附加属性几率
     @param lower:配置中附加属性下限
     @param upper: 配置中附加属性上限
     @param isPrimaryDrop: 是否是指定物品掉落
     @param dropCoefficient: 玩家角色的掉落几率            
     '''
     if lower > upper:
         (lower, upper) = (upper, lower)
     ret_exAttributeId = []
     tmp_exAttributeId = [int(tmp_attr) for tmp_attr in exAttrID.split(';')]
     tmp_exAttributeRate = [int (tmp_attrRate) for tmp_attrRate in exAttrRate.split(';')]
     if isPrimaryDrop and [tmp_attr for tmp_attr in tmp_exAttributeId if int(tmp_attr)>=0]:
         ret_exAttributeId.append[tmp_exAttributeId[0]]
         return ret_exAttributeId
     
     if(lower == upper):
         lv = lower
     else:
         r = random.randint(lower, upper)
         cursor = connection.cursor()
         cursor.execute("select level from `exattribute_level` where value>=%d order by level" % r)
         ret = cursor.fetchall()
         cursor.close()
         lv = ret[0]['level']
     #从符合LV的附加属性项里随出一个项的ID
     cursor = connection.cursor()
     cursor.execute('select * from `extra_attributes` where level =%d' % lv)
     exAttrs = cursor.fetchall()
     l = len(exAttrs)
     if l > 0:#掉落项时,exattrrate参数做为掉落机率,先决定掉落类型
         for i in range(0, len(tmp_exAttributeRate)):
             r = random.randint(0, 100000)
             if r > 0 and r < tmp_exAttributeRate[i] * (dropCoefficient / 100000):
                 #随出本类型个数的MF
                 ret_exAttributeId = []
                 type = 0
                 c = 0
                 while c < (len(tmp_exAttributeRate) - i):
                     l = len(exAttrs)
                     r = random.randint(0, l - 1)
                     exAttr = exAttrs[r]
                     assert(exAttr)
                     exAttrs.remove(exAttr)
                     if (type & (1 << exAttr["type"])) == 0:      #没有同类型 的MF
                         ret_exAttributeId =ret_exAttributeId.append(exAttr["id"])
                         type |= (1 << exAttr["type"])
                         c += 1
                 break
             
     return ret_exAttributeId
    def getShopItemExtraAttr(self, shopInfo):
        '''得到商店物品附加属性'''
        characterLevel = self._owner.level.getLevel()

        cursor = connection.cursor()
        sql = "select parameterMin,parameterMax from `shop_extra_attr_level_config` where type=%d and characterLevel=%d"\
            % (shopInfo['extraAttrLevelConfigType'], characterLevel)
        cursor.execute(sql)
        result = cursor.fetchone()
        min = result['parameterMin']
        max = result['parameterMax']
        r = random.randint(min, max)
        cursor.execute("select level from `exattribute_level` where value>=%d" % r)
        level = cursor.fetchone()['level']
        cursor.execute("select * from `extra_attributes` where level=%d" % level)
        tempAttributeList = cursor.fetchall()
        r1 = random.randint(0, len(tempAttributeList) - 1)
        attributeInfo = tempAttributeList[r1]

        attributeInfo['attributeEffects'] = []
        if attributeInfo['effects'] <> '-1' or attributeInfo['effects'] <> u'-1':
            effects = attributeInfo['effects'].split(';')
            for effect in effects:
                effect = int(effect)
                description = loader.getById('effect', effect, ['description'])['description']
                attributeInfo['attributeEffects'].append(description)
        else:
            script = attributeInfo['script']
            script = util.parseScript(script)
            attributeInfo['attributeEffects'].append(script)

        return attributeInfo
 def getShopItemPrice(self, itemTemplateId, extraAttribute):
     '''获取商店物品的购买价格'''
     #all_ItemTemplate = dbaccess.all_ItemTemplate.values()
     sellPrice = dbaccess.all_ItemTemplate[itemTemplateId]['buyingRateCoin']#loader.getById('item_template', itemTemplateId, ['buyingRateCoin'])['buyingRateCoin']
     extraAttributes = eval('[' + extraAttribute + ']')
     for extraAttrId in extraAttributes:
         extraAttrId = int(extraAttrId)
         isValidExtraAttrID = loader.getById('extra_attributes', extraAttrId, ['id'])
         if((extraAttrId != -1) and isValidExtraAttrID):
             eAttribute = loader.getById('extra_attributes', extraAttrId, ['level'])
             cursor = connection.cursor()
             cursor.execute("select price from exattribute_level where level=%d" % eAttribute['level'])
             value = cursor.fetchone()
             cursor.close()
             sellPrice += int(value['price'])
     return sellPrice
    def getSingleMonsterPracticeExp(self, monsterId):
        id = self._owner.baseInfo.id

        monsterInfo = loader.getById('npc', monsterId, ['monsterGroupId', 'levelGroup'])
        if not monsterInfo:
            return False, Lg().g(439)
        levelList = list(monsterInfo['levelGroup'].split(';'))
        groupId = monsterInfo['monsterGroupId']
        tempList = []
        for level in levelList:
            level = int(level)
            tempList.append(level)
        caughtLevel = tempList[0]
        cursor = connection.cursor()
        cursor.execute("select expBonus from `monster_instance` where level=%d and groupId=%d" % (caughtLevel, groupId))
        monsterInstance = cursor.fetchone()
        cursor.close()
        if not monsterInstance:
            return False, Lg().g(439)
        expBonus = monsterInstance['expBonus']
        return True, expBonus,caughtLevel
 def getShopItemPrice(self, itemTemplateId, extraAttribute):
     '''获取商店物品的购买价格'''
     #all_ItemTemplate = dbaccess.all_ItemTemplate.values()
     sellPrice = dbaccess.all_ItemTemplate[itemTemplateId][
         'buyingRateCoin']  #loader.getById('item_template', itemTemplateId, ['buyingRateCoin'])['buyingRateCoin']
     extraAttributes = eval('[' + extraAttribute + ']')
     for extraAttrId in extraAttributes:
         extraAttrId = int(extraAttrId)
         isValidExtraAttrID = loader.getById('extra_attributes',
                                             extraAttrId, ['id'])
         if ((extraAttrId != -1) and isValidExtraAttrID):
             eAttribute = loader.getById('extra_attributes', extraAttrId,
                                         ['level'])
             cursor = connection.cursor()
             cursor.execute(
                 "select price from exattribute_level where level=%d" %
                 eAttribute['level'])
             value = cursor.fetchone()
             cursor.close()
             sellPrice += int(value['price'])
     return sellPrice
    def getShopItemExtraAttrCount(self, shopInfo):
        '''得到商店物品附加属性数量'''
        characterLevel = self._owner.level.getLevel()

        cursor = connection.cursor()
        sql = "select countRatio from `shop_extra_attr_count_config` where type=%d and characterLevel=%d"\
            % (shopInfo['extraAttrCountConfigType'], characterLevel)
        cursor.execute(sql)
        countRatio = cursor.fetchone()['countRatio']
        cursor.close()
        ratios = countRatio.split(';')
        count = 0
        i = 0
        for ratio in ratios:
            i += 1
            ratio = int(ratio)
            r = random.randint(0, 100000)
            if r < ratio:
                count = len(ratios) - i + 1
                break
            else:
                continue
        return count
    def getShopItemExtraAttrCount(self, shopInfo):
        '''得到商店物品附加属性数量'''
        characterLevel = self._owner.level.getLevel()

        cursor = connection.cursor()
        sql = "select countRatio from `shop_extra_attr_count_config` where type=%d and characterLevel=%d"\
            % (shopInfo['extraAttrCountConfigType'], characterLevel)
        cursor.execute(sql)
        countRatio = cursor.fetchone()['countRatio']
        cursor.close()
        ratios = countRatio.split(';')
        count = 0
        i = 0
        for ratio in ratios:
            i += 1
            ratio = int(ratio)
            r = random.randint(0, 100000)
            if r < ratio:
                count = len(ratios) - i + 1
                break
            else:
                continue
        return count
Exemplo n.º 8
0
    def getSingleMonsterPracticeExp(self, monsterId):
        id = self._owner.baseInfo.id

        monsterInfo = loader.getById('npc', monsterId,
                                     ['monsterGroupId', 'levelGroup'])
        if not monsterInfo:
            return False, Lg().g(439)
        levelList = list(monsterInfo['levelGroup'].split(';'))
        groupId = monsterInfo['monsterGroupId']
        tempList = []
        for level in levelList:
            level = int(level)
            tempList.append(level)
        caughtLevel = tempList[0]
        cursor = connection.cursor()
        cursor.execute(
            "select expBonus from `monster_instance` where level=%d and groupId=%d"
            % (caughtLevel, groupId))
        monsterInstance = cursor.fetchone()
        cursor.close()
        if not monsterInstance:
            return False, Lg().g(439)
        expBonus = monsterInstance['expBonus']
        return True, expBonus, caughtLevel
    def getShopItemExtraAttr(self, shopInfo):
        '''得到商店物品附加属性'''
        characterLevel = self._owner.level.getLevel()

        cursor = connection.cursor()
        sql = "select parameterMin,parameterMax from `shop_extra_attr_level_config` where type=%d and characterLevel=%d"\
            % (shopInfo['extraAttrLevelConfigType'], characterLevel)
        cursor.execute(sql)
        result = cursor.fetchone()
        min = result['parameterMin']
        max = result['parameterMax']
        r = random.randint(min, max)
        cursor.execute(
            "select level from `exattribute_level` where value>=%d" % r)
        level = cursor.fetchone()['level']
        cursor.execute("select * from `extra_attributes` where level=%d" %
                       level)
        tempAttributeList = cursor.fetchall()
        r1 = random.randint(0, len(tempAttributeList) - 1)
        attributeInfo = tempAttributeList[r1]

        attributeInfo['attributeEffects'] = []
        if attributeInfo['effects'] <> '-1' or attributeInfo[
                'effects'] <> u'-1':
            effects = attributeInfo['effects'].split(';')
            for effect in effects:
                effect = int(effect)
                description = loader.getById('effect', effect,
                                             ['description'])['description']
                attributeInfo['attributeEffects'].append(description)
        else:
            script = attributeInfo['script']
            script = util.parseScript(script)
            attributeInfo['attributeEffects'].append(script)

        return attributeInfo
Exemplo n.º 10
0
    def initialise(self, data):
        '''初始化怪物信息
        '''
        levelgroup = data['levelGroup'].split(';')
        encounteroddgroup = data['encounterOddGroup'].split(';')
        dropitemidgroup = data['dropItemIdGroup'].split(';')
        levelQueue = []

        assert len(levelgroup) == len(encounteroddgroup) == len(
            dropitemidgroup)

        last_probability = 0
        for i in range(len(levelgroup)):
            levelMap = {}
            encounterodd_S = int(encounteroddgroup[i]) / self.TotalSeed
            levelMap["level"] = int(levelgroup[i])
            levelMap["dropItemId"] = int(dropitemidgroup[i])
            this_probability = 1 - last_probability
            probability = this_probability * encounterodd_S
            levelMap['probability'] = probability
            last_probability = last_probability + probability
            levelQueue.append(levelMap)

        monster_group_id = data['monsterGroupId']

        element = RandomAssignment(levelQueue)
        monster_level = element['level']
        monster_dropitem_id = element['dropItemId']

        cursor = connection.cursor()
        cursor.execute(
            "select * from `monster_instance` where groupId=%d and level=%d" %
            (monster_group_id, monster_level))
        monsters = cursor.fetchall()
        cursor.close()
        if (len(monsters) <= 0):
            raise Exception('没有找到怪物实例')
            return None
        monster_instance = monsters[0]

        self.formatInfo['id'] = self.baseInfo.id
        self.baseInfo.setName(data['name'])
        self.formatInfo['name'] = data['name']
        self.formatInfo['level'] = monster_level
        self.formatInfo[
            'figure'] = self.templateId  #monster_instance['figure']

        self.formatInfo['hp'] = int(monster_instance['hp'])
        self.formatInfo['mp'] = int(monster_instance['mp'])

        self.formatInfo['maxHp'] = int(monster_instance['hp'])
        self.formatInfo['maxMp'] = int(monster_instance['mp'])

        self.formatInfo['speed'] = int(monster_instance['speed'])
        self.formatInfo['OrdinarySkills'] = int(data['skillId'])
        self.formatInfo['maxAttack'] = int(monster_instance['maxAttack'])
        self.formatInfo['minAttack'] = int(monster_instance['minAttack'])
        self.formatInfo['defense'] = int(monster_instance['defense'])
        self.formatInfo['abs_damage'] = 0
        self.formatInfo['damagePercent'] = 0

        self.formatInfo['hitRate'] = monster_instance['hitRate']
        self.formatInfo['dodgeRate'] = monster_instance['dodgeRate']
        self.formatInfo['criRate'] = monster_instance['criRate']
        self.formatInfo['bogeyRate'] = monster_instance['bogeyRate']

        self.formatInfo['expBonus'] = monster_instance['expBonus']
        self.formatInfo['coinBonus'] = monster_instance['coinBonus']
        self.formatInfo['goldBonus'] = monster_instance['goldBonus']
        self.formatInfo['dropItemId'] = monster_dropitem_id
        self.formatInfo['_instance'] = self

        self.initialiseToo(self.templateId)  #取出数据库里面怪物的值 进行覆盖
Exemplo n.º 11
0
    def initialise(self,data):
        '''初始化怪物信息
        '''
        levelgroup = data['levelGroup'].split(';')
        encounteroddgroup = data['encounterOddGroup'].split(';')
        dropitemidgroup = data['dropItemIdGroup'].split(';')
        levelQueue = []

        assert len(levelgroup) == len(encounteroddgroup) == len(dropitemidgroup)

        last_probability = 0
        for i in range(len(levelgroup)):
            levelMap = {}
            encounterodd_S = int(encounteroddgroup[i]) / self.TotalSeed
            levelMap["level"] = int(levelgroup[i])
            levelMap["dropItemId"] = int(dropitemidgroup[i])
            this_probability = 1 - last_probability
            probability = this_probability * encounterodd_S
            levelMap['probability'] = probability
            last_probability = last_probability + probability
            levelQueue.append(levelMap)

        monster_group_id = data['monsterGroupId']
        
        element = RandomAssignment(levelQueue)
        monster_level = element['level']
        monster_dropitem_id = element['dropItemId']

        cursor = connection.cursor()
        cursor.execute("select * from `monster_instance` where groupId=%d and level=%d" % (monster_group_id, monster_level))
        monsters = cursor.fetchall()
        cursor.close()
        if(len(monsters) <= 0):
            raise Exception('没有找到怪物实例')
            return None
        monster_instance = monsters[0]

        self.formatInfo['id'] = self.baseInfo.id
        self.baseInfo.setName(data['name'])
        self.formatInfo['name'] = data['name']
        self.formatInfo['level'] = monster_level
        self.formatInfo['figure'] = self.templateId#monster_instance['figure']

        self.formatInfo['hp'] = int(monster_instance['hp'])
        self.formatInfo['mp'] = int(monster_instance['mp'])

        self.formatInfo['maxHp'] = int(monster_instance['hp'])
        self.formatInfo['maxMp'] = int(monster_instance['mp'])

        self.formatInfo['speed'] = int(monster_instance['speed'])
        self.formatInfo['OrdinarySkills'] = int(data['skillId'])
        self.formatInfo['maxAttack'] = int(monster_instance['maxAttack'])
        self.formatInfo['minAttack'] = int(monster_instance['minAttack'])
        self.formatInfo['defense'] = int(monster_instance['defense'])
        self.formatInfo['abs_damage'] = 0
        self.formatInfo['damagePercent'] = 0

        self.formatInfo['hitRate'] = monster_instance['hitRate']
        self.formatInfo['dodgeRate'] = monster_instance['dodgeRate']
        self.formatInfo['criRate'] = monster_instance['criRate']
        self.formatInfo['bogeyRate'] = monster_instance['bogeyRate']

        self.formatInfo['expBonus'] = monster_instance['expBonus']
        self.formatInfo['coinBonus'] = monster_instance['coinBonus']
        self.formatInfo['goldBonus'] = monster_instance['goldBonus']
        self.formatInfo['dropItemId'] = monster_dropitem_id
        self.formatInfo['_instance'] = self

        self.initialiseToo(self.templateId) #取出数据库里面怪物的值 进行覆盖