Ability to trade multiple cards at once #360

Merged
Vylpes merged 5 commits from feature/338-trade-multiple into develop 2024-09-15 16:55:19 +01:00
2 changed files with 11 additions and 7 deletions
Showing only changes of commit a294d408c1 - Show all commits

View file

@ -31,7 +31,7 @@ export default class Trade extends ButtonEvent {
const user1Quantity = Number(interaction.customId.split(" ")[8]) ?? 1;
const user2Quantity = Number(interaction.customId.split(" ")[9]) ?? 1;
AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, expiry=${expiry}, timeoutId=${timeoutId}`);
AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, expiry=${expiry}, timeoutId=${timeoutId} user1Quantity=${user1Quantity} user2Quantity=${user2Quantity}`);
const expiryDate = new Date(expiry);
@ -74,8 +74,8 @@ export default class Trade extends ButtonEvent {
return;
}
user1UserInventory1.SetQuantity(user1UserInventory1.Quantity - user1Quantity);
user2UserInventory1.SetQuantity(user2UserInventory1.Quantity - user2Quantity);
user1UserInventory1.RemoveQuantity(user1Quantity);
user2UserInventory1.RemoveQuantity(user2Quantity);
await user1UserInventory1.Save(Inventory, user1UserInventory1);
await user2UserInventory1.Save(Inventory, user2UserInventory1);
@ -84,15 +84,15 @@ export default class Trade extends ButtonEvent {
let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber);
if (!user1UserInventory2) {
user1UserInventory2 = new Inventory(user1UserId, user1CardNumber, user2Quantity);
user1UserInventory2 = new Inventory(user1UserId, user2CardNumber, user2Quantity);
} else {
user1UserInventory2.SetQuantity(user1UserInventory2.Quantity + user2Quantity);
user1UserInventory2.AddQuantity(user2Quantity);
}
if (!user2UserInventory2) {
user2UserInventory2 = new Inventory(user2UserId, user2CardNumber, user1Quantity);
user2UserInventory2 = new Inventory(user2UserId, user1CardNumber, user1Quantity);
} else {
user2UserInventory2.SetQuantity(user2UserInventory2.Quantity + user2Quantity);
user2UserInventory2.AddQuantity(user1Quantity);
}
await user1UserInventory2.Save(Inventory, user1UserInventory2);

View file

@ -35,6 +35,10 @@ export default class Inventory extends AppBaseEntity {
this.Quantity -= amount;
}
public AddQuantity(amount: number) {
this.Quantity += amount;
}
public AddClaim(claim: Claim) {
this.Claims.push(claim);
}