procedure start;

//nuka cola effects
//extra traits, lowered stats

#define dude_level (get_pc_stat(1))

//Traits
#define LowGravity "Low gravity"
#define Ironwall "Ironwall"
#define Swift "Swift"
#define RapidLearner "Rapid learner"
#define JackOfTrades "Jack of all trades"
#define DiligentLearner "Diligent learner"
#define CautiousPickpocket "Cautious pickpocket"
#define BrazenThief "Brazen thief"
#define PerfectAim "Perfect aim"
#define PatheticAim "Pathetic aim"
#define VileBreath "Vile breath"
#define NightPerson "Night person"
#define AnimalFriend "Animal friend"

//Perks

procedure setup_perk_dialog begin
	set_perkbox_title("Choose a trait");
	hide_real_perks;
	perk_add_mode(1);
	set_selectable_perk(LowGravity, 1, 46, "You've always found that the lightest touch has been enough to send your opponents flying. Unfortunately, the same applies to your opponents attacks against you, too.");
	//set_selectable_perk(Ironwall, 1, 171, "You stand where you like, and even a rocket to the face isn't going to move you. Heck, even _you_ sometimes find it difficult to move you.");
	//set_selectable_perk(Swift, 1, 19, "You can move a little faster than those around you, but you lack a little of the reflexes required to use your excessive speed.");
	set_selectable_perk(RapidLearner, 1, 4, "Although you don't have the natural gifts held by others, you make up for it by being able to make much better use of your day to day experiences.");
	set_selectable_perk(JackOfTrades, 1, 4, "Although you seem to be able to succeed in anything you put your mind too, you lack the concentration to master any one ability.");
	set_selectable_perk(DiligentLearner, 1, 4, "You might take a little longer than most to fully grasp a lesson, but you usually manage to pick up a few extra ticks that no one else would have noticed.");
	//set_selectable_perk(CautiousPickpocket, 1, 156, "You have a cautious personality that harms your chances of pulling of a theft. Perhaps with practise, that weakness could be turned into a strength.");
	//set_selectable_perk(BrazenThief, 1, 112, "Your lack of reflexes has never harmed your skill as a thief; your approach to theft is to simply take whatever you like no matter who's watching. You find it helps if you look like you have a right to be somewhere.");
	//set_selectable_perk(PerfectAim, 1, 86, "You don't make stupid mistakes with your weapon; if an opportunity presents itself, you will not miss. Your increased focus on harming your opponents obviously hurts your abilities to dodge, however.");
	set_selectable_perk(PatheticAim, 1, 129, "No matter how hard you aim, you just can't seem to hit anything. On the other hand, no matter how long you stand around doing nothing, nobody seems to be able to hit you either.");
	if(get_pc_base_stat(3) > 2) then begin
		set_selectable_perk(VileBreath, 1, 129, "You are afflicted by a serious case of oral misodor. People tend to avoid your company, but your ability to dazzle your foes with a single exhalation gives you a head start in combat.");
	end
	/*if(get_pc_base_stat(3)>1 and get_pc_base_stat(6)>1 and get_pc_base_stat(3)<10) and get_pc_base_stat(6)<10) then begin
		set_selectable_perk(AnimalFriend, 1, 1, "You are a pet lover. When your four-legged friends are nearby, you flourish and anything you put your mind to sorts itself out just easily. Without a pet's company you're a little grumpy and hapeless, though.");
	end
	if(get_pc_base_stat(1)>1 and get_pc_base_stat(4)>1 and get_pc_base_stat(1)<10) and get_pc_base_stat(4)<10) then begin
		set_selectable_perk(AnimalFriend, 1, 1, "As a night-time person, you are more awake when the sun goes down. Your Intelligence and Perception are improved at night, but dulled during the day.");
	end*/
end

procedure apply_traits_repeat begin
	if(has_fake_trait(LowGravity)) then begin
		set_attacker_knockback(dude_obj, 1, 3.0);
		set_target_knockback(dude_obj, 1, 3.0);
	end
	/*if(has_fake_trait(Ironwall)) then begin
		set_target_knockback(dude_obj, 0, 0);
	end*/
	if(has_fake_trait(RapidLearner)) then begin
		set_xp_mod(200);
	end
	if(has_fake_trait(LowGravity)) then begin
		set_attacker_knockback(dude_obj, 1, 3.0);
		set_target_knockback(dude_obj, 1, 3.0);
	end
	if(has_fake_trait(JackOfTrades)) then begin
		set_critter_skill_mod(dude_obj, 100);
	end
	if(has_fake_trait(DiligentLearner)) then begin
		set_xp_mod(90);
		set_perk_level_mod(6);
	end
	/*if(has_fake_trait(CautiousPickpocket)) then begin
		set_pickpocket_mod(has_skill(dude_obj, 10) / 2);
	end
	if(has_fake_trait(BrazenThief)) then begin
		set_pickpocket_mod(80);
	end
	if(has_fake_trait(PerfectAim)) then begin
		set_hit_chance_mod(100);
	end*/
	if(has_fake_trait(PatheticAim)) then begin
		set_base_hit_chance_mod(50, -5);
	end
end

procedure apply_traits begin
	if(has_fake_trait(Ironwall)) then begin
		set_pc_extra_stat(8, get_pc_extra_stat(8) - 1);
		critter_add_trait(dude_obj, 0, 104, 1);
	end
	/*if(has_fake_trait(Swift)) then begin
		set_pc_extra_stat(8, get_pc_extra_stat(8) + 1);
		set_pc_extra_stat(13, get_pc_extra_stat(13) - get_pc_base_stat(13) );
	end*/
	if(has_fake_trait(RapidLearner)) then begin
		set_pc_base_stat(0, get_pc_base_stat(0) - 1);
		set_pc_base_stat(1, get_pc_base_stat(1) - 1);
		set_pc_base_stat(2, get_pc_base_stat(2) - 1);
		set_pc_base_stat(3, get_pc_base_stat(3) - 1);
		set_pc_base_stat(4, get_pc_base_stat(4) - 1);
		set_pc_base_stat(5, get_pc_base_stat(5) - 1);
		set_pc_base_stat(6, get_pc_base_stat(6) - 1);
	end
	if(has_fake_trait(JackOfTrades)) then begin
		critter_mod_skill(dude_obj, 00, 10);
		critter_mod_skill(dude_obj, 01, 10);
		critter_mod_skill(dude_obj, 02, 10);
		critter_mod_skill(dude_obj, 03, 10);
		critter_mod_skill(dude_obj, 04, 10);
		critter_mod_skill(dude_obj, 05, 10);
		critter_mod_skill(dude_obj, 06, 10);
		critter_mod_skill(dude_obj, 07, 10);
		critter_mod_skill(dude_obj, 08, 10);
		critter_mod_skill(dude_obj, 09, 10);
		critter_mod_skill(dude_obj, 10, 10);
		critter_mod_skill(dude_obj, 11, 10);
		critter_mod_skill(dude_obj, 12, 10);
		critter_mod_skill(dude_obj, 13, 10);
		critter_mod_skill(dude_obj, 14, 10);
		critter_mod_skill(dude_obj, 15, 10);
		critter_mod_skill(dude_obj, 16, 10);
		critter_mod_skill(dude_obj, 17, 10);
	end
	/*if(has_fake_trait(BrazenThief)) then begin
		critter_mod_skill(dude_obj, 10, get_pc_base_stat(3)*3);
	end*/
	if(has_fake_trait(VileBreath)) then begin
		set_pc_base_stat(3, get_pc_base_stat(3) - 2);
		set_pc_base_stat(13, get_pc_base_stat(13) + 15);
	end
end

procedure start begin
	variable mode;
	if (game_loaded) then begin
		mode:=get_sfall_global_int("ts_trt00");
		if(mode==-1) then begin
			return;
		end else if(mode==0) then begin
			if(dude_level>1) then begin
				display_msg("Error: Extra trait mod works for new games only");
				set_sfall_global("ts_trt00", -1);
				return;
			end
			display_msg("Visit the character screen before your first level up to pick your new trait");
			set_perk_owed(1);
			set_global_script_repeat(100);
			call setup_perk_dialog;
		end else begin
			call apply_traits_repeat;
		end
	end else begin
		if(dude_level>1) then begin
			clear_selectable_perks;
			set_perk_owed(get_perk_owed - 1);
			set_global_script_repeat(0);
			set_sfall_global("ts_trt00", 1);
			return;
		end
		if(get_perk_owed>0) then begin
			return;
		end
		clear_selectable_perks;
		set_global_script_repeat(0);
		set_sfall_global("ts_trt00", 1);
		call apply_traits;
		call apply_traits_repeat;
	end
end

