View Single Post
Old June 25, 2020, 07:45   #7
Celiend
Rookie
 
Join Date: Jun 2020
Posts: 8
Celiend is on a distinguished road
Here is the pretty version:

Code:
/**
 * Draw energy from all nearby undead
 */
bool effect_handler_TAP_UNLIFE(effect_handler_context_t *context)
{
	int amount = effect_calculate_value(context, false);
	struct loc target;
	struct monster *mon = NULL;
	char m_name[80];
       
	int drain = 0;
	bool fear = false;
	bool dead = false;
        
	context->ident = true;

	/* Closest living monster */
	if (!target_set_closest(TARGET_KILL, monster_is_undead)) {
		return false;
	}
	target_get(&target);
	mon = target_get_monster();
        
        struct loc origin = origin_get_loc(context->origin);
        
        int i = 0;
        
        for (i = 1; i < cave_monster_max(cave); i++) {
            
            struct monster *mon = cave_monster(cave, i);

            struct loc grid;

            /* Location */
            grid = mon->grid;
            
        	/* Paranoia -- Skip dead monsters */
            if (!mon->race) continue;

	    /* Require line of sight */
            if (!los(cave, origin, mon->grid)) continue;

	    /* Jump directly to the monster */
            /* Hurt the monster */            
            if(monster_is_undead(mon))
            {
                monster_desc(m_name, sizeof(m_name), mon, MDESC_TARG);
                msg("You draw power from the %s.", m_name);
                drain = MIN(mon->hp, amount) / 4;
                dead = mon_take_hit(mon, amount, &fear, " is destroyed!");        
            } 
            	    
            context->ident = true;
	}
	
	/* Gain mana */
	effect_simple(EF_RESTORE_MANA, context->origin, format("%d", drain), 0, 0,
				  0, 0, 0, NULL);	

	return true;
}
Celiend is offline   Reply With Quote