feat: System MessageTarget를 빠르게 생성하는 함수
This commit is contained in:
@@ -381,7 +381,7 @@ class Message
|
|||||||
* @param string $msg
|
* @param string $msg
|
||||||
*/
|
*/
|
||||||
public static function sendPrivateMsgAsNotice(array|int|MessageTarget $targets, string $msg): void{
|
public static function sendPrivateMsgAsNotice(array|int|MessageTarget $targets, string $msg): void{
|
||||||
$src = new MessageTarget(0, '', 0, 'System', '#000000');
|
$src = MessageTarget::buildSystemTarget();
|
||||||
if(is_int($targets)){
|
if(is_int($targets)){
|
||||||
$targets = [$targets];
|
$targets = [$targets];
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -10,7 +10,7 @@ class MessageTarget extends Target {
|
|||||||
public $color;
|
public $color;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $icon;
|
public $icon;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
int $generalID,
|
int $generalID,
|
||||||
string $generalName,
|
string $generalName,
|
||||||
@@ -19,13 +19,13 @@ class MessageTarget extends Target {
|
|||||||
string $color,
|
string $color,
|
||||||
string $icon=''
|
string $icon=''
|
||||||
){
|
){
|
||||||
|
|
||||||
parent::__construct($generalID, $nationID);
|
parent::__construct($generalID, $nationID);
|
||||||
|
|
||||||
if(!$icon){
|
if(!$icon){
|
||||||
$icon = ServConfig::getSharedIconPath().'/default.jpg';
|
$icon = ServConfig::getSharedIconPath().'/default.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->generalName = $generalName;
|
$this->generalName = $generalName;
|
||||||
$this->nationName = $nationName;
|
$this->nationName = $nationName;
|
||||||
$this->color = $color;
|
$this->color = $color;
|
||||||
@@ -47,28 +47,28 @@ class MessageTarget extends Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new MessageTarget(
|
return new MessageTarget(
|
||||||
$arr['id'],
|
$arr['id'],
|
||||||
$arr['name'],
|
$arr['name'],
|
||||||
$arr['nation_id'],
|
$arr['nation_id'],
|
||||||
$arr['nation'],
|
$arr['nation'],
|
||||||
$arr['color'],
|
$arr['color'],
|
||||||
$arr['icon']??''
|
$arr['icon']??''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DB 부하 감수하고 일일히 찾아줌.
|
* DB 부하 감수하고 일일히 찾아줌.
|
||||||
* 게임 로직과 크게 연관이 없는 곳에서 메시지를 생성해야 할 경우에만 사용할 것을 권함.
|
* 게임 로직과 크게 연관이 없는 곳에서 메시지를 생성해야 할 경우에만 사용할 것을 권함.
|
||||||
* @return MessageTarget
|
* @return MessageTarget
|
||||||
*/
|
*/
|
||||||
public static function buildQuick(int $generalID){
|
public static function buildQuick(int $generalID){
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
list(
|
list(
|
||||||
$generalName,
|
$generalName,
|
||||||
$nationID,
|
$nationID,
|
||||||
$imgsvr,
|
$imgsvr,
|
||||||
$picture
|
$picture
|
||||||
) = $db->queryFirstList('SELECT `name`, nation, imgsvr, picture FROM general WHERE `no`=%i', $generalID);
|
) = $db->queryFirstList('SELECT `name`, nation, imgsvr, picture FROM general WHERE `no`=%i', $generalID);
|
||||||
|
|
||||||
if($generalName === null){
|
if($generalName === null){
|
||||||
throw new \RuntimeException('장수가 없음:'.$generalID);
|
throw new \RuntimeException('장수가 없음:'.$generalID);
|
||||||
@@ -79,6 +79,10 @@ class MessageTarget extends Target {
|
|||||||
return new MessageTarget($generalID, $generalName, $nationID, $nation['name'], $nation['color'], $icon);
|
return new MessageTarget($generalID, $generalName, $nationID, $nation['name'], $nation['color'], $icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function buildSystemTarget(): MessageTarget{
|
||||||
|
return new MessageTarget(0, '', 0, 'System', '#000000');
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray() : array{
|
public function toArray() : array{
|
||||||
return [
|
return [
|
||||||
'id'=>$this->generalID,
|
'id'=>$this->generalID,
|
||||||
|
|||||||
Reference in New Issue
Block a user