Files
core/hwe/sammo/AbsGeneralPool.php
T
Hide_D c5ceff6fb5 feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정
- 기존의 랜덤 코드는 deprecated 처리
- 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용
- 랜덤 생성 단위
  - 월 실행
  - 사령턴 실행 결과
  - 커맨드 실행 결과
  - 작위 보상
  - 부대장 생성
  - 유니크 획득 시도
  - 설문 조사
  - 장수 생성
  - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅
  - 전투
  - 도시 점령
  - 자율 행동 선택
  - 랜덤 턴 변경
- 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
2022-05-17 03:46:59 +09:00

112 lines
3.0 KiB
PHP

<?php
namespace sammo;
use MeekroDB;
use sammo\GameConst;
use sammo\Scenario\GeneralBuilder;
use sammo\Util;
abstract class AbsGeneralPool{
protected $builder;
protected $info;
protected $db=null;
protected $uniqueName;
protected $generalName;
protected $validUntil;
/*
* info = [
* uniqueName
* generalName
* imgsvr
* picture
*
* leadership
* strength
* intel
*
* experience
* dedication
*
* dex[5]
*
* specialDomestic
* specialWar
*/
public function __construct(\MeekroDB $db, RandUtil $rng, array $info, string $validUntil)
{
$this->db = $db;
$this->info = $info;
$this->uniqueName = $info['uniqueName'];
$this->generalName = $info['generalName'];
$this->builder = new GeneralBuilder(
$rng,
$info['generalName'],
$info['imgsvr'],
$info['picture'],
0
);
$this->validUntil = $validUntil;
$builder = $this->builder;
if(key_exists('leadership', $info)){
$builder->setStat($info['leadership'], $info['strength'], $info['intel']);
}
if(key_exists('experience', $info)){
$builder->setExpDed($info['experience'], $info['dedication']);
}
if(key_exists('dex', $info)){
$builder->setDex($info['dex'][0], $info['dex'][1], $info['dex'][2], $info['dex'][3], $info['dex'][4]);
}
if(key_exists('specialDomestic', $info) || key_exists('specialWar', $info)){
$builder->setSpecial($info['specialDomestic']??GameConst::$defaultSpecialDomestic, $info['specialWar']??GameConst::$defaultSpecialWar);
}
}
public function getUniqueName():string{
return $this->uniqueName;
}
public function getInfo():array{
return $this->info;
}
static protected function checkDuplicatedCnt(\MeekroDB $db, string $name):int{
$duplicateCnt = 0;
foreach(GeneralBuilder::$prefixList as $npcPrefix){
$testName = "{$npcPrefix}{$name}";
$duplicateCnt += $db->queryFirstField('SELECT count(no) FROM general WHERE name LIKE %s', $testName.'%');
}
return $duplicateCnt;
}
public function getGeneralBuilder():GeneralBuilder{
if(!$this->generalName){
throw new \RuntimeException('generalName not picked');
}
return $this->builder;
}
public function getValidUntil():string{
return $this->validUntil;
}
/**
* @param \MeekroDB $db
* @param int $owner
* @param int $pickCnt
* @param null|string $prefix
* @return AbsGeneralPool[]
*/
static abstract public function pickGeneralFromPool(\MeekroDB $db, RandUtil $rng, int $owner, int $pickCnt, ?string $prefix=null):array;
abstract public function occupyGeneralName():bool;
abstract public static function getPoolName():string;
abstract public static function initPool(\MeekroDB $db);
}