Files
core/hwe/sammo/Event/Condition/Logic.php
T
Hide_D 83d6a2169b 유산 포인트 시스템, 추가 기수 대비 (#187)
- 유산 포인트
  - 기수 뒤로도 누적되는 포인트
  - 생존, 최대 임관년 수, 최대 연속 내정 성공, 병종 상성 우위 횟수, 전투 횟수, 계략 성공 횟수, 천통 기여(규모 상승, 천통 수뇌, 천통 군주), 숙련도, 토너먼트, 베팅 당첨
  - 유산 관리 페이지 제공

- 태수국
  - 181년 1월에 자동 생성되는 u장수국
  - 시간이 지나면 사실상 자동 소멸
  - 유저국과는 4칸 거리, 서로는 2칸 거리
  - 이 시스템으로 인해 m장 거병 차단

- NPC 원조시 불가침
  - 1년 세수만큼 받은 경우 24개월 불가침 제안
  - 최소 6개월
  - 불가침을 받지 않고 추가 원조한 경우 계속해서 기간 상승
  - 단, 불가침 수락 전에 선포를 할 수 있음

Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/187
Co-authored-by: hide_d <hided62@gmail.com>
Co-committed-by: hide_d <hided62@gmail.com>
2021-08-11 21:57:52 +09:00

111 lines
2.8 KiB
PHP

<?php
namespace sammo\Event\Condition;
use sammo\Event\Condition;
class Logic extends \sammo\Event\Condition{
private $mode = 'and';
/** @var \sammo\Event\Condition[] */
private $conditions = [];
const AVAILABLE_LOGIC_NAME = [
'not'=>false,
'and'=>true,
'or'=>true,
'xor'=>true
];
public function __construct(string $mode, ...$conditions){
$mode = strtolower($mode);
if(!array_key_exists($mode, self::AVAILABLE_LOGIC_NAME)){
throw new \InvalidArgumentException('첫번째 인자는 not, and, or, xor 중 하나여야 합니다.');
}
if(!self::AVAILABLE_LOGIC_NAME[$mode] && count($conditions)>1){
throw new \InvalidArgumentException('조건을 하나만 받을 수 있습니다.');
}
$this->mode = $mode;
$this->conditions = array_map(function($condition){
return Condition::build($condition);
}, $conditions);
}
public function eval($env=null){
switch($this->mode){
case 'not':
return $this->logicNot($env);
case 'and':
return $this->logicAnd($env);
case 'or':
return $this->logicOr($env);
case 'xor':
return $this->logicXor($env);
}
throw new \InvalidArgumentException('올바르지 않은 mode.');
}
private function logicNot($env){
$result = self::_eval($this->conditions[0], $env);
$result['value'] = !$result['value'];
$result['chain'][] = 'not';
return $result;
}
private function logicAnd($env){
$value = true;
$chain = [];
foreach($this->conditions as $cond){
$sub = self::_eval($cond, $env);
$chain[] = $sub['chain'];
if(!$sub['value']){
$value = false;
break;
}
}
return [
'value'=>$value,
'chain'=>[$chain, 'and']
];
}
private function logicOr($env){
$value = false;
$chain = [];
foreach($this->conditions as $cond){
$sub = self::_eval($cond, $env);
$chain[] = $sub['chain'];
if($sub['value']){
$value = true;
break;
}
}
return [
'value'=>$value,
'chain'=>[$chain, 'or']
];
}
private function logicXor($env){
$value = false;
$chain = [];
foreach($this->conditions as $cond){
$sub = self::_eval($cond, $env);
$chain[] = $sub['chain'];
$value ^= $sub['value'];
}
return [
'value'=>$value,
'chain'=>[$chain, 'xor']
];
}
}