/[drupal]/contributions/modules/rpg/inc/rpg.hooks.php
ViewVC logotype

Contents of /contributions/modules/rpg/inc/rpg.hooks.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Sat Apr 26 01:03:25 2008 UTC (19 months ago) by aaron
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +28 -4 lines
File MIME type: text/x-php
catchup
1 <?php
2 // $Id: rpg.hooks.php,v 1.10 2008/03/08 00:31:04 aaron Exp $
3
4 /**
5 * @file
6 * This is the API for rpg hooks.
7 * These functions are not actually called directly, but are rather hooks to be used in contributed modules,
8 * that will be called as appropriate from internal RPG functions. Examples are given for the benefit of
9 * contributing programmers. As with all Drupal hooks, replace 'hook' with the internal name of the module.
10 */
11
12 /**
13 * This is called when a new or edited RPG type is saved. Use for saving extra data to the database, etc.
14 * This hook is only called from the module defining that type. It is called both when a type is added programmatically,
15 * and when defined from an admin form. It is called directly after the type is inserted or updated in the database,
16 * but before the global rpg_types array is updated.
17 *
18 * @ingroup hooks
19 */
20 function hook_rpg_save_type($type) {
21 }
22
23 /**
24 * This will load any module-defined custom types, for use by other types and RPG objects.
25 * This function is called when loading rpg types into the system. Note that types are cached, and that admins may override
26 * or delete types manually. Thus, this function is only called when initially creating/updating the type, and may be
27 * overridden later.
28 *
29 * @ingroup hooks
30 */
31 function hook_rpg_load_types() {
32 }
33
34 /**
35 * This hook defines various classes for attributes, such as Number, Text, and Figured. When an attribute is created,
36 * this hook is called according to the assigned class. It will determine what columns to add to dynamically created
37 * tables for both types and objects, and also create form elements for admin display.
38 *
39 * @param $op
40 * This determines the operation being called. Must be a string of one of the following values:
41 * 'save': This defines the columns to save for each type. Must return an array of column names as strings.
42 * 'data': This defines the columns to save object-specific data. Must return an associative array in the
43 * following format: $data['column-name'] = array('type' => 'int|text|varchar', ['not null' => true|false,
44 * 'default' => true|false, 'sortable' => true|false, etc.]);
45 * The values passed will be used to create new columns in the rpg_attribute_rpg_[attribute-name] table.
46 * 'form': This defines form elements to display to the admin when adding/editing the type form.
47 *
48 * @param $class
49 * This is the string name of the class, such as 'number' or 'text'.
50 *
51 * @param $attribute = NULL
52 * This is an array defining the attribute in question.
53 *
54 * @return
55 * The return value depends on the $op. An array is expected in each case, but see above for the values expected.
56 *
57 * @ingroup hooks
58 */
59 function hook_rpg_attribute_class_settings($op, $class, $attribute = NULL) {
60 }
61
62 /**
63 * This hook is used to define what rpg types may be used as player characters for users to choose from.
64 *
65 * Typically used by Rulesets, but any module may use the hook. This is used primarily to create the lists
66 * from /rpg/create/pc.
67 *
68 * @param $user
69 * The user creating the PC. This may be used to limit the available PC types, according to the user's role access settings,
70 * or other criteria, such as whether a user has achieved a certain quest with another character.
71 * @return
72 * An array of types that may be used when creating pc's
73 *
74 * @ingroup hooks
75 */
76 function hook_rpg_pc_types($user) {
77 $current_pcs = rpg_user_pcs($user);
78 if (sizeof($current_pcs) >= 5 && !user_access('administer rpg')) {
79 // don't allow users more than 5 characters
80 return array();
81 }
82 $types = array('human', 'robot', 'elf' => 'elf');
83 if (user_access('super rpg')) {
84 $types[] = 'giant';
85 }
86 if (in_array('power gamer', $user->roles)) {
87 $types[] = 'vampire_cyborg';
88 }
89 foreach ($current_pcs as $pc) {
90 if (module_invoke('rpg_achieve', 'get', 'traversed_labrynth', $pc)) {
91 $types['minotaur'] = 'minotaur';
92 }
93 // only allow one elf per user
94 if (rpg_is_a($pc, 'elf')) {
95 unset($types['elf']);
96 }
97 }
98 return $types
99 }
100
101 /**
102 * Messages are passed using a data structure, which may be altered using hook_rpg_message_alter.
103 *
104 * Messages are an array in the following form:
105 * '#mid' => the unique message id of the message
106 * '#created' => the time of creation of the message
107 * '#action' => the action originally defining the message
108 * '#message' => the default message to be output, ultimately sent through t() using the other parameters
109 * '#who' => who is performing the action (defaults to $rpg['pc'])
110 * '#target' => the target of the action
111 * '#with' => what who is using to do action to target
112 * '#listeners' => an array of objects who receive the message as observers
113 * '#room' => the room where the action takes place (defaults to #who's top room)
114 * '#who_message' => the message to be displayed to #who (overriding #message if provided)
115 * '#target_message' => the message to be displayed to #target (overriding #message if provided)
116 * '#what_message' => the message to be displayed to #what (overriding #message if provided)
117 * '#observer_message' => the message to be displayed to anyone else viewing the action (overriding #message if provided)
118 * '#args' => an array of extra args to be sent to the resulting t() message, in the form of '!key' => l('!key', 'url/' . $key).
119 * this will be done automatically for who, target, with, and room.
120 *
121 * Examples:
122 * using the 'take' action:
123 * $message = array(
124 * '#action' => 'take',
125 * '#message' => '!who takes !target.',
126 * '#who' => $who,
127 * '#target' => $target,
128 * '#who_message' => 'You take !target.',
129 * '#target_message' => '!who takes you.'
130 * );
131 * This will ultimately resolve to
132 * t('!who takes !target', array('!who' => l(rpg_get('name', $who), 'rpg/view/' . $who->rid), '!target' => l(rpg_get('name', $target), 'rpg/view/' . $target->rid)))
133 *
134 * @param $message
135 * The message data structure, as defined above.
136 */
137 function hook_rpg_message_alter(&$message) {
138 if ($message['#action'] == 'take') {
139 if (rpg_get('location', $message['#target']) == rpg_get('top_room', $message['#who'])) {
140 $message['#message'] = '!who lifts !target from the floor.';
141 $message['#who_message'] = 'You lift !target from the floor.';
142 $message['#target_message'] = '!who lifts you from the floor.';
143 }
144 }
145 }
146
147
148 function hook_rpg_object_alter(&$object, $op) {
149 switch ($op) {
150 case 'load':
151 break;
152 }
153 }

  ViewVC Help
Powered by ViewVC 1.1.2