feat: 등용장 일괄 무효화 추가

This commit is contained in:
2023-07-11 22:43:09 +10:00
parent 7f3a9d69ca
commit 246751b4dd
+40 -8
View File
@@ -1,9 +1,11 @@
<?php <?php
namespace sammo; namespace sammo;
use sammo\Enums\MessageType; use sammo\Enums\MessageType;
class ScoutMessage extends Message{ class ScoutMessage extends Message
{
const ACCEPTED = 1; const ACCEPTED = 1;
const DECLINED = -1; const DECLINED = -1;
@@ -18,8 +20,7 @@ class ScoutMessage extends Message{
\DateTime $date, \DateTime $date,
\DateTime $validUntil, \DateTime $validUntil,
array $msgOption array $msgOption
) ) {
{
if ($msgType !== MessageType::private) { if ($msgType !== MessageType::private) {
throw new \InvalidArgumentException('DiplomaticMessage msgType'); 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) { if (!$this->validScout) {
return [self::INVALID, '유효하지 않은 등용장입니다.']; return [self::INVALID, '유효하지 않은 등용장입니다.'];
} }
@@ -57,7 +59,8 @@ class ScoutMessage extends Message{
/** /**
* @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환 * @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 등) //NOTE: 올바른 유저가 agreeMessage() 호출을 한건지는 외부에서 체크 필요(Session->userID 등)
if (!$this->id) { if (!$this->id) {
@@ -96,6 +99,7 @@ class ScoutMessage extends Message{
//메시지 비 활성화 //메시지 비 활성화
$this->msgOption['used'] = true; $this->msgOption['used'] = true;
$this->invalidate(); $this->invalidate();
static::invalidateAll($this->src->generalID, $this->id);
$this->validScout = false; $this->validScout = false;
$josaRo = JosaUtil::pick($this->src->nationName, '로'); $josaRo = JosaUtil::pick($this->src->nationName, '로');
@@ -115,7 +119,33 @@ class ScoutMessage extends Message{
return self::ACCEPTED; 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->msgOption['used'] = true;
$this->invalidate(); $this->invalidate();
$this->validScout = false; $this->validScout = false;
@@ -137,7 +167,8 @@ class ScoutMessage extends Message{
return self::DECLINED; return self::DECLINED;
} }
public function declineMessage(int $receiverID, string &$reason):int{ public function declineMessage(int $receiverID, string &$reason): int
{
if (!$this->id) { if (!$this->id) {
throw new \RuntimeException('전송되지 않은 메시지에 거절 진행 중'); throw new \RuntimeException('전송되지 않은 메시지에 거절 진행 중');
} }
@@ -162,7 +193,8 @@ class ScoutMessage extends Message{
return self::DECLINED; 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 ($srcGeneralID == $destGeneralID) {
if ($reason !== null) { if ($reason !== null) {
$reason = '같은 장수에게 등용장을 보낼 수 없습니다'; $reason = '같은 장수에게 등용장을 보낼 수 없습니다';