// TMW 2 Script
// Author:
// Jesusalva
// Micksha
// Description:
// This NPC is a work on progress. It measures all players equal.
// Controls the weekly guild dungeon feature.
// Variable structure:
// $@KAMELOT_ID [ guild_id ] = instance id
// $@KAMELOT_WAVE [ guild_id ] = contains a temporary control value
// $KAMELOT_MX [ guild_id ] = player average level - difficulty record
// $KAMELOT_PC [ guild_id ] = total members in guild
// $KAMELOT_QUEST [ guild_id ] = quest status (bitmask)
// 0 - Not started
// 1 - Quest Assigned by Arthur (new players cannot enter anymore)
// 2 - Guinevere dialog clear
// 4 - Weapon Room cutscene seen
// 8 - Sewer Gate open
// 16 - Magic Seal Broken
// 32 - Boss cutscene seen (presumably, victory)
// 64 - Boss defeated
// $KAMELOT_KEY [ guild_id ] = (bitmask) Keys and Lockpicks
// 1 - Treasure A (Boss Room key)
// 2 - Treasure B
// 4 - Treasure C
// 8 - Treasure D
// 16 - Weapon Room Key
// Do we ever need to store the data below?
// X,Y door is 2Y below
// 32 - Cell I 33,135
// 64 - Cell II 84,127
// 128 - Cell III 41,119
// 256 - Cell IV 74,107
// 512 - Cell V 36,96
// 1024 - Cell VI 57,84
// 2048 - Cell VII 79,63
// 4096 - Cell VIII 43,67
// 8192 - Cell IX 24,67
// 16384 - Cell X 86,22
// 32768 - Cell XI 59,49
// 65536 - Cell XII 38,27
// If more than 12 players, loop back
// $KAMELOT_KEYMASK [ guild_id ] = Which bit was assigned as the key
// $KAMELOT_COOLDOWN [ guild_id ] = Last attempt (weekly attempts)
// KamelotCleanup(guildid)
function script KamelotCleanup {
.@g=getarg(0);
//$@KAMELOT_ID[.@g]=0;
$@KAMELOT_WAVE[.@g]=0;
$KAMELOT_MX[.@g]=0;
$KAMELOT_PC[.@g]=0;
$KAMELOT_QUEST[.@g]=0;
$KAMELOT_KEYMASK[.@g]=0;
return;
}
014-4,67,26,0 script #KamelotEnter NPC_HIDDEN,0,0,{
end;
OnTouch:
// XXX STATUS: STAGING XXX
if (!is_staff())
end;
// Not in a guild: Gate is sealed (MK might be excluded as well)
if (getcharid(2) < 1) {
dispbottom l("The gates are firmly shut. A warning is on the door, \"DO NOT ENTER. Guild Only.\"");
end;
}
// Save your GID for reference
.@g=getcharid(2);
// Quest already started
if ($KAMELOT_QUEST[.@g] & 1) {
// Quest started but Cooldown expired
// Needs to cleanup - wipe all variables
if ($KAMELOT_COOLDOWN[.@g] < gettimeparam(GETTIME_WEEKDAY)) {
KamelotCleanup(.@g);
} else {
dispbottom l("The gates are firmly shut by some weird magical power.");
end;
}
}
// Build instance if it doesn't exists or has been reallocated
if (instanceowner($@KAMELOT_ID[.@g]) != .@g) {
debugmes "Creating Instance for guild %d", .@g;
.@inst=instance_create("Kamelot@"+.@g, .@g, IOT_GUILD);
if (.@inst < 0)
Exception("Kamelot Instance Error", RB_DEFAULT|RB_ISFATAL);
instance_attachmap("042-0", .@inst, .@g, "042-0@"+.@g);
instance_attachmap("042-1", .@inst, .@g, "042-1@"+.@g);
instance_attachmap("042-2", .@inst, .@g, "042-2@"+.@g);
instance_attachmap("042-3", .@inst, .@g, "042-3@"+.@g);
instance_attachmap("042-4", .@inst, .@g, "042-4@"+.@g);
instance_attachmap("042-5", .@inst, .@g, "042-5@"+.@g);
instance_attachmap("042-6", .@inst, .@g, "042-6@"+.@g);
instance_attachmap("042-7", .@inst, .@g, "042-7@"+.@g);
instance_attachmap("042-8", .@inst, .@g, "042-8@"+.@g);
instance_attachmap("042-9", .@inst, .@g, "042-9@"+.@g);
instance_attachmap("042-10", .@inst, .@g, "042-10@"+.@g);
instance_attachmap("042-11", .@inst, .@g, "042-11@"+.@g);
instance_set_timeout(0, 0, .@inst);
instance_init(.@inst);
$@KAMELOT_ID[.@g] = .@inst;
}
// You can enter in every other state
if (is_admin())
warp "042-0@"+.@g, any(59, 60), 80;
end;
// Debug is only allowed if server is in override mode
OnDebug:
if (!$@GM_OVERRIDE) end;
.@g=getcharid(2);
if (.@g < 1) end;
mes "Kamelot Debug";
select
l("Abort"),
l("Reset"),
l("Reset & Destroy"),
l("Quest - Skip Weapons Room"),
l("Quest - Skip Krukan fight"),
"",
"",
"",
"",
l("Warp - Jump to Entrance"), // 10
l("Warp - Jump to Weapon Room"),
l("Warp - Jump to Basement"),
l("Warp - Jump to Jail");
mes "";
switch (@menu) {
case 2:
KamelotCleanup(.@g);
break;
case 3:
instance_destroy($@KAMELOT_ID[.@g]);
KamelotCleanup(.@g);
break;
case 4:
$KAMELOT_KEYMASK[.@g]=$KAMELOT_KEYMASK[.@g]|16;
break;
case 5:
// FIXME: Can a variable really be named "$@GTEMP_042-2@10"?
.@m$=("042-2@"+.@g);
setd("$@GTEMP_"+.@m$, 0);
setd("$@GTEMP_HP_"+.@m$, 0);
setd("$@GTEMP_PC_"+.@m$, 0);
setd("$@GTEMP_MX_"+.@m$, 0);
$KAMELOT_QUEST[.@g]=$KAMELOT_QUEST[.@g]|4;
mes "WARNING: This skips jail as well.";
break;
case 10:
warp "042-0@"+.@g, 60, 40; break;
case 11:
warp "042-1@"+.@g, 40, 65; break;
case 12:
warp "042-2@"+.@g, 44, 45; break;
case 13:
warp "042-3@"+.@g, 60, 130; break;
}
close;
OnInit:
bindatcmd "kamelotdebug", "#KamelotEnter::OnDebug", 99, 100, 1;
end;
}