def __init__(self, items = {}): DisplayDriver.eventManager.bind(KEYDOWN, self.takeInput) DisplayDriver.engine.graphics.setBackground([51,204,51]) itemHandler.init(False) if not items: self.items = {} items = itemHandler.getItemsSorted(0, False) for i in range(random.randint(3,15)): item = random.choice(items) items.remove(item) self.items[item] = random.randint(1,3) else: self.items = items self.taskId = None self.generate() self.start()
def callback(dbSet): #异步载入数据库,需要验证session是否仍然有效,有可能下线了 db = dbSet['player'] if session.isValid() == False or session.player: return False if len(db.result) == 0: ffext.dump('no this role') return False else: player = PlayerModel.Player(db.result[0]) #ffext.dump(dbSet) session.setPlayer(player) if x != 0 and y != 0: player.x = x player.y = y #载入数据 ffext.dump('load player =%s' % (session.player.name)) session.verify_id(session.player.uid) dbTask = dbSet['task'] dbitem = dbSet['item'] dbFriend = dbSet['friend'] dbEnemy = dbSet['enemy'] dbGuild = dbSet['guild'] dbPet = dbSet['pet'] dbMail = dbSet['mail'] dbLoginAct = dbSet['login_activity'] if dbTask.isOk(): player.taskCtrl.fromData(dbTask.result) if dbitem.isOk(): player.itemCtrl.fromData(dbitem.result) #TaskHandler.processQueryTask(session) #初始化好友信息、仇人信息,屏蔽信息 if dbFriend.isOk(): player.friendCtrl.fromDataFriend(dbFriend.result) if dbEnemy.isOk(): player.friendCtrl.fromDataEnemy(dbEnemy.result) #初始化行会信息 if dbGuild.isOk(): player.guildCtrl.fromData(dbGuild.result) player.petCtrl.fromData(dbPet.result) if dbMail.isOk(): player.mailCtrl.fromData(dbMail.result) if dbLoginAct.isOk(): player.loginActCtrl.fromData(dbLoginAct.result) # 发送属性数据 PlayerModel.sendPropUpdateMsg(player) #发消息通知,通知上线 tmpReq = MsgDef.EnterMapReq(player.mapname, player.x, player.y) processEnterMapReq(session, tmpReq, True) #发送技能数据 SkillHandler.processQuerySkill(session) #发送包裹数据 ItemHandler.processQueryPkg(session) #发送装备数据 ItemHandler.processQueryEquip(session) #发送任务数据 TaskHandler.processQueryTask(session) #发送好友数据 FriendHandler.processListFriend( session, MsgDef.FriendListMsgReq(MsgDef.FriendListClientCmd.GET_FRIENDLIST)) #发送行会数据 GuildHandler.processGuildInfo(session) #发送结义数据 TeamHandler.processBrotherOps( session, MsgDef.BrotherOpsReq(MsgDef.BrotherClientCmd.GET_BROTHERLIST)) #发送安全码 processMoneyBankOps(session) processQueryPet(session) from handler import MarryHandler MarryHandler.processMarryOPS( session, MsgDef.MarriageOpsReq(MsgDef.MarriageClientCmd.MARRY_QUERY_STATUS)) SkillHandler.processAttackModeReq(session) #发送攻击模式 from handler import MailHandler MailHandler.processMarryOPS(session, MsgDef.MailOpsReq(0)) #msg = MsgDef.UpdateSkillPosReq({320:1}) #SkillHandler.processUpdateSkillPosReq(session, msg) #结义数据 # if player.brotherCtrl: # BrotherModel.handleQueryBrother(player) player.checkTimeAfterInit() # 登录(old)-记录log LogModel.logLoginData(accountid, player.uid, player.name, LogModel.LoginOpType.LOGIN_PLAYER, LogModel.LoginReason.OLD_LOGIN) return
def randomlyGenerate(self): """ Randomly generates a graph with the number with max number of shop where all shops are connected to their closest shops with no overlapping lines """ self.shopDict = {} orderedShopDict = {} """ First Generate all the shop and make sure the distance between them in large enough to be viewable """ for i in range(self.maxShops): newShop = True while newShop: p = Point([random.random()*Globals.RESOLUTION[0], random.random()*Globals.RESOLUTION[0]]) newShop = False #Make sure intersections are distenced for shop in self.shopDict: if abs(shop.getX() - p.getX()) < Globals.RESOLUTION[0]/self.maxShops/2 or abs(shop.getY() - p.getY()) < Globals.RESOLUTION[0]/self.maxShops/2: newShop = True category = random.choice(itemHandler.getCategories()) items = itemHandler.getItemsFromCategory(category) self.shopDict[Shop(p, category, items)]=[] """ Then order all the points in order of distance """ for shop in self.shopDict: orderedShopDict[shop] = self.orderDistance(shop, self.shopDict) """ Then connect the points to their closest points without overlapping lines and store these connections """ shouldBreak = False while not shouldBreak: shouldBreak = True for shop in orderedShopDict: if orderedShopDict[shop]: otherShop = orderedShopDict[shop][0] if otherShop not in self.shopDict[shop] and shop not in self.shopDict[otherShop]: if self.notIntersect([shop.getPos(), otherShop.getPos()]) and self.notSmallAngle([shop.getPos(), otherShop.getPos()]): self.shopDict[shop].append(otherShop) self.shopDict[otherShop].append(shop) shouldBreak = False del orderedShopDict[shop][0] """ Then order those points into order of distance for better searching """ for shop in self.shopDict: self.shopDict[shop] = self.orderDistance(shop, self.shopDict[shop], take=0) """ Finally generate the roads based on those connections """ self.roads = [] alreadyDone = [] for shop in self.shopDict: for otherShop in self.shopDict[shop]: if (otherShop, shop) not in alreadyDone: self.roads.append(Road(start = shop.getPos(), end = otherShop.getPos())) alreadyDone.append((shop, otherShop)) self.home = random.choice(list(self.shopDict.keys())) self.home.setHome()