View Single Post
Old March 27, 2020, 00:02   #66
DavidMedley
Knight
 
Join Date: Oct 2019
Posts: 584
DavidMedley is on a distinguished road
Melee_blows

Finally wrote my first effect handler. I really don't understand the code too well, but copy and paste served me surprisingly well. Only bug I'm aware of is it crashes if there's not an enemy to use it on. This obviously needs to be fixed. Anything else anyone sees? I'm not confident in the target and grid stuff.

Code:
bool effect_handler_MELEE_BLOWS(effect_handler_context_t *context)
{
	int blows = effect_calculate_value(context, false);
	bool fear;
	int taim;
	struct loc target = loc(-1, -1);
	struct loc grid = player->grid;

/* players only for now */
	if (context->origin.what != SRC_PLAYER)
		return false;

	/* Ask for a target if no direction given */
	if (context->dir == DIR_TARGET && target_okay()) {
		target_get(&target);
	} else {
		target = loc_sum(player->grid, ddgrid[context->dir]);
	}

	taim = distance(grid, target);
	if (taim > 1) {
		msgt(MSG_GENERIC, "Distance to target %d", taim);
		return false;
	}

	while (blows-- > 0) {
		if(py_attack_real(player, target, &fear)) {return true;}
	}
	return true;
}
DavidMedley is offline   Reply With Quote