Major refactoring for game objects
This commit is contained in:
1 parent
efb85f7328
commit
2cae9998a0
18 files changed
+547
-716
No files matched your search
+24
-63
@@ -4,6 +4,7 @@
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include "Location.h"
|
||||
#include "items/ItemRegistry.h"
|
||||
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
#include <sol/sol.hpp>
|
||||
@@ -53,34 +54,15 @@ namespace ZL {
|
||||
npcs[index]->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
|
||||
});
|
||||
|
||||
// pickup_item(object_name)
|
||||
api.set_function("pickup_item", [game, inventory](const std::string& objectName) {
|
||||
|
||||
|
||||
std::cout << "[script] pickup_item: " << objectName << std::endl;
|
||||
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.id == objectName && intObj.isActive) {
|
||||
// Add item to inventory
|
||||
inventory->addItem(intObj.dropItem);
|
||||
|
||||
// Deactivate object
|
||||
intObj.isActive = false;
|
||||
|
||||
std::cout << "[script] Item picked up successfully: " << intObj.dropItem.name << std::endl;
|
||||
return;
|
||||
}
|
||||
// pickup_item(item_id)
|
||||
api.set_function("pickup_item", [inventory](const std::string& itemId) {
|
||||
const Item* item = ItemRegistry::instance().findById(itemId);
|
||||
if (item) {
|
||||
inventory->addItem(*item);
|
||||
std::cout << "[script] pickup_item: " << item->name << std::endl;
|
||||
} else {
|
||||
std::cerr << "[script] pickup_item: item '" << itemId << "' not found in ItemRegistry\n";
|
||||
}
|
||||
std::cerr << "[script] Warning: Interactive object not found or already picked up: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
|
||||
// add_item(item_id, name, description, icon)
|
||||
api.set_function("add_item", [game, inventory](const std::string& id, const std::string& name,
|
||||
const std::string& description, const std::string& icon) {
|
||||
std::cout << "[script] add_item: " << name << std::endl;
|
||||
Item newItem(id, name, description, icon);
|
||||
inventory->addItem(newItem);
|
||||
});
|
||||
|
||||
// remove_item(item_id)
|
||||
@@ -91,15 +73,26 @@ namespace ZL {
|
||||
|
||||
// deactivate_interactive_object(object_name)
|
||||
api.set_function("deactivate_interactive_object", [game](const std::string& objectName) {
|
||||
std::cout << "[script] deactivate_interactive_object: " << objectName << std::endl;
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.id == objectName) {
|
||||
if (intObj.loadedObject.name == objectName) {
|
||||
intObj.isActive = false;
|
||||
std::cout << "[script] Interactive object deactivated: " << objectName << std::endl;
|
||||
std::cout << "[script] deactivate_interactive_object: " << objectName << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "[script] Warning: Interactive object not found: " << objectName << std::endl;
|
||||
std::cerr << "[script] deactivate_interactive_object: not found: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
// activate_interactive_object(object_name)
|
||||
api.set_function("activate_interactive_object", [game](const std::string& objectName) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name == objectName) {
|
||||
intObj.isActive = true;
|
||||
std::cout << "[script] activate_interactive_object: " << objectName << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "[script] activate_interactive_object: not found: " << objectName << std::endl;
|
||||
});
|
||||
|
||||
// get_inventory_count()
|
||||
@@ -181,38 +174,6 @@ namespace ZL {
|
||||
npcs[index]->enabled = value;
|
||||
});
|
||||
|
||||
// receive_npc_gift(npc_index)
|
||||
api.set_function("receive_npc_gift", [game, inventory](int npcIndex) {
|
||||
std::cout << "[script] receive_npc_gift: npc index " << npcIndex << std::endl;
|
||||
|
||||
auto& npcs = game->npcs;
|
||||
if (npcIndex < 0 || npcIndex >= static_cast<int>(npcs.size())) {
|
||||
std::cerr << "[script] receive_npc_gift: index out of range\n";
|
||||
return;
|
||||
}
|
||||
|
||||
auto& npc = npcs[npcIndex];
|
||||
if (!npc) {
|
||||
std::cerr << "[script] receive_npc_gift: npc is null\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc->giftReceived) {
|
||||
std::cout << "[script] NPC " << npc->npcName << " already gave gift\n";
|
||||
return;
|
||||
}
|
||||
if (npc->giftItem.id.empty()) {
|
||||
std::cerr << "[script] receive_npc_gift: NPC has no gift\n";
|
||||
return;
|
||||
}
|
||||
|
||||
inventory->addItem(npc->giftItem);
|
||||
npc->giftReceived = true;
|
||||
|
||||
std::cout << "[script] Received gift from " << npc->npcName << ": "
|
||||
<< npc->giftItem.name << std::endl;
|
||||
});
|
||||
|
||||
lua.script_file(scriptPath);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user