fix 4
This commit is contained in:
@@ -74,42 +74,20 @@ function gatherState() {
|
|||||||
} catch (e) { log(`storage capacity lookup failed: ${e}`); }
|
} catch (e) { log(`storage capacity lookup failed: ${e}`); }
|
||||||
|
|
||||||
// ---- Market / Trade capacity -----------------------------------------
|
// ---- Market / Trade capacity -----------------------------------------
|
||||||
// Uses multiple fallback paths to robustly read capacity across game versions.
|
// Reads from the same live MM model the game UI uses (CreateOffers).
|
||||||
|
// This model is populated once the player opens their market tab.
|
||||||
let marketCapacity = 0;
|
let marketCapacity = 0;
|
||||||
let availableTradeCapacity = 0;
|
let availableTradeCapacity = 0;
|
||||||
try {
|
try {
|
||||||
const marketLevel = buildings.market ?? 0;
|
const createOffers = uw.MM.getModels?.()?.CreateOffers?.[town.id];
|
||||||
const gd = uw.GameData?.buildingData?.market;
|
if (createOffers?.attributes) {
|
||||||
if (gd) {
|
marketCapacity = createOffers.attributes.trade_capacity ?? 0;
|
||||||
// Try various key names the game uses across versions
|
availableTradeCapacity = createOffers.attributes.available_trade_capacity ?? marketCapacity;
|
||||||
marketCapacity =
|
|
||||||
gd?.capacity_per_level?.[marketLevel] ||
|
|
||||||
gd?.max_capacity?.[marketLevel] ||
|
|
||||||
gd?.merchant_count?.[marketLevel] ||
|
|
||||||
gd?.merchants?.[marketLevel] ||
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
// Try the town object's built-in method first (most accurate)
|
// Fallback: use town method if model not yet loaded (market not yet opened)
|
||||||
if (town.getTradeCapacity) {
|
if (!marketCapacity && town.getTradeCapacity) {
|
||||||
marketCapacity = town.getTradeCapacity() || marketCapacity;
|
marketCapacity = town.getTradeCapacity() || 0;
|
||||||
}
|
availableTradeCapacity = town.getAvailableTradeCapacity?.() ?? marketCapacity;
|
||||||
// Available = total minus what is already used by pending trades
|
|
||||||
if (town.getAvailableTradeCapacity) {
|
|
||||||
availableTradeCapacity = town.getAvailableTradeCapacity() ?? marketCapacity;
|
|
||||||
} else {
|
|
||||||
// Fallback: read from trade collection
|
|
||||||
let usedCapacity = 0;
|
|
||||||
try {
|
|
||||||
const tradeColl = uw.MM.getOnlyCollectionByName('Trade');
|
|
||||||
if (tradeColl) {
|
|
||||||
tradeColl.models.forEach(m => {
|
|
||||||
if (String(m.attributes?.town_id) === String(town.id)) {
|
|
||||||
usedCapacity += (m.attributes?.capacity || 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e2) {}
|
|
||||||
availableTradeCapacity = Math.max(0, marketCapacity - usedCapacity);
|
|
||||||
}
|
}
|
||||||
} catch (e) { log(`market capacity lookup failed: ${e}`); }
|
} catch (e) { log(`market capacity lookup failed: ${e}`); }
|
||||||
|
|
||||||
|
|||||||
@@ -258,11 +258,11 @@
|
|||||||
<script>
|
<script>
|
||||||
window.PLAYER_ID = "{{ player_id }}";
|
window.PLAYER_ID = "{{ player_id }}";
|
||||||
</script>
|
</script>
|
||||||
<script src="/static/js/state.js?v=4"></script>
|
<script src="/static/js/state.js?v=5"></script>
|
||||||
<script src="/static/js/components/townViewer.js?v=4"></script>
|
<script src="/static/js/components/townViewer.js?v=5"></script>
|
||||||
<script src="/static/js/components/commandForm.js?v=4"></script>
|
<script src="/static/js/components/commandForm.js?v=5"></script>
|
||||||
<script src="/static/js/components/commandLog.js?v=4"></script>
|
<script src="/static/js/components/commandLog.js?v=5"></script>
|
||||||
<script src="/static/js/api.js?v=4"></script>
|
<script src="/static/js/api.js?v=5"></script>
|
||||||
<script src="/static/js/app.js?v=4"></script>
|
<script src="/static/js/app.js?v=5"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user