Inherit: Action 완료?
This commit is contained in:
@@ -0,0 +1,79 @@
|
|||||||
|
<?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;
|
||||||
|
use sammo\TriggerInheritBuff;
|
||||||
|
use sammo\Validator;
|
||||||
|
|
||||||
|
class BuyHiddenBuff extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
$v = new Validator($this->args);
|
||||||
|
$v->rule('required', [
|
||||||
|
'type',
|
||||||
|
'level',
|
||||||
|
])
|
||||||
|
->rule('integer', 'level')
|
||||||
|
->rule('min', 'level', 1)
|
||||||
|
->rule('max', 'level', TriggerInheritBuff::MAX_STEP)
|
||||||
|
->rule('keyExists', 'type', TriggerInheritBuff::BUFF_KEY_TEXT);
|
||||||
|
|
||||||
|
if (!$v->validate()) {
|
||||||
|
return $v->errorStr();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
$type = $this->args['type'];
|
||||||
|
$level = $this->args['level'];
|
||||||
|
|
||||||
|
$general = General::createGeneralObjFromDB($generalID);
|
||||||
|
if ($userID != $general->getVar('owner')) {
|
||||||
|
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$inheritBuffList = $general->getAuxVar('inheritBuff') ?? [];
|
||||||
|
$prevLevel = $inheritBuffList[$type] ?? 0;
|
||||||
|
|
||||||
|
if ($prevLevel == $level) {
|
||||||
|
return '이미 구입했습니다.';
|
||||||
|
}
|
||||||
|
if ($prevLevel > $level) {
|
||||||
|
return '이미 더 높은 등급을 구입했습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$reqAmount = GameConst::$inheritBuffPoints[$level] - GameConst::$inheritBuffPoints[$prevLevel];
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||||
|
$previousPoint = $inheritStor->getValue('previous') ?? 0;
|
||||||
|
if ($previousPoint < $reqAmount) {
|
||||||
|
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$inheritBuffList[$type] = $level;
|
||||||
|
$general->setAuxVar('inheritBuff', $inheritBuffList);
|
||||||
|
$inheritStor->setValue('previous', $previousPoint - $reqAmount);
|
||||||
|
$general->flushUpdateValues();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ class BuySpecificUnique extends \sammo\BaseAPI
|
|||||||
])
|
])
|
||||||
->rule('integer', 'amount')
|
->rule('integer', 'amount')
|
||||||
->rule('min', GameConst::$inheritItemUniqueMinPoint)
|
->rule('min', GameConst::$inheritItemUniqueMinPoint)
|
||||||
->rule('keyExists', $availableItems);
|
->rule('keyExists', 'item', $availableItems);
|
||||||
|
|
||||||
if (!$v->validate()) {
|
if (!$v->validate()) {
|
||||||
return $v->errorStr();
|
return $v->errorStr();
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?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 ResetSpecialWar extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
//KVStrorage, 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 '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$currentSpecialWar = $general->getVar('special2');
|
||||||
|
if($currentSpecialWar === null || $currentSpecialWar == 'None'){
|
||||||
|
return '이미 전투 특기가 공란입니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentLevel = $general->getAuxVar('inheritResetSpecialWar') ?? -1;
|
||||||
|
$nextLevel = $currentLevel + 1;
|
||||||
|
while (count(GameConst::$inheritResetAttrPointBase) <= $nextLevel) {
|
||||||
|
$baseLen = count(GameConst::$inheritResetAttrPointBase);
|
||||||
|
GameConst::$inheritResetAttrPointBase[] = GameConst::$inheritResetAttrPointBase[$baseLen - 1] + GameConst::$inheritResetAttrPointBase[$baseLen - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
$reqPoint = GameConst::$inheritResetAttrPointBase[$nextLevel];
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||||
|
$previousPoint = $inheritStor->getValue('previous') ?? 0;
|
||||||
|
if ($previousPoint < $reqPoint) {
|
||||||
|
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$general->setAuxVar('inheritResetSpecialWar', $nextLevel);
|
||||||
|
$general->setVar('special2', 'None');
|
||||||
|
$inheritStor->setValue('previous', $previousPoint - $reqPoint);
|
||||||
|
$general->flushUpdateValues();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\InheritAction;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use sammo\Session;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\GameConst;
|
||||||
|
use sammo\General;
|
||||||
|
use sammo\KVStorage;
|
||||||
|
use sammo\TimeUtil;
|
||||||
|
use sammo\Util;
|
||||||
|
|
||||||
|
class ResetTurnTime extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
//KVStrorage, 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 '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentLevel = $general->getAuxVar('inheritResetTurnTime') ?? -1;
|
||||||
|
$nextLevel = $currentLevel + 1;
|
||||||
|
while (count(GameConst::$inheritResetAttrPointBase) <= $nextLevel) {
|
||||||
|
$baseLen = count(GameConst::$inheritResetAttrPointBase);
|
||||||
|
GameConst::$inheritResetAttrPointBase[] = GameConst::$inheritResetAttrPointBase[$baseLen - 1] + GameConst::$inheritResetAttrPointBase[$baseLen - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
$reqPoint = GameConst::$inheritResetAttrPointBase[$nextLevel];
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||||
|
$previousPoint = $inheritStor->getValue('previous') ?? 0;
|
||||||
|
if ($previousPoint < $reqPoint) {
|
||||||
|
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$gameStor = new KVStorage($db, 'game_env');
|
||||||
|
[$turnTerm, $serverTurnTime] = $gameStor->getValuesAsArray(['turnterm', 'turntime']);
|
||||||
|
|
||||||
|
$serverTurnTimeObj = new DateTimeImmutable($serverTurnTime);
|
||||||
|
$turnTime = new DateTimeImmutable($general->getTurnTime());
|
||||||
|
|
||||||
|
$afterTurn = Util::randRange($turnTerm * -60 / 2, $turnTerm * 60 / 2);
|
||||||
|
|
||||||
|
$turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($afterTurn));
|
||||||
|
if($turnTime <= $serverTurnTimeObj){
|
||||||
|
$turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 60));
|
||||||
|
}
|
||||||
|
|
||||||
|
$general->setVar('turntime', TimeUtil::format($turnTime, true));
|
||||||
|
$general->setAuxVar('inheritResetTurnTime', $nextLevel);
|
||||||
|
$inheritStor->setValue('previous', $previousPoint - $reqPoint);
|
||||||
|
$general->flushUpdateValues();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?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 SetNextSpecialWar extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
$v = new Validator($this->args);
|
||||||
|
$v->rule('required', [
|
||||||
|
'type',
|
||||||
|
])
|
||||||
|
->rule('in', 'type', GameConst::$availableSpecialWar);
|
||||||
|
|
||||||
|
if (!$v->validate()) {
|
||||||
|
return $v->errorStr();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
$type = $this->args['type'];
|
||||||
|
|
||||||
|
$general = General::createGeneralObjFromDB($generalID);
|
||||||
|
if ($userID != $general->getVar('owner')) {
|
||||||
|
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$inheritSpecificSpecialWar = $general->getAuxVar('inheritSpecificSpecialWar');
|
||||||
|
$currentSpecialWar = $general->getVar('special2');
|
||||||
|
|
||||||
|
if ($currentSpecialWar == $type) {
|
||||||
|
return '이미 그 특기를 보유하고 있습니다.';
|
||||||
|
}
|
||||||
|
if ($inheritSpecificSpecialWar == $type) {
|
||||||
|
return '이미 그 특기를 예약하였습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($inheritSpecificSpecialWar !== null){
|
||||||
|
return '이미 예약한 특기가 있습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$reqAmount = GameConst::$inheritSpecificSpecialPoint;
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
|
||||||
|
$previousPoint = $inheritStor->getValue('previous') ?? 0;
|
||||||
|
if ($previousPoint < $reqAmount) {
|
||||||
|
return '충분한 유산 포인트를 가지고 있지 않습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$general->setAuxVar('inheritSpecificSpecialWar', $type);
|
||||||
|
$inheritStor->setValue('previous', $previousPoint - $reqAmount);
|
||||||
|
$general->flushUpdateValues();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -201,6 +201,9 @@ class GameConstBase
|
|||||||
public static $inheritBornStatPoint = 1000;
|
public static $inheritBornStatPoint = 1000;
|
||||||
public static $inheritItemUniqueMinPoint = 5000;
|
public static $inheritItemUniqueMinPoint = 5000;
|
||||||
public static $inheritItemRandomPoint = 3000;
|
public static $inheritItemRandomPoint = 3000;
|
||||||
|
public static $inheritBuffPoints = [0, 250, 750, 1500, 2500, 3750];
|
||||||
|
public static $inheritSpecificSpecialPoint = 5000;
|
||||||
|
public static $inheritResetAttrPointBase = [1000, 1000, 2000, 3000];//필요하면 늘려서 쓰기
|
||||||
|
|
||||||
public static $allItems = [
|
public static $allItems = [
|
||||||
'horse' => [
|
'horse' => [
|
||||||
|
|||||||
Reference in New Issue
Block a user