sp-tarkov / server

University of Illinois/NCSA Open Source License
20 stars 4 forks source link

BotWeaponGenerator.addCartridgeToChamber only adds one cartridge #754

Closed refringe closed 3 days ago

refringe commented 3 days ago

BotWeaponGenerator.addCartridgeToChamber only adds one cartridge. This causes problems with some weapons when the bot fires one shot and starts reloading. This applies to revolvers and shotguns.

The code should looks something like this:

addCartridgeToChamber(
    weaponWithMods: Item[],
    ammoTpl: string,
    chambersAmount: number
): undefined {
    const existingItemWithSlot = weaponWithMods.filter((item) =>
        item.slotId.startsWith("patron_in_weapon")
    );

    if (existingItemWithSlot.length > 0) {
        existingItemWithSlot.forEach((chamber) => {
            chamber.upd = {
                StackObjectsCount: 1,
            };
            chamber._tpl = ammoTpl;
        });
    } else {
        if (chambersAmount === 1) {
            weaponWithMods.push({
                _id: this.hashUtil.generate(),
                _tpl: ammoTpl,
                parentId: weaponWithMods[0]._id,
                slotId: "patron_in_weapon",
                upd: { StackObjectsCount: 1 },
            });
        } else {
            for (
                let chamberNum = 0;
                chamberNum < chambersAmount;
                chamberNum++
            ) {
                const slotIdName = `patron_in_weapon_00${chamberNum}`;
                weaponWithMods.push({
                    _id: this.hashUtil.generate(),
                    _tpl: ammoTpl,
                    parentId: weaponWithMods[0]._id,
                    slotId: slotIdName,
                    upd: { StackObjectsCount: 1 },
                });
            }
        }
    }
}

getChambersAmountFromWeaponTemplate(weaponTemplate: ITemplateItem): number {
    return weaponTemplate._props.Chambers.length;
}

Originally written by _Barlog_M_

refringe commented 3 days ago

Are you sure, here's the Rhino just before that function: image

Do you know what bot/weapon is broken?


Attachments


Originally written by chomp

refringe commented 3 days ago

Here's the Rhino:

image


Attachments


Originally written by chomp

refringe commented 3 days ago

After a lot of debugging I've found issues with:

weapon_izhmeh_mr43_sawed_off_12g - has 2 chambers weapon_izhmash_mp18_multi - has one chamber but slot is called patron_in_weapon_000 not the expected patron_in_weapon


Originally written by chomp

refringe commented 3 days ago

Thank you. Now i'm not shure.


Originally written by _Barlog_M_

refringe commented 3 days ago

Fixed with: https://dev.sp-tarkov.com/SPT-AKI/Server/commit/c801dba0b7301a52c8eba5615b62b8fedd03da41


Originally written by chomp