feat: 등용장 일괄 무효화 추가
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Enums\MessageType;
|
||||
|
||||
class ScoutMessage extends Message{
|
||||
class ScoutMessage extends Message
|
||||
{
|
||||
|
||||
const ACCEPTED = 1;
|
||||
const DECLINED = -1;
|
||||
@@ -18,8 +20,7 @@ class ScoutMessage extends Message{
|
||||
\DateTime $date,
|
||||
\DateTime $validUntil,
|
||||
array $msgOption
|
||||
)
|
||||
{
|
||||
) {
|
||||
if ($msgType !== MessageType::private) {
|
||||
throw new \InvalidArgumentException('DiplomaticMessage msgType');
|
||||
}
|
||||
@@ -39,7 +40,8 @@ class ScoutMessage extends Message{
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkScoutMessageValidation(int $receiverID){
|
||||
protected function checkScoutMessageValidation(int $receiverID)
|
||||
{
|
||||
if (!$this->validScout) {
|
||||
return [self::INVALID, '유효하지 않은 등용장입니다.'];
|
||||
}
|
||||
@@ -57,7 +59,8 @@ class ScoutMessage extends Message{
|
||||
/**
|
||||
* @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환
|
||||
*/
|
||||
public function agreeMessage(int $receiverID, string &$reason):int{
|
||||
public function agreeMessage(int $receiverID, string &$reason): int
|
||||
{
|
||||
//NOTE: 올바른 유저가 agreeMessage() 호출을 한건지는 외부에서 체크 필요(Session->userID 등)
|
||||
|
||||
if (!$this->id) {
|
||||
@@ -96,6 +99,7 @@ class ScoutMessage extends Message{
|
||||
//메시지 비 활성화
|
||||
$this->msgOption['used'] = true;
|
||||
$this->invalidate();
|
||||
static::invalidateAll($this->src->generalID, $this->id);
|
||||
$this->validScout = false;
|
||||
|
||||
$josaRo = JosaUtil::pick($this->src->nationName, '로');
|
||||
@@ -115,7 +119,33 @@ class ScoutMessage extends Message{
|
||||
return self::ACCEPTED;
|
||||
}
|
||||
|
||||
protected function _declineMessage(){
|
||||
public static function invalidateAll(int $generalID, ?int $exceptMsgID = null)
|
||||
{
|
||||
$db = DB::db();
|
||||
$now = TimeUtil::now();
|
||||
//XXX: 뭔가 기존 쿼리가 애매하다. invalid 관련해서 다른 옵션이 가능한가?
|
||||
$rawMsgList = Util::convertArrayToDict($db->query(
|
||||
'SELECT * FROM `message` WHERE
|
||||
`mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND
|
||||
JSON_VALUE(message, "$.option.action") = %s',
|
||||
$generalID,
|
||||
$now,
|
||||
'scout',
|
||||
), 'id');
|
||||
if ($exceptMsgID && key_exists($exceptMsgID, $rawMsgList)) {
|
||||
unset($rawMsgList[$exceptMsgID]);
|
||||
}
|
||||
if (!$rawMsgList) {
|
||||
return;
|
||||
}
|
||||
foreach ($rawMsgList as $rawMsg) {
|
||||
$msg = static::buildFromArray($rawMsg);
|
||||
$msg->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected function _declineMessage()
|
||||
{
|
||||
$this->msgOption['used'] = true;
|
||||
$this->invalidate();
|
||||
$this->validScout = false;
|
||||
@@ -137,7 +167,8 @@ class ScoutMessage extends Message{
|
||||
return self::DECLINED;
|
||||
}
|
||||
|
||||
public function declineMessage(int $receiverID, string &$reason):int{
|
||||
public function declineMessage(int $receiverID, string &$reason): int
|
||||
{
|
||||
if (!$this->id) {
|
||||
throw new \RuntimeException('전송되지 않은 메시지에 거절 진행 중');
|
||||
}
|
||||
@@ -162,7 +193,8 @@ class ScoutMessage extends Message{
|
||||
return self::DECLINED;
|
||||
}
|
||||
|
||||
public static function buildScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null):?self{
|
||||
public static function buildScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null): ?self
|
||||
{
|
||||
if ($srcGeneralID == $destGeneralID) {
|
||||
if ($reason !== null) {
|
||||
$reason = '같은 장수에게 등용장을 보낼 수 없습니다';
|
||||
|
||||
Reference in New Issue
Block a user