13 #include "../../bscript/berror.h" 14 #include "../../bscript/bobject.h" 15 #include "../../bscript/impstr.h" 16 #include "../../clib/clib.h" 17 #include "../../clib/compilerspecifics.h" 18 #include "../../clib/logfacility.h" 19 #include "../../clib/random.h" 20 #include "../../clib/rawtypes.h" 21 #include "../../clib/stlutil.h" 22 #include "../../clib/strutil.h" 23 #include "../containr.h" 24 #include "../item/item.h" 25 #include "../mobile/boundbox.h" 26 #include "../mobile/charactr.h" 27 #include "../mobile/npc.h" 28 #include "../mobile/ufacing.h" 29 #include "../network/packethelper.h" 30 #include "../network/packets.h" 31 #include "../objtype.h" 32 #include "../pktdef.h" 33 #include "../poltype.h" 34 #include "../unicode.h" 35 #include "../uoscrobj.h" 36 #include "../uworld.h" 44 using namespace Module;
85 using namespace Bscript;
91 throw std::runtime_error(
"NPCExecutorModule needs OS module!" );
123 return new BLong( 0 );
132 return new BLong( 0 );
155 <<
"\tCall to function npc::canmove():\n" 156 <<
"\tParameter 0: Expected direction: N S E W NW NE SW SE, got " << dir <<
"\n";
157 return new BError(
"Invalid facing value" );
171 <<
"\tCall to function npc::canmove():\n" 172 <<
"\tParameter 0: Expected direction, got datatype " 174 return new BError(
"Invalid parameter type" );
178 return new BError(
"Invalid parameter count" );
194 return new BError(
"Invalid Coordinates for Realm" );
198 npc.
anchor.
x =
static_cast<unsigned short>( x );
199 npc.
anchor.
y =
static_cast<unsigned short>( y );
202 return new BLong( 1 );
207 return new BLong( 1 );
212 return new BError(
"Invalid parameter type" );
219 bool success =
false;
227 static_cast<unsigned char>( dir ) ) )
242 bool success =
false;
257 if ( success ==
true )
282 return new BLong( success ? 1 : 0 );
288 bool adjust_ok =
true;
308 return move_self( static_cast<Core::UFACING>( newfacing ),
false, adjust_ok );
317 return new BError(
"Invalid parameter type." );
328 <<
"\tCall to function npc::face():\n" 329 <<
"\tParameter 0: Expected direction: N S E W NW NE SW SE, got " << dir <<
"\n";
341 <<
"\tCall to function npc::face():\n" 342 <<
"\tParameter 0: Expected direction, " 348 if ( !
npc.
face( i_facing, flags ) )
349 return new BLong( 0 );
352 return new BLong( i_facing );
367 <<
"\tCall to function npc::move():\n" 368 <<
"\tParameter 0: Expected direction: N S E W NW NE SW SE, got " << dir <<
"\n";
394 npc.
move( static_cast<unsigned char>( facing ) );
407 <<
"\tCall to function npc::move():\n" 408 <<
"\tParameter 0: Expected direction or bounding box, " 416 <<
"\tCall to function npc::move():\n" 417 <<
"\tParameter 0: Expected direction or bounding box, " 433 return new BError(
"Mobile specified cannot be seen" );
440 return new BError(
"Invalid parameter type" );
454 return new BError(
"Mobile specified cannot be seen" );
460 return new BError(
"Invalid parameter type" );
473 return new BError(
"Mobile specified cannot be seen" );
479 return new BError(
"Invalid parameter type" );
492 return new BError(
"Mobile specified cannot be seen" );
498 return new BError(
"Invalid parameter type" );
509 return new BError(
"Invalid parameter type" );
516 return new BError(
"Mobile specified cannot be seen" );
521 return new BLong( 0 );
523 if ( !
npc.
face( facing, flags ) )
524 return new BLong( 0 );
527 return new BLong( 1 );
537 return new BError(
"Invalid parameter type" );
545 return new BError(
"Mobile specified cannot be seen" );
550 return new BLong( 0 );
552 if ( !
npc.
face( facing, flags ) )
553 return new BLong( 0 );
556 return new BLong( 1 );
566 return new BError(
"Invalid Coordinates for Realm" );
572 return new BError(
"Invalid parameter type" );
584 return new BError(
"Invalid Coordinates for Realm" );
590 return new BError(
"Invalid parameter type" );
601 return new BError(
"Invalid Coordinates for Realm" );
607 return new BError(
"Invalid parameter type" );
618 return new BError(
"Invalid Coordinates for Realm" );
624 return new BError(
"Invalid parameter type" );
636 return new BError(
"Invalid parameter type" );
640 return new BError(
"Invalid Coordinates for Realm" );
643 return new BLong( 0 );
646 return new BLong( 0 );
649 return new BLong( 1 );
660 return new BError(
"Invalid parameter type" );
664 return new BError(
"Invalid Coordinates for Realm" );
667 return new BLong( 0 );
670 return new BLong( 0 );
673 return new BLong( 1 );
680 return new BError(
"NPC is squelched" );
689 if ( texttype_str ==
"default" )
691 else if ( texttype_str ==
"whisper" )
693 else if ( texttype_str ==
"yell" )
696 return new BError(
"texttype string param must be either 'default', 'whisper', or 'yell'" );
703 msg->Write<
u8>( texttype );
704 msg->WriteFlipped<
u16>(
npc.speech_color() );
705 msg->WriteFlipped<
u16>(
npc.speech_font() );
706 msg->Write(
npc.
name().c_str(), 30 );
709 : static_cast<u16>( strlen( text ) + 1 ) );
710 u16 len = msg->offset;
712 msg->WriteFlipped<
u16>( len );
724 if ( !chr->is_visible_to_me( &npc ) )
726 msg.Send( chr->client, len );
733 Mobile::NPC* othernpc = static_cast<Mobile::NPC*>( chr );
735 othernpc->on_pc_spoke( &npc, text, texttype );
745 return new BError(
"NPC is squelched" );
756 if ( texttype_str !=
"default" && texttype_str !=
"whisper" && texttype_str !=
"yell" )
758 return new BError(
"texttype string param must be either 'default', 'whisper', or 'yell'" );
761 size_t textlenucc = oText->
ref_arr.size();
763 return new BError(
"Unicode array exceeds maximum size." );
764 if ( lang->
length() != 3 )
765 return new BError(
"langcode must be a 3-character code." );
767 return new BError(
"Invalid value in Unicode array." );
770 unsigned textlen = 0;
773 while (
gwtext[textlen] != L
'\0' )
779 if ( texttype_str ==
"whisper" )
781 else if ( texttype_str ==
"yell" )
787 talkmsg->offset += 2;
790 talkmsg->Write<
u8>( texttype );
791 talkmsg->WriteFlipped<
u16>(
npc.speech_color() );
792 talkmsg->WriteFlipped<
u16>(
npc.speech_font() );
793 talkmsg->Write( languc.c_str(), 4 );
795 talkmsg->WriteFlipped( &
gwtext[0], static_cast<u16>( textlen ) );
796 u16 len = talkmsg->offset;
798 talkmsg->WriteFlipped<
u16>( len );
809 if ( !chr->is_visible_to_me( &npc ) )
811 talkmsg.Send( chr->client, len );
818 for (
unsigned i = 0; i < textlen; ++i )
820 ntextbuf[ntextbuflen++] = std::wcout.narrow( (
wchar_t)
gwtext[i],
'?' );
822 ntextbuf[ntextbuflen++] = 0;
825 Mobile::NPC* othernpc = static_cast<Mobile::NPC*>( chr );
826 if ( othernpc != &npc )
827 othernpc->on_pc_spoke( &npc, ntextbuf, texttype, gwtext, languc.c_str(), nullptr );
833 return new BError(
"A parameter was invalid" );
840 std::unique_ptr<BStruct> oa(
new BStruct );
842 oa->addMember(
"x",
new BLong(
npc.
x ) );
843 oa->addMember(
"y",
new BLong(
npc.
y ) );
844 oa->addMember(
"z",
new BLong(
npc.
z ) );
856 const String* propname_str;
866 return new BError(
"Property not found" );
871 return new BError(
"Invalid parameter type" );
877 const String* propname_str;
882 return new BLong( 1 );
886 return new BError(
"Invalid parameter type" );
897 std::unique_ptr<Items::Item> item( i );
904 return new BLong( 1 );
911 if ( objtype ==
nullptr )
912 return new BLong( 0 );
915 if ( backpack ==
nullptr )
916 return new BLong( 0 );
920 std::unique_ptr<Items::Item> item( i );
921 if ( item.get() == nullptr )
922 return new BLong( 0 );
924 if ( !backpack->
can_add( *item ) )
925 return new BLong( 0 );
927 u8 slotIndex = item->slot_index();
929 return new BLong( 0 );
931 if ( !item->slot_index( slotIndex ) )
932 return new BLong( 0 );
934 u32 serial = item->serial;
936 backpack->
add( item.release() );
938 return new BLong( serial );
945 if ( arealist ==
nullptr )
949 std::unique_ptr<BoundingBoxObjImp> bbox_owner( bbox );
957 while ( is >> a.topleft.x >> a.topleft.y >> a.bottomright.x >> a.bottomright.y )
959 ( *bbox )->addarea( a );
962 return bbox_owner.release();
971 return new BLong( 1 );
976 return new BLong( 0 );
986 return new BLong( 1 );
990 return new BLong( 0 );
Bscript::BObjectImp * mf_RunTowardLocation()
Bscript::BObjectImp * say()
Bscript::BObjectImp * mf_SetOpponent()
static Item * create(u32 objtype, u32 serial=0)
virtual ~NPCExecutorModule()
bool can_add_to_slot(u8 &slotIndex)
const std::string & value() const
std::vector< FunctionDef > FunctionTable
u16 gwtext[(SPEECH_MAX_LEN+1)]
Bscript::BObjectImp * face()
const char * FacingStr(Core::UFACING facing)
void set_opponent(Character *opponent, bool inform_old_opponent=true)
virtual bool can_add(const Items::Item &item) const
Bscript::BObjectImp * mf_WalkAwayFromLocation()
bool isa(BObjectType type) const
void setprop(const std::string &propname, const std::string &propvalue)
Bscript::BObjectImp * mf_Self()
virtual long contains(const BObjectImp &objimp) const
unsigned short whisper_range
bool getParam(unsigned param, int &value)
Core::UFACING GetRandomFacing()
unsigned short yell_range
virtual void on_facing_changed() POL_OVERRIDE
bool is_visible_to_me(const Character *chr) const
Bscript::BObjectImp * mf_RunToward()
bool _internal_move(Core::UFACING facing, int run)
BObjectImp * getParamImp(unsigned param)
const BLong * getLongParam(unsigned param)
Core::UFACING direction_toward(const Character *src, const Core::UObject *idst)
static void InRange(u16 x, u16 y, const Realms::Realm *realm, unsigned range, F &&f)
Bscript::BObjectImp * position()
virtual u8 typeOfInt() const POL_OVERRIDE
Bscript::BObjectImp * move()
const char * paramAsString(unsigned param)
virtual void add(Items::Item *item)
Bscript::BObjectImp * facing()
virtual std::string pack() const
#define EXPLICIT_CAST(totype, fromtype)
Bscript::BObjectImp * CreateItem()
virtual const char * typeOf() const POL_OVERRIDE
const BApplicObjType * object_type() const
Bscript::BObjectImp * mf_RunAwayFrom()
bool getCharacterParam(Bscript::Executor &exec, unsigned param, Mobile::Character *&chrptr)
bool getprop(const std::string &propname, std::string &propvalue) const
Bscript::BObjectImp * CanMove()
bool move(unsigned char dir)
bool face(Core::UFACING i_facing, int flags=0)
ExecutorModule * findModule(const std::string &name)
std::vector< BObjectRef > fparams
bool convertArrayToUC(Bscript::ObjArray *&in_text, u16 *out_wtext, size_t textlen, bool ConvToBE, bool nullterm)
BApplicObjType bounding_box_type
Bscript::BObjectImp * getproperty()
Bscript::BObjectImp * mf_TurnAwayFromLocation()
bool could_move(Core::UFACING dir) const
Bscript::BObjectImp * mf_SetWarMode()
void getpos_ifmove(Core::UFACING i_facing, unsigned short *px, unsigned short *py)
bool use_adjustments() const
static BObjectImp * unpack(const char *pstr)
virtual BObjectImp * copy() const POL_OVERRIDE
const std::string & scriptname() const
unsigned short speech_range
Bscript::BObjectImp * CreateBackpack()
const String * getStringParam(unsigned param)
void equip(Items::Item *item)
Bscript::BObjectImp * mf_Wander()
SettingsManager settingsManager
Bscript::BObjectImp * setproperty()
Bscript::BObjectImp * mf_RunAwayFromLocation()
#define PKTIN_02_FACING_MASK
Core::UContainer * backpack() const
std::array< int, 7 > adjustments
Bscript::BObjectImp * mf_SetAnchor()
bool getUObjectParam(Executor &exec, unsigned param, UObject *&objptr)
Bscript::BObjectImp * mf_WalkTowardLocation()
const String * getStringParam(unsigned param)
std::string strlower(const std::string &str)
BoundingBoxObjImp(const Mobile::BoundingBox &b)
bool anchor_allows_move(Core::UFACING dir) const
void set_warmode(bool warmode)
Core::UFACING direction_away(const Character *src, const Core::UObject *idst)
OSExecutorModule * os_module
Bscript::BObjectImp * mf_WalkToward()
Bscript::BObjectImp * mf_TurnTowardLocation()
bool getObjArrayParam(unsigned param, ObjArray *&pobjarr)
Bscript::BObjectImp * IsLegalMove()
Bscript::BObjectImp * mf_TurnAwayFrom()
bool valid(unsigned short x, unsigned short y, short z) const
bool run(int argc, char **argv)
std::string strupper(const std::string &str)
NPCExecutorModule(Bscript::Executor &ex, Mobile::NPC &npc)
bool equippable(const Items::Item *item) const
virtual std::string description() const
virtual std::string name() const
Bscript::BObjectImp * mf_TurnToward()
Bscript::BObjectImp * mf_WalkAwayFrom()
Bscript::BObjectImp * SayUC()
bool layer_is_equipped(int layer) const
bool DecodeFacing(const char *dir, Core::UFACING &facing)
static const char * typestr(BObjectType typ)
Bscript::BObjectImp * move_self(Core::UFACING facing, bool run, bool adjust_ok=false)
BObjectImp * getParamImp(unsigned param)
void SleepForMs(int msecs)
bool getParam(unsigned param, int &value)
Bscript::BObjectImp * makeboundingbox()