summaryrefslogtreecommitdiff
path: root/npc/config/magic.txt
blob: c4f4e2912456fd20f81ce5883bbf9f106a77f45b (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
// TMW2 script
// Author: Jesusalva <admin@tmw2.org>
//
// Magic Script Core Functions
//
// Used for our pseudo-magic.
// These are only helpers, you can add more restrictions and effects freely.
// Important Variables:
//  MAGIC_EXP
//      Current mana magic experience
//  LAST_SKILL
//      Last Mana Skill used
//  MAGIC_LVL
//      Maximum tier of usable magic, capped by Mana Stone
//  MAGIC_SUBCLASS
//      Bitmasked magic subclass.

// AdjustSpellpower(power=100, {target=@skillTarget{, type=HARM_MAGI}})
function	script	AdjustSpellpower	{
    .@power=getarg(0, 100);
    .@target=getarg(1, @skillTarget);
    .@type=getarg(2, HARM_MAGI);
    .@src=getcharid(3);

    .@dmg=calcdmg(.@src, .@target, .@type);
    // Abizit Influence (80%~130% at best, worst shot at perfect ctrl is 105%)
    .@dmg = .@dmg * (80 + abizit() * rand2(5,10)) / 100;
    .@dmg = .@dmg * .@power / 100;
    return .@dmg;
}

// An alias for simplification
// AdjustAttackpower(power=100, {target=@skillTarget{, type=HARM_PHYS}})
function	script	AdjustAttackpower	{
    .@power=getarg(0, 100);
    .@target=getarg(1, @skillTarget);
    .@type=getarg(2, HARM_PHYS);
    return AdjustSpellpower(.@power, .@target, .@type);
}

// SkillID, EXP Points
function	script	GetManaExp	{
    .@sk=getarg(0);
    .@pt=getarg(1);
    .@bonus=rand(0,getskilllv(TMW2_SAGE)*3/2);
    if (LAST_SKILL == .@sk) {
        .@pt=limit(0, (.@pt+.@bonus)/3, 1);
        .@bonus=0;
    }
    LAST_SKILL=.@sk;
    MAGIC_EXP=MAGIC_EXP+.@pt+.@bonus;
    return;
}

// SkillID, Mana{, MP per level}
function	script	MagicCheck	{
    // PRE EXECUTION
    // Load Variables
    .@sk=getarg(0);
    .@mp=getarg(1);
    .@amp=getarg(2,0);

    // Check Skill
    if (getskilllv(.@sk) < 1)
        return 0;

    // Load mana cost
    .@mp=.@mp+getskilllv(.@sk)*.@amp-.@amp;

    // Check mana
    if (readparam(Sp) < .@mp) {
        dispbottom l("Insufficient mana: @@/@@.", readparam(Sp), .@mp);
        return 0;
    }

    // Apply mana cost
    heal 0, 0-.@mp;

    return 1;
}

// SkillID, MobID{, SkillLevelPerMob=2{, Level Override}}
function	script	SummonMagic	{
    .@sk=getarg(0);
    .@id=getarg(1);
    .@adj=getarg(2,2);
    .@lv=getarg(3,getskilllv(.@sk));

    if (.@adj < 1) {
        debugmes "\033[31mInvalid MobPerSkillLevel for SummonMagic (.@adj): "+.@adj+"\033[0m";
        dispbottom l("Invalid parameter specified, blame saulc.");
        end;
    }

    // Cause effect
    // Summoned monsters live from 45 to 60 seconds, and each skill levels grants 10s extra life
    // The 35~50 is not a defect, remember skill starts at level 1...
    // PS. Abizit gives 3s per level, and +1 HP per level
    for (.@i = 0; .@i < (.@lv+(.@adj-1))/.@adj; .@i++) {
        .@lifetime=rand(35,50)+.@lv*10;
        // Abizit makes lifetime vary (like AdjustSpellpower)
        .@lifetime = .@lifetime * (80 + abizit() * rand2(5,10)) / 100;
    	.@mids=summon("Summoned Monster", .@id, .@lifetime);
        .@bhp=getunitdata(.@mids, UDT_MAXHP);
        .@lvx=max(0, (.@lv-1)*.@bhp/50);
        // Abizit makes bonus HP vary (like AdjustSpellpower)
        .@lvx = .@lvx * (80 + abizit() * rand2(5,10)) / 100;
        setunitdata(.@mids, UDT_MAXHP,    .@bhp+.@lvx);
        setunitdata(.@mids, UDT_HP,       .@bhp+.@lvx);
    }
    dispbottom l("All monsters summoned!");
    return;
}

// mescordialog(text, color, {dialog=1})
function	script	mescordialog	{
    if (getarg(2, true))
        mesc getarg(0), getarg(1);
    else
        dispbottom col(getarg(0), getarg(1));
    return;
}

// ShowAbizit({dialog=1})
function	script	ShowAbizit	{
    .@dial=getarg(0, true);
    if (.@dial)
        mesn l("Current Magic Control");

    .@val=MAGIC_EXP+rand(-MAGIC_LVL*5, MAGIC_LVL*5);
    .@base=((MAGIC_LVL*2)**3);
    if (.@val > .@base*5)
        mescordialog l("You are perfectly in control of your magic."), 3, .@dial;
    else if (.@val > .@base*4)
        mescordialog l("You are mostly in control of your magic."), 2, .@dial;
    else if (.@val > .@base*3)
        mescordialog l("You are somewhat in control of your magic."), 4, .@dial;
    else if (.@val > .@base*2)
        mescordialog l("Your magic is more powerful than you, but you can control."), 7, .@dial;
    else if (.@val > .@base)
        mescordialog l("You still are overwhelmed by your magic."), 6, .@dial;
    else
        mescordialog l("You are completly overwhelmed by your magic."), 1, .@dial;
    return;
}

// SK_summon(ID, amount, mexp)
function	script	SK_summon	{
    .@mob=getarg(0);
    .@amt=getarg(1);
    .@mex=getarg(2);
    if ($@GM_OVERRIDE || debug) debugmes "Skill "+@skillId+" Lv "+@skillLv;

    if (rand2(5) < abizit()) {
        // Summon Magic (with magic level bonus)
        SummonMagic(@skillId, .@mob, .@amt, MAGIC_LVL+@skillLv-1, @skillLv);
    } else {
        dispbottom l("The spell fails!");
    }

    // Get a single mana experience point (this is NOT used by Mana Stone)
    GetManaExp(@sk, .@mex);
    return;
}

/////////////////////////////////////////
// RegisterMagic(MSP, Skill, MaxLv, Item, Amount, Cost, {PreReq, PostReq})
function	script	RegisterMagic	{
    .@msp=getarg(0);
    .@ski=getarg(1);
    .@max=getarg(2);
    .@ite=getarg(3);
    .@amo=getarg(4);
    .@cos=getarg(5);
    .@pre=getarg(6, false);
    .@pos=getarg(7, false);

    $@MSK_MSPCOST[.@ski]=.@msp;
    $@MSK_MAXLV[.@ski]=.@max;

    $@MSK_ITEM[.@ski]=.@ite;
    $@MSK_AMOUNT[.@ski]=.@amo;
    $@MSK_COST[.@ski]=.@cos;

    $@MSK_PREREQ[.@ski]=.@pre;
    $@MSK_POSTREQ[.@ski]=.@pos;
    return;
}

-	script	Magic Load	NPC_HIDDEN,{
OnInit:
    /* RegisterMagic(MSP, Skill, MaxLv, Item, Amount, Cost, {PreReq, PostReq}) */


    //////////////////////// Scholarship
    // Last Standing Man
    RegisterMagic(3, CR_TRUST, 2, SpellBookPage, 1, 0);

    //////////////////////// Physical Sciences
    // Falkon Punch
    RegisterMagic(1, SM_BASH, 10, FluoPowder, 3, 0, false, MC_MAMMONITE);
    // Supreme Attack
    RegisterMagic(1, MC_MAMMONITE, 10, FluoPowder, 3, 0, SM_BASH, KN_AUTOCOUNTER);
    // Counter Attack
    RegisterMagic(2, KN_AUTOCOUNTER, 5, FluoPowder, 3, 0, MC_MAMMONITE, false);

    //////////////////////// Destructive Magic
    //////////////////////// Trickmaster
    //////////////////////// Other: Summonning
    //////////////////////// Other: Misc
    // Chargd Shot
    RegisterMagic(0, AC_CHARGEARROW, 1, NPCEyes, 1, 0);

    end;
}