아이템 구현. 장비매매 추가

This commit is contained in:
2018-10-21 01:55:09 +09:00
parent 05fcb5397e
commit b6db653f41
28 changed files with 777 additions and 208 deletions
+35
View File
@@ -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;
}
}
+25
View File
@@ -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;
}
}
+5
View File
@@ -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;
}
+1 -1
View File
@@ -64,7 +64,7 @@ class ReqCityCapacity extends Constraint{
}
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaUn} 모자랍니다.";
$this->reason = "{$keyNick}{$josaUn} 부족합니다.";
return false;
}
}
+2 -2
View File
@@ -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;
}
+77
View File
@@ -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;
}
}