<?php
class AccountController extends Controller {
/**
* Creating a new character on an account.
*
* @route POST /account/character/create
* @return \Redirect
*/
public function processCharacterCreation()
{
$rules = Config::get('distro::validation.player.create');
// If no vocation has been selected, or no options were provided to the user,
// we want to default it to 0 (no vocation).
if ( ! Input::has('vocation') or ! Config::get('pandaac::app.vocations'))
{
Input::merge(['vocation' => 0]);
$rules = array_except($rules, 'vocation');
}
// If no town has been selected, or no options were provided to the user,
// we want to default it to 1 (usually rookgaard).
if ( ! Input::has('town') or ! Config::get('pandaac::app.towns'))
{
Input::merge(['town' => 1]);
$rules = array_except($rules, 'town');
}
// Let us validate the user input by the rules defined by the active
// distrobution package. These rules are commonly declared within the
// validation.php config file of said package. You can alter them by
// publishing the config files through Artisan.
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
// Once the validation passes through the aforementioned rules, we will then
// verify that the current account contains less than 20 characters. If that is
// not the case however, the user will be shown yet another error message.
if (Auth::user()->players->count() >= 1)
{
$messages = $validator->errors()->add('name', 'You may not have more than 1 character on your account.');
return Redirect::back()->withErrors($messages)->withInput();
}
// We trigger an event so that developers can freely modify the following bit
// of code through a listener rather than touching the original file. If no
// listener is found, we fallback to the callback provided below.
//
// Event::listen('account.character.creation', function($character)
// {
// ...
// });
$character = new Player;
Event::fallback('account.character.creation', function($character)
{
$character->account_id = Auth::id();
$character->name = name(Input::get('name'));
$character->sex = (int) Input::get('gender');
$character->vocation = (int) Input::get('vocation');
$character->town_id = (int) Input::get('town');
$character->conditions = '';
$character->rank_id = 0;
$character->looktype = $character->sex ? 128 : 136;
$character->lookhead = 78;
$character->lookbody = 69;
$character->looklegs = 58;
$character->lookfeet = 76;
// We fetch the new character level set within the configuration and we
// pass it through the value_args function to pass through any arguments
// if the value is an instance of a closure.
if ($level = value_args(Config::get('pandaac::app.character.level'), $character))
{
$character->level = $level;
}
// We fetch the new character magic level set within the configuration and
// we pass it through the value_args function to pass through any arguments
// if the value is an instance of a closure.
if ($maglevel = value_args(Config::get('pandaac::app.character.maglevel'), $character))
{
$character->maglevel = $maglevel;
}
// We fetch the new character health set within the configuration and we
// pass it through the value_args function to pass through any arguments
// if the value is an instance of a closure.
if ($health = value_args(Config::get('pandaac::app.character.health'), $character))
{
$character->health = $health;
$character->healthmax = $health;
}
// We fetch the new character mana set within the configuration and we
// pass it through the value_args function to pass through any arguments
// if the value is an instance of a closure.
if ($mana = value_args(Config::get('pandaac::app.character.mana'), $character))
{
$character->mana = $mana;
$character->manamax = $mana;
}
// We fetch the new character capacity set within the configuration and we
// pass it through the value_args function to pass through any arguments
// if the value is an instance of a closure.
if ($capacity = value_args(Config::get('pandaac::app.character.capacity'), $character))
{
$character->cap = $capacity;
}
$character->save();
}, $character);
// We trigger an event so that developers can freely modify the following bit
// of code through a listener rather than touching the original file.
//
// Event::listen('account.character.created', function($character)
// {
// ...
// });
Event::fire('account.character.created', $character);
return Redirect::route('account')
->withMessage(Lang::get('pandaac::account.character.create.message.created', ['name' => e($character->name)]));
}
}