Some falukant fixes, added undeground ui - no save right now, changed menu (and verification)

This commit is contained in:
Torsten Schulz
2025-07-17 14:28:52 +02:00
parent fceea5b7fb
commit 89cf12a7a8
33 changed files with 1010 additions and 423 deletions

View File

@@ -58,6 +58,8 @@ class FalukantController {
this.renovate = this.renovate.bind(this);
this.renovateAll = this.renovateAll.bind(this);
this.createBranch = this.createBranch.bind(this);
this.getUndergroundTypes = this.getUndergroundTypes.bind(this);
this.getNotifications = this.getNotifications.bind(this);
}
async getUser(req, res) {
@@ -806,6 +808,28 @@ class FalukantController {
console.log(error);
}
}
async getUndergroundTypes(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const result = await FalukantService.getUndergroundTypes(hashedUserId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
console.log(error);
}
}
async getNotifications(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const result = await FalukantService.getNotifications(hashedUserId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
console.log(error);
}
}
}
export default FalukantController;

View File

@@ -56,6 +56,19 @@ const menuStructure = {
diary: {
visible: ["all"],
path: "/socialnetwork/diary"
},
erotic: {
visible: ["over18"],
children: {
pictures: {
visible: ["over18"],
path: "/socialnetwork/erotic/pictures"
},
videos: {
visible: ["over18"],
path: "/socialnetwork/erotic/videos"
}
}
}
}
},
@@ -70,6 +83,10 @@ const menuStructure = {
randomChat: {
visible: ["over12"],
action: "openRanomChat"
},
eroticChat: {
visible: ["over18"],
action: "openEroticChat"
}
}
},
@@ -248,6 +265,8 @@ class NavigationController {
if (value.visible.includes("all")
|| value.visible.some(v => rights.includes(v) || (value.visible.includes("anyadmin") && rights.length > 0))
|| (value.visible.includes("over14") && age >= 14)
|| (value.visible.includes("over12") && age >= 12)
|| (value.visible.includes("over18") && age >= 18)
|| (value.visible.includes('nofalukantaccount') && !hasFalukantAccount)
|| (value.visible.includes('hasfalukantaccount') && hasFalukantAccount)) {
const { visible, ...itemWithoutVisible } = value;

View File

@@ -88,6 +88,8 @@ import PoliticalOfficeRequirement from './falukant/predefine/political_office_pr
import PoliticalOfficePrerequisite from './falukant/predefine/political_office_prerequisite.js';
import PoliticalOfficeHistory from './falukant/log/political_office_history.js';
import ElectionHistory from './falukant/log/election_history.js';
import Underground from './falukant/data/underground.js';
import UndergroundType from './falukant/type/underground.js';
export default function setupAssociations() {
// UserParam related associations
@@ -675,7 +677,7 @@ export default function setupAssociations() {
PoliticalOfficeType.hasMany(PoliticalOfficeHistory, {
foreignKey: 'officeTypeId',
as: 'history',
as: 'history',
});
FalukantCharacter.hasMany(PoliticalOfficeHistory, {
@@ -686,7 +688,7 @@ export default function setupAssociations() {
foreignKey: 'characterId',
as: 'character',
});
ElectionHistory.belongsTo(PoliticalOfficeType, {
foreignKey: 'officeTypeId',
as: 'officeTypeHistory',
@@ -696,5 +698,34 @@ export default function setupAssociations() {
foreignKey: 'officeTypeId',
as: 'electionHistory',
}
)
);
Underground.belongsTo(UndergroundType, {
foreignKey: 'undergroundTypeId',
as: 'undergroundType'
});
UndergroundType.hasMany(Underground, {
foreignKey: 'undergroundTypeId',
as: 'undergrounds'
});
// 2) Täter (performer)
Underground.belongsTo(FalukantCharacter, {
foreignKey: 'performerId',
as: 'performer'
});
FalukantCharacter.hasMany(Underground, {
foreignKey: 'performerId',
as: 'performedUndergrounds'
});
// 3) Opfer (victim)
Underground.belongsTo(FalukantCharacter, {
foreignKey: 'victimId',
as: 'victim'
});
FalukantCharacter.hasMany(Underground, {
foreignKey: 'victimId',
as: 'victimUndergrounds'
});
}

View File

@@ -0,0 +1,36 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class Underground extends Model { }
Underground.init({
undergroundTypeId: {
type: DataTypes.STRING,
allowNull: false,
},
performerId: {
type: DataTypes.INTEGER,
allowNull: false,
},
victimId: {
type: DataTypes.INTEGER,
allowNull: false,
},
parameters: {
type: DataTypes.JSON,
allowNull: true,
},
result: {
type: DataTypes.JSON,
allowNull: true,
}
}, {
sequelize,
modelName: 'Underground',
tableName: 'underground',
schema: 'falukant_data',
timestamps: true,
underscored: true,
});
export default Underground;

View File

@@ -0,0 +1,25 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
class UndergroundType extends Model { }
UndergroundType.init({
tr: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
cost: {
type: DataTypes.INTEGER,
allowNull: false,
}
}, {
sequelize,
modelName: 'UndergroundType',
tableName: 'underground',
schema: 'falukant_type',
timestamps: false,
underscored: true,
});
export default UndergroundType;

View File

@@ -96,6 +96,8 @@ import Vote from './falukant/data/vote.js';
import ElectionResult from './falukant/data/election_result.js';
import PoliticalOfficeHistory from './falukant/log/political_office_history.js';
import ElectionHistory from './falukant/log/election_history.js';
import UndergroundType from './falukant/type/underground.js';
import Underground from './falukant/data/underground.js';
const models = {
SettingsType,
@@ -182,8 +184,6 @@ const models = {
Credit,
DebtorsPrism,
HealthActivity,
// Politics
PoliticalOfficeType,
PoliticalOfficeRequirement,
PoliticalOfficeBenefitType,
@@ -195,6 +195,8 @@ const models = {
ElectionResult,
PoliticalOfficeHistory,
ElectionHistory,
UndergroundType,
Underground,
};
export default models;

View File

@@ -69,5 +69,7 @@ router.post('/politics/elections', falukantController.vote);
router.get('/politics/open', falukantController.getOpenPolitics);
router.post('/politics/open', falukantController.applyForElections);
router.get('/cities', falukantController.getRegions);
router.get('/underground/types', falukantController.getUndergroundTypes);
router.get('/notifications', falukantController.getNotifications);
export default router;

View File

@@ -53,6 +53,8 @@ import Candidate from '../models/falukant/data/candidate.js';
import Vote from '../models/falukant/data/vote.js';
import PoliticalOfficePrerequisite from '../models/falukant/predefine/political_office_prerequisite.js';
import PoliticalOfficeHistory from '../models/falukant/log/political_office_history.js';
import UndergroundType from '../models/falukant/type/underground.js';
import Notification from '../models/falukant/log/notification.js';
function calcAge(birthdate) {
const b = new Date(birthdate); b.setHours(0, 0);
@@ -1063,8 +1065,8 @@ class FalukantService extends BaseService {
]
});
if (regionUserDirectorProposals.length > 0) {
for (const proposal of regionUserDirectorProposals) {
await DirectorProposal.destroy();
for (const p of regionUserDirectorProposals) {
await p.destroy();
}
}
notifyUser(hashedUserId, 'directorchanged');
@@ -1772,7 +1774,7 @@ class FalukantService extends BaseService {
}
const housePrice = this.housePrice(house);
const oldHouse = await UserHouse.findOne({ where: { userId: falukantUser.id } });
if (falukantUser.money < housePrice) {
if (Number(falukantUser.money) < Number(housePrice)) {
throw new Error('notenoughmoney.');
}
if (oldHouse) {
@@ -2779,6 +2781,20 @@ class FalukantService extends BaseService {
return { cost: totalCost };
}
async getUndergroundTypes(hashedUserId) {
const user = await getFalukantUserOrFail(hashedUserId);
const undergroundTypes = await UndergroundType.findAll();
return undergroundTypes;
}
async getNotifications(hashedUserId) {
const user = await getFalukantUserOrFail(hashedUserId);
const notifications = await Notification.findAll({
where: { userId: user.id, shown: false },
order: [['createdAt', 'DESC']]
});
return user.notifications;
}
}
export default new FalukantService();

View File

@@ -14,6 +14,7 @@ import BanquetteType from "../../models/falukant/type/banquette.js";
import LearnRecipient from "../../models/falukant/type/learn_recipient.js";
import PoliticalOfficeType from "../../models/falukant/type/political_office_type.js";
import PoliticalOfficePrerequisite from "../../models/falukant/predefine/political_office_prerequisite.js";
import UndergroundType from "../../models/falukant/type/underground.js";
export const initializeFalukantTypes = async () => {
await initializeFalukantTypeRegions();
@@ -29,6 +30,7 @@ export const initializeFalukantTypes = async () => {
await initializeLearnerTypes();
await initializePoliticalOfficeTypes();
await initializePoliticalOfficePrerequisites();
await initializeUndergroundTypes();
};
const regionTypes = [];
@@ -48,10 +50,10 @@ const regions = [
{ labelTr: "Siebenbachen", regionType: "shire", parentTr: "Groß-Benbach" },
{ labelTr: "Bad Homburg", regionType: "county", parentTr: "Siebenbachen" },
{ labelTr: "Maintal", regionType: "county", parentTr: "Siebenbachen" },
{ labelTr: "Frankfurt", regionType: "city", parentTr: "Bad Homburg", map: {x: 187, y: 117, w: 10, h:11} },
{ labelTr: "Oberursel", regionType: "city", parentTr: "Bad Homburg", map: {x: 168, y: 121, w: 10, h:11} },
{ labelTr: "Offenbach", regionType: "city", parentTr: "Bad Homburg", map: {x: 171, y: 142, w: 10, h:11} },
{ labelTr: "Königstein", regionType: "city", parentTr: "Maintal", map: {x: 207, y: 124, w: 24, h:18} },
{ labelTr: "Frankfurt", regionType: "city", parentTr: "Bad Homburg", map: { x: 187, y: 117, w: 10, h: 11 } },
{ labelTr: "Oberursel", regionType: "city", parentTr: "Bad Homburg", map: { x: 168, y: 121, w: 10, h: 11 } },
{ labelTr: "Offenbach", regionType: "city", parentTr: "Bad Homburg", map: { x: 171, y: 142, w: 10, h: 11 } },
{ labelTr: "Königstein", regionType: "city", parentTr: "Maintal", map: { x: 207, y: 124, w: 24, h: 18 } },
];
const relationships = [
@@ -537,6 +539,29 @@ const politicalOfficePrerequisites = [
}
];
const undergroundTypes = [
{
"tr": "spyin",
"cost": 3000
},
{
"tr": "assassin",
"cost": 5000
},
{
"tr": "sabotage",
"cost": 10000
},
{
"tr": "corrupt_politician",
"cost": 15000
},
{
"tr": "rob",
"cost": 500
},
];
{
const giftNames = promotionalGifts.map(g => g.name);
const traitNames = characterTraits.map(t => t.name);
@@ -777,20 +802,29 @@ export const initializePoliticalOfficeTypes = async () => {
export const initializePoliticalOfficePrerequisites = async () => {
for (const prereq of politicalOfficePrerequisites) {
// zunächst den OfficeType anhand seines Namens (tr) ermitteln
const office = await PoliticalOfficeType.findOne({
where: { name: prereq.officeTr }
});
if (!office) continue;
// Nun findOrCreate mit dem neuen Spaltennamen:
await PoliticalOfficePrerequisite.findOrCreate({
where: { office_type_id: office.id },
defaults: {
office_type_id: office.id,
prerequisite: prereq.prerequisite
}
});
const office = await PoliticalOfficeType.findOne({
where: { name: prereq.officeTr }
});
if (!office) continue;
await PoliticalOfficePrerequisite.findOrCreate({
where: { office_type_id: office.id },
defaults: {
office_type_id: office.id,
prerequisite: prereq.prerequisite
}
});
}
};
};
export const initializeUndergroundTypes = async () => {
for (const underground of undergroundTypes) {
await UndergroundType.findOrCreate({
where: { tr: underground.tr },
defaults: {
tr: underground.tr,
cost: underground.cost
}
});
}
};