1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 15: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/actionopen.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwgui/tooltips.hpp"
@ -87,15 +89,31 @@ namespace MWClass
const std::string lockedSound = "LockedChest";
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
std::cout << "Locked container" << std::endl;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(lockedSound);
return action;
if (it->getCellRef ().refID == ptr.getCellRef().key)
{
hasKey = true;
keyName = MWWorld::Class::get(*it).getName(*it);
}
}
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())
{
@ -112,6 +130,12 @@ namespace MWClass
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

View file

@ -13,6 +13,7 @@
#include "../mwworld/actionteleport.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwgui/tooltips.hpp"
@ -74,60 +75,80 @@ namespace MWClass
const std::string lockedSound = "LockedDoor";
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
// TODO report failure to player (message, sound?). Look up behaviour of original MW.
std::cout << "Locked!" << std::endl;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(lockedSound);
return action;
}
if(!ptr.getCellRef().trap.empty())
{
// Trap activation
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(trapActivationSound);
ptr.getCellRef().trap = "";
return action;
}
if (ref->ref.teleport)
{
// teleport door
/// \todo remove this if clause once ActionTeleport can also support other actors
if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor)
if (it->getCellRef ().refID == ptr.getCellRef().key)
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest));
hasKey = true;
keyName = MWWorld::Class::get(*it).getName(*it);
}
}
action->setSound(openSound);
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())
{
// Trap activation
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(trapActivationSound);
ptr.getCellRef().trap = "";
return action;
}
if (ref->ref.teleport)
{
// teleport door
/// \todo remove this if clause once ActionTeleport can also support other actors
if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor)
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest));
action->setSound(openSound);
return action;
}
else
{
// another NPC or a creature is using the door
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
}
}
else
{
// another NPC or a creature is using the door
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
// animated door
// TODO return action for rotating the door
// This is a little pointless, but helps with testing
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(openSound);
return action;
}
}
else
{
// animated door
// TODO return action for rotating the door
// This is a little pointless, but helps with testing
// locked, and we can't open.
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(openSound);
action->setSound(lockedSound);
return action;
}
}

View file

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