Skip to content

Commit

Permalink
Fixes to getting new megucas
Browse files Browse the repository at this point in the history
  • Loading branch information
kavezo committed Nov 24, 2020
1 parent a384d21 commit 1b5d4d6
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 46 deletions.
39 changes: 0 additions & 39 deletions add_missing_mss.py

This file was deleted.

50 changes: 48 additions & 2 deletions api/gacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,47 @@ def addGem(gem):
dataUtil.setUserObject('userItemList', gem['itemCode'], item)
return item

def addStory(charaId):
existingSections = dataUtil.listUserObjectKeys('userSectionList')
validSections = dataUtil.masterSections.keys()
userSectionDict = {}
for i in range(4):
sectionId = '3{0}{1}'.format(charaId, i+1)
if sectionId in existingSections: continue
if sectionId in validSections:
userSectionDict[sectionId] = {
"userId": dataUtil.userId,
"sectionId": sectionId,
"section": dataUtil.masterSections[sectionId],
"canPlay": True, #str(sectionId).endswith('1'),
"cleared": False,
"createdAt": newUserObjectUtil.nowstr()
}

existingBattles = dataUtil.listUserObjectKeys('userQuestBattleList')
validBattles = dataUtil.masterBattles.keys()
userQuestBattleDict = {}
for i in range(4):
for j in range(3):
battleId = '3{0}{1}{2}'.format(charaId, i+1, j+1)
if battleId in existingBattles: continue
if battleId in validBattles:
userQuestBattleDict[battleId] = {
"userId": dataUtil.userId,
"questBattleId": battleId,
"questBattle": dataUtil.masterBattles[battleId],
"cleared": True,
"missionStatus1": "CLEARED",
"missionStatus2": "CLEARED",
"missionStatus3": "CLEARED",
"rewardDone": True,
"createdAt": newUserObjectUtil.nowstr()
}

dataUtil.batchSetUserObject('userSectionList', userSectionDict)
dataUtil.batchSetUserObject('userQuestBattleList', userQuestBattleDict)
return list(userSectionDict.values()), list(userQuestBattleDict.values())

def addMeguca(charaId):
# TODO: get the story of the meguca
userChara = dataUtil.getUserObject('userCharaList', charaId)
Expand All @@ -165,7 +206,7 @@ def addMeguca(charaId):
dataUtil.saveJson('data/user/userLive2dList.json', dataUtil.readJson(live2dPath) + [userLive2d])
else:
userChara['lbItemNum'] += 1
dataUtil.setUserObject('userCharaList', userChara['userCardId'], userChara)
dataUtil.setUserObject('userCharaList', charaId, userChara)

userCard = dataUtil.getUserObject('userCardList', userChara['userCardId'])
userLive2d = dataUtil.getUserObject('userLive2dList', int(str(charaId)+'00'))
Expand All @@ -189,7 +230,6 @@ def addPiece(pieceId):

def draw():
# TODO: give a destiny gem if there's a dupe in the same multi-pull
# TODO: get stories

# handle different types of gachas
body = flask.request.json
Expand Down Expand Up @@ -233,6 +273,8 @@ def draw():
userPieceList = []
userLive2dList = []
userItemList = []
userSectionList = None
userQuestBattleList = None

responseList = []

Expand All @@ -252,6 +294,7 @@ def draw():
if not foundExisting:
userCardList.append(card)
userLive2dList.append(live2d)
userSectionList, userQuestBattleList = addStory(result['charaId'])
userCharaList.append(chara)
directionType = 3
if result['cardList'][0]['card']['rank'][-1] == "4":
Expand Down Expand Up @@ -355,6 +398,9 @@ def draw():
"userPieceList": userPieceList
}

if userSectionList is not None: response['userSectionList'] = userSectionList
if userQuestBattleList is not None: response['userQuestBattleList'] = userQuestBattleList

# add to user history
pullId = str(uuid1())
if not os.path.exists('data/user/gachaHistory'):
Expand Down
13 changes: 10 additions & 3 deletions api/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

# This will only get you the lowest rarity card, but that's what all shop megucas have been...
def getCard(charaNo):
userCard, userChara, userLive2d, _ = gacha.addMeguca(charaNo)
return {'userCardList': [userCard], 'userCharaList': [userChara], 'userLive2dList': [userLive2d]}
userCard, userChara, userLive2d, foundExisting = gacha.addMeguca(charaNo)
response = {'userCardList': [userCard], 'userCharaList': [userChara], 'userLive2dList': [userLive2d]}

if not foundExisting:
userSectionList, userQuestBattleList = gacha.addStory(charaNo)
response['userSectionList'] = userSectionList
response['userQuestBattleList'] = userQuestBattleList

return response

def getFormation(formationId):
userFormation, exists = newUserObjectUtil.createUserFormation(formationId)
Expand Down Expand Up @@ -92,7 +99,7 @@ def obtain(item, body, args):
elif item['shopItemType'] == 'FORMATION_SHEET':
args.update(getFormation(item['formationSheet']['id']))
elif item['shopItemType'] == 'GEM':
args.update(getGems(item['genericId'], body['num']))
args.update(getGems(int(item['genericId']), body['num']))
elif item['shopItemType'] == 'GIFT':
newGifts = getGift(int(item['gift']['rewardCode'].split('_')[1]), body['num']*int(item['rewardCode'].split('_')[-1]))
args['userGiftList'] = args.get('userGiftList', []) + newGifts['userGiftList']
Expand Down
98 changes: 98 additions & 0 deletions charaTools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from util import dataUtil, newUserObjectUtil
import json

def addMissingMss():
allSectionIds = dataUtil.masterSections.keys()
userSectionIds = dataUtil.userIndices['userSectionList'].keys()
userCharaIds = dataUtil.userIndices['userCharaList'].keys() # don't need to dedupe because this already is a set
missingMSSections = [sectionId for sectionId in allSectionIds if not sectionId in userSectionIds and str(sectionId).startswith('3')]
addSections = [sectionId for sectionId in missingMSSections if int(str(sectionId)[1:5]) in userCharaIds]
userSectionList = dataUtil.readJson('data/user/userSectionList.json')
for sectionId in addSections:
userSection = {
"userId": dataUtil.userId,
"sectionId": sectionId,
"section": dataUtil.masterSections[sectionId],
"canPlay": True, #str(sectionId).endswith('1'),
"cleared": False,
"createdAt": newUserObjectUtil.nowstr()
}
userSectionList.append(userSection)
dataUtil.saveJson('data/user/userSectionList.json', userSectionList)

allBattleIds = dataUtil.masterBattles.keys()
userBattleIds = dataUtil.userIndices['userQuestBattleList'].keys()
missingMSSBattles = [battleId for battleId in allBattleIds if not battleId in userBattleIds and str(battleId).startswith('3')]
addBattles = [battleId for battleId in missingMSSBattles if int(str(battleId)[1:5]) in userCharaIds]
userQuestBattleList = dataUtil.readJson('data/user/userQuestBattleList.json')
for battleId in addBattles:
userBattle = {
"userId": dataUtil.userId,
"questBattleId": battleId,
"questBattle": dataUtil.masterBattles[battleId],
"cleared": True,
"missionStatus1": "CLEARED",
"missionStatus2": "CLEARED",
"missionStatus3": "CLEARED",
"rewardDone": True,
"createdAt": newUserObjectUtil.nowstr()
}
userQuestBattleList.append(userBattle)
dataUtil.saveJson('data/user/userQuestBattleList.json', userQuestBattleList)

def dedupeCharas():
# the problem is, every time you pull a new copy, you get a new chara
# but until the end of the session, the game is stuck on the first chara
# so we take the max episode point, and lbItemNum of the last chara
# this leaves off some episode points that were earned, but might refund some gems
finalCharas = {}
with open('data/user/userCharaList.json', encoding='utf-8') as f:
userCharaList = json.load(f)
for userChara in userCharaList:
charaId = userChara['charaId']
if charaId in finalCharas:
finalCharas[charaId]['bondsTotalPt'] = max(finalCharas[charaId]['bondsTotalPt'], userChara['bondsTotalPt'])
finalCharas[charaId]['lbItemNum'] = userChara['lbItemNum']
else:
finalCharas[charaId] = userChara

with open('data/user/userCharaList.json', 'w+', encoding='utf-8') as f:
json.dump(list(finalCharas.values()), f, ensure_ascii=False)

if __name__=='__main__':
print(
"""
My, are you here for an adjustment?
Which would you like today?
1) Add MSS for characters you've pulled
2) Get rid of extra MSS
3) N-nothing, just wanted to...visit...
"""
)
while True:
choice = input('(type 1, 2, or 3, then enter): ')
if choice == '1':
addMissingMss()
print('Here you go.')
if choice == '2':
dedupeCharas()
print('Done. Oh, I might have accidentally touched some other bits of your fate, like giving you extra destiny gems -- but that shouldn\'t bother you too much.')
if choice == '3':
print()
print('Ooh, I\'m flattered. I\'ll always be here when you need me for adjustment, \'kay?')
input('(enter to close)')
exit(0)
print()

print('Is that all for today?')
while(True):
choice = input('(Y/N): ')
if choice.lower() == 'y':
print()
print('Thanks, come again!')
input('(enter to close)')
exit(0)
if choice.lower() == 'n':
break
print('Sorry, what was that?')
22 changes: 20 additions & 2 deletions util/dataUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def createIndexFromList(xs, idFunc=idxFunc('id'), valFunc=INDEX_VALFUNC):
'userGiftList': createIndex('data/user/userGiftList.json', idxFunc('giftId')),
'userItemList': createIndex('data/user/userItemList.json', idxFunc('itemId')),
'userLimitedChallengeList': createIndex('data/user/userLimitedChallengeList.json', idxFunc('challengeId')),
'userLive2dList': createIndex('data/user/userLimitedChallengeList.json',
'userLive2dList': createIndex('data/user/userLive2dList.json',
lambda x: int(str(x['charaId'])+x['live2dId']),
valFunc=ITEM_VALFUNC),
valFunc=INDEX_VALFUNC),
'userPieceList': createIndex('data/user/userPieceList.json'),
'userPieceCollectionList': createIndex('data/user/userPieceCollectionList.json', idxFunc('pieceId')),
'userPieceSetList': createIndex('data/user/userPieceSetList.json', idxFunc('setNum')),
Expand All @@ -63,6 +63,9 @@ def createIndexFromList(xs, idFunc=idxFunc('id'), valFunc=INDEX_VALFUNC):
# Doesn't work for userShopItemList, but we're having separate cases for that anyways
userPaths = {key: 'data/user/'+key+'.json' for key in userIndices.keys()}

def listUserObjectKeys(listName):
return set(userIndices[listName].keys())

def deleteUserObject(listName, objectId):
path = userPaths[listName]
data = readJson(path)
Expand Down Expand Up @@ -100,6 +103,21 @@ def setUserObject(listName, objectId, objectData):
saveJson(path, data)
return data

def batchSetUserObject(listName, objectDict):
path = userPaths[listName]
data = readJson(path)

for objectId, objectData in objectDict.items():
if objectId in userIndices[listName]:
idx = userIndices[listName][objectId]
data[idx] = objectData
else:
userIndices[listName][objectId] = len(data)
data.append(objectData)

saveJson(path, data)
return data

def getGameUserValue(key):
gameUser = readJson('data/user/gameUser.json')
if not key in gameUser:
Expand Down

0 comments on commit 1b5d4d6

Please sign in to comment.