Skip to content

Commit

Permalink
Merge branch 'develop' into Quiver-Addition
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonSlayer62 authored Jan 30, 2025
2 parents 16254d8 + ed86980 commit 6603436
Show file tree
Hide file tree
Showing 10 changed files with 528 additions and 19 deletions.
408 changes: 390 additions & 18 deletions data/dfndata/regions/regions.dfn

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions data/dfndata/regions/regions_old_haven_only.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file defines the town region for Old Haven, which only exists on the Trammel
// facet in client versions 5.0.0b to 7.0.8.2 with mapdiffs enabled.
//
// If anyone wants to use it, copy it to the main regions.dfn file
// and overwrite the New Haven region (57), while also removing the
// New Haven specific shop-regions (178 to 200).

[REGION 57]
{
NAME=the town of Haven
MUSICLIST=7
GUARDED=1
GUARDLIST=guard
GUARDOWNER=The Town
MAGICDAMAGE=1
MARK=1
GATE=1
RECALL=1
ESCORTS=1
X1=3590
Y1=2460
X2=3710
Y2=2635
X1=3700
Y1=2560
X2=3760
Y2=2730
WORLD=1
}
29 changes: 28 additions & 1 deletion docs/jsdocs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5049,6 +5049,33 @@ <h4>January 9th, 2022</h4>
</div>
</div>

<div class="spoilerWrapper">
<input type="checkbox" id="spoiler_function_combat_CheckTimeSinceLastCombat" />
<label for="spoiler_function_combat_CheckTimeSinceLastCombat">CheckTimeSinceLastCombat <i class="fas fa-angle-down"></i></label>
<div class="spoiler">
<div class="settingsDiv">
<p><span class="hl">Prototype</span></p>
<p><em>CheckTimeSinceLastCombat( pUser, 120 );</em></p>
</div>
<div class="settingsDiv">
<p><span class="hl">Purpose</span></p>
<p>Checks if a character has engaged in combat within a specified time frame (in seconds).</p>
</div>
<div class="settingsDiv">
<p><span class="hl">Example of usage</span></p>
<pre><code class="language-javascript">// Check if the player has been in combat within the last 120 seconds (2 minutes)
if( CheckTimeSinceLastCombat( pUser, 120 ))
{
pUser.SysMessage( "You must wait two minutes after engaging in combat before you can use this item." );
}
else
{
pUser.SysMessage( "You are free to use the item." );
}</code></pre>
</div>
</div>
</div>

</div>
</div> <!-- cd-faq__content -->
</li>
Expand Down Expand Up @@ -17419,4 +17446,4 @@ <h4>Finalize Result Announcement</h4>
<script src="assets/js/main.js"></script>
<script src="assets/js/prism.js"></script>
</body>
</html>
</html>
10 changes: 10 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

1/05/2024 - Dragon Slayer/Xuri

22/01/2025 - Dragon Slayer
Added New Haven for trammel. (Regions.dfn)
Added New Haven Music. (Regions.dfn)
Added new player quest training areas. (Regions.dfn)
Fixed Britains music. (Regions.dfn)
marked old regions file as old because contains old haven.

22/01/2025 - Dragon Slayer
Fixed an issue that prevented onUnequip JS event from triggering on items being unequipped
Minor cleanup of skill_boosting_equipment.js script
Expand Down Expand Up @@ -32,6 +39,9 @@
20/10/2024 - Dragon Slayer
Added SetRandomColor("#") to js functions. (Thanks, Xuri)

14/10/2024 - Dragon Slayer
     Added CheckTimeSinceLastCombat that records the time when combat starts as a timestamp(SEFunctions.cpp).

14/10/2024 - Dragon Slayer
    Added the CheckInstaLog JS function to allow checking if a specific location is within an instant logout zone (SEFunctions.cpp). (thanks, Xuri)

Expand Down
43 changes: 43 additions & 0 deletions source/SEFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,49 @@ JSBool SE_CalcMultiFromSer( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN
return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - SE_CombatTimeCheck()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Checks if a character has engaged in combat within a given time span
//o------------------------------------------------------------------------------------------------o
JSBool SE_CheckTimeSinceLastCombat( JSContext* cx, [[maybe_unused]] JSObject* obj, uintN argc, jsval* argv, jsval* rval )
{
if (argc != 2)
{
ScriptError( cx, "CheckTimeSinceLastCombat: Invalid number of parameters (2)" );
return JS_FALSE;
}

CChar* from = nullptr;
UI32 timespanInSeconds = 0;

if( !JSVAL_IS_OBJECT( argv[0] ) || !( from = ( CChar* )JS_GetPrivate( cx, JSVAL_TO_OBJECT( argv[0] ))))
{
ScriptError( cx, "CheckTimeSinceLastCombat: Invalid first argument (expected CChar)" );
return JS_FALSE;
}

if( !JSVAL_IS_INT( argv[1] ))
{
ScriptError( cx, "CheckTimeSinceLastCombat: Invalid second argument (expected time in seconds)" );
return JS_FALSE;
}

timespanInSeconds = static_cast<UI32>( JSVAL_TO_INT( argv[1] ));

// Use GetGUITimerCurTime() instead of time(nullptr) for consistency
UI32 now = cwmWorldState->GetUICurrentTime();

if(( now - from->GetLastCombatTime() ) < timespanInSeconds )
{
*rval = JSVAL_TRUE;
return JS_TRUE;
}

*rval = JSVAL_FALSE;
return JS_TRUE;
}

//o------------------------------------------------------------------------------------------------o
//| Function - SE_CalcCharFromSer()
//o------------------------------------------------------------------------------------------------o
Expand Down
1 change: 1 addition & 0 deletions source/SEFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SEngineFunc SE_CalcCharFromSer; // ***
SEngineFunc SE_CalcItemFromSer; // ***
SEngineFunc SE_CalcMultiFromSer; // ***

SEngineFunc SE_CheckTimeSinceLastCombat;
SEngineFunc SE_CheckInstaLog;

SEngineFunc SE_MakeItem; // ***
Expand Down
15 changes: 15 additions & 0 deletions source/cChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5950,6 +5950,21 @@ void CChar::LastMoveTime( UI32 newValue )
lastMoveTime = newValue;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CChar::GetLastCombatTime()
//| CChar::SetLastCombatTime()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets/Sets timestamp for when player last combat
//o------------------------------------------------------------------------------------------------o
UI32 CChar::GetLastCombatTime() const
{
return lastCombatTime;
}
void CChar::SetLastCombatTime( UI32 newValue )
{
lastCombatTime = newValue;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CChar::GetLastOn()
//| CChar::SetLastOn()
Expand Down
4 changes: 4 additions & 0 deletions source/cChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class CChar : public CBaseObject
UI08 PoisonStrength;
BodyType bodyType;
UI32 lastMoveTime; // Timestamp for when character moved last
UI32 lastCombatTime; // Timestamp for when character combat last
UI16 npcGuild; // ID of NPC guild character is in (0=no NPC guild)

SKILLVAL baseskill[ALLSKILLS]; // Base skills without stat modifiers
Expand Down Expand Up @@ -841,6 +842,9 @@ class CChar : public CBaseObject
UI32 LastMoveTime( void ) const;
void LastMoveTime( UI32 newValue );

UI32 GetLastCombatTime() const;
void SetLastCombatTime(UI32 newValue);


CChar * GetTrackingTarget( void ) const;
CChar * GetTrackingTargets( UI08 targetNum ) const;
Expand Down
1 change: 1 addition & 0 deletions source/cScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static JSFunctionSpec my_functions[] =
{ "CalcCharFromSer", SE_CalcCharFromSer, 1, 0, 0 },
{ "CalcItemFromSer", SE_CalcItemFromSer, 1, 0, 0 },
{ "CalcMultiFromSer", SE_CalcMultiFromSer, 1, 0, 0 },
{ "CheckTimeSinceLastCombat", SE_CheckTimeSinceLastCombat,2, 0, 0 },
{ "CheckInstaLog", SE_CheckInstaLog, 4, 0, 0 },
{ "GetHour", SE_GetHour, 0, 0, 0 },
{ "GetMinute", SE_GetMinute, 0, 0, 0 },
Expand Down
7 changes: 7 additions & 0 deletions source/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ bool CHandleCombat::StartAttack( CChar *cAttack, CChar *cTarget )
}
}
}
// Record the time when combat starts as a timestamp
cAttack->SetLastCombatTime( cwmWorldState->GetUICurrentTime() );
cTarget->SetLastCombatTime( cwmWorldState->GetUICurrentTime() );
return true;
}

Expand Down Expand Up @@ -580,6 +583,10 @@ void CHandleCombat::AttackTarget( CChar *cAttack, CChar *cTarget )
if( !StartAttack( cAttack, cTarget )) // Is the char allowed to initiate combat with the target?
return;

// Update last combat time for both the attacker and the target
cAttack->SetLastCombatTime( cwmWorldState->GetUICurrentTime() );
cTarget->SetLastCombatTime( cwmWorldState->GetUICurrentTime() );

if( cAttack->CheckAggressorFlag( cTarget->GetSerial() ))
{
// Send attacker message to all nearby players
Expand Down

0 comments on commit 6603436

Please sign in to comment.