156 lines
3.5 KiB
JavaScript
156 lines
3.5 KiB
JavaScript
rs.initiate();
|
|
|
|
db = db.getSiblingDB("heron");
|
|
|
|
const EffectType = {
|
|
CHAMPION_ACTION: "champion_action",
|
|
SUICIDE: "suicide",
|
|
FACTION_COMBO: "faction_combo",
|
|
|
|
CHAMPION_AMOUNT: "champion_amount",
|
|
TOTAL_DAMAGE: "total_damage",
|
|
CARD_AMOUNT: "card_amount",
|
|
ACTION_AMOUNT: "action_amount",
|
|
};
|
|
|
|
const CardRole = {
|
|
PERSONAL: "personal",
|
|
MARKET: "market",
|
|
FIRE_GEM: "fire_gem",
|
|
|
|
HUNTER: "hunter",
|
|
TRAVELER: "traveler",
|
|
CLERIC: "cleric",
|
|
FIGHTER: "fighter",
|
|
RANGER: "ranger",
|
|
THIEF: "thief",
|
|
WIZARD: "wizard",
|
|
|
|
HALF_DEMON: "half-demon",
|
|
DWARF: "dwarf",
|
|
ELF: "elf",
|
|
OGRE: "ogre",
|
|
ORC: "orc",
|
|
SMALLFOLK: "smallfolk",
|
|
};
|
|
|
|
function createEffectCondition(json, cardUUID) {
|
|
const createdCondition = {};
|
|
if (typeof json === "string") {
|
|
createdCondition.effectId = json;
|
|
if (json == EffectType.FACTION_COMBO) {
|
|
createdCondition.faction = cardUUID.faction;
|
|
}
|
|
createdCondition.amount = 1;
|
|
} else {
|
|
createdCondition.effectId = json.id;
|
|
createdCondition.amount = json.amount ?? 1;
|
|
createdCondition.cardId = json.card_id;
|
|
if (json.id == EffectType.FACTION_COMBO) {
|
|
createdCondition.faction = json.faction ?? cardUUID.faction;
|
|
}
|
|
}
|
|
return createdCondition;
|
|
}
|
|
|
|
function createEffects(json, cardUUID) {
|
|
return json.map((e) => {
|
|
const createdEffect = {
|
|
card: cardUUID,
|
|
effect: e.effect,
|
|
amount: e.amount ?? 1,
|
|
subEffects: [],
|
|
times: e.times ?? 1,
|
|
per: e.per,
|
|
faction: e.faction,
|
|
};
|
|
if (e.sub_effects) {
|
|
createdEffect.subEffects = createEffects(e.sub_effects, cardUUID);
|
|
}
|
|
|
|
if (e.effect_type) {
|
|
createdEffect.condition = createEffectCondition(e.effect_type, cardUUID);
|
|
}
|
|
|
|
if (e.mutex) {
|
|
createdEffect.mutex = e.mutex.toString();
|
|
}
|
|
|
|
const { insertedId } = db.effects.insertOne(createdEffect);
|
|
|
|
return insertedId;
|
|
});
|
|
}
|
|
|
|
function createCard(json, pack, playerIndex) {
|
|
const createdCard = {
|
|
cardId: json.id,
|
|
role: json.role,
|
|
cardType: json.card_type,
|
|
faction: json.faction,
|
|
name: json.name,
|
|
pack: pack,
|
|
playerIndex,
|
|
effects: [],
|
|
};
|
|
|
|
if (json.cost) {
|
|
createdCard.cost = json.cost;
|
|
}
|
|
|
|
if (json.defense) {
|
|
createdCard.defense = json.defense;
|
|
}
|
|
|
|
if (json.guard !== undefined) {
|
|
createdCard.guard = json.guard;
|
|
}
|
|
|
|
const { insertedId } = db.cards.insertOne(createdCard);
|
|
|
|
if (json.effects) {
|
|
db.cards.updateOne(
|
|
{ _id: insertedId },
|
|
{ $set: { effects: createEffects(json.effects, insertedId) } }
|
|
);
|
|
}
|
|
}
|
|
|
|
async function loadCards() {
|
|
const cardPath = "/cards-json";
|
|
|
|
const files = fs.readdirSync(cardPath).filter((e) => e.endsWith(".json"));
|
|
|
|
const processed = await Promise.all(
|
|
files.map(async (f) => {
|
|
return [
|
|
path.parse(f).name,
|
|
JSON.parse(fs.readFileSync(path.join(cardPath, f), "utf8")).cards,
|
|
];
|
|
})
|
|
);
|
|
|
|
Object.entries(processed)
|
|
.filter((d) => d[1] && d[1][1])
|
|
.forEach(
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
([_, data]) => {
|
|
data[1].forEach((c) => {
|
|
if (c.role == CardRole.FIRE_GEM || c.role == CardRole.MARKET) {
|
|
for (let i = 0; i < (c.init_amount ?? 1); i++) {
|
|
createCard(c, data[0]);
|
|
}
|
|
} else {
|
|
for (let j = 0; j < 4; j++) {
|
|
for (let i = 0; i < (c.init_amount ?? 1); i++) {
|
|
createCard(c, data[0], j);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
);
|
|
}
|
|
|
|
loadCards();
|