InheritAction: 유니크 입찰, 랜덤 아이템
This commit is contained in:
+3
-1
@@ -1711,6 +1711,8 @@ function tryInheritUniqueItem(General $general, string $acquireType = '아이템
|
||||
rollbackInheritUniqueTrial($general, $itemKey, '절차상의 오류입니다.');
|
||||
continue;
|
||||
}
|
||||
|
||||
//XXX: 정렬할 필요 없지 않나?
|
||||
usort($anyTrials, function ($lhsTrial, $rhsTrial) {
|
||||
[,, $lhsAmount] = $lhsTrial;
|
||||
[,, $rhsAmount] = $rhsTrial;
|
||||
@@ -1718,7 +1720,7 @@ function tryInheritUniqueItem(General $general, string $acquireType = '아이템
|
||||
});
|
||||
|
||||
//공동 1등인데 본인이 있을 수도 있다.
|
||||
[,, $topAmount] = $anyTrials;
|
||||
[,, $topAmount] = $anyTrials[0];
|
||||
if ($amount < $topAmount) {
|
||||
$compAmount = $topAmount / $amount;
|
||||
if ($compAmount > 2.0) {
|
||||
|
||||
@@ -78,12 +78,8 @@ class Join extends \sammo\BaseAPI
|
||||
return static::REQ_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(?Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
if ($session === null) {
|
||||
throw "invalid session";
|
||||
}
|
||||
|
||||
$userID = $session->userID;
|
||||
|
||||
$name = $this->args['name'];
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\InheritAction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\TimeUtil;
|
||||
|
||||
class BuyRandomUnique extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
//General.aux 쓰므로 lock;
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$userID = $session->userID;
|
||||
$generalID = $session->generalID;
|
||||
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
if($userID != $general->getVar('owner')){
|
||||
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||
}
|
||||
|
||||
if($general->getAuxVar('inheritRandomUnique') !== null){
|
||||
return '이미 구입 명령을 내렸습니다. 다음 턴까지 기다려주세요.';
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||
$previousPoint = $inheritStor->getValue('previous')??0;
|
||||
if($previousPoint < GameConst::$inheritItemRandomPoint){
|
||||
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||
}
|
||||
|
||||
$general->setAuxVar('inheritRandomUnique', TimeUtil::now());
|
||||
$inheritStor->setValue('previous', $previousPoint - GameConst::$inheritItemRandomPoint);
|
||||
$general->flushUpdateValues();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\InheritAction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\Validator;
|
||||
|
||||
class BuySpecificUnique extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
foreach(GameConst::$allItems as $items){
|
||||
foreach($items as $itemKey=>$amount){
|
||||
if($amount == 0){
|
||||
continue;
|
||||
}
|
||||
$availableItems[$itemKey] = $amount;
|
||||
}
|
||||
}
|
||||
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'item',
|
||||
'amount',
|
||||
])
|
||||
->rule('integer', 'amount')
|
||||
->rule('min', GameConst::$inheritItemUniqueMinPoint)
|
||||
->rule('keyExists', $availableItems);
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
//KVStrorage, General.aux 모두 쓰므로 lock;
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$itemKey = $this->args['item'];
|
||||
$amount = $this->args['amount'];
|
||||
|
||||
$userID = $session->userID;
|
||||
$generalID = $session->generalID;
|
||||
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
if($userID != $general->getVar('owner')){
|
||||
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||
}
|
||||
|
||||
$itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? [];
|
||||
if(key_exists($itemKey, $itemTrials)){
|
||||
return '이미 입찰한 아이템입니다. 다음 턴에 시도해 주세요.';
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||
$trialStor = KVStorage::getStorage($db, "ut_{$itemKey}");
|
||||
$previousPoint = $inheritStor->getValue('previous')??0;
|
||||
if($previousPoint < $amount){
|
||||
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||
}
|
||||
|
||||
$itemTrials[$itemKey] = $amount;
|
||||
$general->setAuxVar('inheritUniqueTrial', $itemTrials);
|
||||
$inheritStor->setValue('previous', $previousPoint - $amount);
|
||||
$trialStor->setValue("u{$userID}", [$userID, $generalID, $amount]);
|
||||
$general->flushUpdateValues();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ abstract class BaseAPI
|
||||
abstract function validateArgs(): ?string;
|
||||
|
||||
/** @return null|string|array */
|
||||
abstract function launch(?Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag);
|
||||
abstract function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag);
|
||||
|
||||
public function tryCache():?string{
|
||||
return null;
|
||||
|
||||
@@ -199,6 +199,8 @@ class GameConstBase
|
||||
public static $inheritBornTurntimePoint = 3000;
|
||||
public static $inheritBornCityPoint = 1000;
|
||||
public static $inheritBornStatPoint = 1000;
|
||||
public static $inheritItemUniqueMinPoint = 5000;
|
||||
public static $inheritItemRandomPoint = 3000;
|
||||
|
||||
public static $allItems = [
|
||||
'horse' => [
|
||||
|
||||
@@ -21,7 +21,7 @@ class Validator extends \Valitron\Validator
|
||||
* $rule에 함수를 넣는 대신 상속한 클래스에 추가하는 방식을 사용할 것.
|
||||
*
|
||||
* @suppress PhanUndeclaredFunctionInCallable
|
||||
*
|
||||
*
|
||||
* @param string $rule
|
||||
* @param array|string $fields
|
||||
* @return $this
|
||||
@@ -31,7 +31,7 @@ class Validator extends \Valitron\Validator
|
||||
$params = func_get_args();
|
||||
return parent::rule(...$params);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,4 +98,11 @@ class Validator extends \Valitron\Validator
|
||||
$width = mb_strwidth($value);
|
||||
return $params[0] <= $width && $width <= $params[1];
|
||||
}
|
||||
|
||||
protected function validateKeyExists($field, $value, $params){
|
||||
if(!is_string($value) && !is_numeric($value)){
|
||||
return false;
|
||||
}
|
||||
return key_exists($value, $params[0]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user