def __init__(self): utility.DirtyFlag.__init__(self) self.reborn_timer = None self.tuangouCheatTime = Game.res_mgr.res_common.get("tuangouCheatTime") self.tuangouCheatRandTime = Game.res_mgr.res_common.get( "tuangouCheatRandTime") self.tuangouCheatRandNum = Game.res_mgr.res_common.get( "tuangouCheatRandNum") self.tuangouCheatStopTime = Game.res_mgr.res_common.get( "tuangouCheatStopTime") self.cycleData = CycleDay(self) self.JJnum = {} #进阶数量统计 self.zhuanpanmsg = [] #转盘消息 [[resid,name,poolid]] self.redpacket = {} #红包 {key:obj} self.baishiList = {} #拜师列表 玩家id为key self.ChengzhangjijinNum = 0 #成长基金购买人数 self.redpacketindex = 0 #全局红包index self.loop_ChengzhangjijinNum_timer = None self.data = None self.save_cache = {} self._save_loop_task = None Game.sub(MSG_FRAME_STOP, self._frame_stop)
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.maintask = None #主线任务 self.passMainId = 0 #已通关主线任务 self.guild_act_tasks = {} #{任务id:obj} #帮会活跃任务 self.shitu_tasks = {} #{任务id:obj} #师徒任务 self.guild_act_reward_tasks = {} #{任务id:obj} #帮会活跃奖励任务 self.xyll_tasks = {} #{任务id:obj} #西游历练任务 self.rchy_tasks = {} #{任务id:obj} #日常活跃任务 self.zhoumolibaotasks = {} #{任务id:obj} #周末礼包任务 self.Renwudajihuantasks = {} #{任务id:obj} #任务大集换 self.RenwudajihuanIndex = { } #{index:taskid} #任务大集换 index与任务id关系= "1","2","3","4","5", self.Renwudajihuan2tasks = {} #{任务id:obj} #任务大集换 self.Renwudajihuan2Index = { } #{index:taskid} #任务大集换 index与任务id关系= "1","2","3","4","5", self.alreadyOpenTaskId = [] # 已开放的系统功能体验id self.open_tasks = {} #{任务id:obj} #功能开放体验任务 self.alreadyGetRewardOpenTaskId = [] # 已领取完成奖励的系统功能体验id self.alreadyGetOpenRewardOpenTaskId = [] # 已领取开启奖励的系统功能体验id self.activityMonster_tasks = {} #{任务id:obj} 神宠超梦活动前置任务 self.thanksgivingDay_tasks = {} # {任务id:obj} 感恩节任务 self.levelContest_tasks = {} # {任务id:obj} 段位赛任务 self.maze_tasks = {} # {任务id:obj} 迷宫任务 self.gongcheng_tasks = {} #{任务id:obj} 攻城任务 self.zhuanpan_tasks = {} #{任务id:obj} 转盘任务 self.new_kfkh_tasks = {} # {任务id:obj} 新开服狂欢(和全民攻城一样的功能) self.passMainIdDict = {} self.cycleDay = CycleDay(self, keepCyc=2) self.cycleWeek = CycleWeek(self) self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.mapSubId = 1 #当前关卡 self.passSubId = 0 #已通关关卡id self.rewardSubId = [] #领奖的关卡id self.offexp = 0 #离线经验箱子 经验 self.offcoin = 0 #离线经验箱子 金币 self.offexplore = 0 #离线经验箱子 探索值 self.offpetexp = 0 #离线经验箱子 宠物经验 self.offreward = {} #离线经验箱子 道具{id:num} self.offtimes = 0 #离线经验箱子 当前累计次数 self.ChargeEndTime = {} #特权结束时间 {resid:结束时间戳秒} self.offlasttime = time.time() #离线经验箱子 最后一次生成奖励时间错时间戳 self.objIDs = [] #地图物件 ID self.objlasttime = time.time() #地图物 最后一次生成物件时间错时间戳 self.objkey = [] #地图物 已扔关键id self.passEncounterId = 0 #已通关遭遇战id self.firstFailEncounterId = 0 #首次失败遭遇战最大id self.save_cache = {} #存储缓存 # 监听普通场景打怪 self.owner.sub(msg_define.MSG_MORMAL_SCENE_FIGHT, self.event_normal_fight)
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.score = 0 #分数 self.gold = 0 #金币 self.startTime = 0 #点击开始的时间 self.HetiNum = 0 #循环合体次数 self.st = 0 #开始时间 self.obj = [] #物体 self.cycleDay = CycleDay(self) self.level = 0 #难度 self.ver = 0 #难度版本 self.count = 0 #累计开始次数 self.card = [] #未实例化宠物牌堆 self.typeApet = [] #剩余A宠实例 self.typeBpet = [] #剩余B宠实例 self.typeCpet = [] #剩余C宠实例 self.nowgroupidx = 0 #当前循环组idx self.t2v = {} #模板对应宠物实例id self.returnv = [] #被删宠物 元素:[倒计数,宠物id_阶段] self.bigRewardCount = 0 #大宝箱计数 self.smallRewardCount = 0 #大宝箱计数 self.histscore = 0 #历史分数 self.histgold = 0 #历史金币 self.item = {} #本局获得道具 self.lastrank = 0 self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.actList = {} #{图腾pos:obj} self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.activityCycleData = ActivityCycleData(self) self.RollNum = [] # 扭蛋次数 {"k":resid,"v":num} self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.area = 0 # 当前道馆所处地区 self.pavilionData = {} # 道馆数据 {1:obj} self.cycleDay = CycleDay(self) self.save_cache = {} # 监听角色升级 self.owner.sub(msg_define.MSG_ROLE_XLV_UPGRADE, self.event_lv_uprade)
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.freeResetTime = {} #免费重置时间 id:time.time() self.score = {} #得分 resid:score self.rewardid = {} #已经领奖idx resid:[] self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.time = 0 #上次退出时间 self.diaoyutime = 0 #上次钓鱼时间 self.score = 0 #分数 self.yulou = [] #鱼篓 self.hp = {} #血量 self.save_cache = {} #存储缓存 self.status = 0 #钓鱼状态 self.cycleDay = CycleDay(self)
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.grBoss = {} #个人boss {个人bossId:{是否首通:0}} self.qmBoss = {} #{num:1, remind:[], time:0} self.ssjBoss = {} #{配置表id: {是否首通:0}} self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存 self.qmboss_num_timer = None #全民boss挑战次数恢复计时器
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.cycleDay = CycleDay(self) self.owner = owner # 拥有者 self.time = 0 # self.mul = 1 # self.id = 0 # self.quality = 1 # self.becatch = [] # self.history = {} # self.count = 0 # self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner self.clfbSuccessCount = 0 # 材料副本胜利次数 self.clfbFightNum = {} #材料副本胜利次数 {fbid:num} self.clfbId = [] # 材料副本通关id self.lwbz = {} # baotuId:Cangbaotu 神秘宝藏 self.lwbzRewardNum = 0 #领取龙王宝藏星级奖励次数 self.xlysMaxLevelId = 0 # 小雷音寺最大关卡id 古代遗迹 self.ttslMaxLevelId = 0 # 天庭试炼最大通关关卡id 精灵试炼 self.ttslRewardStatus = {} # 关卡id:宝箱状态 self.cycleDay = CycleDay(self) self.save_cache = {}
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.cycleWeek = CycleWeek(self) self.challengeNum = 0 #挑战次数 self.lastRecoverTime = 0 #最后一次恢复时间 self.TotalWin = 0 #历史总战胜次数 self.TotalFightNum = 0 #历史总挑战次数 self.winMax = 0 #历史最大连胜次数 self.revengeNum = 0 #历史复仇次数 self.beChallengeData = [] #复仇列表 self.save_cache = {}
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.vip = 0 #vip等级 self.vipExp = 0 #vip经验 self.vipGetList = [] #已经领取列表 self.monthCard = 0 #月卡过期时间 self.weekCard = 0 #周卡过期时间 self.onlineExpExtra = 0 #在线挂机额外增加百分比 经验 self.onlineGoldExtra = 0 #在线挂机额外增加百分比 金币 self.monthCardReward = [] #月卡领奖列表 self.weekCardReward = [] #周卡领奖列表 self.monthCardBagExt = False #月卡扩容 self.battleJumpNum = 0 # 战斗跳过次数 self.zhizunCardFlag = 0 #至尊卡标识 self.timeFinish = [] #vip前3级免费领取 self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.keyinfo = { } #id:{"num1":??,"num2":??,"num3":??,"num4":??,"num5":??} self.Ding = 1 #丁 resid self.socre = 0 #分数 self.rewards = [] #已经领奖id self.ChargeEndTime = {} #特权结束时间 {resid:结束时间戳秒} self.taskData = [] #{id:任务id,et:任务结束时间戳秒0代表未接,petuid:[]} self.taskInit = 0 #自动生成标记 self.lastSystemID = 0 #最后获取线索resid self.lastIDX = 0 #最后获取线索位置[1~5] self.lastmapSubId = 0 #那时候关卡id self.save_cache = {} #存储缓存
def __init__(self, guildId): utility.DirtyFlag.__init__(self) self.id = guildId #帮会id self.name = "" #帮会名称 self.color = 0 #颜色 self.mainCity = 0 #主城 self.level = 0 #帮会等级 self.exp = 0 # 帮会资金 self.masterId = 0 #帮主id self.masterName = "" #帮主名称 self.notice = "" #帮会公告 self.members = {} #帮会成员 {pid:info} self.autoEnter = 0 # 是否自动入帮(autoEnter, int) self.autoFa = 0 # 自动入帮战力(autoFa, int) self.logs = [] #帮会记录(time, name, type) self.cycleDay = CycleDay(self) # 天周期数据 #帮会boss self.bossHp = 0 self.data = None self.save_cache = {} # 存储缓存
def __init__(self, owner): utility.DirtyFlag.__init__(self) self.cycleDay = CycleDay(self) self.owner = owner # 拥有者 self.guildId = 0 #公会id self.actLv = 0 #帮会活跃等级(actLv, int) self.actExp = 0 # 帮会活跃经验(actExp, int) self.skills = { } # {pos:lv} 帮会技能列表(skill, [json]) 部位(pos, int) 等级(lv, int) self.exList = [ ] #[(exId, status)] 兑换id(exId, int) 状态(status, int) 0=未兑换 1=已兑换 self.refTime = 0 #兑换下次刷新时间戳(refTime, int) #从0点开始每4小时刷新一下 self.firstKill = [] #帮会副本已首通id列表 self.monsterNum = 0 #帮会小怪击杀总次数 self.collectNum = 0 #帮会采集总次数 self.shangxiangNum = 0 #帮会上香总次数 self.barrNum = 0 #历史帮会副本挑战总次数 self.skillUpNum = 0 #帮会技能历史提升次数 self.actRewardNum = 0 #领取公会活跃奖励次数 self.save_cache = {} #存储缓存
class PlayerHeti(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.score = 0 #分数 self.gold = 0 #金币 self.startTime = 0 #点击开始的时间 self.HetiNum = 0 #循环合体次数 self.st = 0 #开始时间 self.obj = [] #物体 self.cycleDay = CycleDay(self) self.level = 0 #难度 self.ver = 0 #难度版本 self.count = 0 #累计开始次数 self.card = [] #未实例化宠物牌堆 self.typeApet = [] #剩余A宠实例 self.typeBpet = [] #剩余B宠实例 self.typeCpet = [] #剩余C宠实例 self.nowgroupidx = 0 #当前循环组idx self.t2v = {} #模板对应宠物实例id self.returnv = [] #被删宠物 元素:[倒计数,宠物id_阶段] self.bigRewardCount = 0 #大宝箱计数 self.smallRewardCount = 0 #大宝箱计数 self.histscore = 0 #历史分数 self.histgold = 0 #历史金币 self.item = {} #本局获得道具 self.lastrank = 0 self.save_cache = {} #存储缓存 # self.owner.sub(msg_define.MSG_ROLE_XLV_UPGRADE, self.event_lv_uprade) def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["score"] = self.score self.save_cache["gold"] = self.gold self.save_cache["histscore"] = self.histscore self.save_cache["histgold"] = self.histgold self.save_cache["HetiNum"] = self.HetiNum self.save_cache["startTime"] = self.startTime self.save_cache["st"] = self.st self.save_cache["obj"] = self.obj self.save_cache["level"] = self.level self.save_cache["ver"] = self.ver self.save_cache["count"] = self.count self.save_cache["card"] = self.card self.save_cache["typeApet"] = self.typeApet self.save_cache["typeBpet"] = self.typeBpet self.save_cache["typeCpet"] = self.typeCpet self.save_cache["nowgroupidx"] = self.nowgroupidx self.save_cache["t2v"] = self.t2v self.save_cache["returnv"] = self.returnv self.save_cache["bigRewardCount"] = self.bigRewardCount self.save_cache["smallRewardCount"] = self.smallRewardCount self.save_cache["item"] = self.item self.save_cache["lastrank"] = self.lastrank return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.score = data.get("score", 0) self.gold = data.get("gold", 0) self.histscore = data.get("histscore", 0) self.histgold = data.get("histgold", 0) self.HetiNum = data.get("HetiNum", 0) self.startTime = data.get("startTime", 0) self.st = data.get("st", 0) self.obj = data.get("obj", []) self.level = data.get("level", 0) self.ver = data.get("ver", 0) self.count = data.get("count", 0) self.card = data.get("card", []) self.typeApet = data.get("typeApet", []) self.typeBpet = data.get("typeBpet", []) self.typeCpet = data.get("typeCpet", []) self.nowgroupidx = data.get("nowgroupidx", 0) self.t2v = data.get("t2v", {}) self.returnv = data.get("returnv", []) self.bigRewardCount = data.get("bigRewardCount", 0) self.smallRewardCount = data.get("smallRewardCount", 0) self.item = data.get("item", {}) self.lastrank = data.get("lastrank", 0) #登录初始化下发数据 def to_init_data(self): init_data = {} init_data["score"] = self.score init_data["gold"] = self.gold init_data["st"] = self.st init_data["obj"] = self.obj nowtime = time.time() heticishu = Game.res_mgr.res_common.get("heticishu") hetiNumCD = Game.res_mgr.res_common.get("hetiNumCD") while self.HetiNum and self.startTime and self.startTime + hetiNumCD.i <= nowtime: self.HetiNum -= 1 self.startTime += hetiNumCD.i if self.HetiNum == 0: self.startTime = 0 init_data["startTime"] = self.startTime init_data["num"] = self.HetiNum self.markDirty() name = "" # rankobj = Game.sub_rank_mgr.getRankobj(constant.RANK_HETI) rankobj = None if rankobj: rankList = rankobj.GetSnapshot() if len(rankList) >= 1: name = rankList[0]["info"]["name"] init_data["name"] = name init_data["hetiBuyNum"] = self.GethetiBuyNum() # init_data["top"] = [] return init_data def buyNum(self): self.HetiNum -= 1 self.AddhetiBuyNum() self.markDirty() def AddHetiNum(self): x = self.HetiNum if x == 0: self.startTime = time.time() self.HetiNum += 1 self.markDirty() def GethetiBuyNum(self): return self.cycleDay.Query("hetiBuyNum", 0) def AddhetiBuyNum(self): self.cycleDay.Set("hetiBuyNum", self.GethetiBuyNum() + 1) def GetHetiTodayScore(self): return self.cycleDay.Query("HetiTodayScore", 0) def SetHetiTodayScore(self, v): self.cycleDay.Set("HetiTodayScore", v) def GetHetiTodayGold(self): return self.cycleDay.Query("HetiTodayGold", 0) def SetHetiTodayGold(self, v): self.cycleDay.Set("HetiTodayGold", v) def uninit(self): pass # self.owner.unsub(msg_define.MSG_ROLE_XLV_UPGRADE, self.event_lv_uprade) def getPetid(self, t): x = getattr(self, "type%spet" % t, None) v = x.pop(0) self.markDirty() return v def findT(self, t): petid = self.t2v.get(t[0] + '_' + t[1], None) if not petid: petid = self.getPetid(t[0]) self.t2v[t[0] + '_' + t[1]] = petid return str(petid) + '-' + t[2] def getReturnv(self): delidx = -1 returnv_l = len(self.returnv) for idx in range(returnv_l): self.returnv[idx][0] -= 1 if self.returnv[idx][0] <= 0: delidx = idx if delidx != -1: v = self.returnv[delidx][1] del self.returnv[delidx] return v return None def findNext(self, v): petid_n = v.split("-") petid = int(petid_n[0]) n = int(petid_n[1]) maxn = 0 if petid in Game.res_mgr.res_typeApet: maxn = 1 elif petid in Game.res_mgr.res_typeBpet: maxn = 2 elif petid in Game.res_mgr.res_typeCpet: maxn = 3 if n >= maxn: return '' return str(petid) + '-' + str(n + 1) def addReward(self, w): self.gold += w.get(constant.CURRENCY_COIN, 0) for k, v in w.items(): self.item[str(k)] = self.item.get(str(k), 0) + v self.markDirty() def start(self): hetiInitCao = Game.res_mgr.res_common.get("hetiInitCao") hetiLevel2Count = Game.res_mgr.res_common.get("hetiLevel2Count") hetiLevel3Count = Game.res_mgr.res_common.get("hetiLevel3Count") if self.count >= hetiLevel3Count.i: self.level = 3 elif self.count >= hetiLevel2Count.i: self.level = 2 else: self.level = 1 vernum = len(Game.res_mgr.res_hetiMakeDict[self.level]) self.ver = random.randint(1, vernum) self.nowgroupidx = len( Game.res_mgr.res_hetiMakeDict[self.level][self.ver]) - 1 #最后一个 self.st = time.time() #开始时间 self.obj = ["*-*"] * hetiInitCao.i self.typeApet = copy.deepcopy(Game.res_mgr.res_typeApet) self.typeBpet = copy.deepcopy(Game.res_mgr.res_typeBpet) self.typeCpet = copy.deepcopy(Game.res_mgr.res_typeCpet) random.shuffle(self.typeApet) random.shuffle(self.typeBpet) random.shuffle(self.typeCpet) self.score = 0 #分数 self.gold = 0 #金币 self.t2v = {} #模板对应宠物实例id self.card = [] #空 self.returnv = [] #被删宠物 self.item = {} self.count += 1 self.AddHetiNum() self.markDirty() # 返回宝箱id,加分 def caoPre(self): hetiPet = Game.res_mgr.res_common.get("hetiPet") hetibigchest = Game.res_mgr.res_common.get("hetibigchest") hetismallchest = Game.res_mgr.res_common.get("hetismallchest") r = [] r.append([0, hetiPet.i]) if self.bigRewardCount < hetibigchest.arrayint1[0]: r.append([1, hetibigchest.arrayint1[1]]) if self.smallRewardCount < hetismallchest.arrayint1[0]: r.append([2, hetismallchest.arrayint1[1]]) boxtype = utility.Choice(r) if boxtype == 0: return 0, 0, boxtype rid = 0 s = 0 if boxtype == 1: self.bigRewardCount += 1 rid, s = hetibigchest.arrayint1[2], hetibigchest.arrayint1[3] elif boxtype == 2: self.smallRewardCount += 1 rid, s = hetismallchest.arrayint1[2], hetismallchest.arrayint1[3] self.score += s self.markDirty() return rid, s, boxtype # 返回 "" def cao(self): self.obj.remove("*-*") v = self.getReturnv() if not v: if len(self.card) == 0: self.nowgroupidx += 1 if self.nowgroupidx >= len( Game.res_mgr.res_hetiMakeDict[self.level][self.ver]): self.nowgroupidx = 0 self.card = copy.deepcopy(Game.res_mgr.res_hetiMakeDict[ self.level][self.ver][self.nowgroupidx]) random.shuffle(self.card) t = self.card.pop(0) v = self.findT(t) self.obj.append(v) # print(self.obj) self.markDirty() return v # 返回 [],加分 def hebing(self, v): self.obj.remove(v) self.obj.remove(v) hetihebingScore = Game.res_mgr.res_common.get("hetihebingScore") petid_n = v.split("-") n = int(petid_n[1]) addscore = hetihebingScore.arrayint1[n - 1] self.score += addscore newv = self.findNext(v) retval = [] if newv: self.obj.append(newv) retval.append(newv) hetiFillCao = Game.res_mgr.res_common.get("hetiFillCao") if self.obj.count("*-*") < hetiFillCao.i: if newv: self.obj.append("*-*") retval.append("*-*") else: self.obj.append("*-*") self.obj.append("*-*") retval.append("*-*") retval.append("*-*") else: if newv: r = random.randint(0, 1) if r: self.obj.append("*-*") retval.append("*-*") else: r = random.randint(1, 2) if r == 1: self.obj.append("*-*") retval.append("*-*") else: self.obj.append("*-*") self.obj.append("*-*") retval.append("*-*") retval.append("*-*") # print(self.obj) return retval, addscore def delv(self, v): self.obj.remove(v) self.obj.append("*-*") hetidel = Game.res_mgr.res_common.get("hetidel") hetiReturn = Game.res_mgr.res_common.get("hetiReturn") step = random.randint(hetiReturn.arrayint1[0], hetiReturn.arrayint1[1]) self.returnv.append([step, v]) hetideli = hetidel.i if self.score < hetideli: hetideli = self.score self.score -= hetideli self.markDirty() return hetideli def donetest(self): # rankobj = Game.sub_rank_mgr.getRankobj(constant.RANK_HETI) rankobj = None if rankobj: rankList = rankobj.GetSnapshot() if len(rankList) >= 1: print(rankList[0]) def done(self): self.st = 0 if self.histscore < self.score: self.histscore = self.score if self.histgold < self.gold: self.histgold = self.gold needupd = 0 if self.GetHetiTodayScore() < self.score: self.SetHetiTodayScore(self.score) needupd = 1 if self.GetHetiTodayGold() < self.gold: self.SetHetiTodayGold(self.gold) needupd = 1 if needupd: self.owner.rank.uploadRank(constant.RANK_HETI) orank = self.lastrank # rankobj = Game.sub_rank_mgr.getRankobj(constant.RANK_HETI) rankobj = None if rankobj: # rankList = rankobj.getRankList() myRank = rankobj.getMyRank(self.owner.id) if myRank: self.lastrank = myRank nrank = self.lastrank if orank == 0: orank = nrank self.markDirty() self.owner.safe_pub(msg_define.MSG_MINI_GAME_UP_TO_STD, self.score) return orank, nrank
class PlayerFuben(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner self.clfbSuccessCount = 0 # 材料副本胜利次数 self.clfbFightNum = {} #材料副本胜利次数 {fbid:num} self.clfbId = [] # 材料副本通关id self.lwbz = {} # baotuId:Cangbaotu 神秘宝藏 self.lwbzRewardNum = 0 #领取龙王宝藏星级奖励次数 self.xlysMaxLevelId = 0 # 小雷音寺最大关卡id 古代遗迹 self.ttslMaxLevelId = 0 # 天庭试炼最大通关关卡id 精灵试炼 self.ttslRewardStatus = {} # 关卡id:宝箱状态 self.cycleDay = CycleDay(self) self.save_cache = {} def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["clfbSuccessCount"] = self.clfbSuccessCount self.save_cache["lwbzRewardNum"] = self.lwbzRewardNum self.save_cache["clfbId"] = self.clfbId self.save_cache["lwbz"] = [] for baozang in self.lwbz.values(): self.save_cache["lwbz"].append( baozang.to_save_dict(forced=forced)) self.save_cache["xlysMaxLevelId"] = self.xlysMaxLevelId self.save_cache["ttslMaxLevelId"] = self.ttslMaxLevelId self.save_cache["ttslRewardStatus"] = [] for k, v in self.ttslRewardStatus.items(): self.save_cache["ttslRewardStatus"].append({ "levelId": k, "status": v }) self.save_cache["clfbFightNum"] = [] for k, v in self.clfbFightNum.items(): self.save_cache["clfbFightNum"].append({"fbid": k, "num": v}) return self.save_cache def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.clfbSuccessCount = data.get("clfbSuccessCount", 0) self.lwbzRewardNum = data.get("lwbzRewardNum", 0) lwbz = data.get("lwbz", []) for one in lwbz: cangbaotu = Cangbaotu(0, data=one, owner=self.owner) self.lwbz[cangbaotu.baotuId] = cangbaotu self.xlysMaxLevelId = data.get("xlysMaxLevelId", 0) self.ttslMaxLevelId = data.get("ttslMaxLevelId", 0) self.clfbId = data.get("clfbId", []) ttslRewardStatus = data.get("ttslRewardStatus", []) for v in ttslRewardStatus: levelId = v.get("levelId", 0) status = v.get("status", 0) if levelId > 0: self.ttslRewardStatus[levelId] = status clfbFightNum = data.get("clfbFightNum", []) for v in clfbFightNum: fbid = v.get("fbid", 0) num = v.get("num", 0) self.clfbFightNum[fbid] = num def to_init_data(self): init_data = {} init_data["clbz"] = [] for k in self.clfbId: init_data["clbz"].append({ "fubenId": k, "challengeNum": self.getClbzChanllengeNum(k) }) init_data["lwbz"] = [] for one in self.lwbz.values(): init_data["lwbz"].append(one.to_init_data()) init_data["xlys"] = {"maxLevelId": self.xlysMaxLevelId} init_data["ttsl"] = {} init_data["ttsl"]["maxLevelId"] = self.ttslMaxLevelId init_data["ttsl"]["todayMaxLevelId"] = self.getTtslTodayMaxLevelId() init_data["ttsl"]["rewardStatus"] = [] for k, v in self.ttslRewardStatus.items(): init_data["ttsl"]["rewardStatus"].append({ "levelId": k, "status": v }) init_data["XlysBuffCanBuy"] = self.getXlysBuffCanBuy() init_data["XlysBuff"] = self.getXlysBuff() return init_data def to_wee_hour_data(self): return self.to_init_data() def clfbGetInfo(self): resp = {} resp["clbz"] = [] for k in self.clfbId: num = self.getClbzChanllengeNum(k) resp["clbz"].append({"fubenId": k, "challengeNum": num}) return resp def getClbzChanllengeNum(self, fubenId): # 今日0点 time_0 = cur_day_hour_time(hour=0) # 今日12点 time_12 = cur_day_hour_time(hour=12) # 今日19点 time_19 = cur_day_hour_time(hour=19) # 当前时间 time_now = int(time.time()) clbzTime = self.cycleDay.Query("clbzChanllengeTime", {}) clbz = self.cycleDay.Query("clbzChanllengeNum", {}) keys = list(clbzTime.keys()) for fid in keys: lasttime = clbzTime.get(fid, 0) if lasttime < time_0: clbz[fid] = 0 elif time_0 <= lasttime <= time_12 and time_12 <= time_now: clbz[fid] = 0 elif time_12 <= lasttime <= time_19 and time_19 <= time_now: clbz[fid] = 0 self.cycleDay.Set("clbzChanllengeNum", clbz) return clbz.get(fubenId, 0) def setClbzChanllengeNum(self, fubenId, num): clbz = self.cycleDay.Query("clbzChanllengeNum", {}) clbz[fubenId] = num self.cycleDay.Set("clbzChanllengeNum", clbz) clbzTime = self.cycleDay.Query("clbzChanllengeTime", {}) clbzTime[fubenId] = int(time.time()) self.cycleDay.Set("clbzChanllengeTime", clbzTime) def getXlysBuffCanBuy(self): l = self.cycleDay.Query("XlysBuffCanBuy", []) if not l: l = list(Game.res_mgr.res_xlysBuff.keys()) # random.shuffle(l) # l=l[:3] l = random.sample(l, 3) self.cycleDay.Set("XlysBuffCanBuy", l) return l def getXlysBuff(self): v = self.cycleDay.Query("XlysBuff", {}) for k in Game.res_mgr.res_xlysBuff.keys(): if k not in v: v[k] = {"per": 0, "count": 0} self.cycleDay.Set("XlysBuff", v) return v def addXlysBuff(self, key): res = Game.res_mgr.res_xlysBuff.get(key, None) buff = self.getXlysBuff() buff[key]["per"] += res.per buff[key]["count"] += 1 self.cycleDay.Set("XlysBuff", buff) def getClbzChanllengeNumTotal(self): return self.cycleDay.Query("clbzChanllengeTotalNum", 0) def setClbzChanllengeNumTotal(self, num): self.cycleDay.Set("clbzChanllengeTotalNum", num) def getCangbaotu(self, baotuId): cangbaotu = self.lwbz.get(baotuId, None) if not cangbaotu: cangbaotu = Cangbaotu(baotuId, None, self.owner) self.lwbz[baotuId] = cangbaotu return cangbaotu def getLwbzUnChallengeLevel(self): unList = [] keys = list(self.lwbz.keys()) keys.sort() for key in keys: cangbaotu = self.lwbz.get(key) isbreak, resp = cangbaotu.getUnChallengeLevel() unList.extend(resp) if isbreak: break return unList def addClbfId(self, fubenId): if fubenId in self.clfbId: return self.clfbId.append(fubenId) def getXlysMaxLevelId(self): return self.xlysMaxLevelId def setXlysMaxLevelId(self, levelId): self.xlysMaxLevelId = levelId self.markDirty() def getTtslMaxLevelId(self): return self.ttslMaxLevelId def setTtslMaxLevelId(self, levelId): self.ttslMaxLevelId = levelId self.markDirty() def getTtslTodayMaxLevelId(self): ttslDailyToday = self.cycleDay.Query("ttslDailyToday", 0) return ttslDailyToday def setTtslTodayMaxLevelId(self, levelId): self.cycleDay.Set("ttslDailyToday", levelId) def getTtslRewardStatus(self, levelId): return self.ttslRewardStatus.get(levelId, 0) def markTtslRewardStatus(self, levelId): self.ttslRewardStatus[levelId] = 1 def getLwbzTotalStar(self): totalStar = 0 for cangbaotu in self.lwbz.values(): totalStar += cangbaotu.getTotalStar() return totalStar def IncClfbSuccessCount(self): self.clfbSuccessCount += 1 self.markDirty() def getClfbSuccessCount(self): return self.clfbSuccessCount def IncLwbzRewardNum(self): self.lwbzRewardNum += 1 self.markDirty() def getLwbzRewardNum(self): return self.lwbzRewardNum def getClfbFightNum(self, fbId): return self.clfbFightNum.get(fbId, 0) def IncClfbFightNum(self, fbId): iNum = self.clfbFightNum.get(fbId, 0) iNum += 1 self.clfbFightNum[fbId] = iNum self.markDirty() def getLwbzMaxKey(self): """获取龙王宝藏最大通关id""" if not self.lwbz: return 0 maxBaotuId = 0 maxBaotuObj = None for BaotuId, BaotuObj in self.lwbz.items(): if BaotuObj.passLevel and BaotuId > maxBaotuId: maxBaotuId = BaotuId maxBaotuObj = BaotuObj if maxBaotuObj: return max(list(maxBaotuObj.passLevel.keys())) else: return 0
class CommonresMgr(utility.DirtyFlag): _rpc_name_ = "rpc_commonres_mgr" DATA_CLS = ModelCommonres def __init__(self): utility.DirtyFlag.__init__(self) self.reborn_timer = None self.tuangouCheatTime = Game.res_mgr.res_common.get("tuangouCheatTime") self.tuangouCheatRandTime = Game.res_mgr.res_common.get( "tuangouCheatRandTime") self.tuangouCheatRandNum = Game.res_mgr.res_common.get( "tuangouCheatRandNum") self.tuangouCheatStopTime = Game.res_mgr.res_common.get( "tuangouCheatStopTime") self.cycleData = CycleDay(self) self.JJnum = {} #进阶数量统计 self.zhuanpanmsg = [] #转盘消息 [[resid,name,poolid]] self.redpacket = {} #红包 {key:obj} self.baishiList = {} #拜师列表 玩家id为key self.ChengzhangjijinNum = 0 #成长基金购买人数 self.redpacketindex = 0 #全局红包index self.loop_ChengzhangjijinNum_timer = None self.data = None self.save_cache = {} self._save_loop_task = None Game.sub(MSG_FRAME_STOP, self._frame_stop) # self.time2Count() # def time2Count(self): # if self.reborn_timer: # currHour = gtime.current_hour() # if currHour not in self.tuangouCheatStopTime.arrayint1: # self.addChargeNumByNum(random.randint(1, self.tuangouCheatRandNum.i)) # self.reborn_timer.kill(block=False) # self.reborn_timer = None # r=random.randint(0, self.tuangouCheatRandTime.i) # self.reborn_timer = spawn_later((self.tuangouCheatTime.i+r)*60, self.time2Count) def markDirty(self): utility.DirtyFlag.markDirty(self) self.data.modify() def start(self): self.data = self.DATA_CLS.load(Game.store, self.DATA_CLS.TABLE_KEY) if not self.data: self.data = self.DATA_CLS() else: self.load_from_dict(self.data.dataDict) self.data.set_owner(self) self._save_loop_task = spawn(self._saveLoop) self.loop_ChengzhangjijinNum_timer = spawn( self.ChengzhangjijinNum_loop) def ChengzhangjijinNum_loop(self): num = random.randint(1, 2) self.ChengzhangjijinNum += num self.markDirty() def _frame_stop(self): if self._save_loop_task: self._save_loop_task.kill(block=False) self._save_loop_task = None if self.reborn_timer: self.reborn_timer.kill(block=False) self.reborn_timer = None if self.loop_ChengzhangjijinNum_timer: self.loop_ChengzhangjijinNum_timer.kill(block=False) self.loop_ChengzhangjijinNum_timer = None self.save(forced=True, no_let=True) def _saveLoop(self): stime = 10 * 60 while True: sleep(stime) try: self.save() except: log.log_except() def save(self, forced=False, no_let=False): self.data.save(Game.store, forced=forced, no_let=no_let) def load_from_dict(self, data): self.ChengzhangjijinNum = data.get("ChengzhangjijinNum", 0) self.redpacketindex = data.get("redpacketindex", 0) self.JJnum = data.get("JJnum", {}) self.zhuanpanmsg = data.get("zhuanpanmsg", []) self.redpacket = data.get("redpacket", {}) baishiList = data.get("baishiList", []) for k in baishiList: if (k["time"] + lobbyTime) > time.time(): #19/4/22 子博提出需求 从7*24改成1 self.baishiList[k["id"]] = k self.cycleData.load_from_dict(data.get("cycleData", "")) def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["ChengzhangjijinNum"] = self.ChengzhangjijinNum self.save_cache["redpacketindex"] = self.redpacketindex self.save_cache["JJnum"] = self.JJnum self.save_cache["zhuanpanmsg"] = self.zhuanpanmsg self.save_cache["redpacket"] = self.redpacket baishiList = [] for kk, vv in self.baishiList.items(): baishiList.append(vv) self.save_cache["baishiList"] = baishiList self.save_cache["cycleData"] = self.cycleData.to_save_bytes() return self.save_cache def addChengzhangjijinNum(self): self.ChengzhangjijinNum += 1 self.markDirty() for addr, logic in Game.rpc_logic_game: if logic: logic.broadcastChengzhangjijinNum(self.ChengzhangjijinNum, _no_result=True) def getChengzhangjijinNum(self): return self.ChengzhangjijinNum def addChargeNum(self): self.addChargeNumByNum(1) def addChargeNumByNum(self, num): v = self.getChargeNum() self.cycleData.Set("crChargeNum", v + num) resAct = Game.res_mgr.res_activity.get(constant.ACTIVITY_TUANGOU) serverInfo = Game.rpc_server_info.GetServerInfo() if resAct.isOpen(serverInfo): for addr, logic in Game.rpc_logic_game: if logic: logic.crChargeNum(v + num, _no_result=True) return v def getChargeNum(self): return self.cycleData.Query("crChargeNum", 0) def getRedpackIsSet(self): return self.cycleData.Query("RedpackIsSet", 0) def setRedpackIsSet(self): return self.cycleData.Set("RedpackIsSet", 1) def addJJnum(self, type, lv): lvs = self.JJnum.get(type, {}) num = lvs.get(lv, 0) num += 1 lvs[lv] = num self.JJnum[type] = lvs self.markDirty() resAct = Game.res_mgr.res_activity.get(constant.ACTIVITY_QMJJ) serverInfo = Game.rpc_server_info.GetServerInfo() openDay = get_days(serverInfo.get("opentime", 0)) + 1 currtype = -1 for kk, vv in Game.res_mgr.res_qmjj.items(): if vv.day == openDay: currtype = vv.type break # print("3333333",currtype,type,lv,resAct,serverInfo,resAct.isOpen(serverInfo),str(currtype)==type) if str(currtype) == type: if resAct.isOpen(serverInfo): for addr, logic in Game.rpc_logic_game: if logic: logic.crJJnum(self.getJJnum(type), _no_result=True) return num def getJJnum(self, type): # if type == "15": # return {"lv": [], "num": []} lvs = self.JJnum.get(type, {}) lv = [] num = [] for kk, vv in lvs.items(): lv.append(int(kk)) num.append(vv) obj = {"lv": lv, "num": num} return obj def shituBaishi(self, id, name, sex, lv, fa, vipLv, portrait, headframe): self.baishiList[id] = { "time": time.time(), "id": id, "name": name, "sex": sex, "lv": lv, "fa": fa, "vipLv": vipLv, "portrait": portrait, "headframe": headframe } self.markDirty() return {} def shituGetBaishi(self): baishiList = [] for kk, vv in self.baishiList.items(): if (vv["time"] + lobbyTime) > time.time(): #19/4/22 子博提出需求 从7*24改成1 baishiList.append(vv) return baishiList def shituBaishiRemove(self, id): self.baishiList.pop(id, {}) self.markDirty() def makerp(self, total, n): x = [random.random() for i in range(n)] e = [int(i / sum(x) * (total - n)) + 1 for i in x] #每人留一分,剩余随机分,用四舍五入可能会超过总数 re = total - sum(e) u = [random.randint(0, n - 1) for i in range(re)] #截断取整剩的零头再随机给各人1分 for i in range(re): e[u[i]] += 1 return e def getRedpacket(self): isset = self.getRedpackIsSet() if not isset: self.setRedpackIsSet() self.markDirty() delk = [] nt = time.time() for k, v in self.redpacket.items(): if not v["uid"]: #清除系统 delk.append(k) elif len(v["uids"]) >= v["able"]: #清除已抢完 delk.append(k) elif v["startTime"] + 3600 * 24 * 3 < nt: #清除3天前的红包 delk.append(k) for k in delk: del self.redpacket[k] resAct = Game.res_mgr.res_activity.get( constant.ACTIVITY_CHINESENEWYEAR_REDPACKET) serverInfo = Game.rpc_server_info.GetServerInfo() if resAct.isOpen(serverInfo): for k, v in Game.res_mgr.res_redpacket.items(): # x=parser.parse(k) # ts=time.mktime(x.timetuple()) ts = custom_today_time(k) for _ in range(v.times): self.redpacketindex += 1 self.redpacket[str(self.redpacketindex)] = { "startTime": ts, "type": v.type, "num": v.num, "able": v.able, "uid": 0, "uids": [], "e": self.makerp(v.num, v.able), } return self.redpacket def pickRedpacket(self, uid, key): v = self.redpacket.get(key, None) if not v: return None, errcode.EC_NOFOUND if len(v["uids"]) >= v["able"]: return None, errcode.EC_REDPACKET_IS_EMPTY if not v["e"]: return None, errcode.EC_REDPACKET_IS_EMPTY if v["startTime"] > time.time(): return None, errcode.EC_REDPACKET_IS_EMPTY for one in v["uids"]: if one["uid"] == uid: return None, errcode.EC_REDPACKET_IS_GET self.markDirty() num = v["e"].pop() v["uids"].append({"uid": uid, "num": num}) return {"num": num, "type": v["type"]}, 0 def sendRedpacket(self, uid, index, type, num, able): self.redpacket[str(uid) + "_" + str(index)] = { "startTime": time.time(), "type": type, "num": num, "able": able, "uid": uid, "uids": [], "e": self.makerp(num, able), } self.markDirty() return self.redpacket def zhuanpanAddMsg(self, resid, name, poolid): self.zhuanpanmsg.append([resid, name, poolid]) self.markDirty() def zhuanpanGetMsg(self, resid): x = [] for v in self.zhuanpanmsg: if v[0] == resid: x.append({"name": v[1], "poolid": v[2]}) return x
class PlayerBoss(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.grBoss = {} #个人boss {个人bossId:{是否首通:0}} self.qmBoss = {} #{num:1, remind:[], time:0} self.ssjBoss = {} #{配置表id: {是否首通:0}} self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存 self.qmboss_num_timer = None #全民boss挑战次数恢复计时器 def SetGrBossTodayTZ(self, id, num): """个人boss 今日已挑战次数""" grBossTodayTZ = self.cycleDay.Query("grTZ", {}) grBossTodayTZ[id] = num self.cycleDay.Set("grTZ", grBossTodayTZ) def GetGrBossTodayTZ(self, id): """个人boss 今日已挑战次数""" grBossTodayTZ = self.cycleDay.Query("grTZ", {}) return grBossTodayTZ.get(id, 0) def SetGrBossTodayKill(self, id): """个人boss 今日是否已击杀""" grBossTodayKill = self.cycleDay.Query("grKill", {}) grBossTodayKill[id] = 1 self.cycleDay.Set("grKill", grBossTodayKill) def GetGrBossTodayKill(self, id): """个人boss 今日是否已击杀""" grBossTodayKill = self.cycleDay.Query("grKill", {}) return grBossTodayKill.get(id, 0) def SetYwBossTodayTZ(self, num): """野外boss 今日已挑战次数""" self.cycleDay.Set("ywTZ", num) def GetYwBossTodayTZ(self): """野外boss 今日已挑战次数""" return self.cycleDay.Query("ywTZ", 0) def SetYwBossLastTZTime(self, iTime): """野外boss 今日最后一次挑战时间""" self.cycleDay.Set("ywLastTZ", iTime) def GetYwBossLastTZTime(self): """野外boss 今日最后一次挑战时间""" return self.cycleDay.Query("ywLastTZ", 0) def SetSsjBossTodayKill(self, id): """生死劫 今日是否已击杀""" ssjBossTodayKill = self.cycleDay.Query("ssjKill", {}) ssjBossTodayKill[id] = 1 self.cycleDay.Set("ssjKill", ssjBossTodayKill) def GetSsjBossTodayKill(self, id): """生死劫 今日是否已击杀""" ssjBossTodayKill = self.cycleDay.Query("ssjKill", {}) return ssjBossTodayKill.get(id, 0) def SetSsjBossTodayHelp(self, num): """生死劫 今日已协助次数""" self.cycleDay.Set("ssjHelp", num) def GetSsjBossTodayHelp(self): """生死劫 今日已协助次数""" return self.cycleDay.Query("ssjHelp", 0) def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() def uninit(self): if self.qmboss_num_timer: self.qmboss_num_timer.kill(block=False) self.qmboss_num_timer = None #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} if self.cycleDay.data: self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() if self.grBoss: self.save_cache["grBoss"] = {} # 个人boss {个人bossId:{是否首通:0}} for k, v in self.grBoss.items(): self.save_cache[str(k)] = v if self.qmBoss: self.save_cache[ "qmBoss"] = self.qmBoss #{num:1, remind:[], time:0} if self.ssjBoss: self.save_cache["ssjBoss"] = {} # {配置表id: {是否首通:0}} for k, v in self.ssjBoss.items(): self.save_cache[str(k)] = v return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) grBoss = data.get("grBoss", {}) # {个人bossId:{是否首通:0}} for k, v in grBoss.items(): self.grBoss[int(k)] = v self.qmBoss = data.get("qmBoss", {}) #{num:1, remind:[], time:0} ssjBoss = data.get("ssjBoss", {}) # {配置表id: {是否首通:0}} for k, v in ssjBoss.items(): self.ssjBoss[int(k)] = v #处理初始化次数 resQmBossTzCnt = Game.res_mgr.res_common.get("qmBossTzCnt") if not self.qmBoss: self.addQmBossTZ(resQmBossTzCnt.i) # 处理全民boss离线增加的挑战次数 now = int(time.time()) resQmBossCD = Game.res_mgr.res_common.get("qmBossCD") qmBossTZ = self.GetQmBossTZ() if qmBossTZ < resQmBossTzCnt.i: iNextTime = self.GetQmBossTime() if not iNextTime: iNextTime = now + resQmBossCD.i self.SetQmBossTime(iNextTime) self.qmboss_num_timer = spawn_later(resQmBossCD.i, self.addQmBossTZ, 1) else: if iNextTime > now: #还没到时间 idelay = iNextTime - now self.qmboss_num_timer = spawn_later( idelay, self.addQmBossTZ, 1) else: #到时间了 self.addQmBossTZ(1) #增加一次 #然后再判断 次数是否满了 qmBossTZ = self.GetQmBossTZ() if qmBossTZ >= resQmBossTzCnt.i: return #次数没满的情况下 判断超过多个周期 iOffLine = now - iNextTime iAdd = int(iOffLine / resQmBossCD.i) if iAdd: self.addQmBossTZ(iAdd) qmBossTZ = self.GetQmBossTZ() #如果还是没满,启动定时器 if qmBossTZ < resQmBossTzCnt.i: idelay = resQmBossCD.i - iOffLine % resQmBossCD.i iNextTime = now + idelay self.SetQmBossTime(iNextTime) self.qmboss_num_timer = spawn_later( idelay, self.addQmBossTZ, 1) #登录初始化下发数据 def to_init_data(self): init_data = {} grBoss = {} bossList = [] for grBossId, data in self.grBoss.items(): one = {} one['id'] = grBossId one['num'] = self.GetGrBossTodayTZ(grBossId) one['first'] = data.get("first", 0) one['kill'] = self.GetGrBossTodayKill(grBossId) bossList.append(one) grBoss['bossList'] = bossList init_data['grBoss'] = grBoss qmBoss = {} qmBoss['num'] = self.qmBoss.get("num", 0) qmBoss['time'] = self.qmBoss.get("time", 0) qmBoss['remind'] = self.qmBoss.get("remind", []) init_data['qmBoss'] = qmBoss ssjBoss = {} allData = [] for ssjBossId, data in self.ssjBoss.items(): one = {} one['id'] = ssjBossId one['firstFinish'] = data.get("first", 0) one['finish'] = self.GetSsjBossTodayKill(ssjBossId) allData.append(one) ssjBoss['allData'] = allData res = Game.res_mgr.res_common.get("ssjBossHelpNum") ssjBoss['num'] = res.i - self.GetSsjBossTodayHelp() init_data['ssjBoss'] = ssjBoss return init_data #零点更新的数据 def to_wee_hour_data(self): return self.to_init_data() def IsGrBossFirst(self, id): """个人boss是否已首通""" data = self.grBoss.get(id, {}) return data.get("first", 0) def to_grboss_data(self, idList): update_data = {} grBoss = {} bossList = [] for id in idList: data = self.grBoss.get(id, {}) if data: one = {} one['id'] = id one['num'] = self.GetGrBossTodayTZ(id) one['first'] = data.get("first", 0) one['kill'] = self.GetGrBossTodayKill(id) bossList.append(one) grBoss['bossList'] = bossList update_data['grBoss'] = grBoss return update_data def SetGrBossFirst(self, id): data = self.grBoss.setdefault(id, {}) data["first"] = 1 self.markDirty() def addQmBossTZ(self, add): num = self.qmBoss.get("num", 0) #{num:1, remind:[], time:0} num += add resQmBossTzCnt = Game.res_mgr.res_common.get("qmBossTzCnt") if num >= resQmBossTzCnt.i: if self.qmboss_num_timer: self.qmboss_num_timer.kill(block=False) self.qmboss_num_timer = None self.SetQmBossTime(0) num = resQmBossTzCnt.i else: now = int(time.time()) if now >= self.GetQmBossTime() and self.qmboss_num_timer: self.qmboss_num_timer.kill(block=False) self.qmboss_num_timer = None resQmBossCD = Game.res_mgr.res_common.get("qmBossCD") self.qmboss_num_timer = spawn_later(resQmBossCD.i, self.addQmBossTZ, 1) self.SetQmBossTime(now + resQmBossCD.i) self.qmBoss["num"] = num self.markDirty() def delQmBossTZ(self, dele): num = self.qmBoss.get("num", 0) # {num:1, remind:[], time:0} num -= dele resQmBossCD = Game.res_mgr.res_common.get("qmBossCD") if not self.qmboss_num_timer: self.qmboss_num_timer = spawn_later(resQmBossCD.i, self.addQmBossTZ, 1) now = int(time.time()) self.SetQmBossTime(now + resQmBossCD.i) self.qmBoss["num"] = num self.markDirty() def GetQmBossTZ(self): return self.qmBoss.get("num", 0) def GetQmBossRemind(self): return self.qmBoss.get("remind", []) def SetQmBossRemind(self, remind): self.qmBoss["remind"] = remind self.markDirty() def GetQmBossTime(self): return self.qmBoss.get("time", 0) def SetQmBossTime(self, iTime): self.qmBoss["time"] = iTime self.markDirty() def getSsjBossFirstNum(self): iTotal = 0 for _id, data in self.ssjBoss.items(): if data.get("first", 0): iTotal += 1 return iTotal def GetSsjBossFirst(self, id): """生死劫boss是否已首通""" data = self.ssjBoss.get(id, {}) return data.get("first", 0) def SetSsjBossFirst(self, id): """生死劫boss是否已首通""" data = self.ssjBoss.setdefault(id, {}) data["first"] = 1 self.markDirty() def to_ssjboss_data(self, idList): update_data = {} ssjBoss = {} allData = [] for id in idList: data = self.ssjBoss.get(id, {}) if data: one = {} one['id'] = id one['firstFinish'] = self.GetSsjBossFirst(id) one['finish'] = self.GetSsjBossTodayKill(id) allData.append(one) ssjBoss['allData'] = allData res = Game.res_mgr.res_common.get("ssjBossHelpNum") ssjBoss['num'] = res.i - self.GetSsjBossTodayHelp() update_data['ssjBoss'] = ssjBoss return update_data
class PlayerVip(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.vip = 0 #vip等级 self.vipExp = 0 #vip经验 self.vipGetList = [] #已经领取列表 self.monthCard = 0 #月卡过期时间 self.weekCard = 0 #周卡过期时间 self.onlineExpExtra = 0 #在线挂机额外增加百分比 经验 self.onlineGoldExtra = 0 #在线挂机额外增加百分比 金币 self.monthCardReward = [] #月卡领奖列表 self.weekCardReward = [] #周卡领奖列表 self.monthCardBagExt = False #月卡扩容 self.battleJumpNum = 0 # 战斗跳过次数 self.zhizunCardFlag = 0 #至尊卡标识 self.timeFinish = [] #vip前3级免费领取 self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存 def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #今日已领取跳过次数的等级 def GetTodayBattleJumpNumLV(self): return self.cycleDay.Query("todayBattleJumpNumLV", []) def SetTodayBattleJumpNumLV(self, lvs): self.cycleDay.Set("todayBattleJumpNumLV", lvs) #今日已领取至尊卡奖励标识 def GetTodayZhiZunRewardFlag(self): return self.cycleDay.Query("todayZhiZunRewardFlag", 0) def SetTodayZhiZunRewardFlag(self, flag): self.cycleDay.Set("todayZhiZunRewardFlag", flag) #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["vip"] = self.vip self.save_cache["vipExp"] = self.vipExp self.save_cache["monthCard"] = self.monthCard self.save_cache["weekCard"] = self.weekCard self.save_cache["onlineExpExtra"] = self.onlineExpExtra self.save_cache["onlineGoldExtra"] = self.onlineGoldExtra self.save_cache["monthCardReward"] = self.monthCardReward self.save_cache["weekCardReward"] = self.weekCardReward self.save_cache["monthCardBagExt"] = self.monthCardBagExt self.save_cache["vipGetList"] = self.vipGetList self.save_cache["battleJumpNum"] = self.battleJumpNum self.save_cache["zhizunCardFlag"] = self.zhizunCardFlag self.save_cache["timeFinish"] = self.timeFinish return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.vip = data.get("vip", 0) # vip等级 self.vipExp = data.get("vipExp", 0) # vip经验 self.monthCard = data.get("monthCard", 0) # 月卡 self.weekCard = data.get("weekCard", 0) # 周卡 self.onlineExpExtra = data.get("onlineExpExtra", 0) # self.onlineGoldExtra = data.get("onlineGoldExtra", 0) # self.monthCardReward = data.get("monthCardReward", []) # 月卡领奖列表 self.weekCardReward = data.get("weekCardReward", []) # 周卡领奖列表 self.monthCardBagExt = data.get("monthCardBagExt", 0) # 月卡扩容 self.vipGetList = data.get("vipGetList", []) # 已经领取列表 self.battleJumpNum = data.get("battleJumpNum", 0) # 战斗跳过次数 self.zhizunCardFlag = data.get("zhizunCardFlag", 0) # 至尊卡标识 self.timeFinish = data.get("timeFinish", []) # vip倒计时免费领取 ilen = len(self.timeFinish) keys = list(Game.res_mgr.res_vip.keys()) keys.sort() for lv in keys: vipRes = Game.res_mgr.res_vip.get(lv) if lv > ilen: self.timeFinish.append(vipRes.rewardTime) if lv in self.vipGetList: self.timeFinish[lv - 1] = 0 #登录初始化下发数据 def to_init_data(self): init_data = {} init_data["vip"] = self.vip init_data["vipExp"] = self.vipExp init_data["monthCard"] = self.monthCard init_data["weekCard"] = self.weekCard init_data["onlineExpExtra"] = self.onlineExpExtra init_data["onlineGoldExtra"] = self.onlineGoldExtra init_data["vipGetList"] = self.vipGetList init_data["vipDayRewardGetList"] = self.GetVIPDayRewardList() init_data["battleJumpNum"] = self.battleJumpNum init_data["zhizunCardFlag"] = self.zhizunCardFlag init_data["timeFinish"] = self.timeFinish init_data["todayZhiZunRewardFlag"] = self.GetTodayZhiZunRewardFlag() self.markDirty() return init_data def to_wee_hour_data(self): self.init_battleJumpNum() return self.to_init_data() def init_battleJumpNum(self, checkMax=True): has_get = self.GetTodayBattleJumpNumLV() if self.vip in has_get: return vipRes = Game.res_mgr.res_vip.get(self.vip, None) if not vipRes: return has_get.append(self.vip) if vipRes.battleJumpNum != -1: self.battleJumpNum += vipRes.battleJumpNum if self.battleJumpNum > vipRes.battleJumpNum * 2 and checkMax: self.battleJumpNum = vipRes.battleJumpNum * 2 else: self.battleJumpNum = -1 self.SetTodayBattleJumpNumLV(has_get) self.markDirty() def getBattleJumpNum(self): return self.battleJumpNum def setBattleJumpNum(self, num): self.battleJumpNum = num self.markDirty() def GetVipLv(self): return self.vip def onlineExpExtraAdd(self, v): self.onlineExpExtra += v self.markDirty() def onlineGoldExtraAdd(self, v): self.onlineGoldExtra += v self.markDirty() def getOnlineExpExtra(self): return self.onlineExpExtra def getOnlineGoldExtra(self): return self.onlineGoldExtra def SetVipLv(self, viplv): for v in range(self.vip + 1, viplv + 1): self.vip = v #抛出角色升级消息 self.owner.safe_pub(msg_define.MSG_ROLE_VIPLV_UPGRADE, self.vip) #抛出change self.owner.safe_pub(msg_define.MSG_ROLE_XLV_UPGRADE) self.markDirty() self.init_battleJumpNum(checkMax=False) def isMonthCard(self): t = int(time.time()) if self.monthCard < t: return 0 return 1 def addMonthCard30day(self): t = int(time.time()) if self.monthCard < t: self.monthCard = t + 60 * 60 * 24 * 30 else: self.monthCard += 60 * 60 * 24 * 30 sd = 0 if len(self.monthCardReward) != 0: sd = self.monthCardReward[-1] nd = gtime.getIntArrayYYYYMMDD(30, sd) self.monthCardReward.extend(nd) self.markDirty() def addWeekCard7day(self): t = int(time.time()) if self.weekCard < t: self.weekCard = t + 60 * 60 * 24 * 7 else: self.weekCard += 60 * 60 * 24 * 7 sd = 0 if len(self.weekCardReward) != 0: sd = self.weekCardReward[-1] nd = gtime.getIntArrayYYYYMMDD(7, sd) self.weekCardReward.extend(nd) self.markDirty() def addzZhiZunCardAllday(self): self.owner.bag.addSize(100) self.zhizunCardFlag = 1 self.markDirty() def GetBuyQmBossTz(self): # 全民boss今日已购买挑战次数(qmBossTz, int) return self.cycleDay.Query("qmBossTodayBuyTZ", 0) def SetBuyQmBossTz(self, num): # 全民boss今日已购买挑战次数(qmBossTz, int) self.cycleDay.Set("qmBossTodayBuyTZ", num) def GetVIPDayRewardList(self): # vip每日奖励领取列表 return self.cycleDay.Query("VIPDayRewardList", []) def SetVIPDayRewardList(self, ls): # vip每日奖励领取列表 self.cycleDay.Set("VIPDayRewardList", ls) def vipRewardMonth(self): nt = gtime.getYYYYMMDD() nt = int(nt) if len(self.monthCardReward) == 0: return False if self.monthCardReward[0] != nt: return False self.monthCardReward.pop(0) self.markDirty() return True def vipRewardWeek(self): nt = gtime.getYYYYMMDD() nt = int(nt) if len(self.weekCardReward) == 0: return False if self.weekCardReward[0] != nt: return False self.weekCardReward.pop(0) self.markDirty() return True def updateRewardTime(self): now = int(time.time()) iloginTime = self.owner.data.GetLoginTime() passtime = now - iloginTime for i in range(len(self.timeFinish)): self.timeFinish[i] = self.timeFinish[i] - passtime if self.vip > 3 and self.vip > i + 1: self.timeFinish[i] = 0 if self.timeFinish[i] < 0: self.timeFinish[i] = 0 self.markDirty() # 0==可以领取 1未到达 2以领取 3时间未到 def vipReward(self, lv): if self.vip < lv: return 1 if lv in self.vipGetList: return 2 if len(self.timeFinish) >= lv and self.timeFinish[lv - 1]: if self.vip > 3 and self.vip > lv: return 0 now = int(time.time()) iloginTime = self.owner.data.GetLoginTime() passtime = now - iloginTime if self.timeFinish[lv - 1] - passtime <= 0: return 0 else: return 3 return 0 def setVipReward(self, lv): self.vipGetList.append(lv) self.markDirty() def addExp(self, exp): self.vipExp += exp while True: res = Game.res_mgr.res_vip.get(self.vip) if not res: Game.glog.log2File("VIP_ADDEXP_NOTFOUND_RES", "%s|%s" % (self.owner.id, self.vip)) break if self.vipExp >= res.exp: resN = Game.res_mgr.res_vip.get(self.vip + 1) # self.owner.bag.addSize(res.addbag) if resN: self.SetVipLv(self.vip + 1) else: break else: break self.markDirty() # 角色下线时要做的清理操作 def uninit(self): pass
class PlayerNiudan(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.activityCycleData = ActivityCycleData(self) self.RollNum = [] # 扭蛋次数 {"k":resid,"v":num} self.save_cache = {} #存储缓存 def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache[ "activityCycleData"] = self.activityCycleData.to_save_bytes() self.save_cache["RollNum"] = self.RollNum return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.activityCycleData.load_from_dict(data.get("activityCycleData", "")) self.RollNum = data.get("RollNum", []) #登录初始化下发数据 def to_init_data(self): init_data = {} init_data["xianshiniudanBaodi"] = self.getCycleBaodi( constant.ACTIVITY_XIANSHINIUDAN) #限时 保底-当前抽卡次数 init_data["xianshiniudanReward"] = self.getCycleReward( constant.ACTIVITY_XIANSHINIUDAN) #限时 领奖 当前积分 init_data["xianshiniudanNeeds"] = self.getCycleNeeds( constant.ACTIVITY_XIANSHINIUDAN) #限时 领奖 已经领奖idx # init_data["RollOneNum"] = self.getRollOneNum() xxx = self.getRollOneNum() freenum = {} for k, v in Game.res_mgr.res_niudanSystem.items(): onenum = xxx.get(k, 0) sv = v.costFree - onenum if sv < 0: sv = 0 freenum[k] = sv init_data["freenum"] = freenum return init_data #零点更新的数据 def to_wee_hour_data(self): return self.to_init_data() # 角色下线时要做的清理操作 def uninit(self): pass def getRollOneNum(self): return self.cycleDay.Query("RollOneNum", {}) def setRollOneNum(self, obj): self.cycleDay.Set("RollOneNum", obj) def getCycleNeeds(self, actid): return self.activityCycleData.Query("CycleNeeds_" + str(actid), []) def setCycleNeeds(self, v, actid): self.activityCycleData.Set("CycleNeeds_" + str(actid), v, actid) def getCycleBaodi(self, actid): return self.activityCycleData.Query("CycleBaodi_" + str(actid), 0) def setCycleBaodi(self, v, actid): self.activityCycleData.Set("CycleBaodi_" + str(actid), v, actid) def getCycleReward(self, actid): return self.activityCycleData.Query("CycleReward_" + str(actid), 0) def setCycleReward(self, v, actid): self.activityCycleData.Set("CycleReward_" + str(actid), v, actid) def getRollNum(self): o = {} for v in self.RollNum: o[v["k"]] = v["v"] return o def setRollNum(self, obj): self.RollNum = [] for k, v in obj.items(): one = {"k": k, "v": v} self.RollNum.append(one) self.markDirty()
class PlayerMap(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.mapSubId = 1 #当前关卡 self.passSubId = 0 #已通关关卡id self.rewardSubId = [] #领奖的关卡id self.offexp = 0 #离线经验箱子 经验 self.offcoin = 0 #离线经验箱子 金币 self.offexplore = 0 #离线经验箱子 探索值 self.offpetexp = 0 #离线经验箱子 宠物经验 self.offreward = {} #离线经验箱子 道具{id:num} self.offtimes = 0 #离线经验箱子 当前累计次数 self.ChargeEndTime = {} #特权结束时间 {resid:结束时间戳秒} self.offlasttime = time.time() #离线经验箱子 最后一次生成奖励时间错时间戳 self.objIDs = [] #地图物件 ID self.objlasttime = time.time() #地图物 最后一次生成物件时间错时间戳 self.objkey = [] #地图物 已扔关键id self.passEncounterId = 0 #已通关遭遇战id self.firstFailEncounterId = 0 #首次失败遭遇战最大id self.save_cache = {} #存储缓存 # 监听普通场景打怪 self.owner.sub(msg_define.MSG_MORMAL_SCENE_FIGHT, self.event_normal_fight) def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["mapSubId"] = self.mapSubId self.save_cache["passSubId"] = self.passSubId self.save_cache["rewardSubId"] = self.rewardSubId self.save_cache["ChargeEndTime"] = utility.obj2list( self.ChargeEndTime) self.save_cache["passEncounterId"] = self.passEncounterId self.save_cache["firstFailEncounterId"] = self.firstFailEncounterId if self.offexp: self.save_cache["offexp"] = self.offexp if self.offcoin: self.save_cache["offcoin"] = self.offcoin if self.offexplore: self.save_cache["offexplore"] = self.offexplore if self.offpetexp: self.save_cache["offpetexp"] = self.offpetexp if self.offreward: self.save_cache["offreward"] = self.offreward if self.offtimes: self.save_cache["offtimes"] = self.offtimes if self.offlasttime: self.save_cache["offlasttime"] = self.offlasttime if self.objIDs: self.save_cache["objIDs"] = self.objIDs if self.objlasttime: self.save_cache["objlasttime"] = self.objlasttime if self.objkey: self.save_cache["objkey"] = self.objkey return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.ChargeEndTime = utility.list2obj(data.get("ChargeEndTime", [])) self.mapSubId = data.get("mapSubId", 1) self.passSubId = data.get("passSubId", 0) self.rewardSubId = data.get("rewardSubId", []) self.offexp = data.get("offexp", 0) self.offcoin = data.get("offcoin", 0) self.offexplore = data.get("offexplore", 0) self.offpetexp = data.get("offpetexp", 0) self.offreward = data.get("offreward", {}) self.offtimes = data.get("offtimes", 0) self.offlasttime = data.get("offlasttime", time.time()) self.objIDs = data.get("objIDs", []) self.objlasttime = data.get("objlasttime", time.time()) self.objkey = data.get("objkey", []) self.passEncounterId = data.get("passEncounterId", 0) # 已通关遭遇战id self.firstFailEncounterId = data.get("firstFailEncounterId", 0) # 首次失败遭遇战最大id #登录初始化下发数据 def to_init_data(self): init_data = {} vipres = Game.res_mgr.res_vip.get(self.owner.vip.vip) mapOffTime = Game.res_mgr.res_common.get("mapOffTime") mapOffMaxTimes = Game.res_mgr.res_common.get("mapOffMaxTimes") mapObjTime = Game.res_mgr.res_common.get("mapObjTime") mapObjNum = Game.res_mgr.res_common.get("mapObjNum") res = Game.res_mgr.res_mapSub.get(self.mapSubId) nt = time.time() n = mapOffMaxTimes.i - self.offtimes for _ in range(n): netxt = self.offlasttime + mapOffTime.i if netxt > nt: break self.offtimes += 1 self.offlasttime = netxt self.offexp += res.offexp * (10000 + vipres.offper) // 10000 self.offcoin += res.offcoin * (10000 + vipres.offper) // 10000 self.offexplore += res.offexplore * (10000 + vipres.offper) // 10000 self.offpetexp += res.offpetexp * (10000 + vipres.offper) // 10000 for offreward in res.offreward: rewardRes = Game.res_mgr.res_reward.get(offreward) resp = rewardRes.doReward() # resp={4:1} for k, v in resp.items(): k = str(k) self.offreward[k] = self.offreward.get(k, 0) + v if self.offtimes == mapOffMaxTimes.i: self.offlasttime = nt obj = [] n = mapObjNum.i - len(self.objIDs) for _ in range(n): netxt = self.objlasttime + mapObjTime.i if netxt > nt: break # 重复类型 obj = res.objReuse rx = random.randint(1, 10000) if len(self.objkey) >= len(res.objOnce): rx = 999 isOnce = False if rx <= res.objPercent: isOnce = True obj = [] ooo = copy.deepcopy(res.objOnce) for vv in ooo: if vv[0] not in self.objkey: obj.append(vv) moid = utility.Choice(obj) self.objIDs.append(moid) if isOnce: self.objkey.append(moid) self.objlasttime = netxt if len(self.objIDs) == mapObjNum.i: self.objlasttime = nt self.markDirty() init_data["mapSubId"] = self.mapSubId init_data["passSubId"] = self.passSubId init_data["rewardSubId"] = self.rewardSubId init_data["quickFree"] = self.getquickFree() init_data["quickUse"] = self.getquickUse() init_data["ChargeEndTime"] = self.ChargeEndTime init_data["offexp"] = self.offexp init_data["offcoin"] = self.offcoin init_data["offexplore"] = self.offexplore init_data["offpetexp"] = self.offpetexp init_data["offreward"] = self.offreward init_data["offlasttime"] = self.offlasttime init_data["offtimes"] = self.offtimes init_data["objIDs"] = self.objIDs init_data["objlasttime"] = self.objlasttime init_data["objkey"] = self.objkey init_data["passEncounterId"] = self.passEncounterId return init_data #零点更新的数据 def to_wee_hour_data(self): return self.to_init_data() # 角色下线时要做的清理操作 def uninit(self): self.owner.unsub(msg_define.MSG_MORMAL_SCENE_FIGHT, self.event_normal_fight) def gainOff(self): offexp = self.offexp offcoin = self.offcoin offexplore = self.offexplore offpetexp = self.offpetexp offreward = {} for k, v in self.offreward.items(): k = int(k) offreward[k] = v self.offexp = 0 self.offcoin = 0 self.offexplore = 0 self.offpetexp = 0 self.offreward = {} self.offtimes = 0 self.markDirty() return offexp, offcoin, offexplore, offpetexp, offreward def gainObj(self, resid): if resid not in self.objIDs: return 0 self.objIDs.remove(resid) return resid def getquickFree(self): return self.cycleDay.Query("quickFree", 0) def setquickFree(self, v): self.cycleDay.Set("quickFree", v) def getquickUse(self): return self.cycleDay.Query("quickUse", 0) def setquickUse(self, v): self.cycleDay.Set("quickUse", v) def event_normal_fight(self, fightResult): """普通场景战斗""" if fightResult: #打赢才算 self.passSubId = self.mapSubId self.mapSubId = self.GetNextMapSubId() # 更新地图关卡排行榜 # baseInfo = self.owner.base.to_rank_data() # rankInfo = {} # rankInfo["id"] = self.owner.id # rankInfo["sortEle"] = [self.passSubId, self.owner.base.GetFightAbility()] # rankInfo["baseInfo"] = baseInfo # Game.sub_rank_mgr.updatePlayer(constant.RANK_TYPE_MAP, rankInfo) self.owner.rank.uploadRank(constant.RANK_TYPE_MAP) # 更新等级榜 # rankInfo = {} # rankInfo["id"] = self.owner.id # rankInfo["sortEle"] = [self.owner.base.lv, self.passSubId, self.owner.base.fa] # rankInfo["baseInfo"] = baseInfo # Game.sub_rank_mgr.updatePlayer(constant.RANK_TYPE_LV, rankInfo) def GetNextMapSubId(self): iNextId = self.mapSubId + 1 curRes = Game.res_mgr.res_mapSub.get(self.mapSubId) nextRes = Game.res_mgr.res_mapSub.get(iNextId) if not nextRes: return self.mapSubId if curRes.mapId != nextRes.mapId: #跨地图需要手动 return self.mapSubId self.objIDs = [] self.objlasttime = 0 self.objkey = [] self.markDirty() return iNextId def SetRewardSubId(self, subId): self.rewardSubId.append(subId) self.markDirty() def SetMapSubId(self, subId): self.mapSubId = subId self.objIDs = [] self.objlasttime = 0 self.objkey = [] self.markDirty() def SetPassEncounterId(self, passEncounterId): self.passEncounterId = passEncounterId self.markDirty() self.owner.safe_pub(msg_define.MSG_PASS_ENCOUNTER_FIGHT) def GetPassEncounterId(self): return self.passEncounterId def initPassEncounterId(self): if self.passEncounterId: return keys = list(Game.res_mgr.res_passId_encounter.keys()) keys.sort() for key in keys: resEncounter = Game.res_mgr.res_passId_encounter.get(key) if resEncounter.passId < self.passSubId: self.passEncounterId = resEncounter.id self.markDirty() else: break def GetFirstFailEncounterId(self): return self.firstFailEncounterId def SetFirstFailEncounterId(self, EncounterId): if EncounterId > self.firstFailEncounterId: self.firstFailEncounterId = EncounterId self.markDirty()
class PlayerZhuanpan(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.freeResetTime = {} #免费重置时间 id:time.time() self.score = {} #得分 resid:score self.rewardid = {} #已经领奖idx resid:[] self.save_cache = {} #存储缓存 def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["freeResetTime"] = utility.obj2list( self.freeResetTime) self.save_cache["score"] = utility.obj2list(self.score) self.save_cache["rewardid"] = utility.obj2list(self.rewardid) return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.freeResetTime = utility.list2obj(data.get("freeResetTime", [])) self.score = utility.list2obj(data.get("score", [])) self.rewardid = utility.list2obj(data.get("rewardid", [])) #登录初始化下发数据 def to_init_data(self): init_data = {} RewardData = self.getRewardData() for v in Game.res_mgr.res_zhuanpanSystem.values(): if v.id not in RewardData: RewardData[v.id] = {"disable": [], "data": {}} for vv in v.idxCanDisable.keys(): pool = [] for k in Game.res_mgr.res_zhuanpanPool.values(): if k.sys == v.id and k.idx == vv: value = (k.id, k.Weight) pool.append(value) RewardData[v.id]["data"][vv] = utility.Choice(pool) self.setRewardData(RewardData) init_data["RewardData"] = RewardData init_data["freeResetTime"] = self.freeResetTime init_data["score"] = self.score init_data["rewardid"] = self.rewardid return init_data #零点更新的数据 def to_wee_hour_data(self): return self.to_init_data() # 角色下线时要做的清理操作 def uninit(self): pass def getRewardData(self): return self.cycleDay.Query("RewardData", {}) def setRewardData(self, v): self.cycleDay.Set("RewardData", v) def reset(self, resid): RewardData = self.getRewardData() RewardData.pop(resid, None) self.setRewardData(RewardData) def addscore(self, res): self.score[res.id] = self.score.get(res.id, 0) + res.score self.markDirty()
class PlayerTask(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.maintask = None #主线任务 self.passMainId = 0 #已通关主线任务 self.guild_act_tasks = {} #{任务id:obj} #帮会活跃任务 self.shitu_tasks = {} #{任务id:obj} #师徒任务 self.guild_act_reward_tasks = {} #{任务id:obj} #帮会活跃奖励任务 self.xyll_tasks = {} #{任务id:obj} #西游历练任务 self.rchy_tasks = {} #{任务id:obj} #日常活跃任务 self.zhoumolibaotasks = {} #{任务id:obj} #周末礼包任务 self.Renwudajihuantasks = {} #{任务id:obj} #任务大集换 self.RenwudajihuanIndex = { } #{index:taskid} #任务大集换 index与任务id关系= "1","2","3","4","5", self.Renwudajihuan2tasks = {} #{任务id:obj} #任务大集换 self.Renwudajihuan2Index = { } #{index:taskid} #任务大集换 index与任务id关系= "1","2","3","4","5", self.alreadyOpenTaskId = [] # 已开放的系统功能体验id self.open_tasks = {} #{任务id:obj} #功能开放体验任务 self.alreadyGetRewardOpenTaskId = [] # 已领取完成奖励的系统功能体验id self.alreadyGetOpenRewardOpenTaskId = [] # 已领取开启奖励的系统功能体验id self.activityMonster_tasks = {} #{任务id:obj} 神宠超梦活动前置任务 self.thanksgivingDay_tasks = {} # {任务id:obj} 感恩节任务 self.levelContest_tasks = {} # {任务id:obj} 段位赛任务 self.maze_tasks = {} # {任务id:obj} 迷宫任务 self.gongcheng_tasks = {} #{任务id:obj} 攻城任务 self.zhuanpan_tasks = {} #{任务id:obj} 转盘任务 self.new_kfkh_tasks = {} # {任务id:obj} 新开服狂欢(和全民攻城一样的功能) self.passMainIdDict = {} self.cycleDay = CycleDay(self, keepCyc=2) self.cycleWeek = CycleWeek(self) self.save_cache = {} #存储缓存 #帮会活跃任务 def GetGuildActTask(self, taskId): guildActTasks = self.cycleDay.Query("guildActTasks", {}) return guildActTasks.get(taskId, {}) def SetGuildActTask(self, taskId, taskInfo): guildActTasks = self.cycleDay.Query("guildActTasks", {}) guildActTasks[taskId] = taskInfo self.cycleDay.Set("guildActTasks", guildActTasks) #师徒任务 def GetShituTask(self, taskId): shituTasks = self.cycleDay.Query("shituTasks", {}) return shituTasks.get(taskId, {}) def SetShituTask(self, taskId, taskInfo): shituTasks = self.cycleDay.Query("shituTasks", {}) shituTasks[taskId] = taskInfo self.cycleDay.Set("shituTasks", shituTasks) #帮会活跃奖励 def GetGuildActRewardTask(self, taskId): guildActRewardTasks = self.cycleDay.Query("guildActRewardTasks", {}) return guildActRewardTasks.get(taskId, {}) def SetGuildActRewardTask(self, taskId, taskInfo): guildActRewardTasks = self.cycleDay.Query("guildActRewardTasks", {}) guildActRewardTasks[taskId] = taskInfo self.cycleDay.Set("guildActRewardTasks", guildActRewardTasks) #西游历练任务 def GetXyllTask(self, taskId, iWhichCyc=0): xyllTasks = self.cycleDay.Query("xyllTasks", {}, iWhichCyc=iWhichCyc) return xyllTasks.get(taskId, {}) def SetXyllTask(self, taskId, taskInfo, iWhichCyc=0): xyllTasks = self.cycleDay.Query("xyllTasks", {}, iWhichCyc=iWhichCyc) xyllTasks[taskId] = taskInfo self.cycleDay.Set("xyllTasks", xyllTasks, iWhichCyc=iWhichCyc) # 日常活跃任务 def GetRchyTask(self, taskId): rchyTasks = self.cycleDay.Query("rchyTasks", {}) return rchyTasks.get(taskId, {}) def SetRchyTask(self, taskId, taskInfo): rchyTasks = self.cycleDay.Query("rchyTasks", {}) rchyTasks[taskId] = taskInfo self.cycleDay.Set("rchyTasks", rchyTasks) def SetZhoumolibaoTask(self, taskId, taskInfo): zhoumolibaoTasks = self.cycleWeek.Query("zhoumolibaoTasks", {}) zhoumolibaoTasks[taskId] = taskInfo self.cycleWeek.Set("zhoumolibaoTasks", zhoumolibaoTasks) def SetRenwudajihuanTask(self, taskId, taskInfo): RenwudajihuanTasks = self.cycleDay.Query("RenwudajihuanTasks", {}) RenwudajihuanTasks[taskId] = taskInfo self.cycleDay.Set("RenwudajihuanTasks", RenwudajihuanTasks) def SetRenwudajihuan2Task(self, taskId, taskInfo): RenwudajihuanTasks = self.cycleDay.Query("Renwudajihuan2Tasks", {}) RenwudajihuanTasks[taskId] = taskInfo self.cycleDay.Set("Renwudajihuan2Tasks", RenwudajihuanTasks) #日常活跃日奖励 def GetRchyDayReward(self): return self.cycleDay.Query("rchyDayReward", []) def SetRchyDayReward(self, dayReward): self.cycleDay.Set("rchyDayReward", dayReward) #日常活跃日累计 def GetRchyDayTotal(self): return self.cycleDay.Query("rchyDayTotal", 0) def SetRchyDayTotal(self, num): self.cycleDay.Set("rchyDayTotal", num) #日常活跃周奖励 def GetRchyWeekReward(self): return self.cycleWeek.Query("rchyWeekReward", []) def SetRchyWeekReward(self, weekReward): self.cycleWeek.Set("rchyWeekReward", weekReward) #日常活跃周累计 def GetRchyWeekTotal(self): return self.cycleWeek.Query("rchyWeekTotal", 0) def SetRchyWeekTotal(self, num): self.cycleWeek.Set("rchyWeekTotal", num) def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} if self.maintask: self.save_cache["maintask"] = self.maintask.to_save_dict() self.save_cache["passMainId"] = self.passMainId self.save_cache["alreadyOpenTaskId"] = self.alreadyOpenTaskId self.save_cache[ "alreadyGetRewardOpenTaskId"] = self.alreadyGetRewardOpenTaskId self.save_cache[ "alreadyGetOpenRewardOpenTaskId"] = self.alreadyGetOpenRewardOpenTaskId self.save_cache["RenwudajihuanIndex"] = self.RenwudajihuanIndex self.save_cache["Renwudajihuan2Index"] = self.Renwudajihuan2Index self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["cycleWeek"] = self.cycleWeek.to_save_bytes() self.save_cache["opentask"] = [] for taskId, taskobj in self.open_tasks.items(): self.save_cache["opentask"].append(taskobj.to_save_dict()) self.save_cache["activityMonster_tasks"] = [] for taskId, taskobj in self.activityMonster_tasks.items(): self.save_cache["activityMonster_tasks"].append( taskobj.to_save_dict()) self.save_cache["thanksgivingDay_tasks"] = [] for taskId, taskobj in self.thanksgivingDay_tasks.items(): self.save_cache["thanksgivingDay_tasks"].append( taskobj.to_save_dict()) self.save_cache["gongcheng_tasks"] = [] for taskId, taskobj in self.gongcheng_tasks.items(): self.save_cache["gongcheng_tasks"].append( taskobj.to_save_dict()) self.save_cache["special_pet_tasks"] = [] for taskId, taskobj in self.special_pet_tasks.items(): self.save_cache["special_pet_tasks"].append( taskobj.to_save_dict()) self.save_cache["zhuanpan_tasks"] = [] for taskId, taskobj in self.zhuanpan_tasks.items(): self.save_cache["zhuanpan_tasks"].append( taskobj.to_save_dict()) self.save_cache["new_kfkh_tasks"] = [] for taskId, taskobj in self.new_kfkh_tasks.items(): self.save_cache["new_kfkh_tasks"].append( taskobj.to_save_dict()) self.save_cache["levelContest_tasks"] = [] for taskId, taskobj in self.levelContest_tasks.items(): self.save_cache["levelContest_tasks"].append( taskobj.to_save_dict()) self.save_cache["maze_tasks"] = [] for taskId, taskobj in self.maze_tasks.items(): self.save_cache["maze_tasks"].append(taskobj.to_save_dict()) return self.save_cache #读库数据初始化 def load_from_dict(self, data): maintask = data.get("maintask", {}) self.passMainId = data.get("passMainId", 0) self.alreadyOpenTaskId = data.get("alreadyOpenTaskId", []) # 已开放的系统功能体验id self.alreadyGetRewardOpenTaskId = data.get( "alreadyGetRewardOpenTaskId", []) # 已领取奖励的系统功能体验id self.alreadyGetOpenRewardOpenTaskId = data.get( "alreadyGetOpenRewardOpenTaskId", []) # 已领取开启奖励的系统功能体验id self.RenwudajihuanIndex = data.get("RenwudajihuanIndex", {}) # 已领取开启奖励的系统功能体验id self.Renwudajihuan2Index = data.get("Renwudajihuan2Index", {}) # 已领取开启奖励的系统功能体验id self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.cycleWeek.load_from_dict(data.get("cycleWeek", "")) self.initMainTasks(maintask) self.initGuildActTasks() self.initShituTasks() self.initGuildActRewardTasks() self.initXyllTasks() self.initRchyTasks() # self.initZhoumolibaoTasks() self.initRenwudajihuanTasks() self.initRenwudajihuan2Tasks() open_task_data = data.get("opentask", []) self.initOpenTasks(open_task_data) activityMonster_tasks = data.get("activityMonster_tasks", []) # {任务id:obj} 神宠超梦活动前置任务 self.initActivityMonsterTasks(activityMonster_tasks) thanksgivingDay_tasks = data.get("thanksgivingDay_tasks", []) self.initThanksgivingDayTasks(thanksgivingDay_tasks) gongcheng_tasks = data.get("gongcheng_tasks", []) self.initGongchengTasks(gongcheng_tasks) special_pet_tasks = data.get("special_pet_tasks", []) self.initSpecPetTasks(special_pet_tasks) zhuanpan_tasks = data.get("zhuanpan_tasks", []) self.initZhuanpanTasks(zhuanpan_tasks) new_kfkh_tasks = data.get("new_kfkh_tasks", []) self.initNewKfkhTasks(new_kfkh_tasks) levelContest_tasks = data.get("levelContest_tasks", []) self.initLevelContestTasks(levelContest_tasks) maze_tasks = data.get("maze_tasks", []) self.initMazeTasks(maze_tasks) def initPassMainTaskList(self): iTaskId = 400001 if self.passMainId: while iTaskId != self.passMainId: res = Game.res_mgr.res_task.get(iTaskId) if res: self.passMainIdDict[iTaskId] = 1 iTaskId = res.nextId else: break self.passMainIdDict[self.passMainId] = 1 def AppendOpenTaskId(self, openTaskId): res = Game.res_mgr.res_openTask.get(openTaskId) if not res: return self.alreadyOpenTaskId.append(openTaskId) for taskId in res.taskList: taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.open_tasks[taskId] = taskobj self.markDirty() #推送更新数据 dUpdate = {} dUpdate["taskInfo"] = self.to_init_data(all=1) spawn(self.owner.call, "roleAllUpdate", {"allUpdate": dUpdate}, noresult=True) def AppendActivityMonsterTaskId(self, activityMonsterId): res = Game.res_mgr.res_actMonster.get(activityMonsterId) if not res: return for taskId in res.taskList: if taskId in self.activityMonster_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.activityMonster_tasks[taskId] = taskobj self.markDirty() # #推送更新数据 # dUpdate = {} # dUpdate["taskInfo"] = self.to_init_data(all=1) # spawn(self.owner.call, "roleAllUpdate", {"allUpdate": dUpdate}, noresult=True) def AppendThanksgivingDayTaskId(self, thanksgivingDayId): res = Game.res_mgr.res_thanksgivingDayTask.get(thanksgivingDayId) if not res: return for taskId in res.taskList: if taskId in self.thanksgivingDay_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.thanksgivingDay_tasks[taskId] = taskobj self.markDirty() def AppendGongchengTaskId(self, gongchengId): res = Game.res_mgr.res_gongchengTask.get(gongchengId) if not res: return for taskId in res.taskList: if taskId in self.gongcheng_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.gongcheng_tasks[taskId] = taskobj self.markDirty() def AppendSpecPetTaskId(self, petSpecialTaskId): res = Game.res_mgr.res_petSpecialTask.get(petSpecialTaskId) if not res: return for taskId in res.taskList: if taskId in self.special_pet_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.special_pet_tasks[taskId] = taskobj self.markDirty() def AppendZhuanpanTaskId(self, zhuanpanId): res = Game.res_mgr.res_cycleNiudan.get(zhuanpanId) if not res: return for taskId in res.taskList: if taskId in self.zhuanpan_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.zhuanpan_tasks[taskId] = taskobj self.markDirty() def AppendNewKfkhTaskId(self, newKfkhId): res = Game.res_mgr.res_newKfkhTask.get(newKfkhId) if not res: return for taskId in res.taskList: if taskId in self.new_kfkh_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.new_kfkh_tasks[taskId] = taskobj self.markDirty() def AppendLevelContestTasks(self): taskList = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_12, []) for taskRes in taskList: taskId = taskRes.id if taskId in self.levelContest_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.levelContest_tasks[taskId] = taskobj self.markDirty() def AppendMazeTasks(self, mazeNo): mazeRes = Game.res_mgr.res_maze.get(mazeNo) if not mazeRes: return for taskRes in mazeRes.taskList: taskId = taskRes.id if taskId in self.maze_tasks: continue taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.maze_tasks[taskId] = taskobj self.markDirty() def AppendMazeTaskById(self, taskId): taskInfo = {"taskId": taskId} taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: return self.maze_tasks[taskId] = taskobj self.markDirty() def checkOpenTask(self): for openId, openRes in Game.res_mgr.res_open.items(): if openRes.openTaskId: self.owner.checkOpenLimit(openId) def GetPassMainTaskDict(self): return self.passMainIdDict def GetPassMainId(self): return self.passMainId def SetPassMainId(self, passId): self.passMainId = passId self.passMainIdDict[passId] = 1 self.markDirty() def GetAlreadyGetRewardOpenTaskId(self): return self.alreadyGetRewardOpenTaskId def SetAlreadyGetRewardOpenTaskId(self, alreadyGetRewardOpenTaskId): self.alreadyGetRewardOpenTaskId = alreadyGetRewardOpenTaskId self.markDirty() def GetAlreadyGetOpenRewardOpenTaskId(self): return self.alreadyGetOpenRewardOpenTaskId def SetAlreadyGetOpenRewardOpenTaskId(self, alreadyGetOpenRewardOpenTaskId): self.alreadyGetOpenRewardOpenTaskId = alreadyGetOpenRewardOpenTaskId self.markDirty() #登录初始化下发数据 def to_init_data(self, all=0): resp = {} resp["mainTask"] = self.maintask.to_save_dict() if all: resp["alreadyOpenTaskId"] = self.alreadyOpenTaskId resp[ "alreadyGetRewardOpenTaskId"] = self.alreadyGetRewardOpenTaskId resp[ "alreadyGetOpenRewardOpenTaskId"] = self.alreadyGetOpenRewardOpenTaskId resp["openTaskData"] = self.to_OpenTasks_data() resp[ "activityMonsterTaskData"] = self.to_activityMonsterTasks_data( ) resp["zhoumolibaoTaskData"] = self.to_ZhoumolibaoTasks_data() resp["RenwudajihuanTaskData"] = self.to_RenwudajihuanTasks_data() resp["Renwudajihuan2TaskData"] = self.to_Renwudajihuan2Tasks_data() resp[ "thanksgivingDayTaskData"] = self.to_thanksgivingDayTasks_data( ) resp["levelContestTaskData"] = self.to_LevelContestTasks_data() resp["mazeTaskData"] = self.to_MazeTasks_data() resp["gongchengTaskData"] = self.to_gongchengTasks_data() resp["zhuanpanTaskData"] = self.to_zhuanpanTasks_data() resp["specPetTaskData"] = self.to_specPetTasks_data() resp["RenwudajihuanIndex"] = self.RenwudajihuanIndex resp["Renwudajihuan2Index"] = self.Renwudajihuan2Index return resp def to_wee_hour_data(self): return self.to_init_data(all=1) def cleanOpenTask(self, openTaskId): openTaskRes = Game.res_mgr.res_openTask.get(openTaskId) if not openTaskRes: return #所有任务必须完成才可领取 for taskId in openTaskRes.taskList: taskobj = self.open_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanActivityMonsterTask(self, activityMonsterId): res = Game.res_mgr.res_actMonster.get(activityMonsterId) if not res: return for taskId in res.taskList: taskobj = self.activityMonster_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanThanksgivingDayTask(self): for taskId, taskobj in self.thanksgivingDay_tasks.items(): taskobj.uninit() self.thanksgivingDay_tasks = {} self.markDirty() def cleanThanksgivingDayTaskById(self, thanksgivingDayId): res = Game.res_mgr.res_thanksgivingDayTask.get(thanksgivingDayId) if not res: return for taskId in res.taskList: taskobj = self.thanksgivingDay_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanGongchengTask(self): for taskId, taskobj in self.gongcheng_tasks.items(): taskobj.uninit() self.gongcheng_tasks = {} self.markDirty() def cleanSpecPetTask(self): for taskId, taskobj in self.special_pet_tasks.items(): taskobj.uninit() self.special_pet_tasks = {} self.markDirty() def cleanZhuanpanTask(self): for taskId, taskobj in self.zhuanpan_tasks.items(): taskobj.uninit() self.zhuanpan_tasks = {} self.markDirty() def cleanGongchengById(self, gongchengId): res = Game.res_mgr.res_gongchengTask.get(gongchengId) if not res: return for taskId in res.taskList: taskobj = self.gongcheng_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanSpecPetById(self, petSpecialTaskId): res = Game.res_mgr.res_petSpecialTask.get(petSpecialTaskId) if not res: return for taskId in res.taskList: taskobj = self.special_pet_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanZhuanpanById(self, zhuanpanId): res = Game.res_mgr.res_cycleNiudan.get(zhuanpanId) if not res: return for taskId in res.taskList: taskobj = self.zhuanpan_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanNewKfhkTask(self): for taskId, taskobj in self.new_kfkh_tasks.items(): taskobj.uninit() self.new_kfkh_tasks = {} self.markDirty() def cleanNewKfkhById(self, newKfkhId): res = Game.res_mgr.res_newKfkhTask.get(newKfkhId) if not res: return for taskId in res.taskList: taskobj = self.new_kfkh_tasks.pop(taskId, None) if taskobj: taskobj.uninit() def cleanLevelContestTask(self): for taskId, taskobj in self.levelContest_tasks.items(): taskobj.uninit() self.levelContest_tasks = {} self.markDirty() def cleanAllMazeTask(self): for taskId, taskobj in self.maze_tasks.items(): taskobj.uninit() self.maze_tasks = {} self.markDirty() def cleanMazeTaskById(self, taskId): taskobj = self.maze_tasks.pop(taskId, None) if taskobj: taskobj.uninit() self.markDirty() def uninit(self): if self.maintask: self.maintask.uninit() for taskId, taskobj in self.shitu_tasks.items(): taskobj.uninit() for taskId, taskobj in self.guild_act_tasks.items(): taskobj.uninit() for taskId, taskobj in self.guild_act_reward_tasks.items(): taskobj.uninit() for taskId, taskobj in self.xyll_tasks.items(): taskobj.uninit() for taskId, taskobj in self.rchy_tasks.items(): taskobj.uninit() for taskId, taskobj in self.zhoumolibaotasks.items(): taskobj.uninit() for taskId, taskobj in self.Renwudajihuantasks.items(): taskobj.uninit() for taskId, taskobj in self.Renwudajihuan2tasks.items(): taskobj.uninit() for taskId, taskobj in self.open_tasks.items(): taskobj.uninit() for taskId, taskobj in self.activityMonster_tasks.items(): taskobj.uninit() for taskId, taskobj in self.thanksgivingDay_tasks.items(): taskobj.uninit() for taskId, taskobj in self.levelContest_tasks.items(): taskobj.uninit() for taskId, taskobj in self.maze_tasks.items(): taskobj.uninit() for taskId, taskobj in self.gongcheng_tasks.items(): taskobj.uninit() for taskId, taskobj in self.special_pet_tasks.items(): taskobj.uninit() for taskId, taskobj in self.zhuanpan_tasks.items(): taskobj.uninit() def initMainTasks(self, maintask): #主线任务 if not maintask: maintask = {"taskId": 400001} self.markDirty() taskId = maintask.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, maintask) if not taskobj: return self.maintask = taskobj def checkNextMainTask(self): if not self.maintask: return mainId = self.maintask.getTaskId() taskRes = Game.res_mgr.res_task.get(mainId) if not taskRes: return nextRes = Game.res_mgr.res_task.get(taskRes.nextId) if not nextRes: return if mainId == self.passMainId: maintask = {"taskId": nextRes.id} _, taskobj = CreatTask(nextRes.id, self, maintask, no_happen=True) if taskobj: self.maintask = taskobj self.markDirty() if taskRes.type == constant.TASK_TYPE_36: self.maintask.num = taskRes.num self.maintask.finish = 1 self.maintask.markDirty() def initGuildActTasks(self): # 帮会活跃任务 guild_act_tasks = self.cycleDay.Query("guildActTasks", {}) if not guild_act_tasks: #隔天从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_1, []) for res in resTasks: guild_act_tasks[res.id] = {"taskId": res.id} self.cycleDay.Set("guildActTasks", guild_act_tasks) if self.owner.guild.GetGuildId(): for taskId, taskobj in self.guild_act_tasks.items(): taskobj.uninit() for taskId, taskInfo in guild_act_tasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.guild_act_tasks[taskId] = taskobj def to_GuildActTasks_data(self): guild_act_tasks = self.cycleDay.Query("guildActTasks", {}) if not guild_act_tasks: # 隔天从新初始化 self.initGuildActTasks() resp = [] for taskId, taskobj in self.guild_act_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def uninitShituTasks(self): for taskId, taskobj in self.shitu_tasks.items(): taskobj.reset() taskobj.uninit() def initShituTasks(self): # 师徒任务 shitu_tasks = self.cycleDay.Query("shituTasks", {}) if not shitu_tasks: #隔天从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_5, []) for res in resTasks: shitu_tasks[res.id] = {"taskId": res.id} self.cycleDay.Set("shituTasks", shitu_tasks) if self.owner.shitu.id: for taskId, taskInfo in shitu_tasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.shitu_tasks[taskId] = taskobj def to_ShituTasks_data(self): shitu_tasks = self.cycleDay.Query("shituTasks", {}) if not shitu_tasks: # 隔天从新初始化 self.initShituTasks() resp = [] for taskId, taskobj in self.shitu_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initGuildActRewardTasks(self): # 帮会活跃奖励 guild_act_reward_tasks = self.cycleDay.Query("guildActRewardTasks", {}) if not guild_act_reward_tasks: #隔天从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_2, []) for res in resTasks: guild_act_reward_tasks[res.id] = {"taskId": res.id} self.cycleDay.Set("guildActRewardTasks", guild_act_reward_tasks) if self.owner.guild.GetGuildId(): for taskId, taskobj in self.guild_act_reward_tasks.items(): taskobj.uninit() for taskId, taskInfo in guild_act_reward_tasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.guild_act_reward_tasks[taskId] = taskobj def to_GuildActRewardTasks_data(self): guild_act_reward_tasks = self.cycleDay.Query("guildActRewardTasks", {}) if not guild_act_reward_tasks: # 隔天从新初始化 self.initGuildActRewardTasks() resp = [] for taskId, taskobj in self.guild_act_reward_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initXyllTasks(self): # 西游历练任务 xyll_tasks = self.cycleDay.Query("xyllTasks", {}) if not xyll_tasks: #隔天从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_3, []) for res in resTasks: xyll_tasks[res.id] = {"taskId": res.id} self.cycleDay.Set("xyllTasks", xyll_tasks) for taskId, taskInfo in xyll_tasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.xyll_tasks[taskId] = taskobj def to_XyllTasks_data(self): xyll_tasks = self.cycleDay.Query("xyllTasks", {}) if not xyll_tasks: # 隔天从新初始化 self.initXyllTasks() resp = [] for taskId, taskobj in self.xyll_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def to_XyllTasks_find_data(self): """西游历练找回""" resp = {} xyllTasks = self.cycleDay.Query("xyllTasks", {}, iWhichCyc=-1) if not xyllTasks: #初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_3, []) for res in resTasks: xyllTasks[res.id] = {"taskId": res.id} self.cycleDay.Set("xyllTasks", xyllTasks, iWhichCyc=-1) for taskId, taskInfo in xyllTasks.items(): if taskInfo.get("find", 0) or taskInfo.get("finish", 0): continue resp[taskId] = taskInfo return resp def initRchyTasks(self): # 日常活跃任务 rchy_tasks = self.cycleDay.Query("rchyTasks", {}) if not rchy_tasks: # 隔天从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_7, []) for res in resTasks: rchy_tasks[res.id] = {"taskId": res.id} self.cycleDay.Set("rchyTasks", rchy_tasks) for taskId, taskInfo in rchy_tasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.rchy_tasks[taskId] = taskobj def to_RchyTasks_data(self): rchy_tasks = self.cycleDay.Query("rchyTasks", {}) if not rchy_tasks: # 隔天从新初始化 self.initRchyTasks() resp = [] for taskId, taskobj in self.rchy_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def uninitZhoumolibaoTasks(self): # 周末活动 for taskId, taskobj in self.zhoumolibaotasks.items(): taskobj.uninit() def initZhoumolibaoTasks(self): # 周末活动 zhoumolibaotasks = self.cycleWeek.Query("zhoumolibaoTasks", {}) if not zhoumolibaotasks: # 隔周从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_11, []) for res in resTasks: zhoumolibaotasks[res.id] = {"taskId": res.id} self.cycleWeek.Set("zhoumolibaoTasks", zhoumolibaotasks) for taskId, taskInfo in zhoumolibaotasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.zhoumolibaotasks[taskId] = taskobj def to_ZhoumolibaoTasks_data(self): zhoumolibaotasks = self.cycleWeek.Query("zhoumolibaoTasks", {}) if not zhoumolibaotasks: # 隔周从新初始化 resTasks = Game.res_mgr.res_group_task.get(constant.TASK_GROUP_11, []) for res in resTasks: zhoumolibaotasks[res.id] = {"taskId": res.id} self.cycleWeek.Set("zhoumolibaoTasks", zhoumolibaotasks) resp = [] for taskId, taskobj in self.zhoumolibaotasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def uninitRenwudajihuanTasks(self): for taskId, taskobj in self.Renwudajihuantasks.items(): taskobj.uninit() def uninitRenwudajihuan2Tasks(self): for taskId, taskobj in self.Renwudajihuan2tasks.items(): taskobj.uninit() def initRenwudajihuanTasks(self): Renwudajihuantasks = self.cycleDay.Query("RenwudajihuanTasks", {}) today = str(datetime.date.today()) resRenwu = Game.res_mgr.res_renwudajihuan.get(today) if not Renwudajihuantasks and resRenwu: while True: rid = utility.Choice(resRenwu.task1) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["1"] = res.id break while True: rid = utility.Choice(resRenwu.task2) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["2"] = res.id break while True: rid = utility.Choice(resRenwu.task3) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["3"] = res.id break while True: rid = utility.Choice(resRenwu.task4) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["4"] = res.id break while True: rid = utility.Choice(resRenwu.task5) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["5"] = res.id break self.markDirty() for taskId, taskInfo in Renwudajihuantasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.Renwudajihuantasks[taskId] = taskobj def initRenwudajihuan2Tasks(self): Renwudajihuantasks = self.cycleDay.Query("Renwudajihuan2Tasks", {}) today = str(datetime.date.today()) resRenwu = Game.res_mgr.res_renwudajihuan2.get(today) if not Renwudajihuantasks and resRenwu: while True: rid = utility.Choice(resRenwu.task1) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["1"] = res.id break while True: rid = utility.Choice(resRenwu.task2) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["2"] = res.id break while True: rid = utility.Choice(resRenwu.task3) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["3"] = res.id break while True: rid = utility.Choice(resRenwu.task4) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["4"] = res.id break while True: rid = utility.Choice(resRenwu.task5) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["5"] = res.id break self.markDirty() for taskId, taskInfo in Renwudajihuantasks.items(): taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.Renwudajihuan2tasks[taskId] = taskobj def to_RenwudajihuanTasks_data(self): Renwudajihuantasks = self.cycleDay.Query("RenwudajihuanTasks", {}) today = str(datetime.date.today()) resRenwu = Game.res_mgr.res_renwudajihuan.get(today) if not Renwudajihuantasks and resRenwu: while True: rid = utility.Choice(resRenwu.task1) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["1"] = res.id break while True: rid = utility.Choice(resRenwu.task) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.Renwudajihuan2Index["2"] = res.id break while True: rid = utility.Choice(resRenwu.task3) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["3"] = res.id break while True: rid = utility.Choice(resRenwu.task4) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["4"] = res.id break while True: rid = utility.Choice(resRenwu.task5) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("RenwudajihuanTasks", Renwudajihuantasks) self.RenwudajihuanIndex["5"] = res.id break self.markDirty() resp = [] for taskId, taskobj in self.Renwudajihuantasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def to_Renwudajihuan2Tasks_data(self): Renwudajihuantasks = self.cycleDay.Query("Renwudajihuan2Tasks", {}) today = str(datetime.date.today()) resRenwu = Game.res_mgr.res_renwudajihuan2.get(today) if not Renwudajihuantasks and resRenwu: while True: rid = utility.Choice(resRenwu.task1) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["1"] = res.id break while True: rid = utility.Choice(resRenwu.task2) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["2"] = res.id break while True: rid = utility.Choice(resRenwu.task3) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["3"] = res.id break while True: rid = utility.Choice(resRenwu.task4) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["4"] = res.id break while True: rid = utility.Choice(resRenwu.task5) if rid not in Renwudajihuantasks: res = Game.res_mgr.res_task.get(rid, None) Renwudajihuantasks[res.id] = {"taskId": res.id} self.cycleDay.Set("Renwudajihuan2Tasks", Renwudajihuantasks) self.Renwudajihuan2Index["5"] = res.id break self.markDirty() resp = [] for taskId, taskobj in self.Renwudajihuan2tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def addRchyExp(self, num): rchyDayExp = self.GetRchyDayTotal() rchyDayExp += num self.SetRchyDayTotal(rchyDayExp) rchyWeekExp = self.GetRchyWeekTotal() rchyWeekExp += num self.SetRchyWeekTotal(rchyWeekExp) self.owner.safe_pub(msg_define.MSG_RCHY_CHANGE, num) spawn(self.owner.call, "PushRchy", { "dayExp": rchyDayExp, "weekExp": rchyWeekExp }, noresult=True) def initOpenTasks(self, open_task_data): # 功能开放体验任务 for taskInfo in open_task_data: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.open_tasks[taskId] = taskobj def to_OpenTasks_data(self): resp = [] for taskId, taskobj in self.open_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initActivityMonsterTasks(self, activityMonster_tasks): # 神宠超梦活动前置任务 for taskInfo in activityMonster_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.activityMonster_tasks[taskId] = taskobj def to_activityMonsterTasks_data(self): resp = [] for taskId, taskobj in self.activityMonster_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initThanksgivingDayTasks(self, thanksgivingDay_tasks): # 感恩节任务 for taskInfo in thanksgivingDay_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.thanksgivingDay_tasks[taskId] = taskobj def to_thanksgivingDayTasks_data(self): resp = [] for taskId, taskobj in self.thanksgivingDay_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initGongchengTasks(self, gongcheng_tasks): # 全民攻城任务 for taskInfo in gongcheng_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.gongcheng_tasks[taskId] = taskobj def to_gongchengTasks_data(self): resp = [] for taskId, taskobj in self.gongcheng_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def to_specPetTasks_data(self): resp = [] for taskId, taskobj in self.special_pet_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initZhuanpanTasks(self, zhuanpan_tasks): # 转盘任务 for taskInfo in zhuanpan_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.zhuanpan_tasks[taskId] = taskobj def to_zhuanpanTasks_data(self): resp = [] for taskId, taskobj in self.zhuanpan_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initNewKfkhTasks(self, new_kfkh_tasks): #新开服狂欢(和全民攻城一样的功能) for taskInfo in new_kfkh_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.new_kfkh_tasks[taskId] = taskobj def to_newKfkhTasks_data(self): resp = [] for taskId, taskobj in self.new_kfkh_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initLevelContestTasks(self, levelContest_tasks): # 段位赛任务 for taskInfo in levelContest_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.levelContest_tasks[taskId] = taskobj def to_LevelContestTasks_data(self): resp = [] for taskId, taskobj in self.levelContest_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp def initMazeTasks(self, maze_tasks): # 迷宫任务 for taskInfo in maze_tasks: taskId = taskInfo.get("taskId", 0) taskRes, taskobj = CreatTask(taskId, self, taskInfo) if not taskobj: continue self.maze_tasks[taskId] = taskobj def to_MazeTasks_data(self): resp = [] for taskId, taskobj in self.maze_tasks.items(): one = taskobj.to_save_dict() resp.append(one) return resp
class PlayerYabiao(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.cycleDay = CycleDay(self) self.owner = owner # 拥有者 self.time = 0 # self.mul = 1 # self.id = 0 # self.quality = 1 # self.becatch = [] # self.history = {} # self.count = 0 # self.save_cache = {} #存储缓存 # self.owner.sub(msg_define.MSG_ROLE_XLV_UPGRADE, self.event_lv_uprade) def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() #存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["time"] = self.time self.save_cache["mul"] = self.mul self.save_cache["id"] = self.id self.save_cache["quality"] = self.quality self.save_cache["becatch"] = self.becatch self.save_cache["history"] = self.history self.save_cache["count"] = self.count return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.time = data.get("time", 0) self.mul = data.get("mul", 1) self.id = data.get("id", 0) self.quality = data.get("quality", 1) self.becatch = data.get("becatch", []) self.history = data.get("history", {}) self.count = data.get("count", 0) #登录初始化下发数据 def to_init_data(self): init_data = {} init_data["time"] = self.time init_data["mul"] = self.mul init_data["quality"] = self.quality init_data["becatch"] = self.becatch init_data["rob"] = self.getYabiaoRob() init_data["husong"] = self.getYabiaoHusong() return init_data # def roomMsg(self,msgtype,data): # if msgtype=="bye": # spawn(self.owner.call, "pushHusongFinish", {"id":data["id"]}, noresult=True) def uninit(self): # self.owner.unsub(msg_define.MSG_ROLE_XLV_UPGRADE, self.event_lv_uprade) pass def addHistory(self, type, data): self.id += 1 t = time.time() self.history[str(self.id)] = { "type": type, "id": self.id, "time": t, "data": data } self.history.pop(str(self.id - 50), None) self.markDirty() def modfiyHistoryFinish(self, id): # if str(id) in self.history: self.history[str(id)]["type"] = 1 self.markDirty() def getHistory(self): list = [] for kk, vv in self.history.items(): list.append(vv) return list def setTimeFinish(self): self.time = time.time() - 1 self.markDirty() def getYabiaoRob(self): return self.cycleDay.Query("YabiaoRob", 0) def addYabiaoRob(self): v = self.getYabiaoRob() self.setYabiaoRob(v + 1) return v def setYabiaoRob(self, v): self.cycleDay.Set("YabiaoRob", v) def getYabiaoHusong(self): return self.cycleDay.Query("YabiaoHusong", 0) def addYabiaoHusong(self): v = self.getYabiaoHusong() self.setYabiaoHusong(v + 1) return v def setYabiaoHusong(self, v): self.cycleDay.Set("YabiaoHusong", v) def husong(self, mul): self.mul = mul yabiaoTime = Game.res_mgr.res_common.get("yabiaoTime") self.time = time.time() + yabiaoTime.i self.becatch = [] self.addYabiaoHusong() if self.quality == 5: self.count += 1 self.owner.safe_pub(msg_define.MSG_XY_PROTECT) self.markDirty() def getBecatchID(self): yabiaoJiebiaoLimit = Game.res_mgr.res_common.get("yabiaoJiebiaoLimit") retv = [] for x in self.becatch: if x["type"]: if yabiaoJiebiaoLimit.i > len(retv): retv.append(x["id"]) return retv def flashCarMax(self): self.quality = 5 self.markDirty() def flashCar(self): q = 1 kks = {} num = 0 for kk, vv in Game.res_mgr.res_yabiao.items(): vvv = [] for _ in range(vv.weight): vvv.append(num) num += 1 kks[kk] = vvv x = randint(0, num - 1) for kk, vv in kks.items(): if x in vv: q = kk break self.quality = q self.markDirty() def finishYabiao(self): self.time = 0 q = 1 kks = {} num = 0 for kk, vv in Game.res_mgr.res_yabiao.items(): vvv = [] for _ in range(vv.weight): vvv.append(num) num += 1 kks[kk] = vvv x = randint(0, num - 1) for kk, vv in kks.items(): if x in vv: q = kk break self.quality = q self.markDirty() def robHusongCar(self, robid, data, fdata, historydata): pvpRounds = Game.res_mgr.res_common.get("pvpRounds") fightobj = Game.fight_mgr.createFight(constant.FIGHT_TYPE_180) fightobj.SetRounds(pvpRounds.i) mydata = self.owner.GetFightData() rs = fightobj.init_players_by_data(fdata, mydata) if not rs: return {} fightLog = fightobj.doFight() fightResult = fightLog["result"].get("win", 0) self.becatch.append({ "id": robid, "name": fdata["name"], "type": fightResult }) historydata["data"]["quality"] = self.quality if fightResult: if robid not in data["data"]["becatchID"]: data["data"]["becatchID"].append(robid) self.addHistory(0, historydata) days = self.owner.base.GetServerOpenDay() ares = Game.res_mgr.res_activity.get(constant.ACTIVITY_YABIAO) startD = ares.openDayRange[0] from game.mgr.room import get_rpc_room rpc_room = get_rpc_room(startD <= days) if rpc_room: rpc_room.update(1, self.owner.id, data["data"]) else: self.addHistory(4, historydata) self.markDirty() return {"data": data, "fightLog": fightLog} def revengeHusongCar(self, robid, data, fdata, historydata): pvpRounds = Game.res_mgr.res_common.get("pvpRounds") fightobj = Game.fight_mgr.createFight(constant.FIGHT_TYPE_180) fightobj.SetRounds(pvpRounds.i) mydata = self.owner.GetFightData() rs = fightobj.init_players_by_data(fdata, mydata) if not rs: return {} fightLog = fightobj.doFight() fightResult = fightLog["result"].get("win", 0) if fightResult: self.addHistory(5, historydata) return {"data": data, "fightLog": fightLog}
class Guild(utility.DirtyFlag): """公会""" DATA_CLS = ModelGuild @staticmethod def to_create_dict(name, lv, playerInfo): dataDict = { "name": name, "level": lv, "masterId": playerInfo.get("rid", 0), "masterName": playerInfo.get("name", ''), "members": [playerInfo], } return dataDict def __init__(self, guildId): utility.DirtyFlag.__init__(self) self.id = guildId #帮会id self.name = "" #帮会名称 self.color = 0 #颜色 self.mainCity = 0 #主城 self.level = 0 #帮会等级 self.exp = 0 # 帮会资金 self.masterId = 0 #帮主id self.masterName = "" #帮主名称 self.notice = "" #帮会公告 self.members = {} #帮会成员 {pid:info} self.autoEnter = 0 # 是否自动入帮(autoEnter, int) self.autoFa = 0 # 自动入帮战力(autoFa, int) self.logs = [] #帮会记录(time, name, type) self.cycleDay = CycleDay(self) # 天周期数据 #帮会boss self.bossHp = 0 self.data = None self.save_cache = {} # 存储缓存 def getName(self): return self.name def getColor(self): if 0 == self.color: self.color = 1 return self.color def addLog(self, args, logType): now = int(time.time()) guildLog = (now, args, logType) self.logs.append(guildLog) # 1=加入帮会 2=退出帮会 3=被踢 4=升职 5=降职 6=禅让 self.logs = self.logs[:20] def addExp(self, add): self.exp += add #判断是否升级 guildlvRes = Game.res_mgr.res_guildlv.get(self.level) nextRes = Game.res_mgr.res_guildlv.get(self.level + 1) if nextRes and guildlvRes and self.exp >= guildlvRes.fund: self.exp -= guildlvRes.fund self.level += 1 self.markDirty() return self.exp, self.level def GetLevel(self): return self.level def SetName(self, name): self.name = name self.markDirty() def SetColor(self, color): self.color = color self.markDirty() def SetNotice(self, notice): self.notice = notice self.markDirty() # 申请列表 {pid:info} 每日清理 def GetApplyDict(self): return self.cycleDay.Query("guildApplyDict", {}) def SetApplyDict(self, applyDict): self.cycleDay.Set("guildApplyDict", applyDict) # 帮会上香日志 每日清理 def GetSXLogs(self): return self.cycleDay.Query("guildSXLogs", []) def SetSXLogs(self, logs): self.cycleDay.Set("guildSXLogs", logs) #帮会香火值进度 每日清0 def GetSXProgress(self): return self.cycleDay.Query("guildSXProgress", 0) def SetSXProgress(self, num): self.cycleDay.Set("guildSXProgress", num) #帮会上香次数 每日清0 def GetSXNum(self): return self.cycleDay.Query("guildSXNum", 0) def SetSXNum(self, num): self.cycleDay.Set("guildSXNum", num) def markDirty(self): utility.DirtyFlag.markDirty(self) self.data.modify() def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["id"] = self.id self.save_cache["name"] = self.name self.save_cache["color"] = self.color self.save_cache["mainCity"] = self.mainCity self.save_cache["level"] = self.level self.save_cache["exp"] = self.exp self.save_cache["masterId"] = self.masterId self.save_cache["masterName"] = self.masterName self.save_cache["notice"] = self.notice self.save_cache["autoEnter"] = self.autoEnter self.save_cache["autoFa"] = self.autoFa self.save_cache["logs"] = self.logs self.save_cache["members"] = [] for member in self.members.values(): self.save_cache["members"].append(member.to_save_dict()) self.save_cache['clcleDayBytes'] = self.cycleDay.to_save_bytes( ) # 天周期数据 return self.save_cache def load_from_dict(self, data): self.id = data.get("id", 0) # 帮会id self.name = data.get("name", "") # 帮会名称 self.color = data.get("color", 0) # color self.mainCity = data.get("mainCity", 0) # mainCity self.level = data.get("level", 0) # 帮会等级 self.exp = data.get("exp", 0) # 帮会资金 self.masterId = data.get("masterId", 0) # 帮主id self.masterName = data.get("masterName", "") # 帮主名称 self.notice = data.get("notice", "") # 帮会公告 self.autoEnter = data.get("autoEnter", 0) # 是否自动入帮(autoEnter, int) self.autoFa = data.get("autoFa", 0) # 自动入帮战力(autoFa, int) self.logs = data.get("logs", []) # 帮会记录(time, name, type) members = data.get("members", []) for one in members: member = GuildMember(self, one) self.members[member.pid] = member # 帮会成员 {pid:info} def save(self, forced=False, no_let=False): self.data.save(Game.store, forced=forced, no_let=no_let) def load(self): self.data = self.DATA_CLS.load(Game.store, self.id) if not self.data: return False else: self.load_from_dict(self.data.to_init_dict()) self.cycleDay.load_from_dict(self.data.clcleDayBytes) self.data.setOwner(self) return True def deleteGuild(self): self.data.delete(Game.store) def to_openUI_dict(self): resp = {} resp["id"] = self.id resp["notice"] = self.notice resp["bzName"] = self.masterName resp["exp"] = self.exp resp["num"] = len(self.members) return resp def to_show_dict(self): resp = {} resp["guildId"] = self.id resp["name"] = self.name resp["color"] = self.color resp["mainCity"] = self.mainCity resp["bzName"] = self.masterName resp["guildLv"] = self.level resp["num"] = len(self.members) resp["fa"] = self.autoFa return resp def update_playerInfo(self, playerInfo): pid = playerInfo.get("rid", 0) member = self.members.get(pid) if member: member.update_playerInfo(playerInfo) #做帮主选举检测 self.choiceMaster() # 让位 # 1)帮主3天(配置吧)不上线 # 会让位给在线的副帮主(战力最高的) # 如果都不在线,则让给最近一次上线的副帮主 # # 如果没有副帮主,让给在线战力最高的玩家 # 如果都不在线,则让给最近一次上线的玩家 def choiceMaster(self): oldmaster = self.members.get(self.masterId) if oldmaster.time <= 0: return iChoice = 0 now = int(time.time()) if now - oldmaster.time >= 3600 * 24 * 2: iChoice = 1 if not iChoice: return #重新选举 newmaster = None deputy = None normal = None for member in self.members.values(): if member.GetJob == constant.GUILD_MEMBER_TYPE_1: newmaster = member elif member.GetJob == constant.GUILD_MEMBER_TYPE_2: if not deputy: deputy = member else: if deputy.time == 0 and member.time == 0: deputy = deputy if deputy.fa >= member.fa else member else: if member.time == 0: deputy = member else: deputy = deputy if deputy.time >= member.time else member else: if not normal: normal = member else: if normal.time == 0 and member.time == 0: normal = normal if normal.fa >= member.fa else member if member.time == 0: normal = member else: normal = normal if normal.time >= member.time else member if deputy: newmaster = deputy else: if normal: newmaster = normal oldmaster.SetJob(constant.GUILD_MEMBER_TYPE_3) newmaster.SetJob(constant.GUILD_MEMBER_TYPE_1) self.masterId = newmaster.pid self.masterName = newmaster.name self.markDirty() def exitGuild(self, pid): # 2)帮主需要让位才出可以退出帮会 member = self.members.get(pid) if not member: return 0, errcode.EC_NO_GUILD if len(self.members) > 1: if member.GetJob == constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_MASTER_EXIT self.members.pop(pid) if len(self.members) <= 0: Game.rpc_guild_mgr.deleteGuild(self.id) # 记录帮会日志 self.addLog((member.name, ), constant.GUILD_LOG_TYPE_2) self.markDirty() return 1, None def GetGiveupCity(self): return self.cycleDay.Query("GiveupCity", 0) def SetGiveupCity(self): self.cycleDay.Set("GiveupCity", self.GetGiveupCity() + 1) def GetWarCity(self): return self.cycleDay.Query("WarCity", 0) def SetWarCity(self): self.cycleDay.Set("WarCity", self.GetWarCity() + 1) #玩家登陆要下发的数据 def to_init_data(self, pid): init_data = {} init_data["guildId"] = self.id init_data["name"] = self.name init_data["color"] = self.color init_data["mainCity"] = self.mainCity init_data["lv"] = self.level member = self.members.get(pid) if member: red = 1 if member.GetJob() != constant.GUILD_MEMBER_TYPE_3 and len( self.GetApplyDict()) else 0 job = member.GetJob() bgCoin = member.GetBgCoin() else: red = 0 job = constant.GUILD_MEMBER_TYPE_3 bgCoin = 0 init_data["red"] = red init_data["job"] = job init_data["bgCoin"] = bgCoin init_data["sxBar"] = self.GetSXProgress() init_data["sxNum"] = self.GetSXNum() init_data["GiveupCity"] = self.GetGiveupCity() init_data["WarCity"] = self.GetWarCity() return init_data #申请加入帮会 0=取消 1=申请 def enterGuild(self, type, playerInfo): guildlvRes = Game.res_mgr.res_guildlv.get(self.level) if not guildlvRes: return 0, errcode.EC_NORES if len(self.members) >= guildlvRes.peoplenum: return 0, errcode.EC_GUILD_MEMBER_MAX pid = playerInfo.get("rid", 0) applyDict = self.GetApplyDict() if type == 1: if pid in applyDict: return 0, errcode.EC_GUILD_HAS_APPLY # 如果有设置 自动入帮战力,自动入帮 fa = playerInfo.get("fa", 0) if self.autoEnter and fa >= self.autoFa: self.addMember(playerInfo) from game.mgr.player import get_rpc_player rpc_player = get_rpc_player(pid) rpc_player.sendEnterGuild(self.id, _no_result=1) else: applyDict[pid] = playerInfo self.SetApplyDict(applyDict) self.markDirty() # 推送给帮会管理 guildInfo = {"red": 1} from game.mgr.player import get_rpc_player for member in self.members.values(): if member.GetJob( ) != constant.GUILD_MEMBER_TYPE_3 and member.time == 0: rpc_player = get_rpc_player(member.pid, offline=False) if rpc_player: rpc_player.sendGuildRed(guildInfo, _no_result=1) else: if pid not in applyDict: return 0, errcode.EC_GUILD_NOT_APPLY applyDict.pop(pid) self.SetApplyDict(applyDict) self.markDirty() return 1, None def addMember(self, playerInfo): member = GuildMember(self, playerInfo) self.members[member.pid] = member # 帮会成员 {pid:info} member.SetJob(constant.GUILD_MEMBER_TYPE_3) #成员 #记录帮会日志 name = playerInfo.get("name", "") self.addLog((name, ), constant.GUILD_LOG_TYPE_1) self.markDirty() def respGuild(self, myId, pid, type): member = self.members.get(myId) if not member: return 0, errcode.EC_NO_GUILD if member.GetJob() == constant.GUILD_MEMBER_TYPE_3: return 0, errcode.EC_GUILD_OPER_LIMIT applyDict = self.GetApplyDict() if pid not in applyDict: return 0, errcode.EC_GUILD_NOT_APPLY playerInfo = applyDict.pop(pid) self.SetApplyDict(applyDict) if type == 1: guildlvRes = Game.res_mgr.res_guildlv.get(self.level) if not guildlvRes: return 0, errcode.EC_NORES #人数满员 if len(self.members) >= guildlvRes.peoplenum: return 0, errcode.EC_GUILD_MEMBER_MAX #已经加入公会 from game.mgr.player import get_rpc_player rpc_player = get_rpc_player(pid) if rpc_player.isInGuild(): return 0, errcode.EC_GUILD_HAS_JOIN self.addMember(playerInfo) rpc_player.sendEnterGuild(self.id, _no_result=1) # 推送给帮会管理 guildInfo = {"red": 1 if len(self.GetApplyDict()) else 0} for member in self.members.values(): if member.GetJob( ) != constant.GUILD_MEMBER_TYPE_3 and member.time == 0: rpc_player = get_rpc_player(member.pid, offline=False) if rpc_player: rpc_player.sendGuildRed(guildInfo, _no_result=1) self.markDirty() return 1, len(self.members) def guildOper(self, myId, pid, type): # 1=禅让 2=升职 3=降职 4=踢出 if type not in (constant.GUILD_OPER_TYPE_1, constant.GUILD_OPER_TYPE_2, constant.GUILD_OPER_TYPE_3, constant.GUILD_OPER_TYPE_4): return 0, errcode.EC_GUILD_OPER_LIMIT my = self.members.get(myId) member = self.members.get(pid) if not my or not member: return 0, errcode.EC_NO_GUILD if my.GetJob() == constant.GUILD_MEMBER_TYPE_3: return 0, errcode.EC_GUILD_OPER_LIMIT if type in (constant.GUILD_OPER_TYPE_1, constant.GUILD_OPER_TYPE_2, constant.GUILD_OPER_TYPE_3)\ and my.GetJob() != constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_OPER_LIMIT if type == constant.GUILD_OPER_TYPE_4 and my.GetJob() not in ( constant.GUILD_MEMBER_TYPE_1, constant.GUILD_MEMBER_TYPE_2): return 0, errcode.EC_GUILD_OPER_LIMIT if type == constant.GUILD_OPER_TYPE_4 and member.GetJob( ) != constant.GUILD_MEMBER_TYPE_3: return 0, errcode.EC_GUILD_OPER_LIMIT if type == constant.GUILD_OPER_TYPE_2: guildlvRes = Game.res_mgr.res_guildlv.get(self.level) if not guildlvRes: return 0, errcode.EC_NORES #副帮主人数限制 iNum = 0 for one in self.members.values(): if one.GetJob() == constant.GUILD_MEMBER_TYPE_2: iNum += 1 if iNum >= guildlvRes.deputybossnum: return 0, errcode.EC_GUILD_DEPUTY_MAX_NUM logType = 0 # 1=禅让 if type == constant.GUILD_OPER_TYPE_1: self.masterId = member.pid self.masterName = member.name my.SetJob(constant.GUILD_MEMBER_TYPE_3) member.SetJob(constant.GUILD_MEMBER_TYPE_1) logType = constant.GUILD_LOG_TYPE_6 elif type == constant.GUILD_OPER_TYPE_2: #2=升职 member.SetJob(constant.GUILD_MEMBER_TYPE_2) logType = constant.GUILD_LOG_TYPE_4 elif type == constant.GUILD_OPER_TYPE_3: #3=降职 member.SetJob(constant.GUILD_MEMBER_TYPE_3) logType = constant.GUILD_LOG_TYPE_5 elif type == constant.GUILD_OPER_TYPE_4: #4=踢出 self.members.pop(pid) logType = constant.GUILD_LOG_TYPE_3 #同步 guildInfo = {} guildInfo["red"] = 1 if member.GetJob( ) != constant.GUILD_MEMBER_TYPE_3 and len(self.GetApplyDict()) else 0 guildInfo["job"] = member.GetJob() from game.mgr.player import get_rpc_player rpc_player = get_rpc_player(pid) rpc_player.sendGuildOperPush(type, guildInfo, _no_result=1) if type == constant.GUILD_OPER_TYPE_1: myGuildInfo = {} myGuildInfo["red"] = 1 if my.GetJob( ) != constant.GUILD_MEMBER_TYPE_3 and len( self.GetApplyDict()) else 0 myGuildInfo["job"] = my.GetJob() from game.mgr.player import get_rpc_player my_rpc_player = get_rpc_player(myId) my_rpc_player.sendGuildOperPush(type, myGuildInfo, _no_result=1) # 记录帮会日志 if logType: if logType == constant.GUILD_LOG_TYPE_3: self.addLog((member.name, my.name), logType) else: self.addLog((member.name, ), logType) self.markDirty() return 1, len(self.members) def changeName(self, pid, name): member = self.members.get(pid) if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_OPER_LIMIT self.SetName(name) return 1, None def GiveupCity(self): # member = self.members.get(pid) # if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: # return 0, errcode.EC_GUILD_OPER_LIMIT self.SetGiveupCity() return 1, None def WarCity(self): # member = self.members.get(pid) # if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: # return 0, errcode.EC_GUILD_OPER_LIMIT self.SetWarCity() return 1, None def changeColor(self, pid, color): member = self.members.get(pid) if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_OPER_LIMIT self.SetColor(color) return 1, None def fixNotice(self, pid, notice): member = self.members.get(pid) if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_OPER_LIMIT self.SetNotice(notice) return 1, None def Add_BgCoin(self, pid, num): member = self.members.get(pid) if not member: return bgCoin = member.GetBgCoin() bgCoin += num member.SetBgCoin(bgCoin) def getLogs(self): return self.logs def getMembers(self): resp = [] for member in self.members.values(): resp.append(member.to_save_dict()) return resp def getApplyData(self): applyDict = self.GetApplyDict() resp = { "enterList": list(applyDict.values()), "autoEnter": self.autoEnter, "autoFa": self.autoFa, } return resp def fixAutoEnter(self, pid, autoEnter, autoFa): member = self.members.get(pid) if member.GetJob() != constant.GUILD_MEMBER_TYPE_1: return 0, errcode.EC_GUILD_OPER_LIMIT self.autoEnter = autoEnter self.autoFa = autoFa self.markDirty() return 1, None def getSxList(self): return self.GetSXLogs() def guildSx(self, pid, sxId): member = self.members.get(pid) if not member: return 0, errcode.EC_NO_GUILD guildlvRes = Game.res_mgr.res_guildlv.get(self.level) if not guildlvRes: return 0, errcode.EC_NORES sxRes = Game.res_mgr.res_guildSx.get(sxId) if not sxRes: return 0, errcode.EC_NORES iSxNum = self.GetSXNum() if iSxNum >= guildlvRes.guildSxNum: return 0, errcode.EC_GUILD_SX_MAX_NUM #增加上香次数 iSxNum += 1 self.SetSXNum(iSxNum) #增加香火值 iProgress = self.GetSXProgress() iProgress += sxRes.addNum if iProgress > guildlvRes.sxMaxNum: iProgress = guildlvRes.sxMaxNum self.SetSXProgress(iProgress) #增加帮会资金 self.addExp(sxRes.addExp) #上香日志 logs = self.GetSXLogs() now = int(time.time()) logs.append({"time": now, "name": member.name, "id": sxId}) self.SetSXLogs(logs) self.markDirty() #同步所有人香火值 from game.mgr.player import get_rpc_player guildInfo = { "sxBar": iProgress, "sxNum": iSxNum, } for pid, member in self.members.items(): if member.time: continue rpc_player = get_rpc_player(pid) if rpc_player: rpc_player.sendGuildSxPush(guildInfo, _no_result=1) return 1, (iProgress, iSxNum) def GetSxInfo(self): resp = { "sxNum": self.GetSXNum(), "sxBar": self.GetSXProgress(), } return resp def enterGuildScene(self): keys = list(self.members.keys()) iLen = len(keys) if iLen > 3: iLen = 3 keys = random.sample(keys, iLen) return keys def broadcast_gongcheng_atkwin(self): from game.mgr.player import get_rpc_player for pid in self.members.keys(): rpc_player = get_rpc_player(pid) if rpc_player: rpc_player.broadcast_gongcheng_atkwin(_no_result=1) def broadcast_gongcheng_defwin(self): from game.mgr.player import get_rpc_player for pid in self.members.keys(): rpc_player = get_rpc_player(pid) if rpc_player: rpc_player.broadcast_gongcheng_defwin(_no_result=1)
class PlayerDaylyPVP(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.cycleDay = CycleDay(self) self.cycleWeek = CycleWeek(self) self.challengeNum = 0 #挑战次数 self.lastRecoverTime = 0 #最后一次恢复时间 self.TotalWin = 0 #历史总战胜次数 self.TotalFightNum = 0 #历史总挑战次数 self.winMax = 0 #历史最大连胜次数 self.revengeNum = 0 #历史复仇次数 self.beChallengeData = [] #复仇列表 self.save_cache = {} def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() def SetTodayWinStreak(self, num): """今日已连胜""" self.cycleDay.Set("todayDaylyPVPWinStreak", num) if num > self.winMax: self.winMax = num self.markDirty() def GetTodayWinStreak(self): """今日已连胜""" return self.cycleDay.Query("todayDaylyPVPWinStreak", 0) def SetTodayRevengeNum(self, num): """今日已复仇次数""" self.cycleDay.Set("todayDaylyPVPRevengeNum", num) def GetTodayRevengeNum(self): """今日已复仇次数""" return self.cycleDay.Query("todayDaylyPVPRevengeNum", 0) def SetWeekWin(self, num): """本周胜利次数""" self.cycleWeek.Set("DaylyPVPWeekWin", num) def GetWeekWin(self): """本周胜利次数""" return self.cycleWeek.Query("DaylyPVPWeekWin", 0) def GetLastWeekWin(self): """上周胜利次数""" return self.cycleWeek.Query("DaylyPVPWeekWin", 0, iWhichCyc=-1) def SetHasGetWeekRankReward(self, rs): """周排行榜奖励是否已领取""" self.cycleWeek.Set("DaylyPVPHasGetWeekRankReward", rs) def GetHasGetWeekRankReward(self): """周排行榜奖励是否已领取""" return self.cycleWeek.Query("DaylyPVPHasGetWeekRankReward", 0) def SetTodayBuyChallengeNum(self, num): """今日已购买挑战次数""" self.cycleDay.Set("todayDaylyPVPBuyChallengeNum", num) def GetTodayBuyChallengeNum(self): """今日已购买挑战次数""" return self.cycleDay.Query("todayDaylyPVPBuyChallengeNum", 0) def SetTodayBeChallengeNum(self, num): """今日被挑战次数""" self.cycleDay.Set("todayDaylyPVPBeChallengeNum", num) def GetTodayBeChallengeNum(self): """今日被挑战次数""" return self.cycleDay.Query("todayDaylyPVPBeChallengeNum", 0) def SetTodayGetRewardList(self, data): """今日已领取连胜奖励""" self.cycleDay.Set("todayDaylyPVPGetRewardList", data) def GetTodayGetRewardList(self): """今日已领取连胜奖励""" return self.cycleDay.Query("todayDaylyPVPGetRewardList", []) def SetTodayChallengeData(self, data): """今日挑战列表""" self.cycleDay.Set("todayDaylyPVPChallengeData", data) def GetTodayChallengeData(self): """今日挑战列表""" return self.cycleDay.Query("todayDaylyPVPChallengeData", []) def SetTodayDoChallengeNum(self, num): """当天发起挑战次数""" self.cycleDay.Set("todayDaylyPVPDoChallengeNum", num) def GetTodayDoChallengeNum(self): """当天发起挑战次数""" return self.cycleDay.Query("todayDaylyPVPDoChallengeNum", 0) def SetTodayChallengeWinNum(self, num): """当天击败对手 / 人""" self.cycleDay.Set("todayDaylyPVPChallengeWinNum", num) def GetTodayChallengeWinNum(self): """当天击败对手 / 人""" return self.cycleDay.Query("todayDaylyPVPChallengeWinNum", 0) def SetTodayChallengeMaxWin(self, num): """当天最高连胜""" self.cycleDay.Set("todayDaylyPVPChallengeMaxWin", num) def GetTodayChallengeMaxWin(self): """当天最高连胜""" return self.cycleDay.Query("todayDaylyPVPChallengeMaxWin", 0) def SetTodayRevengeWin(self, num): """当天复仇成功次数""" self.cycleDay.Set("todayDaylyPVPRevengeWin", num) def GetTodayRevengeWin(self): """当天复仇成功次数""" return self.cycleDay.Query("todayDaylyPVPRevengeWin", 0) def SetLastWeekRank(self, rank): """上周跨服排名名次""" self.cycleDay.Set("todayDaylyPVPLastWeekRank", rank) def GetLastWeekRank(self): """上周跨服排名名次""" return self.cycleDay.Query("todayDaylyPVPLastWeekRank", 0) # 存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() self.save_cache["cycleWeek"] = self.cycleWeek.to_save_bytes() self.save_cache["challengeNum"] = self.challengeNum self.save_cache["lastRecoverTime"] = self.lastRecoverTime self.save_cache["TotalWin"] = self.TotalWin self.save_cache["TotalFightNum"] = self.TotalFightNum self.save_cache["beChallengeData"] = pickle.dumps(self.beChallengeData) self.save_cache["winMax"] = self.winMax self.save_cache["revengeNum"] = self.revengeNum return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) self.cycleWeek.load_from_dict(data.get("cycleWeek", "")) numRes = Game.res_mgr.res_common.get("pvpChallengeNumMax") self.challengeNum = data.get("challengeNum", numRes.i) # 挑战次数 初始3次 self.lastRecoverTime = data.get("lastRecoverTime", 0) # 最后一次恢复时间 self.TotalWin = data.get("TotalWin", 0) # 历史总战胜次数 self.TotalFightNum = data.get("TotalFightNum", 0) # 历史总挑战次数 self.winMax = data.get("winMax", 0) # 历史最大连胜次数 self.revengeNum = data.get("revengeNum", 0) # 历史复仇次数 try: self.beChallengeData = data.get("beChallengeData", []) if self.beChallengeData: self.beChallengeData = pickle.loads(self.beChallengeData) except: self.beChallengeData = [] #判断离线时长 cdRes = Game.res_mgr.res_common.get("pvpChallengeNumCD") now = int(time.time()) add = int((now - self.lastRecoverTime)/cdRes.i) self.challengeNum += add if self.challengeNum > numRes.i: self.challengeNum = numRes.i #设定最后一次恢复时间 nowhour = gtime.current_hour() refresh = (0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22) last = 0 for hour in refresh: if nowhour < hour: break last = hour #今日凌晨时间 zero_day_time = int(gtime.zero_day_time()) self.lastRecoverTime = zero_day_time + 3600*last nextRecoverTime = self.lastRecoverTime + 7200 self.recover_task = spawn_later(nextRecoverTime-now, self.recoverChallengeNum) def recoverChallengeNum(self): if self.recover_task: self.recover_task.kill(block=False) self.recover_task = None numRes = Game.res_mgr.res_common.get("pvpChallengeNumMax") self.challengeNum += 1 if self.challengeNum > numRes.i: self.challengeNum = numRes.i self.lastRecoverTime = int(time.time()) self.recover_task = spawn_later(7200, self.recoverChallengeNum) self.markDirty() def uninit(self): if self.recover_task: self.recover_task.kill(block=False) self.recover_task = None #登录初始化下发数据 def to_init_data(self): init_data = {} spawn(self.registerRobotData, config.serverNo, self.owner.GetFightData(constant.BATTLE_ARRAY_TYPE_NORMAL)) # 用额外的协程,避免卡死 spawn(self.sendWeekRankData) # 用额外的协程,避免卡死 return init_data #零点更新的数据 def to_wee_hour_data(self): init_data = {} return init_data def registerRobotData(self, serverNo, fightData): proxy = get_rpc_daylyPVP() if proxy: proxy.registerRobotData(serverNo, app.addr, fightData, _no_result=True) def no2id(self, no): serverNoClient = 0 resId = Game.res_mgr.res_no2id_kuafuMap.get(no) if resId: res = Game.res_mgr.res_kuafuMap.get(resId) if res: serverNoClient = res.serverNoClient return serverNoClient def getDaylyPVPData(self, exclude=[]): challengeData = self.GetTodayChallengeData() if challengeData: return challengeData proxy = get_rpc_daylyPVP() if proxy: challengeData = proxy.matchPvpData(self.owner.id, self.owner.base.fa, exclude, self.owner.base.lv) if challengeData: upData, curData, lowData = challengeData if upData: upData["sendNotice"] = 1 self.SetTodayChallengeData(challengeData) else: fightData = self.owner.GetFightData(constant.BATTLE_ARRAY_TYPE_NORMAL) randomNames = utility.getRandomName(3) fightData["name"] = randomNames[0] upData = { "serverNo": config.serverNo, "addr": app.addr, "fightData": fightData, "isRobot": 1, } fightData["name"] = randomNames[1] curData = { "serverNo": config.serverNo, "addr": app.addr, "fightData": fightData, "isRobot": 1, } fightData["name"] = randomNames[2] lowData = { "serverNo": config.serverNo, "addr": app.addr, "fightData": fightData, "isRobot": 1, } self.SetTodayChallengeData([upData, curData, lowData]) return challengeData def addBeChallengeRobotData(self): proxy = get_rpc_daylyPVP(force=1) if proxy: robotData = proxy.matchCustomData(1, exclude=[self.owner.id], lv=self.owner.base.lv) if robotData: beChallengeData = self.GetBeChallengeData() robotData["fightTime"] = int(time.time()) robotData["isRobot"] = 1 robotData["isGuide"] = 1 robotData["isWin"] = 1 beChallengeData.insert(0, robotData) self.SetBeChallengeData(beChallengeData) else: fightData = self.owner.GetFightData(constant.BATTLE_ARRAY_TYPE_NORMAL) randomNames = utility.getRandomName(3) fightData["name"] = randomNames[0] robotData = { "serverNo": config.serverNo, "addr": app.addr, "fightData": fightData, "isRobot": 1, } beChallengeData = self.GetBeChallengeData() robotData["fightTime"] = int(time.time()) robotData["isRobot"] = 1 robotData["isGuide"] = 1 robotData["isWin"] = 1 beChallengeData.insert(0, robotData) self.SetBeChallengeData(beChallengeData) def SetBeChallengeData(self, data): """被挑战列表""" self.beChallengeData = data self.markDirty() def GetBeChallengeData(self): """被挑战列表""" resp = [] # 只保留一天的 now = int(time.time()) for oneData in self.beChallengeData: fightTime = oneData.get("fightTime", 0) if now - fightTime < 3600*24: resp.append(oneData) self.SetBeChallengeData(resp) return self.beChallengeData def SetRevengeNum(self, num): # 历史复仇次数 self.revengeNum = num self.markDirty() def GetRevengeNum(self): # 历史复仇次数 return self.revengeNum def SetChallengeNum(self, num): self.challengeNum = num self.markDirty() def GetChallengeNum(self): return self.challengeNum def SetTotalWin(self, num): self.TotalWin = num self.markDirty() def GetTotalWin(self): return self.TotalWin def SetTotalFightNum(self, num): self.TotalFightNum = num self.markDirty() def GetTotalFightNum(self): return self.TotalFightNum def checkRefresh(self): reset = 1 exclude = [] for oneData in self.getDaylyPVPData(): if not oneData: continue isWin = oneData.get("isWin", 0) fightData = oneData.get("fightData", {}) pid = fightData.get("pid", 0) exclude.append(pid) if not isWin: reset = 0 break if reset: self.SetTodayChallengeData([]) self.getDaylyPVPData(exclude) def sendWeekRankData(self): proxy = get_rpc_daylyPVP() if proxy: data = { "pid": self.owner.id, "name": self.owner.name, "weekWin": self.GetWeekWin(), } proxy.sendWeekRankData(config.serverNo, app.addr, data, _no_result=True) def getDaylyPVPRankData(self): proxy = get_rpc_daylyPVP() if proxy: return proxy.getDaylyPVPRankData() def packRivalList(self): days = self.owner.base.GetServerOpenDay() ares = Game.res_mgr.res_activity.get(constant.ACTIVITY_DAYLY_PVP) startD = ares.openDayRange[0] kf = 0 if startD <= days: kf = 1 rivalList = [] for oneData in self.getDaylyPVPData(): if not oneData: continue fightData = oneData.get("fightData", {}) isWin = oneData.get("isWin", 0) name = fightData.get("name", '') if kf: serverNo = oneData.get("serverNo", 0) sid = self.no2id(serverNo) name = name + ".S" + str(sid) rival = { "pid": fightData.get("pid", 0), "name": name, "sex": fightData.get("sex", 0), "vipLv": fightData.get("vipLv", 0), "lv": fightData.get("lv", 0), "fa": fightData.get("fa", 0), "isWin": isWin, "portrait": fightData.get("portrait", 0), "headframe": fightData.get("headframe", 0), } rivalList.append(rival) return rivalList def packRevengeList(self): days = self.owner.base.GetServerOpenDay() ares = Game.res_mgr.res_activity.get(constant.ACTIVITY_DAYLY_PVP) startD = ares.openDayRange[0] kf = 0 if startD <= days: kf = 1 revengeList = [] for oneData in self.GetBeChallengeData(): if not oneData: continue fightData = oneData.get("fightData", {}) name = fightData.get("name", '') if kf: serverNo = oneData.get("serverNo", 0) sid = self.no2id(serverNo) name = name + ".S" + str(sid) revenge = { "pid": fightData.get("pid", 0), "name": name, "sex": fightData.get("sex", 0), "vipLv": fightData.get("vipLv", 0), "lv": fightData.get("lv", 0), "fa": fightData.get("fa", 0), "isRevenge": oneData.get("isRevenge", 0), "revengeWin": oneData.get("revengeWin", 0), "fightTime": oneData.get("fightTime", 0), "isWin": oneData.get("isWin", 0), "isDouble": oneData.get("isDouble", 0), "isGuide": oneData.get("isGuide", 0), "portrait": fightData.get("portrait", 0), "headframe": fightData.get("headframe", 0), } revengeList.append(revenge) return revengeList
class PlayerTotem(utility.DirtyFlag): def __init__(self, owner): utility.DirtyFlag.__init__(self) self.owner = owner # 拥有者 self.actList = {} #{图腾pos:obj} self.cycleDay = CycleDay(self) self.save_cache = {} #存储缓存 def markDirty(self): utility.DirtyFlag.markDirty(self) if self.owner: self.owner.markDirty() # 存库数据 def to_save_dict(self, forced=False): if self.isDirty() or forced or not self.save_cache: self.save_cache = {} self.save_cache["actList"] = [] for totem in self.actList.values(): self.save_cache["actList"].append( totem.to_save_dict(forced=forced)) self.save_cache["cycleDay"] = self.cycleDay.to_save_bytes() return self.save_cache #读库数据初始化 def load_from_dict(self, data): self.cycleDay.load_from_dict(data.get("cycleDay", "")) totemData = data.get("actList", []) for one in totemData: res = Game.res_mgr.res_poslv_totem.get((one["pos"], one["lv"]), None) if res: totem = Totem(res, data=one, owner=self.owner) self.actList[totem.pos] = totem else: Game.glog.log2File("TotemLoadNotFindError", "%s|%s" % (self.owner.id, one)) #登录初始化下发数据 def to_init_data(self): init_data = {} init_data["actList"] = [] for totem in self.actList.values(): init_data["actList"].append(totem.to_init_data()) return init_data def to_wee_hour_data(self): init_data = {} init_data["actList"] = [] for totem in self.actList.values(): init_data["actList"].append(totem.to_wee_hour_data()) return init_data def recalAttr(self): for eleType in constant.ALL_ELE_TYPE: total = {} for obj in self.actList.values(): # {图腾pos:obj} res = Game.res_mgr.res_poslv_totem.get((obj.pos, obj.lv), None) if res and res.ele == eleType: for name, iNum in res.attr1.items(): total[name] = total.get(name, 0) for name, iNum in res.attr2.items(): total[name] = total.get(name, 0) if total: self.owner.attr.addAttr( total, constant.PKM2_FA_TYPE_9, constant.MAP_ELETYPE_ATTR_CONTAINER.get(eleType)) def uninit(self): pass def actTotem(self, res): if res.pos in self.actList: return False totem = Totem(res, owner=self.owner) totem.setBjResId(1) self.actList[res.pos] = totem self.owner.attr.addAttr( res.attr1, constant.PKM2_FA_TYPE_9, constant.MAP_ELETYPE_ATTR_CONTAINER.get(res.ele)) self.owner.attr.addAttr( res.attr2, constant.PKM2_FA_TYPE_9, constant.MAP_ELETYPE_ATTR_CONTAINER.get(res.ele)) totem.markDirty() # 抛事件 self.owner.safe_pub(msg_define.MSG_TOTEM_ACT, res.pos) return True def getTotem(self, pos): return self.actList.get(pos, None) def getActNum(self): return len(self.actList) def getMaxLv(self): iMax = 0 for totem in self.actList.values(): if totem.lv > iMax: iMax = totem.lv return iMax