def handleStartMailEngine(self, data): if not self.agentStatus and random.random() < 0.4: q = self.session.query(Mail).filter(Mail.Recipient == self.user.ID).\ filter((Mail.Type == '112') | (Mail.Type == '47')) epfInvited = self.session.query(q.exists()).scalar() if not epfInvited: postcard = Mail(Recipient=self.user.ID, SenderName="sys", SenderID=0, Details="", Date=int(time.time()), Type=112) self.session.add(postcard) lastPaycheck = self.user.LastPaycheck if lastPaycheck == 0: lastPaycheck = datetime.datetime.now() else: lastPaycheck = datetime.datetime.fromtimestamp(lastPaycheck) today = datetime.datetime.now() lastPaycheck = lastPaycheck.replace(month=(lastPaycheck.month + 1)) lastPaycheck = lastPaycheck.replace(day=2) while lastPaycheck < today: paycheckDate = int(time.mktime(lastPaycheck.timetuple())) if 428 in self.inventory: postcard = Mail(Recipient=self.user.ID, SenderName="sys", SenderID=0, Details="", Date=paycheckDate, Type=172) self.session.add(postcard) self.user.Coins += 250 if self.agentStatus: postcard = Mail(Recipient=self.user.ID, SenderName="sys", SenderID=0, Details="", Date=paycheckDate, Type=171) self.session.add(postcard) self.user.Coins += 350 lastPaycheck = lastPaycheck.replace(month=(lastPaycheck.month + 1)) lastPaycheck = lastPaycheck.replace(day=2) self.user.LastPaycheck = int(time.mktime(today.timetuple())) self.session.commit() totalMail = self.session.query(Mail).\ filter(Mail.Recipient == self.user.ID).count() unreadMail = self.session.query(Mail).\ filter(Mail.Recipient == self.user.ID).\ filter(Mail.HasRead == False).count() self.sendXt("mst", unreadMail, totalMail)
def handleSendAdoptPuffle(self, data): if not data.TypeId in puffleStatistics: return self.transport.loseConnection() if self.user.Coins < 800: return self.sendError(401) self.user.Coins -= 800 maxHealth, maxHunger, maxRest = puffleStatistics[data.TypeId] adoptionDate = int(time.time()) puffle = Puffle(Owner=self.user.ID, Name=data.Name, AdoptionDate=adoptionDate, Type=data.TypeId, Health=maxHunger, Hunger=maxHunger, Rest=maxRest) self.session.add(puffle) self.session.commit() puffleString = "%d|%s|%d|100|100|100|100|100|100" % (puffle.ID, data.Name, data.TypeId) self.sendXt("pn", self.user.Coins, puffleString) postcard = Mail(Recipient=self.user.ID, SenderName="sys", SenderID=0, Details=data.Name, Date=adoptionDate, Type=111) self.session.add(postcard) self.session.commit() self.sendXt("mr", "sys", 0, 111, data.Name, adoptionDate, postcard.ID) # Refresh my player puffles handleGetMyPlayerPuffles(self, [])
def handleSendMail(self, data): q = self.session.query(Penguin).filter(Penguin.ID == data.RecipientId) recipientExists = self.session.query(q.exists()).scalar() if not recipientExists: return if self.user.Coins < 10: self.sendXt("ms", self.user.Coins, 2) self.logger.debug("%d tried to send postcard with insufficient funds.", self.user.ID) return recipientMailCount = self.session.query(Mail).\ filter(Mail.Recipient == data.RecipientId).count() if recipientMailCount >= 100: self.sendXt("ms", self.user.Coins, 0) self.user.Coins -= 10 currentTimestamp = int(time.time()) postcard = Mail(Recipient=data.RecipientId, SenderName=self.user.Username, SenderID=self.user.ID, Details="", Date=currentTimestamp, Type=data.PostcardId) self.session.add(postcard) self.session.commit() self.sendXt("ms", self.user.Coins, 1) if data.RecipientId in self.server.players: recipientObject = self.server.players[data.RecipientId] recipientObject.sendXt("mr", self.user.Username, self.user.ID, data.PostcardId, "", currentTimestamp, postcard.ID) self.logger.info("%d send %d a postcard (%d).", self.user.ID, data.RecipientId, data.PostcardId)
def decreaseStats(server): for (playerId, player) in server.players.items(): if player.room.Id == player.user.ID + 1000: continue for (puffleId, puffle) in player.puffles.items(): maxHealth, maxHunger, maxRest = puffleStatistics[puffle.Type] if int(puffle.Walking): puffle.Hunger = max(10, min(puffle.Hunger - 4, maxHunger)) puffle.Rest = max(10, min(puffle.Rest - 4, maxRest)) else: puffle.Health = max(0, min(puffle.Health - 2, maxHealth)) puffle.Hunger = max(0, min(puffle.Hunger - 2, maxHunger)) puffle.Rest = max(0, min(puffle.Rest - 2, maxRest)) if puffle.Health == 0 and puffle.Hunger == 0 and puffle.Rest == 0: runPostcard = runPostcards[puffle.Type] postcard = Mail(Recipient=player.user.ID, SenderName="sys", SenderID=0, Details=puffle.Name, Date=int(time.time()), Type=runPostcard) player.session.add(postcard) player.session.query(Puffle).filter(Puffle.ID == puffle.ID).delete() player.session.commit() player.sendXt("mr", "sys", 0, runPostcard, puffle.Name, int(time.time()), postcard.ID) del player.puffles[puffle.ID] elif puffle.Hunger < 10: q = player.session.query(Mail).filter(Mail.Recipient == player.user.ID). \ filter(Mail.Type == 110). \ filter(Mail.Details == Puffle.Name) notificationAware = player.session.query(q.exists()).scalar() if not notificationAware: postcard = Mail(Recipient=player.user.ID, SenderName="sys", SenderID=0, Details=puffle.Name, Date=int(time.time()), Type=110) player.session.add(postcard) player.session.commit() player.sendXt("mr", "sys", 0, 110, puffle.Name, int(time.time()), postcard.ID) player.session.commit() handleGetMyPlayerPuffles(player, [])