<commit_before>#include <node.h>
#include <v8.h>
#include <math.h>
#include <stdlib.h>
#include <new>

#include <unistd.h>
#include <uv.h>

#include "randomkit.h"
#include "swtor_tanking_optimizer.h"

using namespace node;
using namespace v8;

extern "C" {

	double
	relicBonusPct(const unsigned int base_rating, const unsigned int bonus_rating, unsigned int stat)
	{
		double delta;
		
		switch (stat){
			case RELIC_STATTYPE_DEF:
				delta = defenseChance(base_rating + bonus_rating, 0) - defenseChance(base_rating, 0);
				break; 
			case RELIC_STATTYPE_SHIELD:
				delta = shieldChance(base_rating + bonus_rating, 0) - shieldChance(base_rating, 0);
				break;
			case RELIC_STATTYPE_ABSORB:
				delta = absorbChance(base_rating + bonus_rating, 0) - absorbChance(base_rating, 0);
				break;
			default:
				delta = 0.0;
				break;
		}
		
		return delta;
	}
	
	double
	procRelicUptime(procrelic_t *relic, dmgtypes_t *dtypes, double def_miss_pct, double resist_pct, double shield_pct, double time_per_swing)
	{
		double modifier;
		switch (relic->stat){
			case RELIC_STATTYPE_ABSORB:
				modifier = shield_pct;
				break;
			case RELIC_STATTYPE_DEF:
			case RELIC_STATTYPE_SHIELD:
			default:
				modifier = 1.0;
				break;
		}
		
		double mean_swings = 1.0 / (relic->rate * modifier * ((1.0 - def_miss_pct) * dtypes->KE + (1.0 - resist_pct) * dtypes->IE));
		return relic->duration_time / (mean_swings * time_per_swing + relic->cooldown_time);
	}
	
	double
	clickRelicUptime(clickrelic_t *relic)
	{
		return relic->duration_time / relic->cooldown_time;
	}
	
	double
	defenseChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.05 + 0.3 * (1.0 - pow(1.0 - 0.01/0.3, (double)rating / (55.0 * 1.2)));
	}
	
	double
	shieldChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.05 + 0.5 * (1.0 - pow(1.0 - 0.01/0.5, (double)rating / (55.0 * 0.78)));
	}
	
	double
	absorbChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.2 + 0.5 * (1.0 - pow(1.0 - 0.01/0.5, (double)rating / (55.0 * 0.65)));
	}
	
	double
	dmgReductionKE(const unsigned int armor, const double bonus)
	{
		return bonus + (double)armor / ((double)armor + 240.0 * 55.0 + 800.0);
	}
	
	double
	dmgReductionIE(const double bonus)
	{
		return bonus + 0.10;
	}
	
	double
	mitigation(dmgtypes_t *dtypes, classdata_t *cdata, statdist_t *stats, unsigned int armor, unsigned int stimDefense, int num_relics, relic_t **relics, unsigned int *relictypes)
	{
		double d, s, a, r, drke, drie;
		
		double dbonus = 0.0, sbonus = 0.0, abonus = 0.0;
		int i;
		
		d = defenseChance(stats->defRating + stimDefense, cdata->defenseAdd + cdata->defenseBonus);
		s = shieldChance(stats->shieldRating, cdata->shieldAdd + cdata->shieldBonus);
		r = cdata->resistPct;
		
		int has_proc_relic = 0;
		int has_click_relic = 0;
		
		for (i = 0; i < num_relics; i++){
			relic_t * relic = *(relics + i);
			switch (*(relictypes + i)){
				case RELIC_TYPE_PROC:
					if (!has_proc_relic || (relic->prelic)->can_stack){
						has_proc_relic = 1;
						if ((relic->prelic)->stat == RELIC_STATTYPE_DEF){
							dbonus = dbonus + relicBonusPct(stats->defRating + stimDefense, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);	
						}
						else if ((relic->prelic)->stat == RELIC_STATTYPE_SHIELD){
							sbonus = sbonus + relicBonusPct(stats->shieldRating, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);
						}
						else if ((relic->prelic)->stat == RELIC_STATTYPE_ABSORB){
							abonus = abonus + relicBonusPct(stats->absorbRating, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);
						}
					}
					break;<commit_msg>Fixing relic stacking bug<commit_after>#include <node.h>
#include <v8.h>
#include <math.h>
#include <stdlib.h>
#include <new>

#include <unistd.h>
#include <uv.h>

#include "randomkit.h"
#include "swtor_tanking_optimizer.h"

using namespace node;
using namespace v8;

extern "C" {

	double
	relicBonusPct(const unsigned int base_rating, const unsigned int bonus_rating, unsigned int stat)
	{
		double delta;
		
		switch (stat){
			case RELIC_STATTYPE_DEF:
				delta = defenseChance(base_rating + bonus_rating, 0) - defenseChance(base_rating, 0);
				break; 
			case RELIC_STATTYPE_SHIELD:
				delta = shieldChance(base_rating + bonus_rating, 0) - shieldChance(base_rating, 0);
				break;
			case RELIC_STATTYPE_ABSORB:
				delta = absorbChance(base_rating + bonus_rating, 0) - absorbChance(base_rating, 0);
				break;
			default:
				delta = 0.0;
				break;
		}
		
		return delta;
	}
	
	double
	procRelicUptime(procrelic_t *relic, dmgtypes_t *dtypes, double def_miss_pct, double resist_pct, double shield_pct, double time_per_swing)
	{
		double modifier;
		switch (relic->stat){
			case RELIC_STATTYPE_ABSORB:
				modifier = shield_pct;
				break;
			case RELIC_STATTYPE_DEF:
			case RELIC_STATTYPE_SHIELD:
			default:
				modifier = 1.0;
				break;
		}
		
		double mean_swings = 1.0 / (relic->rate * modifier * ((1.0 - def_miss_pct) * dtypes->KE + (1.0 - resist_pct) * dtypes->IE));
		return relic->duration_time / (mean_swings * time_per_swing + relic->cooldown_time);
	}
	
	double
	clickRelicUptime(clickrelic_t *relic)
	{
		return relic->duration_time / relic->cooldown_time;
	}
	
	double
	defenseChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.05 + 0.3 * (1.0 - pow(1.0 - 0.01/0.3, (double)rating / (55.0 * 1.2)));
	}
	
	double
	shieldChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.05 + 0.5 * (1.0 - pow(1.0 - 0.01/0.5, (double)rating / (55.0 * 0.78)));
	}
	
	double
	absorbChance(const unsigned int rating, const double bonus)
	{
		return bonus + 0.2 + 0.5 * (1.0 - pow(1.0 - 0.01/0.5, (double)rating / (55.0 * 0.65)));
	}
	
	double
	dmgReductionKE(const unsigned int armor, const double bonus)
	{
		return bonus + (double)armor / ((double)armor + 240.0 * 55.0 + 800.0);
	}
	
	double
	dmgReductionIE(const double bonus)
	{
		return bonus + 0.10;
	}
	
	double
	mitigation(dmgtypes_t *dtypes, classdata_t *cdata, statdist_t *stats, unsigned int armor, unsigned int stimDefense, int num_relics, relic_t **relics, unsigned int *relictypes)
	{
		double d, s, a, r, drke, drie;
		
		double dbonus = 0.0, sbonus = 0.0, abonus = 0.0;
		int i;
		
		d = defenseChance(stats->defRating + stimDefense, cdata->defenseAdd + cdata->defenseBonus);
		s = shieldChance(stats->shieldRating, cdata->shieldAdd + cdata->shieldBonus);
		r = cdata->resistPct;
		
		int has_proc_relic = 0;
		int has_click_relic = 0;
		
		for (i = 0; i < num_relics; i++){
			relic_t * relic = *(relics + i);
			switch (*(relictypes + i)){
				case RELIC_TYPE_PROC:
					if (!has_proc_relic || (relic->prelic)->can_stack){
						if (!(relic->prelic)->can_stack){
							has_proc_relic = 1;	
						}
						
						if ((relic->prelic)->stat == RELIC_STATTYPE_DEF){
							dbonus = dbonus + relicBonusPct(stats->defRating + stimDefense, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);	
						}
						else if ((relic->prelic)->stat == RELIC_STATTYPE_SHIELD){
							sbonus = sbonus + relicBonusPct(stats->shieldRating, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);
						}
						else if ((relic->prelic)->stat == RELIC_STATTYPE_ABSORB){
							abonus = abonus + relicBonusPct(stats->absorbRating, (relic->prelic)->bonus_rating, (relic->prelic)->stat) * procRelicUptime(relic->prelic, dtypes, d + (0.5 * 0.1), r, s, 1.2);
						}
					}
					break;
{'fraction_non_alphanumeric': 0.14282034771410174, 'fraction_numerical': 0.030392788151963942, 'mean_word_length': 3.5256410256410255, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6935625', 'n_tokens_mistral': 3615, 'n_tokens_neox': 3040, 'n_words': 660}