Cleaned up hat effect code (#5462)
Converted from self written container to std::vector. Converted clif code to struct usage.
This commit is contained in:
parent
7336058485
commit
ed473d066d
@ -80,6 +80,9 @@ static struct eri *delay_clearunit_ers;
|
|||||||
|
|
||||||
struct s_packet_db packet_db[MAX_PACKET_DB + 1];
|
struct s_packet_db packet_db[MAX_PACKET_DB + 1];
|
||||||
int packet_db_ack[MAX_ACK_FUNC + 1];
|
int packet_db_ack[MAX_ACK_FUNC + 1];
|
||||||
|
// Reuseable global packet buffer to prevent too many allocations
|
||||||
|
// Take socket.cpp::socket_max_client_packet into consideration
|
||||||
|
static int8 packet_buffer[UINT16_MAX];
|
||||||
unsigned long color_table[COLOR_MAX];
|
unsigned long color_table[COLOR_MAX];
|
||||||
|
|
||||||
#include "clif_obfuscation.hpp"
|
#include "clif_obfuscation.hpp"
|
||||||
@ -20553,9 +20556,7 @@ void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x,
|
|||||||
/// Send hat effects to the client (ZC_HAT_EFFECT).
|
/// Send hat effects to the client (ZC_HAT_EFFECT).
|
||||||
/// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
|
/// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
|
||||||
void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
|
void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
unsigned char* buf;
|
|
||||||
int len,i;
|
|
||||||
struct map_session_data *tsd;
|
struct map_session_data *tsd;
|
||||||
struct block_list* tbl;
|
struct block_list* tbl;
|
||||||
|
|
||||||
@ -20567,39 +20568,40 @@ void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum
|
|||||||
tbl = bl;
|
tbl = bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !tsd->hatEffectCount )
|
nullpo_retv( tsd );
|
||||||
|
|
||||||
|
if( tsd->hatEffects.empty() ){
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len = 9 + tsd->hatEffectCount * 2;
|
|
||||||
|
|
||||||
buf = (unsigned char*)aMalloc( len );
|
|
||||||
|
|
||||||
WBUFW(buf,0) = 0xa3b;
|
|
||||||
WBUFW(buf,2) = len;
|
|
||||||
WBUFL(buf,4) = tsd->bl.id;
|
|
||||||
WBUFB(buf,8) = 1;
|
|
||||||
|
|
||||||
for( i = 0; i < tsd->hatEffectCount; i++ ){
|
|
||||||
WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clif_send(buf, len,tbl,target);
|
struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
|
||||||
|
|
||||||
aFree(buf);
|
p->packetType = HEADER_ZC_HAT_EFFECT;
|
||||||
|
p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
|
||||||
|
p->aid = tsd->bl.id;
|
||||||
|
p->status = 1;
|
||||||
|
|
||||||
|
for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
|
||||||
|
p->effects[i] = tsd->hatEffects[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
clif_send( p, p->packetLength, tbl, target );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
|
void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
unsigned char buf[13];
|
nullpo_retv( sd );
|
||||||
|
|
||||||
WBUFW(buf,0) = 0xa3b;
|
struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
|
||||||
WBUFW(buf,2) = 13;
|
|
||||||
WBUFL(buf,4) = sd->bl.id;
|
|
||||||
WBUFB(buf,8) = enable;
|
|
||||||
WBUFL(buf,9) = effectId;
|
|
||||||
|
|
||||||
clif_send(buf,13,&sd->bl,AREA);
|
p->packetType = HEADER_ZC_HAT_EFFECT;
|
||||||
|
p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) );
|
||||||
|
p->aid = sd->bl.id;
|
||||||
|
p->status = enable;
|
||||||
|
p->effects[0] = effectId;
|
||||||
|
|
||||||
|
clif_send( p, p->packetLength, &sd->bl, AREA );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2248,10 +2248,12 @@
|
|||||||
packet(0x0A2D,-1); // ZC_EQUIPWIN_MICROSCOPE_V6
|
packet(0x0A2D,-1); // ZC_EQUIPWIN_MICROSCOPE_V6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
|
packet( HEADER_ZC_HAT_EFFECT, -1 );
|
||||||
|
#endif
|
||||||
|
|
||||||
// 2015-05-13aRagexe
|
// 2015-05-13aRagexe
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER >= 20150513
|
||||||
// New Packets
|
|
||||||
packet(0xA3B,-1); // ZC_HAT_EFFECT
|
|
||||||
// RODEX Mail system
|
// RODEX Mail system
|
||||||
packet(0x09E7,3); // ZC_NOTIFY_UNREADMAIL
|
packet(0x09E7,3); // ZC_NOTIFY_UNREADMAIL
|
||||||
parseable_packet(0x09E8,11,clif_parse_Mail_refreshinbox,2,3); // CZ_OPEN_MAILBOX
|
parseable_packet(0x09E8,11,clif_parse_Mail_refreshinbox,2,3); // CZ_OPEN_MAILBOX
|
||||||
|
@ -1663,9 +1663,8 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_
|
|||||||
// Initialize BG queue
|
// Initialize BG queue
|
||||||
sd->bg_queue_id = 0;
|
sd->bg_queue_id = 0;
|
||||||
|
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
sd->hatEffectIDs = NULL;
|
sd->hatEffects = {};
|
||||||
sd->hatEffectCount = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sd->catch_target_class = PET_CATCH_FAIL;
|
sd->catch_target_class = PET_CATCH_FAIL;
|
||||||
|
@ -787,9 +787,8 @@ struct map_session_data {
|
|||||||
|
|
||||||
short setlook_head_top, setlook_head_mid, setlook_head_bottom, setlook_robe; ///< Stores 'setlook' script command values.
|
short setlook_head_top, setlook_head_mid, setlook_head_bottom, setlook_robe; ///< Stores 'setlook' script command values.
|
||||||
|
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
uint32* hatEffectIDs;
|
std::vector<int16> hatEffects;
|
||||||
uint8 hatEffectCount;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct{
|
struct{
|
||||||
|
@ -23191,47 +23191,34 @@ BUILDIN_FUNC(recalculatestat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BUILDIN_FUNC(hateffect){
|
BUILDIN_FUNC(hateffect){
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
struct map_session_data* sd;
|
struct map_session_data* sd;
|
||||||
bool enable;
|
|
||||||
int i, effectID;
|
|
||||||
|
|
||||||
if( !script_rid2sd(sd) )
|
if( !script_rid2sd(sd) )
|
||||||
return SCRIPT_CMD_FAILURE;
|
return SCRIPT_CMD_FAILURE;
|
||||||
|
|
||||||
effectID = script_getnum(st,2);
|
int16 effectID = script_getnum(st,2);
|
||||||
enable = script_getnum(st,3) ? true : false;
|
bool enable = script_getnum(st,3) ? true : false;
|
||||||
|
|
||||||
if( effectID <= HAT_EF_MIN || effectID >= HAT_EF_MAX ){
|
if( effectID <= HAT_EF_MIN || effectID >= HAT_EF_MAX ){
|
||||||
ShowError( "buildin_hateffect: unsupported hat effect id %d\n", effectID );
|
ShowError( "buildin_hateffect: unsupported hat effect id %d\n", effectID );
|
||||||
return SCRIPT_CMD_FAILURE;
|
return SCRIPT_CMD_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARR_FIND( 0, sd->hatEffectCount, i, sd->hatEffectIDs[i] == effectID );
|
auto it = util::vector_get( sd->hatEffects, effectID );
|
||||||
|
|
||||||
if( enable ){
|
if( enable ){
|
||||||
if( i < sd->hatEffectCount ){
|
if( it != sd->hatEffects.end() ){
|
||||||
return SCRIPT_CMD_SUCCESS;
|
return SCRIPT_CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECREATE(sd->hatEffectIDs,uint32,sd->hatEffectCount+1);
|
sd->hatEffects.push_back( effectID );
|
||||||
sd->hatEffectIDs[sd->hatEffectCount] = effectID;
|
|
||||||
sd->hatEffectCount++;
|
|
||||||
}else{
|
}else{
|
||||||
if( i == sd->hatEffectCount ){
|
if( it == sd->hatEffects.end() ){
|
||||||
return SCRIPT_CMD_SUCCESS;
|
return SCRIPT_CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; i < sd->hatEffectCount - 1; i++ ){
|
util::vector_erase_if_exists( sd->hatEffects, effectID );
|
||||||
sd->hatEffectIDs[i] = sd->hatEffectIDs[i+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
sd->hatEffectCount--;
|
|
||||||
|
|
||||||
if( !sd->hatEffectCount ){
|
|
||||||
aFree(sd->hatEffectIDs);
|
|
||||||
sd->hatEffectIDs = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !sd->state.connect_new ){
|
if( !sd->state.connect_new ){
|
||||||
|
@ -1842,7 +1842,7 @@ enum e_special_effects {
|
|||||||
EF_MAX
|
EF_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum e_hat_effects {
|
enum e_hat_effects : int16{
|
||||||
HAT_EF_MIN = 0,
|
HAT_EF_MIN = 0,
|
||||||
HAT_EF_BLOSSOM_FLUTTERING,
|
HAT_EF_BLOSSOM_FLUTTERING,
|
||||||
HAT_EF_MERMAID_LONGING,
|
HAT_EF_MERMAID_LONGING,
|
||||||
|
@ -3401,12 +3401,8 @@ int unit_free(struct block_list *bl, clr_type clrtype)
|
|||||||
}
|
}
|
||||||
sd->qi_count = 0;
|
sd->qi_count = 0;
|
||||||
|
|
||||||
#if PACKETVER >= 20150513
|
#if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
|
||||||
if( sd->hatEffectCount > 0 ){
|
sd->hatEffects.clear();
|
||||||
aFree(sd->hatEffectIDs);
|
|
||||||
sd->hatEffectIDs = NULL;
|
|
||||||
sd->hatEffectCount = 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sd->achievement_data.achievements)
|
if (sd->achievement_data.achievements)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user