void LuaChatForm::Sold(Equip::Type t) { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "sold"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 0); LUA_DEBUG_END(l, 0); }
void LuaChatForm::Bought(Equip::Type t) { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "bought"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, LuaConstants::GetConstantString(l, "EquipType", t)); pi_lua_protected_call(l, 2, 0); LUA_DEBUG_END(l, 0); }
Sint64 LuaChatForm::GetPrice(Equip::Type t) const { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "getPrice"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 1); Sint64 price = Sint64(lua_tonumber(l, -1) * 100.0); lua_pop(l, 1); LUA_DEBUG_END(l, 0); return price; }
int LuaChatForm::GetStock(Equip::Type t) const { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "getStock"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 1); int stock = lua_tointeger(l, -1); lua_pop(l, 1); LUA_DEBUG_END(l, 0); return stock; }
bool LuaChatForm::DoesSell(Equip::Type t) const { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "canTrade"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 1); bool can_trade = lua_toboolean(l, -1) != 0; lua_pop(l, 1); LUA_DEBUG_END(l, 0); return can_trade; }
void LuaChatForm::OnClickSell(int t) { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "onClickSell"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 1); bool allow_sell = lua_toboolean(l, -1) != 0; lua_pop(l, 1); LUA_DEBUG_END(l, 0); if (allow_sell) { if (BuyFrom(Pi::player, static_cast<Equip::Type>(t), true)) { Pi::Message(stringf(Lang::SOLD_1T_OF, formatarg("commodity", Equip::types[t].name))); } m_commodityTradeWidget->UpdateStock(t); } }