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
// *** Default attack category type is single attack. ***
if ($blaze) {
    $attack_type = 'blaze';
} 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.
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 {
Example #5
0
    $attack_type['evade'] = 'evade';
}
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;