To begin with we are going to create our character class in symfony. Go to [GameName]/config/doctrine/schema.yml and here we will create a character class that will consist of a name, a race, a sex, a current class, a level, and a position in the game world. It will look like the following:
[GameName]Character:
actAs: { Timestampable: ~ }
columns:
user_id: { type: integer, notnull: true }
name: { type: string(255), unique: true}
sex: { type: string(1) }
class: { type: string(50) }
level: {type: integer, default: 1}
position_x: {type: integer, default: 0 }
position_y: {type: integer, default: 0 }
relations:
sfGuardUser:
type: one
foreignType: many
class: sfGuardUser
local: user_id
foreign: id
onDelete: cascade
foreignAlias: Characters
This will give us our basic class. From here you will want to run symfony doctrine:build --all from your command line in the xampp/[GameName] folder so that it will rebuild your database and include the new class.
From here you will want to go over to the [GameName]Entities project in netbeans and right click and hit Entity Classes from Database. When it loads up the list select [GameName]Character and add it to the right side and click finish.
You will now have a new class in your entity project. You can now use this in the Extension project to create, load, and work with your users' characters.
We now have 2 empty tables that need to be filled. one is [GameName]UserProfile which has the number of character slots the account has. The other is the new [GameName]Character table.
First we need to fill the UserProfile table. To do this, we want to go into our php project and open up app/frontend/modules/game/actions/action.class.php and replace the inside of the executeIndex function with this:
$guardUser = $this->getUser()->getGuardUser();
$characters = $guardUser->getCharacters();
$profile = $guardUser->getProfile();
if($profile == '' )
{
$profile = new AegisBornUserProfile();
$profile->setCharacterSlots(1);
$profile->setSfGuardUser($guardUser);
$profile->save();
}
This block of code attempts to load the users profile and if one does not exist, creates it for them. It gives them 1 character slot and saves that to the database. Without this bit of code, we cannot send the client this information and they won't be able to create any characters. You will now want to log into the web site so that the profile gets created.
In Part 2 we will look at creating the UI in Unity3d so that we can get to a character creation screen and provide the user with the options to fill out the character.
No comments:
Post a Comment