2016-04-08 20:21:46 +00:00
/*
Author: Aaron Clark - EpochMod.com
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Contributors:
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Description:
Uses Epoch server extension to perform various functions like: kick, ban, shutdown, message, unlock/lock
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_server/EPOCH_serverLootObject.sqf
2016-04-08 20:21:46 +00:00
*/
private["_randomItemArray", "_quan", "_randomLootClass", "_randomItem", "_lootPaid", "_mags", "_lootItemWeightedArray", "_lootItemArray", "_weightedItemArray", "_exit", "_maxPayout", "_lootTable", "_lootTableArray", "_weightedArray"];
2016-05-01 19:22:31 +00:00
params ["_object","_type",["_forceSpawn",false]];
2016-04-08 20:21:46 +00:00
_debug = true;
_pricingConfig = 'CfgPricing' call EPOCH_returnConfig;
2017-04-02 04:17:46 +00:00
_lootTableIndex = if (EPOCH_modCUPVehiclesEnabled) then {if (EPOCH_mod_madArma_Enabled) then {3} else {1}} else {if (EPOCH_mod_madArma_Enabled) then {2} else {0}};
_lootTableClass = ["CfgLootTable","CfgLootTable_CUP","CfgLootTable_MAD","CfgLootTable_MADCUP"] select _lootTableIndex;
2016-04-08 20:21:46 +00:00
_randomizeMagazineAmmoCount = ["CfgEpochClient", "randomizeMagazineAmmoCount", true] call EPOCH_fnc_returnConfigEntryV2;
if !(isNull _object) then{
_lootTable = [_type, "CfgMainTable", "tables"] call EPOCH_weightedArray;
_lootTable params ["_lootTableArray","_weightedArray"];
2015-09-17 16:31:04 +00:00
if !(_lootTableArray isEqualTo []) then {
_loots = [];
_config = configFile >> "CfgMainTable" >> _type;
_minLoot = getNumber(_config >> "lootMin");
_maxLoot = getNumber(_config >> "lootMax");
_maxPayout = ((random(_maxLoot) * EPOCH_lootMultiplier) min _maxLoot) max _minLoot;
for "_k" from 1 to _maxPayout do {
2016-04-08 20:21:46 +00:00
_loots pushBack (_lootTableArray select(selectRandom _weightedArray));
2015-09-17 16:31:04 +00:00
};
{
2016-04-08 20:21:46 +00:00
_lootItemWeightedArray = [_x, _lootTableClass, "items"] call EPOCH_weightedArray;
2015-09-17 16:31:04 +00:00
_lootItemArray = _lootItemWeightedArray select 0;
if !(_lootItemArray isEqualTo[]) then {
_weightedItemArray = _lootItemWeightedArray select 1;
2016-04-08 20:21:46 +00:00
_randomItemArray = _lootItemArray select (selectRandom _weightedItemArray);
2015-09-17 16:31:04 +00:00
_randomItem = _randomItemArray select 0;
_type = _randomItemArray select 1;
_quan = 1;
_loop = true;
_exit = false;
while {_loop} do {
switch _type do {
case "item": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object additemCargoGlobal [_randomItem, _quan];
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "magazine": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
if (_randomizeMagazineAmmoCount) then {
// spawn a single Magazine with a random ammo count
_magazineSize = getNumber (configFile >> "CfgMagazines" >> _randomItem >> "count");
_object addMagazineAmmoCargo[_randomItem, _quan, ceil(random(_magazineSize))];
} else {
// spawn a single full Magazine
_object addMagazineCargoGlobal [_randomItem, _quan];
};
2015-12-31 19:29:16 +00:00
} else {
2016-04-08 20:21:46 +00:00
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
2015-12-31 19:29:16 +00:00
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "backpack": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object addBackpackCargoGlobal [_randomItem, _quan];
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "weapon": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object addWeaponCargoGlobal [_randomItem, _quan];
// only spawn mags that have prices
_mags = getArray (configFile >> "CfgWeapons" >> _randomItem >> "magazines") select {isClass (_pricingConfig >> _x)};
if !(_mags isEqualTo []) then {
if (_randomizeMagazineAmmoCount) then {
// spawn a single Magazine with a random ammo count
_magazineSize = getNumber (configFile >> "CfgMagazines" >> (_mags select 0) >> "count");
_object addMagazineAmmoCargo[_mags select 0, 1, ceil(random(_magazineSize))];
} else {
// spawn a single full Magazine with weapon
_object addMagazineCargoGlobal [_mags select 0, 1];
};
2015-12-31 19:29:16 +00:00
};
2016-04-08 20:21:46 +00:00
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
2015-09-17 16:31:04 +00:00
};
_loop = false;
};
case "CfgLootTable": {
2015-12-08 17:07:43 +00:00
// go down the rabit hole
2016-04-08 20:21:46 +00:00
_lootItemWeightedArray = [_randomItem, _lootTableClass, "items"] call EPOCH_weightedArray;
2015-09-17 16:31:04 +00:00
_lootItemArray = _lootItemWeightedArray select 0;
if !(_lootItemArray isEqualTo[]) then {
_weightedItemArray = _lootItemWeightedArray select 1;
2016-04-08 20:21:46 +00:00
_randomItemArray = _lootItemArray select(selectRandom _weightedItemArray);
2015-09-17 16:31:04 +00:00
_randomItem = _randomItemArray select 0;
_type = _randomItemArray select 1;
} else {
_exit = true;
};
};
default {
_exit = true;
};
};
2016-04-08 20:21:46 +00:00
if (_exit) exitWith{if (_debug) then {diag_log "DEBUG: exit from spawn with default state."}};
2015-09-17 16:31:04 +00:00
};
};
} forEach _loots;
};
2015-12-08 17:07:43 +00:00
};