auction: GetAuctionSellItemInfo answers maxStack and link, as the patched 1.12 Lua reads

This commit is contained in:
chairmanpow
2026-10-06 17:05:56 +01:00
parent e42270f762
commit 7e043060eb
+33 -5
View File
@@ -250,7 +250,19 @@ fn row_at(model: &Model, kind: &str, index: usize) -> Option<AuctionItemRow> {
/// The sell slot's `(name, texture, count, quality, canUse, stackValue)`, `stackValue` being the
/// vendor price times the stack: the base of the suggested opening price and the deposit.
fn sell_item_info(model: &Model) -> Option<(String, Option<String>, u32, i64, bool, u32)> {
#[allow(clippy::type_complexity)]
fn sell_item_info(
model: &Model,
) -> Option<(
String,
Option<String>,
u32,
i64,
bool,
u32,
u32,
Option<String>,
)> {
let it = model.auction_sell_item.as_ref()?;
// The real stack size, not the split-carry field: the deposit is per stack.
let count = cursor::held_count(model, it);
@@ -259,6 +271,9 @@ fn sell_item_info(model: &Model) -> Option<(String, Option<String>, u32, i64, bo
let quality = it.quality.map_or(-1, i64::from);
let sell_price = template.map_or(0, |v| v.sell_price);
let can_use = super::item_stats::item_usable_by_id(model, it.item_id);
// The item's stack size, the seventh value the patched 1.12 Lua reads for its deposit
// (`Blizzard_AuctionUI.lua:1123`); 1 when the template is unknown, so the arithmetic is safe.
let max_stack = template.map_or(1, |v| v.stackable.max(1));
Some((
name,
it.texture.clone(),
@@ -266,6 +281,8 @@ fn sell_item_info(model: &Model) -> Option<(String, Option<String>, u32, i64, bo
quality,
can_use,
sell_price.saturating_mul(count),
max_stack,
it.link.clone(),
))
}
@@ -682,13 +699,16 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
lua.create_function(|lua, minutes: u32| {
let model = lua.app_data_ref::<Model>().expect("model app_data");
let rate = model.auction.as_ref().map_or(0, |a| a.deposit_percent);
let stack_value = sell_item_info(&model).map_or(0, |(_, _, _, _, _, v)| v);
let stack_value = sell_item_info(&model).map_or(0, |(_, _, _, _, _, v, _, _)| v);
Ok(i64::from(deposit_for(rate, stack_value, minutes)))
})?,
)?;
// GetAuctionSellItemInfo() → name, texture, count, quality, canUse, price: six values always.
// An empty slot answers count 1 and quality -1: the stock Lua reads `count > 1` unguarded.
// GetAuctionSellItemInfo() → name, texture, count, quality, canUse, price, maxStack, link: the
// eight the patched 1.12 Lua reads (`Blizzard_AuctionUI.lua:1123` reads `maxStack` for the
// deposit; the era's own six plus the stacked-item pair). An empty slot answers count 1,
// quality -1 and maxStack 1: the stock Lua reads `count > 1` and does `maxStack - stackSize`
// unguarded, so both must be numbers.
g.set(
"GetAuctionSellItemInfo",
lua.create_function(|lua, ()| {
@@ -696,7 +716,8 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let model = lua.app_data_ref::<Model>().expect("model app_data");
sell_item_info(&model)
};
let Some((name, texture, count, quality, can_use, price)) = info else {
let Some((name, texture, count, quality, can_use, price, max_stack, link)) = info
else {
return Ok(MultiValue::from_vec(vec![
Value::Nil,
Value::Nil,
@@ -704,6 +725,8 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Value::Integer(-1),
Value::Nil,
Value::Integer(0),
Value::Integer(1),
Value::Nil,
]));
};
Ok(MultiValue::from_vec(vec![
@@ -720,6 +743,11 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Value::Integer(quality),
flag(can_use),
Value::Integer(i64::from(price)),
Value::Integer(i64::from(max_stack)),
match &link {
Some(l) => Value::String(lua.create_string(l)?),
None => Value::Nil,
},
]))
})?,
)?;