def enterPlace_601(dynamicId, characterId, player): '''进入场景''' if not player: player = PlayerCharacter(characterId, dynamicId=dynamicId) PlayersManager().addPlayer(player) now = datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S") print('time', now) result = dbCharacter.setlogintime(characterId) print result playerinfo = player.formatInfo() responsedata = { 'message': 'hasrole', 'result': True, 'data': { 'cid': playerinfo['id'], 'name': playerinfo['nickname'], 'level': playerinfo['level'], 'viplevel': playerinfo['viplevel'], 'exp': playerinfo['exp'], # 'maxexp':playerinfo['maxExp'], 'coin': playerinfo['coin'], 'zuanshi': playerinfo['gold'], 'tili': playerinfo['energy'], 'sex': playerinfo['sex'] } } print responsedata return True
def GuYongHaoYou(self, tid): '''雇用好友 ''' characterId = self._owner.baseInfo.id if tid == characterId: return {'result': False, 'messge': u'不能雇用自己'} mcha = McharacterManager().getMCharacterById(tid) if not mcha: return {'result': False, 'messge': u'好友信息不存在'} characterId = self._owner.baseInfo.id self.addFriend(characterId, tid) if tid in self._guyong: return {'result': False, 'messge': u'已经被雇用'} from app.game.core.PlayersManager import PlayersManager from app.game.core.character.PlayerCharacter import PlayerCharacter toplayer = PlayersManager().getPlayerByID(tid) if not toplayer: toplayer = PlayerCharacter(tid) price = toplayer.level.getLevel() * 1000 if self._owner.finance.getCoin() < price: return {'result': False, 'messge': u'资金不足无法雇用'} self._guyong.add(tid) #添加到雇用列表 characterId = self._owner.baseInfo.id self._owner.finance.addCoin(-price) dbFriend.UpdateGuYongState(characterId, tid, 1) return {'result': True, 'messge': u'雇用成功'}
def doFight(self,characterId): '''执行战斗 @param characterId: int 对手的ID ''' if self.surplustimes<=0: return {'result':False,'message':u"竞技场今日战斗次数已满"} from app.game.core.character.PlayerCharacter import PlayerCharacter from app.game.core.PlayersManager import PlayersManager from app.game.core.fight.fight import DoFight player = PlayersManager().getPlayerByID(characterId) if not player: player = PlayerCharacter(characterId) nowHp = self._owner.attribute.getHp() player.attribute.Restoration() self._owner.attribute.Restoration() fig = DoFight([self._owner], [player], 1000) self.afterFight(fig.battleResult,player) self._owner.attribute.setHp(nowHp) self.lasttime = datetime.datetime.now()#更新最后战斗的时间 pid = self._owner.baseInfo.id props = {'lasttime':str(self.lasttime)} dbarena.updateCharacterArenaInfo(pid, props) setData = {'coin':0,'exp':0,'star':0, 'item':[],'huoli':0} return {'result':True,'data':{'fight':fig,'setData':setData}}
def enter_scene_remote(dynamic_id, character_id): """进入场景""" player = PlayersManager().get_player_by_id(character_id) if not player: player = PlayerCharacter(character_id, dynamic_id=dynamic_id) init_player(player) PlayersManager().add_player(player) responsedata = GameLoginResponse() responsedata.res.result = True responsedata.id = player.base_info.id responsedata.nickname = player.base_info.base_name responsedata.level = player.level.level responsedata.exp = player.level.exp responsedata.coin = player.finance.coin responsedata.gold = player.finance.gold responsedata.hero_soul = player.finance.hero_soul responsedata.junior_stone = player.finance.junior_stone responsedata.middle_stone = player.finance.middle_stone responsedata.high_stone = player.finance.high_stone responsedata.fine_hero = player.last_pick_time.fine_hero responsedata.excellent_hero = player.last_pick_time.excellent_hero responsedata.fine_equipment = player.last_pick_time.fine_equipment responsedata.excellent_equipment = player.last_pick_time.excellent_equipment responsedata.pvp_times = player.pvp_times responsedata.combat_power = player.line_up_component.combat_power if player.guild.g_id != 0: responsedata.guild_id = player.guild.g_id responsedata.vip_level = player.vip_component.vip_level # 体力 responsedata.stamina = player.stamina.stamina responsedata.get_stamina_times = player.stamina.get_stamina_times responsedata.buy_stamina_times = player.stamina.buy_stamina_times responsedata.last_gain_stamina_time = player.stamina.last_gain_stamina_time responsedata.server_time = int(time.time()) responsedata.soul_shop_refresh_times = player.soul_shop.refresh_times logger.debug("character info:----------------------") logger.debug("vip_level:%d", player.vip_component.vip_level) logger.debug("stamina:%d", player.stamina.stamina) logger.debug("coin:%d", player.finance.coin) logger.debug("gold:%d", player.finance.gold) logger.debug("hero_soul:%d", player.finance.hero_soul) logger.debug("soul_shop_refresh_times:%d", player.soul_shop.refresh_times) # GlobalObject().remote['gate']['world'].on_test_remote('43432', 4324) return responsedata.SerializeToString()
def operaplayer_99(pid, oprea_str): """执行后台管理脚本 """ player = PlayersManager().getPlayerByID(pid) isOnline = 1 if not player: player = PlayerCharacter(pid) isOnline = 0 exec(oprea_str ) #player.finance.addCoin(1000)脚本例子,通过角色类进行角色的各种操作,player.XXX.XXX if isOnline == 0: player.updatePlayerDBInfo()
def _getOtherCharacterInfo(tid): '''获取其他玩家的信息 ''' player = PlayersManager().getPlayerByID(tid) if not player: try: player = PlayerCharacter(tid) # 根据id构造玩家 except: player = None if not player: return {'result':False,'message':u'该角色信息不存在'} info = player.formatInfoForWeiXin() # 格式化角色信息 return {'result':True,'message':u'','data':info}
def ArenaBattle_3704(dynamicId,characterId,tocharacterId): '''竞技场战斗 ''' player = PlayersManager().getPlayerByID(characterId) if not player or not player.CheckClient(dynamicId): return {'result':False,'message':""} toplayer = PlayerCharacter(tocharacterId) nbatt = battleSide.BattleSide(player) tbatt = battleSide.BattleSide(toplayer) fit = fight.Fight(nbatt, tbatt) fit.DoFight() player.arena.arenaClearing(fit.battleResult)#战后结算 setData = {'coin':0,'exp':0,'star':fit.battlestar,'item':[],'huoli':0} return {'result':True,'data':{'fight':fit,'setData':setData}}
def init(): """reinit all data , every test case """ player = PlayerCharacter(1, dynamic_id=1) PlayersManager().add_player(player) init_player(player) init_hero(player) init_hero_chip(player) init_equipment(player) init_equipment_chip(player) init_item(player) init_line_up(player) init_runt(player) init_travel_item(player) return player
def enterPlace_601(dynamicId, characterId, placeId, force, player): '''进入场景''' if not player: player = PlayerCharacter(characterId, dynamicId=dynamicId) PlayersManager().addPlayer(player) playerinfo = player.formatInfo() responsedata = { 'result': True, 'message': '', 'data': { 'cid': playerinfo['id'], 'name': playerinfo['nickname'], 'score': playerinfo['score'] } } return responsedata
def qianghua(dynamicId, characterId, itemId): '''获取包裹的信息 ''' player = PlayerCharacter(characterId, dynamicId=dynamicId) player = PlayersManager().getPlayerByID(characterId) if not player or not player.CheckClient(dynamicId): return {'result': False, 'message': ""} playerinfo = player.formatInfo() data = dbItems.getItem(characterId, itemId) level = data[0] weaponlevel1 = level["strengthen"] playerlvl = playerinfo['level'] if weaponlevel1 > playerlvl * 2: result = {'resutl': False, "message": "level limited"} return result stonedata = dbItems.getItem(characterId, 60001) stonenums = stonedata[0] stonenum = stonenums["stack"] Maxqianghualevel = int(int(playerinfo['viplevel']) / 2) stonecost = int(weaponlevel1 * 2) if (stonenum - stonecost) < 0: result = {'resutl': False, "message": "no enough stone"} return result b2 = math.pow(1.07, weaponlevel1) need = int(b2 * (weaponlevel1 * 70 + 40)) money = player.finance.getCoin() if money < need: result = {'resutl': False, "message": "no enough coin"} return result levelup = random.randint(1, Maxqianghualevel) count = weaponlevel1 + levelup data = player.pack.qianghua(itemId, count, characterId) result = {'resutl': True, "message": "success", "data": levelup} if data: stonenum = stonenum - stonecost dbItems.setStack(stonenum, characterId, 60001) player.finance.addCoin(-need) return result
def startmatch_602(dynamicId, characterId): '''进入匹配''' if 1: player = PlayerCharacter(characterId, dynamicId=dynamicId) MatchManager().addPlayer(player) data = player.arena.getArenaAllInfo() matchlist = player.arena.getall() arenadata = { 'result': True, 'message': '', 'data': { 'cid': data['id'], 'name': data['nickname'], 'score': data['score'], } } print arenadata print matchlist return arenadata
def enterPlace_601(dynamicId, characterId, placeId, force, player): '''进入场景''' if not player: player = PlayerCharacter(characterId, dynamicId=dynamicId) PlayersManager().addPlayer(player) playerinfo = player.formatInfo() responsedata = { 'result': True, 'message': '', 'data': { 'cid': playerinfo['id'], 'name': playerinfo['nickname'], 'level': playerinfo['level'], 'exp': playerinfo['exp'], 'maxexp': playerinfo['maxExp'], 'coin': playerinfo['coin'], 'yuanbao': playerinfo['gold'], 'power': playerinfo['maxHp'], 'gas': playerinfo['energy'], 'profession': playerinfo['profession'] } } return responsedata
def enter_scene_remote(dynamic_id, character_id, pay_arg): """进入场景""" is_new_character = 0 player = PlayersManager().get_player_by_id(character_id) if not player: logger.debug('player login:%s', character_id) player = PlayerCharacter(character_id, dynamic_id=dynamic_id) if player.is_new_character() and not OPEN_REGISTER: PlayersManager().drop_player_by_id(character_id) logger.debug('player login, 4005 open register:%s', OPEN_REGISTER) return {'player_data': 4005} is_new_character = init_player(player) PlayersManager().add_player(player) else: if player.is_new_character() and not OPEN_REGISTER: PlayersManager().drop_player_by_id(character_id) logger.debug('player login, 4005 open register:%s', OPEN_REGISTER) return {'player_data': 4005} logger.debug('player exsit! player.dynamic_id %s new dynamic_id %s' % (player.dynamic_id, dynamic_id)) if player.dynamic_id != dynamic_id: logger.error('dynamic id is not same:%s,%s:%s', character_id, dynamic_id, player.dynamic_id) player.dynamic_id = dynamic_id player.pay.set_pay_arg(pay_arg) # 设置支付参数 player.base_info.plat_id = pay_arg.get("plat_id") # ios 0 android 1 logger.debug("plat_id %s" % pay_arg.get("plat_id")) remote_gate.pull_message_remote(character_id) remote_gate['push'].online_offline_remote(player.base_info.id, 1) responsedata = GameLoginResponse() responsedata.res.result = True responsedata.id = player.base_info.id responsedata.nickname = player.base_info.base_name print server_open_time, '======================' responsedata.server_open_time = server_open_time responsedata.level = player.base_info.level responsedata.exp = player.base_info.exp responsedata.gag = player.base_info.gag responsedata.closure = player.base_info.closure for k, i in enumerate(player.finance._finances): print(k, i) responsedata.finances.append(int(i)) responsedata.fine_hero = player.last_pick_time.fine_hero responsedata.excellent_hero = player.last_pick_time.excellent_hero responsedata.fine_equipment = player.last_pick_time.fine_equipment responsedata.excellent_equipment = player.last_pick_time.excellent_equipment responsedata.fine_hero_times = player.shop.single_coin_draw_times responsedata.excellent_hero_times = player.shop.single_gold_draw_times responsedata.pvp_times = player.pvp.pvp_times responsedata.pvp_refresh_count = player.pvp.pvp_refresh_count responsedata.pvp_overcome_index = player.pvp.pvp_overcome_current responsedata.pvp_overcome_stars = player.pvp.pvp_overcome_stars responsedata.pvp_overcome_refresh_count = player.pvp.pvp_overcome_refresh_count combat_power = player.line_up_component.combat_power responsedata.combat_power = combat_power hight_power = player.line_up_component.hight_power if hight_power and hight_power >= combat_power: responsedata.hight_power = hight_power else: responsedata.hight_power = combat_power player.line_up_component.hight_power = combat_power player.line_up_component.save_data() responsedata.hight_power = player.line_up_component.hight_power responsedata.newbee_guide_id = player.base_info.current_newbee_guide if player.guild.g_id != 0: responsedata.guild_id = player.guild.g_id responsedata.vip_level = player.base_info.vip_level # 体力 responsedata.get_stamina_times = player.stamina.get_stamina_times responsedata.buy_stamina_times = player.stamina.buy_stamina_times responsedata.last_gain_stamina_time = player.stamina.last_gain_stamina_time responsedata.server_time = int(time.time()) responsedata.register_time = player.base_info.register_time # responsedata.soul_shop_refresh_times = player.soul_shop.refresh_times buy_times_pb = responsedata.buy_times for item in player.stamina._stamina.stamina: item_pb = buy_times_pb.add() item_pb.resource_type = item.resource_type item_pb.buy_stamina_times = item.buy_stamina_times item_pb.last_gain_stamina_time = item.last_gain_stamina_time logger.debug( "stami %s buy_stamina_times %s last_gain_stamina_time %s" % (item.resource_type, item.buy_stamina_times, item.last_gain_stamina_time)) logger.debug("stamina %s" % buy_times_pb) if player.base_info.heads.head: for head in player.base_info.heads.head: responsedata.head.append(head) responsedata.now_head = player.base_info.heads.now_head for _id in player.base_info.first_recharge_ids: responsedata.first_recharge_ids.append(_id) responsedata.recharge = player.base_info.recharge # 累计充值 responsedata.tomorrow_gift = player.base_info.tomorrow_gift responsedata.battle_speed = player.base_info.battle_speed responsedata.story_id = player.base_info.story_id for k, i in enumerate(player.base_info._button_one_time): responsedata.button_one_time.append(int(i)) logger.debug("button_one_time %s" % player.base_info._button_one_time) # 战力排行 if rank_helper.flag_doublu_day(): rank_name = 'PowerRank2' else: rank_name = 'PowerRank1' rank_no = rank_helper.get_rank_by_key(rank_name, player.base_info.id) responsedata.fight_power_rank = rank_no responsedata.is_open_next_day_activity = player.base_info.is_open_next_day_activity responsedata.first_recharge_activity = player.base_info.first_recharge_activity responsedata.one_dollar_flowid = str(player.base_info.one_dollar_flowid) responsedata.q360_recharge_url = SDK360_RECHARGE_URL logger.debug("character info:----------------------id: %s" % player.base_info.id) logger.debug("stage_id: %s" % player.fight_cache_component.stage_id) logger.debug("vip_level:%d", player.base_info.vip_level) logger.debug("recharge:%d", player.base_info.recharge) logger.debug("register_time:%d", player.base_info.register_time) logger.debug("buy_stamina_times:%d", player.stamina.buy_stamina_times) logger.debug("first_recharge_activity:%d", player.base_info.first_recharge_activity) logger.debug("newbee_guide_id:%d", player.base_info.current_newbee_guide) # logger.debug("coin:%d", player.finance.coin) # logger.debug("gold:%d", player.finance.gold) # logger.debug("hero_soul:%d", player.finance.hero_soul) # logger.debug("soul_shop_refresh_times:%d", player.soul_shop.refresh_times) # mock guild # player.guild.g_id = 1989 # 更新7日奖励的状态 # player.start_target.update_29() if const.DEBUG: for slot_no, slot in player.line_up_component.line_up_slots.items(): hero = slot.hero_slot.hero_obj if not hero: continue combat_power_hero_lineup(player, hero, slot_no) # awake_hero = player.fight_cache_component.change_hero(hero, hero.hero_info["awakeHeroID"]) # combat_power_hero_lineup(player, awake_hero, slot_no, "awake") logger.debug('login:<%s>%s:%s %s:%s', player, character_id, responsedata.level, dynamic_id, player.dynamic_id) return { 'player_data': responsedata.SerializeToString(), 'is_new_character': is_new_character }
# dbpool.initPool(host=hostname, user=user, # passwd=password, port=port, # db=dbname, charset=charset) from app.game.core.character.PlayerCharacter import PlayerCharacter from app.game.action.node.line_up import line_up_info rank_length = 300 nickname_set = set() while len(nickname_set) < rank_length + 5: pre1 = random.choice(game_configs.rand_name_config.get('pre1')) pre2 = random.choice(game_configs.rand_name_config.get('pre2')) str = random.choice(game_configs.rand_name_config.get('str')) nickname_set.add(pre1 + pre2 + str) player = PlayerCharacter(1, dynamic_id=1) player.create_character_data() for k, val in game_configs.hero_config.items(): if val.type == 0: hero1 = player.hero_component.add_hero(k) hero1.hero_no = k hero1.level = 1 hero1.break_level = 1 hero1.exp = 0 pvp_ranks = {} for rank in range(1, rank_length + 1): for k, v in game_configs.robot_born_config.items(): rank_period = v.get('period') if rank in range(rank_period[0] - 1, rank_period[1] + 1): level_period = v.get('level')
def Maintaskreward(dynamicId, characterId, taskId): '''玩家主要任务奖励发放 @param userId: int 用户id @param characterId: 角色的id ''' player = PlayerCharacter(characterId, dynamicId=dynamicId) #player = PlayersManager().getPlayerByID(characterId) taskinfo = dbTask.getPersonalTaskInfo(characterId, taskId) print taskinfo rewardlist = {} if taskinfo[0]['ifachieved'] == 1: if taskId == 101: #升级 rewardlist.update({"Gold": 5 * player.formatInfo()['level']}) print(taskinfo[0]['ifrewarded'] + 1) RewardCleanOut(dynamicId, characterId, rewardlist) i = taskinfo[0]['ifrewarded'] + 1 resutl = dbTask.setPersonalTaskrInfo(characterId, 101, int(i)) resutl1 = dbTask.setPersonalTaskaInfo(characterId, 101, 0) return {'message': resutl} if taskId == 102: #过副本 rewardlist.update({"Coin": 10000}) RewardCleanOut(dynamicId, characterId, rewardlist) pass if taskId == 103: #签到 pass if taskId == 104: #商城 pass if taskId == 105: #好友 rewardlist.update({"Coin": 10000}) pass if taskId == 106: #喇叭 rewardlist.update({"Coin": 10000}) pass if taskId == 107: #天梯 pass if taskId == 108: #强化 pass if taskId == 109: #宠物 pass if taskId == 110: #装扮宠物房间 pass if taskId == 111: #在告白墙发一次告白 pass if taskId == 112: #结婚 pass if taskId == 113: #装扮情侣空间 rewardlist.update({"Gold": 10}) pass if taskId == 114: #种下爱情树 rewardlist.update({"Gold": 50}) pass if taskId == 115: #第一次情侣蜜语 rewardlist.update({"Coin": 50000}) pass if taskId == 116: #建立一个王国 rewardlist.update({"Gold": 100}) pass
def getReward3711(dynamicId, characterId): '''签到奖励 ''' player = PlayerCharacter(characterId, dynamicId=dynamicId) #player.updatePlayerDBInfo dat = dbCharacter.getreward(characterId) data = dat[0] i1 = int(data / 1000) i2 = int((data - i1 * 1000) / 100) i3 = int((data - i2 * 100 - i1 * 1000) / 10) i4 = int(data - i2 * 100 - i1 * 1000 - i3 * 10) signtimes = dbCharacter.getlastsignByCharacterId(characterId)['signtimes'] result11 = False result2 = False result3 = False result4 = False if i1 == 1 and signtimes > 2: addcoin = player.finance.addCoin(50000) addgold = player.finance.addGold(10) player.updatePlayerDBInfo() print(addcoin, addgold) newstone = dbItems.getItem(characterId, 60001)[0]['stack'] nums = newstone + 5 result11 = dbItems.setStack(nums, characterId, 60001) i1 += 1 if i2 == 1 and signtimes > 6: i2 += 1 player.finance.addCoin(80000) player.finance.addGold(30) newstone = dbItems.getItem(characterId, 60001)[0]['stack'] newstone += 20 result2 = dbItems.setStack(newstone, characterId, 60001) if i3 == 1 and signtimes > 14: i3 += 1 player.finance.addCoin(200000) player.finance.addGold(60) newstone = dbItems.getItem(characterId, 60001)[0]['stack'] newstone += 80 result3 = dbItems.setStack(newstone, characterId, 60001) if i4 == 1 and signtimes > 24: i4 += 1 player.finance.addCoin(300000) player.finance.addGold(100) newstone = dbItems.getItem(characterId, 60001)[0]['stack'] newstone += 150 result4 = dbItems.setStack(newstone, characterId, 60001) newdata = i1 * 1000 + i2 * 100 + i3 * 10 + i4 genxin = dbCharacter.updatePlayerDB(player) result1 = dbCharacter.setget(characterId, newdata) print { "message": { '3': result11, '7': result2, '15': result3, '25': result4 } } return { "message": { '3': result11, '7': result2, '15': result3, '25': result4 } }
Ranking.init('StarRank1', 99999) Ranking.init('StarRank2', 99999) Ranking.init('LimitHeroRank', 99999) if game_configs.base_config.get('initial') and GlobalObject().json_config.get( "name") == u"game": character_obj = tb_character_info.getObj(999) if not character_obj.exists(): character_obj = tb_character_info.getObj(9199) #print("999======", character_obj.exists()) print(GlobalObject().json_config.get("name"), "GlobalObject================") robotname_id, robot_level, rhero_id, rhero_level = game_configs.base_config.get( 'initial') player = PlayerCharacter(999, dynamic_id=-1) player.base_info._level = robot_level hero = player.hero_component.add_hero(rhero_id) hero.hero_no = rhero_id hero.level = rhero_level hero.break_level = 0 hero.exp = 0 player.line_up_component.update_guild_attr() player.line_up_component.change_hero(1, rhero_id, 0) PlayersManager().add_player(player) player.create_character_data() character_obj = tb_character_info.getObj(999) character_obj.hset(