Merge remote-tracking branch 'origin/unstable' into unstable

This commit is contained in:
KingRainbow44 2023-04-10 22:23:19 -04:00
commit 92afa64629
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 10 additions and 12 deletions

View File

@ -36,8 +36,7 @@ export async function grantAvatar(
talents = 6 talents = 6
): Promise<CommandResponse> { ): Promise<CommandResponse> {
// Validate the numbers. // Validate the numbers.
if (invalid(avatar) || invalid(level) if (invalid(avatar) || invalid(level) || invalid(constellations) || invalid(talents))
|| invalid(constellations) || invalid(talents))
return { status: -1, message: "Invalid arguments." }; return { status: -1, message: "Invalid arguments." };
return await fetch(`https://localhost:443/handbook/avatar`, { return await fetch(`https://localhost:443/handbook/avatar`, {
@ -60,18 +59,16 @@ export async function grantAvatar(
* @param item The item's ID. * @param item The item's ID.
* @param amount The amount of the item to give. * @param amount The amount of the item to give.
*/ */
export async function giveItem( export async function giveItem(item: number, amount = 1): Promise<CommandResponse> {
item: number, amount = 1
): Promise<CommandResponse> {
// Validate the number. // Validate the number.
if (isNaN(amount) || amount < 1) if (isNaN(amount) || amount < 1) return { status: -1, message: "Invalid amount." };
return { status: -1, message: "Invalid amount." };
return await fetch(`https://localhost:443/handbook/item`, { return await fetch(`https://localhost:443/handbook/item`, {
method: "POST", body: JSON.stringify({ method: "POST",
body: JSON.stringify({
player: targetPlayer.toString(), player: targetPlayer.toString(),
item: item.toString(), item: item.toString(),
amount amount
}) })
}).then(res => res.json()); }).then((res) => res.json());
} }

View File

@ -82,9 +82,10 @@ class ItemCard extends React.Component<IProps, IState> {
* @private * @private
*/ */
private async addToInventory(): Promise<void> { private async addToInventory(): Promise<void> {
await giveItem(this.props.item?.id ?? 102, await giveItem(
typeof(this.state.count) == "string" ? this.props.item?.id ?? 102,
parseInt(this.state.count) : this.state.count); typeof this.state.count == "string" ? parseInt(this.state.count) : this.state.count
);
} }
componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>, snapshot?: any) { componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>, snapshot?: any) {