MCPcopy Create free account
hub / github.com/EasyRPG/Player / IsItemUsable

Method IsItemUsable

src/game_party.cpp:269–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269bool Game_Party::IsItemUsable(int item_id, const Game_Actor* target) const {
270 if (target && !target->IsItemUsable(item_id)) {
271 return false;
272 }
273
274 const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
275 if (!item) {
276 Output::Warning("IsItemUsable: Invalid item ID {}", item_id);
277 return false;
278 }
279
280 const auto* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, item->skill_id);
281 const bool in_battle = Game_Battle::IsBattleRunning();
282
283 if (item->use_skill) {
284 // RPG_RT BUG: Does not check if skill is usable.
285 return skill &&
286 (in_battle
287 || skill->scope == lcf::rpg::Skill::Scope_self
288 || skill->scope == lcf::rpg::Skill::Scope_ally
289 || skill->scope == lcf::rpg::Skill::Scope_party);
290 }
291
292 switch (item->type) {
293 case lcf::rpg::Item::Type_medicine:
294 return !in_battle || !item->occasion_field1;
295 case lcf::rpg::Item::Type_material:
296 case lcf::rpg::Item::Type_book:
297 return !in_battle;
298 case lcf::rpg::Item::Type_switch:
299 return in_battle ? item->occasion_battle : item->occasion_field2;
300 case lcf::rpg::Item::Type_special:
301 if (skill && Algo::IsSkillUsable(*skill, false)) {
302 // RPG_RT requires one actor in the party and alive who can use the item.
303 // But only if the item invokes a normal or subskill. This check is
304 // not performed for escape, teleport, or switch skills!
305 if (!Algo::IsNormalOrSubskill(*skill)) {
306 return true;
307 } else {
308 for (auto* actor: GetActors()) {
309 if (actor->CanAct() && actor->IsItemUsable(item_id)) {
310 return true;
311 }
312 }
313 }
314 }
315 return false;
316 default:
317 break;
318 }
319
320 return false;
321}
322
323bool Game_Party::UseItem(int item_id, Game_Actor* target) {
324 bool was_used = false;

Callers 1

Calls 3

IsSkillUsableFunction · 0.85
IsNormalOrSubskillFunction · 0.85
CanActMethod · 0.80

Tested by

no test coverage detected