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 = "-1" tmp_exAttributeId = exAttrID.split(';') tmp_exAttributeRate = exAttrRate.split(';') if isPrimaryDrop and tmp_exAttributeId[0] >= 0: return tmp_exAttributeId[0] 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 += (str(exAttr["id"]) + ",") type |= (1 << exAttr["type"]) c += 1 break if ret_exAttributeId == "": ret_exAttributeId = "-1" return ret_exAttributeId
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 = "-1" tmp_exAttributeId = exAttrID.split(';') ; tmp_exAttributeRate = exAttrRate.split(';'); if isPrimaryDrop and tmp_exAttributeId[0] >= 0: return tmp_exAttributeId[0] 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 += (str(exAttr["id"]) + ",") type |= (1 << exAttr["type"]) c += 1 break if ret_exAttributeId == "": ret_exAttributeId = "-1" return ret_exAttributeId
def getSingleMonsterPracticeExp(self, monsterId): id = self._owner.baseInfo.id monsterInfo = loader.getById('npc', monsterId, ['monsterGroupId', 'levelGroup']) if not monsterInfo: return False, u'没有找到怪物' levelList = list(monsterInfo['levelGroup'].split(';')) groupId = monsterInfo['monsterGroupId'] import random tempList = [] for level in levelList: level = int(level) tempList.append(level) #r = random.randint(0, len(tempList) - 1) 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, u'没有找到怪物' expBonus = monsterInstance['expBonus'] return True, expBonus, caughtLevel
def getRelatedShops(self): '''获取玩家所在国家的四所相关商店''' camp = self._owner.camp.getCamp() sql = "select id,name from `place` where camp=%d and (name='武器屋' or name='防具屋' or name='杂货屋' or name='材料屋')" % camp cursor = connection.cursor() cursor.execute(sql) result = cursor.fetchall() cursor.close() return result
def getReceiveableQuests(self): '''得到玩家可接任务''' profession = self._owner.profession.getProfession() exec("profession=u\'" + str(profession) + "\'") camp = self._owner.camp.getCamp() level = self._owner.level.getLevel() templateList = dbaccess.getQuestRecordsTemlate(self._owner.baseInfo.id) cursor = connection.cursor() cursor.execute("select * from `quest_template` where minLevelRequire<=%d and maxLevelRequire>=%d and type<>2" % (level, level)) result = cursor.fetchall() finishedList = self.getFinishedRecordList() list = [] for templateInfo in result: questInfo = {} questInfo['provider'] = templateInfo['provider'] questInfo['accepter'] = templateInfo['accepter'] questInfo['name'] = templateInfo['name'] questInfo['type'] = templateInfo['type'] questInfo['category'] = templateInfo['category'] questInfo['minLevelRequire'] = templateInfo['minLevelRequire'] questInfo['questTemplateId'] = templateInfo['id'] professionLimits = templateInfo['professionRequire'].split(';') parentQuestIds = templateInfo['parentId'].split(';') for parent in parentQuestIds: if int(parent) == -1: if((templateInfo['campRequire'] == camp or templateInfo['campRequire'] == -1)\ and((profession in professionLimits) or (templateInfo['professionRequire'] == u'-1'))): if(templateInfo['type'] == 4): if(templateInfo['minLevelRequire'] == 38): list.append(questInfo) elif(profession in professionLimits): list.append(questInfo) else: list.append(questInfo) else: for quest in finishedList: questTemplateId = quest['questTemplateId'] if questTemplateId == int(parent): if((templateInfo['campRequire'] == camp or templateInfo['campRequire'] == -1)\ and((profession in professionLimits) or (templateInfo['professionRequire'] == u'-1'))): if(templateInfo['type'] == 4): if(templateInfo['minLevelRequire'] == 38): list.append(questInfo) elif(profession in professionLimits): list.append(questInfo) else: list.append(questInfo) if templateInfo['id'] in templateList: if questInfo in list: list.remove(questInfo) for elm in list: elm = self.wrapRecievableQuestObject(elm) return list
def getExtraAttributeValue(self,extraAttributeId): '''得到每个附加属性的价值''' eAttribute = loader.getById('extra_attributes', extraAttributeId, ['level']) cursor = connection.cursor() cursor.execute("select price from exattribute_level where level=%d"%eAttribute['level']) value = cursor.fetchone() cursor.close() return int(value['price'])
def getChildPlaces(placeId): '''获取当前地点的所有下层地点''' cursor = connection.cursor() places = cursor.execute(u"select id,regionId,type,name,camp,levelRequire,image,extentLeft,extentTop,desciption,isBuilded from `place` where parentId=%d and type<>'地点'"\ % placeId).fetchall() cursor.close() if places and len(places) > 0: return places else: return []
def getDropItemTemplate(self, dropConfig): ''' 根据倒落配置得到物品模版 @param dropConfig: 掉落配置 ''' itemTemplate = None r = random.randint(0, 100000) if r > 0 and r < dropConfig['primaryItemRate']: itemTemplate = loader.getById('item_template', dropConfig['primaryItemId'], '*') else: r = random.randint(0, 100000) if r > 0 and r < dropConfig['secondaryItemRate']: cursor = connection.cursor() itemTemplates = cursor.execute("select * from `item_template` where qualityLevel>=%d and qualityLevel<=%d"\ % (dropConfig['secondaryItemQualityLevelLowerBound'], dropConfig['secondaryItemQualityLevelUpperBound'])).fetchall() filterList = self.getItemTypeList(dropConfig['secondaryItemTypeFilter']) itemTemplate = self.getItemWithFilter(itemTemplates, filterList) return itemTemplate
def getChangingProfessionStageQuests(self): '''获取玩家转职任务''' id = self._owner.baseInfo.id profession = self._owner.profession.getProfession() camp = self._owner.camp.getCamp() cursor = connection.cursor() cursor.execute("select * from `quest_template` where type=4 and professionRequire=%d" % profession) quests = cursor.fetchall() questLV20 = None questLV38 = None for quest in quests: if quest['minLevelRequire'] == 20 and quest['campRequire'] == camp: questLV20 = quest else: questLV38 = quest questRecord = dbaccess.getQuestByTemplateId(id, quest['id']) if questRecord: quest['questRecordId'] = questRecord[0] return questLV20, questLV38
def _getQuestNpcInfo(self, npcId, info): '''获取任务npc信息''' cursor = connection.cursor() cursor.execute("select placeId from `place_npc` where npcId=%d" % npcId) placeId = cursor.fetchall() placeIdLen = len(placeId) for id in placeId: cursor.execute("select name,camp,type from `place` where id=%d" % int(id['placeId'])) placeName = cursor.fetchone() if placeIdLen != 1: if placeName['camp'] == self._owner.camp.getCamp() or placeName['camp'] == -1: info['placeId'] = id['placeId'] info['placeName'] = placeName['name'] info['parentPlaceList'] = self.getFullPlaceList(info) else: info['placeId'] = id['placeId'] info['placeName'] = placeName['name'] info['parentPlaceList'] = self.getFullPlaceList(info) cursor.close() return info
def getShopItemPrice(self, itemTemplateId, extraAttribute): '''获取商店物品的购买价格''' sellPrice = 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 getDropItemTemplate(self, dropConfig): ''' 根据倒落配置得到物品模版 @param dropConfig: 掉落配置 ''' itemTemplate = None r = random.randint(0, 100000) if r > 0 and r < dropConfig['primaryItemRate']: itemTemplate = loader.getById('item_template', dropConfig['primaryItemId'], '*') else: r = random.randint(0, 100000) if r > 0 and r < dropConfig['secondaryItemRate']: cursor = connection.cursor() itemTemplates = cursor.execute("select * from `item_template` where qualityLevel>=%d and qualityLevel<=%d"\ % (dropConfig['secondaryItemQualityLevelLowerBound'], dropConfig['secondaryItemQualityLevelUpperBound'])).fetchall() filterList = self.getItemTypeList( dropConfig['secondaryItemTypeFilter']) itemTemplate = self.getItemWithFilter(itemTemplates, filterList) return itemTemplate
def getSingleMonsterPracticeExp(self, monsterId): id = self._owner.baseInfo.id monsterInfo = loader.getById('npc', monsterId, ['monsterGroupId', 'levelGroup']) if not monsterInfo: return False, u'没有找到怪物' levelList = list(monsterInfo['levelGroup'].split(';')) groupId = monsterInfo['monsterGroupId'] import random tempList = [] for level in levelList: level = int(level) tempList.append(level) #r = random.randint(0, len(tempList) - 1) 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, u'没有找到怪物' expBonus = monsterInstance['expBonus'] return True, expBonus,caughtLevel
def getAllRecievableRewardQuestList(self, npcId): '''得到所有符合玩家条件的赏金任务列表''' questLevel = 10 level = self._owner.level.getLevel() camp = self._owner.camp.getCamp() if level >= 10 and level < 20: questLevel = 10 elif level >= 20 and level < 30: questLevel = 20 elif level >= 30 and level < 40: questLevel = 30 elif level >= 40 and level < 50: questLevel = 40 elif level >= 50 and level < 60: questLevel = 50 else: questLevel = 60 cursor = connection.cursor() cursor.execute("select * from `quest_template` where type=2 and provider=%s and minLevelRequire =%d\ and campRequire=%d" % (npcId, questLevel, camp)) rewardQuestList = cursor.fetchall() cursor.close() return rewardQuestList
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 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 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'] def RandomAssignment(queue): lst = [] down = 0 up = 0 for item in queue: down = up up += item["probability"] assert up <= 1 lst.append((item, down, up)) import random randomnumber = random.random() for i in lst: if i[1] <= randomnumber < i[2]: return i[0] 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._details = _getCommonbaseValues() self._details['isCharacter'] = self.getType() == 1 self._details['id'] = data['id'] self._details['name'] = data['name'] self._details['level'] = monster_level self._details['image'] = data['image'] self._details['professionName'] = '' self._details['figure'] = monster_instance['figure'] self._details['hp'] = int(monster_instance['hp']) self._details['mp'] = int(monster_instance['mp']) self._details['maxHp'] = int(monster_instance['hp']) self._details['maxMp'] = int(monster_instance['mp']) self._details['speed'] = int(monster_instance['speed']) #self._details['speedDesc'] = self._owner.attribute.getCurrSpeedDescription(self._details['speed']) self._details['maxAttack'] = int(monster_instance['maxAttack']) self._details['minAttack'] = int(monster_instance['minAttack']) self._details['defense'] = int(monster_instance['defense']) self._details['hitRate'] = monster_instance['hitRate'] self._details['dodgeRate'] = monster_instance['dodgeRate'] self._details['criRate'] = monster_instance['criRate'] self._details['bogeyRate'] = monster_instance['bogeyRate'] self._details['startBattleSentence'] = data['startBattleSentence'] self._details['criSentence'] = data['criSentence'] self._details['breSentence'] = data['breSentence'] self._details['criAndBreSentence'] = data['criAndbreSentence'] self._details['missSentence'] = data['missSentence'] self._details['beMissedSentence'] = data['beMissedSentence'] self._details['beCrackedSentence'] = data['beCrackedSentence'] self._details['usingSkillSentence'] = data['usingSkillSentence'] self._details['winSentence'] = data['winSentence'] self._details['failSentence'] = data['failSentence'] self._details['expBonus'] = monster_instance['expBonus'] self._details['coinBonus'] = monster_instance['coinBonus'] self._details['goldBonus'] = monster_instance['goldBonus'] self._details['dropItemId'] = monster_dropitem_id self._details['_instance'] = self
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'] def RandomAssignment(queue): lst = [] down = 0 up = 0 for item in queue: down = up up += item["probability"] assert up <= 1 lst.append((item, down, up)) import random randomnumber = random.random() for i in lst: if i[1] <= randomnumber < i[2]: return i[0] 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._details = _getCommonbaseValues() self._details['isCharacter'] = self.getType() == 1 self._details['id'] = data['id'] self._details['name'] = data['name'] self._details['level'] = monster_level self._details['image'] = data['image'] self._details['professionName'] = '' self._details['figure'] = monster_instance['figure'] self._details['hp'] = int(monster_instance['hp']) self._details['mp'] = int(monster_instance['mp']) self._details['maxHp'] = int(monster_instance['hp']) self._details['maxMp'] = int(monster_instance['mp']) self._details['speed'] = int(monster_instance['speed']) #self._details['speedDesc'] = self._owner.attribute.getCurrSpeedDescription(self._details['speed']) self._details['maxAttack'] = int(monster_instance['maxAttack']) self._details['minAttack'] = int(monster_instance['minAttack']) self._details['defense'] = int(monster_instance['defense']) self._details['hitRate'] = monster_instance['hitRate'] self._details['dodgeRate'] = monster_instance['dodgeRate'] self._details['criRate'] = monster_instance['criRate'] self._details['bogeyRate'] = monster_instance['bogeyRate'] self._details['startBattleSentence'] = data['startBattleSentence'] self._details['criSentence'] = data['criSentence'] self._details['breSentence'] = data['breSentence'] self._details['criAndBreSentence'] = data['criAndbreSentence'] self._details['missSentence'] = data['missSentence'] self._details['beMissedSentence'] = data['beMissedSentence'] self._details['beCrackedSentence'] = data['beCrackedSentence'] self._details['usingSkillSentence'] = data['usingSkillSentence'] self._details['winSentence'] = data['winSentence'] self._details['failSentence'] = data['failSentence'] self._details['expBonus'] = monster_instance['expBonus'] self._details['coinBonus'] = monster_instance['coinBonus'] self._details['goldBonus'] = monster_instance['goldBonus'] self._details['dropItemId'] = monster_dropitem_id self._details['_instance'] = self