Beispiel #1
0
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);
}
Beispiel #2
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);
}
Beispiel #3
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;
}
Beispiel #4
0
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;
}
Beispiel #5
0
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;
}
Beispiel #6
0
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);
	}
}