root/npc/custom/eAAC_Scripts/kafraExpress/ke_jobswap.txt @ 1

Revision 1, 9.9 kB (checked in by jinshiro, 17 years ago)
RevLine 
[1]1//===== eAthena Script =======================================
2//= Kafra Express - Job Swapping Module
3//===== By: ==================================================
4//= Skotlex
5//===== Current Version: =====================================
6//= 3.8
7//===== Compatible With: =====================================
8//= eAthena SVN8840+
9//===== Description: =========================================
10//= Part of the Kafra Express Script Package.
11//= Enables job changing among classes of the same 'type'
12//= (ie among 1st classes, or among 2nd classes)
13//===== Additional Comments: =================================
14//= See config.txt for configuration.
15//= * The previous Job, when enabled, is stored in:
16//= kej_prev_job (job id)
17//= kej_prev_joblv (job level)
18//= kej_prev_skills (skill count)
19//= kej_prev_dye (cloth dye)
20//============================================================
21
22-       script  keInit_jobSwap  -1,{
23OnInit: //Load Config
24        donpcevent "keConfig::OnLoadJobSwap";
25        end;
26}
27
28function        script  F_keJobSwap     {
29
30function SF_canRevert;
31function SF_canSwitch;
32function SF_revertJob;
33function SF_switch;
34function SF_calcSwapCost;
35function SF_testSwap;
36function SF_swapJob;
37function SF_getJobNames;
38
39        set @thisJob, eaclass(Class);
40        set @type, @thisJob&~EAJ_UPPERMASK;
41        set @prevJob, eaclass(kej_prev_job);
42        set @prevLv, kej_prev_joblv;
43       
44        if (SF_canRevert())
45        {       //Qualifies for Reverting
46                do {
47                        set @revertmenu, select(
48                                "- Return",
49                                "- Return to previous class",
50                                "- Change into another class"
51                        );
52                        switch (@revertmenu) {
53                        case 2: //Revert
54                                if (SF_revertJob())
55                                        return;
56                                break;
57                        case 3: //Switch
58                                if (SF_switch())
59                                        return;
60                                break;
61                        }
62                } while (@revertmenu > 1);
63                return;
64        }
65        if (SF_canSwitch())
66        {
67                SF_switch();
68                return;
69        }
70
71        callfunc "F_keIntro", e_swt2, "There are no available jobs of your level.";
72        return;
73
74//SubFunction SF_canRevert, specifies if the character can revert to previous job.
75function SF_canRevert {
76        if ($@kejs_revertPolicy == 0 || @prevLv == 0 ||
77                (@thisJob&EAJL_BABY != @prevJob&EAJL_BABY))
78                return 0;
79
80        if ($@kejs_revertPolicy == 2)
81                return 1;
82
83        if ((@thisJob&EAJ_BASEMASK) == EAJ_NOVICE)
84        {
85                if ($@kejs_disable&1)
86                        return 0;
87                if (@prevJob&(EAJL_UPPER|EAJL_2))
88                        return 0;
89                return 1;
90        }
91
92        if ((@prevJob&EAJ_BASEMASK) == EAJ_NOVICE)
93        {
94                if ($@kejs_disable&1)
95                        return 0;
96
97                if (@thisJob&(EAJL_UPPER|EAJL_2))
98                        return 0;
99                return 1;
100        }
101       
102        if (@thisJob&~EAJ_UPPERMASK != @prevJob&~EAJ_UPPERMASK)
103                return 0;
104
105        if (@thisJob&EAJL_2 && !(@prevJob&EAJL_2))
106                return 0;
107       
108        if (@prevJob&EAJL_2 && !(@thisJob&EAJL_2))
109                return 0;
110       
111        return 1;
112}
113
114//SubFunction SF_canSwitch, specifies if character can change to another job.
115function SF_canSwitch {
116        switch(@thisJob&EAJ_BASEMASK) {
117                case EAJ_NOVICE:
118                        if ($@kejs_disable&1 || !@thisJob&EAJL_2)
119                                return 0;
120                        break;
121                case EAJ_TAEKWON:
122                        if ($@kejs_disable&2)
123                                return 0;
124                        break;
125                case EAJ_GUNSLINGER:
126                        if ($@kejs_disable&4)
127                                return 0;
128                        break;
129                case EAJ_NINJA:
130                        if ($@kejs_disable&8)
131                                return 0;
132                        break;
133        }
134        return 1;
135}
136
137//Sub Function SF_switch. Presents the switch job menu. Returns 1 only if the
138//menu was left by picking "Cancel".
139function SF_switch {
140        if (@thisJob&EAJL_2 && (@thisJob&EAJ_BASEMASK) != EAJ_NOVICE) {
141        //Second Classes
142                set @cost, SF_calcSwapCost($@kejs_job2ND, $@kejs_cost2ND, $@kejs_discount2ND);
143                set @preserve, $@kejs_preserve2ND;
144                if (!SF_testSwap($@kejs_job2ND, @cost))
145                        return 0;
146               
147                setarray @classes[0],
148                        EAJ_Assassin|@type,
149                        EAJ_Rogue|@type,
150                        EAJ_Blacksmith|@type,
151                        EAJ_Alchemist|@type,
152                        EAJ_Hunter|@type,
153                        EAJ_BardDancer|@type,
154                        EAJ_Knight|@type,
155                        EAJ_Crusader|@type,
156                        EAJ_Priest|@type,
157                        EAJ_Monk|@type,
158                        EAJ_Wizard|@type,
159                        EAJ_Sage|@type,
160                        EAJ_Star_Gladiator|@type,
161                        EAJ_Soul_Linker|@type;
162
163                SF_getJobNames getarraysize(@classes);
164               
165                if (@type || $@kejs_disable&2)
166                {       //No SG/SL
167                        set @names$[12], "";
168                        set @names$[13], "";
169                }
170
171                do {
172                        set @kmenu, select(
173                                "- Cancel job change",
174                                @names$[0], @names$[1], @names$[2], @names$[3],
175                                @names$[4], @names$[5], @names$[6], @names$[7],
176                                @names$[8], @names$[9], @names$[10], @names$[11],
177                                @names$[12], @names$[13]
178                        );
179
180                        if (@kmenu > 1) {
181                                set @job, roclass(@classes[@kmenu-2]);
182                                if (@job > -1 && SF_swapJob(@job,@cost,@preserve))
183                                        return 1;
184                        }
185                } while (@kmenu > 1);
186                return 0;
187        } else {
188        //First Classes
189                set @cost, SF_calcSwapCost($@kejs_job1ST, $@kejs_cost1ST, $@kejs_discount1ST);
190                set @preserve, $@kejs_preserve1ST;
191                if (!SF_testSwap($@kejs_job1ST, @cost))
192                        return 0;
193                setarray @classes[0],
194                        EAJ_Acolyte|@type,
195                        EAJ_Archer|@type,
196                        EAJ_Mage|@type,
197                        EAJ_Merchant|@type,
198                        EAJ_Swordman|@type,
199                        EAJ_Thief|@type,
200                        EAJ_Taekwon|@type,
201                        EAJ_Super_Novice|@type,
202                        EAJ_GunSlinger|@type,
203                        EAJ_Ninja|@type;
204
205                SF_getJobNames getarraysize(@classes);
206
207                if ($@kejs_disable&1 || @type&EAJL_UPPER)
208                        set @names$[7], ""; //No S.Novice
209                if (@type)
210                {       //No TK/NJ/GS for Baby/Advanced
211                        set @names$[6], "";
212                        set @names$[8], "";
213                        set @names$[9], "";
214                } else {
215                        if ($@kejs_disable&2) //No TK
216                                set @names$[6], "";
217                        if ($@kejs_disable&4) //No GS
218                                set @names$[8], "";
219                        if ($@kejs_disable&8) //No NJ
220                                set @names$[9], "";
221                }
222
223                do {
224                        set @kmenu, select(
225                                "- Cancel job swap",
226                                @names$[0], @names$[1], @names$[2],
227                                @names$[3], @names$[4], @names$[5],
228                                @names$[6], @names$[7], @names$[8],
229                                @names$[9]
230                        );
231
232                        if (@kmenu > 1) {
233                                set @job, roclass(@classes[@kmenu-2]);
234                                if (@job > -1 && SF_swapJob(@job,@cost,@preserve))
235                                        return 0;
236                        }
237                } while (@kmenu > 1);
238                return 0;
239        }
240}
241
242//SubFunction: SF_calcSwapCost (MinJob, BaseCost, Discount)
243//Calculates cost to swap jobs
244function SF_calcSwapCost {
245        set @cost, getarg(1);
246        set @cost, @cost - @cost*getarg(2)*(JobLevel-getarg(0))/100;
247        if (@cost < 0)
248                set @cost,0; //Free Change
249        return @cost;
250}
251
252//SubFunction: SF_testSwap(MinJobLv, Cost)
253//Checks if the player qualifies for job changing.
254function SF_testSwap {
255        if (JobLevel < getarg(0)) {
256                callfunc "F_keIntro", e_dots, "You need to be at least Job Lv "+getarg(0)+" before exchanging.";
257                return 0;
258        }
259       
260        set @cost, callfunc("F_keCost",getarg(1),$@kejs_swapDiscount);
261        if (Zeny < @cost) {
262                callfunc "F_keIntro", e_dots, "You need "+@cost+"z to be able to change.";
263                return 0;
264        }
265        return 1;
266}
267
268//SubFunction: SF_swapJob (JobNumber, Zeny, PreserveRate)
269//Attempts to swap to the Jobgiven.
270//Zeny is the money cost
271//Preserve is how much of the previous job to preserve.
272function SF_swapJob {
273        set @newjobId, getarg(0);
274        set @cost, callfunc("F_keCost",getarg(1),$@kejs_swapDiscount);
275        set @preserve, getarg(2);
276
277        if (Class == @newjobId) {
278                callfunc "F_keIntro", e_meh, "Um... you are already that class!";
279                return 0;
280        }
281
282        set @newJob$, jobname(@newjobId);
283        set @oldJob$, jobname(Class);
284        set @newjoblv, JobLevel*@preserve/100;
285       
286        if (@newjoblv > 1) {
287                if (select("- Cancel", "- Change to a Lv"+@newjoblv+" "+@newJob$+" ("+@cost+"z)") != 2)
288                        return 0;
289        } else {
290                set @newjoblv,1;
291                if (select("- Cancel", "- Change to "+@newJob$+" ("+@cost+"z)") != 2)
292                        return 0;
293        }
294
295        set @basic, getSkilllv("NV_BASIC");
296        set @skillpoint, skillpointcount() -JobLevel -@basic +@newjoblv;        //Preserve holds the final amount of SkillPoints you should have.
297
298        if (@skillpoint < 0) {
299                callfunc "F_keIntro", e_gasp, "You need "+(-@skillpoint)+" more skill points to change class!";
300                return 0;
301        }
302
303        set @thisJoblevel, JobLevel;
304        resetSkill;
305
306        //Set previous job as needed.
307        if ($@kejs_revertPolicy) {
308                set kej_prev_job, Class;
309                set kej_prev_joblv, @thisJoblevel;
310                set kej_prev_skills, SkillPoint;
311                if($@kejs_saveDye)
312                        set kej_prev_dye,getlook(7);
313        }
314        if ($@kejs_announce)
315                announce strcharinfo(0)+" has changed from "+@oldJob$+" to "+@newJob$+"...",16;
316               
317        if ($@kejs_resetDye)
318                setlook 7,0;
319        jobchange @newjobId, 0;
320        skill 1,@basic,0;
321        set JobLevel, @newjoblv;
322        set SkillPoint, @skillpoint;
323        setoption(0);
324        sc_end -1;
325        callfunc "F_keCharge",getarg(1),$@kejs_swapDiscount,1;
326       
327        emotion e_ok;   
328        return 1;
329}
330
331//SubFunction: SF_revertJob (cost)
332//Reverts to the previous job.
333function SF_revertJob {
334        if (@thisJob == @prevJob) {
335                callfunc "F_keIntro", e_no, "Hmm... You can't go back, because your previous class is the same as your current one??";
336                return 0;
337        }
338        set @newjob$, jobname(kej_prev_job);
339       
340        set @cost,callfunc("F_keCost",$@kejs_revertCost,$@kejs_revertDiscount);
341
342        if (select("- Cancel","- Return to a Lv"+kej_prev_joblv+" "+@newjob$+" ("+@cost+"z)") != 2)
343                return 0;
344
345        if (!(callfunc("F_keCharge",$@kejs_revertCost,$@kejs_revertDiscount,1))) {
346                callfunc "F_keIntro", -1, "Sorry, you need "+@cost+"z before you can revert to a Lv"+kej_prev_joblv+" "+@newjob$+".";
347                return 0;
348        }
349        set @thisJobId, Class;
350        set @thisJobLv, JobLevel;
351
352        set @basic, getSkilllv("NV_BASIC");
353        resetSkill;
354        set @skill, SkillPoint;
355        if($@kejs_saveDye) {
356                set @prevDye, getlook(7);
357                setlook 7,0;
358        }
359        if ($@kejs_resetDye)
360                setlook 7,0;
361        jobchange kej_prev_job, 0;
362        if($@kejs_saveDye) {
363                setlook 7,kej_prev_dye;
364                set kej_prev_dye,@prevDye;
365        }
366        set JobLevel, kej_prev_joblv;
367        set SkillPoint, kej_prev_skills;
368
369        skill 1, @basic, 0;
370        set SkillPoint, SkillPoint-@basic;
371       
372        set kej_prev_job, @thisJobId;
373        set kej_prev_joblv, @thisJobLv;
374        set kej_prev_skills, @skill;
375        setoption(0);
376        sc_end -1;
377
378        if ($@kejs_announce)
379                announce strcharinfo(0)+" has changed from "+jobname(@thisJobId)+" to "+@newjob$+"...",16;
380        return 1;
381}       
382
383//SubFunction: SF_getJobNames(Qty)
384//Fills an array @names$ with the job names taken from the array "classes",
385// making each entry start with "- " followed by the job name.
386function SF_getJobNames {
387        set @size, getarg(0);
388        for (set @i, 0; @i < @size; set @i, @i+1)
389                setd "@names$["+@i+"]", "- "+jobname(roclass(@classes[@i]));
390}
391
392}
Note: See TracBrowser for help on using the browser.