Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jan 15, 2024
1 parent c005a23 commit c21393c
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/applications/auctioneer/Bids/BidItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$: selected = bid.auction.uuid === $store.tabs[$store.activeTab].selected;
$: auctionSucceeded = bid.auction.won ? bid.auction.won.user === game.user : false;
$: auctionFailed = bid.auction.won ? bid.auction.won.user !== game.user : false;
$: auctionFailed = bid.auction.cancelled || (bid.auction.won ? bid.auction.won.user !== game.user : false);
</script>

Expand Down
4 changes: 3 additions & 1 deletion src/applications/auctioneer/Bids/Bids.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
const sortAlg = tab.sortByColumns[tab.sortBy].sort;
sortedBids = $store.auctionData.auctions
.filter(auction => {
return !auction.cancelled && auction.highestOwnedBid
return auction.highestOwnedBid
&& (
auction.cancelled
||
!auction.expired
||
(auction.expired && auction.won.user !== game.user && !auction.highestOwnedBid?.claimed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</script>

<div class="item-list-entry-actions">
{#if showCurrency && !auction.expired}
{#if showCurrency && !auction.expired && !auction.cancelled}
<div class="character-currencies">
{#each currencies as currency (currency.name)}
<div class="currency-list-item" data-tooltip={currency.name}>
Expand Down Expand Up @@ -75,9 +75,9 @@
Collect item
</ReactiveButton>
{:else}
{#if auction.expired}
{#if auction.expired || auction.cancelled}
<ReactiveButton callback={() => store.claimAuctions([auction])} completelyDisable
disabled={!auction.expired}>
disabled={!auction.expired && !auction.cancelled}>
Collect currency
</ReactiveButton>
{:else}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/auctioneer/Logs/ClaimedAuctionLog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<LogEntry date={entry.date}>
<div>
<span>{data.displayName}</span> <span
class="auction-claimed-log">claimed</span> the successful auction for {@html getItemColorElement(data.item)}<span
>{data.item.name}</span> {quantity} for <span>{price}</span>
class="auction-claimed-log">claimed</span> the money for the <span>successful</span> auction for {@html getItemColorElement(data.item)}<span
>{data.item.name}</span> {quantity} that sold for <span>{price}</span>
</div>
</LogEntry>
21 changes: 21 additions & 0 deletions src/applications/auctioneer/Logs/ClaimedLostBidLog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
import { getItemColorElement } from "~/lib.js";
import LogEntry from "~/applications/auctioneer/Logs/LogEntry.svelte";
export let entry;
const data = entry.data;
const quantity = data.auction.quantity > 1 ? " x " + data.auction.quantity : "";
</script>

<LogEntry date={entry.date}>
<div>
<span>{data.displayName}</span> reclaimed money from their <span class="auction-failed-bid-log">failed bid</span> on
the {@html getItemColorElement(data.auction.item)}<span
>{data.auction.item.name}</span> {quantity} from
<span>{data.auction.displayName}</span>
</div>
</LogEntry>
2 changes: 2 additions & 0 deletions src/applications/auctioneer/Logs/Logs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ClaimedBidLog from "~/applications/auctioneer/Logs/ClaimedBidLog.svelte";
import ClaimedExpiredAuctionLog from "~/applications/auctioneer/Logs/ClaimedExpiredAuctionLog.svelte";
import SuccessfulExpiredAuctionLog from "~/applications/auctioneer/Logs/SuccessfulExpiredAuctionLog.svelte";
import ClaimedLostBidLog from "~/applications/auctioneer/Logs/ClaimedLostBidLog.svelte";
const store = getContext("store");
Expand All @@ -25,6 +26,7 @@
CancelledAuctionLog,
BidLog,
ClaimedBidLog,
ClaimedLostBidLog,
BuyoutLog
}
Expand Down
18 changes: 14 additions & 4 deletions src/applications/auctioneer/auctioneer-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ export function createStore(auctioneer) {
? game.itempiles.API.calculateCurrencies(bidPaymentData.basePriceString, existingBids[existingBidForAuctionIndex]?.price)
: bidPaymentData.basePriceString;

await game.itempiles.API.removeCurrencies(targetActor, currencyCost);

await game.user.setFlag(CONSTANTS.MODULE_NAME, CONSTANTS.BIDS_FLAG, existingBids);

await game.itempiles.API.removeCurrencies(targetActor, currencyCost);

return true;

}
Expand All @@ -371,6 +371,15 @@ export function createStore(auctioneer) {
ui.notifications.warn("Insufficient funds - you do not have enough funds to buy out this auction");
return false;
}

const existingBids = lib.getUserBids();
for(const bid of existingBids){
if(bid.auctionUuid === auction.uuid){
bid.toMigrate = true;
}
}
await game.user.setFlag(CONSTANTS.MODULE_NAME, CONSTANTS.BIDS_FLAG, existingBids);

const existingBuyouts = lib.getUserBuyouts();
existingBuyouts.push({
id: randomID(),
Expand All @@ -380,8 +389,9 @@ export function createStore(auctioneer) {
price: auction.buyoutPrice,
date: lib.evaluateFoundryTime(auctioneer)
});
await game.itempiles.API.removeCurrencies(targetActor, auction.buyoutPrice);
return game.user.setFlag(CONSTANTS.MODULE_NAME, CONSTANTS.BUYOUTS_FLAG, existingBuyouts);
await game.user.setFlag(CONSTANTS.MODULE_NAME, CONSTANTS.BUYOUTS_FLAG, existingBuyouts);

return game.itempiles.API.removeCurrencies(targetActor, auction.buyoutPrice);
}

/**
Expand Down
190 changes: 104 additions & 86 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function cleanUserFlags(acc, entry, flagPath) {
return acc;
}

export function getAuctionMigrationData(auctioneer, getLogs = true) {
export function getAuctionMigrationData(auctioneer) {

const flags = getAuctioneerActorFlags(auctioneer);

Expand Down Expand Up @@ -445,6 +445,11 @@ export function getAuctionMigrationData(auctioneer, getLogs = true) {

}

function _addToLog(acc, condition, data) {
if (!condition || acc[data.id]) return;
acc[data.id] = data;
}

export function getLogData(auctioneer) {

const { auctions, bids, buyouts } = getAuctioneerData(auctioneer);
Expand All @@ -453,103 +458,105 @@ export function getLogData(auctioneer) {

const auctionLogs = auctions
.reduce((acc, auction, index) => {
if (auction.cancelled && auction.claimed && currentDatetime >= auction.claimedDate && !acc[auction.id + "-cancelled"]) {
acc[auction.id + "-cancelled"] = {
data: auction,
type: "CancelledAuctionLog",
id: auction.id + "-cancelled",
date: auction.claimedDate,
visible: true,
priority: index
};
}
if (!auction.cancelled && auction.expired && auction.claimed && !auction.won && !acc[auction.id + "-claimed-expired"]) {
acc[auction.id + "-claimed-expired"] = {
data: auction,
type: "ClaimedExpiredAuctionLog",
id: auction.id + "-claimed-expired",
date: auction.claimedDate,
visible: true,
priority: index + 1
};
}
if (!auction.cancelled && auction.expired && auction.claimed && auction.won && currentDatetime >= auction.claimedDate && !acc[auction.id + "-claimed"]) {
acc[auction.id + "-claimed"] = {
data: auction,
type: "ClaimedAuctionLog",
id: auction.id + "-claimed",
date: auction.claimedDate,
visible: true,
priority: index + 2
};
}
if (!auction.cancelled && auction.expired && !auction.won && !acc[auction.id + "-expired"]) {
acc[auction.id + "-expired"] = {
data: auction,
type: "ExpiredAuctionLog",
id: auction.id + "-expired",
date: auction.expiryDate,
visible: true,
priority: index + 3
};
}
if (!auction.cancelled && auction.expired && auction.won && !acc[auction.id + "-successful-expired"]) {
acc[auction.id + "-successful-expired"] = {
data: auction,
type: "SuccessfulExpiredAuctionLog",
id: auction.id + "-successful-expired",
date: auction.expiryDate,
visible: true,
priority: index + 4
};
}
if (!acc[auction.id]) {
acc[auction.id] = {
data: auction,
type: "AuctionLog",
id: auction.id,
date: auction.date,
visible: true,
priority: index + 5
};
}
return acc;
}, {});

const bidLogs = bids.reduce((acc, bid, index) => {
if (bid.claimed && currentDatetime >= bid.claimedDate && !acc[bid.claimed + "-claimed"]) {
acc[bid.id + "-claimed"] = {
data: bid,
type: "ClaimedBidLog",
id: bid.id + "-claimed",
date: bid.claimedDate,
_addToLog(acc, auction.cancelled && auction.claimed && currentDatetime >= auction.claimedDate, {
data: auction,
type: "CancelledAuctionLog",
id: auction.id + "-cancelled",
date: auction.claimedDate,
visible: true,
priority: index
}
}
if (!acc[bid.id]) {
acc[bid.id] = {
data: bid,
type: "BidLog",
id: bid.id,
date: bid.date,
});

_addToLog(acc, !auction.cancelled && auction.expired && auction.claimed && !auction.won, {
data: auction,
type: "ClaimedExpiredAuctionLog",
id: auction.id + "-claimed-expired",
date: auction.claimedDate,
visible: true,
priority: index + 1
}
}
});

_addToLog(acc, !auction.cancelled && auction.expired && auction.claimed && auction.won && currentDatetime >= auction.claimedDate, {
data: auction,
type: "ClaimedAuctionLog",
id: auction.id + "-claimed",
date: auction.claimedDate,
visible: true,
priority: index + 2
});

_addToLog(acc, !auction.cancelled && auction.expired && !auction.won, {
data: auction,
type: "ExpiredAuctionLog",
id: auction.id + "-expired",
date: auction.expiryDate,
visible: true,
priority: index + 3
});

_addToLog(acc, !auction.cancelled && auction.expired && auction.won, {
data: auction,
type: "SuccessfulExpiredAuctionLog",
id: auction.id + "-successful-expired",
date: auction.expiryDate,
visible: true,
priority: index + 4
});

_addToLog(acc, true, {
data: auction,
type: "AuctionLog",
id: auction.id,
date: auction.date,
visible: true,
priority: index + 5
});

return acc;
}, {});

const bidLogs = bids.reduce((acc, bid, index) => {
_addToLog(acc, bid.claimed && currentDatetime >= bid.claimedDate && bid.auction.won === bid, {
data: bid,
type: "ClaimedBidLog",
id: bid.id + "-claimed",
date: bid.claimedDate,
visible: true,
priority: index
});

_addToLog(acc, bid.claimed && currentDatetime >= bid.claimedDate && bid.auction.won !== bid, {
data: bid,
type: "ClaimedLostBidLog",
id: bid.id + "-claimed-lost",
date: bid.claimedDate,
visible: true,
priority: index + 1
});

_addToLog(acc, true, {
data: bid,
type: "BidLog",
id: bid.id,
date: bid.date,
visible: true,
priority: index + 2
});

return acc;
}, {});

const buyoutLogs = buyouts.reduce((acc, buyout, index) => {
if (acc[buyout.id]) return acc;
acc[buyout.id] = {
_addToLog(acc, true, {
data: buyout,
type: "BuyoutLog",
id: buyout.id,
date: buyout.date,
visible: true,
priority: index
}
});

return acc;
}, {});

Expand Down Expand Up @@ -662,7 +669,7 @@ export function getAuctioneerData(auctioneer) {

auction.bids.sort((a, b) => b.priceData.totalPrice - a.priceData.totalPrice);

const ownedBids = auction.bids.filter(bid => bid.user === game.user);
const ownedBids = auction.bids.filter(bid => bid.user === game.user && !bid.claimed);

auction.bidPriceData = auction.bidVisibility === CONSTANTS.VISIBILITY_KEYS.VISIBLE || auction.user === game.user
? (auction.bids.length ? auction.bids[0].priceData : auction.startPriceData)
Expand Down Expand Up @@ -691,6 +698,12 @@ export function getAuctioneerData(auctioneer) {
}
auction.highBidder = (auction.won.displayName || "Unknown") + " (buyout)";
} else {
if (auction.cancelled) {
auction.timeLeft = {
label: "Cancelled",
value: Infinity
}
}
auction.highBidder = auction.bids?.[0]?.displayName;
if (auction.expired && auction.bids.length) {
if (!auction.reservePrice || !isPriceHigherThan(auction.bids[0].priceData, auction.reservePriceData)) {
Expand All @@ -705,11 +718,16 @@ export function getAuctioneerData(auctioneer) {
}
}

if (ownedBids.length && !auction.claimed) {
if (ownedBids.length) {
const highestOwnedBid = ownedBids[0];
auction.highestOwnedBid = highestOwnedBid;
const bidIndex = auction.bids.indexOf(highestOwnedBid);
if (auction.bidVisibility === CONSTANTS.VISIBILITY_KEYS.VISIBLE) {
if (auction.cancelled || (auction.expired && auction.won !== highestOwnedBid)){
highestOwnedBid.bidStatus = {
value: Math.min(bidIndex, 3),
label: "Lost bid"
}
}else if (auction.bidVisibility === CONSTANTS.VISIBILITY_KEYS.VISIBLE) {
let label = "Low Bid";
if (bidIndex === 0) {
label = "Highest Bid"
Expand Down
4 changes: 4 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ Hooks.once("ready", () => {
Hooks.on(game.itempiles.hooks.PRE_RENDER_INTERFACE, lib.auctioneerRendered);
game.itempiles.API.registerItemPileType(CONSTANTS.AUCTIONEER, "Auctioneer", CONSTANTS.AUCTIONEER_SETTINGS);
if (lib.isResponsibleGM()) lib.migrateData();

game.itempilesauctioneer.API = {
getAuctioneerData: lib.getAuctioneerData
}
});
Loading

0 comments on commit c21393c

Please sign in to comment.