/** * Constructor * HeroPower is abstract, but the extended classes hold information about triggers and functionality * * @param array $options Options to set during initialization */ public function __construct(array $options = []) { // Listen to board start $options['listeners'] = [EntityEvent::EVENT_BOARD_TURN_START]; // Call the parent constructor to set up events, etc. parent::__construct($options); }
/** * Method to add a minion to the battlefield * * @param \PHPHearthSim\Model\Entity $entity * @param \PHPHearthSim\Model\Player $player * @param int|null $newPosition The new entity position, if null we place it at the end * * @throws \PHPHearthSim\Exception\Board\InvalidBattlefieldOwnerException when player is not instance of Player * @throws \PHPHearthSim\Exception\Board\InvalidBattlefieldEntityException when entity is not instance of Minion * @return boolean "true" if entity was placed on battlefield, "false" if entity was not placed on battlefield */ public function addToBattlefield(Entity $entity, Player $player, $newPosition = null) { // Make sure $player is a Player if (!$player instanceof Player) { throw new InvalidBattlefieldOwnerException('Owner of entity passed is not an instance of type Player'); } // Make sure entity is a minion, can't play spell on the battlefield! if (!$entity instanceof Minion) { throw new InvalidBattlefieldEntityException('Only entities of type Minion can be placed on the battlefield'); } // Update entity references $entity->setBoard($this); $entity->setOwner($player); // Get minions $minions = $this->getBattlefieldForPlayer($player); // Make sure we have room for another minion if (count($minions) < Board::MAX_BATTLEFIELD_SIZE) { // If not position is provided, we generate a new index if ($newPosition == null) { $newPosition = count($minions); } // Insert minion at position array_splice($minions, $newPosition + 1, 0, [$entity]); // Update battlefield for player $this->battlefield[$player->getid()] = $minions; return true; } return false; }
/** * Trigger healing on entity * * @param number $amount The amount of healing received * @param \PHPHearthSim\Model\Entity $from The entity that did the healing to us * @return \PHPHearthSim\Model\Entity */ public function healFor($amount = 0, Entity $from = null) { // Just make sure damage is a positive value so we don't get any wierd interactions if ($amount < 0) { $amount = 0; } // Check and adjust values if ($from != null) { // Professor Velen doubles the healing received if ($this->getBoard()->isOnBattlefield('PHPHearthSim\\Game\\Minion\\P\\ProfessorVelen', $from->getOwner())) { $amount = $amount * 2; } // Auchenai Soulpriest turns healing into damage if ($this->getBoard()->isOnBattlefield('PHPHearthSim\\Game\\Minion\\A\\AuchenaiSoulpriest', $from->getOwner())) { return $this->takeDamage($amount, $from); } } // Apply adjustment to health $this->addAdjustment(new EntityAdjustment(EntityAdjustment::ADJUSTMENT_HEALTH, $amount)); // Emit that we received healing $this->emit(EntityEvent::EVENT_ENTITY_RECEIVE_HEAL, ['amount' => $amount]); return $this; }