summaryrefslogtreecommitdiff
path: root/npc/items/master_skillbook.txt
blob: e00a1abca4cae0b1d3ec52dc307220e74b68bd3f (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
// Evol script.
// Author:
//    Jesusalva
//    Elvano
// Description:
//    Contains master skills which can only be learnt after killing boss
//    See also: <link to tmw forum topic>
// Notes:
//    Not exactly as Elvano proposal. I actually care for restrictions you know...
// Variables:
//  PERMANENT:
//      MASTERBOOK_PAGES - How many pages your Master Book have.
//                         Defaults to zero, so you can't @item it.
//      MASTERBOOK_SKILL - An array with the skills you have learnt from Master Book.
//                       - It's more flexible this way.
//  TEMPORARY:
//      @mb_BossId  - Contains the MobID of the boss your party killed.
//      @mb_SkillId - Contains the SkillID which can be learnt with the boss.
//      @mb_ItemId  - Contains the Feather Id to write (or whatever)
//      @mb_ItemAm  - How many ink is required to write the skill
//  Remember: @mb_BossId will be reset to zero after 15 seconds from boss death.
//  Or upon logout. Or when changing maps. Temporary variables aren't reliable.
//
//  @mb_BossId controls if you'll try to LEARN a skill, or READ the book.
//  Remember: A dialog prevents timer events from happening, but doesn't stops the timer.
//    TODO: Currently no way to get skill name from database (add getskillinfo() to server-plugin please)
//    TODO: Reset @mb_* when register_skill() finish
//    TODO: You cannot get Magic Feather anywhere in the game (yet)
//    TODO: See if the time (15s) is enough.

-	script	#MasterBook	NPC_HIDDEN,{


    function register_skill {

        setnpcdialogtitle l(.book_name$);

        // If boss is set, but is negative, this means somebody else defeated it
        if (@mb_BossId < 0)
        {
            mesc l("You did not defeat the boss, you can't learn any skills.");
            @mb_BossId=0;
            close;
        }

        // Report the boss you killed, and the boss level
        .@mb_lvl=strmobinfo(3, @mb_BossId);
        mesc l("You just defeated the following boss: @@ (Lv. @@)", strmobinfo(1, @mb_BossId), .@mb_lvl);

        // The boss must have a skill
        if (!@mb_SkillId)
        {
            mesc l("But there is no skill to be learnt from this boss.");
            @mb_BossId=0;
            close;
        }
        // You must have free pages
        if (array_entries(MASTERBOOK_SKILL) >= MASTERBOOK_PAGES)
        {
            mesc l("But you ran out of empty pages on this book.");
            @mb_BossId=0;
            close;
        }
        // TODO: Party Level Range
        // You must be at most 30 levels below the monster level
        if (BaseLevel+30 < .@mb_lvl)
        {
            mesc l("But you are out of the boss level range.");
            @mb_BossId=0;
            close;
        }
        // You must have enough materials
        if (countitem(@mb_ItemId) < @mb_ItemAm)
        {
            mesc l("But you do not have enough Magic Ink. (You need: @@ @@)", @mb_ItemAm, getitemlink(@mb_ItemId));
            //@mb_BossId=0;
            close;
        }

        // Allow you to check which skills are here to learn
        mes "";
        mesc l("You have: @@/@@ @@", countitem(@mb_ItemId), @mb_ItemAm, getitemlink(@mb_ItemId));
        select
            rif(!getskilllv(@mb_SkillId), l("Learn Skill")),
            l("Do not learn");
        mes "";
        if (@menu == 1)
        {
            delitem @mb_ItemId, @mb_ItemAm;
            skill(@mb_SkillId, 1, 0);
            array_push(MASTERBOOK_SKILL, @mb_SkillId);
            closeclientdialog;
            dispbottom l("You have learnt the skill.");
        }
        @mb_BossId=0;
        close;
    }


    function read_book {

        setnpcdialogtitle l(.book_name$);
        mesc l("@@/@@ pages used.", array_entries(MASTERBOOK_SKILL), MASTERBOOK_PAGES);

        mesc l("List of known master skills:");
        mes "";
        for (.@i = 0; .@i < getarraysize(MASTERBOOK_SKILL); ++.@i) {
            mesc l("* Skill ID: @@", MASTERBOOK_SKILL[.@i]);
        }
        close;
    }

OnUse:
    // We assume if @mb_BossId is set, everything else is set, too
    if (@mb_BossId)
        register_skill;
    if (openbook())
        read_book;
    closeclientdialog();
    close;

OnInit:
    .book_name$ = getitemname(MasterBook);
    .sex = G_OTHER;
    .distance = 1;
    end;
}