mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
104 lines
1.9 KiB
C++
104 lines
1.9 KiB
C++
/** @file
|
|
*
|
|
* @par History
|
|
*/
|
|
|
|
#include "door.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "../bscript/executor.h"
|
|
#include "../clib/rawtypes.h"
|
|
#include "globals/uvars.h"
|
|
#include "item/itemdesc.h"
|
|
#include "network/client.h"
|
|
#include "syshookscript.h"
|
|
#include "ufunc.h"
|
|
#include "uworld.h"
|
|
|
|
|
|
namespace Pol
|
|
{
|
|
namespace Core
|
|
{
|
|
UDoor::UDoor( const Items::DoorDesc& descriptor ) : ULockable( descriptor, UOBJ_CLASS::CLASS_ITEM )
|
|
{
|
|
}
|
|
|
|
void UDoor::builtin_on_use( Network::Client* client )
|
|
{
|
|
if ( locked() )
|
|
{
|
|
private_say_above( client->chr, this, "That is locked." );
|
|
}
|
|
else
|
|
{
|
|
toggle();
|
|
}
|
|
}
|
|
|
|
void UDoor::toggle()
|
|
{
|
|
const Items::DoorDesc* dd = static_cast<const Items::DoorDesc*>( &itemdesc() );
|
|
|
|
Pos4d oldpos = this->pos();
|
|
Pos4d newpos = oldpos;
|
|
|
|
set_dirty();
|
|
if ( is_open() )
|
|
{
|
|
if ( dd->graphic )
|
|
graphic = dd->graphic;
|
|
else
|
|
graphic = static_cast<u16>( objtype_ );
|
|
|
|
newpos -= Vec2d( dd->xmod, dd->ymod );
|
|
}
|
|
else
|
|
{
|
|
graphic = dd->open_graphic;
|
|
newpos += Vec2d( dd->xmod, dd->ymod );
|
|
}
|
|
|
|
this->setposition( newpos );
|
|
MoveItemWorldPosition( oldpos, this );
|
|
|
|
send_item_to_inrange( this );
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void UDoor::open()
|
|
{
|
|
if ( !is_open() )
|
|
toggle();
|
|
}
|
|
|
|
void UDoor::close()
|
|
{
|
|
if ( is_open() )
|
|
toggle();
|
|
}
|
|
|
|
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
|