Bootstrap new actors from bank account creation
- Move starting bank credit and actor bootstrap to bank account creation - Rename bank store init function to `initBankStore`
This commit is contained in:
parent
9b31184f0c
commit
7b7eb2a0f0
@ -1 +1,28 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
if (isNil QEGVAR(common,EventBus)) then { call EFUNC(common,eventBus); };
|
||||||
|
if (isNil QGVAR(BankAccountCreatedEventTokens)) then {
|
||||||
|
private _bootstrapNewActorFromBankAccount = {
|
||||||
|
params ["_event"];
|
||||||
|
|
||||||
|
private _uid = _event getOrDefault ["uid", ""];
|
||||||
|
if (_uid isEqualTo "" || { isNil QGVAR(ActorStore) }) exitWith {};
|
||||||
|
|
||||||
|
private _actor = GVAR(ActorStore) call ["get", [_uid, ""]];
|
||||||
|
if !(_actor isEqualType createHashMap) then {
|
||||||
|
_actor = createHashMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_actor isEqualTo createHashMap) then {
|
||||||
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
||||||
|
_actor = GVAR(ActorModel) call ["fromPlayer", [_player]];
|
||||||
|
_actor set ["uid", _uid];
|
||||||
|
};
|
||||||
|
|
||||||
|
GVAR(ActorStore) call ["bootstrapNewActor", [_uid, _actor]];
|
||||||
|
};
|
||||||
|
|
||||||
|
GVAR(BankAccountCreatedEventTokens) = [
|
||||||
|
EGVAR(common,EventBus) call ["on", ["bank.account.created", _bootstrapNewActorFromBankAccount, "actor.newActor.bootstrap"]]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|||||||
@ -203,51 +203,12 @@ GVAR(ActorBaseStore) = compileFinal createHashMapFromArray [
|
|||||||
|
|
||||||
true
|
true
|
||||||
}],
|
}],
|
||||||
["grantNewActorStartingBankCredit", compileFinal {
|
|
||||||
params [["_uid", "", [""]], ["_amount", 2000, [0]]];
|
|
||||||
|
|
||||||
if (_uid isEqualTo "" || { _amount <= 0 }) exitWith { false };
|
|
||||||
if (isNil QEGVAR(bank,BankStore) || { isNil QEGVAR(bank,BankMessenger) }) exitWith {
|
|
||||||
["WARNING", format ["Unable to grant new actor starting bank credit for %1: bank store or messenger is unavailable.", _uid]] call EFUNC(common,log);
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
private _account = EGVAR(bank,BankStore) call ["get", [_uid, ""]];
|
|
||||||
if (_account isEqualTo createHashMap) then {
|
|
||||||
_account = EGVAR(bank,BankStore) call ["init", [_uid]];
|
|
||||||
};
|
|
||||||
if (_account isEqualTo createHashMap) exitWith {
|
|
||||||
["WARNING", format ["Unable to grant new actor starting bank credit for %1: bank account could not be initialized.", _uid]] call EFUNC(common,log);
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
private _currentBank = _account getOrDefault ["bank", 0];
|
|
||||||
if !(_currentBank isEqualType 0) then { _currentBank = 0; };
|
|
||||||
|
|
||||||
private _patch = EGVAR(bank,BankStore) call [
|
|
||||||
"mset",
|
|
||||||
[
|
|
||||||
_uid,
|
|
||||||
createHashMapFromArray [["bank", _currentBank + _amount]],
|
|
||||||
true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
if (_patch isEqualTo createHashMap) exitWith {
|
|
||||||
["WARNING", format ["Unable to grant new actor starting bank credit for %1: bank account update failed.", _uid]] call EFUNC(common,log);
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
EGVAR(bank,BankMessenger) call ["sendAccountSync", [_uid, _patch]];
|
|
||||||
|
|
||||||
true
|
|
||||||
}],
|
|
||||||
["bootstrapNewActor", compileFinal {
|
["bootstrapNewActor", compileFinal {
|
||||||
params [["_uid", "", [""]], ["_actor", createHashMap, [createHashMap]]];
|
params [["_uid", "", [""]], ["_actor", createHashMap, [createHashMap]]];
|
||||||
|
|
||||||
if (_uid isEqualTo "") exitWith { false };
|
if (_uid isEqualTo "") exitWith { false };
|
||||||
|
|
||||||
_self call ["sendNewActorWelcomeComms", [_uid, _actor]];
|
_self call ["sendNewActorWelcomeComms", [_uid, _actor]];
|
||||||
_self call ["grantNewActorStartingBankCredit", [_uid, 2000]];
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}],
|
}],
|
||||||
@ -307,8 +268,6 @@ GVAR(ActorBaseStore) = compileFinal createHashMapFromArray [
|
|||||||
_createdActor = +_actor;
|
_createdActor = +_actor;
|
||||||
};
|
};
|
||||||
_createdActor = GVAR(ActorModel) call ["migrate", [_createdActor]];
|
_createdActor = GVAR(ActorModel) call ["migrate", [_createdActor]];
|
||||||
_self call ["bootstrapNewActor", [_uid, _createdActor]];
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}],
|
}],
|
||||||
["hydrateActorIfNeeded", compileFinal {
|
["hydrateActorIfNeeded", compileFinal {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
PREP(initBank);
|
PREP(initBank);
|
||||||
|
PREP(initBankStore);
|
||||||
PREP(initMessenger);
|
PREP(initMessenger);
|
||||||
PREP(initModel);
|
PREP(initModel);
|
||||||
PREP(initPayloadBuilder);
|
PREP(initPayloadBuilder);
|
||||||
PREP(initSessionManager);
|
PREP(initSessionManager);
|
||||||
PREP(initStore);
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "..\script_component.hpp"
|
#include "..\script_component.hpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* File: fnc_initStore.sqf
|
* File: fnc_initBankStore.sqf
|
||||||
* Author: IDSolutions
|
* Author: IDSolutions
|
||||||
* Date: 2025-12-17
|
* Date: 2025-12-17
|
||||||
* Last Update: 2026-04-02
|
* Last Update: 2026-04-02
|
||||||
@ -330,12 +330,14 @@ GVAR(BankBaseStore) = compileFinal createHashMapFromArray [
|
|||||||
};
|
};
|
||||||
|
|
||||||
private _finalAccount = createHashMap;
|
private _finalAccount = createHashMap;
|
||||||
|
private _wasCreated = false;
|
||||||
if (_result isEqualTo "true") then {
|
if (_result isEqualTo "true") then {
|
||||||
_finalAccount = _self call ["loadHotBank", [_uid, true, _playerName]];
|
_finalAccount = _self call ["loadHotBank", [_uid, true, _playerName]];
|
||||||
["INFO", format ["Found bank account for %1", _uid]] call EFUNC(common,log);
|
["INFO", format ["Found bank account for %1", _uid]] call EFUNC(common,log);
|
||||||
} else {
|
} else {
|
||||||
_finalAccount = GVAR(BankModel) call ["fromPlayer", [_player]];
|
_finalAccount = GVAR(BankModel) call ["fromPlayer", [_player]];
|
||||||
_finalAccount set ["uid", _uid];
|
_finalAccount set ["uid", _uid];
|
||||||
|
_finalAccount set ["bank", 2000];
|
||||||
if ((_finalAccount getOrDefault ["name", ""]) isEqualTo "") then {
|
if ((_finalAccount getOrDefault ["name", ""]) isEqualTo "") then {
|
||||||
_finalAccount set ["name", _playerName];
|
_finalAccount set ["name", _playerName];
|
||||||
};
|
};
|
||||||
@ -359,6 +361,7 @@ GVAR(BankBaseStore) = compileFinal createHashMapFromArray [
|
|||||||
};
|
};
|
||||||
|
|
||||||
_finalAccount = _self call ["loadHotBank", [_uid, true, _playerName]];
|
_finalAccount = _self call ["loadHotBank", [_uid, true, _playerName]];
|
||||||
|
_wasCreated = true;
|
||||||
["INFO", format ["Created new bank account for %1", _uid]] call EFUNC(common,log);
|
["INFO", format ["Created new bank account for %1", _uid]] call EFUNC(common,log);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,6 +373,17 @@ GVAR(BankBaseStore) = compileFinal createHashMapFromArray [
|
|||||||
|
|
||||||
_finalAccount = _self call ["normalizeAccount", [_uid, _finalAccount, _playerName]];
|
_finalAccount = _self call ["normalizeAccount", [_uid, _finalAccount, _playerName]];
|
||||||
GVAR(BankMessenger) call ["sendAccountSync", [_uid, _finalAccount, CRPC(bank,responseInitBank)]];
|
GVAR(BankMessenger) call ["sendAccountSync", [_uid, _finalAccount, CRPC(bank,responseInitBank)]];
|
||||||
|
if (_wasCreated && { !(isNil QEGVAR(common,EventBus)) }) then {
|
||||||
|
EGVAR(common,EventBus) call ["emit", [
|
||||||
|
"bank.account.created",
|
||||||
|
createHashMapFromArray [
|
||||||
|
["uid", _uid],
|
||||||
|
["account", +_finalAccount],
|
||||||
|
["playerName", _playerName]
|
||||||
|
],
|
||||||
|
createHashMapFromArray [["source", "bank"]]
|
||||||
|
]];
|
||||||
|
};
|
||||||
_finalAccount
|
_finalAccount
|
||||||
}],
|
}],
|
||||||
["get", compileFinal {
|
["get", compileFinal {
|
||||||
@ -28,7 +28,7 @@ if (isNil QEGVAR(bank,BankSessionManager)) then { call EFUNC(bank,initSessionMan
|
|||||||
if (isNil QEGVAR(bank,BankMessenger)) then { call EFUNC(bank,initMessenger); };
|
if (isNil QEGVAR(bank,BankMessenger)) then { call EFUNC(bank,initMessenger); };
|
||||||
if (isNil QEGVAR(bank,BankModel)) then { call EFUNC(bank,initModel); };
|
if (isNil QEGVAR(bank,BankModel)) then { call EFUNC(bank,initModel); };
|
||||||
if (isNil QEGVAR(bank,BankPayloadBuilder)) then { call EFUNC(bank,initPayloadBuilder); };
|
if (isNil QEGVAR(bank,BankPayloadBuilder)) then { call EFUNC(bank,initPayloadBuilder); };
|
||||||
if (isNil QEGVAR(bank,BankStore)) then { call EFUNC(bank,initStore); };
|
if (isNil QEGVAR(bank,BankStore)) then { call EFUNC(bank,initBankStore); };
|
||||||
|
|
||||||
// Garage
|
// Garage
|
||||||
if (isNil QEGVAR(garage,GarageStore)) then { call EFUNC(garage,initGarageStore); };
|
if (isNil QEGVAR(garage,GarageStore)) then { call EFUNC(garage,initGarageStore); };
|
||||||
|
|||||||
2
docus/dist/sitemap.xml
vendored
2
docus/dist/sitemap.xml
vendored
@ -99,4 +99,4 @@
|
|||||||
<url>
|
<url>
|
||||||
<loc>/</loc>
|
<loc>/</loc>
|
||||||
</url>
|
</url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user