Skip to content

Commit

Permalink
Add Support for Snooping via Item Descriptor element SnoopScript (#491
Browse files Browse the repository at this point in the history
)

* Initial work on adding SnoopScript

* use message "That doesn't belong to you..." if lifting a snoopable item

* fix configfile changes

* Update core-changes
  • Loading branch information
KevinEady committed Dec 20, 2022
1 parent 83de33a commit 999ca84
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/docs.polserver.com/pol100/configfiles.xml
Expand Up @@ -1430,6 +1430,7 @@ Item (objtype)
[Tooltip (string tooltip {default empty})]
[WalkOnScript (string scriptname)]
[Script (string scriptname)]
[SnoopScript (string scriptname)]
[EquipScript (string scriptname)]
[UnequipScript (string scriptname)]
[ControlScript (string scriptname)]
Expand Down Expand Up @@ -1602,7 +1603,7 @@ Armor (objtype)
<explain>Note: if objtype &lt; 0x4000, the 'graphic' property is not required, it is assumed objtype=graphic in this case.</explain>
<explain>Valid ranges for custom items are 0x5000-0xEFFF (0xF000-0xFFFF reserved by core)</explain>
<explain>Properties having to do with equipping an item is only meaningful if the item is actualy equippable (determined by the graphic number's tiledata flags).</explain>
<explain>Item Create, Destroy, and Control scripts are in pkg format or in scripts/control. Method scripts must be packaged.</explain>
<explain>Item Create, Destroy, Snoop, and Control scripts are in pkg format or in scripts/control. Method scripts must be packaged.</explain>
<explain>Container scripts are in pkg format, or in scripts/control</explain>
<explain>RequiresAttention 1 causes container gumps to close when you move, or to unhide you if the item is used.</explain>
<explain>StackingIgnoresCProps is a space-delimited list of case-sensative CProp names that are ignored when stacking 2 of this item objtype. See also stacking.cfg for a global list.</explain>
Expand Down
7 changes: 6 additions & 1 deletion docs/docs.polserver.com/pol100/corechanges.xml
Expand Up @@ -2,9 +2,14 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>12-17-2022</datemodified>
<datemodified>12-19-2022</datemodified>
</header>
<version name="POL100.1.0">
<entry>
<date>12-19-2022</date>
<author>Kevin:</author>
<change type="Added">SnoopScript to itemdesc.cfg Item descriptors which runs when a character double-clicks an item that is owned by a different character, eg. another character's backpack or an item within that backpack. This can be used to implement the Snooping skill.</change>
</entry>
<entry>
<date>12-17-2022</date>
<author>Turley:</author>
Expand Down
1 change: 1 addition & 0 deletions pol-core/bscript/objaccess.cpp
Expand Up @@ -269,6 +269,7 @@ ObjMember object_members[] = {
{ MBR_EXPORTED_FUNCTIONS, "exported_functions", false }, // 250
{ MBR_DISABLE_INACTIVITY_TIMEOUT, "disable_inactivity_timeout", false },
{ MBR_CURSED, "cursed", false },
{ MBR_SNOOPSCRIPT, "snoopscript", false },
};
int n_objmembers = sizeof object_members / sizeof object_members[0];
ObjMember* getKnownObjMember( const char* token )
Expand Down
1 change: 1 addition & 0 deletions pol-core/bscript/objmembers.h
Expand Up @@ -291,6 +291,7 @@ enum MemberID
MBR_EXPORTED_FUNCTIONS,
MBR_DISABLE_INACTIVITY_TIMEOUT,
MBR_CURSED,
MBR_SNOOPSCRIPT,
};


Expand Down
2 changes: 2 additions & 0 deletions pol-core/doc/core-changes.txt
@@ -1,4 +1,6 @@
-- POL100.1.0 --
12-19-2022 Kevin:
Added: SnoopScript to itemdesc.cfg Item descriptors which runs when a character double-clicks an item that is owned by a different character, eg. another character's backpack or an item within that backpack. This can be used to implement the Snooping skill.
12-17-2022 Turley:
Fixed: potential crash in client login phase
12-13-2022 Kevin:
Expand Down
16 changes: 13 additions & 3 deletions pol-core/pol/dblclick.cpp
Expand Up @@ -174,8 +174,11 @@ void doubleclick( Network::Client* client, PKTIN_06* msg )
// next, search worn items, items in the backpack, and items in the world.
Items::Item* item = find_legal_item( client->chr, serial );

// next, check people's backpacks. (don't recurse down)
// (not done yet)
Mobile::Character* owner = nullptr;
if ( item == nullptr )
{
item = find_snoopable_item( serial, &owner );
}

if ( item != nullptr )
{
Expand Down Expand Up @@ -222,7 +225,14 @@ void doubleclick( Network::Client* client, PKTIN_06* msg )
client->chr->start_script( prog.get(), false, new Module::EItemRefObjImp( item ) );
}

item->double_click( client );
if ( owner == nullptr )
{
item->double_click( client );
}
else
{
item->snoop( client, owner );
}
return;
}

Expand Down
6 changes: 6 additions & 0 deletions pol-core/pol/getitem.cpp
Expand Up @@ -78,6 +78,12 @@ void get_item( Network::Client* client, PKTIN_07* msg )
item = find_legal_item( client->chr, serial, &inRemoteContainer, &isRemoteContainer );
if ( item == nullptr || isRemoteContainer )
{
if ( find_snoopable_item( serial ) != nullptr )
{
send_item_move_failure( client, MOVE_ITEM_FAILURE_BELONGS_TO_OTHER );
return;
}

send_item_move_failure( client, MOVE_ITEM_FAILURE_CANNOT_PICK_THAT_UP );
return;
}
Expand Down
34 changes: 34 additions & 0 deletions pol-core/pol/item/item.cpp
Expand Up @@ -492,6 +492,7 @@ void Item::readProperties( Clib::ConfigElem& elem )
on_use_script_ = elem.remove_string( "ONUSESCRIPT", "" );
equip_script_ = elem.remove_string( "EQUIPSCRIPT", equip_script_.get().c_str() );
unequip_script_ = elem.remove_string( "UNEQUIPSCRIPT", unequip_script_.get().c_str() );
snoop_script_ = elem.remove_string( "SNOOPSCRIPT", snoop_script_.get().c_str() );

decayat_gameclock_ = elem.remove_ulong( "DECAYAT", 0 );
sellprice_( elem.remove_ulong( "SELLPRICE", SELLPRICE_DEFAULT ) );
Expand Down Expand Up @@ -596,6 +597,39 @@ void Item::builtin_on_use( Network::Client* client )
Core::send_sysmessage( client, "I can't think of a way to use that." );
}

void Item::snoop( Network::Client* client, Mobile::Character* owner )
{
const ItemDesc& itemdesc = this->itemdesc();

if ( client->chr->skill_ex_active() || client->chr->casting_spell() )
{
Core::send_sysmessage( client, "I am already doing something else." );
return;
}

ref_ptr<Bscript::EScriptProgram> prog;

if ( !snoop_script_.get().empty() )
{
Core::ScriptDef sd( snoop_script_, nullptr, "" );
prog = find_script2( sd,
true, // complain if not found
Plib::systemstate.config.cache_interactive_scripts );
}
else if ( !itemdesc.snoop_script.empty() )
{
prog = find_script2( itemdesc.snoop_script, true,
Plib::systemstate.config.cache_interactive_scripts );
}

if ( prog.get() != nullptr )
{
if ( client->chr->start_snoop_script( prog.get(), this, owner ) )
return;
// else log the fact?
}
}

void Item::double_click( Network::Client* client )
{
const ItemDesc& itemdesc = this->itemdesc();
Expand Down
2 changes: 2 additions & 0 deletions pol-core/pol/item/item.h
Expand Up @@ -86,6 +86,7 @@ class Item : public Core::UObject
virtual size_t estimatedSize() const override;

virtual void double_click( Network::Client* client );
void snoop( Network::Client* client, Mobile::Character* owner );
virtual void builtin_on_use( Network::Client* client );
virtual void walk_on( Mobile::Character* chr );

Expand Down Expand Up @@ -276,6 +277,7 @@ class Item : public Core::UObject
boost_utils::script_name_flystring on_use_script_;
boost_utils::script_name_flystring equip_script_;
boost_utils::script_name_flystring unequip_script_;
boost_utils::script_name_flystring snoop_script_;
mutable const ItemDesc* _itemdesc;

public:
Expand Down
2 changes: 2 additions & 0 deletions pol-core/pol/item/itemdesc.cpp
Expand Up @@ -176,6 +176,7 @@ ItemDesc::ItemDesc( u32 objtype, Clib::ConfigElem& elem, Type type, const Plib::
on_use_script( elem.remove_string( "SCRIPT", "" ), pkg, "scripts/items/" ),
equip_script( elem.remove_string( "EQUIPSCRIPT", "" ) ),
unequip_script( elem.remove_string( "UNEQUIPSCRIPT", "" ) ),
snoop_script( elem.remove_string( "SNOOPSCRIPT", "" ), pkg, "scripts/items/" ),
control_script( elem.remove_string( "CONTROLSCRIPT", "" ), pkg, "scripts/control/" ),
create_script( elem.remove_string( "CREATESCRIPT", "" ), pkg, "scripts/control/" ),
destroy_script( elem.remove_string( "DESTROYSCRIPT", "" ), pkg, "scripts/control/" ),
Expand Down Expand Up @@ -774,6 +775,7 @@ void ItemDesc::PopulateStruct( Bscript::BStruct* descriptor ) const
descriptor->addMember( "Script", new String( on_use_script.relativename( pkg ) ) );
descriptor->addMember( "EquipScript", new String( equip_script ) );
descriptor->addMember( "UnequipScript", new String( unequip_script ) );
descriptor->addMember( "SnoopScript", new String( snoop_script.relativename( pkg ) ) );
descriptor->addMember( "ControlScript", new String( control_script.relativename( pkg ) ) );
descriptor->addMember( "CreateScript", new String( create_script.relativename( pkg ) ) );
descriptor->addMember( "DestroyScript", new String( destroy_script.relativename( pkg ) ) );
Expand Down
1 change: 1 addition & 0 deletions pol-core/pol/item/itemdesc.h
Expand Up @@ -97,6 +97,7 @@ class ItemDesc
Core::ScriptDef on_use_script;
boost_utils::script_name_flystring equip_script;
boost_utils::script_name_flystring unequip_script;
Core::ScriptDef snoop_script;
Core::ScriptDef control_script;
Core::ScriptDef create_script;
Core::ScriptDef destroy_script;
Expand Down
2 changes: 2 additions & 0 deletions pol-core/pol/mobile/charactr.h
Expand Up @@ -599,6 +599,8 @@ class Character : public Core::UObject
bool start_skill_script( Bscript::EScriptProgram* prog );
bool start_itemuse_script( Bscript::EScriptProgram* prog, Items::Item* item,
bool start_attached );
bool start_snoop_script( Bscript::EScriptProgram* prog, Items::Item* item,
Mobile::Character* owner );
bool start_spell_script( Bscript::EScriptProgram* prog, Core::USpell* spell );
void cancel_menu();

Expand Down
7 changes: 7 additions & 0 deletions pol-core/pol/mobile/chrituse.cpp
Expand Up @@ -83,7 +83,14 @@ bool Character::start_itemuse_script( Bscript::EScriptProgram* prog, Items::Item
{
return start_script( prog, start_attached, new Module::EItemRefObjImp( item ) );
}

bool Character::start_snoop_script( Bscript::EScriptProgram* prog, Items::Item* item,
Mobile::Character* owner )
{
return start_script( prog, false, new Module::EItemRefObjImp( item ),
new Module::EOfflineCharacterRefObjImp( owner ) );
}
} // namespace Mobile
namespace Items
{
void Item::walk_on( Mobile::Character* chr )
Expand Down
18 changes: 18 additions & 0 deletions pol-core/pol/ufunc.cpp
Expand Up @@ -962,6 +962,24 @@ UContainer* find_legal_container( const Character* chr, u32 serial )
return nullptr;
}

Item* find_snoopable_item( u32 serial, Character** pchr )
{
Item* item = system_find_item( serial );
if ( item != nullptr )
{
Character* owner = item->GetCharacterOwner();
if ( owner != nullptr )
{
if ( pchr != nullptr )
{
*pchr = owner;
}
return item;
}
}
return nullptr;
}

// assume if you pass additlegal or isRemoteContainer, you init to false
Item* find_legal_item( const Character* chr, u32 serial, bool* additlegal, bool* isRemoteContainer )
{
Expand Down
2 changes: 2 additions & 0 deletions pol-core/pol/ufunc.h
Expand Up @@ -172,6 +172,8 @@ void play_moving_effect2_ex( const Pos3d& src, const Pos3d& dst, Realms::Realm*
Items::Item* find_legal_item( const Mobile::Character* chr, u32 serial, bool* additlegal = nullptr,
bool* isRemoteContainer = nullptr );

Items::Item* find_snoopable_item( u32 serial, Mobile::Character** powner = nullptr );

void send_sysmessage( Network::Client* client, const char* text,
unsigned short font = Plib::DEFAULT_TEXT_FONT,
unsigned short color = Plib::DEFAULT_TEXT_COLOR );
Expand Down
6 changes: 6 additions & 0 deletions pol-core/pol/uoscrobj.cpp
Expand Up @@ -846,6 +846,9 @@ BObjectImp* Item::get_script_member_id( const int id ) const
case MBR_USESCRIPT:
return new String( on_use_script_ );
break;
case MBR_SNOOPSCRIPT:
return new String( snoop_script_ );
break;
case MBR_EQUIPSCRIPT:
return new String( equip_script_ );
break;
Expand Down Expand Up @@ -1107,6 +1110,9 @@ BObjectImp* Item::set_script_member_id( const int id, const std::string& value )
case MBR_USESCRIPT:
on_use_script_ = value;
return new String( value );
case MBR_SNOOPSCRIPT:
snoop_script_ = value;
return new String( value );
case MBR_EQUIPSCRIPT:
equip_script_ = value;
return new String( value );
Expand Down

0 comments on commit 999ca84

Please sign in to comment.