Ejemplo n.º 1
0
 def refreshMonster(self):
     result = {}
     roleLevel = self.owner.getLevel()
     goldInstanceDict = self.getGoldInstanceData()
     roleLevel = Utils.ceil_key(goldInstanceDict, roleLevel)
     print "GoldInstanceSystem, method:refreshMonster, roleLevel, goldInstanceDict:", roleLevel, goldInstanceDict
     goldInstanceData = self.getGoldInstanceDataByLevel(roleLevel)
     print "GoldInstanceSystem, method:refreshMonster, goldInstanceData:", goldInstanceData
     #获取到记录的怪物统计信息等
     statistic = self.getGoldInstanceStatistic()
     print "GoldInstanceSystem, method:refreshMonster, statistic:", statistic
     weightDict = self.getMonstersWeightInfo()
     print "GoldInstanceSystem, method:refreshMonster, weightDict:",weightDict
     #剩余可以生成怪物总量
     remainder = REFRESH_MONSTER_NUMBER
     #循环所有怪物,获取随机数是否可以
     while remainder > 0:
         #随机一个值,如果这个值在当前怪物的权重范围内,再循环一次
         rate = random.randint(0, 100)
         #通过随机数计算出来的权值
         value = Utils.ceil_key(weightDict, rate)
         print "GoldInstanceSystem, method:refreshMonster, rate,value:",rate,value
         #通过权值获取到怪物id
         monsterId = weightDict.get(value)
         
         #判断统计信息中,是否存在这只怪物,如果存在获取到怪物创建次数
         if monsterId in statistic:
             monster = self.getStatisticInfoById(monsterId)
             createTimes = monster[INFO_INDEX_CREATE]
         else:
             createTimes = 0
         #获取到怪物配置信息
         goldInstance = goldInstanceData[monsterId]
         count = goldInstance.get("count_i")#数量
         #判断当前出现次数是否小于指定次数
         if createTimes < count:
             remainder -=1
             if monsterId not in result:
                 result[monsterId] = 1
             else:
                 result[monsterId] = result[monsterId] + 1
     print "GoldInstanceSystem, method:refreshMonster, result:",result
     return result
Ejemplo n.º 2
0
 def getGoldInstanceDataByLevel(self, roleLevel):
     goldInstanceData = self.getGoldInstanceData()
     if goldInstanceData:
         roleLevelKey = Utils.ceil_key(goldInstanceData, roleLevel)
         if roleLevelKey:
             roleLevelValueData = goldInstanceData.get(roleLevelKey)
             if roleLevelValueData:
                 return roleLevelValueData
             else:
                 logging.error("GoldInstanceSystem, method: getGoldInstanceDataByLevel, roleLevelValueData: %s:" % (roleLevelValueData))
         else:
             logging.error("GoldInstanceSystem, method: getGoldInstanceDataByLevel, roleLevelKey: %s:" % (roleLevelKey))
     else:
         logging.error("GoldInstanceSystem, method: getGoldInstanceDataByLevel, goldInstanceData: %s:" % (goldInstanceData))
     return None
Ejemplo n.º 3
0
 def refreshMonster_bak(self):
     result = {}
     roleLevel = self.owner.getLevel()
     goldInstanceDict = self.getGoldInstanceData()
     roleLevel = Utils.ceil_key(goldInstanceDict, roleLevel)
     #print "GoldInstanceSystem, method:refreshMonster, roleLevel, goldInstanceDict:", roleLevel, goldInstanceDict
     goldInstanceData = self.getGoldInstanceDataByLevel(roleLevel)
     #print "GoldInstanceSystem, method:refreshMonster, goldInstanceData:", goldInstanceData
     #获取到记录的怪物统计信息等
     statistic = self.getGoldInstanceStatistic()
     #print "GoldInstanceSystem, method:refreshMonster, statistic:", statistic
     
     monstersList,weightList = self.getMonstersAndWeight_bak()
     simpleMosterId = monstersList[-1]
     #print "GoldInstanceSystem, method:refreshMonster, monstersList, simpleMosterId: weightList:", monstersList, simpleMosterId, weightList
     #剩余可以生成怪物总量
     remainder = REFRESH_MONSTER_NUMBER
     #循环所有怪物,获取随机数是否可以
     #for monsterId in goldInstanceData:
     for monsterId in monstersList:
         #print "GoldInstanceSystem, method:refreshMonster, monsterId:", monsterId
         if monsterId in statistic:
             monster = self.getStatisticInfoById(monsterId)
             createTimes = monster[INFO_INDEX_CREATE]
         else:
             createTimes = 0
         #print "GoldInstanceSystem, method:refreshMonster, createTimes,", createTimes
         
         goldInstance = goldInstanceData[monsterId]
         weight = goldInstance.get("weight_i")#权重
         count = goldInstance.get("count_i")#数量
         #获取到普通怪物的ID,三元表达式
         #simpleMosterId = simpleMosterId == weight?monsterId:simpleMosterId
         simpleMosterId = monsterId if simpleMosterId == weight else simpleMosterId
         #print "GoldInstanceSystem, method:refreshMonster, simpleMosterId:", simpleMosterId
         #如果生成次数小于等于生成上限制,取随机数.随机出
         if createTimes < count:
             isBreak = True
             #这里可以加个while循环,用于实现策划的循环需求
             while isBreak:
                 #print "GoldInstanceSystem, method:refreshMonster, result, monsterId:", result, monsterId
                 #随机一个值,如果这个值在当前怪物的权重范围内,再循环一次
                 rate = random.randint(0, 100)
                 value = Utils.ceilListKey(weightList, rate) 
                 #print "GoldInstanceSystem, method:refreshMonster, rate,value", rate, value
                 
                 if  value == weight:
                     #怪物中标,剩余怪物总量-1,加入集合
                     remainder -=1
                     if monsterId not in result:
                         result[monsterId] = 1
                     else:
                         result[monsterId] = result[monsterId] + 1
                 else:
                     #没中标,停止循环,循环下一个怪物
                     isBreak = False
                 #如果已经生成了指定数量的怪物,则停止循环
                 if remainder == 0:
                     break
     #如果怪物没有生成到指定数量,则生成全部的小怪
     if remainder > 0:
         #print "GoldInstanceSystem, method:refreshMonster, result, simpleMosterId,remainder:", result, simpleMosterId,remainder
         if simpleMosterId not in result:
             result[simpleMosterId] = remainder
         else:
             result[simpleMosterId] = result[simpleMosterId] + remainder
     #print "GoldInstanceSystem, method:refreshMonster, result:", result
     #返回生成的怪物集合
     return result