def pvpCDTimeDelete(request, response): ''' pvp 清除冷却时间 ''' # 在冷却的时间内不能进行战斗也不能进行刷新对手。如果想要做上述操作,需要先清除冷却的cd player = request.player #玩家没有到达PVP建筑开启等级 if not player.isOpenArena: AlertHandler( player, response, AlertID.ALERT_LEVEL_SHORTAGE, u"pvpCDTimeDelete:playerLevel(%s) startLevel(%s)" % (player.level, Static.PVP_LEVEL)) return response if player.yuanbo < Static.PVP_DELETE_CD_TIME_COST: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"pvpCDTimeDelete cost(%s) now player have (%s)" % (Static.PVP_DELETE_CD_TIME_COST, player.yuanbo)) return response player.PVP.cd_time = datetime.datetime.now() player.PVP.update() player.sub_yuanbo(Static.PVP_DELETE_CD_TIME_COST, info=u"清除PVP冷却时间") response.common_response.player.set("arena", player.PVP.to_dict()) return response
def eliteInstanceStart(request, response): ''' 精英结算 ''' player = request.player eliteInstancelevel_id = getattr(request.logic_request, "instanceId", 0) heroLayoutData = getattr(request.logic_request, "heroLayoutData", []) deadCount = 0 isWin = getattr(request.logic_request, "isWin", False) summary = getattr(request.logic_request, "summary", {}) elite_instancelevel = get_eliteinstancelevel(eliteInstancelevel_id) playereliteinstancelevel = player.eliteinstancelevels.get(eliteInstancelevel_id) #副本没有开启 if not playereliteinstancelevel: AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"eliteInstanceStart:instance(%s) is not open" % eliteInstancelevel_id) return response if playereliteinstancelevel.succeedCount >= elite_instancelevel.eliteMaxPlayCount: AlertHandler(player, response, AlertID.ALERT_INSTANCE_FIGHT_COUNT_EXCEED_MAX, u"eliteInstanceStart:instance(%s) fight number(%s) exceed maxCount(%s)" % (eliteInstancelevel_id, playereliteinstancelevel.succeedCount, elite_instancelevel.eliteMaxPlayCount)) return response #[玩家卡id, 卡id, 站位行, 列] player.update_hero_layout(heroLayoutData) if summary: leftWarriorDead = summary["leftWarriorDead"] #英雄小兵全部存在 for i in range(0, len(leftWarriorDead), 2): if int(str(leftWarriorDead[i])[0:2]) == 11: deadCount += leftWarriorDead[i+1] # 默認三星,死一個兩星,其餘一星 star = get_star(deadCount) data = playereliteinstancelevel.fight(star, isWin) if isWin: player.sub_power(elite_instancelevel.elitePowerCost) rewards = data["rewards"] heroLevelUp = data["heroLevelUp"] if isWin: # 策划修改,完成精英副本的时候,计算每日任务,既算完成一次普通副本,也算完成一次精英副本 player.dailytask_going(Static.DAILYTASK_CATEGORY_ELIT_INSTANCE, number=1, is_incr=True, is_series=True) # 完成一个副本以后,进行任务值的添加 player.task_going(Static.TASK_CATEGORY_ELIT_INSTANCE, number=1, c1=eliteInstancelevel_id, is_incr=False, is_series=False) player.dailytask_going(Static.DAILYTASK_CATEGORY_INSTANCE, number=1, is_incr=True, is_series=True) player.update_eliteinstancelevel(playereliteinstancelevel, True) response.logic_response.set("rewards", rewards) response.logic_response.set("heroLevelUp",heroLevelUp) response.logic_response.set("summary",summary) response.common_response.player.set("soldiers", player.armies.to_dict()) response.common_response.player.set("populationCost", player.populationCost) response.logic_response.set("star", star) return response
def vipRewardsGet(request, response): player = request.player vip_level = getattr(request.logic_request, "vipLevel", 0) vip_level = int(vip_level) if not player.can_buy_vip_bag(vip_level) and vip_level > 0: AlertHandler( player, response, AlertID.ALERT_VIP_CAN_NOT_BUY, u"vipRewardsGet:vipLevel(%s) playerVipLevel(%s) can_buy_vip_bag" % (vip_level, player.vip_level)) return response vip = get_vip(vip_level) if player.yuanbo < vip.giftBagDiamond: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"vipRewardsGet:vipLevel(%s) playerVipLevel(%s) price(%s) playerYuanbo(%s)" % (vip_level, player.vip_level, vip.giftBagDiamond, player.yuanbo)) return response player.buy_vip_bag(vip_level) rewards = vip.giftRewards info = u"VIP礼包:%s" % vip_level for reward in rewards: reward_send(player, reward, info) player.sub_yuanbo(vip.giftBagDiamond, info) response.common_response.player.set("vip", player.vip) return response
def guildSiegeBattleEnter(request, response): """ 获取公会团战的报名 """ player = request.player #身份检查 只有会长和副会长才能报名 if not player.guild.isChairman or not player.guild.isViChairman: # TODO:更换 AlertID AlertHandler( player, response, AlertID.ALERT_GUILD_LIMIT_NOT_ENOUGH, u"guildSiegeBattleEnter:only chairman or vice-chairman can sign up" ) return response guildSiege = get_sysguildsiege() #检查公会战当前状态 if not guildSiege.stage_sign_up: # TODO:更换 AlertID AlertHandler( player, response, AlertID.ALERT_GUILD_LIMIT_NOT_ENOUGH, u"guildSiegeBattleEnter:current stage can not be registered") return response #报名 guildSiege.join(player.guildId) return response
def instanceBoxOpen(request, response): ''' 打开章节宝箱 ''' rewards = [] player = request.player instance_id = getattr(request.logic_request, "instanceId", 0) chestLevel = getattr(request.logic_request, "level", 0) category = getattr(request.logic_request, "category", 0) if category == 2: isElite = True star_data = Static.ELITE_STAR_CHEST_OPEN_COUNTS else: isElite = False star_data = Static.STAR_CHEST_OPEN_COUNTS playerinstance_star = get_all_player_star_by_instance_id(player, instance_id, isElite) if playerinstance_star < star_data[chestLevel]: AlertHandler(player, response, AlertID.ALERT_INSTANCE_CHEST_CAN_NOT_OPEN, u"instanceBoxOpen:instatnce(%s) playerinstance_star(%s) chestlevel(%s)" % (instance_id, playerinstance_star, star_data[chestLevel])) return response if not player.chestWithDrawn(instance_id, chestLevel, isElite): AlertHandler(player, response, AlertID.ALERT_INSTANCE_CHEST_ALREADY_OPEN, u"instanceBoxOpen:instatnce(%s) chest is opened" % (instance_id)) return response rewards = get_chest_rewards(player, instance_id, chestLevel, isElite) for reward in rewards: rewardTemp = CommonReward(reward["type"], reward["count"], 0) reward_send(player, rewardTemp, info=u"打开章节宝箱:%s" % instance_id) response.common_response.player.set("starBox", {"history" : player.starChest}) response.common_response.player.set("eliteStarBox", {"history" : player.eliteStarChest}) response.logic_response.set("rewards", rewards) return response
def dailyTaskActivityReward(request, response): """ 领取活跃度奖励 """ player = request.player activityId = getattr(request.logic_request, "activityId", 0) activity = get_dailytask_activity(activityId) if activityId in player.activityBoxIds: AlertHandler( player, response, AlertID.ALERT_DAILYTASK_REWARD_RECEIVED, u"dailyTaskActivityReward:activityId(%s) had received" % (activityId)) return response if player.dailyTaskActivity < activity.activityValue: AlertHandler( player, response, AlertID.ALERT_DAILYTASK_ACTIVITY_NOT_ENOUGH, u"dailyTaskActivityReward:activity(%s) need (%s) player have (%s)" % (activityId, activity.activityValue, player.dailyTaskActivity)) return response # 完成日常任务会获取活跃度 player.activityBoxIds.append(activityId) player.set_update("activityBoxIds") for reward in activity.rewards: reward_send(player, reward, info=u"活跃度奖励") return response
def guildFireStopBuff(request, response): """ 停止火堆燃烧 """ player = request.player fireIndex = getattr(request.logic_request, "index", 0) category = getattr(request.logic_request, "category", -1) if player.guild.isMember: AlertHandler(player, response, AlertID.ALERT_GUILD_LIMIT_NOT_ENOUGH, u"guildFireStopBuff:only chairman can create fire") return response guildInfo = player.guild.guildInfo fire = getattr(guildInfo, "fire%s" % fireIndex) guildFire = guildInfo.get_fire_by_index(fireIndex) if not guildFire: guildInfo.self_release_lock() return response if not fire["buffLevel"]: AlertHandler(player, response, AlertID.ALERT_GUILD_FIRE_NOT_SET, u"guildFireStopBuff:guild fire buff not set") return response if category == 0: guildInfo.stop_fire_buring(fireIndex) if category == 1: guildInfo.start_fire_buring(fireIndex) response.common_response.player.set("guild", player.guild.to_dict()) return response
def siegeBattleDelCDTime(request, response): """ 攻城战删除冷却时间 """ player = request.player # 检查等级 if not player.isOpenSiege: AlertHandler( player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH, u"siegeBattleDelCDTime:need level(%s) player level is %s" % (Static.SIEGE_LEVEL, player.level)) return response if player.yuanbo < Static.SIEGE_DELETE_CD_TIME_COST: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"siegeBattleDelCDTime cost(%s) now player have (%s)" % (Static.SIEGE_DELETE_CD_TIME_COST, player.yuanbo)) return response player.SiegeBattle.reset_cdTime() player.SiegeBattle.update() player.sub_yuanbo(Static.SIEGE_DELETE_CD_TIME_COST, info=u"攻城战清除CD") response.common_response.player.set("siegeBattle", player.SiegeBattle.to_dict()) return response
def pvpResetCount(request, response): ''' pvp ''' player = request.player #玩家没有到达PVP建筑开启等级 if not player.isOpenArena: AlertHandler( player, response, AlertID.ALERT_LEVEL_SHORTAGE, u"pvpOpps:playerLevel(%s) startLevel(%s)" % (player.level, Static.PVP_LEVEL)) return response vip = get_vip(player.vip_level) if player.PVP.resetCount >= vip.resetPVPCount: AlertHandler( player, response, AlertID.ALERT_RESET_PVP_COUNT_NOT_ENOUGH, u"pvpResetCount:player pvpResetCount(%s) >= now VIP can have (%s)" % (player.PVP.resetCount, vip.resetPVPCount)) needDiamond = player.PVP.resetCost if player.yuanbo < needDiamond: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"pvpResetCount:player has (%s) reset PVP need (%s)" % (player.yuanbo, needDiamond)) return response player.PVP.resetPVPCount() player.sub_yuanbo(needDiamond, info=u"竞技场重置") response.common_response.player.set("arena", player.PVP.to_dict()) return response
def siegeBattleFortReset(request, response): """ 攻城战堡垒信息重置 """ player = request.player fortIndexes = getattr(request.logic_request, "indexes", 0) # 检查等级 if not player.isOpenSiege: AlertHandler( player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH, u"siegeBattleFortReset:need level(%s) player level is %s" % (Static.SIEGE_LEVEL, player.level)) return response diamondCost = player.SiegeBattle.reset_fort_cost for fortIndex in fortIndexes: if player.SiegeBattle.can_reset_fort(fortIndex - 1): print "OK" if player.yuanbo < diamondCost: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"siegeBattleFortReset cost(%s) now player have (%s)" % (diamondCost, player.yuanbo)) return response player.sub_yuanbo(diamondCost, info=u"攻城战堡垒信息重置") player.SiegeBattle.reset_fort(fortIndex - 1) continue response.common_response.player.set("siegeBattle", player.SiegeBattle.to_dict()) return response
def createGuild(request, response): """ 创建社团 """ player = request.player # 如果玩家在社团内部那么他不可以再创建社团 if player.guildId: AlertHandler(player, response, AlertID.ALERT_IS_IN_GUILD, u"already in guild") return response # 钻石不足不可以创建社团 if player.yuanbo < Static.CREATE_GUILD: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"createGuild:need diamond(%s) player has %s" % (Static.CREATE_GUILD, player.yuanbo)) return response # 等级不足不可以创建社团 if player.level < Static.CREATE_GUILD_LEVEL: AlertHandler( player, response, AlertID.ALERT_LEVEL_SHORTAGE, u"createGuild:need level(%s) player level is %s" % (Static.CREATE_GUILD_LEVEL, player.level)) if player.guild.canJoinGuildAt > time.time(): return response # 社团名字 guildName = getattr(request.logic_request, "name", "") # 图标 iconId = getattr(request.logic_request, "icon", 0) # 限制的等级 limitLevel = getattr(request.logic_request, "limitLevel", 0) # 加入的类型,随意加,需审核,不允许 category = getattr(request.logic_request, "category", 0) # 判断是否名字重复 if get_guild_by_name(guildName): AlertHandler(player, response, AlertID.ALERT_GUILD_ALREADY_EXITS, u"name already exits") return response # 创建社团 player.guild.create_guild(guildName, iconId, limitLevel, category) player.sub_yuanbo(Static.CREATE_GUILD, info=u"创建公会") # 创建一级公会的副本 allGuildInstanceLevels = get_all_guildinstancelevels() for guildInstanceLevel in allGuildInstanceLevels: if guildInstanceLevel.guildLevelLimit == 1: sysGuildInstance = create_sysguildinstance(player, guildInstanceLevel.pk) #player.joinGuild(guild.id, Static.GUILD_CHAIRMAN_POSITION) # 返回公会的信息 # info = make_guildInfo(guild) # 更新信息,告诉前端 response.common_response.player.set("guild", player.guild.to_dict(True)) return response
def instanceSetUp(request, response): ''' 请求敌军信息 ''' player = request.player level_id = getattr(request.logic_request, "instanceId", 0) version = getattr(request.logic_request, "version", 0) data = {} instancelevel = get_instancelevel(level_id) playerinstancelevel = player.instancelevels.get(level_id) #副本 if not playerinstancelevel: AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"instanceSetUp:instance(%s) is not open" % level_id) return response if instancelevel.minUserLevel > player.level: AlertHandler(player, response, AlertID.ALERT_LEVEL_SHORTAGE, u"instanceSetUp:instance(%s) level is %s and playerLevel is %s" % (level_id, instancelevel.minUserLevel, player.level)) return response if playerinstancelevel.succeedCount >= instancelevel.maxPlayCount: AlertHandler(player, response, AlertID.ALERT_INSTANCE_FIGHT_COUNT_EXCEED_MAX, u"instanceSetUp:instance(%s) fight count(%s) exceed max count(%s)" % (level_id, playerinstancelevel.succeedCount, instancelevel.maxPlayCount)) return response #体力不足 if player.power < instancelevel.powerCost: AlertHandler(player, response, AlertID.ALERT_POWER_NOT_ENOUGH, u"instanceSetUp:power error (%s)" % player.power) return response enemies = instancelevel.enemies if not enemies: raise ErrorException(player, u"instanceSetUp: enemyData(%s) is not existed" % level_id) # 这个打完boss的剧情以后进行的赋值 状态为400,并且完成,200进400出 if player.tutorial_id == Static.TUTORIAL_ID_INIT_1: player.tutorial_begin() # 这里的firstIn是选名字的新手引导。如果一进游戏提示你选名字是因为这个没有置成0 player.set("firstIn", 0) if player.tutorial_id == Static.TUTORIAL_ID_INSTANCE_1ST_3: player.tutorial_complete() # 一请求副本就把新手引导的状态关闭掉。防止断线以后游戏会卡主 elif player.tutorial_id == Static.TUTORIAL_ID_HEROCOMPOSE2_11: player.tutorial_complete() # 这里做的奖励提前展示,结算后会把展示的奖励发放出去 rewards = playerinstancelevel.make_rewards_before_fight() player.update_instancelevel(playerinstancelevel, True) response.logic_response.set("rewards", rewards) response.logic_response.set("enemies", [enemy.to_dict() for enemy in enemies]) response.logic_response.set("version", version) return response
def elementTowerBoxOpen(request, response): """ 元素之塔宝箱开启状态 """ player = request.player status = getattr(request.logic_request, "status", 0) #0 放弃 1 开启 category = getattr(request.logic_request, "category", 0) levelId = getattr(request.logic_request, "levelId", 0) #正常逻辑开箱子 if not player.elementTower.isInSweep: if not player.elementTower.boxCanOpen: raise ErrorException(player, u"elementTowerBoxOpen levelStatus(%s) is error" % player.elementTower.levelStatus) cost = player.elementTower.tower.levels[player.elementTower.levelId - 1].diamondCosts[player.elementTower.diamondBoxIndex] if status and player.yuanbo < cost: AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"elementTowerBoxOpen:playerDiamond(%s) costDiamond(%s)" % (player.yuanbo, cost)) return response if status and cost: player.sub_yuanbo(cost, info=u"元素之塔%s, level(%s)开启宝箱, %s" % (player.elementTower.towerId, player.elementTower.levelId, player.elementTower.diamondBoxIndex)) rewards = player.elementTower.openDiamondBox(status) #扫荡开箱子 else: if "boxLevelIds" not in player.elementTower.sweepInfo or len(player.elementTower.sweepInfo["boxLevelIds"]) == 0: raise ErrorException(player, u"elementTowerBoxOpen sweep not box can open") # levelId = player.elementTower.sweepInfo["boxLevelIds"][0][0] # boxIndex = player.elementTower.sweepInfo["boxLevelIds"][0][1] cost = 0 if status: cost = player.elementTower.openSweepDiamondBoxCost(category, levelId) if status and player.yuanbo < cost: AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"elementTowerBoxOpen:sweep:playerDiamond(%s) costDiamond(%s)" % (player.yuanbo, cost)) return response if status and cost: player.sub_yuanbo(cost, info=u"元素之塔%s, sweep level(%s)开启宝箱, %s" % (player.elementTower.towerId, levelId, status)) rewards = player.elementTower.openSweepDiamondBox(status, category, levelId) for reward in rewards: reward_send(player, reward, info=u"开宝箱奖励:%s:%s" % (player.elementTower.towerId,player.elementTower.levelId)) response.logic_response.set("rewards", [reward.to_dict() for reward in rewards]) response.logic_response.set("category", category) response.common_response.player.set("elementTower", player.elementTower.to_dict()) return response
def startGuildAuc(request, response): """ 开始拍卖 """ # 这个接口的功能,一个玩家出价,拍卖商品,把价格信息更新到max 和 all里面。 # max里面每次比较新的值和老的值如果新的值比较大,更新 # all每次都会把数据插入到这个表里面 from guild.tasks import task_balance_guildauctionmaxinfo price = abs(int(getattr(request.logic_request, "price", 0))) aucRewardId = int(getattr(request.logic_request, "aucRewardId", 0)) player = request.player aucInfo = get_guildmaxinfo(aucRewardId) #itemallinfo = getitemallinfo(player.guildId, itemId, instanceId) # 这件商品拍卖时间到了,被删除掉。 if not aucInfo or not aucInfo.isAuctioning: AlertHandler(player, response, AlertID.ALERT_AUCTION_HAS_CLOSED, u"") else: if price > aucInfo.auctionReward.maxPrice: price = aucInfo.auctionReward.maxPrice if aucInfo.isOffer(player.id): AlertHandler(player, response, AlertID.ALERT_AUCTION_HAS_AUCED, u"") elif price > player.guild.gold: AlertHandler( player, response, AlertID.ALERT_GUILD_GOLD_NOT_ENOUGH, u"startGuildAuc need guild_gold %s now player has %s " % (price, player.guild.gold)) else: info = u"拍卖" player.guild.sub_gold(price, info) aucInfo.auction(player, price) if not aucInfo.isAuctioning: task_balance_guildauctionmaxinfo.delay(aucInfo.id) #异步发奖 aucInfos = [] #TODO没有instanceId 从mongo里面读取 maxinfos = get_guildauctionmaxinfos(player.guildId) for maxinfo in maxinfos: aucInfos.append(maxinfo.to_dict()) response.common_response.player.set("guild", player.guild.to_dict()) response.logic_response.set("aucInfos", aucInfos) return response
def guildReName(request, response): """ 社团名变更 """ player = request.player param = getattr(request.logic_request, "name", "") level = getattr(request.logic_request, "level", 0) category = getattr(request.logic_request, "category", -1) # 1修改名字2修改头像3修改加入权限和等级 ##if not player.guild.isChairman: if player.guild.isMember: return response guildInfo = player.guild.guildInfo if category == 1: if player.yuanbo < Static.RENAME_GUILD: guildInfo.self_release_lock() AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"guildReName:need diamond(%s) player has %s" % (Static.RENAME_GUILD, player.yuanbo)) return response if get_guild_by_name(param): guildInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_ALREADY_EXITS, u"name already exits") return response guildInfo.change_name(param) guildInfo.save() player.sub_yuanbo(Static.RENAME_GUILD, info=u"公会改名") elif category == 2: guildInfo.change_icon(param) guildInfo.save() elif category == 3: if param: guildInfo.change_category(int(param)) if level: guildInfo.change_limitLevel(int(level)) guildInfo.save() else: guildInfo.self_release_lock() response.common_response.player.set("guild", player.guild.to_dict()) return response
def instanceReset(request, response): ''' 刷新副本次数 ''' #type = 1 普通 2 精英 player = request.player level_id = getattr(request.logic_request, "instanceId", 0) category = getattr(request.logic_request, "category", 0) if category == 1: isElite = False instancelevel = get_instancelevel(level_id) elif category == 2: isElite = True instancelevel = get_eliteinstancelevel(level_id) else: raise ErrorException(player, u"instance reset category error (%s)" % level_id) if isElite: playerinstancelevel = player.eliteinstancelevels.get(instancelevel.pk) else: playerinstancelevel = player.instancelevels.get(instancelevel.pk) if not playerinstancelevel: AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"instanceReset:instance(%s) is not open" % level_id) return response vip = get_vip(player.vip_level) if playerinstancelevel.refreshCount >= vip.resetElitInstanceCount: AlertHandler(player, response, AlertID.ALERT_INSTANCE_REFRESH_COUNT_EXCEED_MAX, u"instanceReset:instance(%s) refresh count(%s) exceed max(%s)" % (level_id, playerinstancelevel.refreshCount , vip.resetElitInstanceCount)) return response cost_diamond = Static.REFRESH_INSTANCE_COST * (playerinstancelevel.refreshCount + 1) if player.yuanbo < cost_diamond: AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"instanceReset:instance(%s) refresh costDiamond(%s) playerDiamond(%s)" % (level_id, cost_diamond, player.yuanbo )) return response player.sub_yuanbo(cost_diamond, info=u"重置副本次数") playerinstancelevel.refresh_count() if isElite: player.update_eliteinstancelevel(playerinstancelevel, True) else: player.update_instancelevel(playerinstancelevel, True) return response
def mysteryShopBuy(request, response): """ 神秘商店兑换 """ player = request.player info = u"神秘商店兑换" shop_id = getattr(request.logic_request, "mysteryShopId", 0) #shop_id = int(shop_id) shop_item = get_mysteryshop(shop_id) if not shop_item: raise ErrorException( player, u"mysteryShopBuy:shopitem(%s) no existed" % shop_id) if not player.mysteryshop.can_exchange(shop_id): response.common_response.player.set("mysteryShop", player.mysteryshop.to_dict()) AlertHandler( player, response, AlertID.ALERT_MYSTERYSHOP_CAN_NOT_EXCHANGE, u"mysteryShopBuy:shopitem(%s) can not buyed buyItem(%s) shopItem(%s)" % (shop_id, str( player.mysteryshop.buyItem), str(player.mysteryshop.shopItem))) return response if shop_item.diamond > 0: if player.yuanbo < shop_item.diamond: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"mysteryShopBuy:shopitem(%s) can not buyed diamond(%s) playerYuanbo(%s)" % (shop_id, shop_item.diamond, player.yuanbo)) return response else: if player.gold < shop_item.gold: AlertHandler( player, response, AlertID.ALERT_GOLD_NOT_ENOUGH, u"mysteryShopBuy:shopitem(%s) can not buyed gold(%s) playerCouragePoint(%s)" % (shop_id, shop_item.gold, player.couragepoint)) return response if shop_item.diamond > 0: player.sub_yuanbo(shop_item.diamond, info=info) else: player.sub_gold(shop_item.gold, info=info) player.mysteryshop.exchange(shop_item.pk) reward_send(player, shop_item.reward, info=u"神秘商店购买") response.common_response.player.set("mysteryShop", player.mysteryshop.to_dict()) return response
def siegeBattlePlayerLock(request, response): """ 攻城战对手锁定 or 解锁 """ player = request.player oppId = getattr(request.logic_request, "oppId", 0) isLocked = True # 检查等级 if not player.isOpenSiege: AlertHandler( player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH, u"siegeBattlePlayerLock:need level(%s) player level is %s" % (Static.SIEGE_LEVEL, player.level)) return response for _index, _opp in enumerate(player.SiegeBattle.opps): _player = get_player(_opp["player_id"], False) if _opp["player_id"] == oppId: player.SiegeBattle.opps[_index]["isLocked"] = not _opp["isLocked"] player.SiegeBattle.update() isLocked = player.SiegeBattle.opps[_index]["isLocked"] break response.logic_response.set("isLocked", isLocked) response.common_response.player.set("siegeBattle", player.SiegeBattle.to_dict()) return response
def taskDailyReward(request, response): """ 日常任务领取 """ player = request.player task_id = getattr(request.logic_request, "taskId", 0) task_id = int(task_id) task = get_dailytask(task_id) if player.dailytask_is_done(task.category): player.dailytask_done(task.category) #扫荡券 if task.is_vip_sweep: vip = get_vip(player.vip_level) acquire_item(player, Static.ITEM_SWEEP_ID, number=vip.sweepCount, info=u"VIP领取") else: for reward in task.rewards: reward_send(player, reward, info=u"日常任务领取") else: player.update_dailytask(task.category) AlertHandler(player, response, AlertID.ALERT_DAILYTASK_UNDONE, u"taskDailyReward:taskGid(%s) is not done" % (task_id)) return response
def siegeBattlePlayer(request, response): """ 搜索攻城战对手 """ player = request.player category = getattr(request.logic_request, "category", 0) # 默认0正常匹配 1为确定取消保护再匹配 if not player.isOpenSiege: AlertHandler( player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH, u"siegeBattlePlayer:need level(%s) player level is %s" % (Static.SIEGE_LEVEL, player.level)) return response if player.siege_be_challenging: # 正在被攻击 不能进行匹配 AlertHandler(player, response, AlertID.ALERT_SIEGE_BATTLE_BE_CHALLENGING, u"siegeBattlePlayer:be challenging") return response # 运送车辆上限检查 if not player.SiegeBattle.has_truck: AlertHandler(player, response, AlertID.ALERT_SIEGE_BATTLE_TRUCK_COUNT_IS_TOP, u"siegeBattlePlayer:truck count is top") return response if player.siege_in_safed: # 处于被保护阶段 if category == 1: player.cancel_protect_time() else: response.logic_response.set("hasSafeTime", True) return response # 不释放上一个对手的话30秒自动过期 opp = player.SiegeBattle.searchOpp() if opp.id > 0: resource = opp.SiegeBattle.get_resources() # 能被抢夺的资源 opp.siege_be_searched() # 设置被搜到 else: resource = get_robot_resource(opp.id) response.logic_response.set("resources", resource) response.logic_response.set("opp", opp.siege_view_data()) response.common_response.player.set("siegeBattle", player.SiegeBattle.to_dict()) return response
def guildShopBuy(request, response): """ 公会商店购买 """ player = request.player shopId = getattr(request.logic_request, "shopId", 0) info = u"公会商店购买" # 获取商店的信息。 guildShop = get_guildshop(shopId) if not player.guildshop.can_buy(shopId): return response if player.guild.gold < guildShop.cost: AlertHandler( player, response, AlertID.ALERT_GUILD_GOLD_NOT_ENOUGH, u"guildShopBuy need guild_gold %s now player has %s" % (guildShop.cost, player.guild.gold)) return response player.guildshop.buy(shopId) if guildShop.is_item: acquire_item(player, guildShop.itemId, number=guildShop.count, info=info) elif guildShop.is_equipfragment: acquire_equipfragment(player, guildShop.itemId, guildShop.count, info=info) elif guildShop.is_artifactfragment: acquire_artifactfragment(player, guildShop.itemId, number=guildShop.count, info=info) elif guildShop.is_soul: acquire_soul(player, guildShop.itemId, guildShop.count, info=info) else: raise ErrorException( player, u"mysteryShopBuy:arenashop(%s) is error" % (guildShop.itemId)) player.guild.sub_gold(guildShop.cost, info=info) rewards = [] rewards.append({"type": guildShop.itemId, "count": guildShop.count}) response.common_response.player.set("guild", player.guild.to_dict()) response.common_response.player.set("guildShop", player.guildshop.to_dict()) response.logic_response.set("rewards", rewards) return response
def guildInstanceBook(request, response): """ 公会副本飞鸽传书 & bookType 0 为一键提醒 其他为关闭此副本的提醒 """ player = request.player instanceId = getattr(request.logic_request, "instanceId", 0) bookType = getattr(request.logic_request, "bookType", 0) if bookType == 1: if str(player.id) in player.guild.guildInfo.feiBookDict: if str(instanceId) in player.guild.guildInfo.feiBookDict[str(player.id)]: del player.guild.guildInfo.feiBookDict[str(player.id)][str(instanceId)] player.guild.guildInfo.save() return response #会长 if not player.guild.isChairman: # TODO:更换 AlertID AlertHandler(player, response, AlertID.ALERT_GUILD_LIMIT_NOT_ENOUGH, u"guildInstanceBook:only chairman or vice-chairman can send feiBook") return response # if not instanceId or (bookType and not to_player_id): # 取得公会副本的信息 sysGuildInstanceInfo = get_sysguildinstanceInfo(instanceId, player.guildId) if not sysGuildInstanceInfo or not sysGuildInstanceInfo.canFeiBook: if sysGuildInstanceInfo: sysGuildInstanceInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_HAS_ALREADY_EXPIRED, u"guildInstanceBook this instacelevel has already expired") return response if not sysGuildInstanceInfo or not sysGuildInstanceInfo.isOpen: if sysGuildInstanceInfo: sysGuildInstanceInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_HAS_ALREADY_EXPIRED, u"guildInstanceBook this instacelevel has already expired") return response pid_list = sysGuildInstanceInfo.get_unFighting_member_list() for player_id in pid_list: if str(player_id) not in player.guild.guildInfo.feiBookDict: player.guild.guildInfo.feiBookDict[str(player_id)] = {str(instanceId): int(time.time())} elif instanceId not in player.guild.guildInfo.feiBookDict[str(player_id)].keys(): player.guild.guildInfo.feiBookDict[str(player_id)][str(instanceId)] = int(time.time()) # response.logic_response.set("configinfo", configinfo.to_dict()) return response
def heroCompose(request, response): """ 灵魂碎片合成英雄 """ player = request.player soul_id = getattr(request.logic_request, "soulId", 0) info = u"灵魂碎片合成英雄" soul = get_soul(soul_id) playersoul = player.souls.get(soul_id) if not playersoul or not playersoul.can_sub(soul.recruitCost): if not playersoul: player.delete_soul(soul_id) else: player.update_soul(playersoul) AlertHandler( player, response, AlertID.ALERT_HERO_COMPOSE_SOUL_NUMBER_NOT_ENOUGH, u"heroCompose:soul(%s) recruitCost(%s)" % (soul_id, soul.recruitCost)) return response playerhero = player.heroes.get(soul.recruitHeroId) if playerhero: player.update_hero(playerhero) AlertHandler( player, response, AlertID.ALERT_HERO_ALREADY_EXSIT, u"heroCompose:soul(%s) recruitHeroId(%s) existed" % (soul_id, soul.recruitHeroId)) return response playersoul.sub(soul.recruitCost, info=info) star = int(str(soul.warrior_id)[-2:]) new_id = soul.warrior_id / 100 * 100 acquire_hero(player, new_id, info=info, star=star) if player.tutorial_id == Static.TUTORIAL_ID_HEROCOMPOSE_10: player.tutorial_complete() player.next_tutorial_open() return response
def buildingPlantBuild(request, response): """ 创建植物 """ centerX = getattr(request.logic_request, "centerX", 0) centerY = getattr(request.logic_request, "centerY", 0) building_id = getattr(request.logic_request, "buildingId", -1) # building 表主键 player = request.player buildingplant = get_buildingplant_by_buildingid(building_id) if not buildingplant: raise ErrorException(player, u"buildingBuild:plant(%s) is not existed" % building_id) building = get_building(building_id) #检查单个植物总数 building_count = get_building_count_by_level(building, player.castleLevel) if building_count <= 0: raise ErrorException(player, u"buildingBuild:plant(%s) create allow number is %s" % (building_id, building_count)) return response playerbuilding_count = player.get_plants_count(buildingplant.pk) if playerbuilding_count >= building_count: AlertHandler(player, response, AlertID.ALERT_BUILDING_BUILD_OVER_MAX_NUMBER, u"buildingBuild:building(%s) create allow number is %s , already building number is %s" % (building_id, building_count, playerbuilding_count)) return response #检查植物总数 vip = get_vip(player.vip_level) if len(player.buildingplants.all()) >= vip.plantCount: AlertHandler(player, response, AlertID.ALERT_BUILDING_BUILD_OVER_MAX_NUMBER, u"buildingBuild:building(%s) create allow number is %s , already building number is %s" % (building_id, vip.plantCount, len(player.buildingplants.all()))) return response #创建消耗检查 costs = buildingplant.costs for cost in costs: playeritem = player.items.get(cost.type) if not playeritem: raise ErrorException(player, u"itemUse:playeritem(%s) no existed" % (playeritem.pk)) if not playeritem.can_sub(cost.count): #更新数据 player.update_item(playeritem) AlertHandler(player, response, AlertID.ALERT_ITEM_NOT_ENOUGH, u"itemUse:item(%s) playeritem(%s) useCount(%s) count(%s)" % (playeritem.item_id,cost.type, cost.count, playeritem.count)) return response playeritem.sub(cost.count, u"物品使用") info = u"创建植物" playerbuildingplant = acquire_buildingplant(player, buildingplant, centerX = centerX, centerY = centerY, status = 0, buildingId = building_id) ActionLogWriter.building_create(player, playerbuildingplant.pk, playerbuildingplant.plantId, info) return response
def guildLevelUp(request, response): """ 社团升级 """ player = request.player category = getattr(request.logic_request, "category", 0) # 金币捐献 if not player.guild.isChairman and not player.guild.isViChairman: return response nextGuildLevel = get_guild(player.guild.guildInfo.level + 1) if not nextGuildLevel: return response guildLevel = get_guild(player.guild.guildInfo.level) if player.yuanbo < guildLevel.levelUpCost: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"guildLevelUp need diamond %s you have %s" % (guildLevel.levelUpCost, player.yuanbo)) return response #经验值不足 if player.guild.guildInfo.xp < guildLevel.level: return response player.sub_yuanbo(guildLevel.levelUpCost, info=u"社团升级") player.guild.level_up(guildLevel) #公会升级后 添加相应的公会副本 allGuildInstanceLevels = get_all_guildinstancelevels() # 获取所有公会副本 sysGuildInstances = get_sysguild_instances(player.guildId) # 获取当前公会所有存在副本 instanceIds = [i.instanceId for i in sysGuildInstances] for guildInstanceLevel in allGuildInstanceLevels: if player.guild.guildInfo.level >= guildInstanceLevel.guildLevelLimit and guildInstanceLevel.pk not in instanceIds: sysGuildInstance = create_sysguildinstance(player, guildInstanceLevel.pk) #if player.guild.guildInfo.instanceIsOpen and not player.guild.guildInfo.createdInstance: # allGuildInstanceLevels = get_all_guildinstancelevels() # guildInfo = player.guild.guildInfo # chairmanLastInstanceId = player.lastInstance["lastLevelId"] # lastInstanceLevel = get_instancelevel(chairmanLastInstanceId) # for guildInstanceLevel in allGuildInstanceLevels: #如果是章节最后一关并且通关 or 当前章节没有通关 # if (lastInstanceLevel.levelIndex == 10 and player.lastInstance["lastFinished"] and int(str(chairmanLastInstanceId)[2:4]) >= guildInstanceLevel.id[2:4]) or int(str(chairmanLastInstanceId)[2:4]) > guildInstanceLevel.id[2:4]: #guildInfo.instanceIds.append(guildInstanceLevel.id) # guildInfo.createdInstance = 1 # create_guildinstance(player, guildInstanceLevel.id) # guildInfo.save() response.common_response.player.set("guild", player.guild.to_dict()) return response
def guildInstanceSetUp(request, response): ''' 请求敌军信息 ''' player = request.player level_id = getattr(request.logic_request, "instanceId", 0) guildInstancelevel = get_guildinstanceLevel(level_id) guildInstancelevelInfo = get_sysguildinstanceInfo(level_id,player.guildId) if not guildInstancelevelInfo or not guildInstancelevelInfo.isOpen: if guildInstancelevelInfo: guildInstancelevelInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_HAS_ALREADY_EXPIRED, u"guildInstanceSetUp this instacelevel has already expired") return response # 副本有人正在打 if guildInstancelevelInfo.isFighting > 0: guildInstancelevelInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_IS_FIGHTING, u"guildInstanceSetUp somebody is in this instancelevel") return response # 已经打过这个副本一次了 if player.id in guildInstancelevelInfo.memberList: guildInstancelevelInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_HAS_ALREADY_FIGHTED, u"guildInstanceSetUp this instacelevel has already fighted") return response enemies = guildInstancelevel.enemies if not enemies: guildInstancelevelInfo.self_release_lock() raise ErrorException(player, u"instanceSetUp: enemyData(%s) is not existed" % level_id) guildInstancelevelInfo.fight(player) response.logic_response.set("bossHp", guildInstancelevelInfo.bossHp) response.logic_response.set("bossPercentage", guildInstancelevelInfo.bossPercentage) response.logic_response.set("enemies", [enemy.to_dict() for enemy in enemies]) return response
def guildInstanceOpen(request, response): ''' 开启公会副本 ''' player = request.player # 前端从静态表里面取出来公会副本的id instanceLevelId = getattr(request.logic_request, "instanceId", 0) guildInfo = player.guild.guildInfo # if not player.guild.guildInfo.instanceIsOpen: # AlertHandler(player, response, AlertID.ALERT_GUILD_INSTANCE_LEVEL_LIMIT, u"guildInstanceOpen your guild level %s is limit" % player.guild.guildInfo.level) # guildInfo.self_release_lock() # return response # 在公会达到十级的时候就已经把所有的副本全部加入备选的方案了,只不过状态还是设置为未开启的状态 # 普通成员没有权限开启副本 if player.guild.isMember: guildInfo.self_release_lock() AlertHandler(player, response, AlertID.ALERT_GUILD_LIMIT_CAN_NOT_OPEN_INSTANCE, u"guildInstanceOpen your position is %s open instance need 2 or 1" %(player.guild.position)) return response # 去静态表里面取得公会副本的信息 sysGuildInstance = get_sysguildinstanceInfo(instanceLevelId, player.guildId) guildinstancelevel = get_guildinstanceLevel(instanceLevelId) if player.yuanbo < guildinstancelevel.diamondCost: AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"guildInstanceOpen:instanceLevelId(%s) melt costYuanbo(%s) playerYuanbo(%s)" % (instanceLevelId, guildinstancelevel.diamondCost, player.yuanbo)) return response info = u"开启公会副本:%s:%s" % (player.guildId, instanceLevelId) player.sub_yuanbo(guildinstancelevel.diamondCost, info) if not sysGuildInstance or not sysGuildInstance.isWaiting or player.guild.guildInfo.level < guildinstancelevel.guildLevelLimit: guildInfo.self_release_lock() if sysGuildInstance: sysGuildInstance.self_release_lock() response.logic_response.set("instanceInfo", sysGuildInstance.to_dict()) return response sysGuildInstance.open() guildInfo.self_release_lock() response.logic_response.set("instanceInfo", sysGuildInstance.to_dict()) return response
def sevenDaysHalfBuy(request, response): """ 七天乐半价购买 """ player = request.player sevenId = getattr(request.logic_request, "sevenId", 0) sevenPrice = get_sevenDaysHalfPrice(sevenId) if player.daysFromcreated > 9 or player.daysFromcreated < sevenId: AlertHandler( player, response, AlertID.ALERT_SEVENDAYS_IS_NOT_ALLOWED, u"sevenDaysHalfBuy:playerdays not between 1 and 9 had received" % (player.daysFromcreated)) return response if sevenPrice.id in player.halfBuyIds: AlertHandler( player, response, AlertID.ALERT_SEVENDAYS_ONLY_ONCE, u"sevenDaysHalfBuy:this is item(%s) had buyed" % (sevenPrice.id)) return response if player.yuanbo < sevenPrice.itemCost: AlertHandler( player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"sevenDaysHalfBuy: sevenPrice cost (%s) and player has (%s)" % (sevenPrice.itemCost, player.yuanbo)) return response reward_send(player, sevenPrice.reward, info=u"七天半价购买%s" % sevenPrice.id) player.halfBuyIds.append(sevenPrice.pk) player.set_update("halfBuyIds") player.sub_yuanbo(sevenPrice.itemCost, info=u"七天半价购买%s" % sevenPrice.id) response.common_response.player.set("halfBuyIds", player.halfBuyIds) if player.isOpenArena: response.common_response.player.set("arena", player.PVP.to_dict()) return response
def heroLevelUp(request, response): """ 英雄升级 """ playerhero_id = getattr(request.logic_request, "playerHeroId", 0) item_ids = getattr(request.logic_request, "itemIds", 0) player = request.player info = u"英雄升级:%s" % playerhero_id playerhero = player.heroes.get(playerhero_id) if not playerhero: raise ErrorException( player, u"heroLevelUp:playerhero(%s) is not existed" % (playerhero_id)) items = dict(zip(item_ids[0:len(item_ids):2], item_ids[1:len(item_ids):2])) total_xp = 0 for item_id, count in items.items(): playeritem = player.items.get(item_id) if not playeritem: raise ErrorException( player, u"heroLevelUp:playeritem(%s) no existed" % (item_id)) if not playeritem.can_sub(count): #更新数据 player.update_item(playeritem) AlertHandler( player, response, AlertID.ALERT_ITEM_NOT_ENOUGH, u"heroLevelUp:item(%s) playeritem(%s) useCount(%s) count(%s)" % (playeritem.item_id, item_id, count, playeritem.count)) return response total_xp += playeritem.item.number * count playerhero.add_xp(total_xp, player=player) player.update_hero(playerhero, True) playerheroteam = player.heroteams.get(playerhero.warrior.hero.heroTeamId) playerheroteam.update_score() player.update_heroteam(playerheroteam, True) if player.tutorial_id == Static.TUTORIAL_ID_ADD_XP_12: player.tutorial_complete() for item_id, count in items.items(): playeritem = player.items.get(item_id) playeritem.sub(count, info=info) return response
def buildingPlantHarvest(request, response): ''' 植物采摘 ''' player = request.player playerplant_id = getattr(request.logic_request, "playerPlantId", 0) playerbuildingplant = player.buildingplants.get(playerplant_id) if playerbuildingplant.harvestLeftTimes <= 0: AlertHandler(player, response, AlertID.ALERT_PLANT_HARVEST_OVER_MAX_NUMBER, u"buildingPlantHarvest:plant(%s) is not mature" % playerbuildingplant.plantId) return response if not playerbuildingplant.is_maturation: AlertHandler(player, response, AlertID.ALERT_PLANT_HARVEST_NOT_MATURATION, u"buildingPlantHarvest:plant(%s) is not mature" % playerbuildingplant.plantId) return response info = u"植物采摘奖励" rewards = [] rewards = playerbuildingplant.harvest() for reward in rewards: reward_send(player, reward, info=info) player.update_buildingplant(playerbuildingplant, True) response.logic_response.set("rewards", [reward.to_dict() for reward in rewards]) return response