update status
This commit is contained in:
parent
b0b49777a0
commit
71bdfab874
3 changed files with 203 additions and 93 deletions
|
|
@ -2,11 +2,12 @@
|
|||
/**
|
||||
* status class
|
||||
*/
|
||||
// require_once __DIR__ . "/status.class.php";
|
||||
require_once __DIR__ . "/status.class.php";
|
||||
/**
|
||||
* item class
|
||||
*/
|
||||
require_once __DIR__ . "/item.class.php";
|
||||
|
||||
class Character extends Module
|
||||
{
|
||||
protected $_rawdata;
|
||||
|
|
|
|||
195
AvocadoAmber/classes/character/status.class.php
Normal file
195
AvocadoAmber/classes/character/status.class.php
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
class Status
|
||||
{
|
||||
/**
|
||||
* get status by character id and status id
|
||||
* @param string|int $character_id
|
||||
* @param string|int $status_id
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getStatus($character_id, $status_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$query = "SELECT
|
||||
s.sc_value,
|
||||
s.sc_max,
|
||||
c.st_use_max,
|
||||
c.st_max,
|
||||
c.st_min
|
||||
FROM {$g5['status_table']} s
|
||||
JOIN {$g5['status_config_table']} c ON s.st_id = c.st_id
|
||||
WHERE s.ch_id = '{$character_id}'
|
||||
AND s.st_id = '{$status_id}'
|
||||
";
|
||||
|
||||
$row = sql_fetch($query);
|
||||
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'config_max' => (bool) $row['st_use_max'],
|
||||
'max' => (bool) $row['st_use_max'] ? (int) $row['st_max'] : (int) $row['sc_max'],
|
||||
'min' => (int) $row['st_min'],
|
||||
'drop' => (int) $row['sc_value'],
|
||||
'now' => $row['sc_max'] - $row['sc_value'],
|
||||
'has' => (int) $row['sc_max']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* get status by character id and status name
|
||||
* @param string|int $character_id
|
||||
* @param string $status_name
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getStatusByName($character_id, $status_name)
|
||||
{
|
||||
global $g5;
|
||||
$status_name = addslashes($status_name);
|
||||
$st_id = sql_fetch("SELECT st_id FROM {$g5["status_config_table"]} WHERE st_name = '{$status_name}'");
|
||||
if ($st_id) {
|
||||
return self::getStatus($character_id, $st_id["st_id"]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 분배 최소값을 포함하지 않는 계산 방식을 사용하는 새 함수입니다. 최대 포인트를 100으로 지정하고 특정 스테이터스 포인트의
|
||||
* 최소값이 10인 경우 사용량이 10이 아닌 0으로 계산됩니다.
|
||||
* @param string|int $character_id
|
||||
* @return int
|
||||
*/
|
||||
public static function getUsedPoint($character_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$query = "SELECT SUM(s.sc_max - a.st_min) as total
|
||||
FROM {$g5['status_table']} s
|
||||
JOIN {$g5['status_config_table']} a ON s.st_id = a.st_id
|
||||
WHERE s.ch_id = '{$character_id}'
|
||||
";
|
||||
|
||||
$result = sql_fetch($query);
|
||||
return isset($result['total']) ? max((int) $result['total'], 0) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 분배 최소값을 포함하지 않는 계산 방식을 사용하는 새 함수입니다. 최대 포인트를 100으로 지정하고 특정 스테이터스 포인트의
|
||||
* 최소값이 10인 경우 사용량이 10이 아닌 0으로 계산됩니다.
|
||||
* @param string|int $character_id
|
||||
* @return int
|
||||
*/
|
||||
public static function getAvailablePoint($character_id)
|
||||
{
|
||||
global $g5, $config;
|
||||
|
||||
$ch = Character::getCharacter($character_id);
|
||||
$use_point = self::getUsedPoint($character_id);
|
||||
|
||||
if (!$ch['ch_point'])
|
||||
$ch['ch_point'] = $config['cf_status_point'];
|
||||
|
||||
$result = ((int) $ch['ch_point']) - $use_point;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 분배 최소값을 분배 포인트에 포함하려면 이 함수를 참조하십시오.
|
||||
* @param string|int $character_id
|
||||
* @return int
|
||||
*/
|
||||
public static function getUsedPointLegacy($character_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = sql_fetch("SELECT SUM(s.sc_max) as total FROM {$g5['status_table']} s WHERE s.ch_id = '{$character_id}'");
|
||||
|
||||
return isset($result['total']) ? max((int) $result['total'], 0) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 분배 최소값을 분배 포인트에 포함하려면 이 함수를 참조하십시오.
|
||||
* @param string|int $character_id
|
||||
* @return int
|
||||
*/
|
||||
public static function getAvailablePointLegacy($character_id)
|
||||
{
|
||||
global $g5, $config;
|
||||
|
||||
$ch = Character::getCharacter($character_id);
|
||||
$use_point = self::getUsedPointLegacy($character_id);
|
||||
|
||||
if (!$ch['ch_point'])
|
||||
$ch['ch_point'] = $config['cf_status_point'];
|
||||
|
||||
$result = ((int) $ch['ch_point']) - $use_point;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* set status by status id
|
||||
* @param string|int $character_id
|
||||
* @param string|int $status_id
|
||||
* @param string|int $value
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
*/
|
||||
public static function setStatus($character_id, $status_id, $value, $message = "")
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$query = "SELECT c.st_id, s.sc_id, s.sc_value, s.sc_max
|
||||
FROM {$g5['status_config_table']} c
|
||||
LEFT JOIN {$g5['status_table']} s ON c.st_id = s.st_id AND s.ch_id = '{$character_id}'
|
||||
WHERE c.st_id = '{$status_id}'";
|
||||
|
||||
$result = sql_fetch($query);
|
||||
|
||||
if (isset($result["st_id"])) {
|
||||
$new_value = $result['sc_value'] + $value;
|
||||
|
||||
if ($new_value >= $result['sc_max']) {
|
||||
$new_value = $result['sc_max'];
|
||||
} else if ($new_value < 0) {
|
||||
$message = "";
|
||||
$new_value = 0;
|
||||
}
|
||||
|
||||
$update_query = "UPDATE {$g5['status_table']}
|
||||
SET sc_value = '{$new_value}'
|
||||
WHERE sc_id = '{$result['sc_id']}'";
|
||||
|
||||
sql_query($update_query);
|
||||
return $message;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* set status by status name
|
||||
* @param string|int $character_id
|
||||
* @param string $status_name
|
||||
* @param string|int $value
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
*/
|
||||
public static function setStatusByName($character_id, $status_name, $value, $message = "")
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = sql_fetch("select st_id from {$g5['status_config_table']} where st_name = '{$status_name}'");
|
||||
|
||||
if (isset($result["st_id"])) {
|
||||
return self::setStatus($character_id, $result["st_id"], $value, $message);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
@ -4,119 +4,33 @@ if (!defined('_GNUBOARD_'))
|
|||
|
||||
function get_status($ch_id, $st_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = [];
|
||||
$sc = sql_fetch("select sc_value, sc_max from {$g5['status_table']} where ch_id = '{$ch_id}' and st_id = '{$st_id}'");
|
||||
$sl = sql_fetch("select st_id, st_use_max, st_max, st_min from {$g5['status_config_table']} where st_id = '{$st_id}'");
|
||||
|
||||
$result['config_max'] = $sl['st_use_max'] ? true : false;
|
||||
$result['max'] = (int) $sl['st_max'];
|
||||
$result['min'] = (int) $sl['st_min'];
|
||||
$result['drop'] = (int) $sc['sc_value'];
|
||||
$result['now'] = $sc['sc_max'] - $sc['sc_value'];
|
||||
$result['has'] = (int) $sc['sc_max'];
|
||||
|
||||
return $result;
|
||||
return Status::getStatus($ch_id, $st_id);
|
||||
}
|
||||
|
||||
function get_status_by_name($ch_id, $st_name)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = [];
|
||||
|
||||
$sl = sql_fetch("select st_id, st_use_max, st_max from {$g5['status_config_table']} where st_name = '{$st_name}'");
|
||||
$sc = sql_fetch("select sc_value, sc_max from {$g5['status_table']} where ch_id = '{$ch_id}' and st_id = '{$sl['st_id']}'");
|
||||
|
||||
if ($sl['st_use_max']) {
|
||||
// 최대값 기준으로 출력 시, 스탯 설정에서 등록한 최대값을 MAX 값으로 둔다
|
||||
$result['max'] = $sl['st_max'];
|
||||
} else {
|
||||
$result['max'] = $sl['sc_max'];
|
||||
}
|
||||
|
||||
$result['drop'] = $sc['sc_value'];
|
||||
$result['now'] = $sc['sc_max'] - $sc['sc_value'];
|
||||
$result['has'] = $sc['sc_max'];
|
||||
|
||||
return $result;
|
||||
return Status::getStatusByName($ch_id, $st_name);
|
||||
}
|
||||
|
||||
// 사용한 포인트
|
||||
function get_use_status($ch_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$sc = sql_fetch("select SUM(sc_max) as total from {$g5['status_table']} where ch_id = '{$ch_id}'");
|
||||
$result = $sc['total'];
|
||||
|
||||
return $result;
|
||||
return Status::getUsedPoint($ch_id);
|
||||
}
|
||||
|
||||
// 미분배 포인트
|
||||
function get_space_status($ch_id)
|
||||
{
|
||||
global $g5, $config;
|
||||
|
||||
$ch = get_character($ch_id);
|
||||
$use_point = get_use_status($ch_id);
|
||||
|
||||
|
||||
if (!$ch['ch_point'])
|
||||
$ch['ch_point'] = $config['cf_status_point'];
|
||||
|
||||
$result = $ch['ch_point'] - $use_point;
|
||||
|
||||
return $result;
|
||||
return Status::getAvailablePoint($ch_id);
|
||||
}
|
||||
|
||||
//스탯 변동 적용
|
||||
function set_status($ch_id, $st_id, $hunt, $msg = '')
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = [];
|
||||
|
||||
$sl = sql_fetch("select st_id from {$g5['status_config_table']} where st_id = '{$st_id}'");
|
||||
$sc = sql_fetch("select sc_id, sc_value, sc_max from {$g5['status_table']} where ch_id = '{$ch_id}' and st_id = '{$sl['st_id']}'");
|
||||
|
||||
$sc['sc_value'] = $sc['sc_value'] + $hunt;
|
||||
|
||||
$message = "";
|
||||
|
||||
if ($sc['sc_value'] >= $sc['sc_max']) {
|
||||
$message = $msg;
|
||||
$sc['sc_value'] = $sc['sc_max'];
|
||||
} else if ($sc['sc_value'] < 0) {
|
||||
$sc['sc_value'] = 0;
|
||||
}
|
||||
sql_query(" update {$g5['status_table']} set sc_value = '{$sc['sc_value']}' where sc_id = '{$sc['sc_id']}'");
|
||||
|
||||
return $message;
|
||||
|
||||
return Status::setStatus($ch_id, $st_id, $hunt, $msg);
|
||||
}
|
||||
|
||||
function set_status_by_name($ch_id, $st_name, $hunt, $msg = '')
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$result = [];
|
||||
|
||||
$sl = sql_fetch("select st_id from {$g5['status_config_table']} where st_name = '{$st_name}'");
|
||||
$sc = sql_fetch("select sc_id, sc_value, sc_max from {$g5['status_table']} where ch_id = '{$ch_id}' and st_id = '{$sl['st_id']}'");
|
||||
|
||||
$sc['sc_value'] = $sc['sc_value'] + $hunt;
|
||||
|
||||
$message = "";
|
||||
|
||||
if ($sc['sc_value'] >= $sc['sc_max']) {
|
||||
$message = $msg;
|
||||
$sc['sc_value'] = $sc['sc_max'];
|
||||
} else if ($sc['sc_value'] < 0) {
|
||||
$sc['sc_value'] = 0;
|
||||
}
|
||||
sql_query(" update {$g5['status_table']} set sc_value = '{$sc['sc_value']}' where sc_id = '{$sc['sc_id']}'");
|
||||
|
||||
return $message;
|
||||
return Status::setStatusByName($ch_id, $st_name, $hunt, $msg);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue