Skip to content

Commit

Permalink
Add ServSpecOpt UndoGetItemEnableRangeCheck and UndoGetItemDropHere t…
Browse files Browse the repository at this point in the history
…o control get item undo behaviour (#547)

* Add Character member .parrychance_mod, additive modificator of the parry_chance from the defender when it has shield equipped. Add parrychance_mod to parry formula.

* Add repsys.cfg General section PartyHarmFullCountsAsCriminal 1/0 default 1. If 0 OnHarm does not set mobile to criminal when they are in the same party.

* fix settings/party namespace

* fix pointer

* add ServSpecOpt UndoGetItemEnableRangeCheck and UndoGetItemDropHere undo getItem behaviour options

* fix code style len

* add missing comas

* special case for no drop item

* if no drop item and was not able to return to original container try to put to backpack

* fix remove item in range (was still displaying item in container, but was not really present there)

* add first simple test

* remove all tests

* remove all tests

* do not export test function

* ReloadConfiguration add reload servspecopt; Testsuite add fileaccess and servspecopt files; Add test fro undo get item

* check what produce SanitizerBuild fail

* run all test to fail on ThreadSanitizer Build

* Add repsys.cfg General section PartyHarmFullCountsAsCriminal 1/0 default 1. If 0 OnHarm does not set mobile to criminal when they are in the same party.

* add ServSpecOpt UndoGetItemEnableRangeCheck and UndoGetItemDropHere undo getItem behaviour options

* add missing comas

* fix remove item in range (was still displaying item in container, but was not really present there)

* remove all tests

* check what produce SanitizerBuild fail

* run all test to fail on ThreadSanitizer Build

* test new reload conf fix

* double check that build successful

* fix test comments; fix change log

* add DefaultAccessibleRange = 2 for tests

* delete unnecessary servspecopt file

* change check to toplevel_pos; add test for toplevel_pos

* try to update backpacks for client; increase distance to on drop backpack

* add heavy robe for tests; use robe instead flooding client with arrows

* fix test messages

---------

Co-authored-by: Oleksii Rebreniuk <oleksii.rebreniuk@shopit.se>
  • Loading branch information
murderinc and Oleksii Rebreniuk committed Nov 1, 2023
1 parent 63f3c77 commit 6e9b28e
Show file tree
Hide file tree
Showing 11 changed files with 640 additions and 21 deletions.
9 changes: 9 additions & 0 deletions docs/docs.polserver.com/pol100/configfiles.xml
Expand Up @@ -385,6 +385,8 @@ Spell (int spellid)
[MobilesBlockNpcMovement (0/1 {default 1})]
[DefaultCharacterHeight (1-32 {default 15})]
[EnableWorldMapPackets (0/1 (default 0))]
[UndoGetItemEnableRangeCheck (0/1 {default 0})]
[UndoGetItemDropHere (0/1 {default 0})]
</structure>
<explain><i>RefreshDecayAfterBoatMoves</i> if enabled item's decayat will be refreshed after each move or turn of a boat. Note that item decay on boats is not yet handled by the core.</explain>
<explain><i>TotalStatsAtCreation:</i> takes a comma-delimited lists of values and/or ranges (default = '65,80'). Example: TotalStatsAtCreation=65,80,90-95,100-110</explain>
Expand Down Expand Up @@ -457,6 +459,13 @@ Note: Token and nonToken Eventtype is still the same (SYSEVENT_SPEECH)</explain>
<explain><i>EnableWorldMapPackets:</i> Custom clients have implemented a packet that tracks the position of<br/>
party and guild members. This enables the client to overlay member positions on a world map<br/>
directly inside the client. Set to 1 to enable core handling of this packet.<br/></explain>
<explain><i>UndoGetItemEnableRangeCheck:</i> If enabled - on fail to equip item back on character (if it has been taken from character layer)<br/>
and on fail to put item back to backpack will check if item has been taken from position/container that is in default_accessible_range.<br/>
If origin position/container is not in default_accessible_range will skip try to put item to origin position/container (unless item is no_drop)<br/>
and as last resort will drop item at character position (feet). UndoGetItemDropHere executed before UndoGetItemEnableRangeCheck if both are set.</explain>
<explain><i>UndoGetItemDropHere:</i> If enabled - on fail to equip item back on character (if it has been taken from character layer)<br/>
and on fail to put item back to backpack drops item at character position (feet), except no_drop items. Attempt to return item in<br/>
origin container will be skipped.</explain>
<related>movecost.cfg</related>
<related>repsys.cfg</related>
</cfgfile>
Expand Down
23 changes: 19 additions & 4 deletions docs/docs.polserver.com/pol100/corechanges.xml
Expand Up @@ -2,9 +2,24 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>10-23-2023</datemodified>
<datemodified>10-28-2023</datemodified>
</header>
<version name="POL100.1.0">
<entry>
<date>10-28-2023</date>
<author>Ins:</author>
<change type="Added">ServSpecOpt &quot;UndoGetItemEnableRangeCheck&quot; 1/0 default 0.<br/>
If enabled - on fail to equip item back on character (if it has been taken from character layer)<br/>
and on fail to put item back to backpack will check if item has been taken from position/container that is in default_accessible_range.<br/>
If origin position/container is not in default_accessible_range will skip try to put item to origin position/container (unless item is no_drop)<br/>
and as last resort will drop item at character position (feet). UndoGetItemDropHere executed before UndoGetItemEnableRangeCheck if both are set.</change>
<change type="Added">ServSpecOpt &quot;UndoGetItemDropHere&quot; 1/0 default 0.<br/>
If enabled - on fail to equip item back on character (if it has been taken from character layer)<br/>
and on fail to put item back to backpack drops item at character position (feet), except no_drop items. Attempt to return item in<br/>
origin container will be skipped.</change>
<change type="Fixed">Leftover items in corpse on client side.</change>
<change type="Changed">Added ServerSpecOpt reload to ReloadConfiguration.</change>
</entry>
<entry>
<date>10-23-2023</date>
<author>Turley:</author>
Expand All @@ -22,10 +37,10 @@
<change type="Fixed">Changed return values and parameters used by storage module functions to match documentation.</change>
</entry>
<entry>
<date>03-09-2023</date>
<date>09-03-2023</date>
<author>Ins:</author>
<change type="Added">repsys.cfg General section &quot;PartyHarmFullCountsAsCriminal 1/0&quot; default 1.<br/>
If 0 OnHarm does not set mobile to criminal when they are in the same party.</change>
<change type="Added">repsys.cfg General section &quot;PartyHarmFullCountsAsCriminal&quot; 1/0 default 1.<br/>
If 0 OnHarm does not set mobile to criminal when they are in the same party.</change>
</entry>
<entry>
<date>08-30-2023</date>
Expand Down
14 changes: 13 additions & 1 deletion pol-core/doc/core-changes.txt
@@ -1,12 +1,24 @@
-- POL100.1.0 --
10-28-2023 Ins:
Added: ServSpecOpt "UndoGetItemEnableRangeCheck" 1/0 default 0.
If enabled - on fail to equip item back on character (if it has been taken from character layer)
and on fail to put item back to backpack will check if item has been taken from position/container that is in default_accessible_range.
If origin position/container is not in default_accessible_range will skip try to put item to origin position/container (unless item is no_drop)
and as last resort will drop item at character position (feet). UndoGetItemDropHere executed before UndoGetItemEnableRangeCheck if both are set.
Added: ServSpecOpt "UndoGetItemDropHere" 1/0 default 0.
If enabled - on fail to equip item back on character (if it has been taken from character layer)
and on fail to put item back to backpack drops item at character position (feet), except no_drop items. Attempt to return item in
origin container will be skipped.
Fixed: Leftover items in corpse on client side.
Changed: Added ServerSpecOpt reload to ReloadConfiguration.
10-23-2023 Turley:
Changed: added movemode parameter to uo:FindPath, defaults to "L". Before the move mode was fixed to land, now its possible to use the FindPath functionality also for eg sea monsters
10-18-2023 Turley:
Added: print/syslog console_color parameter. When used with one of the basicio.em CONSOLE_COLOR constants, or a custom xterm formatting string the output to the console is formatted accordingly. Resets the formatting at the end. Xterm formatting is supported on Linux and Windows11. For syslog only the output to the console is modified not the logfile entry.
Added: pol.cfg EnableColoredOutput 1/0 to disable formatted output. Default is 1.
10-15-2023 Kevin:
Fixed: Changed return values and parameters used by storage module functions to match documentation.
03-09-2023 Ins:
09-03-2023 Ins:
Added: repsys.cfg General section "PartyHarmFullCountsAsCriminal 1/0" default 1.
If 0 OnHarm does not set mobile to criminal when they are in the same party.
08-30-2023 Kevin:
Expand Down
65 changes: 51 additions & 14 deletions pol-core/pol/getitem.cpp
Expand Up @@ -138,6 +138,8 @@ void GottenItem::handle( Network::Client* client, PKTIN_07* msg )

UObject* my_owner = item->toplevel_owner();

send_remove_object_to_inrange( item );

UContainer* orig_container = item->container;
Pos4d orig_pos = item->pos(); // potential container pos
Pos4d orig_toppos = item->toplevel_pos();
Expand All @@ -157,7 +159,6 @@ void GottenItem::handle( Network::Client* client, PKTIN_07* msg )
}
else
{
send_remove_object_to_inrange( item );
gotten_info._source = GOTTEN_ITEM_TYPE::GOTTEN_ITEM_ON_GROUND;
remove_item_from_world( item );
}
Expand Down Expand Up @@ -291,28 +292,50 @@ void GottenItem::undo( Mobile::Character* chr )

if ( _source == GOTTEN_ITEM_TYPE::GOTTEN_ITEM_IN_CONTAINER )
{
// First attempt to put it back in the original container.
// First attempt to place the item in the player's backpack.
UContainer* container = nullptr;
auto* orig_obj = system_find_object( _cnt_serial );
if ( orig_obj && orig_obj->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
{
container = static_cast<UContainer*>( orig_obj );
if ( !container->can_add( *_item ) ||
if( !_item->no_drop() ) {
container = chr->backpack();
if ( !container || !container->can_add( *_item ) ||
!container->can_insert_add_item( chr, UContainer::MT_PLAYER, _item ) )
container = nullptr;
if ( _item->orphan() )
return;
}
if ( _item->orphan() )
return;
if ( !container )
// Attempt to put it back in the original container.
if ( !container
&& ( !Core::settingsManager.ssopt.undo_get_item_drop_here || _item->no_drop() ) )
{
// Attempt to place the item in the player's backpack.
auto* orig_obj = system_find_object( _cnt_serial );
if ( orig_obj && orig_obj->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
{
if ( _item->no_drop()
|| chr->can_moveanydist()
|| !Core::settingsManager.ssopt.undo_get_item_enable_range_check
|| chr->pos().pol_distance( orig_obj->toplevel_pos() )
<= Core::settingsManager.ssopt.default_accessible_range )
{
container = static_cast<UContainer*>( orig_obj );
if ( !container->can_add( *_item ) ||
!container
->can_insert_add_item( chr, UContainer::MT_PLAYER, _item ) )
container = nullptr;
}
}
if ( _item->orphan() )
return;
}

// No drop item has not returned to original container, place the item in the player's backpack.
if( !container && _item->no_drop() ) {
container = chr->backpack();
if ( !container || !container->can_add( *_item ) ||
!container->can_insert_add_item( chr, UContainer::MT_PLAYER, _item ) )
container = nullptr;
if ( _item->orphan() )
return;
}
if ( _item->orphan() )
return;

if ( container )
{
u8 newSlot = _slot_index ? _slot_index : 1;
Expand All @@ -323,8 +346,9 @@ void GottenItem::undo( Mobile::Character* chr )
_item->setposition( _pos );
container->add( _item );
}
else
else {
container->add_at_random_location( _item );
}
update_item_to_inrange( _item );
container->on_insert_add_item( chr, UContainer::MT_PLAYER, _item );
return;
Expand All @@ -333,6 +357,19 @@ void GottenItem::undo( Mobile::Character* chr )
_pos = chr->pos();
}

if( Core::settingsManager.ssopt.undo_get_item_drop_here )
{
_pos = chr->pos();
}
else if ( !chr->can_moveanydist() )
{
if ( Core::settingsManager.ssopt.undo_get_item_enable_range_check
&& chr->pos().pol_distance( _pos ) > Core::settingsManager.ssopt.default_accessible_range )
{
_pos = chr->pos();
}
}

// Last resort - put it on the ground, to players feet in case of error from above.
_item->setposition( _pos );
_item->container = nullptr;
Expand Down
1 change: 1 addition & 0 deletions pol-core/pol/loadunld.cpp
Expand Up @@ -268,6 +268,7 @@ void load_data()
void reload_configuration()
{
PolConfig::read_pol_config( false );
ServSpecOpt::read_servspecopt();
Network::read_bannedips_config( false );
gamestate.unload_npc_templates();
load_npc_templates();
Expand Down
5 changes: 5 additions & 0 deletions pol-core/pol/ssopt.cpp
Expand Up @@ -139,6 +139,11 @@ void ServSpecOpt::read_servspecopt()
settingsManager.ssopt.enable_worldmap_packets =
elem.remove_bool( "EnableWorldMapPackets", false );

settingsManager.ssopt.undo_get_item_enable_range_check =
elem.remove_ushort( "UndoGetItemEnableRangeCheck", false );
settingsManager.ssopt.undo_get_item_drop_here =
elem.remove_ushort( "UndoGetItemDropHere", false );

ssopt_parse_totalstats( elem );

// Turley 2009/11/06 u8 range...
Expand Down
3 changes: 3 additions & 0 deletions pol-core/pol/ssopt.h
Expand Up @@ -99,6 +99,9 @@ struct ServSpecOpt
unsigned char default_character_height;
bool enable_worldmap_packets;

bool undo_get_item_enable_range_check;
bool undo_get_item_drop_here;

static void read_servspecopt();
static void ssopt_parse_totalstats( Clib::ConfigElem& elem );
};
Expand Down
21 changes: 21 additions & 0 deletions pol-core/poltool/baredistrofiles.cpp
Expand Up @@ -588,6 +588,27 @@ void BareDistro::distro_files( std::map<fs::path, std::vector<std::string>>& dis
"# map directly inside the client. Set to 1 to enable core handling of this packet.",
"#",
"EnableWorldMapPackets=0",
"",
"#",
"# UndoGetItemEnableRangeCheck - 1/0 (default 0)",
"#",
"# If enabled - on fail to equip item back on character (if it has been taken from character layer)",
"# and on fail to put item back to backpack will check if item has been taken from position/container",
"# that is in default_accessible_range.",
"# If origin position/container is not in default_accessible_range will skip try to put item ",
"# to origin position/container (unless item is no_drop) and as last resort will drop item at character",
"# position (feet). UndoGetItemDropHere executed before UndoGetItemEnableRangeCheck if both are set.",
"#",
"UndoGetItemEnableRangeCheck=0",
"",
"#",
"# UndoGetItemDropHere - 1/0 (default 0)",
"#",
"# If enabled - on fail to equip item back on character (if it has been taken from character layer)",
"# and on fail to put item back to backpack drops item at character position (feet), except no_drop items.",
"# Attempt to return item in origin container will be skipped.",
"#",
"UndoGetItemDropHere=0",
} ) );

distro.emplace( "config/startloc.cfg",
Expand Down
10 changes: 10 additions & 0 deletions testsuite/pol/config/fileaccess.cfg
@@ -0,0 +1,10 @@
FileAccess AllowAllFiles
{
Package *
Extension *
Directory *
AllowRead 1
AllowRemote 1
AllowWrite 1
AllowAppend 1
}

0 comments on commit 6e9b28e

Please sign in to comment.