Ability to trade multiple cards at once #360
2 changed files with 11 additions and 7 deletions
|
@ -31,7 +31,7 @@ export default class Trade extends ButtonEvent {
|
||||||
const user1Quantity = Number(interaction.customId.split(" ")[8]) ?? 1;
|
const user1Quantity = Number(interaction.customId.split(" ")[8]) ?? 1;
|
||||||
const user2Quantity = Number(interaction.customId.split(" ")[9]) ?? 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);
|
const expiryDate = new Date(expiry);
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ export default class Trade extends ButtonEvent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user1UserInventory1.SetQuantity(user1UserInventory1.Quantity - user1Quantity);
|
user1UserInventory1.RemoveQuantity(user1Quantity);
|
||||||
user2UserInventory1.SetQuantity(user2UserInventory1.Quantity - user2Quantity);
|
user2UserInventory1.RemoveQuantity(user2Quantity);
|
||||||
|
|
||||||
await user1UserInventory1.Save(Inventory, user1UserInventory1);
|
await user1UserInventory1.Save(Inventory, user1UserInventory1);
|
||||||
await user2UserInventory1.Save(Inventory, user2UserInventory1);
|
await user2UserInventory1.Save(Inventory, user2UserInventory1);
|
||||||
|
@ -84,15 +84,15 @@ export default class Trade extends ButtonEvent {
|
||||||
let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber);
|
let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber);
|
||||||
|
|
||||||
if (!user1UserInventory2) {
|
if (!user1UserInventory2) {
|
||||||
user1UserInventory2 = new Inventory(user1UserId, user1CardNumber, user2Quantity);
|
user1UserInventory2 = new Inventory(user1UserId, user2CardNumber, user2Quantity);
|
||||||
} else {
|
} else {
|
||||||
user1UserInventory2.SetQuantity(user1UserInventory2.Quantity + user2Quantity);
|
user1UserInventory2.AddQuantity(user2Quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user2UserInventory2) {
|
if (!user2UserInventory2) {
|
||||||
user2UserInventory2 = new Inventory(user2UserId, user2CardNumber, user1Quantity);
|
user2UserInventory2 = new Inventory(user2UserId, user1CardNumber, user1Quantity);
|
||||||
} else {
|
} else {
|
||||||
user2UserInventory2.SetQuantity(user2UserInventory2.Quantity + user2Quantity);
|
user2UserInventory2.AddQuantity(user1Quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
await user1UserInventory2.Save(Inventory, user1UserInventory2);
|
await user1UserInventory2.Save(Inventory, user1UserInventory2);
|
||||||
|
|
|
@ -35,6 +35,10 @@ export default class Inventory extends AppBaseEntity {
|
||||||
this.Quantity -= amount;
|
this.Quantity -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AddQuantity(amount: number) {
|
||||||
|
this.Quantity += amount;
|
||||||
|
}
|
||||||
|
|
||||||
public AddClaim(claim: Claim) {
|
public AddClaim(claim: Claim) {
|
||||||
this.Claims.push(claim);
|
this.Claims.push(claim);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue