polserver/pol-core/pol/module/partymod.cpp

195 lines
5.6 KiB
C++
Raw Permalink Normal View History

/** @file
*
* @par History
* - 2009/12/21 Turley: ._method() call fix
*/
2009-09-08 11:08:59 +00:00
#include "pol_global_config.h"
#include "partymod.h"
#include <stddef.h>
2009-09-08 11:08:59 +00:00
#include "../../bscript/berror.h"
#include "../../bscript/executor.h"
#include "../../bscript/impstr.h"
2009-09-08 11:08:59 +00:00
#include "../../bscript/objmembers.h"
#include "../../bscript/objmethods.h"
#include "../../clib/rawtypes.h"
#include "../../clib/stlutil.h"
2009-09-08 11:08:59 +00:00
#include "../clfunc.h"
#include "../fnsearch.h"
#include "../globals/settings.h"
2014-12-30 15:20:59 +01:00
#include "../globals/uvars.h"
#include "../mobile/charactr.h"
2018-12-30 21:35:54 +01:00
#include "../network/pktdef.h"
#include "../party.h"
#include "../party_cfg.h"
#include "../polobject.h"
#include "../syshook.h"
#include "../uoexec.h"
#include "../uoscrobj.h"
#include "../partyscrobj.h"
#include <module_defs/party.h>
namespace Pol
{
namespace Core
{
class UOExecutor;
}
namespace Module
{
using namespace Bscript;
using UOExecutor = Core::UOExecutor;
PartyExecutorModule::PartyExecutorModule( Executor& exec )
: TmplExecutorModule<PartyExecutorModule, Core::PolModule>( exec )
{
}
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;
if ( exec.hasParams( param + 1 ) )
aob = exec.getApplicObjParam( param, &party_type );
2018-07-31 14:30:29 +02:00
if ( aob == nullptr )
{
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 )
{
err = new BError( "Party has no leader" );
return false;
}
return true;
}
BObjectImp* PartyExecutorModule::mf_CreateParty()
{
Mobile::Character* leader;
Mobile::Character* firstmem;
if ( ( getCharacterParam( 0, leader ) ) && ( getCharacterParam( 1, firstmem ) ) )
{
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(),
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 );
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 ) )
{
const String* text;
Mobile::Character* chr;
if ( ( getCharacterParam( 1, chr ) ) && ( getUnicodeStringParam( 2, text ) ) )
{
if ( text->length() > SPEECH_MAX_LEN )
return new BError( "Text exceeds maximum size." );
if ( Core::settingsManager.party_cfg.Hooks.OnPublicChat )
Core::settingsManager.party_cfg.Hooks.OnPublicChat->call( chr->make_ref(),
new String( *text ) );
2019-01-03 13:09:50 +01:00
party->send_member_msg_public( chr, text->value() );
return new BLong( 1 );
}
else
return new BError( "Invalid parameter type" );
}
else
return err;
}
2009-09-08 11:08:59 +00:00
BObjectImp* PartyExecutorModule::mf_SendPrivatePartyMsg()
{
Core::Party* party;
BError* err;
if ( getPartyParam( exec, 0, party, err ) )
{
const String* text;
Mobile::Character* chr;
Mobile::Character* tochr;
if ( ( getCharacterParam( 1, chr ) ) && ( getCharacterParam( 2, tochr ) ) &&
( getUnicodeStringParam( 3, text ) ) )
{
if ( text->length() > SPEECH_MAX_LEN )
return new BError( "Text exceeds maximum size." );
if ( Core::settingsManager.party_cfg.Hooks.OnPrivateChat )
Core::settingsManager.party_cfg.Hooks.OnPrivateChat->call(
chr->make_ref(), tochr->make_ref(), new String( *text ) );
2019-01-03 13:09:50 +01:00
party->send_member_msg_private( chr, tochr, text->value() );
return new BLong( 1 );
}
else
return new BError( "Invalid parameter type" );
}
else
return err;
}
2018-12-30 21:35:54 +01:00
} // namespace Module
} // namespace Pol