Lorsque le service Gacha est effectivement exploité, il est nécessaire d'ajouter régulièrement de nouveaux éléments.
Dans la structure de données jusqu'à précédente, il était nécessaire de réécrire les informations d'élément gacha
lorsqu'il était temps d'ajouter un élément.
Par conséquent, considérons une structure de données qui répond aux demandes de fonction suivantes.
――Je souhaite définir la période de mise en œuvre de gacha
gacha
id | start_time | end_time | gacha_group | gacha_lottery_id |
---|---|---|---|---|
1 | 2020-05-01 00:00:00 | 2020-05-31 23:59:59 | A | normal_1 |
2 | 2020-05-01 00:00:00 | 2020-05-31 23:59:59 | A | normal_11 |
3 | 2020-05-25 00:00:00 | 2020-05-31 23:59:59 | B | fighter_2 |
4 | 2020-06-01 00:00:00 | 2020-06-04 23:59:59 | C | omake_2_11 |
5 | 2020-05-20 00:00:00 | 2020-05-31 23:59:59 | A | omake_fighter_6 |
6 | 2020-06-01 00:00:00 | 2020-06-30 23:59:59 | C | normal_1 |
7 | 2020-06-01 00:00:00 | 2020-06-30 23:59:59 | C | normal_11 |
Les identifiants des lettres bleues (1 et 2) </ font> et lettres rouges (6 et 7) </ font> utilisent respectivement le même gacha_lottery_id. , Le groupe cible de loterie à utiliser diffère comme suit.
C
Si vous définissez chaque période de cette manière, vous pouvez basculer sans mettre à jour les informations de l'élément gacha à ce moment-là. Les paramètres sont résumés ci-dessous.
--Début et fin de la période d'implémentation de gacha (heure_début, heure_fin) --Groupe cible de loterie (gacha_group) pendant la période
gacha_lottery
id | item_type | times | rarity | omake_times | omake_rarity | cost |
---|---|---|---|---|---|---|
normal_1 | 0 | 1 | 0 | 0 | 0 | 10 |
normal_11 | 0 | 10 | 0 | 1 | 3 | 100 |
fighter_2 | 0 | 2 | 0 | 0 | 0 | 30 |
omake_2_11 | 0 | 9 | 2 | 2 | 3 | 150 |
omake_fighter_6 | 2 | 5 | 0 | 1 | 3 | 100 |
La gestion du groupe cible de la loterie (gacha_group) sera transférée vers Gacha information
, et les informations seront liées les unes aux autres par gacha_lottery_id.
`Le préfixe de groupe (A ou B) a été supprimé de l'ID car il ne contient plus d'élément de groupe de contrôle de loterie (gacha_group) ''
gacha.py
import random
from datetime import datetime
def gacha(lots, times: int=1) -> list:
return random.choices(tuple(lots), weights=lots.values(), k=times)
def get_rarity_name(rarity: int) -> str:
rarity_names = {5: "UR", 4: "SSR", 3: "SR", 2: "R", 1: "N"}
return rarity_names[rarity]
#Dictionnaire d'information Gacha
def get_gacha_info(now_time: int) -> dict:
gachas = {
1: {"start_time": "2020-05-01 00:00:00", "end_time": "2020-05-31 23:59:59", "gacha_group": "A",
"gacha_lottery_id": "normal_1"},
2: {"start_time": "2020-05-01 00:00:00", "end_time": "2020-05-31 23:59:59", "gacha_group": "A",
"gacha_lottery_id": "normal_11"},
3: {"start_time": "2020-05-25 00:00:00", "end_time": "2020-05-31 23:59:59", "gacha_group": "B",
"gacha_lottery_id": "fighter_2"},
4: {"start_time": "2020-06-01 00:00:00", "end_time": "2020-06-04 23:59:59", "gacha_group": "C",
"gacha_lottery_id": "omake_2_11"},
5: {"start_time": "2020-05-20 00:00:00", "end_time": "2020-05-31 23:59:59", "gacha_group": "A",
"gacha_lottery_id": "omake_fighter_6"},
6: {"start_time": "2020-06-01 00:00:00", "end_time": "2020-06-30 23:59:59", "gacha_group": "C",
"gacha_lottery_id": "normal_1"},
7: {"start_time": "2020-06-01 00:00:00", "end_time": "2020-06-30 23:59:59", "gacha_group": "C",
"gacha_lottery_id": "normal_11"}
}
results = {}
for gacha_id, info in gachas.items():
start_time = int(datetime.strptime(info["start_time"], '%Y-%m-%d %H:%M:%S').timestamp())
end_time = int(datetime.strptime(info["end_time"], '%Y-%m-%d %H:%M:%S').timestamp())
#Affinez les informations gacha cible dans la plage de la date et de l'heure
if start_time <= now_time <= end_time:
results[gacha_id] = info
return results
#Dictionnaire des informations sur la définition de la méthode gacha
def get_gacha_lottery_info(gacha_lottery_id: str) -> dict:
# gacha_Groupe transféré
gacha_lottery = {
"normal_1": {"item_type": 0, "times": 1, "rarity": 0, "omake_times": 0, "omake_rarity": 0, "cost":10},
"normal_11": {"item_type": 0, "times": 10, "rarity": 0, "omake_times": 1, "omake_rarity": 3, "cost":100},
"fighter_2": {"item_type": 0, "times": 2, "rarity": 0, "omake_times": 0, "omake_rarity": 0, "cost":30},
"omake_2_11": {"item_type": 0, "times": 9, "rarity": 2, "omake_times": 2, "omake_rarity": 3, "cost":150},
"omake_fighter_6": {"item_type": 2, "times": 5, "rarity": 0, "omake_times": 1, "omake_rarity": 3, "cost":100}
}
return gacha_lottery[gacha_lottery_id]
def set_gacha(items: dict, gacha_items: dict):
#Inclure les informations d'élément requises pour les paramètres gacha dans les informations d'élément gacha
dic_gacha_items = {}
for gacha_item_id, info in gacha_items.items():
info["item_info"] = items[info["item_id"]]
dic_gacha_items[gacha_item_id] = info
#Extraire la liste des cibles de loterie
def get_lots(lottery_info: dict):
lots = {}
omake_lots = {}
for id, info in dic_gacha_items.items():
if lottery_info["gacha_group"] != info["gacha_group"]:
continue
if lottery_info["item_type"] and lottery_info["item_type"] != info["item_info"]["item_type"]:
continue
if not(lottery_info["rarity"]) or lottery_info["rarity"] <= info["item_info"]["rarity"]:
lots[id] = info["weight"]
if lottery_info["omake_times"]:
if not(lottery_info["omake_rarity"]) or lottery_info["omake_rarity"] <= info["item_info"]["rarity"]:
omake_lots[id] = info["weight"]
return lots, omake_lots
#Exécution de Gacha
def exec(gacha_lottery_id: str, now_time: int=0) -> list:
if not now_time: now_time = int(datetime.now().timestamp())
#Obtenir des informations gacha exécutables
gachas = get_gacha_info(now_time)
lottery_info = get_gacha_lottery_info(gacha_lottery_id)
ids = []
for gacha_id, gacha_info in gachas.items():
if gacha_lottery_id == gacha_info["gacha_lottery_id"]:
lottery_info["gacha_group"] = gacha_info["gacha_group"]
print("==%s==:gacha_group:%s" % (gacha_lottery_id, lottery_info["gacha_group"]))
lots, omake_lots =get_lots(lottery_info)
ids = gacha(lots, lottery_info["times"])
if len(omake_lots) > 0:
ids.extend(gacha(omake_lots, lottery_info["omake_times"]))
return ids
return exec
def main():
#Informations sur l'élément
items = {
5101: {"rarity": 5, "item_name": "UR_Courageux", "item_type": 1, "hp": 1200},
4201: {"rarity": 4, "item_name": "SSR_guerrier", "item_type": 2, "hp": 1000},
4301: {"rarity": 4, "item_name": "SSR_sorcier", "item_type": 3, "hp": 800},
4401: {"rarity": 4, "item_name": "SSR_Prêtre", "item_type": 4, "hp": 800},
3201: {"rarity": 3, "item_name": "SR_guerrier", "item_type": 2, "hp": 600},
3301: {"rarity": 3, "item_name": "SR_sorcier", "item_type": 3, "hp": 500},
3401: {"rarity": 3, "item_name": "SR_Prêtre", "item_type": 4, "hp": 500},
2201: {"rarity": 2, "item_name": "R_guerrier", "item_type": 2, "hp": 400},
2301: {"rarity": 2, "item_name": "R_sorcier", "item_type": 3, "hp": 300},
2401: {"rarity": 2, "item_name": "R_Prêtre", "item_type": 4, "hp": 300},
3199: {"rarity": 3, "item_name": "SR_Courageux", "item_type": 1, "hp": 600},
#Ajouté ci-dessous
4101: {"rarity": 4, "item_name": "SSR_Courageux", "item_type": 1, "hp": 1000},
5201: {"rarity": 5, "item_name": "UR_guerrier", "item_type": 2, "hp": 1300},
5301: {"rarity": 5, "item_name": "UR_sorcier", "item_type": 3, "hp": 1000},
}
#Informations sur l'article Gacha
gacha_items = {
1: {"gacha_group": "A", "weight": 3, "item_id": 5101},
2: {"gacha_group": "A", "weight": 9, "item_id": 4201},
3: {"gacha_group": "A", "weight": 9, "item_id": 4301},
4: {"gacha_group": "A", "weight": 9, "item_id": 4401},
5: {"gacha_group": "A", "weight": 20, "item_id": 3201},
6: {"gacha_group": "A", "weight": 20, "item_id": 3301},
7: {"gacha_group": "A", "weight": 20, "item_id": 3401},
8: {"gacha_group": "A", "weight": 40, "item_id": 2201},
9: {"gacha_group": "A", "weight": 40, "item_id": 2301},
10: {"gacha_group": "A", "weight": 40, "item_id": 2401},
11: {"gacha_group": "B", "weight": 15, "item_id": 4201},
12: {"gacha_group": "B", "weight": 30, "item_id": 3201},
13: {"gacha_group": "B", "weight": 55, "item_id": 2201},
#Ajouté ci-dessous
14: {"gacha_group": "C", "weight": 1, "item_id": 5101},
15: {"gacha_group": "C", "weight": 1, "item_id": 5201},
16: {"gacha_group": "C", "weight": 1, "item_id": 5301},
17: {"gacha_group": "C", "weight": 9, "item_id": 4101},
18: {"gacha_group": "C", "weight": 6, "item_id": 4201},
19: {"gacha_group": "C", "weight": 6, "item_id": 4301},
20: {"gacha_group": "C", "weight": 6, "item_id": 4401},
21: {"gacha_group": "C", "weight": 20, "item_id": 3201},
22: {"gacha_group": "C", "weight": 20, "item_id": 3301},
23: {"gacha_group": "C", "weight": 20, "item_id": 3401},
24: {"gacha_group": "C", "weight": 40, "item_id": 2201},
25: {"gacha_group": "C", "weight": 40, "item_id": 2301},
26: {"gacha_group": "C", "weight": 40, "item_id": 2401},
}
#Gacha taple à réaliser
gacha_lottery_ids = (
"normal_1","normal_11","fighter_2","omake_2_11","omake_fighter_6"
)
#Spécifiez la date et l'heure d'exécution de gacha pour vérifier l'opération
now_time = int(datetime.strptime("2020-06-01 00:00:00", '%Y-%m-%d %H:%M:%S').timestamp())
#Définir les éléments, etc.
func_gacha = set_gacha(items, gacha_items)
# gacha_lottery_Exécuter gacha en définissant l'id
for gacha_lottery_id in gacha_lottery_ids:
ids = func_gacha(gacha_lottery_id,now_time)
for id in ids:
item_info = items[gacha_items[id]["item_id"]]
print("ID:%d, %s, %s" % (id, get_rarity_name(item_info["rarity"]), item_info["item_name"]))
if __name__ == '__main__':
main()
Le programme est écrit de manière à ce que le gacha soit exécuté en spécifiant gacha_lottery_id
afin qu'il soit facile de comprendre que le groupe gacha cible est commuté en fonction de la date et de l'heure d'exécution.
==normal_1==:gacha_group:C
ID:26, R, R_Prêtre
==normal_11==:gacha_group:C
ID:25, R, R_sorcier
ID:22, SR, SR_sorcier
ID:26, R, R_Prêtre
ID:24, R, R_guerrier
ID:25, R, R_sorcier
ID:21, SR, SR_guerrier
ID:15, UR, UR_guerrier
ID:24, R, R_guerrier
ID:23, SR, SR_Prêtre
ID:24, R, R_guerrier
ID:21, SR, SR_guerrier
==omake_2_11==:gacha_group:C
ID:21, SR, SR_guerrier
ID:25, R, R_sorcier
ID:24, R, R_guerrier
ID:21, SR, SR_guerrier
ID:23, SR, SR_Prêtre
ID:25, R, R_sorcier
ID:23, SR, SR_Prêtre
ID:18, SSR, SSR_guerrier
ID:25, R, R_sorcier
ID:23, SR, SR_Prêtre
ID:17, SSR, SSR_Courageux
Dans le jeu réel, comme indiqué dans le flux ci-dessous, le gacha sera exécuté en spécifiant gacha_id
, donc la configuration du programme sera légèrement différente.
Recommended Posts