| 1 |
<?php |
<?php |
| 2 |
// $Id: game.module,v 1.52.2.18 2008/11/29 03:30:39 morbus Exp $ |
// $Id: game.module,v 1.52.2.19 2008/12/01 00:15:02 morbus Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 12 |
* [19:16] <litwol|mac> mydiv.scrollTop = mydiv.scrollHeight |
* [19:16] <litwol|mac> mydiv.scrollTop = mydiv.scrollHeight |
| 13 |
* @todo create a Log tab for the user under logs. |
* @todo create a Log tab for the user under logs. |
| 14 |
* @todo admin settings for name of game. use on tab/menu items. |
* @todo admin settings for name of game. use on tab/menu items. |
|
* @todo add missing/null/unowned bid checking to game_battle_process_form(); |
|
| 15 |
* @todo run an EXPLAIN on game_log_recent (8 seconds? wtf.) |
* @todo run an EXPLAIN on game_log_recent (8 seconds? wtf.) |
| 16 |
* @todo error if there are no mobs available (modules, etc.). |
* @todo error if there are no mobs available (modules, etc.). |
|
* @todo game_battle_play() needs to complain about missing params. |
|
| 17 |
* @todo go through and fine-tooth game_battle_play(). |
* @todo go through and fine-tooth game_battle_play(). |
| 18 |
* @todo move the dynamic 'hp' values into $state? |
* @todo move the dynamic 'hp' values into $state? |
| 19 |
* @todo add in uname to the variables (and other missing values). |
* @todo add in uname to the variables (and other missing values). |
| 44 |
$items['game/battle/%game_battle'] = array( |
$items['game/battle/%game_battle'] = array( |
| 45 |
'access arguments' => array('play game'), |
'access arguments' => array('play game'), |
| 46 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 47 |
'page arguments' => array('game_battle_process_form', 2), |
'page arguments' => array('game_battle_turn_form', 2), |
| 48 |
'title' => 'Game battle', |
'title' => 'Game battle', |
| 49 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 50 |
); |
); |
| 125 |
* @param $battle |
* @param $battle |
| 126 |
* A loaded battle from game_battle_load() (menu wildcard loader). |
* A loaded battle from game_battle_load() (menu wildcard loader). |
| 127 |
*/ |
*/ |
| 128 |
function game_battle_process_form(&$form_state, $battle) { |
function game_battle_turn_form(&$form_state, $battle) { |
| 129 |
global $user; // keep structure. |
global $user; // keep structure. |
| 130 |
$form['game']['#tree'] = TRUE; |
$form['game']['#tree'] = TRUE; |
| 131 |
$state = game_state_load($user->uid, $battle['bid']); |
$state = game_state_load($user->uid, $battle['bid']); |
| 167 |
/** |
/** |
| 168 |
* Form #submit callback; starts a battle and passes to main handler. |
* Form #submit callback; starts a battle and passes to main handler. |
| 169 |
*/ |
*/ |
| 170 |
function game_battle_process_form_submit($form, &$form_state) { |
function game_battle_turn_form_submit($form, &$form_state) { |
| 171 |
global $user; // side effects may include uncontrollable muscle movement. |
global $user; // side effects may include uncontrollable muscle movement. |
| 172 |
$state = game_state_load($user->uid, $form_state['values']['game']['bid']); |
$state = game_state_load($user->uid, $form_state['values']['game']['bid']); |
| 173 |
|
|
| 218 |
// loop through all the attackers remaining creatures and attack. |
// loop through all the attackers remaining creatures and attack. |
| 219 |
foreach (array_keys($state['battle']['parties'][$attacker_uid]) as $attacking_mob_num) { |
foreach (array_keys($state['battle']['parties'][$attacker_uid]) as $attacking_mob_num) { |
| 220 |
$state['battle']['state']['attacker']['mob_num'] = $attacking_mob_num; |
$state['battle']['state']['attacker']['mob_num'] = $attacking_mob_num; |
| 221 |
|
// @todo the above line may be removable once we split this up more. |
| 222 |
|
|
| 223 |
// if this mob has a target opponent and mob, use it. otherwise, random remaining. |
// let other modules interject on this attack. |
| 224 |
// this should really only be used when the AI is not automatically picking an |
drupal_alter('game_battle_attack_start', $state); |
|
// opponent; users would always choose opponent + mob via the standard form UI. |
|
|
// @todo this defaulting should eventually go into an AI-sorta module. |
|
|
if (!$state['battle']['state']['attacker']['party'][$attacking_mob_num]['target_uid']) { |
|
|
$state['battle']['state']['attacker']['party'][$attacking_mob_num]['target_uid'] = array_rand(array_diff_key($state['battle']['parties'], array($attacker_uid => 1))); |
|
|
$state['battle']['state']['attacker']['party'][$attacking_mob_num]['target_mob_num'] = array_rand($state['battle']['parties'][$state['battle']['state']['attacker']['party'][$attacking_mob_num]['target_uid']]); |
|
|
$state['battle']['state']['attacker']['party'][$attacking_mob_num]['attack'] = array_rand($state['battle']['parties'][$attacker_uid][$attacking_mob_num]['actions']); |
|
|
} |
|
| 225 |
|
|
| 226 |
// roll attack for success or failure. |
// roll attack and call teh hookz. |
| 227 |
$state = game_battle_attack($state); |
$state = game_battle_attack($state); |
| 228 |
|
|
| 229 |
// @todo move this and other damage related stuff into a new function. |
// @todo move this and other damage related stuff into a new function. |