// TMW2 scripts.
// Authors:
// Jesusalva
// TMW Org.
// Description:
// Core functions (it MUST be loaded first)
// Some setup is required
// Check if you have something to ask to Blue Sage staff
// BSQuestion( )
function script BSQuestion {
.@b1=getq(NivalisQuest_BlueSage);
.@b2=getq2(NivalisQuest_BlueSage);
.@b3=getq3(NivalisQuest_BlueSage);
.@rt=0;
// After you collected everyone's feedback, hide the option
if (is_between(3,8,.@b1)) {
if (.@b3 < BS_NPCALL)
.@rt=.@rt | BS_QHELPER;
}
if (.@b1 == 6) {
if (.@b2 < BS_NPCALL)
.@rt=.@rt | BS_QVISITOR;
}
return .@rt;
}
// Clear a Nest ID
// BSClearNest( ID )
function script BSClearNest {
.@id=getarg(0);
switch (.@id) {
case BS_SNEST1:
$@BS_NEST1=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill1");
break;
case BS_SNEST2:
$@BS_NEST2=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill2");
break;
case BS_SNEST3:
$@BS_NEST3=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill3");
break;
case BS_SNEST4:
$@BS_NEST4=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill4");
break;
case BS_SNEST5:
$@BS_NEST5=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill5");
break;
case BS_SNEST6:
$@BS_NEST6=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill6");
break;
case BS_SNEST7:
$@BS_NEST7=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill7");
break;
case BS_SNEST8:
$@BS_NEST8=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill8");
break;
case BS_SNEST9:
$@BS_NEST9=0;
killmonster("020-7-1", "#BlueSageHUB::OnSlimeKill9");
break;
}
if (playerattached()) {
@nestid=0;
setq2 NivalisQuest_BlueSageSlimes, 0;
}
return;
}
// Return the Nest ID
// BSNestID( x, y )
function script BSNestID {
.@xa=getarg(0);
.@ya=getarg(1);
switch (.@xa) {
case 1:
if (.@ya == 1)
return BS_SNEST1;
else if (.@ya == 2)
return BS_SNEST2;
else if (.@ya == 3)
return BS_SNEST3;
break;
case 2:
if (.@ya == 1)
return BS_SNEST4;
else if (.@ya == 2)
return BS_SNEST5;
else if (.@ya == 3)
return BS_SNEST6;
break;
case 3:
if (.@ya == 1)
return BS_SNEST7;
else if (.@ya == 2)
return BS_SNEST8;
else if (.@ya == 3)
return BS_SNEST9;
break;
}
Exception("Invalid BS Nest Quadrands: ("+.@xa+", "+.@ya+")");
return 0;
}
// Return the Nest Quadrands
// BSQuadrand( NestID )
function script BSQuadrand {
.@nx=getarg(0);
switch (.@nx) {
case BS_SNEST1:
return 1;
case BS_SNEST2:
return 2;
case BS_SNEST3:
return 3;
case BS_SNEST4:
return 4;
case BS_SNEST5:
return 5;
case BS_SNEST6:
return 6;
case BS_SNEST7:
return 7;
case BS_SNEST8:
return 8;
case BS_SNEST9:
return 9;
}
Exception("Invalid BS Nest ID: ("+.@nx+")");
return 0;
}
// Proccess the slime type and amount
// BSProccess( )
function script BSProccess {
.@b1=getq(NivalisQuest_BlueSageSlimes);
.@b2=getq2(NivalisQuest_BlueSageSlimes);
.@b3=getq3(NivalisQuest_BlueSageSlimes);
// Quest state not assigned
if (!.@b1)
return;
// Fix your coordinates
getmapxy(.@m$, .@xc, .@yc,0);
.@x=.@xc-63;
.@y=.@yc-31;
// Check if you're off the library area
if (.@x <= 0 || .@y <= 0)
return;
// Calculate quadrand
// The map goes from (64,32) to (139,83)
// There is a 3x3 area, totalizing nine nests
// The useful area is 75 x 51, divided by 3 we have
// 25 x 17 quadrands.
// Anything beyond these quadrands is not regarded
.@x=(.@x/25)+1;
.@y=(.@y/17)+1;
if (.@x > 3 || .@y > 3)
return;
// We want the Quadrand ID to know if it was cleared or not
.@nest=BSNestID(.@x,.@y);
.@id=BSQuadrand(.@nest);
// Check if the nest was triggered
if (@nestid == .@nest)
return;
// Check if it was cleared already
if (getq3(NivalisQuest_BlueSageSlimes) & .@nest)
return;
// Check if we should spawn or if the quadrand is active
if (getd("$@BS_NEST"+str(.@id)))
return;
// Let's see if something should happen (16.7% odds each second. 3% of drip)
.@chance=rand(30);
if (.@chance <= 25) {
return;
} else if (.@chance == 27) {
dispbottom l("A slime drips in front of you and explodes!");
percentheal -40, 0;
} else {
dispbottom l("You notice a group of slimes emerging from the debris among the shelves.");
}
// If it haven't returned yet: It's good to go!
// Reserve the nest ID for us, and clear the previous.
BSClearNest(@nestid);
BSClearNest(.@nest);
@nestid=.@nest;
setd("$@BS_NEST"+.@id, getcharid(0));
// We spawn monsters
if (.@id % 4 == 0)
.@mid=WhiteSlime;
else
.@mid=BlueSlime;
//debugmes "Spawning %d slimes on quadrand %d", getd("$@BS_KNEST"+.@id), .@id;
// Does getd() works against a constant? I don't think so
monster .@m$, .@xc, .@yc, strcharinfo(0)+"'s slime", .@mid, getd("$@BS_KNEST"+.@id), "#BlueSageHUB::OnSlimeKill"+.@id;
return;
}
// Proccess the slime death
// BSProccessDeath( nestid, total )
function script BSProccessDeath {
.@nest=getarg(0);
.@ammo=getarg(1);
.@id=BSQuadrand(.@nest);
// First and foremost: Drops
if (playerattached()) {
getmapxy(.@m$, .@x, .@y, 0);
// Capped at ~12% drop chance of book pages
if (rand(0,10000) <= 560+(readparam(bLuck)*7))
makeitem SpellBookPage, 1, .@m$, .@x, .@y;
if (rand(0,10000) <= 100)
makeitem Candy, 1, .@m$, .@x, .@y;
}
// Mark the score if appliable and player is attached
if (playerattached()) {
if (@nestid == .@nest) {
.@q2=getq2(NivalisQuest_BlueSageSlimes)+1;
setq2 NivalisQuest_BlueSageSlimes, .@q2;
}
}
// All mobs are dead
if (!mobcount("020-7-1", "#BlueSageHUB::OnSlimeKill"+.@id)) {
if (playerattached()) {
// Did you killed all slimes? Or did they explode themselves?
// You have some chance to win even if you failed to kill all
// Will not work if this was not your nest
if ((.@q2 == .@ammo || rand(0,9000) == 255) && @nestid == .@nest) {
.@q3=getq3(NivalisQuest_BlueSageSlimes);
setq3 NivalisQuest_BlueSageSlimes, .@q3 | .@nest;
dispbottom l("It wasn't easy, but you think that you extinguished this nest.");
if ((.@q3 | .@nest) == BS_SNESTALL)
dispbottom l("Perhaps that was the last of them?");
} else {
dispbottom l("You don't see any slimes from that nest anymore. But did you really get all of them?");
debugmes "Nest %d, killed %d/%d slimes", .@id, .@q2, .@ammo;
debugmes "NEST ID: %d / %d", @nestid, .@nest;
}
}
// Regardless of player attached or not, this nest must be clean
BSClearNest(.@nest);
}
return;
}
020-7-1,24,84,0 script #BlueSageHUB NPC_HIDDEN,2,2,{
end;
OnSlimeKill1:
BSProccessDeath(BS_SNEST1, $@BS_KNEST1);
end;
OnSlimeKill2:
BSProccessDeath(BS_SNEST2, $@BS_KNEST2);
end;
OnSlimeKill3:
BSProccessDeath(BS_SNEST3, $@BS_KNEST3);
end;
OnSlimeKill4:
BSProccessDeath(BS_SNEST4, $@BS_KNEST4);
end;
OnSlimeKill5:
BSProccessDeath(BS_SNEST5, $@BS_KNEST5);
end;
OnSlimeKill6:
BSProccessDeath(BS_SNEST6, $@BS_KNEST6);
end;
OnSlimeKill7:
BSProccessDeath(BS_SNEST7, $@BS_KNEST7);
end;
OnSlimeKill8:
BSProccessDeath(BS_SNEST8, $@BS_KNEST8);
end;
OnSlimeKill9:
BSProccessDeath(BS_SNEST9, $@BS_KNEST9);
end;
OnTouch:
addtimer2(1000, "#BlueSageHUB::OnCycle");
end;
OnCycle:
BSProccess();
addtimer(1000, "#BlueSageHUB::OnCycle");
end;
OnInit:
// K - Nest Kills
$@BS_KNEST1=3;
$@BS_KNEST2=2;
$@BS_KNEST3=1;
$@BS_KNEST4=4; // WS
$@BS_KNEST5=2;
$@BS_KNEST6=1;
$@BS_KNEST7=3;
$@BS_KNEST8=5; // WS
$@BS_KNEST9=1;
end;
}