require_login(); } else { $user = 647133029;} // Try to grab this users session key / get an infinite session key for this user saveSession($user,$facebook->api_client->session_key); debug('Session key = ' . $facebook->api_client->session_key); $spellcaster = loaduser($user); if (! $spellcaster){ // This is a brand new user // We need to load this user from scratch newuser($user); $spellcaster = loaduser($user); } if (strlen($spellcaster->name) == 0 OR !$spellcaster->name ){$showpage='profile';} // Set variables ready for game play $showform = TRUE; $showaction = FALSE; $showfooter = TRUE; $success = ''; $error = ''; $explanation = ''; // Supercaston overides the caston_uid. Should allow games between non-friends. if ($supercaston) {$caston_uid = $supercaston;} if ($caston_uid){$victim = loaduser($caston_uid);} // Check that this user actually has the game installed /* =================================================================== WRITE OUT THE HEADER EARLY TO AS "PROOF OF LIFE" ====================================================================== */ echo '
'; echo '
'; /* =================================================================== CHECK FOR NON-PLAYING PAGES ====================================================================== */ if ($showpage){ $showform = FALSE; $showaction = FALSE; $showfooter = FALSE; $postedword = FALSE; include $showpage . '.php'; } /* ================================================================= */ // PLAY THE GAME /* ================================================================= */ if ($showform){ // Search for any unresolved attacks $actions = loadPendingAction($spellcaster->uid); if ($nextaction = mysql_fetch_object($actions)){ $showaction = $nextaction; } if ($caston_uid > 0 AND ($casttype == 'Deflected' or $casttype == 'Cast')){$overkill = loadOverkillCheck($user,$caston_uid);} else {$overkill = FALSE;} if ($resetrunes){ // The user needs to reset their runes, as they simply cannot make a word. // This will cost them twice the value of the outstanding runes. $lostpoints = calculateWordPoints($spellcaster->tiles); $spellcaster->score = $spellcaster->score - $lostpoints; $spellcaster->tiles = getTiles($basetilecount,'',''); saveuser($spellcaster); $successtitle = 'Runic Redemption!'; $success = 'Your runes have been reset, but at a cost of ' . $lostpoints . ' points.'; // Ensure there is no continued play $postedword = FALSE; } echo '

' . $spellcaster->name . '

Points: ' . $spellcaster->points . '

Status: ' . $spellcaster->status . '

Refresh Status

'; } // Process the posted action if ($postedword AND ($caston_uid > 0 OR $casttype == 'Blocked') AND $overkill != TRUE AND ($victim->uid OR $casttype == 'Blocked')){ // If $showaction is set and we have a posted word, then we retaliating against another player. // Build appropriate tileset, include tiles for spells cast against player. if ($showaction){ $response = $showaction->action_id; $enemyword = $showaction->word; } else { $response = 0; $enemyword = ''; } switch ($casttype){ case 'Cast': $currenttiles = $spellcaster->tiles; break; case 'Absorbed' : $currenttiles = $spellcaster->tiles; break; case 'Blocked' : $currenttiles = $enemyword; break; case 'Deflected' : $currenttiles = $spellcaster->tiles . $enemyword; break; } /* Checks 1: Is this a real word? 2: Can this word be made from my tiles? */ if (checkword($postedword)){ if (checkWordFromTiles($postedword,$currenttiles)){ // Success! // If this is a block, deflect, or absorb, we need to check against the cast enemy tiles if ($casttype == 'Cast' OR $casttype == 'Absorbed'){ $nextresponse = 0; // Find out what effect this might have had on our spellcaster $score = calculateWordPoints($postedword); $newstatus = calculateStatus($postedword,$spellcaster->status); // Find out what effect this might have on our spellcaster's target $victimscore = calculateVictimWordPoints($postedword,$caston_uid) * -1; $victimstatus = calculateVictimStatus($postedword,$caston_uid); // Update tile set on spellcaster // In Absorb mode, we must take tiles from the enemy spell FIRST $spellcaster->tiles = removeWordFromTiles($postedword,$spellcaster->tiles); $spellcaster->tiles = getTiles($basetilecount,$spellcaster->tiles,$enemyword); } if ($casttype == 'Blocked'){ $nextresponse = -1; // We need to calculate how many points the spellcaster has retrieved. // Calculate this by taking the original points drain and taking away the points drain // of any tiles that we were unable to block $unblockedTiles = removeWordFromTiles($postedword,$enemyword); $blockedTiles = removeWordFromTiles($unblockedTiles,$enemyword); $blockedpoints = calculateVictimWordPoints($blockedTiles,$user); // Now calculate the points of damage that we have inflicted on our opponent and saved ourselves from $score = $blockedpoints; $newstatus = calculateStatus($postedword,$spellcaster->status); // Find out the impact on the person we are defending against // Override the caston_uid data with the caster of the spell and reload the victim $caston_uid = $showaction->from_uid; $victim = loaduser($caston_uid); $victimscore = calculateVictimWordPoints($postedword,$caston_uid) * -1; $victimstatus = calculateVictimStatus($postedword,$caston_uid); // Special Rule: SUPERBLOCK if (strlen($unblockedTiles) == 0 AND (strlen($postedword) == strlen($enemyword)) AND strtoupper($postedword) != strtoupper($enemyword) ){ // This is a superblock! Double points!! $score = $score * 4; $victimscore = $victimscore * 4; $explaintitle = 'SuperBlock! Double Points!'; $explanation = 'You have discovered the power of the "Superblock". Superblock activates when you cast a spell that is an anagram of the spell cast on you.'; } // Special Rule: BACKFIRE if (strtoupper($postedword) == strtoupper($enemyword)){ $successtitle = 'Backfire!'; $errortitle = 'Backfire!'; $error = 'You cannot block a spell with the same spell!'; $score = $score * -1; $victimscore = abs($victimscore); } // No need to update tile set on spellcaster, as we can only use letters that we had in our block set. // Remember that we have only used tiles of our own that we did not block } if ($casttype == 'Deflected'){ $nextresponse = 0; // In Deflect, we are not saving any points from ourselves, just bouncing a more powerful spell // onto the new target. In theory this can chain multiple times, becoming a very powerful spell indeed! $unblockedTiles = removeWordFromTiles($postedword,$enemyword); $blockedTiles = removeWordFromTiles($unblockedTiles,$enemyword); $blockedpoints = calculateVictimWordPoints($blockedTiles,$user); $usedTiles = removeWordFromTiles($blockedTiles,$postedword); // Calculate our score $score = calculateWordPoints($usedTiles) + $blockedpoints; $newstatus = calculateStatus($postedword,$spellcaster->status); // Calculate impact on victim $victimscore = calculateVictimWordPoints($postedword,$caston_uid) * -1; $victimstatus = calculateVictimStatus($postedword,$caston_uid); // Update the tileset on spellcaster. Remember, we have only used tiles that we did not deflect. $spellcaster->tiles = removeWordFromTiles($usedTiles,$spellcaster->tiles); $spellcaster->tiles = getTiles($basetilecount,$spellcaster->tiles,''); } // Apply the calculated effects to our spellcaster and his victim // -------------------------------------------------------------- // Spellcaster $spellcaster->points += $score; if ($newstatus) {$spellcaster->status = $newstatus;} $victim->points += $victimscore; if ($victimstatus) {$victim->status = $victimstatus;} // Save the results of this activity newaction($casttype,$user,$caston_uid,$postedword,$score,$victimscore,$newstatus,$victimstatus,$response,$nextresponse); saveuser($spellcaster); if ($victim->uid > 0){saveuser($victim);} // If we have just responded to an action, then we need to load the next action up ready for display if ($casttype != 'Cast') { $actions = loadPendingAction($spellcaster->uid); if ($nextaction = mysql_fetch_object($actions)){ $showaction = $nextaction; } else {$showaction = FALSE;} } // Compose success message $success = 'You have cast the spell "' . $postedword . '" on ' . rendername($caston_uid); $success .= '
You have scored ' . $score . ' points and reduced your opponents scored by ' . abs($victimscore); } else { $error .= 'You do not have the runes to cast the spell "' . $postedword . '"'; } } else { $error .= 'The spell "' . $postedword . '" could not be found in our grimoire.'; } } elseif ($postedword AND $caston_uid <= 0) { $errortitle = 'You missed!'; $error = 'Remember, you must enter a target to cast, absorb, or deflect a spell!'; } elseif ($postedword AND $overkill) { // Notify the user they are on overkill ! notify($caston_uid,$user, 'has reached overkill!
Click to defend yourself!', 'is a victim of Spellcasting overkill!
Click to defend yourself!'); $errortitle = 'Overkill!'; $error = 'You cannot attack ' . rendername($caston_uid) . ' again until they defended themselves against the spells you have already cast on them.'; $error .= '
You can still Absorb or Block attacks from this player, or Deflect their spell onto someone else ...'; } elseif ($postedword AND !($victim->uid)){ $errortitle = 'Civilian casualty!'; $error = 'You cannot cast spells at friends who do not have SpellCasters installed.
'; $error .= 'Click here to invite more players'; } /* ================================================================= */ // GAME COMPLETE! /* ================================================================= */ /* ================================================================= */ // OUTPUT THE PAGE, FORM & RESULTS /* ================================================================= */ if ($success){ echo '

' . ($successtitle ? $successtitle : 'Success!') . '

' . $success . '

';} if ($error){ echo '

' . ($errortitle ? $errortitle : 'Error!') . '

' . $error . '

';} if ($explanation){ echo '

' . ($explaintitle ? $explaintitle : 'A Magical Discovery') . '

' . $explanation . '

';} if ($showform) { echo '
'; if ($showaction){ echo '
'; echo '

You are under attack!

'; echo '
'; echo renderName($showaction->from_uid) . '
'; echo 'Attack this Spellcaster
'; echo ' cast the spell "' . strtoupper($showaction->word) . '" on you.'; echo '
This spell originally scored '. $showaction->from_points . ' and cost you ' . abs($showaction->to_points) . ' points.'; echo '

'; } echo '

Your available runes are
' . renderTiles($spellcaster->tiles); if ($showaction) { echo 'The runes cast by your oppenent where
' . renderTiles($showaction->word) . '
'; } echo '


'; echo '
'; if ($lock){ echo '
';} else {echo '';} if ($showaction){echo 'Enter your counterspell ...
';} else { echo 'Enter your spell
';} echo '

'; if ($supercaston){ echo ''; echo 'You are targetting ' . rendername($supercaston); if ($lock){ echo ' (UNLOCK)'; } else {echo ' (LOCK)';} echo '

'; } else { echo 'Select your target ...
You don't have any friends yet. Please Sign Up!

'; } if ($showaction){ echo 'Choose the type of spell you will cast ...
'; echo 'Absorb'; if (!$lock){echo 'Block';} echo 'Deflect'; } else { echo ''; } echo '

'; echo '
If you cannot cast a spell from your runes, you can beg the gods for better runes. Be warned however, that the gods will exact a heavy penalty from those they find unworthy ...'; echo '
'; echo '
Click here for help!

'; echo '
' . renderhistory(10,$user) . '
'; echo '
'; } /* ================================================================= */ // END OF FORM ETC. /* ================================================================= */ /* ================================================================= */ // THE ADVERTISING. /* ================================================================= */ echo '
'; renderAdvert('banner',0); echo '
'; renderAdvert('banner',3); echo '
'; /* ================================================================= */ // OUTPUT THE LEADERBOARD, CURRENT ACTIVITY, ETC. /* ================================================================= */ if ($showfooter){ echo ''; echo ''; echo ''; echo ''; echo '
' . renderhistory(25,0) . '' . renderleaderboard(15) . '' . renderleaderboard(0,TRUE) . '
'; } /* ==================================================================== * SET THE PROFILE FBML ==================================================================== */ $facebook->api_client->profile_setFBML(' ' , $user); /* ================================================================= */ // OUTPUT THE DEBUG /* ================================================================= */ if ($debugshow AND $user == 647133029){ echo '
'; echo $debug; echo '
Message = ' . $message; echo '
Success = ' . $success; echo '
Error = ' . $error; echo '
Explanation = ' . $explanation; } echo ' '; ?>