summaryrefslogblamecommitdiff
path: root/npc/items/master_skillbook.txt
blob: 007125cc82d4079e8fa29f3d629ab229a3e6d8ff (plain) (tree)
1
2
3
4
5
6
7
8
9
                         




                                                                        
                                                                         
         
                                                                                  








                                                                                     
                                                                    







                                                                                                         

                                                                   

                                              







                                            








                                                                                

                                                                                                         
 



                                                                         
                         





                                                                   
                         






                                                                
                         





                                                                                                                   
                           





                                                                                                 
                                                                 











                                                            
                     



























                                                                                       

                  
































                                                                                      
 

 
// 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;
}