summaryrefslogtreecommitdiff
path: root/npc/items/master_skillbook.txt
blob: 007125cc82d4079e8fa29f3d629ab229a3e6d8ff (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
// The Mana World script.
// Author:
//    Jesusalva
//    Elvano
// Description:
//    Contains master skills which can only be learnt after killing boss
//    See also: https://forums.themanaworld.org/viewtopic.php?f=2&t=19918
// 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.
//    TODO: Skill level up
//    TODO: Use the data supplied by magic.txt

-	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));
        mesc l("Skill Available: %s", getskillname(@mb_SkillId));
        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);
    .distance = 1;
    end;

OnUnset:
    @mb_BossId=0;
    @mb_SkillId=0;
    @mb_ItemId=0;
    @mb_ItemAm=0;
    end;
}

// Script Helper
// BossSlain(npcname, "variable")
function	script	BossSlain	{
    .@n$=getarg(0);
    // Error
    if (!playerattached())
        return;
    // Only the party which defeated the boss can learn the skill
    getmapxy(.@m$, .@x, .@y, 0);
    .@party=getcharid(1);
    if (.@party > 0)
    {
        setd(getarg(1), .@party);
        areatimer(.@m$, .@x-15, .@y-15, .@x+15, .@y+15, 10, .@n$+"::OnBossCheck");
        mapannounce .@m$, "Boss deafeated by Party: " + getpartyname(.@party), bc_all;
    }
    else
    {
        setd(getarg(1), -2);
        areatimer(.@m$, .@x-15, .@y-15, .@x+15, .@y+15, 10, .@n$+"::OnBossCheck");
        addtimer(20, .@n$+"::OnBegin");
        mapannounce .@m$, "Boss deafeated by: " + strcharinfo(0), bc_all;
    }
    return;
}