public function testThatAShurikenHasSliceEffect() { $item = new Item('shuriken'); $this->assertGreaterThan(0, $item->hasEffect('slice')); }
/** * Given 2 players and an item, mutate player states based on item effects * * @return Array * @note * Slow and speed effects are exclusive. */ private function applyItemEffects(Player $user, Player $target, Item $item) { $success = true; $notice = null; $message = ''; $extra_message = ''; $turns_change = null; $bonus = $this->calculateBonus($user, $target); if ($item->hasEffect('wound')) { $item->setTargetDamage(rand(1, $item->getMaxDamage())); if ($item->hasEffect('slice')) { $item->setTargetDamage(rand(1, max(9, $user->getStrength() - 4)) + $bonus); } if ($item->hasEffect('pierce')) { $item->setTargetDamage(rand(1, $item->getMaxDamage()) + $bonus); } if ($item->hasEffect('fire')) { $item->setTargetDamage(rand(20, $user->getStrength() + 20) + $bonus); } } if ($item->hasEffect('stealth')) { $target->addStatus(STEALTH); $extra_message = "__TARGET__ is now stealthed."; $notice = ' be shrouded in smoke.'; } if ($item->hasEffect('vigor')) { if ($target->hasStatus(STR_UP1)) { $message = "__TARGET__'s body cannot become more vigorous!"; $success = false; } else { $target->addStatus(STR_UP1); $message = "__TARGET__'s muscles experience a strange tingling."; } } if ($item->hasEffect('strength')) { if ($target->hasStatus(STR_UP2)) { $message = "__TARGET__'s body cannot become any stronger!"; $success = false; } else { $target->addStatus(STR_UP2); $message = "__TARGET__ feels a surge of power!"; } } if ($item->hasEffect('slow')) { $item->setTurnChange(-1 * $this->caltropTurnLoss($target, $bonus)); $turns_change = $item->getTurnChange(); if ($target->hasStatus(SLOW)) { // If the effect is already in play, it will have a decreased effect. $turns_change = ceil($turns_change * 0.3); $extra_message = "__TARGET__ is already moving slowly."; } else { if ($target->hasStatus(FAST)) { $target->subtractStatus(FAST); $extra_message = "__TARGET__ is no longer moving quickly."; } else { $target->addStatus(SLOW); $extra_message = "__TARGET__ begins to move slowly..."; } } if ($turns_change == 0) { $extra_message .= " You fail to take any turns from __TARGET__."; } $notice = " lose " . abs($turns_change) . " turns."; $target->changeTurns(-1 * $turns_change); } else { if ($item->hasEffect('speed')) { $item->setTurnChange($item->getMaxTurnChange()); $turns_change = $item->getTurnChange(); if ($target->hasStatus(FAST)) { // If the effect is already in play, it will have a decreased effect. $turns_change = ceil($turns_change * 0.5); $extra_message = "__TARGET__ is already moving quickly."; } else { if ($target->hasStatus(SLOW)) { $target->subtractStatus(SLOW); $extra_message = "__TARGET__ is no longer moving slowly."; } else { $target->addStatus(FAST); $extra_message = "__TARGET__ begins to move quickly!"; } } $notice = " gain {$turns_change} turns."; $target->changeTurns($turns_change); } } if ($item->getTargetDamage() > 0) { // HP Altering $extra_message .= " __TARGET__ takes " . $item->getTargetDamage() . " damage."; if ($user->id() === $target->id()) { $message .= "You take " . $item->getTargetDamage() . " damage!"; } else { if (strlen($notice) > 0) { $notice .= " You also"; // Join multiple targetResult messages. } $notice .= " take " . $item->getTargetDamage() . " damage!"; } $target->harm($item->getTargetDamage()); } // if the item was meant to affect turns, even if the net change was 0 if ($turns_change !== null) { if ($turns_change > 0) { $message .= "__TARGET__ has gained back {$turns_change} turns!"; } else { if ($turns_change === 0) { $message .= "__TARGET__ did not lose any turns!"; } else { $message .= "__TARGET__ has lost " . abs($turns_change) . " turns!"; } if ($target->turns <= 0) { // Message when a target has no more turns to remove. $message .= " __TARGET__ no longer has any turns."; } } } if ($item->hasEffect('death')) { $target->death(); $message = "The life force drains from __TARGET__ and they drop dead before your eyes!"; $notice = " be drained of your life-force and die!"; } // Unstealth if (!$item->isCovert() && !$item->hasEffect('stealth') && $user->hasStatus(STEALTH)) { //non-covert acts $user->subtractStatus(STEALTH); } $target->save(); $user->save(); if ($notice) { $notice = " and caused you to {$notice}."; } else { $notice = '.'; } return ['success' => $success, 'message' => $message, 'extra_message' => $extra_message, 'notice' => $notice]; }