Adding Actions - bugladen/bga7s5s GitHub Wiki
Actions are handled as separate classes attached to Characters. To implement an Action, first choose what type of action you are going to create. This affects what Action class you are going to be inheriting from. The inherited classes included useful and essential functionality:
Inherited Class | Reasoning |
---|---|
AttachmentAction | Use for Actions on Attachments. |
CharacterAction | Use for Actions on Characters who are self-performing. |
EventCityAction | Use for Actions attached to City Event Cards. |
RiskAction | Use for Actions attached to Risk cards that are played from hand. |
Create Class File
Create a file called Action_XXXXX
, where X is the card number. Place this file in the modules\php\cards\actions\
folder. Create a skeleton class like the one described below.
class Action_01180 extends CharacterAction
{
public function __construct()
{
parent::__construct();
$this->Name = "Equip Artifact from City Deck";
}
}
Set the Name
property of the class to a short but descriptive phrase. Name
is what will be displayed on the title bar of the UI as a button, along with all other actions that are available.
Implement isAvailableToPlayer() Method
This method is called by the framework and will determine if the action will be show on the interface as an available action. Always call the parent method and return if the result is false.
Add code to check for specific conditions. For example, this checks to see if Kaj is in the city.
public function isAvailableToPlayer(int $playerId, Theah $theah): bool
{
if ( ! parent::isAvailableToPlayer($playerId, $theah))
{
return false;
}
$kaj = $this->getOwningCard($theah);
return $theah->cardInCity($kaj);
}