Some extensions and fixes

This commit is contained in:
Torsten Schulz
2025-01-28 09:55:36 +01:00
parent 2f60741116
commit 90b4f51dcb
27 changed files with 910 additions and 53 deletions

View File

@@ -5,6 +5,7 @@ import ProductType from "../../models/falukant/type/product.js";
import FalukantStockType from "../../models/falukant/type/stock.js";
import TitleOfNobility from "../../models/falukant/type/title_of_nobility.js";
import TitleRequirement from "../../models/falukant/type/title_requirement.js";
import { sequelize } from "../sequelize.js";
export const initializeFalukantPredefines = async () => {
await initializeFalukantFirstnames();
@@ -14,6 +15,7 @@ export const initializeFalukantPredefines = async () => {
await initializeFalukantTitles();
await initializeFalukantTitleRequirements();
await initializeFalukantBranchTypes();
await initializeFalukantTownProductWorth();
}
const initializeFalukantFirstnames = async () => {
@@ -342,3 +344,12 @@ async function initializeFalukantBranchTypes() {
{ labelTr: 'fullstack', baseCost: 4500},
], { ignoreDuplicates: true });
}
async function initializeFalukantTownProductWorth() {
const deleteQuery = 'delete from \"falukant_data\".\"town_product_worth\"';
const createQuery = 'insert into \"falukant_data\".\"town_product_worth\" (\"product_id\", \"region_id\", \"worth_percent\") \
select ftp.\"id\", fdr.\"id\", ROUND(40 + RANDOM() * 20) \
from \"falukant_type\".\"product\" ftp, \"falukant_data\".\"region\" fdr';
sequelize.query(deleteQuery);
sequelize.query(createQuery);
}

View File

@@ -1,5 +1,11 @@
import RegionData from "../../models/falukant/data/region.js";
import RegionType from "../../models/falukant/type/region.js";
import Relationship from "../../models/falukant/type/relationship.js";
import Mood from "../../models/falukant/type/mood.js";
import CharacterTrait from "../../models/falukant/type/character_trait.js";
import PromotionalGift from "../../models/falukant/type/promotional_gift.js";
import PromotionalGiftCharacterTrait from "../../models/falukant/predefine/promotional_gift_character_trait.js";
import PromotionalGiftMood from "../../models/falukant/predefine/promotional_gift_mood.js";
const regionTypes = [];
const regionTypeTrs = [
@@ -10,6 +16,7 @@ const regionTypeTrs = [
"county",
"city"
];
const regions = [
{ labelTr: "falukant", regionType: "country", parentTr: null },
{ labelTr: "duchy1", regionType: "duchy", parentTr: "falukant" },
@@ -22,10 +29,179 @@ const regions = [
{ labelTr: "town4", regionType: "city", parentTr: "county1" },
];
// Step 1: Initialize region types
const relationships = [
{ tr: "wooing" },
{ tr: "engaged" },
{ tr: "married" },
{ tr: "widowed" }
];
const moods = [
{ name: "happy", description: "Feeling joyful and content." },
{ name: "sad", description: "Feeling down or unhappy." },
{ name: "angry", description: "Feeling annoyed or upset." },
{ name: "calm", description: "Feeling peaceful and relaxed." },
{ name: "nervous", description: "Feeling anxious or tense." },
{ name: "excited", description: "Feeling thrilled and enthusiastic." },
{ name: "bored", description: "Feeling uninterested or tired of something." },
{ name: "fearful", description: "Feeling scared or worried about something." },
{ name: "confident", description: "Feeling self-assured and positive." },
{ name: "curious", description: "Eager to learn or know more about something." },
{ name: "hopeful", description: "Feeling optimistic about the future." },
{ name: "frustrated", description: "Feeling irritated or annoyed due to obstacles." },
{ name: "lonely", description: "Feeling isolated or missing companionship." },
{ name: "grateful", description: "Feeling thankful and appreciative." },
{ name: "jealous", description: "Feeling envious of someone or something." },
{ name: "guilty", description: "Feeling regretful or responsible for wrongdoing." },
{ name: "apathetic", description: "Feeling indifferent or lacking emotion." },
{ name: "relieved", description: "Feeling a sense of ease after a problem is resolved." },
{ name: "proud", description: "Feeling satisfaction about achievements." },
{ name: "ashamed", description: "Feeling embarrassed or guilty about something." },
];
const characterTraits = [
{ name: "brave", description: "Courageous and willing to take risks." },
{ name: "kind", description: "Compassionate and caring for others." },
{ name: "greedy", description: "Focused on acquiring material wealth." },
{ name: "wise", description: "Possesses deep understanding and insight." },
{ name: "loyal", description: "Faithful to friends or obligations." },
{ name: "cunning", description: "Skilled in achieving goals through cleverness or deceit." },
{ name: "generous", description: "Willing to give and share with others." },
{ name: "arrogant", description: "Overly proud and dismissive of others." },
{ name: "honest", description: "Truthful and sincere." },
{ name: "ambitious", description: "Driven by a strong desire to achieve success." },
{ name: "patient", description: "Able to endure delays or problems without frustration." },
{ name: "impatient", description: "Eager to act or react quickly, often without waiting." },
{ name: "selfish", description: "Focused on one's own needs and desires over others'." },
{ name: "charismatic", description: "Charming and able to inspire others." },
{ name: "empathetic", description: "Able to understand and share the feelings of others." },
{ name: "timid", description: "Shy and lacking confidence." },
{ name: "stubborn", description: "Unwilling to change one's attitude or opinion." },
{ name: "resourceful", description: "Able to find quick and clever solutions to problems." },
{ name: "reckless", description: "Acting without considering the consequences." },
{ name: "disciplined", description: "Able to control oneself and follow rules." },
{ name: "optimistic", description: "Expecting the best possible outcome." },
{ name: "pessimistic", description: "Expecting the worst possible outcome." },
{ name: "manipulative", description: "Skilled at influencing others for one's benefit." },
{ name: "independent", description: "Self-reliant and not needing others' help." },
{ name: "dependent", description: "Relying on others for support or assistance." },
{ name: "adventurous", description: "Willing to take risks and seek new experiences." },
{ name: "humble", description: "Modest and not overly proud of oneself." },
{ name: "vengeful", description: "Driven by a desire to seek revenge." },
{ name: "pragmatic", description: "Focused on practical and realistic approaches." },
{ name: "idealistic", description: "Guided by ideals and principles rather than practicality." },
];
const promotionalGifts = [
{ name: "Gold Coin", description: "A shiny gold coin as a token of appreciation.", value: 100 },
{ name: "Silk Scarf", description: "A luxurious silk scarf with elegant patterns.", value: 50 },
{ name: "Exotic Perfume", description: "A rare and enchanting fragrance.", value: 200 },
{ name: "Crystal Pendant", description: "A beautiful pendant made of pure crystal.", value: 150 },
{ name: "Leather Journal", description: "A high-quality leather-bound journal.", value: 75 },
{ name: "Fine Wine", description: "An exquisite bottle of fine wine.", value: 120 },
{ name: "Artisan Chocolate", description: "A box of handcrafted chocolates.", value: 40 },
{ name: "Pearl Necklace", description: "A stunning necklace made with real pearls.", value: 300 },
{ name: "Rare Painting", description: "A rare painting by a renowned artist.", value: 500 },
{ name: "Silver Watch", description: "An elegant silver wristwatch.", value: 250 },
{ name: "Cat", description: "A cuddly and affectionate companion.", value: 70 },
{ name: "Dog", description: "A loyal and loving pet.", value: 150 },
{ name: "Horse", description: "A majestic animal for riding or companionship.", value: 1000 },
];
const promotionalGiftTraitLinks = [
{ gift: "Gold Coin", trait: "brave", suitability: 3 },
{ gift: "Gold Coin", trait: "kind", suitability: 2 },
{ gift: "Gold Coin", trait: "greedy", suitability: 5 },
{ gift: "Gold Coin", trait: "wise", suitability: 3 },
{ gift: "Gold Coin", trait: "loyal", suitability: 2 },
{ gift: "Silk Scarf", trait: "brave", suitability: 2 },
{ gift: "Silk Scarf", trait: "kind", suitability: 5 },
{ gift: "Silk Scarf", trait: "greedy", suitability: 3 },
{ gift: "Silk Scarf", trait: "wise", suitability: 4 },
{ gift: "Silk Scarf", trait: "loyal", suitability: 3 },
{ gift: "Exotic Perfume", trait: "brave", suitability: 2 },
{ gift: "Exotic Perfume", trait: "kind", suitability: 3 },
{ gift: "Exotic Perfume", trait: "greedy", suitability: 4 },
{ gift: "Exotic Perfume", trait: "wise", suitability: 3 },
{ gift: "Exotic Perfume", trait: "loyal", suitability: 1 },
{ gift: "Crystal Pendant", trait: "brave", suitability: 4 },
{ gift: "Crystal Pendant", trait: "kind", suitability: 4 },
{ gift: "Crystal Pendant", trait: "greedy", suitability: 3 },
{ gift: "Crystal Pendant", trait: "wise", suitability: 5 },
{ gift: "Crystal Pendant", trait: "loyal", suitability: 4 },
{ gift: "Leather Journal", trait: "brave", suitability: 3 },
{ gift: "Leather Journal", trait: "kind", suitability: 3 },
{ gift: "Leather Journal", trait: "greedy", suitability: 2 },
{ gift: "Leather Journal", trait: "wise", suitability: 5 },
{ gift: "Leather Journal", trait: "loyal", suitability: 3 },
{ gift: "Cat", trait: "brave", suitability: 2 },
{ gift: "Cat", trait: "kind", suitability: 5 },
{ gift: "Cat", trait: "greedy", suitability: 2 },
{ gift: "Cat", trait: "wise", suitability: 3 },
{ gift: "Cat", trait: "loyal", suitability: 4 },
{ gift: "Dog", trait: "brave", suitability: 4 },
{ gift: "Dog", trait: "kind", suitability: 4 },
{ gift: "Dog", trait: "greedy", suitability: 1 },
{ gift: "Dog", trait: "wise", suitability: 3 },
{ gift: "Dog", trait: "loyal", suitability: 5 },
{ gift: "Horse", trait: "brave", suitability: 5 },
{ gift: "Horse", trait: "kind", suitability: 3 },
{ gift: "Horse", trait: "greedy", suitability: 2 },
{ gift: "Horse", trait: "wise", suitability: 4 },
{ gift: "Horse", trait: "loyal", suitability: 4 },
];
const promotionalGiftMoodLinks = [
{ gift: "Gold Coin", mood: "happy", suitability: 5 },
{ gift: "Gold Coin", mood: "sad", suitability: 1 },
{ gift: "Gold Coin", mood: "angry", suitability: 2 },
{ gift: "Gold Coin", mood: "calm", suitability: 3 },
{ gift: "Gold Coin", mood: "nervous", suitability: 3 },
{ gift: "Silk Scarf", mood: "happy", suitability: 4 },
{ gift: "Silk Scarf", mood: "sad", suitability: 3 },
{ gift: "Silk Scarf", mood: "angry", suitability: 2 },
{ gift: "Silk Scarf", mood: "calm", suitability: 5 },
{ gift: "Silk Scarf", mood: "nervous", suitability: 4 },
{ gift: "Exotic Perfume", mood: "happy", suitability: 5 },
{ gift: "Exotic Perfume", mood: "sad", suitability: 2 },
{ gift: "Exotic Perfume", mood: "angry", suitability: 1 },
{ gift: "Exotic Perfume", mood: "calm", suitability: 3 },
{ gift: "Exotic Perfume", mood: "nervous", suitability: 5 },
{ gift: "Crystal Pendant", mood: "happy", suitability: 4 },
{ gift: "Crystal Pendant", mood: "sad", suitability: 2 },
{ gift: "Crystal Pendant", mood: "angry", suitability: 2 },
{ gift: "Crystal Pendant", mood: "calm", suitability: 4 },
{ gift: "Crystal Pendant", mood: "nervous", suitability: 3 },
{ gift: "Leather Journal", mood: "happy", suitability: 3 },
{ gift: "Leather Journal", mood: "sad", suitability: 3 },
{ gift: "Leather Journal", mood: "angry", suitability: 1 },
{ gift: "Leather Journal", mood: "calm", suitability: 4 },
{ gift: "Leather Journal", mood: "nervous", suitability: 2 },
{ gift: "Cat", mood: "happy", suitability: 5 },
{ gift: "Cat", mood: "sad", suitability: 4 },
{ gift: "Cat", mood: "angry", suitability: 2 },
{ gift: "Cat", mood: "calm", suitability: 5 },
{ gift: "Cat", mood: "nervous", suitability: 3 },
{ gift: "Dog", mood: "happy", suitability: 5 },
{ gift: "Dog", mood: "sad", suitability: 3 },
{ gift: "Dog", mood: "angry", suitability: 4 },
{ gift: "Dog", mood: "calm", suitability: 4 },
{ gift: "Dog", mood: "nervous", suitability: 3 },
{ gift: "Horse", mood: "happy", suitability: 4 },
{ gift: "Horse", mood: "sad", suitability: 3 },
{ gift: "Horse", mood: "angry", suitability: 2 },
{ gift: "Horse", mood: "calm", suitability: 5 },
{ gift: "Horse", mood: "nervous", suitability: 4 },
];
export const initializeFalukantTypes = async () => {
await initializeFalukantTypeRegions();
}
await initializeFalukantRelationships();
await initializeFalukantMoods();
await initializeFalukantCharacterTraits();
await initializeFalukantPromotionalGifts();
await initializePromotionalGiftMoodLinks();
};
const initializeFalukantTypeRegions = async () => {
for (const regionType of regionTypeTrs) {
@@ -40,17 +216,14 @@ const initializeFalukantTypeRegions = async () => {
}
};
// Utility: Find region type object by region type
const findRegionTypeObjectByRegionType = async (regionType) => {
return regionTypes.find(region => region.labelTr === regionType) || null;
};
// Utility: Find region object by label
const findRegionObjectByLabelTr = async (labelTr) => {
return await RegionData.findOne({ where: { name: labelTr } });
};
// Step 2: Initialize regions
export const initializeFalukantRegions = async () => {
for (const region of regions) {
const regionType = await findRegionTypeObjectByRegionType(region.regionType);
@@ -58,18 +231,14 @@ export const initializeFalukantRegions = async () => {
console.error(`Region type not found for: ${region.regionType}`);
continue;
}
const parentRegion = region.parentTr
? await findRegionObjectByLabelTr(region.parentTr)
: null;
if (region.parentTr && !parentRegion) {
console.error(`Parent region not found for: ${region.parentTr}`);
continue;
}
console.log('Creating/Fetching Region:', region.labelTr, 'Type:', regionType.labelTr, 'Parent:', parentRegion?.name);
await RegionData.findOrCreate({
where: { name: region.labelTr },
defaults: {
@@ -79,3 +248,81 @@ export const initializeFalukantRegions = async () => {
});
}
};
export const initializeFalukantRelationships = async () => {
for (const relationship of relationships) {
await Relationship.findOrCreate({
where: { tr: relationship.tr },
defaults: {}
});
}
};
export const initializeFalukantMoods = async () => {
for (const mood of moods) {
await Mood.findOrCreate({
where: { tr: mood.name },
});
}
};
export const initializeFalukantCharacterTraits = async () => {
for (const trait of characterTraits) {
await CharacterTrait.findOrCreate({
where: { tr: trait.name },
});
}
};
export const initializeFalukantPromotionalGifts = async () => {
for (const gift of promotionalGifts) {
await PromotionalGift.findOrCreate({
where: { name: gift.name },
defaults: {
description: gift.description,
value: gift.value,
},
});
}
};
export const initializePromotionalGiftTraitLinks = async () => {
for (const link of promotionalGiftTraitLinks) {
const gift = await PromotionalGift.findOne({ where: { name: link.gift } });
const trait = await CharacterTrait.findOne({ where: { tr: link.trait } });
if (!gift || !trait) {
console.error(`Gift or Trait not found for: ${link.gift}, ${link.trait}`);
continue;
}
await PromotionalGiftCharacterTrait.findOrCreate({
where: {
gift_id: gift.id,
trait_id: trait.id,
},
defaults: {
suitability: link.suitability,
},
});
}
};
export const initializePromotionalGiftMoodLinks = async () => {
for (const link of promotionalGiftMoodLinks) {
const gift = await PromotionalGift.findOne({ where: { name: link.gift } });
const mood = await Mood.findOne({ where: { tr: link.mood } });
if (!gift || !mood) {
console.error(`Gift or Mood not found for: ${link.gift}, ${link.mood}`);
continue;
}
await PromotionalGiftMood.findOrCreate({
where: {
gift_id: gift.id,
mood_id: mood.id,
},
defaults: {
suitability: link.suitability,
},
});
}
};

View File

@@ -1,10 +1,15 @@
import { initializeFalukantTypes, initializeFalukantRegions } from './falukant/initializeFalukantTypes.js';
import { initializeFalukantTypes, initializeFalukantRegions, initializeFalukantRelationships,
initializeFalukantMoods, initializeFalukantCharacterTraits, initializePromotionalGiftTraitLinks } from './falukant/initializeFalukantTypes.js';
import { initializeFalukantPredefines } from './falukant/initializeFalukantPredefines.js';
const initializeFalukant = async () => {
await initializeFalukantTypes();
await initializeFalukantRegions();
await initializeFalukantPredefines();
await initializeFalukantRelationships();
await initializeFalukantMoods();
await initializeFalukantCharacterTraits();
await initializePromotionalGiftTraitLinks();
}
export default initializeFalukant;

View File

@@ -42,7 +42,6 @@ export function getUserSockets() {
export async function notifyUser(recipientHashedUserId, event, data) {
const io = getIo();
const userSockets = getUserSockets();
try {
const recipientUser = await baseService.getUserByHashedId(recipientHashedUserId);
if (recipientUser) {