예제 #1
0
 public function testCanAttackAsOneCharByIdAndAnotherByName()
 {
     $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);
     $char2 = new Player($char_2_id);
     $legal = new AttackLegal($char_id, $char2->name(), ['required_turns' => 1, 'ignores_stealth' => true]);
     $checked = $legal->check($update_timer = false);
     $this->assertEquals(null, $legal->getError(), 'There was an attack error message when there shouldn\'t be one.');
     $this->assertTrue($checked);
 }
예제 #2
0
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);
}
예제 #3
0
} 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}!";
            $attacker_msg = "You have killed {$attackee} in combat and taken {$loot} gold on {$today}.";
            subtractStatus($attackee, STEALTH + POISON + FROZEN + CLASS_STATE);
예제 #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 ****/
            echo "Preparing to use item - <br>\n";