EQdkp Plus Navigation:   Home  |   Forum  |   Wiki  |   Translate  |   Bugtracker  |   WebSVN  |  USVN

Multigame

From EQdkp Plus Wiki

The game-class manages all game-specific information. It can be called by "global $game;". The information about the game are stored in the games-folder. For e.g. WoW: "games/WoW/WoW.class.php". Additionally there are the language files (e.g. english.php) and the images in their folders.

Contents

Game-Class Functions

$type

In many functions $type is used. $type is a string and for e.g. WoW you have the following types: 'classes', 'races', 'factions', 'filters', 'realmlist'.

get_RenderImages
get_RenderImages($class_id=-1, $race_id=-1, $member_name='', $member_xml=false, $realm='', $options=false)
redirects to the function defined in the <gamename>.class.php or, if this does not exists, but 3dmodels are available, creates them. otherwise returns nothing (an empty string).
get_games
get_games()
returns all available games with their "code" (e.g. array('wow', 'lotro'))
get_game
get_game()
returns current game.
type_exists
type_exists($type)
checks if the given $type exists in the selected game. return boolean.
icon_exists
icon_exists($icon)
checks if the given $icon exists in the selected game. return boolean.
glang
glang($var, $lang=false)
return the language string in the given language, if not default language (user->lang).
callFunc
callFunc($function_name, $params)
calls function of game class
new_object
new_object($classname, $index, $params=NULL, $force_new=false, $overwrite_index=false)
creates a new instance of the given class $classname and stores this instance in $game->obj[$index].
the class must be listed in the game-specific class (e.g. wow.class.php) in the objects-array.
$params is an array containing all params passed to constructor
if $force_new is false before instantiating a new class it checks if an older instance exists and returns the index.
if $overwrite_index is false the function returns false if there already exists an element on that index.
return false or the index of the class.
get_class_color
get_class_color($class_id)
return hex_class_color_code for given class.
get
get($type, $filter=array(), $lang=false)
return array of the type in the given language (or default language)
possible filters:
filtername Description
id_0 remove dataset for id=0
get_id
get_id($type, $name, $searched=false)
return id for the given name in the type. e.g.(game wow): get_id('classes', 'Hunter') returns 3.
get_name
get_name($type, $id, $lang=false)
return name of id in given or default language.
decorate
decorate($type, $params)
$type is e.g. classes, races, etc.; $params are the params needed for the decoration function (see below)
Redirects to decoration functions. First search in the specificgame class, second search for default function, otherwise falls back to simple name
Default Decoration functions:
decorate_classes($class_id, $big=false, $pathonly=false)
returns image tag with class icon (big image if wanted) or only the path to the image
decorate_races($race_id, $gender=false, $pathonly=false)
returns image tag with race icon in gender or only the path to the image
decorate_ranks($rank_id, $size=16, $pathonly=false)
returns image tag with rank image in size (height and width)
decorate_talents($class_id, $talent=0, $pathonly=false)
returns image tag with talent images for talentskill ($talent, 0-2 for wow)
decorate_events($icon, $size=16, $pathonly=false)
similar to rank
decorate_roles($role_id, $size=20, $pathonly=false)
returns image tag with role images for $role_id
Examples
  • If we want a class-icon: $game->decorate('classes', array($class_id));
  • If we want a path to an event-icon $game->decorate('events', array($pdh->get('event', 'icon', array($event_id)), 0, true)); //the size does not matter here, because we only want the path
  • If we want the 2nd talent tree for a class $game->decorate('talents', array($class_id, 1)); //we use 1 for the talent because 0 = 1st, 1 = 2nd, 2 = 3rd
ChangeGame
ChangeGame($newgame, $lang)
returns DB-Updates for game changing

Adding a new game

Every Game has its own class where all information are saved. The file has to be named <gamename>.class.php (e.g. wow.class.php) and must lie in the games/<gamename> folder. The gamename should only be in small letters! The first lines should be this: So it is not possible to access that file directly. It should only be included.

<?php
if ( !defined('EQDKP_INC') )
{
    header('HTTP/1.0 404 Not Found');
    exit;
}

Afterwards we start the definition of our class: The class is named after the game!

if(!class_exists('wow')) {
  class wow extends game_generic
  {

The next thing we have to do is to define which information the class holds:

    private $this_game = 'wow';
    private $types = array('classes', 'races', 'factions', 'filters', 'realmlist');       // which information are stored?
    private $classes = array();							          //
    private $races = array();							          // for each type there must be the according var
    private $factions = array();							  // and the according function: load_$type
    private $filters = array();							          //
    private $realmlist = array();							  //
 
    public  $objects = array('wow_modelviewer'); // eventually there are some objects  (php-classes) in this game (stored in objects. e.g. 
                                                 //                                                               wow_modelviewer.class.php)
    public  $langs = array('english', 'german', 'french', 'russian');			  // in which languages do we have information?
    public  $icons = array('classes', 'races', 'ranks', 'events', 'talents', '3dmodel');  // which icons do we have?

The first must-have-function is the function "get_OnChangeInfos":

	/**
	 * Returns Information to change the game
	 *
	 * @param bool $install
	 * @return array
	 */
	public function get_OnChangeInfos($install=false)
	{
	    //if there exist class_colors add them here
	    $info['class_color'] = array(
                $class_id => #hex_code,
                //e.g.:
                6 => '#FFFFFF',
            );
 
	    //here we add sql-queries, which shall be done on every game-change
	    $info['aq'] = array(
                //for e.g. WoW we have special logos in some templates, so change the logo_path
	        "UPDATE __style_config SET logo_path='/logo/logo_wow.gif' WHERE style_id = 14  ;",
                // [...]
	        "UPDATE __style_config SET logo_path='wowlogo3.png' WHERE style_id = 35  ;",
	        //Itemstats exists for WoW, so we ensure, that there will be correct information for itemstats 
   		"UPDATE __config SET config_value = 'armory_wowhead' WHERE config_name = 'pk_is_webdb' ;",
    		"UPDATE __config SET config_value = 'http://wowdata.buffed.de/img/icons/wow/32/' WHERE config_name = 'pk_is_icon_loc' ;",
                "UPDATE __config SET config_value = '1' WHERE config_name = 'pk_itemstats' ;",
                "UPDATE __config SET config_value = '0' WHERE config_name = 'pk_is_autosearch' ;",
	    );
 
	    //here we add sql-queries which shall only be done on the first install of eqdkp
	    if($install)
	    {
                        //for WoW we have some events, most one want:
			array_push($info['aq'], "INSERT INTO __events VALUES (1, 'Ulduar (10)', 0.00, 'default', NULL, 'ulduar3.png'); ");
                        // [...]
			array_push($info['aq'], "INSERT INTO __events VALUES (8, 'Sartharion (25)', 0.00, 'default', NULL, 'wotlk-raid-obsidian_sanctum_25.gif'); ");
			//default links
			array_push($info['aq'], "INSERT INTO __plus_links (`link_url`, `link_name`, `link_window`, `link_menu`) VALUES ('eu.wowarmory.com', 'Armory', 1, 0);");
			array_push($info['aq'], "INSERT INTO __plus_links (`link_url`, `link_name`, `link_window`, `link_menu`) VALUES ('www.wow-europe.com', 'WoW-Europe', 1, 0);");
		}
		return $info;
	}

Afterwards you have to write a load_filters function. Here you have to define which filters shall be selectable. Each filter is an array with $name => $value. The $name is what you want to have displayed. The $value is what shall be selected. (e.g.: classes with the ids 1 and 4 => 'class:1,4').

/**
 * Initialises filters
 *
 * @param array $langs
 */
private function load_filters($langs)
{
    global $user;
    //we want to display class_names so we need to load them, if they are not already loaded
    if(!$this->classes) {
        $this->load_classes($langs);
    }
    foreach($langs as $lang) {
        //here we store the class_names
	$names = $this->classes[$this->lang];
    	$this->filters[$lang] = array(
            //the first entry should have a false value
	    array('name' => '-----------', 'value' => false),
    	    array('name' => $names[0], 'value' => 'class:0'),
            // [...]
	    array('name' => $names[10], 'value' => 'class:10'),
	    array('name' => '-----------', 'value' => false),
            //here we load the name of the filter from the game_language
	    array('name' => $this->glang('plate', $lang), 'value' => 'class:1,5,10'),
	    array('name' => $this->glang('mail', $lang), 'value' => 'class:3,8'),
            // [...]
	);
    }
}

It is possible to create a load function foreach type. The function name must be load_$type.

Now all the "must-have" functions are there. If you want you can define here custom decorate functions or custom functions, which are game-specific. They can be called via $game->callFunc('funcname', array $params);

Now we have finished the wow.class.php! Don't forget to add
 ?>
at the end of the file. There must not be any whitespaces or line breaks after the "?>"!

Next we have to create our language files. For each language we specified in the WoW.class.php we need an extra file. So in this case: english.php, german.php, french.php, russian.php. Because the language files also shall only be included, we add

<?php
if ( !defined('EQDKP_INC') )
{
    header('HTTP/1.0 404 Not Found');
    exit;
}

at the beginning of the file. What follows now is one array with all the "language" information about the game. german.php of WoW:

//The array is named <languagename>_array!
$german_array = array(
        // the index 'classes' can be chosen freely, but if it differs from the 'type', you need a load function for that type!
        // First we define our classes: class_id => class_name. The ID's must be the same in the other languages!
        // For the first language you create you can choose the ID freely, but the ID "0" always should belong to "Unknown"
	'classes' => array(
		0 => 'Unbekannt',
		1 => 'Todesritter',
		2 => 'Druide',
                // [...]
	),
        //same for the races
	'races' => array(
		'Unknown',
		'Gnom',
		'Mensch',
                // [...]
	),
        //and same for the factions
	'factions' => array('Allianz', 'Horde'),
        //here we define all game specific language-vars
	'lang' => array(
		'plate' => 'Platte',
		'cloth' => 'Stoff',
                // [...]
                // in WoW we have names for talent-trees they are stored in the lang_var 'talents'.
                // each class has 3 talent-trees so we have an assignment: $class_id => array('talent_tree0', 'talent_tree1', 'talent_tree2')
		'talents' => array(
	            1 => array('Blut','Frost','Unheilig'),
                    // [...]
		),
	),
        //here follow the realms
	'realmlist' => array(
        "Aegwynn",
        "Alexstrasza",
        // [...]
    ),
);

Now the file is complete. End it with "?>"! Now you only have to add the images into their folders, and you have successfully added a new Game to EQDKP-Plus!