summaryrefslogtreecommitdiff
path: root/npc/custom/eAAC_Scripts/kafraExpress/ke_jobchange.txt
blob: b7c9a7c6c604875b05c12199d91e3cfd111356e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
//===== eAthena Script =======================================
//= Kafra Express - Job Changing Module
//===== By: ==================================================
//= Skotlex
//===== Current Version: =====================================
//= 3.5
//===== Compatible With: =====================================
//= eAthena SVN R3579+
//===== Description: =========================================
//= Part of the Kafra Express Script Package.
//= Enables job changing through the class trees.
//= Novice -> 1st Class, 1st Class -> 2nd Class, rebirths, etc
//===== Additional Comments: =================================
//= See config.txt for configuration.
//= When using Upper Job policy, previous jobs are stored in
//= the server wide variables kej_class1 and kej_class2
//============================================================

-	script	keInit_jobchange	-1,{
OnInit:	//Load Config
	donpcevent "keConfig::OnLoadJobChange";
	end;
}

function	script	F_keJobChange	{
	
	function SF_to1stJob;
	function SF_to2ndJob;
	function SF_getJobNames;
	function SF_testChangeJob;
	function SF_changeJob;
	
	set @job, callfunc("GF_getJobLevel", class);
	set @upper, Upper; //Because it is changed when rebirthing
	set @reset, 0;	//Base Level is reset only on rebirths
	switch (@job) {
	case 0: //Novices
		if ($@kejc_skipNovice)
			set @jobLv, 0; //jobLv is used again when checking for S.Novice's base level restriction.
		else
			set @jobLv, 10;
		if (SF_testChangeJob(0,0,@jobLv))
			SF_to1stJob(0);
		break;
	case 1: //First Classes
		if (SF_testChangeJob($@kejc_cost2ND,$@kejc_base2ND,$@kejc_job2ND))
			SF_to2ndJob();
		break;
	case 2: //Second Classes
		if (Upper == 0 && BaseClass != Job_Taekwon) {
			if (SF_testChangeJob($@kejc_costRebirth,$@kejc_baseRebirth,$@kejc_jobRebirth)) {
				set @upper, 1;
				if ($@kejc_skipNovice)
					SF_to1stJob(1);
				else
					SF_changeJob @job,Upper,Job_Novice,1,0,0,$@kejc_costRebirth,1,$@kejc_rebirthReset;
			}
			break;
		}
	default:	//Dead End
		callfunc "F_keIntro", e_swt2, "I cannot change you from your current job.";
		break;
	}
	return;

//Handles changing to 1st job.
function SF_to1stJob {
	do {
		set @submenu, 1;	
		if (@upper == 1 && $@kejc_upperPolicy && kej_class1) {
			switch (kej_class1) {
			case Job_Acolyte:
				set @submenu, 2;
				break;
			case Job_Archer:
				set @submenu, 3;
				break;
			case Job_Mage:
				set @submenu, 4;
				break;
			case Job_Merchant:
				set @submenu, 5;
				break;
			case Job_Swordman:
				set @submenu, 6;
				break;
			case Job_Thief:
				set @submenu, 7;
				break;
			case Job_Taekwon:
				set @submenu, 8;
				break;
			}
		}
		if (@submenu == 1) {
			SF_getJobNames 8,Job_Acolyte,Job_Archer,Job_Mage,Job_Merchant,Job_Swordman,Job_Thief,Job_Taekwon,Job_SuperNovice;
			switch (@upper) {
			case 0: //All
				set @submenu, select(
					"- Cancel job change",
					"- "+@name1$,
					"- "+@name2$,
					"- "+@name3$,
					"- "+@name4$,
					"- "+@name5$,
					"- "+@name6$,
					"- "+@name7$,
					"- "+@name8$
				);
				break;
			case 1: //No Taekwon/S.Novice
				set @submenu, select(
					"- Cancel job change",
					"- "+@name1$,
					"- "+@name2$,
					"- "+@name3$,
					"- "+@name4$,
					"- "+@name5$,
					"- "+@name6$
				);
				break;
			case 2: //No Taekwon
				set @submenu, select(
					"- Cancel job change",
					"- "+@name1$,
					"- "+@name2$,
					"- "+@name3$,
					"- "+@name4$,
					"- "+@name5$,
					"- "+@name6$,
					"- "+@name8$
				);
				if (@submenu == 8)
					set @submenu, 9;
				break;
			}
		}
		switch (@submenu) {
		case 2: //Acolyte
			set @newJob,Job_Acolyte;
			set @weapon, $@kejc_wAcolyte;
			break;
		case 3: //Archer
			set @newJob,Job_Archer;
			set @weapon, $@kejc_wArcher;
			break;
		case 4: //Mage
			set @newJob,Job_Mage;
			set @weapon, $@kejc_wMage;
			break;	
		case 5: //Merchant
			set @newJob,Job_Merchant;
			set @weapon, $@kejc_wMerchant;
			break;
		case 6: //Swordman
			set @newJob,Job_Swordman;
			set @weapon, $@kejc_wSwordman;
			break;
		case 7: //Thief
			set @newJob,Job_Thief;
			set @weapon, $@kejc_wThief;
			break;
		case 8: //Taekwon
			set @newJob,Job_Taekwon;
			set @weapon, $@kejc_wTaekwon;
			break;
		case 9: //S. Novice
			set @newJob,Job_SuperNovice;
			set @weapon, $@kejc_wSuperNovice;
			if (SF_testChangeJob(0,$@kejc_baseSN,@jobLv) == 0)
				return;
			break;
		}
		if (@submenu > 1) {
			if (getarg(0)) { //Skipping High Novice, charge rebirth costs.
				if (SF_changeJob(@job,Upper,@newJob,1,@weapon,0,$@kejc_costRebirth,2,$@kejc_rebirthReset))
					return;
			} else {
				if (SF_changeJob(@job,Upper,@newJob,@upper,@weapon,0,0,2,0))
					return;
			}
		}
	} while (@submenu > 1);
}

function SF_to2ndJob {
	do {
		set @submenu, 1;	
		if (@upper == 1 && $@kejc_upperPolicy && kej_class2) {
			switch (kej_class2) {
			case Job_Priest:
			case Job_Hunter:
			case Job_Wizard:
			case Job_Blacksmith:
			case Job_Knight:
			case Job_Knight2:
			case Job_Assassin:
			case Job_Star_Gladiator:
			case Job_Star_Gladiator2:
				set @submenu, 2;
				break;
			case Job_Monk:
			case Job_Bard:
			case Job_Dancer:
			case Job_Sage:
			case Job_Alchem:
			case Job_Crusader:
			case Job_Crusader2:
			case Job_Rogue:
			case Job_Soul_Linker:
				set @submenu, 3;
				break;
			}
		}
		if (@submenu == 1) { //Fetch from menu.
			switch (BaseClass) {
			case Job_Acolyte:
				SF_getJobNames 2,Job_Priest,Job_Monk;
				break;
			case Job_Archer:
				SF_getJobNames 3,Job_Hunter,Job_Bard,Job_Dancer;
				if (sex == 0)
					set @name2$, @name3$;
				break;
			case Job_Mage:
				SF_getJobNames 2,Job_Wizard,Job_Sage;
				break;
			case Job_Merchant:
				SF_getJobNames 2,Job_Blacksmith,Job_Alchem;
				break;
			case Job_Swordman:
				SF_getJobNames 2,Job_Knight,Job_Crusader;
				break;
			case Job_Thief:
				SF_getJobNames 2,Job_Assassin,Job_Rogue;
				break;
			case Job_Taekwon:
				SF_getJobNames 2,Job_Star_Gladiator,Job_Soul_Linker;
				break;
			default:
				callfunc "F_keIntro", e_swt2, "I don't know how to change you from your current job.";
				return;
			}
			set @submenu, select(
				"- Cancel job change",
				"- "+@name1$,
				"- "+@name2$
			);
		}
		switch (BaseClass) {
		case Job_Acolyte:
			switch (@submenu) {
			case 2: //Priest
				set @newJob,Job_Priest;
				set @weapon,$@kejc_wPriest;
				set @weapon2,$@kejc_w2Priest;
				break;
			case 3: //Monk
				set @newJob,Job_Monk;
				set @weapon,$@kejc_wMonk;
				set @weapon2,$@kejc_w2Monk;
				break;
			}
			break;
		case Job_Archer:
			switch (@submenu) {
			case 2: //Hunter
				set @newJob,Job_Hunter;
				set @weapon,$@kejc_wHunter;
				set @weapon2,$@kejc_w2Hunter;
				break;
			case 3: //Bard/Dancer
				if (sex == 1) { //Bard
					set @newJob,Job_Bard;
					set @weapon,$@kejc_wBard;
					set @weapon2,$@kejc_w2Bard;
				} else { //Dancer
					set @newJob,Job_Dancer;
					set @weapon,$@kejc_wDancer;
					set @weapon2,$@kejc_w2Dancer;
				}
				break;
			}
			break;
		case Job_Mage:
			switch (@submenu) {
			case 2: //Wizard
				set @newJob,Job_Wizard;
				set @weapon,$@kejc_wWizard;
				set @weapon2,$@kejc_w2Wizard;
				break;
			case 3: //Sage
				set @newJob,Job_Sage;
				set @weapon,$@kejc_wSage;
				set @weapon2,$@kejc_w2Sage;
				break;
			}
			break;
		case Job_Merchant:
			switch (@submenu) {
			case 2: //Blacksmith
				set @newJob,Job_Blacksmith;
				set @weapon,$@kejc_wBlacksmith;
				set @weapon2,$@kejc_w2Blacksmith;
				break;
			case 3: //Alchemist
				set @newJob,Job_Alchem;
				set @weapon,$@kejc_wAlchemist;
				set @weapon2,$@kejc_w2Alchemist;
				break;
			}
			break;
		case Job_Swordman:
			switch (@submenu) {
			case 2: //Knight
				set @newJob,Job_Knight;
				set @weapon,$@kejc_wKnight;
				set @weapon2,$@kejc_w2Knight;
				break;
			case 3: //Crusader
				set @newJob,Job_Crusader;
				set @weapon,$@kejc_wCrusader;
				set @weapon2,$@kejc_w2Crusader;
				break;
			default:
				mes "uh oh";
				break;
			}
			break;
		case Job_Thief:
			switch (@submenu) {
			case 2: //Assassin
				set @newJob,Job_Assassin;
				set @weapon,$@kejc_wAssassin;
				set @weapon2,$@kejc_w2Assassin;
				break;
			case 3: //Rogue
				set @newJob,Job_Rogue;
				set @weapon,$@kejc_wRogue;
				set @weapon2,$@kejc_w2Rogue;
				break;
			}
			break;
		case Job_Taekwon:
			switch (@submenu) {
			case 2: //Star Gladiator
				set @newJob,Job_Star_Gladiator;
				set @weapon,$@kejc_wStarGladiator;
				set @weapon2,$@kejc_w2StarGladiator;
				break;
			case 3: //Soul Linker
				set @newJob,Job_Soul_Linker;
				set @weapon,$@kejc_wSoulLinker;
				set @weapon2,$@kejc_w2SoulLinker;
				break;
			}
			break;
		}
		if (@submenu > 1) {
			if (SF_changeJob(@job,Upper,@newJob,@upper,@weapon,@weapon2,$@kejc_cost2ND,0,0))
				return;
		}
	} while (@submenu > 1);
}

//SubFunction: SF_testChangeJob(Zeny, BaseLv, JobLv)
//Function that checks if the player qualifies for job changing.
function SF_testChangeJob {
	set @fail, 0;
	if (Zeny < getarg(0))
		set @fail, 1;
	if (BaseLevel < getarg(1))
		set @fail, @fail+2;
	if (JobLevel < getarg(2))
		set @fail, @fail+4;	
	if (@fail > 0) {
		if (@fail&1)
			mes "You need "+getarg(0)+"z for the conversion process.";
		if (@fail&2)
			mes "You need to be at least Lv "+getarg(1)+".";
		if (@fail&4)
			mes "You need at least job Lv "+getarg(2)+".";
		callfunc "F_keIntro", e_pif, "Sorry, you don't qualify for a job change yet.";
		return 0;
	}

	if (SkillPoint > 0 && $@kejc_skillsPolicy == 0) {
		callfunc "F_keIntro", e_dots, "Sorry, use your remaining Skill points before being able to change class.";
		return 0;
	}
	return 1;
}

//SubFunction: SF_changeJob (CurrentJobLv, CurrentJobType, NewJobBase, NewJobType
//Weapon, Weapon2, Zeny, WipeSkills, ResetLv)
//Attempts to change to the Jobgiven.
//CurrentJobLv is 0-3 (novice, 1st class, 2nd class, s.novice)
//Type is 0-2 (Normal, Advanced Class, Baby)
//Weapon is the ID of the weapon to grant
//Weapon2 is the alternative weapon granted when your job level is above $@kejc_wBonusLv
//Zeny is the money required (if negative, it is money awarded)
//WipeSkills if 1, indicates that skills should be wiped,
//if 2, it means basic skills have to be given back
//Reset Level indicates the base lv must be reset to 1.
//Note: Zeny/Base/Job requirements should had been checked with SF_testChangeJob already!
function SF_changeJob {
	set @newjob,getarg(2);
	set @newtype,getarg(3);
	set @weapon,getarg(4);
	set @weapon2,getarg(5);
	set @cost,getarg(6);
	set @wipeSkill,getarg(7);
	set @resetLv,getarg(8);

	set @jobStr$, callfunc("GF_getJobName2",@newjob, @newtype);
	if (@wipeSkill == 0 && SkillPoint > 0 && $@kejc_skillsPolicy == 1) {
		set @selection, select(
			"- Do not change yet",
			"- Change to "+@jobStr$+" (skill points lost)",
			"- View details"
		);
	} else {
		set @selection, select(
			"- Cancel",
			"- Change to "+@jobStr$,
			"- View details"
		);
	}
	switch (@selection) {
		case 3: //Details
			mes "Okay.. listen up:";
			next;
			mes "["+@name$+"]";
			mes "Changing to "+@jobStr$+" now means:";
			if (@wipeSkill == 0 && SkillPoint > 0 && $@kejc_skillsPolicy == 1)
				mes "- You will lose your "+SkillPoint+" unused skill points.";
			else if (@wipeSkill == 1)
				mes "- You will lose all your skills.";
			if (@resetLv)
				mes "- Your base level will be reset to 1.";
			if (@cost > 0)
				mes "- You will be charged "+@cost+"z.";
			else if (@cost < 0)
				mes "- You will be aided with "+(0-@cost)+"z.";
			if (@weapon > 0) {
				if (@weapon2 > 0 && $@kejc_wBonusLv) {
					if (JobLevel < $@kejc_wBonusLv) {
						mes "- You will receive a "+getitemname(@weapon)+"["+getitemslots(@weapon)+"].";
						mes "- If you wait until Job Lv"+$@kejc_wBonusLv+", you can receive instead a "+getitemname(@weapon2)+"["+getitemslots(@weapon)+"].";
					} else {
						mes "- You will receive a "+getitemname(@weapon2)+"["+getitemslots(@weapon)+"] for reaching Job Lv"+$@kejc_wBonusLv+".";
					}
				} else
					mes "- You will receive a "+getitemname(@weapon)+".";
			}
			mes "So... will you change?";
			if (select(
				"- Cancel",
				"- Change to "+@jobStr$
			) != 2) {
				callfunc "F_keIntro", e_dots, "...alright.";
				return 0;
			}
			callfunc "F_keIntro", -1, "Enjoy your new Job.";
		case 2: //Change
			//Set/Unset job path variables as needed.
			if($@kejc_upperPolicy) {
				set @class,getarg(0);
				set @type, getarg(1);
				if(@class == 1 && @type == 0)
					set kej_class1,class; //Advancing to second class, so...
				if(@class == 2)
					set kej_class2,class; //Only way of being here is by doing a rebirth
				if(@type > 0)
					set kej_class1,0;	//Clear when one is a high class
				if(@type > 0 && @class == 1)
					set kej_class2,0;	//Clear when leaving high 1st class
			}
			if (@resetLv) {
				jobchange Job_Novice_High; //Done to give players those 100 points from High classes
				resetlvl(1);
			}
			if (@wipeSkill) {
				resetskill;
				setoption(0);
				set SkillPoint,0;
			} else if ($@kejc_skillsPolicy == 1)
				set SkillPoint,0;
			if (@wipeSkill>1)
				skill 1,9,0;
			if($@kejc_resetDye)
				setlook 7,0;
			jobchange @newjob, @newtype;
			if ($@kejc_announce)
				announce strcharinfo(0)+" has been promoted to "+@jobStr$+"!",8;
			set Zeny,Zeny-@cost;
			if ($@kejc_weaponPolicy && @weapon > 0) {
				if ($@kejc_wBonusLv && @weapon2 > 0) {
					if (JobLevel < $@kejc_wBonusLv)
						getitem @weapon,1;
					else
						getitem @weapon2,1;
				} else
					getitem @weapon,1;
			}
			emotion e_grat;	
			return 1;
		default: //Cancel...
			callfunc "F_keIntro", e_dots, "...alright.";
			return 0;	
	}
}
//SubFunction: SF_getJobNames(Qty, Jobid1, Jobid2,...)
//Workaround until eA gets a fix for the bug where you can't use callfunc or
//callsub within a menu
function SF_getJobNames {
	switch (getarg(0)) {
	case 8:
		set @name8$, callfunc("GF_getJobName2",getarg(8),@upper);
		set @name7$, callfunc("GF_getJobName2",getarg(7),@upper);
		set @name6$, callfunc("GF_getJobName2",getarg(6),@upper);
		set @name5$, callfunc("GF_getJobName2",getarg(5),@upper);
		set @name4$, callfunc("GF_getJobName2",getarg(4),@upper);
	case 3:
		set @name3$, callfunc("GF_getJobName2",getarg(3),@upper);
	case 2:
		set @name2$, callfunc("GF_getJobName2",getarg(2),@upper);
		set @name1$, callfunc("GF_getJobName2",getarg(1),@upper);
	}
	return;
}

}