//===== Hercules Script ======================================
//= Job Master
//===== By: ==================================================
//= Euphy
//===== Current Version: =====================================
//= 1.4
//===== Description: =========================================
//= A fully functional job changer.
//===== Additional Comments: =================================
//= 1.1 Fixed reset on Baby job change. [Euphy]
//= 1.2 Added Expanded Super Novice support and initial Kagerou/Oboro support. [Euphy]
//= 1.3 Kagerou/Oboro added. [Euphy]
//= 1.4 Improved legibility (renamed variables, replaced
//      numbers with constants; Changed syntax to match
//      Hercules standards; Fixed status point exploit upon
//      Baby Novice job change. [Haru]
//============================================================

//@unloadnpc Job Master#o
//@loadnpc npc/valhalla/jobmaster.txt


office,136,34,3	script	Job Master#o	4_M_KNIGHT_GOLD,{
	function Job_Menu; function A_An;

	mes "[Job Master]";
	if (Class > Job_Soul_Linker) {
		mes "No more jobs are available.";
		close;
	}
	if (checkfalcon() || checkcart() || checkmount() || hascashmount()) {
		mes "Please remove your "+((checkfalcon())?"falcon":"")+((checkcart())?"cart":"")+((checkmount() || hascashmount())?"mount":"")
		    +" before proceeding.";
		close;
	}
	if (.skill_point_check && SkillPoint > 0) {
		mes "Please use all your skill points before proceeding.";
		close;
	}

	.@eac = eaclass();
	.@base = .third_classes ? roclass(.@eac&EAJ_UPPERMASK) : Class;
	if (.@base >= Job_Knight && .@base <= Job_Crusader2) {
		if (BaseLevel < .rebirth_blevel || JobLevel < .rebirth_jlevel) {
			.@blvl = .rebirth_blevel - BaseLevel;
			.@jlvl = .rebirth_jlevel - JobLevel;
			mes "You need "
			    + (BaseLevel < .rebirth_blevel ? ((.rebirth_blevel - BaseLevel) +" more base levels "+ (JobLevel < .rebirth_jlevel ? "and " : "")) : "")
			    + (JobLevel < .rebirth_jlevel ? (.rebirth_jlevel - JobLevel) +" more job levels " : "")
			    + "to continue.";
			close;
		}
		if (Class > Job_Crusader2) {
			mes "Switch to third class?";
			next;
			Job_Menu(roclass(.@eac|EAJL_THIRD));
			close;
		}
		while (true) {
			mes "Select an option.";
			next;
			.@choice = select(" ~ ^0055FFRebirth^000000", (.third_classes ? " ~ ^FF0000Third Class^000000":""), " ~ ^777777Cancel^000000");
			if (.@choice == 3)
				close;
			mes "[Job Master]";
			mes "Are you sure?";
			next;
			if (.@choice == 1)
				Job_Menu(Job_Novice_High);
			else
				Job_Menu(roclass(.@eac|EAJL_THIRD));
			mes "[Job Master]";
		}
	}
	.@job1 = roclass(.@eac|EAJL_2_1);
	.@job2 = roclass(.@eac|EAJL_2_2);
	if ((.@eac&EAJ_UPPERMASK) == EAJ_SUPER_NOVICE) {
		.@newclass = roclass(.@eac|EAJL_THIRD);
		.@required_jlevel = 99;
	} else if (Class == Job_Ninja || Class == Job_Gunslinger) {
		.@newclass = .@job1;
		.@required_jlevel = 70;
	}
	if (.@newclass && .third_classes) {
		if (BaseLevel < .rebirth_blevel || JobLevel < .@required_jlevel) {
			mes "You need "
			    + (BaseLevel < .rebirth_blevel ? ((.rebirth_blevel - BaseLevel) +" more base levels "+ (JobLevel < .@required_jlevel ? "and " : "")) : "")
			    + (JobLevel < .@required_jlevel ? (.@required_jlevel - JobLevel) +" more job levels " : "")
			    + "to continue.";
			close;
		}
		mes "Switch to "+jobname(.@newclass)+"?";
		next;
		Job_Menu(.@newclass);
		close;
	}
	if (.@eac&EAJL_2)
		if (.@eac&(EAJL_UPPER|EAJL_BABY) || roclass(.@eac|EAJL_UPPER) == -1) {
			mes "No more jobs are available.";
			close;
		}
	if ((.@eac&EAJ_BASEMASK) == EAJ_NOVICE) {
		if (JobLevel < .jobchange_first) {
			mes "A job level of "+.jobchange_first+" is required to change into the 1st Class.";
		} else if (Class == Job_Novice_High && .linear_jobchange && lastJob) {
			mes "Switch classes now?";
			next;
			Job_Menu(roclass((eaclass(lastJob)&EAJ_BASEMASK)|EAJL_UPPER));
		} else if (Class == Job_Novice) {
			Job_Menu(Job_Swordman, Job_Mage, Job_Archer, Job_Acolyte, Job_Merchant, Job_Thief,
			         Job_SuperNovice, Job_Taekwon, Job_Gunslinger, Job_Ninja);
		} else if (Class == Job_Novice_High) {
			Job_Menu(Job_Swordman_High, Job_Mage_High, Job_Archer_High, Job_Acolyte_High, Job_Merchant_High, Job_Thief_High);
		} else if (Class == Job_Baby) {
			Job_Menu(Job_Baby_Swordman, Job_Baby_Mage, Job_Baby_Archer, Job_Baby_Acolyte, Job_Baby_Merchant, Job_Baby_Thief,
			         Job_Super_Baby);
		} else {
			mes "An error has occurred.";
		}
		close;
	}
	if (roclass(.@eac|EAJL_2_1) == -1 || roclass(.@eac|EAJL_2_2) == -1) {
		mes "No more jobs are available.";
	} else if (!(.@eac&EAJL_2) && JobLevel < .jobchange_second) {
		mes "A job level of "+.jobchange_second+" is required to change into the 2nd Class.";
	} else if (.linear_jobchange && lastJob && (.@eac&EAJL_UPPER)) {
		mes "Switch classes now?";
		next;
		Job_Menu(lastJob+Job_Novice_High);
	} else {
		Job_Menu(.@job1, .@job2);
	}
	close;

function Job_Menu {
	while (true) {
		if (getargcount() > 1) {
			mes "Select a job.";
			.@menu$ = "";
			for (.@i = 0; .@i < getargcount(); ++.@i)
				.@menu$ += " ~ "+jobname(getarg(.@i))+":";
			.@menu$ += " ~ ^777777Cancel^000000";
			next;
			.@newjob = getarg(select(.@menu$)-1, 0);
			if (!.@newjob) close;
			if ((.@newjob == Job_SuperNovice || .@newjob == Job_Super_Baby) && BaseLevel < .supernovice_level) {
				mes "[Job Master]";
				mes "A base level of "+.supernovice_level+" is required to turn into a "+jobname(.@newjob)+".";
				close;
			}
			mes "[Job Master]";
			mes "Are you sure?";
			next;
		} else {
			.@newjob = getarg(0);
			if (.@newjob == Job_Novice_High && !rebirth_paid ){
				if(countitem(30010) > 0){
					mes "[Job Master]";
					mes "Very Excited? You have not opened your "+getitemname(30010)+"! You may not be able to open it after your rebirth.";
					close;
				}
				mes "[Job Master]";
				mes "The suggested";
				mes "donation amount for rebirth is";
				mes "1,285,000 zeny.";
				next;
				if (select("Donate.", "Cancel.") == 2) {
					mes "[Job Master]";
					mes "Unfortunately, you don't seem to possess enough zeny at the moment. Please check your funds and come back again.";
					close;
				}
				if (Zeny >= 1285000) {
					Zeny -= 1285000;
					rebirth_paid = 1;
					mes "[Job Master]";
					mes "Thank you, your donation will be used for a good cause. You may";
					mes "now go in and read the book.";
					next;
				} else {
					mes "[Job Master]";
					mes "Sorry, you don't have enough zeny.";
					close;
				}
			}
		}
		if (select(" ~ Change into ^0055FF"+ jobname(.@newjob) +"^000000 class", " ~ ^777777"+(getargcount() > 1 ? "Go back": "Cancel")+"^000000") == 1) {
			mes "[Job Master]";
			mes "You are now "+A_An(jobname(.@newjob))+"!";
			if (.@newjob == Job_Novice_High && .linear_jobchange)
				lastJob = Class; // Note: This is incompatible with the Valkyrie rebirth script.
			jobchange .@newjob;
			if (.@newjob == Job_Novice_High)
				resetlvl(1);
			if (.@newjob == Job_Baby) {
				resetlvl(4);
				SkillPoint = 0;
			}
			specialeffect(EF_ANGEL2, AREA, playerattached());
			specialeffect(EF_ELECTRIC, AREA, playerattached());
			if (.platinum)
				callsub Get_Platinum;
			callsub Get_Weapon,.@newjob;
			close;
		}
		if (getargcount() == 1)
			return;
		mes "[Job Master]";
	}
	end;
}

function A_An {
	setarray .@vowels$, "a", "e", "i", "o", "u";
	.@firstletter$ = strtolower(charat(getarg(0), 0));
	for (.@i = 0; .@i < getarraysize(.@vowels); ++.@i) {
		if (.@vowels$[.@i] == .@firstletter$)
			return "an "+getarg(0);
	}
	return "a "+getarg(0);
}

Get_Weapon:
	next;
	if (getarg(0) == Job_Knight) {
		mes "[Job Master]";
		mes "Oh...";
		mes "We have prepared a small gift to congratulate you on your job change. Please use it when you are in battle as you honorably protect others.";
		getitem Awakening_Potion,7;
	} else if (getarg(0) == Job_Priest) {
		if(JobLevel < 50) {
			mes "[Job Master]";
			mes "This book is for you. I hope it will aid you in spreading God's message on earth.";
			getitem Book,1;
		} else {
			mes "In commemoration of your job change, I am giving you a bible. This will lighten your way to the path of righteousness.";
			getitem Bible,1; 
		}
	} else if (getarg(0) == Job_Wizard) {
		mes "[Job Master]";
		mes "Here you go. I hope you'll make good use of it when you need it. ~tehehe";
		mes "I gave them to you as a present, so don't go out and sell it. Use it for yourself, ok?";
		getitem Blue_Potion,6;
	} else if (getarg(0) == Job_Blacksmith) {
		mes "[Job Master]";
		mes "Here is a little";
		mes "gift to mark the";
		mes "beginning of your";
		mes "life as a Blacksmith.";
		mes "Congratulations!!!";
		if(JobLevel < 50)
			getitem Steel,5;
		else 
			getitem Steel,30;
	} else if (getarg(0) == Job_Hunter) {
		mes "[Job Master]";
		mes "And also, here is a little reward for all the effort you put in. It's from me, of course~";
		if(JobLevel < 50){ 
			getitem CrossBow,1; 
		} else {
			 getitem Hunter_Bow,1; 
		}
	} else if (getarg(0) == Job_Assassin) {
		mes "[Job Master]";
		mes "Well, I've said too much. Please choose a weapon as a present.";
		next;
		mes "[Job Master]";
		mes "You can choose a Jur, Katar, Main Gauche, or a Gladius. As a master, I love them all.";
		next;
		switch(select("Jur", "Katar", "Main Gauche", "Gladius")) {
		case 1:
			mes "[Job Master]";
			mes "A Jur...";
			mes "Good choice. There you are. I hope it will serve you well.";
			getitem Jur_,1;
			break;
		case 2:
			mes "[Job Master]";
			mes "A Katar...";
			mes "Here you are.";
			mes "Although it's used,";
			mes "I know it will";
			mes "serve you well.";
			getitem Katar_,1;
			break;
		case 3:
			mes "[Job Master]";
			mes "I see. You want to use both hands. Here, take your Main Gauche.";
			getitem Main_Gauche_,1;
			break;
		case 4:
			mes "[Job Master]";
			mes "A Gladius...";
			mes "It used to rule over the Assassin weapon market. Please take care of my gladius.";
			getitem Gladius_,1;
		}
	} else if (getarg(0) == Job_Crusader) {
		mes "[Job Master]";
		mes "And use this in times of dire peril. It will give you strength when your wounds are most grievous.";
		if(JobLevel < 50){ 
			getitem 504, 6;
		} else {
			getitem 504, 12;
		}
	} else if (getarg(0) == Job_Monk) {
		mes "[Job Master]";
		mes "Now...you may leave where the wind may take you.";
		mes "Oh and I have a gift for you before you leave.";
		if(JobLevel < 50){ 
			getitem Waghnakh,1;
		} else {
			getitem Knuckle_Duster_,1;
		}
	} else if (getarg(0) == Job_Sage) {

	} else if (getarg(0) == Job_Rogue) {
		mes "[Job Master]";
		mes "Enjoy your freedom as a Rogue. Just remember that you gotta be free and responsible at the same time. So treat other guys the way you wanna be treated, kay? Alright, seeya round.";
		if(JobLevel < 50){ 
			getitem Gladius,1;
		} else {
			getitem Gladius_,1;
		}
	} else if (getarg(0) == Job_Alchemist) {

		if(JobLevel < 50){ 
			mes "[Job Master]";
			mes "And...";
			mes "Here's a little\r"
				"something to help\r"
				"you begin your\r"
				"research.";
			switch(rand(1,6)) {
			case 1:
				getitem Alcol_Create_Book,1;
				break;
			case 2:
				getitem FireBottle_Create_Book,1;
				break;
			case 3:
				getitem Acid_Create_Book,1;
				break;
			case 4:
				getitem Plant_Create_Book,1;
				break;
			case 5:
				getitem Mine_Create_Book,1;
				break;
			case 6:
				getitem Normal_Potion_Book,1;
			}
		} else {
			mes "[Job Master]";
			mes "Let me give you\r"
				"something special.";
			mes "You can use this to"
				"begin your life"
				"of research.";
			getitem Slim_Potion_Create_Book,1;
		}
	} else if (getarg(0) == Job_Bard) {
		mes "[Job Master]";
		mes "^3355FFScrape Scrape Tang Tang^000000";
		mes "^3355FFSqueak Squeak Scratch Scratch^000000";
		if(JobLevel < 50){
			getitem 1901,1;
		} else {
			getitem 1910,1;
		}
	} else if (getarg(0) == Job_Dancer) {
		mes "[Job Master]";
		mes "Here's a small";
		mes "gift from me.";
		mes "Please take it.";
		mes "May your performances always bring joy to your audience~";
		if(JobLevel < 50){ 
			getitem Rope,1;
		} else {
			getitem Line_,1;
		}
	} else if (getarg(0) == Job_Gunslinger) {
		mes "[Job Master]";
		mes "In any case, it's always";
		mes "a pleasure for me to talk";
		mes "to another Gunslinger, so";
		mes "let's keep in touch. May the";
		mes "power of the earth protect";
		mes "you in all of your adventures~";
		if (rand(1,2) == 1) {
			getitem Six_Shooter,1; // Six_Shooter
		} else {
			getitem Branch,1; // Branch
		}
	} else if (getarg(0) == Job_Ninja) {
		mes "[Job Master]";
		mes "As of today, you are";
		mes "now a proud member of the";
		mes "Touga Ninja Corps. Be as";
		mes "agile as the wind, and as";
		mes "quiet as the falling shadows.";
		getitem Asura,1;
	} else if (getarg(0) == Job_Taekwon) {
		mes "[Job Master]";
		mes "You are still young, so";
		mes "I assume you'll want a job";
		mes "title. Mm. In that case, you";
		if (Sex == SEX_FEMALE)
			mes "are now a ^FF0000Taekwon Girl^000000.";
		else
			mes "are now a ^FF0000Taekwon Boy^000000.";
		mes "Yes, that sounds good. ";
		getitem Guard,1; // Guard[0]

	}
	close2;
	return;


Get_Platinum:
	skill NV_FIRSTAID, 1, 0;
	if (BaseClass == Job_Novice) {
		if (Class != Job_SuperNovice)
			skill NV_TRICKDEAD, 1, 0;
	} else if (BaseClass == Job_Swordman) {
		skill SM_MOVINGRECOVERY, 1, 0;
		skill SM_FATALBLOW, 1, 0;
		skill SM_AUTOBERSERK, 1, 0;
	} else if (BaseClass == Job_Mage) {
		skill MG_ENERGYCOAT, 1, 0;
	} else if (BaseClass == Job_Archer) {
		skill AC_MAKINGARROW, 1, 0;
		skill AC_CHARGEARROW, 1, 0;
	} else if (BaseClass == Job_Acolyte) {
		skill AL_HOLYLIGHT, 1, 0;
	} else if (BaseClass == Job_Merchant) {
		skill MC_CARTREVOLUTION, 1, 0;
		skill MC_CHANGECART, 1, 0;
		skill MC_LOUD, 1, 0;
	} else if (BaseClass == Job_Thief) {
		skill TF_SPRINKLESAND, 1, 0;
		skill TF_BACKSLIDING, 1, 0;
		skill TF_PICKSTONE, 1, 0;
		skill TF_THROWSTONE, 1, 0;
	}

	if (BaseJob == Job_Knight) {
		skill KN_CHARGEATK, 1, 0;
	} else if (BaseJob == Job_Priest) {
		skill PR_REDEMPTIO, 1, 0;
	} else if (BaseJob == Job_Wizard) {
		skill WZ_SIGHTBLASTER, 1, 0;
	} else if (BaseJob == Job_Blacksmith) {
		skill BS_UNFAIRLYTRICK, 1, 0;
		skill BS_GREED, 1, 0;
	} else if (BaseJob == Job_Hunter) {
		skill HT_PHANTASMIC, 1, 0;
	} else if (BaseJob == Job_Assassin) {
		skill AS_SONICACCEL, 1, 0;
		skill AS_VENOMKNIFE, 1, 0;
	} else if (BaseJob == Job_Crusader) {
		skill CR_SHRINK, 1, 0;
	} else if (BaseJob == Job_Monk) {
		skill MO_KITRANSLATION, 1, 0;
		skill MO_BALKYOUNG, 1, 0;
	} else if (BaseJob == Job_Sage) {
		skill SA_CREATECON, 1, 0;
		skill SA_ELEMENTWATER, 1, 0;
		skill SA_ELEMENTGROUND, 1, 0;
		skill SA_ELEMENTFIRE, 1, 0;
		skill SA_ELEMENTWIND, 1, 0;
	} else if (BaseJob == Job_Rogue) {
		skill RG_CLOSECONFINE, 1, 0;
	} else if (BaseJob == Job_Alchemist) {
		skill AM_BIOETHICS, 1, 0;
	} else if (BaseJob == Job_Bard) {
		skill BA_PANGVOICE, 1, 0;
	} else if (BaseJob == Job_Dancer) {
		skill DC_WINKCHARM, 1, 0;
	}
	return;

OnInit:
	.rebirth_blevel = 99;    // Minimum base level to reborn OR change to third class
	.rebirth_jlevel = 50;    // Minimum base job level to reborn OR change to third class
	.jobchange_first = 10;   // Minimum job level to turn into 1st class
	.jobchange_second = 40;  // Minimum job level to turn into 2nd class
	.third_classes = 0;      // Enable third classes/Extended Classes? (1: yes / 0: no)
	.supernovice_level = 45; // Minimum base level to turn into Super Novice
	.linear_jobchange = 1;   // Enforce linear class changes? (1: yes / 0: no)
	.skill_point_check = 1;  // Force player to use up all skill points? (1: yes / 0: no)
	.platinum = 1;           // Get platinum skills automatically? (1: yes / 0: no)
	end;
}
