Skip to content
Crindigo edited this page Mar 29, 2013 · 1 revision

Modifiers, since the olden days of Zajako's RCS, provided a way to add snippets of code to customize the behavior of items and skills. In Maroon, I want to take this into an event-based direction, having the ability to modify what's executed onAttack, onUse, etc. Items, skills, and other "eventable" objects will have a prioritized event chain in the code. The lowest priority will contain code that handles built-in behaviors that are controlled via the admin. When an action is performed, it will run through the chain and execute all the events set up for the object (unless something like $event->stop(); is called). These event classes should also have the ability to accept parameters, so we can avoid having things like "Cool Atk lv1" and "Cool Atk lv2" that do the same thing but with a different number somewhere.

Some rough code sketched out while thinking:

  <?php
  interface ItemEvents {
    public $parameters = array(); // on a higher interface?
    public function getAdminParameters(); // on a higher interface?
    public function onUse(ItemUseEvent $event);
  }
  
  abstract class AbstractItemEvents implements ItemEvents {
    public function getAdminParameters() {
      return array();
    }
    public function onUse(ItemUseEvent $event) {
    }
  }
  
  class GenericItemEvents extends AbstractItemEvents {
    public function getAdminParameters() {
      return array('modify_hp' => 'int'); // probably more options than this...
    }
    public function onUse(ItemUseEvent $event) {
      $event->action->modifyHP($this->parameters['modify_hp']);
    }
  }

Full Customization

Just a draft for now to quickly jot down what's on my mind. If modifiers are not powerful enough for something, or if it'd be a huge pain to handle it that way, give the ability to set a custom PHP class for an item, skill, job, etc.

One implementation idea:

<?php
class EmergencyRegenArmor extends GenericEquipment {
  /* Gives an HP regeneration rate approaching 20% the closer you are to death. */
  public function getHPRegenerationRate() {
    $hpPercentage = $this->character->getHP() / $this->character->getMaxHP();
    return 0.2 * (1 - $hpPercentage);
  }
}

Clone this wiki locally