POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

Guilds

Guilds system tutorial.

Table of Contents

Guild ranks

Members of each guild are grouped within ranks. There are three types of ranks - leader, vice-leader and regular member. Players have assigned guild ranks which have assigned guild with it. Player is member of that guild, to which his/her rank is assigned. Here is an example solution to list members in oryginal Tibia-like way:

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. // loads guild with ID 1
  7. $guild new OTS_Guild(1);
  8.  
  9. $color '#FFFFCC';
  10.  
  11. echo '<h1>Members of 'htmlspecialchars$guild->getName() )'</h1>';
  12.  
  13. ?>
  14. <table>
  15.     <thead>
  16.         <tr>
  17.             <th>Rank</th>
  18.             <th>Members</th>
  19.         </tr>
  20.     </thead>
  21.     <tbody>
  22. <?php
  23.  
  24. // lists members of all ranks
  25. foreach($guild as $guildRank)
  26. {
  27.     // display rank in first row
  28.     $first true;
  29.     // switches rank rows color
  30.     $color $color == '#FFFFCC' '#FFCCFF' '#FFFFCC';
  31.  
  32.     // list members of this rank
  33.     foreach($guildRank as $player)
  34.     {
  35.         echo '<tr style="background-color: '$color'">
  36.     <td>'$first htmlspecialchars$guildRank->getName() ) '''</td>
  37.     <td>'$player->getName()'</td>
  38. </tr>';
  39.         $first false;
  40.     }
  41. }
  42.  
  43. ?>
  44.     </tbody>
  45. </table>

Guild action drivers

Mechanism known from oryginal Tibia to put new members into guild is based on invitations. However - OTServ and it's database doesn't provide such featue as it is quite abstract logic which has nothing to do with it's core code. So basicly you would need to write everything completly on your own. But in POT you can bind your logic layer with action driver - object which will handle guild operations and use your code to execute invitations.

Guild class contains methods to handle invitations: listInvites(), invite(), deleteInvite() and acceptInvite(). However remember, that those are only bindings for abstract logic - you have to implement driver for them. Here is an example class that will handle invitations:

  1. <?php
  2.  
  3. // to not repeat all that stuff
  4. include('quickstart.php');
  5.  
  6. /*
  7.     POT guilds invites driver.
  8. */
  9.  
  10. class InvitesDriver implements IOTS_GuildAction
  11. {
  12.     // assigned guild
  13.     private $guild;
  14.  
  15.     // initializes driver
  16.     public function __construct(OTS_Guild $guild)
  17.     {
  18.         $this->guild $guild;
  19.         // this line automates the process - you can call it manualy from outside, but why?
  20.         $this->guild->setInvitesDriver($this);
  21.     }
  22.  
  23.     // returns all invited players to current guild
  24.     public function listRequests()
  25.     {
  26.         $invites array();
  27.  
  28.         /* here you must create OTS_Player object for each invited player */
  29.  
  30.         return $invites;
  31.     }
  32.  
  33.     // invites player to current guild
  34.     public function addRequest(OTS_Player $player)
  35.     {
  36.         /* here you must save invitation for given player */
  37.     }
  38.  
  39.     // un-invites player
  40.     public function deleteRequest(OTS_Player $player)
  41.     {
  42.         /* here you must delete invitation for given player */
  43.     }
  44.  
  45.     // commits invitation
  46.     public function submitRequest(OTS_Player $player)
  47.     {
  48.         $rank null;
  49.  
  50.         // finds normal member rank
  51.         foreach$this->guild->getGuildRanks(as $guildRank)
  52.         {
  53.             if$guildRank->getLevel(== 1)
  54.             {
  55.                 $rank $guildRank;
  56.                 break;
  57.             }
  58.         }
  59.  
  60.         $player->setRank($rank);
  61.         $player->save();
  62.  
  63.         // clears invitation
  64.         $this->deleteRequest($player);
  65.     }
  66. }
  67.  
  68. /*
  69.     Parts of this class driver has been taken from OTSCMS (http://otscms.com/) project source code.
  70. */
  71.  
  72. // loads player wiht ID 1
  73. $player new OTS_Player();
  74. $player->load(1);
  75.  
  76. // loads guild with ID 1
  77. $guild new OTS_Guild();
  78. $guild->load(1);
  79.  
  80. // creates invitation logic driver for your implementation for current guild
  81. new InvitesDriver($guild);
  82.  
  83. // note that you call guild method!
  84. $guild->invite($player);
  85.  
  86. ?>

Two ways

OTS_Guild class provides bindings for two kinds of actions - invitations and membership requests. They are both similar, they only differs direction in which actions are taken. Invitations are initiated by guild leaders to give player possiblity to join the guild. Requests are sent by player and after being accepted by any of leaders player is included into the guild.


Prev Up Next
Players DAO objects List objects