1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 18:45:34 +00:00

key usage to open doors or containers

to test: player->additem, "key_arrile", 1 (door in arille's tradehouse)
player->additem, "key_alvur", 1 (chest in the back of beshara)
This commit is contained in:
scrawl 2012-09-10 17:44:59 +02:00
parent fdc2a7433c
commit 89ad2af1d9
3 changed files with 95 additions and 49 deletions

View file

@ -14,6 +14,8 @@
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/actionopen.hpp" #include "../mwworld/actionopen.hpp"
#include "../mwworld/physicssystem.hpp" #include "../mwworld/physicssystem.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
@ -87,15 +89,31 @@ namespace MWClass
const std::string lockedSound = "LockedChest"; const std::string lockedSound = "LockedChest";
const std::string trapActivationSound = "Disarm Trap Fail"; const std::string trapActivationSound = "Disarm Trap Fail";
if (ptr.getCellRef().lockLevel>0) MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player);
bool needKey = ptr.getCellRef().lockLevel>0;
bool hasKey = false;
std::string keyName;
for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it)
{ {
// TODO check for key if (it->getCellRef ().refID == ptr.getCellRef().key)
std::cout << "Locked container" << std::endl; {
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction); hasKey = true;
action->setSound(lockedSound); keyName = MWWorld::Class::get(*it).getName(*it);
return action;
} }
else }
if (needKey && hasKey)
{
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}", std::vector<std::string>());
ptr.getCellRef().lockLevel = 0;
// using a key disarms the trap
ptr.getCellRef().trap = "";
}
if (!needKey || hasKey)
{ {
if(ptr.getCellRef().trap.empty()) if(ptr.getCellRef().trap.empty())
{ {
@ -112,6 +130,12 @@ namespace MWClass
return action; return action;
} }
} }
else
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(lockedSound);
return action;
}
} }
std::string Container::getName (const MWWorld::Ptr& ptr) const std::string Container::getName (const MWWorld::Ptr& ptr) const

View file

@ -13,6 +13,7 @@
#include "../mwworld/actionteleport.hpp" #include "../mwworld/actionteleport.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp" #include "../mwworld/physicssystem.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
@ -74,19 +75,31 @@ namespace MWClass
const std::string lockedSound = "LockedDoor"; const std::string lockedSound = "LockedDoor";
const std::string trapActivationSound = "Disarm Trap Fail"; const std::string trapActivationSound = "Disarm Trap Fail";
if (ptr.getCellRef().lockLevel>0) MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player);
bool needKey = ptr.getCellRef().lockLevel>0;
bool hasKey = false;
std::string keyName;
for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it)
{ {
// TODO check for key if (it->getCellRef ().refID == ptr.getCellRef().key)
// TODO report failure to player (message, sound?). Look up behaviour of original MW. {
std::cout << "Locked!" << std::endl; hasKey = true;
keyName = MWWorld::Class::get(*it).getName(*it);
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction); }
action->setSound(lockedSound);
return action;
} }
if (needKey && hasKey)
{
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}", std::vector<std::string>());
ptr.getCellRef().lockLevel = 0;
// using a key disarms the trap
ptr.getCellRef().trap = "";
}
if (!needKey || hasKey)
{
if(!ptr.getCellRef().trap.empty()) if(!ptr.getCellRef().trap.empty())
{ {
// Trap activation // Trap activation
@ -131,6 +144,14 @@ namespace MWClass
return action; return action;
} }
} }
else
{
// locked, and we can't open.
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(lockedSound);
return action;
}
}
void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const
{ {

View file

@ -179,6 +179,7 @@ namespace MWGui
mWindowManager.getInventoryWindow()->transferBoughtItems(); mWindowManager.getInventoryWindow()->transferBoughtItems();
// add or remove gold from the player. // add or remove gold from the player.
if (mCurrentBalance != 0)
addOrRemoveGold(mCurrentBalance); addOrRemoveGold(mCurrentBalance);
std::string sound = "Item Gold Up"; std::string sound = "Item Gold Up";