2016-01-28 14:52:40 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
* - 2009/12/21 Turley: ._method() call fix
|
|
|
|
|
*/
|
2009-09-08 11:08:59 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 21:04:40 +01:00
|
|
|
#include "pol_global_config.h"
|
|
|
|
|
|
2014-11-02 13:50:25 +01:00
|
|
|
#include "partymod.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include <stddef.h>
|
2009-09-08 11:08:59 +00:00
|
|
|
|
|
|
|
|
#include "../../bscript/berror.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../bscript/executor.h"
|
2018-12-31 14:28:37 +01:00
|
|
|
#include "../../bscript/impstr.h"
|
2009-09-08 11:08:59 +00:00
|
|
|
#include "../../bscript/objmembers.h"
|
|
|
|
|
#include "../../bscript/objmethods.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../clib/rawtypes.h"
|
2018-10-28 09:31:58 +01:00
|
|
|
#include "../../clib/stlutil.h"
|
2009-09-08 11:08:59 +00:00
|
|
|
#include "../clfunc.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../fnsearch.h"
|
|
|
|
|
#include "../globals/settings.h"
|
2014-12-30 15:20:59 +01:00
|
|
|
#include "../globals/uvars.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../mobile/charactr.h"
|
2018-12-30 21:35:54 +01:00
|
|
|
#include "../network/pktdef.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../party.h"
|
|
|
|
|
#include "../party_cfg.h"
|
2020-02-08 09:21:35 +01:00
|
|
|
#include "../polobject.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../syshook.h"
|
2020-02-08 09:21:35 +01:00
|
|
|
#include "../uoexec.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../uoscrobj.h"
|
2020-02-08 09:21:35 +01:00
|
|
|
#include "../partyscrobj.h"
|
2019-11-10 22:04:08 +01:00
|
|
|
#include <module_defs/party.h>
|
|
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
2020-02-08 09:21:35 +01:00
|
|
|
namespace Core
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2020-02-08 09:21:35 +01:00
|
|
|
class UOExecutor;
|
2016-02-19 19:26:35 +01:00
|
|
|
|
|
|
|
|
}
|
2020-02-08 09:21:35 +01:00
|
|
|
namespace Module
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2020-02-08 09:21:35 +01:00
|
|
|
using namespace Bscript;
|
|
|
|
|
using UOExecutor = Core::UOExecutor;
|
2016-02-19 19:26:35 +01:00
|
|
|
|
2020-02-08 09:21:35 +01:00
|
|
|
PartyExecutorModule::PartyExecutorModule( Executor& exec )
|
|
|
|
|
: TmplExecutorModule<PartyExecutorModule, Core::PolModule>( exec )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BObjectImp* CreatePartyRefObjImp( Core::Party* party )
|
|
|
|
|
{
|
|
|
|
|
return new EPartyRefObjImp( ref_ptr<Core::Party>( party ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// party.em Functions:
|
|
|
|
|
bool getPartyParam( Executor& exec, unsigned param, Core::Party*& party, BError*& err )
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
BApplicObjBase* aob = nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( exec.hasParams( param + 1 ) )
|
|
|
|
|
aob = exec.getApplicObjParam( param, &party_type );
|
|
|
|
|
|
2018-07-31 14:30:29 +02:00
|
|
|
if ( aob == nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
err = new BError( "Invalid parameter type" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EPartyRefObjImp* pr = static_cast<EPartyRefObjImp*>( aob );
|
|
|
|
|
party = pr->value().get();
|
2018-07-31 14:30:29 +02:00
|
|
|
if ( Core::system_find_mobile( party->leader() ) == nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
err = new BError( "Party has no leader" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BObjectImp* PartyExecutorModule::mf_CreateParty()
|
|
|
|
|
{
|
|
|
|
|
Mobile::Character* leader;
|
|
|
|
|
Mobile::Character* firstmem;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( ( getCharacterParam( 0, leader ) ) && ( getCharacterParam( 1, firstmem ) ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
if ( leader->has_party() )
|
|
|
|
|
return new BError( "Leader is already in a party" );
|
|
|
|
|
else if ( leader->has_candidate_of() )
|
|
|
|
|
return new BError( "Leader is already candidate of a party" );
|
|
|
|
|
else if ( leader->has_offline_mem_of() )
|
|
|
|
|
return new BError( "Leader is already offline member of a party" );
|
|
|
|
|
else if ( leader == firstmem )
|
|
|
|
|
return new BError( "Leader and Firstmember are the same" );
|
|
|
|
|
else if ( firstmem->has_party() )
|
|
|
|
|
return new BError( "First Member is already in a party" );
|
|
|
|
|
else if ( firstmem->has_candidate_of() )
|
|
|
|
|
return new BError( "First Member is already candidate of a party" );
|
|
|
|
|
else if ( firstmem->has_offline_mem_of() )
|
|
|
|
|
return new BError( "First Member is already offline member of a party" );
|
|
|
|
|
|
|
|
|
|
Core::Party* party = new Core::Party( leader->serial );
|
|
|
|
|
Core::gamestate.parties.push_back( ref_ptr<Core::Party>( party ) );
|
|
|
|
|
leader->party( party );
|
|
|
|
|
|
|
|
|
|
if ( party->add_member( firstmem->serial ) )
|
|
|
|
|
{
|
|
|
|
|
firstmem->party( party );
|
|
|
|
|
if ( Core::settingsManager.party_cfg.Hooks.OnPartyCreate )
|
|
|
|
|
Core::settingsManager.party_cfg.Hooks.OnPartyCreate->call( CreatePartyRefObjImp( party ) );
|
|
|
|
|
party->send_msg_to_all( Core::CLP_Added ); // You have been added to the party.
|
|
|
|
|
if ( leader->has_active_client() )
|
2019-01-03 17:21:55 +01:00
|
|
|
Core::send_sysmessage_cl_affix( leader->client, Core::CLP_Joined, firstmem->name(),
|
2016-02-19 19:26:35 +01:00
|
|
|
true ); // : joined the party.
|
|
|
|
|
if ( firstmem->has_active_client() )
|
2019-01-03 17:21:55 +01:00
|
|
|
Core::send_sysmessage_cl_affix( firstmem->client, Core::CLP_Joined, leader->name(), true );
|
2018-07-31 14:30:29 +02:00
|
|
|
party->send_member_list( nullptr );
|
2016-02-19 19:26:35 +01:00
|
|
|
party->send_stats_on_add( firstmem );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new BLong( 1 );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return new BError( "Invalid parameter type" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BObjectImp* PartyExecutorModule::mf_DisbandParty()
|
|
|
|
|
{
|
|
|
|
|
Core::Party* party;
|
|
|
|
|
BError* err;
|
|
|
|
|
if ( getPartyParam( exec, 0, party, err ) )
|
|
|
|
|
{
|
|
|
|
|
Core::disband_party( party->leader() );
|
|
|
|
|
return new BLong( 1 );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BObjectImp* PartyExecutorModule::mf_SendPartyMsg()
|
|
|
|
|
{
|
|
|
|
|
Core::Party* party;
|
|
|
|
|
BError* err;
|
|
|
|
|
if ( getPartyParam( exec, 0, party, err ) )
|
|
|
|
|
{
|
2018-12-31 14:28:37 +01:00
|
|
|
const String* text;
|
2016-02-19 19:26:35 +01:00
|
|
|
Mobile::Character* chr;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( ( getCharacterParam( 1, chr ) ) && ( getUnicodeStringParam( 2, text ) ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2018-12-31 14:28:37 +01:00
|
|
|
if ( text->length() > SPEECH_MAX_LEN )
|
|
|
|
|
return new BError( "Text exceeds maximum size." );
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( Core::settingsManager.party_cfg.Hooks.OnPublicChat )
|
2019-01-03 18:58:13 +01:00
|
|
|
Core::settingsManager.party_cfg.Hooks.OnPublicChat->call( chr->make_ref(),
|
|
|
|
|
new String( *text ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
|
2019-01-03 13:09:50 +01:00
|
|
|
party->send_member_msg_public( chr, text->value() );
|
2016-02-19 19:26:35 +01:00
|
|
|
return new BLong( 1 );
|
2015-05-16 10:30:34 +02:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
else
|
|
|
|
|
return new BError( "Invalid parameter type" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2009-09-08 11:08:59 +00:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
BObjectImp* PartyExecutorModule::mf_SendPrivatePartyMsg()
|
|
|
|
|
{
|
|
|
|
|
Core::Party* party;
|
|
|
|
|
BError* err;
|
|
|
|
|
if ( getPartyParam( exec, 0, party, err ) )
|
|
|
|
|
{
|
2018-12-31 14:28:37 +01:00
|
|
|
const String* text;
|
2016-02-19 19:26:35 +01:00
|
|
|
Mobile::Character* chr;
|
|
|
|
|
Mobile::Character* tochr;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( ( getCharacterParam( 1, chr ) ) && ( getCharacterParam( 2, tochr ) ) &&
|
2018-12-31 14:28:37 +01:00
|
|
|
( getUnicodeStringParam( 3, text ) ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2018-12-31 14:28:37 +01:00
|
|
|
if ( text->length() > SPEECH_MAX_LEN )
|
|
|
|
|
return new BError( "Text exceeds maximum size." );
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( Core::settingsManager.party_cfg.Hooks.OnPrivateChat )
|
2018-12-31 14:28:37 +01:00
|
|
|
Core::settingsManager.party_cfg.Hooks.OnPrivateChat->call(
|
2019-01-03 18:58:13 +01:00
|
|
|
chr->make_ref(), tochr->make_ref(), new String( *text ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
|
2019-01-03 13:09:50 +01:00
|
|
|
party->send_member_msg_private( chr, tochr, text->value() );
|
2016-02-19 19:26:35 +01:00
|
|
|
return new BLong( 1 );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return new BError( "Invalid parameter type" );
|
2013-12-21 09:10:46 +00:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
else
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2018-12-30 21:35:54 +01:00
|
|
|
} // namespace Module
|
|
|
|
|
} // namespace Pol
|