아이템 구현. 장비매매 추가
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace sammo\ActionItem;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
use function sammo\isConsumable;
|
||||
use function sammo\getItemInfo;
|
||||
use function sammo\getItemCost2;
|
||||
|
||||
//XXX:임시용!
|
||||
class che_Dummy extends \sammo\BaseItem{
|
||||
|
||||
public $id;
|
||||
public $name;
|
||||
public $info;
|
||||
public $cost;
|
||||
public $consumable = false;
|
||||
|
||||
public function __construct(int $itemCode)
|
||||
{
|
||||
$this->id = $itemCode = true;
|
||||
[$this->name, $this->info] = getItemInfo($itemCode);
|
||||
$this->cost = getItemCost2($itemCode);
|
||||
$this->consumable = isConsumable($itemCode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
class che_계략_삼략 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 22;
|
||||
public $name = '삼략(계략)';
|
||||
public $info = '[계략] 화계·탈취·파괴·선동 : 성공률 +20%p';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{
|
||||
if($turnType == '계략'){
|
||||
if($varType == 'success') return $value + 0.2;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralCommand' && $command == '계략'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
class che_계략_육도 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 21;
|
||||
public $name = '육도(계략)';
|
||||
public $info = '[계략] 화계·탈취·파괴·선동 : 성공률 +20%p';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{
|
||||
if($turnType == '계략'){
|
||||
if($varType == 'success') return $value + 0.2;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralCommand' && $command == '계략'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
class che_계략_이추 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 5;
|
||||
public $name = '이추(계략)';
|
||||
public $info = '[계략] 화계·탈취·파괴·선동 : 성공률 +10%p';
|
||||
public $cost = 1000;
|
||||
public $consumable = true;
|
||||
|
||||
public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{
|
||||
if($turnType == '계략'){
|
||||
if($varType == 'success') return $value + 0.1;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralCommand' && $command == '계략'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
class che_계략_향낭 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 5;
|
||||
public $name = '항냥(계략)';
|
||||
public $info = '[계략] 화계·탈취·파괴·선동 : 성공률 +20%p';
|
||||
public $cost = 3000;
|
||||
public $consumable = true;
|
||||
|
||||
public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float{
|
||||
if($turnType == '계략'){
|
||||
if($varType == 'success') return $value + 0.2;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralCommand' && $command == '계략'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_의술_청낭서 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 23;
|
||||
public $name = '청낭서(의술)';
|
||||
public $info = '[군사] 매 턴마다 자신(100%)과 소속 도시 장수(적 포함 50%) 부상 회복<br>[전투] 페이즈마다 20% 확률로 치료 발동(아군 피해 1/3 감소)';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_도시치료($general)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
class che_의술_태평청령 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 24;
|
||||
public $name = '태평청령(의술)';
|
||||
public $info = '[군사] 매 턴마다 자신(100%)과 소속 도시 장수(적 포함 50%) 부상 회복<br>[전투] 페이즈마다 20% 확률로 치료 발동(아군 피해 1/3 감소)';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_도시치료($general)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_도소연명 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 9;
|
||||
public $name = '도소연명(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복.';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_무후행군 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 8;
|
||||
public $name = '무후행군(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복.';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_오석산 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 7;
|
||||
public $name = '오석산(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복.';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_정력견혈 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 11;
|
||||
public $name = '정력견혈(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복.';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_칠엽청점 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 10;
|
||||
public $name = '칠엽청점(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복.';
|
||||
public $cost = 200;
|
||||
public $consumable = false;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace sammo\ActionNationType;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
use \sammo\GeneralTrigger;
|
||||
|
||||
class che_치료_환약 extends \sammo\BaseItem{
|
||||
|
||||
public $id = 1;
|
||||
public $name = '환약(치료)';
|
||||
public $info = '[군사] 턴 실행 전 부상 회복. 1회용';
|
||||
public $cost = 100;
|
||||
public $consumable = true;
|
||||
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller{
|
||||
return new GeneralTriggerCaller([
|
||||
new GeneralTrigger\che_아이템치료($general)
|
||||
]);
|
||||
}
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
if($actionType == 'GeneralTrigger' && $command == 'che_아이템치료'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
use \sammo\iAction;
|
||||
use \sammo\General;
|
||||
|
||||
//XXX: 아직 아이템 구현이 끝나지 않았으므로 바뀔 수 있음
|
||||
class BaseItem implements iAction{
|
||||
use \sammo\DefaultAction;
|
||||
|
||||
static $id = 0;
|
||||
static $name = '-';
|
||||
static $info = '';
|
||||
static $consumable = false;
|
||||
|
||||
function isValidTurnItem(string $actionType, string $command):bool{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
namespace sammo\GeneralCommand;
|
||||
|
||||
//TODO: 아이템 클래스 재확정 후 재 구현!
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use function \sammo\{
|
||||
uniqueItemEx,
|
||||
getItemCost, getItemCost2,
|
||||
getItemInfo,
|
||||
getHorseName, getWeapName, getBookName, getItemName
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
|
||||
class che_장비매매 extends Command\GeneralCommand{
|
||||
static protected $actionName = '장비매매';
|
||||
|
||||
static $itemMap = [
|
||||
'horse'=>'명마',
|
||||
'weap'=>'무기',
|
||||
'book'=>'서적',
|
||||
'item'=>'도구',
|
||||
];
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
$itemType = $this->arg['itemType'];
|
||||
$itemTypeName = static::$itemMap[$itemType];
|
||||
$itemCode = $this->arg['itemCode'];
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['ReqCityTrader', $general->getVar('npc')],
|
||||
['ReqCityCapacity', 'secu', '치안 수치', $itemCode * 1000],
|
||||
['ReqGeneralGold', $reqGold],
|
||||
['ReqGeneralRice', $reqRice],
|
||||
];
|
||||
|
||||
if($itemCode == 0){
|
||||
$this->runnableConstraints[] = ['ReqGeneralValue', $itemType, $itemTypeName, 1];
|
||||
}
|
||||
else if($itemCode == $general->getVar($itemType)){
|
||||
$this->runnableConstraints = [['AlwaysFail', '이미 가지고 있습니다.']];
|
||||
}
|
||||
else if($itemType != 'item' && $general->getVar($itemType) > 6){
|
||||
$this->runnableConstraints[] = [['AlwaysFail', '이미 진귀한 것을 가지고 있습니다.']];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function argTest():bool{
|
||||
$itemType = $this->arg['itemType']??null;
|
||||
if(!in_array($itemType, array_keys(static::$itemMap))){
|
||||
return false;
|
||||
}
|
||||
$itemCode = $this->arg['itemCode']??null;
|
||||
if(!is_int($itemCode)){
|
||||
return false;
|
||||
}
|
||||
if($itemCode < 0 || 6 < $itemCode){
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'itemType'=>$itemType,
|
||||
'itemCode'=>$itemCode
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$itemType = $this->arg['itemType'];
|
||||
$itemCode = $this->arg['itemCode'];
|
||||
if($itemType == 'item'){
|
||||
$reqGold = getItemCost2($itemCode);
|
||||
}
|
||||
else{
|
||||
$reqGold = getItemCost($itemCode);
|
||||
}
|
||||
return [$reqGold, 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = substr($general->getVar('turntime'),11,5);
|
||||
|
||||
$itemType = $this->arg['itemType'];
|
||||
$itemCode = $this->arg['itemCode'];
|
||||
|
||||
if($itemCode == 0){
|
||||
$buying = false;
|
||||
$itemCode = $general->getVar($itemType);
|
||||
if($itemType == 'item'){
|
||||
$cost = getItemCost2($itemCode);
|
||||
}
|
||||
else{
|
||||
$cost = getItemCost($itemCode);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buying = true;
|
||||
$cost = $this->getCost()[0];
|
||||
}
|
||||
|
||||
if($itemType == 'horse'){
|
||||
$itemName = getHorseName($itemCode);
|
||||
}
|
||||
else if($itemType == 'weap'){
|
||||
$itemName = getWeapName($itemCode);
|
||||
}
|
||||
else if($itemType == 'book'){
|
||||
$itemName = getBookName($itemCode);
|
||||
}
|
||||
else{
|
||||
$itemName = getItemName($itemCode);
|
||||
}
|
||||
$josaUl = JosaUtil::pick($itemName, '을');
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
if($buying){
|
||||
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 구입했습니다. <1>$date</>");
|
||||
$general->increaseVarWithLimit('gold', -$cost, 0);
|
||||
$general->setVar($itemType, $itemCode);
|
||||
}
|
||||
else{
|
||||
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 판매했습니다. <1>$date</>");
|
||||
$general->increaseVarWithLimit('gold', $cost / 2);
|
||||
$general->setVar($itemType, 0);
|
||||
}
|
||||
|
||||
$exp = 10;
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
//일일히 클래스를 만들기 싫을 때 간단히 끝내는 Constraint
|
||||
|
||||
class AdhocCallback extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_ARG;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_callable($this->arg)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require callback");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
$reason = ($this->arg)();
|
||||
if($reason === null){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = $reason;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
//일일히 클래스를 만들기 싫을 때 간단히 끝내는 Constraint
|
||||
|
||||
class AlwaysFail extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_STRING_ARG;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
$this->reason = $this->arg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ class OccupiedCity extends Constraint{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
//특수 예외로 ARG가 지정된 경우에는 재야여도 'OccupiedCity'로 허용함
|
||||
if($this->arg && $this->general['nation'] == 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->city['nation'] == $this->general['nation']){
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class ReqCityCapacity extends Constraint{
|
||||
}
|
||||
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaUn} 모자랍니다.";
|
||||
$this->reason = "{$keyNick}{$josaUn} 부족합니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class ReqCityTrader extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_CITY;
|
||||
const REQ_VALUES = Constraint::REQ_CITY|Constraint::REQ_INT_ARG;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
@@ -22,7 +22,7 @@ class ReqCityTrader extends Constraint{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->city['trade'] !== null){
|
||||
if($this->city['trade'] !== null || $this->arg >= 2){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
use \sammo\JosaUtil;
|
||||
use \sammo\Util;
|
||||
|
||||
class RegGeneralValue extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG;
|
||||
|
||||
protected $key;
|
||||
protected $maxKey;
|
||||
protected $keyNick;
|
||||
protected $reqVal;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
[$this->key, $this->keyNick, $this->reqVal] = $this->arg;
|
||||
|
||||
$this->maxKey = $this->key.'2';
|
||||
|
||||
if(!key_exists($this->key, $this->city)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->key} in city");
|
||||
}
|
||||
|
||||
if(is_numeric($this->reqVal)){
|
||||
$this->isPercent = false;
|
||||
}
|
||||
else if(is_str($this->reqVal)){
|
||||
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
|
||||
if($this->reqVal === null){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
|
||||
}
|
||||
|
||||
if(!key_exists($this->maxKey, $this->city)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->maxKey} in general");
|
||||
}
|
||||
$this->isPercent = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->isPercent){
|
||||
if($this->general[$this->key] >= $this->general[$this->maxKey] * $this->reqVal){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
if($this->general[$this->key] >= $this->reqVal){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->reqVal === 1){
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaUn} 없습니다.";
|
||||
}
|
||||
else{
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaUn} 부족합니다.";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,10 @@ trait DefaultAction{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $stat, $value){
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function onCalcStrategic(string $turnType, string $varType, $value){
|
||||
return $value;
|
||||
}
|
||||
|
||||
+17
-1
@@ -79,10 +79,26 @@ class General implements iAction{
|
||||
|
||||
$personalityClass = getPersonalityClass($raw['personal']);
|
||||
$this->personalityObj = new $personalityClass;
|
||||
|
||||
|
||||
$itemClass = getItemClass($raw['item']);
|
||||
if($itemClass !== null){
|
||||
$this->itemObjs['item'] = new $itemClass;
|
||||
}
|
||||
else{
|
||||
$this->itemObjs['item'] = new ActionItem\che_Dummy($raw['item']);
|
||||
}
|
||||
//TODO: $specialItemClass 설정
|
||||
}
|
||||
|
||||
function deleteItem(){
|
||||
$this->setVar('item', 0);
|
||||
$this->itemObjs['item'] = new ActionItem\che_Dummy(0);
|
||||
}
|
||||
|
||||
function getItem():BaseItem{
|
||||
return $this->itemObjs['item'];
|
||||
}
|
||||
|
||||
function getLastTurn():LastTurn{
|
||||
return $this->lastTurn;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace sammo\GeneralTrigger;
|
||||
use sammo\BaseGeneralTrigger;
|
||||
use sammo\General;
|
||||
use sammo\ActionLogger;
|
||||
use sammo\DB;
|
||||
use sammo\Util;
|
||||
use sammo\JosaUtil;
|
||||
|
||||
class che_아이템치료 extends BaseGeneralTrigger{
|
||||
static protected $priority = 20010;
|
||||
|
||||
public function action(?array $env=null, $arg=null):?array{
|
||||
|
||||
/** @var \sammo\General $general */
|
||||
$general = $this->object;
|
||||
|
||||
if($general->getVar('injury') > 0){
|
||||
$general->updateVar('injury', 0);
|
||||
$general->activateSkill('pre.부상경감', 'pre.치료');
|
||||
$itemObj = $general->getItem();
|
||||
$itemName = $itemObj->$name;
|
||||
$josaUl = JosaUtil::pick($itemName, '을');
|
||||
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 사용하여 치료합니다!", ActionLogger::PLAIN);
|
||||
|
||||
if($itemObj::$consumable && $itemObj->isValidTurnItem('GeneralTrigger', 'che_아이템치료')){
|
||||
$general->deleteItem();
|
||||
}
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
namespace sammo;
|
||||
|
||||
interface iAction{
|
||||
//TODO: 능력치는?
|
||||
public function getPreTurnExecuteTriggerList(General $general):?GeneralTriggerCaller;
|
||||
public function onCalcDomestic(string $turnType, string $varType, float $value, $aux=null):float;
|
||||
|
||||
public function onPreGeneralStatUpdate(General $general, string $statName, $value);
|
||||
|
||||
public function onCalcStat(General $general, string $stat, $value);
|
||||
public function onCalcStrategic(string $turnType, string $varType, $value);
|
||||
public function onCalcNationalIncome(string $type, int $amount):int;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user