mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
[Cleanup] Rework Lua QuestReward to not use try/catch blocks (#2417)
Quest system will catch any errors and result it in being reported where these weren't
This commit is contained in:
parent
5134a0e43b
commit
ba53b4144e
@ -1683,110 +1683,52 @@ void Lua_Client::QuestReward(Lua_Mob target, luabind::adl::object reward) {
|
|||||||
QuestReward_Struct quest_reward;
|
QuestReward_Struct quest_reward;
|
||||||
quest_reward.mob_id = 0;
|
quest_reward.mob_id = 0;
|
||||||
quest_reward.target_id = self->GetID();
|
quest_reward.target_id = self->GetID();
|
||||||
quest_reward.copper = 0;
|
quest_reward.copper = luabind::type(reward["copper"]) != LUA_TNIL ? luabind::object_cast<uint32>(reward["copper"]) : 0;
|
||||||
quest_reward.silver = 0;
|
quest_reward.silver = luabind::type(reward["silver"]) != LUA_TNIL ? luabind::object_cast<uint32>(reward["silver"]) : 0;
|
||||||
quest_reward.gold = 0;
|
quest_reward.gold = luabind::type(reward["gold"]) != LUA_TNIL ? luabind::object_cast<uint32>(reward["gold"]) : 0;
|
||||||
quest_reward.platinum = 0;
|
quest_reward.platinum = luabind::type(reward["platinum"]) != LUA_TNIL ? luabind::object_cast<uint32>(reward["platinum"]) : 0;
|
||||||
quest_reward.exp_reward = 0;
|
quest_reward.exp_reward = luabind::type(reward["exp"]) != LUA_TNIL ? luabind::object_cast<uint32>(reward["exp"]) : 0;
|
||||||
quest_reward.faction = 0;
|
quest_reward.faction = 0;
|
||||||
quest_reward.faction_mod = 0;
|
quest_reward.faction_mod = 0;
|
||||||
bool faction = false;
|
bool faction = false;
|
||||||
std::fill(std::begin(quest_reward.item_id), std::end(quest_reward.item_id), -1);
|
std::fill(std::begin(quest_reward.item_id), std::end(quest_reward.item_id), -1);
|
||||||
|
|
||||||
auto cur = reward["copper"];
|
auto item_id = reward["itemid"];
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
if (luabind::type(item_id) != LUA_TNIL) {
|
||||||
try {
|
quest_reward.item_id[0] = luabind::object_cast<uint32>(item_id);
|
||||||
quest_reward.copper = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = reward["silver"];
|
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
|
||||||
try {
|
|
||||||
quest_reward.silver = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = reward["gold"];
|
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
|
||||||
try {
|
|
||||||
quest_reward.gold = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = reward["platinum"];
|
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
|
||||||
try {
|
|
||||||
quest_reward.platinum = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = reward["itemid"];
|
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
|
||||||
try {
|
|
||||||
quest_reward.item_id[0] = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if you define both an itemid and items table, the itemid is thrown away
|
// if you define both an itemid and items table, the itemid is thrown away
|
||||||
// should we error?
|
// should we error?
|
||||||
cur = reward["items"];
|
auto items = reward["items"];
|
||||||
if (luabind::type(cur) == LUA_TTABLE) {
|
if (luabind::type(items) == LUA_TTABLE) {
|
||||||
try {
|
|
||||||
// assume they defined a compatible table
|
// assume they defined a compatible table
|
||||||
for (int i = 1; i <= QUESTREWARD_COUNT; ++i) {
|
for (int i = 1; i <= QUESTREWARD_COUNT; ++i) {
|
||||||
auto item = cur[i];
|
auto item = items[i];
|
||||||
int cur_value = -1;
|
int cur_value = -1;
|
||||||
if (luabind::type(item) != LUA_TNIL) {
|
if (luabind::type(item) != LUA_TNIL) {
|
||||||
try {
|
|
||||||
cur_value = luabind::object_cast<uint32>(item);
|
cur_value = luabind::object_cast<uint32>(item);
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
quest_reward.item_id[i - 1] = cur_value;
|
quest_reward.item_id[i - 1] = cur_value;
|
||||||
}
|
}
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = reward["exp"];
|
auto lua_faction = reward["faction"];
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
if (luabind::type(lua_faction) != LUA_TNIL) {
|
||||||
try {
|
|
||||||
quest_reward.exp_reward = luabind::object_cast<uint32>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = reward["faction"];
|
|
||||||
if (luabind::type(cur) != LUA_TNIL) {
|
|
||||||
// if it's a table it will be {faction, faction_mod}
|
// if it's a table it will be {faction, faction_mod}
|
||||||
if (luabind::type(cur) == LUA_TTABLE) {
|
if (luabind::type(lua_faction) == LUA_TTABLE) {
|
||||||
auto item = cur[1];
|
auto item = lua_faction[1];
|
||||||
if (luabind::type(item) != LUA_TNIL) {
|
if (luabind::type(item) != LUA_TNIL) {
|
||||||
try {
|
|
||||||
quest_reward.faction = luabind::object_cast<uint32>(item);
|
quest_reward.faction = luabind::object_cast<uint32>(item);
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
}
|
||||||
}
|
item = lua_faction[2];
|
||||||
item = cur[2];
|
|
||||||
if (luabind::type(item) != LUA_TNIL) {
|
if (luabind::type(item) != LUA_TNIL) {
|
||||||
try {
|
|
||||||
quest_reward.faction_mod = luabind::object_cast<uint32>(item);
|
quest_reward.faction_mod = luabind::object_cast<uint32>(item);
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
faction = luabind::object_cast<bool>(lua_faction);
|
||||||
faction = luabind::object_cast<bool>(cur);
|
|
||||||
} catch (luabind::cast_failed &) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user