Skip to content

Commit

Permalink
Merge branch 'feature/bonded' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
raydienull committed Nov 30, 2023
2 parents e156449 + 7882ad0 commit 743a7d9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/game/chars/CCharNPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CCharNPC::CCharNPC( CChar * pChar, NPCBRAIN_TYPE NPCBrain )
m_Home_Dist_Wander = INT16_MAX; // as far as i want.
m_Act_Motivation = 0;
m_bonded = 0;
_bondedTime = 0;
#ifndef _WIN32
for (int i_tmpN=0;i_tmpN < MAX_NPC_PATH_STORAGE_SIZE;i_tmpN++)
{
Expand Down Expand Up @@ -83,6 +84,9 @@ bool CCharNPC::r_LoadVal( CChar * pChar, CScript &s )
if ( !g_Serv.IsLoading() )
pChar->UpdatePropertyFlag();
break;
case CNC_BONDEDTIME:
_bondedTime = s.GetArg64Val();
break;
case CNC_FOLLOWERSLOTS:
pChar->SetDefNum(s.GetKey(), s.GetArgVal(), false );
break;
Expand Down Expand Up @@ -167,6 +171,9 @@ bool CCharNPC::r_WriteVal( CChar * pChar, lpctstr ptcKey, CSString & sVal )
case CNC_BONDED:
sVal.FormatVal( m_bonded );
break;
case CNC_BONDEDTIME:
sVal.Format64Val( _bondedTime );
break;
case CNC_FOLLOWERSLOTS:
sVal.FormatLLVal(pChar->GetDefNum(ptcKey, true));
break;
Expand Down Expand Up @@ -248,6 +255,9 @@ void CCharNPC::r_WriteChar( CChar * pChar, CScript & s )
if (m_bonded)
s.WriteKeyVal("BONDED", m_bonded);

if (_bondedTime)
s.WriteKeyVal("BONDEDTIME", _bondedTime);

if ( m_Need.GetResourceID().IsValidUID())
{
TemporaryString tsTemp;
Expand Down
1 change: 1 addition & 0 deletions src/game/chars/CCharNPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CCharNPC
word m_Home_Dist_Wander; // Distance to allow to "wander".
byte m_Act_Motivation; // 0-100 (100=very greatly) how bad do i want to do the current action.
bool m_bonded; // Bonded pet
int64 _bondedTime; // Time when bonded

CResourceRefArray m_Speech; // Speech fragment list (other stuff we know): We respond to what we hear with this.

Expand Down
10 changes: 10 additions & 0 deletions src/game/chars/CCharNPCPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
#include "../components/CCSpawn.h"
#include "../items/CItemVendable.h"
#include "../CServerTime.h"
#include "../CWorldGameTime.h"
#include "../triggers.h"
#include "CChar.h"
#include "CCharNPC.h"

static int32 const BondedTime = 7 * 24 * 60 * 60 * MSECS_PER_SEC; // 7 days

void CChar::NPC_OnPetCommand( bool fSuccess, CChar * pMaster )
{
ADDTOCALLSTACK("CChar::NPC_OnPetCommand");
Expand Down Expand Up @@ -548,6 +551,7 @@ void CChar::NPC_PetClearOwners()
CChar * pOwner = NPC_PetGetOwner();
Memory_ClearTypes(MEMORY_IPET|MEMORY_FRIEND);
m_pNPC->m_bonded = 0; // pets without owner cannot be bonded
m_pNPC->_bondedTime = 0; // reset bonded time

if ( NPC_IsVendor() )
{
Expand Down Expand Up @@ -614,6 +618,12 @@ bool CChar::NPC_PetSetOwner( CChar * pChar )
pBank->m_itEqBankBox.m_Check_Amount = 0;
StatFlag_Set(STATF_INVUL);
}
else
{
// if is a pet, set the bonded time to new owner
if (m_pNPC)
m_pNPC->_bondedTime = CWorldGameTime::GetCurrentTime().GetTimeRaw() + BondedTime;
}

if ( IsSetOF(OF_PetSlots) )
{
Expand Down
5 changes: 5 additions & 0 deletions src/game/chars/CCharSkill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../items/CItemVendable.h"
#include "../triggers.h"
#include "../CServer.h"
#include "../CWorldGameTime.h"
#include "../CWorldMap.h"
#include "CChar.h"
#include "CCharNPC.h"
Expand Down Expand Up @@ -2305,6 +2306,10 @@ int CChar::Skill_Taming( SKTRIG_TYPE stage )
pChar->m_Act_UID = GetUID();
pChar->Skill_Start(NPCACT_FOLLOW_TARG);

// set the new bonded time for the pet
if (pChar->m_pNPC)
pChar->m_pNPC->_bondedTime = CWorldGameTime::GetCurrentTime().GetTimeRaw();

if (fTamedPrev)
return -SKTRIG_QTY; // no credit for this.

Expand Down
18 changes: 18 additions & 0 deletions src/game/chars/CCharUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,24 @@ void CChar::Use_EatQty( CItem * pFood, ushort uiQty )
UpdateDir(pFood);
EatAnim(pFood->GetName(), uiRestore * uiQty);
pFood->ConsumeAmount(uiQty);

//check bondet time to bond
if (m_pNPC && m_pNPC->_bondedTime && m_pNPC->_bondedTime < CWorldGameTime::GetCurrentTime().GetTimeRaw())
{
//only if have owner
const CChar * pOwner = NPC_PetGetOwner();
if (pOwner)
{
m_pNPC->_bondedTime = 0;
m_pNPC->m_bonded = true;
UpdatePropertyFlag();
const CClient* pClient = pOwner->GetClientActive();
if (pClient)
{
pClient->addBarkLocalized(1049666, nullptr); // Your pet has bonded with you!
}
}
}
}

bool CChar::Use_Eat( CItem * pItemFood, ushort uiQty )
Expand Down
1 change: 1 addition & 0 deletions src/tables/CCharNpc_props.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

ADD(ACTPRI, "ACTPRI")
ADD(BONDED, "BONDED")
ADD(BONDEDTIME, "BONDEDTIME")
ADD(FOLLOWERSLOTS, "FOLLOWERSLOTS")
ADD(HOMEDIST, "HOMEDIST")
ADD(NEED, "NEED")
Expand Down

0 comments on commit 743a7d9

Please sign in to comment.