mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 17:59:22 +02:00

* wip * wip * wip * wip * wip * fix: reusing pdo connection from pot * wip * wip * wip * wip * move files In future, all classes will be in src/ folder * Replace namespace name, for future * Remove duplicated exception * Fix towns from db * Fix spells page * Add default FAQ question + FAQ model * feat: reset colors in menus * Add confirm + save button at the top (menus) * Do not insert duplicated FAQ on install * Refactor install menus * Fix changelogs showing * Fix menu update, only with specified template name * Fix account create -> missing compat * Fix bans_per_page * banned_by is player_id. type = 2 is namelock in tfs 0.3 * Add getPlayerNameById, fix getPlayerNameByAccount * Change link name * Order by lastlogin * fix: query optimize * wip * wip * wip * wip * wip * wip * wip * Refactor notepad.php, class was useless * This is showing error, if the updated rows = 0 * Fix success & error class (bootstrap) * Uncomment require migrate.php * Some distro have owner_id * Update Player.php --------- Co-authored-by: slawkens <slawkens@gmail.com>
139 lines
2.4 KiB
PHP
139 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace MyAAC\Models;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Player extends Model {
|
|
|
|
protected $table = 'players';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $casts = [
|
|
'worldid' => 'integer',
|
|
'sex' => 'integer',
|
|
'level' => 'integer',
|
|
'vocation' => 'integer',
|
|
'promotion' => 'integer',
|
|
'looktype' => 'integer',
|
|
'lookhead' => 'integer',
|
|
'lookbody' => 'integer',
|
|
'looklegs' => 'integer',
|
|
'lookfeet' => 'integer',
|
|
'lookaddons' => 'integer',
|
|
'isreward' => 'integer',
|
|
];
|
|
|
|
public function scopeOrderBySkill($query, $value)
|
|
{
|
|
global $db;
|
|
$query->when($db->hasColumn('players', 'skill_fist'), function ($query) {
|
|
|
|
});
|
|
}
|
|
|
|
public function getVocationNameAttribute()
|
|
{
|
|
$vocation = $this->vocation;
|
|
if (isset($this->promotion)) {
|
|
$vocation *= $this->promotion;
|
|
}
|
|
|
|
return config('vocations')[$vocation] ?? 'Unknown';
|
|
}
|
|
|
|
public function getIsDeletedAttribute()
|
|
{
|
|
if (isset($this->deleted)) {
|
|
return $this->deleted !== 0;
|
|
}
|
|
|
|
if (isset($this->deletion)) {
|
|
return $this->deletion !== 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function scopeNotDeleted($query) {
|
|
global $db;
|
|
|
|
$column = 'deleted';
|
|
if($db->hasColumn('players', 'deletion')) {
|
|
$column = 'deletion';
|
|
}
|
|
|
|
$query->where($column, 0);
|
|
}
|
|
|
|
public function scopeWithOnlineStatus($query) {
|
|
global $db;
|
|
$query->when($db->hasTable('players_online'), function ($query) {
|
|
$query->with('onlineTable');
|
|
});
|
|
}
|
|
|
|
public function getOnlineStatusAttribute()
|
|
{
|
|
global $db;
|
|
if ($db->hasColumn('players', 'online')) {
|
|
return $this->online;
|
|
}
|
|
|
|
if ($db->hasTable('players_online')) {
|
|
return $this->onlineTable != null;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function onlineTable()
|
|
{
|
|
return $this->belongsTo(PlayerOnline::class);
|
|
}
|
|
|
|
public function account()
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
public function storages()
|
|
{
|
|
return $this->hasMany(PlayerStorage::class);
|
|
}
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany(PlayerItem::class);
|
|
}
|
|
|
|
public function kills()
|
|
{
|
|
return $this->hasMany(PlayerKillers::class);
|
|
}
|
|
|
|
public function deaths()
|
|
{
|
|
return $this->hasMany(PlayerDeath::class);
|
|
}
|
|
|
|
public function houses()
|
|
{
|
|
return $this->hasMany(House::class, 'owner');
|
|
}
|
|
|
|
public function skills()
|
|
{
|
|
return $this->hasMany(PlayerSkill::class);
|
|
}
|
|
|
|
public function viplist()
|
|
{
|
|
return $this->hasMany(PlayerVipList::class);
|
|
}
|
|
|
|
public function scopeOnline($query) {
|
|
$query->where('online', '>', 0);
|
|
}
|
|
}
|