Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FFS] Facilitation du restock des vêtements en rupture #350

Open
wants to merge 3 commits into
base: oss
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions resources/[soz]/soz-core/src/server/job/ffs/ffs.restock.provider.ts
Original file line number Diff line number Diff line change
@@ -46,33 +46,33 @@ export class FightForStyleRestockProvider {
);
}

public garmentToCategory(garment: Garment | LuxuryGarment): number {
public garmentToCategory(garment: Garment | LuxuryGarment): number[] {
switch (garment) {
case Garment.TOP:
case LuxuryGarment.TOP:
return 1;
return [1, 30];
case Garment.PANT:
case LuxuryGarment.PANT:
return 15;
return [15, 50];
case Garment.SHOES:
case LuxuryGarment.SHOES:
return 25;
return [25, 75];
case Garment.UNDERWEAR:
case LuxuryGarment.UNDERWEAR:
return 21;
return [21, -1];
case Garment.BAG:
case LuxuryGarment.BAG:
return 52;
return [52, -1];
case Garment.GLOVES:
case LuxuryGarment.GLOVES:
return 50;
return [50, -1];
case Garment.UNDERWEAR_TOP:
case LuxuryGarment.UNDERWEAR_TOP:
return 60;
return [60, 75];
case Garment.MASK:
return 41;
return [41, 30];
default:
return -1;
return [-1, -1];
}
}

@@ -121,8 +121,10 @@ export class FightForStyleRestockProvider {

public async restockLoop(brand: ClothingBrand, garment: Garment | LuxuryGarment, amount: number) {
const sexes = [PlayerPedHash.Male, PlayerPedHash.Female];
const category = this.garmentToCategory(garment);

const catLim = this.garmentToCategory(garment);
const category = catLim[0];
const filterLimit = catLim[1];

if (category == -1) {
this.logger.error('Invalid category for item ', garment);
return;
@@ -164,7 +166,18 @@ export class FightForStyleRestockProvider {
}
}
}
const randomItem = loopItems[Math.floor(Math.random() * loopItems.length)];

const itemStock = loopItems.filter(
item => item.stock != null && item.stock < filterLimit
);

let randomItem;
if (!itemStock) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!itemStock) {
if (!itemStock.length) {

Ca marche en python, mais pas en JS 🙏

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah mince! X) je pensais que ça marchais pcq j'avais vu cette ligne (Je suis néophyte en TS )
" if (!randomItem || !loopItems) {" (ligne 179)

randomItem = loopItems[Math.floor(Math.random() * loopItems.length)];
} else {
randomItem = itemStock[Math.floor(Math.random() * itemStock.length)];
}

if (!randomItem || !loopItems) {
return;
}
@@ -191,6 +204,7 @@ export class FightForStyleRestockProvider {
},
},
});
this.notifier.notify(source, `Vous avez restock des ~g~${randomItem.modelLabel} ~s~`, 'success');
}

// Update repository