def gameOver(self, playerLeft=None): if playerLeft is not None and playerLeft in self[:2]: self.send('cz', playerLeft['nickname']) opponent, OIndex = (self[0], 0) if self[1] is playerLeft else (self[1], 1) Coin(player_id=opponent['id'], transaction=self.Points[OIndex], comment="Coins earned by playing FindFour").save() opponent['coins'] += self.Points[OIndex] else: Coin(player_id=self[0]['id'], transaction=self.Points[0], comment="Coins earned by playing FindFour").save() Coin(player_id=self[1]['id'], transaction=self.Points[1], comment="Coins earned by playing FindFour").save() self[0]['coins'] += self.Points[0] self[1]['coins'] += self.Points[1] for peng in list(self): peng.send('zo', peng['coins']) del self[self.index(peng)] self.onRemove(peng)
def addItem(self, item, comment="Added via catalog"): if isinstance(item, int): item = self.engine.itemCrumbs[item] elif isinstance(item, str): try: item = self.engine.itemCrumbs[int(item)] except: item = None if item is None: returnValue(False) cost = item.cost if int(self.penguin.coins) < cost: self.send('e', 401) returnValue(False) if self['RefreshHandler'].inInventory(item): returnValue(False) yield Inventory(penguin_id=self['id'], item=int(item), comments=comment).save() yield Coin(penguin_id=self['id'], transaction=-cost, comment="Money spent on adding item ({}). Item: {}".format( comment, int(item))).save() self.penguin.coins -= cost returnValue(True)
def handleSendPuffleBackToTheWoods(client, data): puffle = int(data[2][0]) puffleById = {i.id: i for i in client['data'].puffles} puffle = puffleById[puffle] if puffle in puffleById else None if puffle is None: returnValue(0) pMonths = int((time() - puffle.adopt())/60/60/24/30.5) dcoins = 500 + 10 * pMonths if int(client['coins']) < dcoins: dcoins = int(client['coins']) yield Coin(penguin_id=client['id'], transaction=-dcoins, comment="Penalized for abandoning adopted puffle. Puffle: {}, ID: {}".format(puffle.type, puffle.id)) client['coins'] -= dcoins handlePuffleWalk(client, int(puffle.id), False) post_id = 100 + int(puffle.type) if puffle.type == 7: post_id = 169 elif puffle.type == 8: post_id += 1 yield Mail(penguin_id=client['id'], from_user=0, type=post_id, description=str(puffle.name)).save() yield puffle.delete() client['RefreshHandler'].forceRefresh()
def handleAddPuffleItem(client, _id): if _id not in client.engine.puffleCrumbs.puffleItems: returnValue(client.send('e', 402)) item_details = client.engine.puffleCrumbs.puffleItems[_id] cost = int(item_details['cost']) is_member = bool(int(item_details['is_member_only'])) quantity = int(item_details['quantity']) if is_member and not client['member']: returnValue(client.send('e', 999)) if cost > int(client['coins']): returnValue(client.send('e', 401)) yield Coin( penguin_id=client['id'], transaction=-cost, comment="Spent money buying puffle care item. Item: {}".format(_id)) client['coins'] -= cost careItems = yield client.dbpenguin.careItems.get() careItemsById = {i.id: i for i in careItems} if _id not in careItemsById: yield CareItem(penguin_id=client['id'], item=_id, quantity=quantity).save() else: careItemsById[_id].quantity = int( careItemsById[_id].quantity) + quantity yield careItemsById[_id].save() client['RefreshHandler'].forceRefresh()
def handleBuyPowerCard(client, data): if not client['member']: return client.send('e', 999) if int(client['coins']) < 1500: return client.send('bpc', 401) cardsBought = list() availablePowerCards = [ k for k in client.engine.cardCrumbs.cards if k.power > 0 ] cards = list(sample(availablePowerCards, 3)) Coin(penguin_id=client['id'], transaction=-1500, comment="Money spent on buying [3] CJ Power Card. Item: {}".format( ','.join(map(repr, cards)))).save() client['coins'] -= 1500 client.send('bpc', ','.join(map(str, map(int, cards))), client['coins']) for card in cards: if card.id not in client['ninjaHandler'].cards: client['ninjaHandler'].cards[card.id] = [card, 0] client['ninjaHandler'].cards[card.id][1] += 1 client['ninjaHandler'].ninja.cards = '|'.join( map(lambda x: "{},{}".format(x, client['ninjaHandler'].cards[x][1]), client['ninjaHandler'].cards)) client['ninjaHandler'].ninja.save()
def handleStampEarned(client, _id, fromServer=False): stamp = client.engine.stampCrumbs[_id] if stamp is None: return if stamp.group in SERVER_ONLY_STAMP_GROUP and not fromServer: client.engine.log("warn", client['username'], "trying to manipulate Stamp System.") # ban? return stamps = [x.stamp for x in client['data'].stamps] if int(stamp) in stamps: return # lol #You earned a stamp, earn a penny now B-) client['coins'] += 1 yield Coin(penguin_id=client['id'], transaction=1, comment="Earned money by earning stamp. Stamp: {}".format( stamp)).save() yield Stamp(penguin_id=client['id'], stamp=int(stamp)).save() client['recentStamps'].append(stamp)
def handleBuyFurniture(client, _id, deduce_coins=True): furniture = client.engine.iglooCrumbs.getFurnitureById(_id) if furniture is None: returnValue(client.send('e', 402)) if furniture.is_member and not client['member']: returnValue(client.send('e', 999)) furn = client['RefreshHandler'].getAsset(_id, 'f') quantity = furn.quantity if furn is not None else 0 if quantity > furniture.max: returnValue(client.send('e', 403)) if int(client['coins'] + 1) < furniture.cost: returnValue(client.send('e', 401)) if furn is None: furn = Asset(penguin_id=client['id'], item=_id, type='f', quantity=1) yield furn.save() else: furn.quantity = int(furn.quantity) + 1 furn.save() client.send('af', _id, client['coins']) yield Coin(penguin_id=client['id'], transaction=-furniture.cost * deduce_coins, comment="Spent money buying furniture. Furniture: {}".format( _id)).save() client['RefreshHandler'].forceRefresh()
def handleGoldRushDig(client, data): cannotDig = max(0, 3 - int(time() - client['lastGoldenRushDig'])) dcoin = DIGGABLE.next() * int(not cannotDig) if dcoin: setattr(client.penguin, 'lastGoldenRushDig', int(time())) Coin(penguin_id = client['id'], transaction = dcoin, comment = "Earned coin by digging in the Golde Mine. " "Player in Golde Mine = {}".format(client['room'].ext_id == 813)).save() client['coins'] += dcoin client.send('cdu', dcoin, client['coins'])
def _refresh(self, forced=False): if self.DEBUG: self.logger.info( 'Penguin ASync-Refresh-ing : Penguin - {}, Forced - {}'.format( self.penguin['nickname'], forced)) if self.penguin['connectionLost']: returnValue(0) if self.firstTimeCall: yield self._setupCache() self.firstTimeCall = False returnValue(1) # coins update self.penguin.penguin.coins = (yield Registry.getConfig(). \ execute("SELECT SUM(transaction) FROM coins where penguin_id = %s" % self.penguin['id']))[0][0] if self.penguin['coins'] is None: yield Coin(penguin_id=self.penguin['id'], transaction=100, comment="Player went bankrupt. " "Giving them +100").save() self.penguin.penguin.coins = 100 self.penguin.penguin.coins = int(self.penguin['coins']) self.penguin.send('gtc', self.penguin['coins']) for item in self.REFRESH_ITEMS: if not hasattr(self.penguin.dbpenguin, item): continue relation = getattr(self.penguin.dbpenguin, item) items_o = set(self.cache[item]) items_ = yield relation.get() items_updated = set(items_) items_added = items_updated - items_o items_removed = items_o - items_updated reactor.callFromThread(self.cacheHandlers[item], items_added, items_removed, items_o) reactor.callFromThread(self.cacheHandlers['igloos']) GeneralEvent( 'Refresh-Cache', self) # Refresh cache data for things other than those in here if forced: reactor.callFromThread( self.RefreshManagerLoop.stop ) if self.RefreshManagerLoop.running else None reactor.callFromThread(self.RefreshManagerLoop.start, self.REFRESH_INTERVAL, False) if \ not self.penguin['connectionLost'] else None
def handleAdopt(client, _type, name, sub_type, sendPuffleAdopt=True): if not handleCheckPuffleName(client, [0, 0, [name]]): returnValue(None) if not client['id'] in PENDING: PENDING[client['id']] = [] PENDING[client['id']].append(name) puffle = client.engine.puffleCrumbs[sub_type] if puffle is None or (_type == 10 and not client['canAdoptRainbow']) or ( _type == 11 and not client['canAdoptGold']): PENDING[client['id']].remove(name) returnValue(None) cost = 800 if sub_type in client.engine.puffleCrumbs.defautPuffles: cost = 400 if puffle.member and not client['member']: PENDING[client['id']].remove(name) client.send('e', 999) returnValue(None) if client['coins'] < cost: returnValue(client.send('e', 401)) now = int(time()) care = '{"food" : {now},"play" : {now},"bath" : {now}}'.replace( '{now}', str(now)) puffle_db = yield Puffle(penguin_id=client['id'], name=name, type=_type, subtype=sub_type, food=puffle.hunger, play=100, rest=puffle.rest, clean=puffle.health, lastcare=care).save() yield Coin( penguin_id=client['id'], transaction=-cost, comment="Pet Puffle Adoption. Puffle: {}".format(sub_type)).save() client['coins'] -= cost yield Mail(penguin_id=client['id'], from_user=0, type=111, description=name).save() client['RefreshHandler'].forceRefresh() PENDING[client['id']].remove(name) returnValue(puffle_db)
def handleGameOver(client, data): score = int(data[2][0]) coins = round(score / 10.0) client.penguin.playing = False current_game = client['room'] if coins > 10000: client.engine.log('warn', "Potential coins manipulation,", current_game, ':', score) return if not isinstance(current_game, Game) or isinstance( current_game, Multiplayer): try: current_game.gameOver(client=client) except: client.engine.log('warn', "Game exploitation,", current_game.name, ':', score) return stamps = map(int, client['recentStamps']) g_stamps = map( int, client.engine.stampCrumbs.getStampsByGroup(current_game.stamp_id)) e_stamps = list( set(map(lambda x: int(x.stamp), client['data'].stamps)).intersection(g_stamps)) stamps = list(set(stamps).intersection(g_stamps)) earned = len(e_stamps) total = len(g_stamps) if total == earned and total != 0: coins *= 2 client.send('zo', client['coins'] + coins, '|'.join(map(str, stamps)), earned, total, total) client['coins'] += coins Coin(penguin_id=client['id'], transaction=coins, comment="Coins earned by playing game. Game: {}".format( current_game.name)).save() GeneralEvent("Game-Over", client, score, current_game) client['room'].remove(client) for room in client['prevRooms'][::-1]: if isinstance(room, Place): room.append(client) return
def gameOver(self, playerLeft = None, client = None): self.GameStarted = False if playerLeft is not None: self.send('cz', playerLeft['nickname']) for u in list(self): self.remove(u) self.room.append(u) return Coin(player_id=client['id'], transaction=10 + client['isFirst'] * 50, comment="Coins earned by playing Sled Racing").save() client['coins'] += 10 + client['isFirst'] * 50 client.send('zo', client['coins']) if client in self: self.remove(client)
def sendMail(self, to, mail): postcard = self.penguin.engine.postcardHandler[mail] if postcard is None: self.penguin.send('ms', self.penguin['coins'], 0) returnValue(None) if not (int(self.penguin['coins']) > 10): self.penguin.send('ms', self.penguin['coins'], 2) returnValue(None) yield Mail(penguin_id=to, from_user=self.penguin['id'], type=mail, description=str(postcard)).save() yield Coin(penguin_id=self.penguin['id'], transaction=-10, comment="Postal Stamp charges. Mail sent: {}, to {}".format(mail, to)).save() self.penguin['coins'] -= 10 self.penguin.send('ms', self.penguin['coins'], 1)
def handleBuyLocation(client, _id): location = client.engine.iglooCrumbs.getLocationById(_id) if location is None: returnValue(client.send('e', 402)) if client['RefreshHandler'].hasAsset(_id, 'l'): returnValue(client.send('e', 400)) if int(client['coins'] + 1) < location.cost: returnValue(client.send('e', 401)) location_db = IglooFurniture(penguin_id = client['id'], item = _id, type = 'l') yield location_db.save() client['coins'] -= location.cost yield Coin(penguin_id = client['id'], transaction = -location.cost, comment = "Spent money on buying location. " "Location: {}".format(_id)).save() client['RefreshHandler'].forceRefresh()
def handleBuyIgloo(client, _id): igloo = client.engine.iglooCrumbs.getIglooById(_id) if igloo is None: returnValue(client.send('e', 402)) if client['RefreshHandler'].hasAsset(_id, 'i'): returnValue(client.send('e', 500)) if int(client['coins'] + 1) < igloo.cost: returnValue(client.send('e', 401)) item = Asset(penguin_id=client['id'], item=_id, type='i') yield item.save() yield Coin(penguin_id=client['id'], transaction=-igloo.cost, comment="Spent money buying igloo. Igloo: {}".format(_id)).save() client['RefreshHandler'].forceRefresh()
def handleBuyFloor(client, _id): floor = client.engine.iglooCrumbs.getFloorById(_id) if floor is None: returnValue(client.send('e', 402)) if client['RefreshHandler'].hasAsset(_id, 'fl'): returnValue(client.send('e', 400)) if int(client['coins'] + 1) < floor.cost: returnValue(client.send('e', 401)) item = Asset(penguin_id=client['id'], item=_id, type='fl') yield item.save() yield Coin(penguin_id=client['id'], transaction= -floor.cost, comment="Spent money buying floor. Floor: {}".format(_id)).save() client['RefreshHandler'].forceRefresh()
def handleCollectRBQCoins(client, data): questID = int(data[2][0]) if not 0 <= questID < len( client['currencyHandler'].quest['puffle']['rainbow']['tasks']): return iTask = client['currencyHandler'].quest['puffle']['rainbow']['tasks'][ questID] if not iTask['completed'] or iTask['coin'] > 1: return iTask['coin'] = 2 coins = 100 + 10 * questID Coin(penguin_id=client['id'], transaction=coins, comment="Coins rewarded for completing Rainbow Quests.").save() client['coins'] += coins client['currencyHandler'].refreshCurrencies() client.send('rpqcc', questID, 2, client['coins'])
def handlePuffleDig(client, data): if client['walkingPuffle'] is None: return cmd = data[1] lDC = 'lastDig' if 'oncommand' in cmd: lDC += 'OC' lastDig = client[lDC] cmd = max(0, (40 if 'oncommand' not in cmd else 120) - int(time() - client[lDC])) if cmd: returnValue(0) # no dig digables = range(5) setattr(client.penguin, lDC, time()) digChances = list() canDigGold = client['walkingPuffle'].state == 1 for i in digables: if i is 4 and not canDigGold: continue elif i is 1 and canDigGold: continue chance = randint(0, 3 + 4 * int(canDigGold and i is 'gold')) digChances += [i for _ in range(chance)] dig = choice(digChances) if dig == 0: coinsDug = int(10 * randint(1, 40)) Coin(penguin_id=client['id'], transaction=coinsDug, comment="Coins earned by puffle dig. Puffle: {}".format( client['walkingPuffle'].id)).save() client['coins'] += coinsDug returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 0, 0, coinsDug, 0, 0)) elif dig == 1: returnValue(client['room'].send('nodig', client['id'], 1)) elif dig == 2: diggables = DIGGABLE_FURN if client['walkingPuffle'].id == 11: diggables += GOLD_DIGGABLE_FURN shuffle(diggables) for dug in diggables: tryDigging = yield handleBuyFurniture(client, dug, False) if tryDigging is True: returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 2, dug, 1, 0, 0)) Coin(penguin_id=client['id'], transaction=600, comment="Coins earned by puffle dig. Puffle: {}".format( client['walkingPuffle'].id)).save() client['coins'] += 600 returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 0, 0, 600, 0, 0)) elif dig == 3: diggables = DIGGABLES if client['walkingPuffle'].id == 11: diggables += GOLD_DIGGABLES shuffle(diggables) for dug in diggables: if not client['RefreshHandler'].inInventory(dug): client.addItem(dug, 'Dug item') returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 3, dug, 1, 0, 0)) Coin(penguin_id=client['id'], transaction=500, comment="Coins earned by puffle dig. Puffle: {}".format( client['walkingPuffle'].id)).save() returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 0, 0, 500, 0, 0)) elif dig == 4: dug = randint(1, 3) client['currencyHandler'].currencies[1] += dug client['currencyHandler'].refreshCurrencies() handleGetCurrencies(client, [-1, '', []]) if client['currencyHandler'].currencies[1] > 14: client.penguin.canAdoptGold = True returnValue(client['room'].send('puffledig', client['id'], client['walkingPuffle'].id, 4, 0, dug, 0, 0))