mirror of
https://github.com/slawkens/myaac.git
synced 2025-11-20 09:16:23 +01:00
[WIP] Rewrite OTS_Player class
This commit is contained in:
@@ -249,10 +249,10 @@ else if (isset($_REQUEST['search'])) {
|
|||||||
$player->setLookHead($look_head);
|
$player->setLookHead($look_head);
|
||||||
$player->setLookLegs($look_legs);
|
$player->setLookLegs($look_legs);
|
||||||
$player->setLookType($look_type);
|
$player->setLookType($look_type);
|
||||||
if ($hasLookAddons)
|
if ($hasLookAddons) {
|
||||||
$player->setLookAddons($look_addons);
|
$player->setLookAddons($look_addons);
|
||||||
if ($db->hasColumn('players', 'offlinetraining_time'))
|
}
|
||||||
$player->setCustomField('offlinetraining_time', $offlinetraining);
|
|
||||||
$player->setPosX($pos_x);
|
$player->setPosX($pos_x);
|
||||||
$player->setPosY($pos_y);
|
$player->setPosY($pos_y);
|
||||||
$player->setPosZ($pos_z);
|
$player->setPosZ($pos_z);
|
||||||
@@ -275,23 +275,11 @@ else if (isset($_REQUEST['search'])) {
|
|||||||
if ($hasBlessingsColumn)
|
if ($hasBlessingsColumn)
|
||||||
$player->setBlessings($blessings);
|
$player->setBlessings($blessings);
|
||||||
|
|
||||||
if ($hasBlessingColumn) {
|
|
||||||
for ($i = 1; $i <= $bless_count; $i++) {
|
|
||||||
$a = 'blessing' . $i;
|
|
||||||
$player->setCustomField('blessings' . $i, ${'blessing' . $i} ? '1' : '0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$player->setBalance($balance);
|
$player->setBalance($balance);
|
||||||
if ($db->hasColumn('players', 'stamina'))
|
if ($db->hasColumn('players', 'stamina'))
|
||||||
$player->setStamina($stamina);
|
$player->setStamina($stamina);
|
||||||
if ($db->hasColumn('players', 'deletion'))
|
|
||||||
$player->setCustomField('deletion', $deleted ? '1' : '0');
|
$player->setDeleted($deleted ? '1' : '0');
|
||||||
else
|
|
||||||
$player->setCustomField('deleted', $deleted ? '1' : '0');
|
|
||||||
$player->setCustomField('hide', $hide ? '1' : '0');
|
|
||||||
$player->setCustomField('created', $created);
|
|
||||||
if (isset($comment))
|
|
||||||
$player->setCustomField('comment', $comment);
|
|
||||||
|
|
||||||
foreach ($_POST['skills'] as $skill => $value) {
|
foreach ($_POST['skills'] as $skill => $value) {
|
||||||
$player->setSkill($skill, $value);
|
$player->setSkill($skill, $value);
|
||||||
@@ -300,6 +288,24 @@ else if (isset($_REQUEST['search'])) {
|
|||||||
$player->setSkillTries($skill, $value);
|
$player->setSkillTries($skill, $value);
|
||||||
}
|
}
|
||||||
$player->save();
|
$player->save();
|
||||||
|
|
||||||
|
if ($db->hasColumn('players', 'offlinetraining_time')) {
|
||||||
|
$player->setCustomField('offlinetraining_time', $offlinetraining);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hasBlessingColumn) {
|
||||||
|
for ($i = 1; $i <= $bless_count; $i++) {
|
||||||
|
$a = 'blessing' . $i;
|
||||||
|
$player->setCustomField('blessings' . $i, ${'blessing' . $i} ? '1' : '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$player->setCustomField('hide', $hide ? '1' : '0');
|
||||||
|
$player->setCustomField('created', $created);
|
||||||
|
if (isset($comment)) {
|
||||||
|
$player->setCustomField('comment', $comment);
|
||||||
|
}
|
||||||
|
|
||||||
echo_success('Player saved at: ' . date('G:i'));
|
echo_success('Player saved at: ' . date('G:i'));
|
||||||
$player->load($id);
|
$player->load($id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,46 @@ if ($db->hasTable('players')) {
|
|||||||
|
|
||||||
$query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($p['name']));
|
$query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($p['name']));
|
||||||
if ($query->rowCount() == 0) {
|
if ($query->rowCount() == 0) {
|
||||||
if (!query("INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `lastlogout`, `balance`, `$deleted`, `created`, `hide`, `comment`) VALUES (null, " . $db->quote($p['name']) . ", 1, " . getSession('account') . ", " . $p['level'] . ", " . $p['vocation_id'] . ", " . $p['health'] . ", " . $p['healthmax'] . ", " . $p['experience'] . ", 118, 114, 38, 57, " . $p['looktype'] . ", 0, " . $p['mana'] . ", " . $p['manamax'] . ", 0, " . $p['soul'] . ", 1, 1000, 1000, 7, '', " . $p['cap'] . ", 1, " . $time . ", 2130706433, 1, " . $time . ", 0, 0, " . $time . ", 1, '');"))
|
$player = new OTS_Player();
|
||||||
$success = false;
|
|
||||||
|
$player->setData([
|
||||||
|
'name' => $p['name'],
|
||||||
|
'group_id' => 1,
|
||||||
|
'account_id' => getSession('account'),
|
||||||
|
'level' => $p['level'],
|
||||||
|
'vocation' => $p['vocation_id'],
|
||||||
|
'health' => $p['health'],
|
||||||
|
'healthmax' => $p['healthmax'],
|
||||||
|
'experience' => $p['experience'],
|
||||||
|
'lookbody' => 118,
|
||||||
|
'lookfeet' => 114,
|
||||||
|
'lookhead' => 38,
|
||||||
|
'looklegs' => 57,
|
||||||
|
'looktype' => $p['looktype'],
|
||||||
|
'maglevel' => 0,
|
||||||
|
'mana' => $p['mana'],
|
||||||
|
'manamax' => $p['manamax'],
|
||||||
|
'manaspent' => 0,
|
||||||
|
'soul' => $p['soul'],
|
||||||
|
'town_id' => 1,
|
||||||
|
'posx' => 1000,
|
||||||
|
'posy' => 1000,
|
||||||
|
'posz' => 7,
|
||||||
|
'conditions' => '',
|
||||||
|
'cap' => $p['cap'],
|
||||||
|
'sex' => 1,
|
||||||
|
'lastlogin' => $time,
|
||||||
|
'lastip' => 2130706433,
|
||||||
|
'save' => 1,
|
||||||
|
'lastlogout' => $time,
|
||||||
|
'balance' => 0,
|
||||||
|
$deleted => 0,
|
||||||
|
'created' => $time,
|
||||||
|
'hide' => 1,
|
||||||
|
'comment' => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$player->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$__load = array();
|
|
||||||
/*
|
use MyAAC\Models\Player as PlayerModel;
|
||||||
'loss_experience' => NULL,
|
|
||||||
'loss_items' => NULL,
|
|
||||||
'guild_info' => NULL,
|
|
||||||
'skull_type' => NULL,
|
|
||||||
'skull_time' => NULL,
|
|
||||||
'blessings' => NULL,
|
|
||||||
'direction' => NULL,
|
|
||||||
'stamina' => NULL,
|
|
||||||
'world_id' => NULL,
|
|
||||||
'online' => NULL,
|
|
||||||
'deletion' => NULL,
|
|
||||||
'promotion' => NULL,
|
|
||||||
'marriage' => NULL
|
|
||||||
);*/
|
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* @version 0.0.1
|
* @version 0.0.1
|
||||||
@@ -109,6 +95,10 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
POT::SKILL_FISH => array('value' => 0, 'tries' => 0)
|
POT::SKILL_FISH => array('value' => 0, 'tries' => 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private array $columns = ['name', 'account_id', 'group_id', 'sex', 'vocation', 'experience', 'level', 'maglevel', 'health', 'healthmax', 'mana', 'manamax', 'manaspent', 'soul', 'lookbody', 'lookfeet', 'lookhead', 'looklegs', 'looktype', 'posx', 'posy', 'posz', 'lastlogin', 'lastlogout', 'lastip', 'town_id', 'balance', 'created', 'comment', 'hide'];
|
||||||
|
|
||||||
|
private array $optionalColumns = ['cap', 'skull', 'skull_type', 'skull_time', 'loss_experience', 'loss_mana', 'loss_skills', 'loss_items', 'loss_containers', 'guildnick', 'rank_id', 'promotion', 'direction', 'blessings', 'stamina', 'lookaddons', 'save', 'conditions', 'world_id', 'online', 'deletion', 'deleted', 'marriage'];
|
||||||
|
|
||||||
private static array $playersOnline;
|
private static array $playersOnline;
|
||||||
/**
|
/**
|
||||||
* Magic PHP5 method.
|
* Magic PHP5 method.
|
||||||
@@ -133,90 +123,14 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
*/
|
*/
|
||||||
public function load($id, $fields = null, $load_skills = true)
|
public function load($id, $fields = null, $load_skills = true)
|
||||||
{
|
{
|
||||||
global $__load;
|
$columns = $this->columns;
|
||||||
|
foreach ($this->optionalColumns as $column) {
|
||||||
if(!isset($__load['loss_experience']))
|
if ($this->db->hasColumn('players', $column)) {
|
||||||
{
|
$columns[] = $column;
|
||||||
$loss = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_experience')) {
|
|
||||||
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$__load['loss_experience'] = $loss;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($__load['loss_items']))
|
|
||||||
{
|
|
||||||
$loss_items = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_items')) {
|
|
||||||
$loss_items = ', `loss_items`, `loss_containers`';
|
|
||||||
}
|
|
||||||
|
|
||||||
$__load['loss_items'] = $loss_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($__load['guild_info']))
|
|
||||||
{
|
|
||||||
$guild_info = '';
|
|
||||||
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
|
|
||||||
$guild_info = ', `guildnick`, `rank_id`';
|
|
||||||
}
|
|
||||||
|
|
||||||
$__load['guild_info'] = $guild_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($__load['skull_type']))
|
|
||||||
{
|
|
||||||
$skull_type = 'skull';
|
|
||||||
if($this->db->hasColumn('players', 'skull_type')) {
|
|
||||||
$skull_type = 'skull_type';
|
|
||||||
}
|
|
||||||
|
|
||||||
$__load['skull_type'] = $skull_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($__load['skull_time']))
|
|
||||||
{
|
|
||||||
$skull_time = 'skulltime';
|
|
||||||
if($this->db->hasColumn('players', 'skull_time')) {
|
|
||||||
$skull_time = 'skull_time';
|
|
||||||
}
|
|
||||||
|
|
||||||
$__load['skull_time'] = $skull_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($__load['blessings'])) {
|
|
||||||
$__load['blessings'] = $this->db->hasColumn('players', 'blessings');
|
|
||||||
}
|
|
||||||
if(!isset($__load['direction'])) {
|
|
||||||
$__load['direction'] = $this->db->hasColumn('players', 'direction');
|
|
||||||
}
|
|
||||||
if(!isset($__load['stamina'])) {
|
|
||||||
$__load['stamina'] = $this->db->hasColumn('players', 'stamina');
|
|
||||||
}
|
|
||||||
if(!isset($__load['world_id'])) {
|
|
||||||
$__load['world_id'] = $this->db->hasColumn('players', 'world_id');
|
|
||||||
}
|
|
||||||
if(!isset($__load['online'])) {
|
|
||||||
$__load['online'] = $this->db->hasColumn('players', 'online');
|
|
||||||
}
|
|
||||||
if(!isset($__load['deletion'])) {
|
|
||||||
$__load['deletion'] = $this->db->hasColumn('players', 'deletion');
|
|
||||||
}
|
|
||||||
if(!isset($__load['promotion'])) {
|
|
||||||
$__load['promotion'] = $this->db->hasColumn('players', 'promotion');
|
|
||||||
}
|
|
||||||
if(!isset($__load['marriage'])) {
|
|
||||||
$__load['marriage'] = $this->db->hasColumn('players', 'marriage');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($fields)) { // load only what we wish
|
if(isset($fields)) { // load only what we wish
|
||||||
if(in_array('promotion', $fields)) {
|
|
||||||
if(!$this->db->hasColumn('players', 'promotion')) {
|
|
||||||
unset($fields[array_search('promotion', $fields)]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(in_array('deleted', $fields)) {
|
if(in_array('deleted', $fields)) {
|
||||||
if($this->db->hasColumn('players', 'deletion')) {
|
if($this->db->hasColumn('players', 'deletion')) {
|
||||||
unset($fields[array_search('deleted', $fields)]);
|
unset($fields[array_search('deleted', $fields)]);
|
||||||
@@ -224,21 +138,20 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array('online', $fields)) {
|
$columns = [];
|
||||||
if(!$this->db->hasColumn('players', 'online')) {
|
foreach ($fields as $field) {
|
||||||
unset($fields[array_search('online', $fields)]);
|
if ($this->db->hasColumn('players', $field)) {
|
||||||
|
$columns[] = $field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->data = $this->db->query('SELECT ' . implode(', ', $fields) . ' FROM `players` WHERE `id` = ' . (int)$id)->fetch();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// SELECT query on database
|
|
||||||
$this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . ($this->db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hide` FROM `players` WHERE `id` = ' . (int)$id)->fetch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array_unshift($columns, 'id');
|
||||||
|
|
||||||
|
$this->data = PlayerModel::where('id', $id)->first($columns)->toArray();
|
||||||
|
|
||||||
// loads skills
|
// loads skills
|
||||||
if( $this->isLoaded() && $load_skills)
|
if( $this->isLoaded() && $load_skills) {
|
||||||
{
|
|
||||||
if($this->db->hasColumn('players', 'skill_fist')) {
|
if($this->db->hasColumn('players', 'skill_fist')) {
|
||||||
|
|
||||||
$skill_ids = array(
|
$skill_ids = array(
|
||||||
@@ -318,153 +231,57 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
*/
|
*/
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
$skull_type = 'skull';
|
$defaultValues = [
|
||||||
if($this->db->hasColumn('players', 'skull_type')) {
|
'loss_experience' => 100,
|
||||||
$skull_type = 'skull_type';
|
'loss_mana' => 100,
|
||||||
|
'loss_skills' => 100,
|
||||||
|
'loss_items' => 100,
|
||||||
|
'loss_containers' => 100,
|
||||||
|
'guildnick' => '',
|
||||||
|
'rank_id' => 0,
|
||||||
|
'promotion' => 0,
|
||||||
|
'direction' => 0,
|
||||||
|
'blessings' => 0,
|
||||||
|
'conditions' => '',
|
||||||
|
'town_id' => 1,
|
||||||
|
'deletion' => 0,
|
||||||
|
'deleted' => 0,
|
||||||
|
'stamina' => 0,
|
||||||
|
'marriage' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($defaultValues as $key => $value) {
|
||||||
|
if (!isset($this->data[$key])) {
|
||||||
|
$this->data[$key] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$skull_time = 'skulltime';
|
$columns = $this->columns;
|
||||||
if($this->db->hasColumn('players', 'skull_time')) {
|
foreach ($this->optionalColumns as $column) {
|
||||||
$skull_time = 'skull_time';
|
if ($this->db->hasColumn('players', $column)) {
|
||||||
|
$columns[] = $column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->data['loss_experience']))
|
$values = [];
|
||||||
$this->data['loss_experience'] = 100;
|
foreach ($columns as $column) {
|
||||||
|
$value = $this->data[$column];
|
||||||
|
if ($column == 'created') {
|
||||||
|
$value = time();
|
||||||
|
}
|
||||||
|
|
||||||
if(!isset($this->data['loss_mana']))
|
$values[$column] = $value;
|
||||||
$this->data['loss_mana'] = 100;
|
}
|
||||||
|
|
||||||
if(!isset($this->data['loss_skills']))
|
|
||||||
$this->data['loss_skills'] = 100;
|
|
||||||
|
|
||||||
if(!isset($this->data['loss_items']))
|
|
||||||
$this->data['loss_items'] = 10;
|
|
||||||
|
|
||||||
if(!isset($this->data['loss_containers']))
|
|
||||||
$this->data['loss_containers'] = 100;
|
|
||||||
|
|
||||||
if(!isset($this->data['guildnick']))
|
|
||||||
$this->data['guildnick'] = '';
|
|
||||||
|
|
||||||
if(!isset($this->data['rank_id']))
|
|
||||||
$this->data['rank_id'] = 0;
|
|
||||||
|
|
||||||
if(!isset($this->data['promotion']))
|
|
||||||
$this->data['promotion'] = 0;
|
|
||||||
|
|
||||||
if(!isset($this->data['direction']))
|
|
||||||
$this->data['direction'] = 0;
|
|
||||||
|
|
||||||
if(!isset($this->data['conditions']))
|
|
||||||
$this->data['conditions'] = '';
|
|
||||||
|
|
||||||
if(!isset($this->data['town_id']))
|
|
||||||
$this->data['town_id'] = 1;
|
|
||||||
|
|
||||||
// updates existing player
|
// updates existing player
|
||||||
if( isset($this->data['id']) )
|
if( isset($this->data['id']) ) {
|
||||||
{
|
PlayerModel::where('id', $this->data['id'])->update($values);
|
||||||
$loss = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_experience')) {
|
|
||||||
$loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$loss_items = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_items')) {
|
|
||||||
$loss_items = ', `loss_items` = ' . $this->data['loss_items'] . ', `loss_containers` = ' . $this->data['loss_containers'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$guild_info = '';
|
|
||||||
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
|
|
||||||
$guild_info = ', `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$direction = '';
|
|
||||||
if($this->db->hasColumn('players', 'direction')) {
|
|
||||||
$direction = ', `direction` = ' . $this->db->quote($this->data['direction']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$blessings = '';
|
|
||||||
if($this->db->hasColumn('players', 'blessings')) {
|
|
||||||
$blessings = ', `blessings` = ' . $this->db->quote($this->data['blessings']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$stamina = '';
|
|
||||||
if($this->db->hasColumn('players', 'stamina')) {
|
|
||||||
$stamina = ', `stamina` = ' . $this->db->quote($this->data['stamina']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lookaddons = '';
|
|
||||||
if($this->db->hasColumn('players', 'lookaddons')) {
|
|
||||||
$lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// UPDATE query on database
|
|
||||||
$this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($this->data['name']) . ', ' . $this->db->fieldName('account_id') . ' = ' . $this->data['account_id'] . ', ' . $this->db->fieldName('group_id') . ' = ' . $this->data['group_id'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('experience') . ' = ' . $this->data['experience'] . ', ' . $this->db->fieldName('level') . ' = ' . $this->data['level'] . ', ' . $this->db->fieldName('maglevel') . ' = ' . $this->data['maglevel'] . ', ' . $this->db->fieldName('health') . ' = ' . $this->data['health'] . ', ' . $this->db->fieldName('healthmax') . ' = ' . $this->data['healthmax'] . ', ' . $this->db->fieldName('mana') . ' = ' . $this->data['mana'] . ', ' . $this->db->fieldName('manamax') . ' = ' . $this->data['manamax'] . ', ' . $this->db->fieldName('manaspent') . ' = ' . $this->data['manaspent'] . ', ' . $this->db->fieldName('soul') . ' = ' . $this->data['soul'] . ', ' . $this->db->fieldName('lookbody') . ' = ' . $this->data['lookbody'] . ', ' . $this->db->fieldName('lookfeet') . ' = ' . $this->data['lookfeet'] . ', ' . $this->db->fieldName('lookhead') . ' = ' . $this->data['lookhead'] . ', ' . $this->db->fieldName('looklegs') . ' = ' . $this->data['looklegs'] . ', ' . $this->db->fieldName('looktype') . ' = ' . $this->data['looktype'] . $lookaddons . ', ' . $this->db->fieldName('posx') . ' = ' . $this->data['posx'] . ', ' . $this->db->fieldName('posy') . ' = ' . $this->data['posy'] . ', ' . $this->db->fieldName('posz') . ' = ' . $this->data['posz'] . ', ' . $this->db->fieldName('cap') . ' = ' . $this->data['cap'] . ', ' . $this->db->fieldName('lastlogin') . ' = ' . $this->data['lastlogin'] . ', ' . $this->db->fieldName('lastlogout') . ' = ' . $this->data['lastlogout'] . ', ' . $this->db->fieldName('lastip') . ' = ' . $this->db->quote($this->data['lastip']) . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', `' . $skull_time . '` = ' . $this->data['skulltime'] . ', `' . $skull_type . '` = ' . (int) $this->data['skull'] . $guild_info . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . $loss . $loss_items . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . $blessings . $stamina . $direction . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
|
|
||||||
}
|
}
|
||||||
// creates new player
|
// creates new player
|
||||||
else
|
else {
|
||||||
{
|
$player = PlayerModel::create($values);
|
||||||
$loss = '';
|
|
||||||
$loss_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_experience')) {
|
|
||||||
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
|
|
||||||
$loss_data = ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$loss_items = '';
|
|
||||||
$loss_items_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'loss_items')) {
|
|
||||||
$loss_items = ', `loss_items`, `loss_containers`';
|
|
||||||
$loss_items_data = ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$guild_info = '';
|
|
||||||
$guild_info_data = '';
|
|
||||||
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
|
|
||||||
$guild_info = ', `guildnick`, `rank_id`';
|
|
||||||
$guild_info_data = ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$promotion = '';
|
|
||||||
$promotion_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'promotion')) {
|
|
||||||
$promotion = ', `promotion`';
|
|
||||||
$promotion_data = ', ' . $this->data['promotion'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$direction = '';
|
|
||||||
$direction_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'direction')) {
|
|
||||||
$direction = ', `direction`';
|
|
||||||
$direction_data = ', ' . $this->data['direction'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$blessings = '';
|
|
||||||
$blessings_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'blessings')) {
|
|
||||||
$blessings = ', `blessings`';
|
|
||||||
$blessings_data = ', ' . $this->data['blessings'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$stamina = '';
|
|
||||||
$stamina_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'stamina')) {
|
|
||||||
$stamina = ', `stamina`';
|
|
||||||
$stamina_data = ', ' . $this->data['stamina'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$lookaddons = '';
|
|
||||||
$lookaddons_data = '';
|
|
||||||
if($this->db->hasColumn('players', 'lookaddons')) {
|
|
||||||
$lookaddons = ', `lookaddons`';
|
|
||||||
$lookaddons_data = ', ' . $this->data['lookaddons'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// INSERT query on database
|
|
||||||
$this->db->query('INSERT INTO `players` (`name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . $lookaddons . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $skull_time . '`, `' . $skull_type . '`' . $guild_info . ', `town_id`' . $loss . $loss_items . ', `balance`' . $blessings . $stamina . $direction . ', `created`' . $promotion . ', `comment`) VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['group_id'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['experience'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['soul'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . $lookaddons_data . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastlogout'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skulltime'] . ', ' . (int) $this->data['skull'] . $guild_info_data . ', ' . $this->data['town_id'] . $loss_data . $loss_items_data . ', ' . $this->data['balance'] . $blessings_data . $stamina_data . $direction_data . ', ' . time() . $promotion_data . ', "")');
|
|
||||||
// ID of new group
|
// ID of new group
|
||||||
$this->data['id'] = $this->db->lastInsertId();
|
$this->data['id'] = $player->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates skills - doesn't matter if we have just created character - trigger inserts new skills
|
// updates skills - doesn't matter if we have just created character - trigger inserts new skills
|
||||||
@@ -490,7 +307,7 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
$set .= ',';
|
$set .= ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
$skills = $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
|
$this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
|
||||||
}
|
}
|
||||||
else if($this->db->hasTable('player_skills')) {
|
else if($this->db->hasTable('player_skills')) {
|
||||||
foreach($this->skills as $id => $skill)
|
foreach($this->skills as $id => $skill)
|
||||||
@@ -748,21 +565,25 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
|
|
||||||
public function isDeleted()
|
public function isDeleted()
|
||||||
{
|
{
|
||||||
$field = 'deleted';
|
$column = 'deleted';
|
||||||
if($this->db->hasColumn('players', 'deletion'))
|
if($this->db->hasColumn('players', 'deletion'))
|
||||||
$field = 'deletion';
|
$column = 'deletion';
|
||||||
|
|
||||||
if( !isset($this->data[$field]) )
|
if( !isset($this->data[$column]) )
|
||||||
{
|
{
|
||||||
throw new E_OTS_NotLoaded();
|
throw new E_OTS_NotLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->data[$field] > 0;
|
return $this->data[$column] > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDeleted($deleted)
|
public function setDeleted($deleted)
|
||||||
{
|
{
|
||||||
$this->data['deleted'] = (int) $deleted;
|
$column = 'deleted';
|
||||||
|
if($this->db->hasColumn('players', 'deletion'))
|
||||||
|
$column = 'deletion';
|
||||||
|
|
||||||
|
$this->data[$column] = (int) $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOnline()
|
public function isOnline()
|
||||||
@@ -1792,12 +1613,12 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
*/
|
*/
|
||||||
public function getSkullTime()
|
public function getSkullTime()
|
||||||
{
|
{
|
||||||
if( !isset($this->data['skulltime']) )
|
$column = 'skulltime';
|
||||||
{
|
if($this->db->hasColumn('players', 'skull_time')) {
|
||||||
throw new E_OTS_NotLoaded();
|
$column = 'skull_time';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->data['skulltime'];
|
return $this->data[$column] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1811,7 +1632,12 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
*/
|
*/
|
||||||
public function setSkullTime($skulltime)
|
public function setSkullTime($skulltime)
|
||||||
{
|
{
|
||||||
$this->data['skulltime'] = (int) $skulltime;
|
$column = 'skulltime';
|
||||||
|
if($this->db->hasColumn('players', 'skull_time')) {
|
||||||
|
$column = 'skull_time';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->data[$column] = (int) $skulltime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3250,6 +3076,10 @@ class OTS_Player extends OTS_Row_DAO
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setData(array $data): void{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Magic PHP5 method.
|
* Magic PHP5 method.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ class Player extends Model {
|
|||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'worldid' => 'integer',
|
'worldid' => 'integer',
|
||||||
'sex' => 'integer',
|
'sex' => 'integer',
|
||||||
|
|||||||
Reference in New Issue
Block a user