Skip to content

Commit

Permalink
add new bank building to increase the deposit limit (#17)
Browse files Browse the repository at this point in the history
Invests into #6
  • Loading branch information
bratkartoffel authored Jan 28, 2023
2 parents 00f536b + d7e9018 commit 5b1c03e
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- (gebaeude) add new bank building to increase the deposit limit

### Fixed

- fix some minor inconsistencies for `Forschung`-columns in `mitglieder` database table
Expand Down
3 changes: 2 additions & 1 deletion actions/bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
if ($data === null) {
redirectTo('/?p=bank', 112, __LINE__);
}
$depositLimit = pow(2, $data['Gebaeude' . building_bank]) * Config::getInt(Config::SECTION_BANK, 'deposit_limit');

switch ($art) {
// deposit money
case 1:
if ($betrag > $data['Geld'] || $data['Bank'] + $betrag > Config::getInt(Config::SECTION_BANK, 'deposit_limit')) {
if ($betrag > $data['Geld'] || $data['Bank'] + $betrag > $depositLimit) {
redirectTo(sprintf('/?p=bank&art=%d&betrag=%f', $art, $betrag), 110, __LINE__);
}

Expand Down
2 changes: 1 addition & 1 deletion actions/gebaeude.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
restrictSitter('Gebaeude');

$was = getOrDefault($_POST, 'was', 0);
$data = Database::getInstance()->getPlayerMoneyAndBuildingLevelsAndExpenseMafia($_SESSION['blm_user']);
$data = Database::getInstance()->getPlayerMoneyAndBuildingLevelsAndExpenseMafiaAndEinnahmenZinsen($_SESSION['blm_user']);
requireEntryFound($data, '/?p=gebaeude', 112, __LINE__);
$buildingData = calculateBuildingDataForPlayer($was, $data);

Expand Down
10 changes: 9 additions & 1 deletion config/config-defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ factor_duration = 1.28
mafia_bonus = 0.025

[bank]
; building data for bank
base_cost = 200000
base_duration = 43200
factor_cost = 1.70
factor_duration = 1.60
; minimum interest rate (1 = 100%, 0.5 = 50%, 0 = 0%)
interest_debit_rate_min = 0.011
; maximum interest rate (1 = 100%, 0.5 = 50%, 0 = 0%)
Expand All @@ -267,7 +272,8 @@ interest_debit_rate_max = 0.015
interest_credit_rate_min = 0.017
; maximum credit rate (1 = 100%, 0.5 = 50%, 0 = 0%)
interest_credit_rate_max = 0.023
; maximum amount a user may deposit on the bank account
; base amount a user may deposit on the bank account
; each level of the building doubles this amount
deposit_limit = 100000
; maximum amount a user may overdraw a bank account
credit_limit = -15000
Expand Down Expand Up @@ -398,6 +404,8 @@ Gebaeude6 = 0
Gebaeude7 = 0
; Pizzeria
Gebaeude8 = 0
; Bankschliessfach
Gebaeude9 = 0
; Kartoffeln
Forschung1 = 1
; Karotten
Expand Down
7 changes: 4 additions & 3 deletions cronjobs/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ function CheckAllAuftraege(Database $database): void
function handleInterestRates(Database $database): void
{
$interestRates = calculateInterestRates();
$entries = $database->getAllPlayerIdAndBankAndBioladenAndDoenerstand();
$entries = $database->getAllPlayerIdAndBankAndBioladenAndDoenerstandAndBank();
foreach ($entries as $entry) {
$database->updateTableEntryCalculate(Database::TABLE_USERS, $entry['ID'],
array('Geld' => getIncome($entry['Gebaeude' . building_shop], $entry['Gebaeude' . building_kebab_stand])));
$database->updateTableEntryCalculate(Database::TABLE_STATISTICS, null,
array('EinnahmenGebaeude' => getIncome($entry['Gebaeude' . building_shop], $entry['Gebaeude' . building_kebab_stand])),
array('user_id = :whr0' => $entry['ID']));

if ($entry['Bank'] > Config::getInt(Config::SECTION_BANK, 'deposit_limit')) continue;
$depositLimit = pow(2, $entry['Gebaeude' . building_bank]) * Config::getInt(Config::SECTION_BANK, 'deposit_limit');
if ($entry['Bank'] >= $depositLimit) continue;

if ($entry['Bank'] >= 0) {
$amount = $entry['Bank'] * $interestRates['Debit'];
$amount = min(Config::getInt(Config::SECTION_BANK, 'deposit_limit'), $entry['Bank'] + $amount) - $entry['Bank'];
$amount = min($depositLimit, $entry['Bank'] + $amount) - $entry['Bank'];
} else {
$amount = $entry['Bank'] * $interestRates['Credit'];
}
Expand Down
10 changes: 5 additions & 5 deletions include/database.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public function getPlayerDataById(int $id): ?array

public function getPlayerNameAndBankAndMoneyAndGroupById(int $id): ?array
{
$stmt = $this->prepare("SELECT Name, Bank, Geld, Gruppe FROM " . self::TABLE_USERS . " WHERE ID = :id");
$stmt = $this->prepare("SELECT Name, Bank, Geld, Gruppe, Gebaeude9 FROM " . self::TABLE_USERS . " WHERE ID = :id");
$stmt->bindParam("id", $id, PDO::PARAM_INT);
return $this->executeAndExtractFirstRow($stmt);
}
Expand Down Expand Up @@ -1094,10 +1094,10 @@ public function getPlayerPointsAndGruppeAndMoneyAndNextMafiaAndPizzeriaById(int
return $this->executeAndExtractFirstRow($stmt);
}

public function getPlayerMoneyAndBuildingLevelsAndExpenseMafia(int $id): ?array
public function getPlayerMoneyAndBuildingLevelsAndExpenseMafiaAndEinnahmenZinsen(int $id): ?array
{
$stmt = $this->prepare("SELECT m.Geld, m.Gebaeude1, m.Gebaeude2, m.Gebaeude3, m.Gebaeude4,
m.Gebaeude5, m.Gebaeude6, m.Gebaeude7, m.Gebaeude8, s.AusgabenMafia
m.Gebaeude5, m.Gebaeude6, m.Gebaeude7, m.Gebaeude8, m.Gebaeude9, s.AusgabenMafia, s.EinnahmenZinsen
FROM " . self::TABLE_USERS . " m INNER JOIN " . self::TABLE_STATISTICS . " s ON m.ID = s.user_id
WHERE m.ID = :id");
$stmt->bindParam("id", $id, PDO::PARAM_INT);
Expand Down Expand Up @@ -1305,9 +1305,9 @@ public function getMessageByIdAndAnOrVonEquals(int $id, int $blm_user): ?array
return $this->executeAndExtractFirstRow($stmt);
}

public function getAllPlayerIdAndBankAndBioladenAndDoenerstand(): ?array
public function getAllPlayerIdAndBankAndBioladenAndDoenerstandAndBank(): ?array
{
return $this->executeAndExtractRows($this->prepare("SELECT ID, Bank, Gebaeude3, Gebaeude4 FROM " . self::TABLE_USERS . " WHERE ID > 0 AND EmailAct IS NULL"));
return $this->executeAndExtractRows($this->prepare("SELECT ID, Bank, Gebaeude3, Gebaeude4, Gebaeude9 FROM " . self::TABLE_USERS . " WHERE ID > 0 AND EmailAct IS NULL"));
}

public function getAllPlayerIdAndResearchLevels(): ?array
Expand Down
10 changes: 9 additions & 1 deletion include/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
const building_school = 6;
const building_fence = 7;
const building_pizzeria = 8;
const building_bank = 9;

// enum constants for items
const item_potatoes = 1;
Expand Down Expand Up @@ -60,7 +61,7 @@
const count_wares = 15;

// number of implemented items
const count_buildings = 8;
const count_buildings = 9;

function abortWithErrorPage(string $body)
{
Expand Down Expand Up @@ -567,6 +568,8 @@ function getBuildingName(int $building_id): string
return 'Zaun';
case building_pizzeria:
return 'Pizzeria';
case building_bank:
return 'Bankschliessfach';
default:
trigger_error(sprintf('invalid building_id given: %d', $building_id), E_USER_ERROR);
}
Expand Down Expand Up @@ -1195,6 +1198,8 @@ function buildingRequirementsMet(int $building_id, array $player): bool
return $player[$attribute] > 0 || ($player['AusgabenMafia'] >= 10000 && $player['Gebaeude' . building_plantage] > 9);
case building_pizzeria:
return $player[$attribute] > 0 || ($player['AusgabenMafia'] >= 25000 && $player['Gebaeude' . building_plantage] > 11);
case building_bank:
return $player[$attribute] > 0 || ($player['Gebaeude' . building_plantage] >= 15 && $player['EinnahmenZinsen'] >= 100000);
default:
return false;
}
Expand Down Expand Up @@ -1258,6 +1263,9 @@ function calculateBuildingDataForPlayer(int $building_id, array $player, int $le
case building_pizzeria:
$section = Config::SECTION_PIZZERIA;
break;
case building_bank:
$section = Config::SECTION_BANK;
break;
default:
trigger_error(sprintf('Unknown building id given: %d, %d, %d', $building_id, $player['ID'], $level_increment), E_USER_ERROR);
}
Expand Down
6 changes: 6 additions & 0 deletions install/sql/20-1.11.0-add_building_bank.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- MIT Licence
-- Copyright (c) 2023 Simon Frankenberger
-- Please see LICENCE.md for complete licence text.

alter table mitglieder
add Gebaeude9 smallint(2) not null default 0 after Gebaeude8;
5 changes: 3 additions & 2 deletions pages/bank.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$art = getOrDefault($_GET, 'art', 1);
$betrag = getOrDefault($_GET, 'betrag', .0);
$interestRates = calculateInterestRates();
$depositLimit = pow(2, $data['Gebaeude' . building_bank]) * Config::getInt(Config::SECTION_BANK, 'deposit_limit');
?>
<div id="SeitenUeberschrift">
<img src="/pics/big/kwallet.webp" alt=""/>
Expand All @@ -25,7 +26,7 @@
werden jeden Tag neu ausgerechnet. Gebucht werden die Zinsen
alle <?= Config::getInt(Config::SECTION_BASE, 'cron_interval'); ?> Minuten. Die
maximale Summe, die Sie anlegen können,
sind <?= formatCurrency(Config::getInt(Config::SECTION_BANK, 'deposit_limit')); ?>, Ihr Kreditlimit sind
sind <?= formatCurrency($depositLimit); ?>, Ihr Kreditlimit sind
<span class="red"><?= formatCurrency(Config::getInt(Config::SECTION_BANK, 'credit_limit')); ?></span>.
</p>
<p>
Expand Down Expand Up @@ -73,7 +74,7 @@ function AuswahlBank(option) {
const field = document.form_bank.betrag;
const bank = <?=$data['Bank'];?>;
const hand = <?=$data['Geld'];?>;
const maxDeposit = Math.min(hand, <?=Config::getInt(Config::SECTION_BANK, 'deposit_limit'); ?> - bank).toFixed(2);
const maxDeposit = Math.min(hand, <?=$depositLimit; ?> - bank).toFixed(2);
const maxWithdraw = Math.max(0, bank).toFixed(2);
const currentValue = Number.parseFloat(field.value).toFixed(2);
// only change value if the user didn't change it yet
Expand Down
8 changes: 7 additions & 1 deletion pages/gebaeude.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

$auftraege_db = Database::getInstance()->getAllAuftraegeByVonAndWasGreaterEqualsAndWasSmaller($_SESSION['blm_user'],
job_type_factor * job_type_building, (job_type_factor * job_type_building) + job_type_factor);
$data = Database::getInstance()->getPlayerMoneyAndBuildingLevelsAndExpenseMafia($_SESSION['blm_user']);
$data = Database::getInstance()->getPlayerMoneyAndBuildingLevelsAndExpenseMafiaAndEinnahmenZinsen($_SESSION['blm_user']);

$auftraege = array();
for ($i = 0; $i < count($auftraege_db); $i++) {
Expand Down Expand Up @@ -155,6 +155,12 @@ function printBuildingInformation($playerData, $auftraege, $buildingId, $buildin
höher
sind Ihre Erfolgschancen. Dabei steigen die Chancen pro Stufe um ' . formatPercent(Config::getFloat(Config::SECTION_PIZZERIA, 'mafia_bonus')) . '.');
}

if (buildingRequirementsMet(building_bank, $data)) {
printBuildingInformation($data, $auftraege, building_bank,
'Mit wachsendem Imperium stellten Sie schnell fest, dass Ihre lokale Bank mit Ihren Einlagen überfordert ist,<br/>
und ihr Bankschlieesfach regelmässig überfüllt war. Jede Stufe dieses Gebäudes verdoppelt den maximal erlaubten Betrag in Ihrer Bank.');
}
?>

<script nonce="<?= getCspNonce(); ?>">
Expand Down
10 changes: 7 additions & 3 deletions pages/hilfe.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
- Zaun (gesenkte Erfolgschance für gegnerischen Mafiaangriff)
[b]Plantage Stufe >= 11 und Ausgaben für Mafia >= 25.000 €:[/b]
- Pizzeria (Erhöht die Erfolgschancen der Mafia)'
- Pizzeria (Erhöht die Erfolgschancen der Mafia)
[b]Plantage Stufe >= 15 und Einnahmen durch Zinsen >= 100.000 €:[/b]
- Bankschliessfach (Erhöht die Kapazität der Bank)'
),
105 => array(
'Plantage',
Expand Down Expand Up @@ -116,12 +119,13 @@
'Bank',
'Diese verwaltet Ihr Vermögen, gibt Zinsen auf Anlagen und vergibt Kredite.
Sie haben von Anfang an ein Bankkonto mit ' . formatCurrency(Config::getSection(Config::SECTION_STARTING_VALUES)['Geld']) . ' Startguthaben.
Die maximale Summe, welche Sie einzahlen können liegt bei ' . formatCurrency(Config::getInt(Config::SECTION_BANK, 'deposit_limit')) . '
Sie haben von Anfang an ein Bankkonto mit ' . formatCurrency(Config::getSection(Config::SECTION_STARTING_VALUES)['Bank']) . ' Startguthaben.
Die maximale Summe, welche Sie zu Beginn einzahlen können liegt bei ' . formatCurrency(Config::getInt(Config::SECTION_BANK, 'deposit_limit')) . '
(Bitte beachten: Bei diesem Betrag bekommen Sie auch keine Zinsen mehr!), die maximale Kreditsumme beträgt ' . formatCurrency(Config::getInt(Config::SECTION_BANK, 'credit_limit')) . '.
Die Zinsen werden alle ' . Config::getInt(Config::SECTION_BASE, 'cron_interval') . ' Minuten abgerechnet.
Das Geld auf der Bank kann nicht (im Gegensatz zum Bargeld) von anderen Spielern geklaut werden.
Die Kapazität der Bank kann mit Hilfe des Bankschliessfaches je Stufe verdoppelt werden.
[color=red]Wichtig: Falls Ihr Kontostand unter ' . formatCurrency(Config::getInt(Config::SECTION_BANK, 'dispo_limit')) . ' fällt, wird Ihr Account automatisch resettet![/color]'
),
Expand Down
Binary file modified pics/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pics/buildings.webp
Binary file not shown.
4 changes: 4 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,8 @@ div#Building_8 {
background-position: -405px -90px;
}

div#Building_9 {
background-position: -0px -180px;
}

/*endregion*/
2 changes: 1 addition & 1 deletion styles/style.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 5b1c03e

Please sign in to comment.