Example #1
0
 public function testCantAttackIfExcessiveAmountOfTurnsIsRequired()
 {
     $confirm = true;
     $char_id = TestAccountCreateAndDestroy::create_testing_account($confirm);
     $this->oldify_character_last_attack($char_id);
     $char_2_id = TestAccountCreateAndDestroy::create_alternate_testing_account($confirm);
     $this->oldify_character_last_attack($char_2_id);
     $char = new Player($char_2_id);
     $legal = new AttackLegal($char_id, $char->name(), ['required_turns' => 4000000000.0, 'ignores_stealth' => true]);
     $this->assertFalse($legal->check($update_timer = false));
 }
function test_attack_legal_object()
{
    // in: same ninja, out: fail
    $attacker = 'glassbox';
    $target = 'glassbox';
    $params = array('required_turns' => 5, 'attacked' => 1);
    $AttackLegal = new AttackLegal($attacker, $target, $params);
    $attack_checked = $AttackLegal->check();
    $attack_error = $AttackLegal->getError();
    assert($attack_checked == false);
    // in: two different characters, out: legal
    $attacker = 'glassbox';
    $target = 'test';
    $params = array('required_turns' => 5, 'attacked' => 1);
    $AttackLegal = new AttackLegal($attacker, $target, $params);
    $attack_checked = $AttackLegal->check();
    $attack_error = $AttackLegal->getError();
    assert($attack_checked == true);
    // Sometimes hits the time limit when unit testing.
    echo $attack_error;
    // In: excessive required turns, out: failure
    $attacker = 'glassbox';
    $target = 'test';
    $params = array('required_turns' => 1000000, 'attacked' => 1);
    $AttackLegal = new AttackLegal($attacker, $target, $params);
    $attack_checked = $AttackLegal->check();
    $attack_error = $AttackLegal->getError();
    assert($attack_checked == false);
    // In: different name and attacker_id, out: legal
    $attacker = 10;
    $target = 'test';
    $params = array('required_turns' => 1, 'attacked' => 1);
    $AttackLegal = new AttackLegal($attacker, $target, $params);
    $attack_checked = $AttackLegal->check();
    $attack_error = $AttackLegal->getError();
    assert($attack_checked == true);
}
Example #3
0
} elseif ($deflect) {
    $attack_type = 'deflect';
} elseif ($duel) {
    $attack_type = 'duel';
}
$skillListObj = new Skill();
$ignores_stealth = $skillListObj->getIgnoreStealth($attack_type);
$required_turns = $skillListObj->getTurnCost($attack_type);
// *** Attack Legal section ***
$attacker = $username;
$params = array('required_turns' => $required_turns, 'ignores_stealth' => $ignores_stealth);
assert($attacker != $target);
$AttackLegal = new AttackLegal($attacker, $target, $params);
// *** There's a same-domain problem with this attack-legal now that it's been modified for skills ***
// ***  MAIN BATTLE ALGORITHM  ***
if (!$AttackLegal->check()) {
    // *** Display the reason the attack failed.
    echo "<div class='ninja-error centered'>" . $AttackLegal->getError() . "</div>";
} else {
    // *** ATTACKING + STEALTHED SECTION  ***
    if (!$duel && $attacker_status['Stealth']) {
        //Not dueling, and attacking from stealth
        subtractStatus($username, STEALTH);
        $turns_to_take = 1;
        echo "You are striking from the shadows, you quickly strike your victim!<br>\n";
        echo "Your attack has revealed you from the shadows! You are no longer stealthed.<br>\n";
        if (!subtractHealth($attackee, $stealthAttackDamage)) {
            //if Stealth attack of whatever damage kills target.
            $gold_mod = 0.1;
            $loot = round($gold_mod * getGold($attackee));
            $attackee_msg = "DEATH: You have been killed by a stealthed ninja in combat and lost {$loot} gold on {$today}!";
Example #4
0
}
if (!is_object($item)) {
    echo "No such item.";
    die;
    // hack to avoid fatal error, proper checking for items should be done.
}
$article = get_indefinite_article($item->getName());
if ($using_item) {
    $turn_cost = $item->getTurnCost();
}
// Attack Legal section
$attacker = $username;
$params = array('required_turns' => $turn_cost, 'ignores_stealth' => $item->ignoresStealth(), 'self_use' => $selfTarget);
assert(!!$selfTarget || $attacker != $target);
$AttackLegal = new AttackLegal($attacker, $target, $params);
$attack_allowed = $AttackLegal->check();
$attack_error = $AttackLegal->getError();
// *** Any ERRORS prevent attacks happen here  ***
if (!$attack_allowed) {
    //Checks for error conditions before starting.
    echo "<div class='ninja-error centered'>{$attack_error}</div>";
    // Display the reason the attack failed.
} else {
    if (is_string($item) || $target == "") {
        echo "You didn't choose an item/victim.\n";
    } else {
        $row = $sql->data;
        if ($item_count < 1) {
            echo "You do not have" . ($item ? " {$article} " . $item->getName() : ' that item') . ".\n";
        } else {
            /**** MAIN SUCCESSFUL USE ****/
Example #5
0
}
if ($duel) {
    $attack_type['duel'] = 'duel';
} else {
    $attack_type['attack'] = 'attack';
}
$skillListObj = new Skill();
$ignores_stealth = false;
foreach ($attack_type as $type) {
    $ignores_stealth = $ignores_stealth || $skillListObj->getIgnoreStealth($type);
    $required_turns += $skillListObj->getTurnCost($type);
}
// *** Attack Legal section ***
$params = array('required_turns' => $required_turns, 'ignores_stealth' => $ignores_stealth);
$AttackLegal = new AttackLegal($attacker, $target, $params);
$attack_is_legal = $AttackLegal->check();
$attack_error = $AttackLegal->getError();
// *** There's a same-domain problem with this attack-legal now that it's been modified for skills ***
$target_player = new Player($target_id);
$attacking_player = new Player($attacker_id);
// ***  MAIN BATTLE ALGORITHM  ***
if ($attack_is_legal) {
    // *** Target's stats. ***
    $target_health = $target_player->vo->health;
    $target_level = $target_player->vo->level;
    $target_str = $target_player->getStrength();
    // *** Attacker's stats. ***
    $attacker_health = $attacking_player->vo->health;
    $attacker_level = $attacking_player->vo->level;
    $attacker_turns = $attacking_player->vo->turns;
    $attacker_str = $attacking_player->getStrength();
Example #6
0
 $player = $target = $player_info['uname'];
 // reset the target and target_id vars.
 $target_id = $player_info['player_id'];
 $target_class_theme = char_class_theme($target_id);
 if ($message) {
     send_message($char_id, $target_id, $message);
     // "message sent" notice will be displayed by the template itself.
 }
 // Get the player's kills for this date.
 $kills_today = query_item('select sum(killpoints) from levelling_log where _player_id = :player_id and killsdate = CURRENT_DATE and killpoints > 0', array(':player_id' => $target_id));
 $viewers_clan = $viewing_player_obj instanceof Player && $viewing_player_obj->vo ? get_clan_by_player_id($viewing_player_obj->vo->player_id) : null;
 // Attack Legal section
 $params = array('required_turns' => 0, 'ignores_stealth' => true);
 // 0 for unstealth.
 $AttackLegal = new AttackLegal($username, $target, $params);
 $attack_allowed = $AttackLegal->check(false);
 $attack_error = $AttackLegal->getError();
 $sel_rank_spot = "SELECT rank_id FROM rankings WHERE player_id = :char_id limit 1";
 $rank_spot = query_item($sel_rank_spot, array(':char_id' => $player_info['player_id']));
 // Display the player info.
 $status_list = get_status_list($player);
 $level_category = level_category($player_info['level']);
 $gurl = $gravatar_url = generate_gravatar_url($target_player_obj);
 if ($char_id && !$attack_error && !$self) {
     // They're not dead or otherwise unattackable.
     // Attack or Duel
     $skillDAO = new SkillDAO();
     $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'combat', $viewing_player_obj->vo->level)->fetchAll();
     $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'targeted', $viewing_player_obj->vo->level)->fetchAll();
     // *** todo When Smarty3 is released, remove fetch all and change template to new foreach-as syntax ***
     // Check all the combat toggles to see if they should be checked on the profile page.