Gamer_Hardox / Ogame: Max_Cargo_patch

// ==UserScript==
// @name         Ogame: Max_Cargo_patch
// @author       =Hardox=  @2021
// @licence      MIT
// @version      0.62
// @description  Patch for freight with maximum load.
// @namespace    http://tampermonkey.net/
// @homepage     https://openuserjs.org/users/Gamer_Hardox/scripts
// @updateURL    https://openuserjs.org/meta/Gamer_Hardox/Ogame_Max_Cargo_patch.meta.js
// @downloadURL  https://openuserjs.org/install/Gamer_Hardox/Ogame_Max_Cargo_patch.user.js
// @match        https://*.ogame.gameforge.com/game/index.php?page=ingame&component=fleetdispatch*
// @grant        none
// @run-at       document-end
// ==/UserScript==

let shipsDB = [
    {id:202, CapacityBase:   5000, bonusCollector:0.25, bonusGeneral:   0, CapacityCargo: 0, name: 'TransporterSmall'},
    {id:203, CapacityBase:  25000, bonusCollector:0.25, bonusGeneral:   0, CapacityCargo: 0, name: 'TransporterLarge'},
    {id:208, CapacityBase:   7500, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'ColonyShip'},
    {id:209, CapacityBase:  20000, bonusCollector:   0, bonusGeneral:0.20, CapacityCargo: 0, name: 'Recycler'},
    {id:210, CapacityBase:      0, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Probe'},
    {id:204, CapacityBase:     50, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'FighterLight'},
    {id:205, CapacityBase:    100, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'FighterHeavy'},
    {id:206, CapacityBase:    800, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Cruiser'},
    {id:207, CapacityBase:   1500, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Battleship'},
    {id:215, CapacityBase:    750, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Interceptor'},
    {id:211, CapacityBase:    500, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Bomber'},
    {id:213, CapacityBase:   2000, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Destroyer'},
    {id:214, CapacityBase:1000000, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Deathstar'},
    {id:218, CapacityBase:  10000, bonusCollector:   0, bonusGeneral:   0, CapacityCargo: 0, name: 'Reaper'},
    {id:219, CapacityBase:  10000, bonusCollector:   0, bonusGeneral:0.20, CapacityCargo: 0, name: 'Explorer'},
];

let Patch=0;
const HS_Tech = parseInt(fleetDispatcher.apiTechData[6][1], 10); // 114 = HiperSpace_Tech_level
const Player_Class = parseInt(apiCommonData[1][1], 10);

if (fleetDispatcher.fleetHelper.shipsData[210].baseCargoCapacity !== 0) {shipsDB[4].CapacityBase = 5;} // Is it a universe in which the probes are carrying capacity? -> update value

shipsDB.forEach(function (nave) {
   let plus_Tech = (nave.CapacityBase * HS_Tech * 5/100);
   let plus_Class = nave.CapacityBase * ((Player_Class == 1 ? nave.bonusCollector : 0) + (Player_Class == 2 ? nave.bonusGeneral : 0));
   nave.CapacityCargo = nave.CapacityBase + plus_Tech + plus_Class;
   if (fleetDispatcher.fleetHelper.shipsData[nave.id].cargoCapacity !== nave.CapacityCargo){ Patch += 1;} // Patches number
});

if (Patch == 0) {
    fadeBox("It is not necessary to correct the cargo capacity.<br>You can disable the script:<br>'" + GM_info.script.name +"'", true, 0, 7000);
}

FleetHelper.prototype.calcCargoCapacity = function (shipId, number) {
    let index = shipsDB.findIndex(nave => nave.id === shipId);
    let cargo = Math.trunc(shipsDB[index].CapacityCargo * number);
    return cargo;
}