Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
// addnews ready
// translator ready
// mail ready
$battle = false;
page_header("The Green Dragon!");
$op = httpget('op');
if ($op==""){
if (!httpget('nointro')) {
output("`\$Fighting down every urge to flee, you cautiously enter the cave entrance, intent on catching the great green dragon sleeping, so that you might slay it with a minimum of pain.");
output("Sadly, this is not to be the case, for as you round a corner within the cave you discover the great beast sitting on its haunches on a huge pile of gold, picking its teeth with a rib.");
$badguy = array(
"creaturename"=>translate_inline("`@The Green Dragon`0"),
"creatureweapon"=>translate_inline("Great Flaming Maw"),
//toughen up each consecutive dragon.
// First, find out how each dragonpoint has been spent and count those
// used on attack and defense.
// Coded by JT, based on collaboration with MightyE
$points = round(get_player_dragonkillmod(true)*0.75,0);
$atkflux = e_rand(0, $points);
$defflux = e_rand(0,$points-$atkflux);
$hpflux = ($points - ($atkflux+$defflux)) * 5;
debug("DEBUG: $points modification points total.`0`n");
debug("DEBUG: +$atkflux allocated to attack.`n");
debug("DEBUG: +$defflux allocated to defense.`n");
debug("DEBUG: +". ($hpflux/5) . "*5 to hitpoints.`0`n");
$badguy = modulehook("buffdragon", $badguy);
$flawless = (int)(httpget('flawless'));
if ($flawless) {
output("`b`c`&~~ Flawless Fight ~~`0`c`b`n`n");
output("`2Before you, the great dragon lies immobile, its heavy breathing like acid to your lungs.");
output("You are covered, head to toe, with the foul creature's thick black blood.");
output("The great beast begins to move its mouth. You spring back, angry at yourself for having been fooled by its ploy of death, and watch for its huge tail to come sweeping your way.");
output("But it does not.");
output("Instead the dragon begins to speak.`n`n");
output("\"`^Why have you come here mortal? What have I done to you?`2\" it says with obvious effort.");
output("\"`^Always my kind are sought out to be destroyed. Why? Because of stories from distant lands that tell of dragons preying on the weak? I tell you that these stories come only from misunderstanding of us, and not because we devour your children.`2\"");
output("The beast pauses, breathing heavily before continuing, \"`^I will tell you a secret. Behind me now are my eggs. They will hatch, and the young will battle each other. Only one will survive, but she will be the strongest. She will quickly grow, and be as powerful as me.`2\"");
output("Breath comes shorter and shallower for the great beast.`n`n");
output("\"`#Why do you tell me this? Don't you know that I will destroy your eggs?`2\" you ask.`n`n");
output("\"`^No, you will not, for I know of one more secret that you do not.`2\"`n`n");
output("\"`#Pray tell oh mighty beast!`2\"`n`n");
output("The great beast pauses, gathering the last of its energy. \"`^Your kind cannot tolerate the blood of my kind. Even if you survive, you will be a feeble creature, barely able to hold a weapon, your mind blank of all that you have learned. No, you are no threat to my children, for you are already dead!`2\"`n`n");
output("Realizing that already the edges of your vision are a little dim, you flee from the cave, bound to reach the healer's hut before it is too late.");
output("Somewhere along the way you lose your weapon, and finally you trip on a stone in a shallow stream, sight now limited to only a small circle that seems to float around your head.");
output("As you lay, staring up through the trees, you think that nearby you can hear the sounds of the village.");
output("Your final thought is that although you defeated the dragon, you reflect on the irony that it defeated you.`n`n");
output("As your vision winks out, far away in the dragon's lair, an egg shuffles to its side, and a small crack appears in its thick leathery skin.");
if ($flawless) {
output("`n`nYou fall forward, and remember at the last moment that you at least managed to grab some of the dragon's treasure, so maybe it wasn't all a total loss.");
addnav("It is a new day","news.php");
$sql = "DESCRIBE " . db_prefix("accounts");
$result = db_query($sql);
$dkpoints = 0;
foreach ($session['user']['dragonpoints'] as $val) {
if ($val=="hp") $dkpoints+=5;
$hpgain = array(
'total' => $session['user']['maxhitpoints'],
'dkpoints' => $dkpoints,
'extra' => $session['user']['maxhitpoints'] - $dkpoints -
'base' => $dkpoints + ($session['user']['level'] * 10),
$hpgain = modulehook("hprecalc", $hpgain);
$nochange = modulehook("dk-preserve", $nochange);
$badguys = $session['user']['badguy']; //needed for the dragons name later
$session['user']['dragonage'] = $session['user']['age'];
if ($session['user']['dragonage'] < $session['user']['bestdragonage'] ||
$session['user']['bestdragonage'] == 0) {
$session['user']['bestdragonage'] = $session['user']['dragonage'];
while ($row = db_fetch_assoc($result)) {
if (array_key_exists($row['Field'],$nochange) &&
$session['user'][$row['Field']] = $row["Default"];
$session['user']['gold'] = getsetting("newplayerstartgold",50);
$session['user']['location'] = getsetting('villagename', LOCATION_FIELDS);
$session['user']['armor'] = getsetting('startarmor','T-Shirt');
$session['user']['weapon'] = getsetting('startweapon','Fists');
$newtitle = get_dk_title($session['user']['dragonkills'], $session['user']['sex']);
$restartgold = $session['user']['gold'] +
getsetting("newplayerstartgold", 50)*$session['user']['dragonkills'];
$restartgems = 0;
if ($restartgold > getsetting("maxrestartgold", 300)) {
$restartgold = getsetting("maxrestartgold", 300);
$restartgems = max(0,($session['user']['dragonkills'] -
(getsetting("maxrestartgold", 300)/
getsetting("newplayerstartgold", 50)) - 1));
if ($restartgems > getsetting("maxrestartgems", 10)) {
$restartgems = getsetting("maxrestartgems", 10);
$session['user']['gold'] = $restartgold;
$session['user']['gems'] += $restartgems;
if ($flawless) {
$session['user']['gold'] += 3*getsetting("newplayerstartgold",50);
$session['user']['gems'] += 1;
$session['user']['maxhitpoints'] = 10 + $hpgain['dkpoints'] +
// Sanity check
if ($session['user']['maxhitpoints'] < 1) {
// Yes, this is a freaking hack.
die("ACK!! Somehow this user would end up perma-dead.. Not allowing DK to proceed! Notify admin and figure out why this would happen so that it can be fixed before DK can continue. Most likely, you have less than Level*10 Hitpoints when you kill the dragon. Let this fix and tell the admin that such a case should not happen. If necessary, bite her/his toes until she/he complies.");
// Set the new title.
$newname = change_player_title($newtitle);
$session['user']['title'] = $newtitle;
$session['user']['name'] = $newname;
foreach ($session['user']['dragonpoints'] as $val) {
switch ($val) {
//legacy support
case "at":
case "de":
$session['user']['laston']=date("Y-m-d H:i:s",strtotime("-1 day"));
if (!getsetting('pvpdragonoptout',0)) $session['user']['slaydragon'] = 1;
$companions = array();
$session['user']['companions'] = array();
output("`n`nYou wake up in the midst of some trees. Nearby you hear the sounds of a village.");
output("Dimly you remember that you are a new warrior, and something of a dangerous Green Dragon that is plaguing the area. You decide you would like to earn a name for yourself by perhaps some day confronting this vile creature.");
// allow explanative text as well.
$regname = get_player_basename();
//get the dragons name
$badguys = @unserialize ($badguys);
$badguy=array("creaturename"=>translate_inline("`@The Green Dragon`0"));
foreach ($badguys['enemies'] as $opponent) {
if ($opponent['type']=='dragon') {
$howoften=($session['user']['dragonkills']>1?"times":"time"); // no translation, we never know who is viewing...
addnews("`#%s`# has earned the title `&%s`# for having slain `@%s`& `^%s`# %s!",$regname,$session['user']['title'],$badguy['creaturename'],$session['user']['dragonkills'],$howoften);
output("`n`n`^You are now known as `&%s`^!!",$session['user']['name']);
output("`n`n`&Because you have slain %s`& %s %s, you start with some extras. You also keep additional permanent hitpoints you've earned.`n",$badguy['creaturename'],$session['user']['dragonkills'],$howoften);
output("`^You gain FIVE charm points for having defeated the dragon!`n");
debuglog("slew the dragon and starts with {$session['user']['gold']} gold and {$session['user']['gems']} gems");
// Moved this hear to make some things easier.
modulehook("dragonkill", array());
if ($op=="run"){
output("The creature's tail blocks the only exit to its lair!");
httpset('op', 'fight');
if ($op=="fight" || $op=="run"){
if ($battle){
if ($victory){
$flawless = 0;
if ($badguy['diddamage'] != 1) $flawless = 1;
output("`&With a mighty final blow, `@%s`& lets out a tremendous bellow and falls at your feet, dead at last.",$badguy['creaturename']);
addnews("`&%s has slain the hideous creature known as `@%s`&. All across the land, people rejoice!",$session['user']['name'],$badguy['creaturename']);
addnav("Daily news","news.php");
$taunt = select_taunt_array();
if ($session['user']['sex']){
addnews("`%%s`5 has been slain when she encountered `@%s`5!!! Her bones now litter the cave entrance, just like the bones of those who came before.`n%s",$session['user']['name'],$badguy['creaturename'],$taunt);
addnews("`%%s`5 has been slain when he encountered `@%s`5!!! His bones now litter the cave entrance, just like the bones of those who came before.`n%s",$session['user']['name'],$badguy['creaturename'],$taunt);
debuglog("lost {$session['user']['gold']} gold when they were slain");
output("`b`&You have been slain by `@%s`&!!!`n",$badguy['creaturename']);
output("`4All gold on hand has been lost!`n");
//grant modules a chance to exclusively hook in here and do worse things to the user =)
output("You may begin fighting again tomorrow.");