Wenn der Gacha-Dienst tatsächlich betrieben wird, müssen regelmäßig neue Elemente hinzugefügt werden. In der Datenstruktur bis vorherige war es erforderlich, die "Gacha-Artikelinformationen" neu zu schreiben, wenn es Zeit war, einen Artikel hinzuzufügen.
Betrachten wir daher eine Datenstruktur, die die folgenden Funktionsanforderungen erfüllt.
――Ich möchte den Implementierungszeitraum von Gacha festlegen
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 |
Die IDs der blauen Buchstaben (1 und 2) </ font> und roten Buchstaben (6 und 7) </ font> verwenden jeweils dieselbe gacha_lottery_id. Das zu verwendende Lotteriegruppenziel unterscheidet sich wie folgt.
Wenn Sie jeden Zeitraum auf diese Weise einstellen, können Sie wechseln, ohne die Gacha-Elementinformationen zu diesem Zeitpunkt zu aktualisieren. Die Einstellungen sind unten zusammengefasst.
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 |
Die Verwaltung der Lotterie-Zielgruppe (gacha_group) wird auf "Gacha-Informationen" übertragen, und die Informationen werden durch gacha_lottery_id miteinander verknüpft.
Das Gruppenpräfix (A oder B) wurde aus der ID entfernt, da es kein Lotteriekontrollgruppenelement (gacha_group) mehr enthält
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]
#Gacha Informationswörterbuch
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())
#Grenzen Sie die Ziel-Gacha-Informationen im Bereich von Datum und Uhrzeit ein
if start_time <= now_time <= end_time:
results[gacha_id] = info
return results
#Wörterbuch der Informationen zur Definition der Gacha-Methode
def get_gacha_lottery_info(gacha_lottery_id: str) -> dict:
# gacha_Übertragene Gruppe
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):
#Fügen Sie Artikelinformationen, die für Gacha-Einstellungen erforderlich sind, in Gacha-Artikelinformationen ein
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
#Extrahieren Sie die Lotteriezielliste
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
#Gacha Hinrichtung
def exec(gacha_lottery_id: str, now_time: int=0) -> list:
if not now_time: now_time = int(datetime.now().timestamp())
#Holen Sie sich ausführbare Gacha-Informationen
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():
#Gegenstand Information
items = {
5101: {"rarity": 5, "item_name": "UR_Mutig", "item_type": 1, "hp": 1200},
4201: {"rarity": 4, "item_name": "SSR_Krieger", "item_type": 2, "hp": 1000},
4301: {"rarity": 4, "item_name": "SSR_Magier", "item_type": 3, "hp": 800},
4401: {"rarity": 4, "item_name": "SSR_Priester", "item_type": 4, "hp": 800},
3201: {"rarity": 3, "item_name": "SR_Krieger", "item_type": 2, "hp": 600},
3301: {"rarity": 3, "item_name": "SR_Magier", "item_type": 3, "hp": 500},
3401: {"rarity": 3, "item_name": "SR_Priester", "item_type": 4, "hp": 500},
2201: {"rarity": 2, "item_name": "R_Krieger", "item_type": 2, "hp": 400},
2301: {"rarity": 2, "item_name": "R_Magier", "item_type": 3, "hp": 300},
2401: {"rarity": 2, "item_name": "R_Priester", "item_type": 4, "hp": 300},
3199: {"rarity": 3, "item_name": "SR_Mutig", "item_type": 1, "hp": 600},
#Unten hinzugefügt
4101: {"rarity": 4, "item_name": "SSR_Mutig", "item_type": 1, "hp": 1000},
5201: {"rarity": 5, "item_name": "UR_Krieger", "item_type": 2, "hp": 1300},
5301: {"rarity": 5, "item_name": "UR_Magier", "item_type": 3, "hp": 1000},
}
#Gacha-Artikelinformationen
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},
#Unten hinzugefügt
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 ausführen
gacha_lottery_ids = (
"normal_1","normal_11","fighter_2","omake_2_11","omake_fighter_6"
)
#Geben Sie das Datum und die Uhrzeit der Gacha-Ausführung an, um den Vorgang zu überprüfen
now_time = int(datetime.strptime("2020-06-01 00:00:00", '%Y-%m-%d %H:%M:%S').timestamp())
#Set Items etc.
func_gacha = set_gacha(items, gacha_items)
# gacha_lottery_Führen Sie Gacha aus, indem Sie die ID festlegen
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()
Das Programm ist so geschrieben, dass die Gacha ausgeführt wird, indem "gacha_lottery_id" angegeben wird, so dass leicht zu verstehen ist, dass die Ziel-Gacha-Gruppe abhängig vom Ausführungsdatum und der Ausführungszeit umgeschaltet wird.
==normal_1==:gacha_group:C
ID:26, R, R_Priester
==normal_11==:gacha_group:C
ID:25, R, R_Magier
ID:22, SR, SR_Magier
ID:26, R, R_Priester
ID:24, R, R_Krieger
ID:25, R, R_Magier
ID:21, SR, SR_Krieger
ID:15, UR, UR_Krieger
ID:24, R, R_Krieger
ID:23, SR, SR_Priester
ID:24, R, R_Krieger
ID:21, SR, SR_Krieger
==omake_2_11==:gacha_group:C
ID:21, SR, SR_Krieger
ID:25, R, R_Magier
ID:24, R, R_Krieger
ID:21, SR, SR_Krieger
ID:23, SR, SR_Priester
ID:25, R, R_Magier
ID:23, SR, SR_Priester
ID:18, SSR, SSR_Krieger
ID:25, R, R_Magier
ID:23, SR, SR_Priester
ID:17, SSR, SSR_Mutig
Im eigentlichen Spiel wird die Gacha, wie im folgenden Ablauf gezeigt, durch Angabe von "gacha_id" ausgeführt, sodass die Programmkonfiguration geringfügig abweicht.
Recommended Posts