2024-03-22 17:27:04 +00:00
|
|
|
from typing import Optional, Dict, List
|
|
|
|
from os import walk, path
|
|
|
|
import urllib
|
2023-05-26 17:45:20 +00:00
|
|
|
import csv
|
|
|
|
|
2024-03-22 16:22:07 +00:00
|
|
|
from read import BaseReader
|
2024-03-22 17:27:04 +00:00
|
|
|
from core.config import CoreConfig
|
2024-03-22 16:22:07 +00:00
|
|
|
from titles.sao.database import SaoData
|
2024-03-22 17:27:04 +00:00
|
|
|
from titles.sao.const import SaoConstants
|
2023-05-26 17:45:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SaoReader(BaseReader):
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
config: CoreConfig,
|
|
|
|
version: int,
|
|
|
|
bin_arg: Optional[str],
|
|
|
|
opt_arg: Optional[str],
|
|
|
|
extra: Optional[str],
|
|
|
|
) -> None:
|
|
|
|
super().__init__(config, version, bin_arg, opt_arg, extra)
|
|
|
|
self.data = SaoData(config)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.logger.info(
|
|
|
|
f"Start importer for {SaoConstants.game_ver_to_string(version)}"
|
|
|
|
)
|
|
|
|
except IndexError:
|
|
|
|
self.logger.error(f"Invalid project SAO version {version}")
|
|
|
|
exit(1)
|
|
|
|
|
2024-03-23 06:01:06 +00:00
|
|
|
async def read(self) -> None:
|
|
|
|
if path.exists(self.bin_dir):
|
|
|
|
await self.read_csv(f"{self.bin_dir}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2024-03-23 06:01:06 +00:00
|
|
|
else:
|
|
|
|
self.logger.warn("Directory not found, nothing to import")
|
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
|
2024-03-23 06:01:06 +00:00
|
|
|
async def read_csv(self, bin_dir: str) -> None:
|
2023-05-26 17:45:20 +00:00
|
|
|
self.logger.info(f"Read csv from {bin_dir}")
|
|
|
|
|
|
|
|
self.logger.info("Now reading QuestScene.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/QuestScene.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
questSceneId = row["QuestSceneId"]
|
|
|
|
sortNo = row["SortNo"]
|
|
|
|
name = row["Name"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added quest {questSceneId} | Name: {name}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_quest(
|
2024-03-22 17:27:04 +00:00
|
|
|
questSceneId,
|
|
|
|
0,
|
|
|
|
sortNo,
|
|
|
|
name,
|
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
self.logger.info("Now reading HeroLog.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/HeroLog.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
heroLogId = row["HeroLogId"]
|
|
|
|
name = row["Name"]
|
|
|
|
nickname = row["Nickname"]
|
|
|
|
rarity = row["Rarity"]
|
|
|
|
skillTableSubId = row["SkillTableSubId"]
|
|
|
|
awakeningExp = row["AwakeningExp"]
|
|
|
|
flavorText = row["FlavorText"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added hero {heroLogId} | Name: {name}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_hero(
|
2023-05-26 17:45:20 +00:00
|
|
|
0,
|
|
|
|
heroLogId,
|
|
|
|
name,
|
|
|
|
nickname,
|
|
|
|
rarity,
|
|
|
|
skillTableSubId,
|
|
|
|
awakeningExp,
|
|
|
|
flavorText,
|
2024-03-22 17:27:04 +00:00
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
self.logger.info("Now reading Equipment.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/Equipment.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
equipmentId = row["EquipmentId"]
|
|
|
|
equipmentType = row["EquipmentType"]
|
|
|
|
weaponTypeId = row["WeaponTypeId"]
|
|
|
|
name = row["Name"]
|
|
|
|
rarity = row["Rarity"]
|
|
|
|
flavorText = row["FlavorText"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added equipment {equipmentId} | Name: {name}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_equipment(
|
2023-05-26 17:45:20 +00:00
|
|
|
0,
|
|
|
|
equipmentId,
|
|
|
|
name,
|
|
|
|
equipmentType,
|
|
|
|
weaponTypeId,
|
|
|
|
rarity,
|
|
|
|
flavorText,
|
2024-03-22 17:27:04 +00:00
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2023-05-26 17:45:20 +00:00
|
|
|
|
|
|
|
self.logger.info("Now reading Item.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/Item.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
itemId = row["ItemId"]
|
|
|
|
itemTypeId = row["ItemTypeId"]
|
|
|
|
name = row["Name"]
|
|
|
|
rarity = row["Rarity"]
|
|
|
|
flavorText = row["FlavorText"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added item {itemId} | Name: {name}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_item(
|
2024-03-22 17:27:04 +00:00
|
|
|
0,
|
|
|
|
itemId,
|
|
|
|
name,
|
|
|
|
itemTypeId,
|
|
|
|
rarity,
|
|
|
|
flavorText,
|
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
self.logger.info("Now reading SupportLog.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/SupportLog.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
supportLogId = row["SupportLogId"]
|
|
|
|
charaId = row["CharaId"]
|
|
|
|
name = row["Name"]
|
|
|
|
rarity = row["Rarity"]
|
|
|
|
salePrice = row["SalePrice"]
|
|
|
|
skillName = row["SkillName"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added support log {supportLogId} | Name: {name}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_support_log(
|
2023-05-26 17:45:20 +00:00
|
|
|
0,
|
|
|
|
supportLogId,
|
|
|
|
charaId,
|
|
|
|
name,
|
|
|
|
rarity,
|
|
|
|
salePrice,
|
|
|
|
skillName,
|
2024-03-22 17:27:04 +00:00
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
self.logger.info("Now reading Title.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/Title.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
titleId = row["TitleId"]
|
|
|
|
displayName = row["DisplayName"]
|
|
|
|
requirement = row["Requirement"]
|
|
|
|
rank = row["Rank"]
|
|
|
|
imageFilePath = row["ImageFilePath"]
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
self.logger.info(f"Added title {titleId} | Name: {displayName}")
|
2024-03-22 17:27:04 +00:00
|
|
|
|
2023-05-26 17:45:20 +00:00
|
|
|
if len(titleId) > 5:
|
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_title(
|
2023-05-26 17:45:20 +00:00
|
|
|
0,
|
|
|
|
titleId,
|
|
|
|
displayName,
|
|
|
|
requirement,
|
|
|
|
rank,
|
|
|
|
imageFilePath,
|
2024-03-22 17:27:04 +00:00
|
|
|
enabled
|
2023-05-26 17:45:20 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2024-03-22 17:27:04 +00:00
|
|
|
elif len(titleId) < 6: # current server code cannot have multiple lengths for the id
|
2023-05-26 17:45:20 +00:00
|
|
|
continue
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|
2023-06-03 15:42:50 +00:00
|
|
|
|
|
|
|
self.logger.info("Now reading RareDropTable.csv")
|
|
|
|
try:
|
|
|
|
fullPath = bin_dir + "/RareDropTable.csv"
|
|
|
|
with open(fullPath, encoding="UTF-8") as fp:
|
|
|
|
reader = csv.DictReader(fp)
|
|
|
|
for row in reader:
|
|
|
|
questRareDropId = row["QuestRareDropId"]
|
|
|
|
commonRewardId = row["CommonRewardId"]
|
|
|
|
enabled = True
|
|
|
|
|
2024-03-22 17:27:04 +00:00
|
|
|
self.logger.info(f"Added rare drop {questRareDropId} | Reward: {commonRewardId}")
|
|
|
|
|
2023-06-03 15:42:50 +00:00
|
|
|
try:
|
2024-03-23 06:01:06 +00:00
|
|
|
await self.data.static.put_rare_drop(
|
2024-03-22 17:27:04 +00:00
|
|
|
0,
|
|
|
|
questRareDropId,
|
|
|
|
commonRewardId,
|
|
|
|
enabled
|
2023-06-03 15:42:50 +00:00
|
|
|
)
|
|
|
|
except Exception as err:
|
2023-11-09 02:17:48 +00:00
|
|
|
self.logger.error(err)
|
2023-07-16 20:58:34 +00:00
|
|
|
except Exception:
|
2023-08-08 14:17:56 +00:00
|
|
|
self.logger.warning(f"Couldn't read csv file in {self.bin_dir}, skipping")
|