def init_setting(): """ 奖励上限,返回:(银币, 练历) """ global arena_level, max_rewards, free_count, arena_coin, arena_ranks, \ arena_rw_succ, arena_rw_fail, arena_rw_weekdays, arena_rewards, \ arena_auto_start setting_mgr = Game.setting_mgr arena_level = setting_mgr.setdefault(ARENA_LEVEL, ARENA_LEVEL_V) auto_times = setting_mgr.setdefault(ARENA_MAX_REWARD, ARENA_MAX_REWARD_V) max_rewards = make_lv_regions(str2dict2(auto_times).items()) free_count = setting_mgr.setdefault(ARENA_FREE_COUNT, ARENA_FREE_COUNT_V) arena_coin = setting_mgr.setdefault(ARENA_YB, ARENA_YB_V) ranks = setting_mgr.setdefault(ARENA_RANK, ARENA_RANK_V) arena_ranks = make_lv_regions(str2dict2(ranks).items()) #奖励 rw_succ = setting_mgr.setdefault(ARENA_RW_SUCC, ARENA_RW_SUCC_v) arena_rw_succ = map(int, rw_succ.split('|')) rw_fail = setting_mgr.setdefault(ARENA_RW_FAIL, ARENA_RW_FAIL_v) arena_rw_fail = map(int, rw_fail.split('|')) arena_rw_weekdays = setting_mgr.setdefault(ARENA_RW_WEEKDAY, ARENA_RW_WEEKDAY_V) arena_rw_weekdays = map(int, arena_rw_weekdays.split('|')) rewards = setting_mgr.setdefault(ARENA_REWARDS, ARENA_REWARDS_V) arena_rewards = make_lv_regions(rewards) arena_auto_start = setting_mgr.setdefault(ARENA_AUTO_START, ARENA_AUTO_START_V)
def handle_setting(cls): """ 处理修改资源表 """ cls.setting_data = {} res_cost = Game.setting_mgr.setdefault(ROLEUP_COST_ITEM, ROLEUP_COST_ITEM_V) cls.setting_data[ROLEUP_COST_ITEM] = common.str2list(res_cost) #银币培养 res_coin1 = Game.setting_mgr.setdefault(ROLETRAIN_COIN1, ROLETRAIN_COIN1_V) cls.setting_data[ROLETRAIN_COIN1] = common.str2dict2(res_coin1) #元宝培养 res_coin2 = Game.setting_mgr.setdefault(ROLETRAIN_COIN2, ROLETRAIN_COIN2_V) cls.setting_data[ROLETRAIN_COIN2] = common.str2dict2(res_coin2) res_locklevel = Game.setting_mgr.setdefault(ROLETRAIN_LOCKLEVEL, ROLETRAIN_LOCKLEVEL_V) cls.setting_data[ROLETRAIN_LOCKLEVEL] = res_locklevel
def gem_reset(self): """珠宝商店重置""" d_cost = self.player._game.setting_mgr.setdefault(GEM_SHOP_RESET_COST, GEM_SHOP_RESET_COST_V) if d_cost is None: return False, errcode.EC_VALUE if not common.is_today(self.gemShopData.rt): self.gemShopData.rc = 0 self.gemShopData.rt = common.current_time() d_cost = common.str2dict2(d_cost) cost = 0 for k, v in d_cost.iteritems(): start, end = int(v[0]), int(v[1]) cs = 0 if start <= self.gemShopData.rc + 1 <= end: index = range(start, end + 1).index(self.gemShopData.rc + 1) + 1 cost = int(k) * index + cs break cs += int(k) * end if not self.player.enough_coin_ex(0, aCoin3=cost): return False, errcode.EC_COST_ERR self.player.cost_coin_ex(aCoin3=cost) self.gemShopData.rc += 1 self.gemShopData.sids = self.player._game.res_mgr.get_gem_shop_by_rate(self.gemShopData.n) nt = self.gem_next_time() return True, dict(n = self.gemShopData.n, sids = self.gemShopData.sids, t=nt - common.current_time(), data = self.player.pack_msg_data(coin=True), rc = self.gemShopData.rc)
def join(self, pid): """ 加入房间 """ if self.is_war: return False, errcode.EC_ALLY_WAR_ING if len(self.pids) >= self.res_warstart_config.mplayer: return False, errcode.EC_ALLY_WAR_ROOMMAX if pid in self.pids: return False, errcode.EC_ALLY_WAR_ENTERED self.pids.append(pid) _, glory = Game.rpc_ally_mgr.get_glory_by_pid(pid) if not self.books: books = common.str2dict2(self.res_warstart_config.books) for bid, (num, emax) in books.iteritems(): self.books[bid] = int(num) self.ebooks[bid] = int(emax) now = common.current_time() rtime = self.res_warstart_config.rtime - (now - self.b_time) if not self.tname: self.tname = self.get_change_tname data = dict(rnum=self.id, rtime=rtime, pnum=len(self.pids), asid=self.res_warstart_config.id, glory=glory, books=self.books, tname=self.tname) self.join_broad(pid) return True, data
def _calc_CBE(self, prop): """计算角色战力 战斗力 = 勇力*0.8 + 迅捷*2 + 体魄*2 + 智略*0.7 + 攻击*0.5 + 防御*2 + 速度*2 + 生命/5+ (命中率—95)*100 + 回避率*200 + 格挡率*200 + 反击率*200 + 暴击率*50 +爆伤率*50 + 破甲率*50 + 免伤率*100 + 连击率*100 """ CBE = 0 setting = self.player._game.setting_mgr data = setting.setdefault(CALC_CBE, CALC_CBE_V) data = str2dict(data, ktype=str, vtype=float) type_data = setting.setdefault(DATA_TYPE_KEY, DATA_TYPE_KEY_V) setting_type = str2dict2(type_data) for k, v in data.iteritems(): if CBE_FIX_TAG in k: CBE += v continue if setting_type.has_key(k) and len(setting_type[k]) > 1: value = float(getattr(prop, k, 0)) else: value = int(getattr(prop, k, 0)) CBE += value * v return int(CBE)
def _init_res_task(self, objs): """ 任务表提取兵符任务 """ self.bf_task_by_unlock.clear() for o in objs: if o.type == TT_OFFER: unlock = str2dict2(o.unlock) level = unlock['level'] if unlock.has_key('tid'): tid = int(unlock['tid'][0]) else: tid = 0 tKey = (int(level[0]), int(level[1]), tid) self.bf_task_by_unlock.setdefault(tKey, []) self.bf_task_by_unlock[tKey].append(o)
def _init_res_task(self, objs): """ 任务表提取兵符任务 """ self.bf_task_by_unlock.clear() for o in objs: if o.type == TT_OFFER: unlock = str2dict2(o.unlock) level = unlock['level'] if unlock.has_key('tid'): tid = int(unlock['tid'][0]) else: tid = 0 tKey = (int(level[0]),int(level[1]), tid) self.bf_task_by_unlock.setdefault(tKey, []) self.bf_task_by_unlock[tKey].append(o)
def inlay(self, player, eid, gid, index): """镶嵌""" equip, res_eq = player.bag.get_equip_ex(eid) if equip is None or res_eq is None: return False, errcode.EC_GEM_NOT_FIND #已经镶嵌 if index in equip.data.gem: return False, errcode.EC_GEM_INDEX_USED gem, res_gem = player.bag.get_gem_ex(gid) if gem is None or res_gem is None: return False, errcode.EC_GEM_NOT_FIND #部位检查 if res_eq.part not in res_gem.parts: return False, errcode.EC_GEM_ERR_PART #是否已镶嵌同类型珠宝 for _gid in equip.data.gem.itervalues(): log.debug('_gid--- %s', _gid) _gem, _res_gem = player.bag.get_gem_ex(_gid) if _res_gem.type == res_gem.type: return False, errcode.EC_GEM_SAME_TYPE #合法的index max_index = 0 data = player._game.setting_mgr.setdefault(GEM_MAX_INDEX, GEM_MAX_INDEX_V) data = str2dict2(data) for d_index, st_end in data.iteritems(): start = int(st_end[0]) end = int(st_end[1]) if start <= res_eq.limit <= end: max_index = int(d_index) break if index > max_index: return False, errcode.EC_GEM_ERR_INDEX gem.data.used = USED_DO player.bag.update_gem(gem, used_count=-1) equip.data.gem[index] = gid player.bag.update_equip(equip) return True, player.pack_msg_data(equips=[equip], gem=[gem])
def _calc_role(self, role): """ 计算角色属性 """ prop = RoleProperty() setting = self.player._game.setting_mgr item_mgr = self.player._game.item_mgr res_mgr = self.player._game.res_mgr bag = self.player.bag calc_args = setting.setdefault(CALC_PROP_ARGS, CALC_PROP_ARGS_V) calc_args = str2dict2(calc_args) calc_args = self.get_calc_args(role, calc_args) #角色基础属性 res_role_level = role.get_res_role_level() if res_role_level: role_level = self._calc_base(res_role_level, calc_args, is_all=False) prop.add_dict(role_level) #武器(宝具) r = res_mgr.roles.get(role.data.rid) if r: key = (r.armId, role.data.armLevel) res_arm_leve = res_mgr.arm_level_by_keys.get(key) arm_leve = self._calc_base(res_arm_leve, calc_args) prop.add_dict(arm_leve) #装备 suit = {} #套装 for _, eid in role.iter_equips(): equip, res_equip = bag.get_equip_ex(eid) if not res_equip: continue #基础 base_equip = self._calc_base(res_equip, calc_args) prop.add_dict(base_equip) #珠宝 for gid in equip.data.gem.itervalues(): gem = self.player.bag.get_gem(gid) if gem is None: continue key = (gem.data.gid, gem.data.level) res_gem_level = self.player._game.res_mgr.gem_levels.get(key) if res_gem_level is None: continue prop_gem = self._calc_base(res_gem_level, calc_args) prop.add_dict(prop_gem) #强化 if equip.data.level > 0: res_equip_level = item_mgr.get_res_equip_level( res_equip.part, equip.data.level) equip_level = self._calc_base(res_equip_level, calc_args) prop.add_dict(equip_level) #套装 suit.setdefault(res_equip.sid, 0) suit[res_equip.sid] += 1 for sid, num in suit.iteritems(): res = res_mgr.equip_sets.get(sid) if res is None: continue effect = res.get_effect(num) if effect is None: continue effect = self.str2dict1(effect, ktype=str, vtype=float) if effect is None: continue effect = self._calc_base_dict(effect, calc_args) prop.add_dict(effect) #命格 for _, fid in role.iter_fates(): fate, res_fate = bag.get_fate_ex(fid) if not res_fate: continue res_fate_level = item_mgr.get_res_fate_level( res_fate.id, fate.data.level) fate_level = self._calc_base(res_fate_level, calc_args) prop.add_dict(fate_level) #阵型 position = self.player.positions.get_active() position_level = None if position: key = (position.data.posId, position.data.level) position_level = res_mgr.position_levels.get(key) if position_level: for pos, rid in position.iter_rids(): if rid != role.data.rid: continue n = position.POS_TMP % pos attrs = getattr(position_level, n) if attrs: attrs = self.str2dict1(attrs, ktype=str, vtype=float) attrs = self._calc_base_dict(attrs, calc_args) prop.add_dict(attrs) return prop