Ejemplo n.º 1
0
/**
 * Conta a quantidade de chats enviadas pelas funções de procura de mapa. [CarlosHenrq]
 *
 * @param struct block_list*
 * @param va_list ap
 *
 * @return int
 */
int chat_count_sub(struct block_list *bl, va_list ap)
{
	struct map_session_data* sd = BL_UCAST(BL_PC, bl);
	int* chatCount = (int*)va_arg(ap, int *);

	if(sd != NULL && sd->chatID)
		(*chatCount)++;

	return 0;
}
Ejemplo n.º 2
0
/**
 * Map iterator subroutine to update quest objectives for a party after killing a monster.
 *
 * @see map_foreachinrange
 * @param ap Argument list, expecting:
 *           int Party ID
 *           int Mob ID
 */
int quest_update_objective_sub(struct block_list *bl, va_list ap)
{
	struct map_session_data *sd = NULL;
	int party_id = va_arg(ap, int);
	int mob_id = va_arg(ap, int);

	nullpo_ret(bl);
	Assert_ret(bl->type == BL_PC);
	sd = BL_UCAST(BL_PC, bl);

	if( !sd->avail_quests )
		return 0;
	if( sd->status.party_id != party_id )
		return 0;

	quest->update_objective(sd, mob_id);

	return 1;
}
Ejemplo n.º 3
0
/**
 * Handler called whenever a global message is spoken in a NPC's area
 */
int npc_chat_sub(struct block_list* bl, va_list ap)
{
	struct npc_data *nd = NULL;
	struct npc_parse *npcParse = NULL;
	char *msg;
	int len, i;
	struct map_session_data* sd;
	struct npc_label_list* lst;
	struct pcrematch_set* pcreset;
	struct pcrematch_entry* e;

	nullpo_ret(bl);
	Assert_ret(bl->type == BL_NPC);
	nd = BL_UCAST(BL_NPC, bl);
	npcParse = nd->chatdb;

	// Not interested in anything you might have to say...
	if (npcParse == NULL || npcParse->active == NULL)
		return 0;

	msg = va_arg(ap,char*);
	len = va_arg(ap,int);
	sd = va_arg(ap,struct map_session_data *);

	// iterate across all active sets
	for (pcreset = npcParse->active; pcreset != NULL; pcreset = pcreset->next)
	{
		// n across all patterns in that set
		for (e = pcreset->head; e != NULL; e = e->next)
		{
			int offsets[2*10 + 10]; // 1/3 reserved for temp space required by pcre_exec

			// perform pattern match
			int r = libpcre->exec(e->pcre_, e->pcre_extra_, msg, len, 0, 0, offsets, ARRAYLENGTH(offsets));
			if (r > 0)
			{
				// save out the matched strings
				for (i = 0; i < r; i++)
				{
					char var[6], val[255];
					snprintf(var, sizeof(var), "$@p%i$", i);
					libpcre->copy_substring(msg, offsets, r, i, val, sizeof(val));
					script->set_var(sd, var, val);
				}

				// find the target label.. this sucks..
				lst = nd->u.scr.label_list;
				ARR_FIND(0, nd->u.scr.label_list_num, i, strncmp(lst[i].name, e->label, sizeof(lst[i].name)) == 0);
				if (i == nd->u.scr.label_list_num) {
					ShowWarning("npc_chat_sub: Nao foi possivel localizar a label: %s\n", e->label);
					return 0;
				}

				// run the npc script
				script->run_npc(nd->u.scr.script,lst[i].pos,sd->bl.id,nd->bl.id);
				return 0;
			}
		}
	}
	return 0;
}