Skip to content

Commit

Permalink
Further improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamXZE committed Mar 14, 2023
1 parent a37b310 commit 8b90290
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 12 deletions.
136 changes: 132 additions & 4 deletions resources/[soz]/soz-core/src/client/job/ffs/ffs.showroom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Once, OnceStep, OnEvent, OnNuiEvent } from '../../../core/decorators/event';
import { Inject } from '../../../core/decorators/injectable';
import { Provider } from '../../../core/decorators/provider';
import { Component, FfsComponent, OutfitItem, Prop } from '../../../shared/cloth';
import {
Component,
FfsComponent,
OutfitItem,
Prop,
ShowRoomFreeElement,
ShowRoomPricePerSelection,
} from '../../../shared/cloth';
import { ClientEvent, NuiEvent, ServerEvent } from '../../../shared/event';
import { JobPermission } from '../../../shared/job';
import { MenuType } from '../../../shared/nui/menu';
Expand Down Expand Up @@ -60,7 +67,10 @@ export class FightForStylShowRoomProvider {

private outfit_type = null;

private components_to_craft: object = {};
private components_to_craft: object = {
3: { Drawable: 0, Texture: 0 },
8: { Drawable: 0, Texture: 25 },
};

private props_to_craft: object = {};

Expand Down Expand Up @@ -91,6 +101,24 @@ export class FightForStylShowRoomProvider {
});
}

@OnNuiEvent(NuiEvent.FfsMenuCraftingPrice)
public async GetCraftingPrice(): Promise<object> {
let price = 0;
Object.keys(this.components_to_craft).map(componentIndex => {
if (!ShowRoomFreeElement[componentIndex]?.includes(this.components_to_craft[componentIndex].Drawable)) {
if (this.should_craft.drawables?.[componentIndex]) {
price += ShowRoomPricePerSelection;
}
}
});
Object.keys(this.props_to_craft).map(propIndex => {
if (this.should_craft.props?.[propIndex]) {
price += ShowRoomPricePerSelection;
}
});
return Ok(price);
}

@OnNuiEvent(NuiEvent.FfsMenuShouldCraftPanel)
public async OpenShouldCraftPanel(): Promise<object> {
return Ok(this.should_craft);
Expand All @@ -105,7 +133,10 @@ export class FightForStylShowRoomProvider {
DeletePed(this.ped_id);
this.ped_id = null;
this.outfit_type = null;
this.components_to_craft = {};
this.components_to_craft = {
3: { Drawable: 0, Texture: 0 },
8: { Drawable: 0, Texture: 25 },
};
this.props_to_craft = {};
this.should_craft = {
drawables: {},
Expand Down Expand Up @@ -196,6 +227,55 @@ export class FightForStylShowRoomProvider {
this.outfit_type = 'ffs_crafted_outfit_m';
this.ped_id = await this.pedFactory.createPed({
model: 'mp_m_freemode_01',
modelCustomization: { SkinMix: 0.5, ShapeMix: 0.15, Father: 20, Mother: 32 },
components: {
3: [0, 0, 0],
8: [0, 25, 0],
11: [0, 0, 0],
},
face: {
CheeksBoneHigh: 0.0,
NosePeakLength: 0.1,
ChimpBoneWidth: -0.3,
NoseWidth: -0.9,
ChimpBoneLength: -0.1,
ChimpHole: 0.0,
JawBoneWidth: 0.0,
Ageing: -1,
EyebrowHigh: 0.0,
NeckThickness: 0.0,
NoseBoneHigh: 0.0,
LipsThickness: 0.0,
Moles: 3,
ChimpBoneLower: -0.3,
EyeColor: 11,
NosePeakLower: 0.0,
JawBoneBackLength: 0.0,
CheeksWidth: 0.0,
Complexion: -1,
NoseBoneTwist: 0.0,
CheeksBoneWidth: 0.0,
Blemish: -1,
EyebrowForward: 0.0,
AddBodyBlemish: -1,
EyesOpening: 0.2,
BodyBlemish: -1,
NosePeakHeight: 0.0,
},
hair: {
BeardType: -1,
HairColor: 31,
EyebrowColor: 60,
BeardColor: 0,
BeardOpacity: 1.0,
HairSecondaryColor: 33,
ChestHairOpacity: 1.0,
ChestHairColor: 0,
ChestHairType: -1,
EyebrowOpacity: 1.0,
EyebrowType: 0,
HairType: 33,
},
coords: {
x: this.PED_POSITION[0],
y: this.PED_POSITION[1],
Expand All @@ -206,7 +286,6 @@ export class FightForStylShowRoomProvider {
freeze: true,
blockevents: true,
});
// Set ped variation so it does not look bad
this.cameraService.setupCamera(this.CAMERA_POSITION, this.CAMERA_TARGET);
await this.onShowRoomOpenMenu();
},
Expand All @@ -224,6 +303,55 @@ export class FightForStylShowRoomProvider {
this.outfit_type = 'ffs_crafted_outfit_f';
this.ped_id = await this.pedFactory.createPed({
model: 'mp_f_freemode_01',
modelCustomization: { SkinMix: 0.5, ShapeMix: 0.15, Father: 25, Mother: 26 },
components: {
3: [0, 0, 0],
8: [0, 25, 0],
11: [0, 0, 0],
},
face: {
CheeksBoneHigh: 0.0,
NosePeakLength: 0.1,
ChimpBoneWidth: -0.3,
NoseWidth: -0.9,
ChimpBoneLength: -0.1,
ChimpHole: 0.0,
JawBoneWidth: 0.0,
Ageing: -1,
EyebrowHigh: 0.0,
NeckThickness: 0.0,
NoseBoneHigh: 0.0,
LipsThickness: 0.0,
Moles: 3,
ChimpBoneLower: -0.3,
EyeColor: 11,
NosePeakLower: 0.0,
JawBoneBackLength: 0.0,
CheeksWidth: 0.0,
Complexion: -1,
NoseBoneTwist: 0.0,
CheeksBoneWidth: 0.0,
Blemish: -1,
EyebrowForward: 0.0,
AddBodyBlemish: -1,
EyesOpening: 0.2,
BodyBlemish: -1,
NosePeakHeight: 0.0,
},
hair: {
BeardType: -1,
HairColor: 31,
EyebrowColor: 60,
BeardColor: 0,
BeardOpacity: 1.0,
HairSecondaryColor: 33,
ChestHairOpacity: 1.0,
ChestHairColor: 0,
ChestHairType: -1,
EyebrowOpacity: 1.0,
EyebrowType: 0,
HairType: 10,
},
coords: {
x: this.PED_POSITION[0],
y: this.PED_POSITION[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const FightForStyleShowRoomMenu: FunctionComponent<FightForStyleShowRoomC
const [currentCraft, setcurrentCraft] = useState<{ drawables: object; props: object }>();
const [shouldCraft, setshouldCraft] = useState<{ drawables: object; props: object }>();
const [description, setDescription] = useState<string>();
const [price, setPrice] = useState<number>();
const state = data.state;
const can_craft = data.can_craft;

Expand All @@ -91,6 +92,14 @@ export const FightForStyleShowRoomMenu: FunctionComponent<FightForStyleShowRoomC
);
}, [currentDrawable]);

useEffect(() => {
fetchNui<never, Result<number, never>>(NuiEvent.FfsMenuCraftingPrice).then(result => {
if (isOk(result)) {
setPrice(result.ok);
}
});
}, [shouldCraft, currentCraft]);

useNuiEvent(
'ffs_skin_submenu',
'SetComponentDrawable',
Expand Down Expand Up @@ -231,7 +240,9 @@ export const FightForStyleShowRoomMenu: FunctionComponent<FightForStyleShowRoomC
});
}}
>
{`${TRANSLATED_INDEXES[FfsComponent[componentIndex]]}`}
{`${TRANSLATED_INDEXES[FfsComponent[componentIndex]]}: ${
currentCraft.drawables[componentIndex].Drawable
} - ${currentCraft.drawables[componentIndex].Texture}`}
</MenuItemCheckbox>
))}
{Object.keys(currentCraft?.props || {}).map(propIndex => (
Expand All @@ -252,7 +263,9 @@ export const FightForStyleShowRoomMenu: FunctionComponent<FightForStyleShowRoomC
});
}}
>
{`${TRANSLATED_INDEXES[Prop[propIndex]]}`}
{`${TRANSLATED_INDEXES[Prop[propIndex]]}: ${currentCraft.props[propIndex].Drawable} - ${
currentCraft.props[propIndex].Texture
}`}
</MenuItemCheckbox>
))}
<MenuItemButton
Expand All @@ -265,7 +278,7 @@ export const FightForStyleShowRoomMenu: FunctionComponent<FightForStyleShowRoomC
await fetchNui(NuiEvent.FfsMenuCraftOutfit);
}}
>
Confectionner la tenue
{`Confectionner la tenue - ${price}$`}
</MenuItemButton>
</MenuContent>
</SubMenu>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OnEvent } from '../../../core/decorators/event';
import { Inject } from '../../../core/decorators/injectable';
import { Provider } from '../../../core/decorators/provider';
import { ShowRoomFreeElement, ShowRoomPricePerSelection } from '../../../shared/cloth';
import { ServerEvent } from '../../../shared/event';
import { InventoryManager } from '../../inventory/inventory.manager';
import { Notifier } from '../../notifier';
Expand All @@ -17,15 +18,15 @@ export class FightForStylShowRoomProvider {
@Inject(QBCore)
private qbcore: QBCore;

private cost_per_craft = 125;

@OnEvent(ServerEvent.FFS_SHOW_ROOM_CRAFTING)
async onShowRoomCrafting(source: number, outfit: object, outfit_type: string) {
const player = this.qbcore.getPlayer(source);

let cost_mult = 0;
Object.keys(outfit['Components']).forEach(() => {
cost_mult++;
Object.keys(outfit['Components']).forEach(componentIndex => {
if (!ShowRoomFreeElement[componentIndex]?.includes(outfit['Components'][componentIndex].Drawable)) {
cost_mult++;
}
});
Object.keys(outfit['Props']).forEach(() => {
cost_mult++;
Expand All @@ -50,7 +51,7 @@ export class FightForStylShowRoomProvider {
return;
}

const total_cost = this.cost_per_craft * cost_mult;
const total_cost = ShowRoomPricePerSelection * cost_mult;
if (!player.Functions.RemoveMoney('money', total_cost)) {
this.notifier.notify(source, `Vous n'avez pas assez d'argent.`, 'error');
return;
Expand Down
6 changes: 6 additions & 0 deletions resources/[soz]/soz-core/src/shared/cloth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export enum Prop {
Helmet = 'Helmet',
}

export const ShowRoomPricePerSelection = 125;
export const ShowRoomFreeElement = {
3: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
8: [0],
};

export type OutfitItem = {
Index?: number;
Drawable?: number;
Expand Down
1 change: 1 addition & 0 deletions resources/[soz]/soz-core/src/shared/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export enum NuiEvent {
FfsMenuLookAtDrawable = 'soz-core:client:ffs:look-at-drawable',
FfsMenuChangeDescription = 'soz-core:client:ffs:change-description',
FfsMenuCraftingPanel = 'soz-core:client:ffs:crafting-panel',
FfsMenuCraftingPrice = 'soz-core:client:ffs:crafting-price',
FfsMenuShouldCraftPanel = 'soz-core:client:ffs:should-craft',
FfsShowRoomSelectToCraft = 'soz-core:client:ffs:select-to-craft',
FfsMenuCraftOutfit = 'soz-core:client:ffs:craft-outfit',
Expand Down

0 comments on commit 8b90290

Please sign in to comment.