Skip to content

Commit

Permalink
container updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonSlayer62 committed Apr 27, 2024
1 parent 0a2dfeb commit d348c75
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
2 changes: 2 additions & 0 deletions source/Changelog.txt
@@ -1,3 +1,5 @@
27/04/2024 - Dragon Slayer/Xuri
Fixed an issue where non-corpse containers - including treasure chests in dungeons - would decay and leave all their contents on the ground.
20/04/2024 - Dragon Slayer/Xuri
Fixed misspeling in shopkeepers ai (js shopkeeper)
Added shopkeeper AI script to basevendor definition to support bonuses/penalties for guild members
Expand Down
7 changes: 5 additions & 2 deletions source/SEFunctions.cpp
Expand Up @@ -4141,8 +4141,8 @@ JSBool SE_GetServerSetting( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN
*rval = STRING_TO_JSVAL( tString );
break;
}
case 47: // LOOTDECAYSWITHCORPSE
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->CorpseLootDecay() );
case 47: // PLAYERLOOTDECAYSWITHCORPSE
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->PlayerCorpseLootDecay() );
break;
case 49: // GUARDSACTIVE
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->GuardsStatus() );
Expand Down Expand Up @@ -5083,6 +5083,9 @@ JSBool SE_GetServerSetting( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN
case 348: // AUTOUNEQUIPPEDCASTING
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->AutoUnequippedCasting() );
break;
case 349: // NPCLOOTDECAYSWITHCORPSE
*rval = BOOLEAN_TO_JSVAL( cwmWorldState->ServerData()->NpcCorpseLootDecay() );
break;
default:
ScriptError( cx, "GetServerSetting: Invalid server setting name provided" );
return false;
Expand Down
48 changes: 34 additions & 14 deletions source/cServerData.cpp
Expand Up @@ -71,7 +71,7 @@ const std::map<std::string, SI32> CServerData::uox3IniCaseValue
{"BACKUPDIRECTORY"s, 44},
{"MSGBOARDDIRECTORY"s, 45},
{"SHAREDDIRECTORY"s, 46},
{"LOOTDECAYSWITHCORPSE"s, 47},
{"PLAYERLOOTDECAYSWITHCORPSE"s, 47},
{"GUARDSACTIVE"s, 49},
{"DEATHANIMATION"s, 27},
{"AMBIENTSOUNDS"s, 50},
Expand Down Expand Up @@ -368,8 +368,8 @@ const std::map<std::string, SI32> CServerData::uox3IniCaseValue
{"YOUNGLOCATION"s, 345},
{"SECRETSHARDKEY"s, 346},
{"MOONGATEFACETS"s, 347},
{"AUTOUNEQUIPPEDCASTING"s, 348}

{"AUTOUNEQUIPPEDCASTING"s, 348},
{"NPCLOOTDECAYSWITHCORPSE"s, 349}
};
constexpr auto MAX_TRACKINGTARGETS = 128;
constexpr auto SKILLTOTALCAP = 7000;
Expand All @@ -381,7 +381,7 @@ constexpr auto BIT_ANNOUNCEJOINPART = UI32( 1 );
constexpr auto BIT_SERVERBACKUP = UI32( 2 );
constexpr auto BIT_SHOOTONANIMALBACK = UI32( 3 );
constexpr auto BIT_NPCTRAINING = UI32( 4 );
constexpr auto BIT_LOOTDECAYSONCORPSE = UI32( 5 );
constexpr auto BIT_PLAYERLOOTDECAYSONCORPSE = UI32( 5 );
constexpr auto BIT_GUARDSENABLED = UI32( 6 );
constexpr auto BIT_PLAYDEATHANIMATION = UI32( 7 );
constexpr auto BIT_AMBIENTFOOTSTEPS = UI32( 8 );
Expand Down Expand Up @@ -480,6 +480,7 @@ constexpr auto BIT_ENABLENPCGUILDPREMIUMS = UI32( 101 );
constexpr auto BIT_SNOOPAWARENESS = UI32( 102 );
constexpr auto BIT_YOUNGPLAYERSYSTEM = UI32( 103 );
constexpr auto BIT_AUTOUNEQUIPPEDCASTING = UI32( 104 );
constexpr auto BIT_NPCLOOTDECAYSONCORPSE = UI32( 105 );


// New uox3.ini format lookup
Expand Down Expand Up @@ -634,7 +635,8 @@ auto CServerData::ResetDefaults() -> void
ServerSkillCap( 1000 );
ServerStatCap( 225 );
StatsAffectSkillChecks( false );
CorpseLootDecay( true );
PlayerCorpseLootDecay( true );
NpcCorpseLootDecay( true );
ServerSavesTimer( 600 );

// Enable login-support only for latest available client by default
Expand Down Expand Up @@ -1969,17 +1971,31 @@ auto CServerData::DumpPaths() -> void
}

//o------------------------------------------------------------------------------------------------o
//| Function - CServerData::CorpseLootDecay()
//| Function - CServerData::PlayerCorpseLootDecay()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets whether loot decays along with player corpses or is left on ground
//o------------------------------------------------------------------------------------------------o
auto CServerData::PlayerCorpseLootDecay() const -> bool
{
return boolVals.test( BIT_PLAYERLOOTDECAYSONCORPSE );
}
auto CServerData::PlayerCorpseLootDecay( bool newVal ) -> void
{
boolVals.set( BIT_PLAYERLOOTDECAYSONCORPSE, newVal );
}

//o------------------------------------------------------------------------------------------------o
//| Function - CServerData::NpcCorpseLootDecay()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets whether loot decays along with corpses or is left on ground
//| Purpose - Gets/Sets whether loot decays along with npc corpses or is left on ground
//o------------------------------------------------------------------------------------------------o
auto CServerData::CorpseLootDecay() const -> bool
auto CServerData::NpcCorpseLootDecay() const -> bool
{
return boolVals.test( BIT_LOOTDECAYSONCORPSE );
return boolVals.test( BIT_NPCLOOTDECAYSONCORPSE );
}
auto CServerData::CorpseLootDecay( bool newVal ) -> void
auto CServerData::NpcCorpseLootDecay( bool newVal ) -> void
{
boolVals.set( BIT_LOOTDECAYSONCORPSE, newVal );
boolVals.set( BIT_NPCLOOTDECAYSONCORPSE, newVal );
}

//o------------------------------------------------------------------------------------------------o
Expand Down Expand Up @@ -4995,7 +5011,8 @@ auto CServerData::SaveIni( const std::string &filename ) -> bool
ofsOutput << "}" << '\n';

ofsOutput << '\n' << "[settings]" << '\n' << "{" << '\n';
ofsOutput << "LOOTDECAYSWITHCORPSE=" << ( CorpseLootDecay() ? 1 : 0 ) << '\n';
ofsOutput << "PLAYERLOOTDECAYSWITHCORPSE=" << ( PlayerCorpseLootDecay() ? 1 : 0 ) << '\n';
ofsOutput << "NPCLOOTDECAYSWITHCORPSE=" << ( NpcCorpseLootDecay() ? 1 : 0 ) << '\n';
ofsOutput << "GUARDSACTIVE=" << ( GuardsStatus() ? 1 : 0 ) << '\n';
ofsOutput << "DEATHANIMATION=" << ( DeathAnimationStatus() ? 1 : 0 ) << '\n';
ofsOutput << "AMBIENTSOUNDS=" << WorldAmbientSounds() << '\n';
Expand Down Expand Up @@ -5656,8 +5673,8 @@ auto CServerData::HandleLine( const std::string& tag, const std::string& value )
Directory( CSDDP_SHARED, value );
break;
}
case 47: // LOOTDECAYSWITHCORPSE
CorpseLootDecay( static_cast<UI16>( std::stoul( value, nullptr, 0 )) != 0 );
case 47: // PLAYERLOOTDECAYSWITHCORPSE
PlayerCorpseLootDecay( static_cast<UI16>( std::stoul( value, nullptr, 0 )) != 0 );
break;
case 49: // GUARDSACTIVE
GuardStatus( static_cast<UI16>( std::stoul( value, nullptr, 0 )) != 0 );
Expand Down Expand Up @@ -6545,6 +6562,9 @@ auto CServerData::HandleLine( const std::string& tag, const std::string& value )
case 348: // AUTOUNEQUIPPEDCASTING
AutoUnequippedCasting(( static_cast<UI16>( std::stoul( value, nullptr, 0 )) >= 1 ? true : false ));
break;
case 349: // NPCLOOTDECAYSWITHCORPSE
NpcCorpseLootDecay( static_cast<UI16>( std::stoul( value, nullptr, 0 )) != 0 );
break;
default:
rValue = false;
break;
Expand Down
8 changes: 5 additions & 3 deletions source/cServerData.h
Expand Up @@ -212,7 +212,7 @@ class CServerData

// Once over 62, bitsets are costly. std::vector<bool> has a special exception in the c++ specificaiton, to minimize wasted space for bools
// These should be updated
std::bitset<105> boolVals; // Many values stored this way, rather than using bools.
std::bitset<106> boolVals; // Many values stored this way, rather than using bools.
std::bitset<64> spawnRegionsFacets; // Used to determine which facets to enable spawn regions for, set in UOX>INI
std::bitset<64> moongateFacets; // Used to determine which facets to enable moongates for, set in UOX>INI

Expand Down Expand Up @@ -606,8 +606,10 @@ class CServerData
std::string Directory( CSDDirectoryPaths dp );


auto CorpseLootDecay( bool value ) -> void;
auto CorpseLootDecay() const -> bool;
auto PlayerCorpseLootDecay( bool value ) -> void;
auto PlayerCorpseLootDecay() const -> bool;
auto NpcCorpseLootDecay( bool value ) -> void;
auto NpcCorpseLootDecay() const -> bool;

auto GuardStatus( bool value ) -> void;
auto GuardsStatus() const -> bool;
Expand Down
3 changes: 2 additions & 1 deletion source/items.cpp
Expand Up @@ -1342,7 +1342,8 @@ auto DecayItem( CItem& toDecay, const UI32 nextDecayItems, UI32 nextDecayItemsIn

if( toDecay.IsContType() )
{
if( !isCorpse || ValidateObject(toDecay.GetOwnerObj() ) || !cwmWorldState->ServerData()->CorpseLootDecay() )
if( isCorpse && (( ValidateObject( toDecay.GetOwnerObj() ) && !cwmWorldState->ServerData()->PlayerCorpseLootDecay() ) // Player corpse
|| ( !ValidateObject( toDecay.GetOwnerObj() ) && !cwmWorldState->ServerData()->NpcCorpseLootDecay() ))) // NPC corpse
{
std::vector<CItem *> corpseItems;
auto iCont = toDecay.GetContainsList();
Expand Down

0 comments on commit d348c75

Please sign in to comment.