polserver/pol-core/pol/door.cpp

104 lines
1.9 KiB
C++
Raw Permalink Normal View History

/** @file
*
* @par History
*/
2016-02-11 22:54:43 +01:00
#include "door.h"
#include <stddef.h>
#include "bscript/executor.h"
#include "clib/rawtypes.h"
#include "base/vector.h"
#include "globals/uvars.h"
2016-02-11 22:54:43 +01:00
#include "item/itemdesc.h"
#include "network/client.h"
#include "syshookscript.h"
2016-02-11 22:54:43 +01:00
#include "ufunc.h"
#include "uworld.h"
namespace Pol
{
namespace Core
{
UDoor::UDoor( const Items::DoorDesc& descriptor ) : ULockable( descriptor, UOBJ_CLASS::CLASS_ITEM )
{
}
2016-02-11 22:54:43 +01:00
void UDoor::builtin_on_use( Network::Client* client )
{
if ( locked() )
{
private_say_above( client->chr, this, "That is locked." );
}
else
{
toggle();
}
}
2016-02-11 22:54:43 +01:00
void UDoor::toggle()
{
const Items::DoorDesc* dd = static_cast<const Items::DoorDesc*>( &itemdesc() );
2016-02-11 22:54:43 +01:00
Pos4d oldpos = pos();
2016-02-11 22:54:43 +01:00
set_dirty();
if ( is_open() )
{
if ( dd->graphic )
graphic = dd->graphic;
else
graphic = static_cast<u16>( objtype_ );
setposition( pos() - dd->mod );
}
else
{
graphic = dd->open_graphic;
setposition( pos() + dd->mod );
}
2016-02-11 22:54:43 +01:00
MoveItemWorldPosition( oldpos, this );
2016-02-11 22:54:43 +01:00
send_item_to_inrange( this );
}
2016-02-11 22:54:43 +01:00
bool UDoor::is_open() const
{
const Items::DoorDesc* dd = static_cast<const Items::DoorDesc*>( &itemdesc() );
if ( graphic == dd->open_graphic )
return true;
else
return false;
}
2016-02-11 22:54:43 +01:00
void UDoor::open()
{
if ( !is_open() )
toggle();
}
2016-02-11 22:54:43 +01:00
void UDoor::close()
{
if ( is_open() )
toggle();
}
2016-02-11 22:54:43 +01:00
size_t UDoor::estimatedSize() const
{
return base::estimatedSize();
}
bool UDoor::get_method_hook( const char* methodname, Bscript::Executor* ex, ExportScript** hook,
unsigned int* PC ) const
{
if ( gamestate.system_hooks.get_method_hook( gamestate.system_hooks.door_method_script.get(),
methodname, ex, hook, PC ) )
return true;
return base::get_method_hook( methodname, ex, hook, PC );
}
} // namespace Core
} // namespace Pol