def giveDrops(battle): resultDict = {} # default drop seems to always be CC... if 'defaultDropItem' in battle['questBattle']: cc = int(battle['questBattle']['defaultDropItem']['rewardCode1'].split( '_')[-1]) if len(getEpisodeUpCards(battle['deckType'])) > 0: cc *= 1.05 # CC up memes resultDict['gameUser'] = dt.setGameUserValue( 'riche', dt.getGameUserValue('riche') + cc) battle['riche'] = cc dropRewardCodes = [] dropCodes = dt.readJson('data/user/promisedDrops.json') if dropCodes['questBattleId'] != battle[ 'questBattleId']: # weird error that should never happen... logger.error('questBattleId mismatch when sending drops') return resultDict for dropCode, amount in dropCodes.items(): if dropCode == 'questBattleId': continue resultDict = dt.updateJson(resultDict, obtainItem(dropCode, amount)) dropRewardCodes += [dropCode] * amount battle['dropRewardCodes'] = ','.join(dropRewardCodes) return resultDict
def giveUserExp(battle): userExp = battle['questBattle']['exp'] battle['exp'] = battle['questBattle']['exp'] gameUser = dt.setGameUserValue('exp', dt.getGameUserValue('exp') + userExp) newStatus = [] if gameUser['exp'] >= gameUser['totalExpForNextLevel']: newLevel = gameUser['level'] + 1 dt.setGameUserValue('level', newLevel) dt.setGameUserValue('totalExpForCurrentLevel', gameUser['totalExpForNextLevel']) expAdd = 0 for i in range(0, newLevel + 1): expAdd += expForNextLevel[i] if i < len(expForNextLevel) else 30704 gameUser = dt.setGameUserValue( 'totalExpForNextLevel', gameUser['totalExpForNextLevel'] + expAdd) maxAP = dt.getUserObject('userStatusList', 'MAX_ACP') currAP = dt.getUserObject('userStatusList', 'ACP') maxAP['point'] += 1 currAP['point'] += maxAP['point'] currBP = dt.getUserObject('userStatusList', 'BTP') currBP['point'] = 5 newStatus.append(maxAP) newStatus.append(currAP) dt.setUserObject('userStatusList', 'MAX_ACP', maxAP) dt.setUserObject('userStatusList', 'ACP', currAP) dt.setUserObject('userStatusList', 'BTP', currBP) return gameUser, newStatus
def obtainItem(itemCode, amount=1): resultDict = {} if itemCode.startswith('GIFT'): giftId = int(itemCode.split('_')[1]) dropNum = amount * int( itemCode.split('_')[-1]) # seems to be always 1, but whatever userGift = dt.getUserObject('userGiftList', giftId) userGift['quantity'] += dropNum resultDict['userGiftList'] = resultDict.get('userGiftList', []) + [userGift] dt.setUserObject('userGiftList', giftId, userGift) elif itemCode.startswith('ITEM'): itemId = '_'.join(itemCode.split('_')[1:-1]) dropNum = amount * int( itemCode.split('_')[-1]) # seems to be always 1, but whatever userItem = dt.getUserObject('userItemList', itemId) userItem['quantity'] += dropNum resultDict['userItemList'] = resultDict.get('userItemList', []) + [userItem] dt.setUserObject('userItemList', itemId, userItem) elif itemCode.startswith('RICHE'): cc = amount * int(itemCode.split('_')[-1]) resultDict['gameUser'] = dt.setGameUserValue( 'riche', dt.getGameUserValue('riche') + cc) return resultDict
def user(endpoint): response = { "followCount": 0, "followerCount": 0, "follow": False, "follower": False, "blocked": False } with open('data/user/user.json', encoding='utf-8') as f: user = json.load(f) response['userName'] = dt.getUserValue('loginName') response['lastAccessDate'] = dt.getUserValue('lastLoginDate') if endpoint.split('/')[-1] != user['id']: flask.abort(501, description='User does not exist') response['gameUser'] = dt.readJson('data/user/gameUser.json') response['userRank'] = dt.getGameUserValue('level') response['comment'] = dt.getGameUserValue('comment') response['inviteCode'] = dt.getGameUserValue('inviteCode') response['userCardList'] = dt.readJson('data/user/userCardList.json') leaderId = dt.getGameUserValue('leaderId') for userCard in response['userCardList']: if userCard['id'] == leaderId: response['leaderUserCard'] = userCard response['cardId'] = userCard['cardId'] response['charaName'] = userCard['card']['cardName'] response['cardRank'] = userCard['card']['rank'] response['attributeId'] = userCard['card']['attributeId'] response['level'] = userCard['level'] response['displayCardId'] = userCard['displayCardId'] response['revision'] = userCard['revision'] break response['userDeck'] = dt.getUserObject('userDeckList', 20) for key in [ 'userCharaList', 'userPieceList', 'userDoppelList', 'userArenaBattle' ]: response[key] = dt.readJson('data/user/' + key + '.json') return flask.jsonify(response)
def sale(): body = flask.request.json totalCC = 0 for userPieceId in body['saleUserPieceIdList']: soldMemoria = dt.getUserObject('userPieceList', userPieceId) totalCC += priceCalc(soldMemoria['piece']['rank'], soldMemoria['lbCount']) dt.deleteUserObject('userPieceList', soldMemoria['id']) gameUser = dt.setGameUserValue('riche', dt.getGameUserValue('riche') + totalCC) response = {'resultCode': 'success', 'gameUser': gameUser} return flask.jsonify(response)
def compose(): body = flask.request.json targetUserCardId = body['userCardId'] targetUserCard = dt.getUserObject('userCardList', targetUserCardId) if targetUserCard is None: flask.abort(400, description='Tried to level up a card you don\'t have...') # figure out success type # (totally BS rates but whatevs) success = np.random.choice([1, 1.5, 2], p=[0.9, 0.08, 0.02]) # modify meguca's level and stats rank = targetUserCard['card']['rank'] origLevel = targetUserCard['level'] exp = getComposeExp(targetUserCard['card']['attributeId'], body['useItem']) * success targetUserCard = levelUp(targetUserCard, rank, exp) dt.setUserObject('userCardList', targetUserCardId, targetUserCard) # spend items try: revisedItemList = spend(body['useItem']) except ValueError as e: flask.abort(400, description='{"errorTxt": "'+repr(e)+'","resultCode": "error","title": "Error"}') # modify CC cc = getCCAmount(rank, origLevel, body['useItem']) currCC = dt.getGameUserValue('riche') if currCC < cc: flask.abort(400, description='{"errorTxt": "Tried to use more cc than you have...","resultCode": "error","title": "Error"}') gameUser = dt.setGameUserValue('riche', currCC-cc) # make response response = { 'composeEffect': success, 'resultCode': 'success', 'gameUser': gameUser, 'userCardList': [targetUserCard], 'userItemList': revisedItemList } return flask.jsonify(response)
def makeLoginBonus(lastLoginBonusDate, response): loginBonusCount = (dt.getGameUserValue('loginBonusCount') % 7) + 1 if datetime.now().date().weekday() == 0: loginBonusCount = 1 lastMonday, nextMonday = homu.thisWeek() if homu.strToDateTime(lastLoginBonusDate).date() < lastMonday: loginBonusCount = 1 dt.setGameUserValue('loginBonusGetAt', homu.nowstr()) dt.setGameUserValue('loginBonusPattern', 'S1') # no clue how to get the other patterns, even from JP, or if this even matters... dt.setGameUserValue('loginBonusCount', loginBonusCount) bonuses = dt.readJson('data/loginBonusList.json') currBonus = bonuses[loginBonusCount-1] for rewardCode in currBonus['rewardCodes'].split(','): loginItems = obtainItem(rewardCode) response = dt.updateJson(response, loginItems) response['loginBonusList'] = bonuses response['loginBonusPeriod'] = lastMonday.strftime('%m/%d') + '〜' + nextMonday.strftime('%m/%d')
def composeMagia(): body = flask.request.json targetUserCardId = body['userCardId'] # change userCard magia level targetUserCard = dt.getUserObject('userCardList', targetUserCardId) targetUserCard['magiaLevel'] += 1 if targetUserCard is None: flask.abort(400, description='{"errorTxt": "Tried to level magia of a card you don\'t have...' + targetUserCardId + '","resultCode": "error","title": "Error"}') dt.setUserObject('userCardList', targetUserCardId, targetUserCard) # spend items charaId = targetUserCard['card']['charaNo'] giftsToSpend = {} magiaLevel = {2: 'first', 3: 'second', 4: 'third', 5: 'fourth'} magiaPrefix = magiaLevel[targetUserCard['magiaLevel']] targetChara = dt.getUserObject('userCharaList', charaId)['chara'] for i in range(6): if magiaPrefix+'MagiaGiftId'+str(i+1) in targetChara \ and magiaPrefix+'MagiaGiftNum'+str(i+1) in targetChara: giftsToSpend[targetChara[magiaPrefix+'MagiaGiftId'+str(i+1)]] = targetChara[magiaPrefix+'MagiaGiftNum'+str(i+1)] revisedGiftList = spendGift(giftsToSpend) # spend CC ccByLevel = {2: 10000, 3: 100000, 4: 300000, 5: 1000000} # not sure about how much CC this actually takes currCC = dt.getGameUserValue('riche') if currCC - ccByLevel[targetUserCard['magiaLevel']] < 0: flask.abort(400, description='{"errorTxt": "Tried to use more cc than you have...","resultCode": "error","title": "Error"}') gameUser = dt.setGameUserValue('riche', currCC - ccByLevel[targetUserCard['magiaLevel']]) # make response response = { 'resultCode': 'success', 'gameUser': gameUser, 'userCardList': [targetUserCard], 'userGiftList': revisedGiftList } return flask.jsonify(response)
def limitBreak(): body = flask.request.json targetUserCardId = body['userCardId'] # edit userCard targetUserCard = dt.getUserObject('userCardList', targetUserCardId) if targetUserCard is None: flask.abort(400, description='{"errorTxt": "Tried to limit break a card you don\'t have...' + targetUserCardId + '","resultCode": "error","title": "Error"}') targetUserCard['revision'] += 1 dt.setUserObject('userCardList', targetUserCardId, targetUserCard) # edit userChara neededGems = {'RANK_1': 10, 'RANK_2': 10, 'RANK_3': 3, 'RANK_4': 1} charaNo = targetUserCard['card']['charaNo'] targetUserChara = dt.getUserObject('userCharaList', targetUserCard['card']['charaNo']) if targetUserChara is None: flask.abort(400, description='{"errorTxt": "Tried to limit break a card you don\'t have...' + targetUserCard['card']['charaNo'] + '","resultCode": "error","title": "Error"}') targetUserChara['lbItemNum'] -= neededGems[targetUserChara['chara']['defaultCard']['rank']] dt.setUserObject('userCharaList', charaNo, targetUserChara) # spend cc ccBySlotNum = [0, 0, 0, 0] # no idea how much it actually takes lol currCC = dt.getGameUserValue('riche') if currCC - ccBySlotNum[targetUserCard['revision']-1] < 0: flask.abort(400, description='{"errorTxt": "Tried to use more cc than you have...","resultCode": "error","title": "Error"}') gameUser = dt.setGameUserValue('riche', currCC - ccBySlotNum[targetUserCard['revision']-1]) # make response response = { "resultCode": "success", 'gameUser': gameUser, 'userCardList': [targetUserCard], 'userCharaList': [targetUserChara] } return flask.jsonify(response)
def myPage(response): lastLoginBonusDate = dt.getGameUserValue('loginBonusGetAt') if homu.beforeToday(lastLoginBonusDate): makeLoginBonus(lastLoginBonusDate, response) makeCampaignLoginBonus(lastLoginBonusDate, response)
def compose(): body = flask.request.json targetUserPieceId = body['baseUserPieceId'] targetUserPiece = dt.getUserObject('userPieceList', targetUserPieceId) memoriaToSpend = [] for materialPieceId in body['materialUserPieceIdList']: memoriaToSpend.append( dt.getUserObject('userPieceList', materialPieceId)) if targetUserPiece == {}: flask.abort( 400, description='Tried to level up a memoria you don\'t have...') # limit break isLimitBreak = False for memoria in memoriaToSpend: if memoria['pieceId'] == targetUserPiece['pieceId'] or \ ('pieceKind' in memoria['piece'] and memoria['piece']['pieceKind']=='LIMIT_BREAK'): isLimitBreak = True if isLimitBreak: targetUserPiece['lbCount'] += len(memoriaToSpend) originalUserPiece = {k: v for k, v in targetUserPiece.items()} targetUserPiece, success = levelUp(targetUserPiece, memoriaToSpend) dt.setUserObject('userPieceList', targetUserPieceId, targetUserPiece) # modify CC totalCC = 0 for memoria in memoriaToSpend: totalCC += priceCalc(memoria['piece']['rank'], memoria['lbCount']) dt.deleteUserObject('userPieceList', memoria['id']) currCC = dt.getGameUserValue('riche') if currCC < totalCC: raise ValueError("Tried to use more cc than you have...") gameUser = dt.setGameUserValue('riche', currCC - totalCC) # It looks like the archive ignores this information and shows everything max leveld and mlb'd... # with open('data/user/userPieceCollectionList.json', encoding='utf-8') as f: # pieceCollection = json.load(f) # for i, piece in enumerate(pieceCollection): # if piece['pieceId'] == targetUserPiece['pieceId']: # if targetUserPiece['level'] > piece['maxLevel']: # pieceCollection[i]['maxLevel'] = targetUserPiece['level'] # if targetUserPiece['lbCount'] > piece['maxLbCount']: # pieceCollection[i]['maxLbCount'] = targetUserPiece['lbCount'] # with open('data/user/userPieceCollectionList.json', 'w+', encoding='utf-8') as f: # json.dump(pieceCollection, f, ensure_ascii=False) response = { 'resultCode': 'success', 'gameUser': gameUser, 'userPieceList': [targetUserPiece], "memoria": { "materialList": [memoria['pieceId'] for memoria in memoriaToSpend], "memoriaId": targetUserPiece['pieceId'], "status": { "current": { "atk": originalUserPiece['attack'], "def": originalUserPiece['defense'], "gainedExp": originalUserPiece['experience'], "hp": originalUserPiece['hp'], "lbCount": originalUserPiece['lbCount'], "level": originalUserPiece['level'], "limitExp": dExpdLevel[originalUserPiece['level'] - 1], "limitLevel": getMaxLevel(originalUserPiece['piece']['rank'], originalUserPiece['lbCount']), "rarity": int(originalUserPiece['piece']['rank'][-1]) }, "result": { "atk": targetUserPiece['attack'], "def": targetUserPiece['defense'], "gainedExp": targetUserPiece['experience'], "hp": targetUserPiece['hp'], "lbCount": targetUserPiece['lbCount'], "level": targetUserPiece['level'], "limitExp": dExpdLevel[targetUserPiece['level'] - 1], "limitLevel": getMaxLevel(targetUserPiece['piece']['rank'], targetUserPiece['lbCount']), "rarity": int(targetUserPiece['piece']['rank'][-1]) } }, "successType": success } } return flask.jsonify(response)
def draw(): # handle different types of gachas body = flask.request.json chosenGacha = None for gacha in dt.readJson('data/gachaScheduleList.json'): if gacha['id'] == body['gachaScheduleId']: chosenGacha = gacha break if chosenGacha is None: flask.abort(404, description="Tried to pull on a gacha that doesn't exist...") if 'gachaGroupId' in chosenGacha.keys(): _, pity = setUpPity(chosenGacha['gachaGroupId']) else: pity = 0 # draw draw10 = body['gachaBeanKind'].endswith('10') or body['gachaBeanKind'] == 'SELECTABLE_TUTORIAL' isFreePull = False results = [] itemTypes = [] if body['gachaBeanKind'].startswith('NORMAL'): if draw10: results, itemTypes = drawTenNormal() isFreePull = beforeToday(dt.getGameUserValue('freeGachaAt')) else: results, itemTypes = drawOneNormal() else: if draw10: results, itemTypes, pity = drawTenPremium(pity) else: results, itemTypes, pity = drawOnePremium(pity) if 'gachaGroupId' in chosenGacha.keys(): pityGroup, _ = setUpPity(chosenGacha['gachaGroupId'], pity) else: pityGroup = None # sort into lists userCardList = [] userCharaList = [] userPieceList = [] userLive2dList = [] userItemList = [] userSectionList = [] userQuestBattleList = [] responseList = [] for result, itemType in zip(results, itemTypes): if itemType.startswith('g'): userItemList.append(addGem(result)) responseList.append({ "direction": 5, "displayName": result['name'], "isNew": False, "itemId": result['itemCode'], "rarity": 'RANK_'+str(result['name'].count('+')+1), "type": "ITEM" }) if itemType.startswith('p'): card, chara, live2ds, foundExisting = addMeguca(result['charaId']) if not foundExisting: userCardList.append(card) userLive2dList += live2ds newSectionList, newQuestBattleList = addStory(result['charaId']) userSectionList += newSectionList userQuestBattleList += newQuestBattleList userCharaList.append(chara) directionType = 3 if result['cardList'][0]['card']['rank'][-1] == "4": # give it the rainbow swirlies directionType = 4 responseList.append({ "type": "CARD", "rarity": result['cardList'][0]['card']['rank'], "maxRarity": result['cardList'][-1]['card']['rank'], "cardId": result['cardList'][0]['cardId'], "attributeId": result['chara']['attributeId'], "charaId": result['charaId'], "direction": directionType, "displayName": result['chara']['name'], "isNew": not foundExisting }) if foundExisting: responseList[-1]["itemId"] = "LIMIT_BREAK_CHARA" if itemType.startswith('m'): userPiece, foundExisting = addPiece(result['pieceId']) userPieceList.append(userPiece) directionType = 1 if result['rank'][-1] == "4": # give it the memoria equivalent of the rainbow swirlies directionType = 2 responseList.append({ "type": "PIECE", "rarity": result['rank'], "pieceId": result['pieceId'], "direction": directionType, "displayName": result['pieceName'], "isNew": not foundExisting }) # spend items gachaKind = None for kind in chosenGacha['gachaKindList']: if kind['beanKind'] == body['gachaBeanKind']: gachaKind = kind if not isFreePull: userItemList += \ spend(gachaKind['needPointKind'], gachaKind['needQuantity'], gachaKind['substituteItemId'] if 'substituteItemId' in gachaKind else None) # create response gachaAnimation = { "live2dDetail": gachaKind['live2dDetail'], "messageId": gachaKind['messageId'], "message": gachaKind['message'], # Determines which picture to show in the intro animation # # first picture # 1 = flower thingy (default, no real meaning) # 2 = inverted flower thingy (should mean at least 1 3+ star CARD (not necessarily meguca, could be memoria)) "direction1": 1, # # second picture # 1 = mokyuu (default, no real meaning) # 2 = attribute (specified with "direction2AttributeId") "direction2": 1, # # third picture # 1 = spear thingy (default, no real meaning) # 2 = iroha (should mean at least 1 3+ star) # 3 = mikazuki villa (at least 1 4 star) "direction3": 1, "gachaResultList": responseList } high_rarity_pulled = [thingy for thingy in responseList if thingy["rarity"] == "RANK_3" or thingy["rarity"] == "RANK_4"] cards_pulled = [thingy for thingy in responseList if thingy["type"] == "CARD"] any_3stars_pulled = [card for card in cards_pulled if card["rarity"] == "RANK_3"] any_4stars_pulled = [card for card in cards_pulled if card["rarity"] == "RANK_4"] # if any high rarity thingies pulled, set direction1 if len(high_rarity_pulled) >= 1: gachaAnimation["direction1"] = 2 # 50-50 chance of displaying a random card's attribute symbol instead of mokyuu # but only if cards were pulled (i.e. not for FP gacha) if len(cards_pulled) >= 1 and random.randint(1, 2) == 2: random_card = random.choice(cards_pulled) gachaAnimation["direction2"] = 2 gachaAnimation["direction2AttributeId"] = random_card["attributeId"] if len(any_4stars_pulled) >= 1: # show mikazuki villa if any 4 stars were pulled gachaAnimation["direction3"] = 3 elif len(any_3stars_pulled) >= 1: # show iroha if any 3 stars were pulled gachaAnimation["direction3"] = 2 if pityGroup is not None: gachaAnimation["userGachaGroup"] = pityGroup response = { "resultCode": "success", "gachaAnimation": gachaAnimation, "userCardList": userCardList, "userCharaList": userCharaList, "userLive2dList": userLive2dList, "userItemList": userItemList, "userPieceList": userPieceList } if isFreePull: response['gameUser'] = dt.setGameUserValue('freeGachaAt', nowstr()) if len(userSectionList) > 0: response['userSectionList'] = userSectionList if len(userQuestBattleList) > 0: response['userQuestBattleList'] = userQuestBattleList # add to user history pullId = str(uuid1()) if not os.path.exists('data/user/gachaHistory'): os.mkdir('data/user/gachaHistory') dt.saveJson('data/user/gachaHistory/'+pullId+'.json', {'gachaAnimation': gachaAnimation}) newHistory = { "id": pullId, "userId": dt.userId, "gachaScheduleId": body['gachaScheduleId'], "gachaSchedule": chosenGacha, "gachaBeanKind": body['gachaBeanKind'], "bonusTimeFlg": False, "createdAt": nowstr() } dt.setUserObject('gachaHistoryList', pullId, newHistory) return flask.jsonify(response)
def sendArena(request, response): """ The response has 7 values: gameUser (should be in response), resultCode="success" userArenaBattle, userArenaBattleResultList, userDailyChallengeList, userItemList, userQuestBattleResultList (should be in response), """ userArenaBattle = dt.readJson('data/user/userArenaBattle.json') userArenaBattleResult = dt.readJson('data/user/userArenaBattleResult.json') coins = dt.getUserObject('userItemList', 'ARENA_COIN') if (request['result'] == 'SUCCESSFUL'): coins['quantity'] += 3 numTurnsCapped = min(max(request['totalTurn'], 2), 7) # cap to 2 and 7 turnBonus = 1.0 + 0.1 * (7 - numTurnsCapped) opponentBonus = { 'SAME': 1.0, 'HIGHER': 1.2, 'LOWER': 0.8 }[userArenaBattleResult['arenaBattleOpponentType']] consecBonus = [0, 1, 2, 3, 5, 7, 10 ][userArenaBattleResult['numberOfConsecutiveWins'] - 1] getPoints = 10 * turnBonus * opponentBonus + consecBonus userArenaBattle['freeRankArenaPoint'] += getPoints userArenaBattleResult['arenaBattleStatus'] = 'WIN' userArenaBattleResult[ 'numberOfConsecutiveWins'] = userArenaBattleResult[ 'numberOfConsecutiveWins'] % 7 + 1 userArenaBattleResult['point'] = getPoints dt.setGameUserValue( 'numberOfFreeRankTotalWins', dt.getGameUserValue('numberOfFreeRankTotalWins') + 1) else: userArenaBattleResult['arenaBattleStatus'] = 'LOSE' coins['quantity'] += 1 userArenaBattleResult['numberOfConsecutiveWins'] = 0 userArenaBattle['freeRankArenaPoint'] += 3 userArenaBattleResult['point'] = userArenaBattle['freeRankArenaPoint'] dt.setGameUserValue('freeRankArenaPoint', userArenaBattle['freeRankArenaPoint']) gameUser = dt.setGameUserValue( 'numberOfFreeRankConsecutiveWins', userArenaBattleResult['numberOfConsecutiveWins']) dt.saveJson('data/user/userArenaBattle.json', userArenaBattle) dt.saveJson('data/user/userArenaBattleResult.json', userArenaBattleResult) # updating coins dt.setUserObject('userItemList', 'ARENA_COIN', coins) userItemList = [coins] resultCode = "success" response.update({ 'gameUser': gameUser, 'userArenaBattle': userArenaBattle, 'userItemList': userItemList, 'userArenaBattleResultList': [userArenaBattleResult], 'resultCode': resultCode }) response = storyUtil.progressMirrors(response) return flask.jsonify(response)
def evolve(): body = flask.request.json targetUserCardId = body['userCardId'] targetUserCard = dt.getUserObject('userCardList', targetUserCardId) if targetUserCard is None: flask.abort(400, description='{"errorTxt": "Tried to awaken a card you don\'t have: ' + targetUserCardId + '","resultCode": "error","title": "Error"}') charaId = targetUserCard['card']['charaNo'] # get next card masterCard = dt.masterCards[charaId] if masterCard is None: flask.abort(400, description='{"errorTxt": "Tried to awaken a character that doesn\'t exist...","resultCode": "error","title": "Error"}') cardList = masterCard['cardList'] newCard = None foundCurrentCard = False for card in cardList: if foundCurrentCard: newCard = card['card'] break if targetUserCard['card']['cardId'] == card['cardId']: foundCurrentCard = True if newCard is None and foundCurrentCard: newCard = cardList[-1]['card'] if newCard is None: flask.abort(400, description='{"errorTxt": "This character can\'t be awakened anymore...","resultCode": "error","title": "Error"}') # make new userCard and userChara newUserCard, _, _ = newtil.createUserMeguca(charaId, newCard) newUserCard['revision'] = targetUserCard['revision'] newUserCard['magiaLevel'] = targetUserCard['magiaLevel'] revisedUserChara = dt.getUserObject('userCharaList', charaId) if revisedUserChara is None: flask.abort(400, description='Tried to awaken a character you don\'t have...') revisedUserChara['userCardId'] = newUserCard['id'] # save user info targetUserCard['enabled'] = False dt.setUserObject('userCardList', targetUserCardId, targetUserCard) dt.setUserObject('userCardList', newUserCard['id'], newUserCard) dt.setUserObject('userCharaList', charaId, revisedUserChara) with open('data/user/userDeckList.json', encoding='utf-8') as f: decks = f.read() decks = decks.replace(targetUserCardId, newUserCard['id']) with open('data/user/userDeckList.json', 'w+', encoding='utf-8') as f: f.write(decks) if dt.getGameUserValue('leaderId') == targetUserCardId: dt.setGameUserValue('leaderId', newUserCard['id']) # spend CC ccByLevel = {'RANK_2': 10000, 'RANK_3': 100000, 'RANK_4': 300000, 'RANK_5': 1000000} # not sure about how much CC it takes to go from 2* to 3* currCC = dt.getGameUserValue('riche') if currCC - ccByLevel[newCard['rank']] < 0: flask.abort(400, description='{"errorTxt": "Tried to use more cc than you have...","resultCode": "error","title": "Error"}') gameUser = dt.setGameUserValue('riche', currCC - ccByLevel[newCard['rank']]) # make response response = { 'evolution': { 'current': { 'attr': targetUserCard['card']['attributeId'], 'cardId': targetUserCard['card']['cardId'], 'rarity': int(targetUserCard['card']['rank'][-1]) }, 'giftIdList': [targetUserCard['card']['cardCustomize'][giftKey] for giftKey in targetUserCard['card']['cardCustomize'].keys() if giftKey.startswith('giftId')], 'result': { 'attr': newCard['attributeId'], 'cardId': newCard['cardId'], 'rarity': int(newCard['rank'][-1]) } }, "resultCode": "success", 'gameUser': gameUser, 'userCardList': [targetUserCard, newUserCard], 'userCharaList': [revisedUserChara] } return flask.jsonify(response)
def getCC(amount): gameUser = dt.setGameUserValue('riche', dt.getGameUserValue('riche') + amount) return {'gameUser': gameUser}