feat,game: 장비매매시 반응하는 트리거 추가, 판매시 국고에 추가되는 유니크 추가

This commit is contained in:
2022-02-20 04:34:10 +09:00
parent 435044dddd
commit 91c46f465b
2 changed files with 81 additions and 78 deletions
@@ -0,0 +1,58 @@
<?php
namespace sammo\ActionItem;
use sammo\DB;
use \sammo\iAction;
use \sammo\General;
use sammo\KVStorage;
use sammo\Util;
class che_보물_도기 extends \sammo\BaseItem
{
protected $rawName = '도기';
protected $name = '도기(보물)';
protected $info = '[개인] 판매 시 국고에 금, 쌀 중 하나를 추가 (+10,000, 5년마다 +10,000)';
protected $cost = 200;
protected $consumable = false;
public function onArbitraryAction(General $general, string $actionType, ?string $phase = null, $aux = null): ?array
{
if ($aux === null){
return $aux;
}
if ($actionType !== '장비매매') {
return $aux;
}
if ($phase !== '판매') {
return $aux;
}
if (($aux['itemCode']??'') !== Util::getClassNameFromObj($this)){
return $aux;
}
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
[$year, $startYear] = $gameStor->getValuesAsArray(['year', 'startyear']);
$relYear = $year - $startYear;
$score = 10000 * (1 + Util::valueFit(intdiv($relYear, 5), 0));
[$resName, $resKey] = Util::choiceRandom([
['금', 'gold'],
['쌀', 'rice']
]);
$db->update('nation', [
$resKey => $db->sqleval('%b + %i', $resKey, $score)
]);
$score = Util::round($score);
$scoreText = number_format($score, 0);
$logger = $general->getLogger();
$logger->pushGeneralActionLog("국고에 {$resName} <C>{$scoreText}</>을 보충합니다.");
return $aux;
}
}
+23 -78
View File
@@ -173,11 +173,13 @@ class che_장비매매 extends Command\GeneralCommand
if ($buying) {
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 구입했습니다. <1>$date</>");
$general->increaseVarWithLimit('gold', -$cost, 0);
$general->setVar($itemType, $itemCode);
$general->setItem($itemType, $itemCode);
$general->onArbitraryAction($general, '장비매매', '구매', ['itemCode' => $itemCode]);
} else {
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 판매했습니다. <1>$date</>");
$general->increaseVarWithLimit('gold', $cost / 2);
$general->deleteItem($itemType);
$general->onArbitraryAction($general, '장비매매', '판매', ['itemCode' => $itemCode]);
$general->setItem($itemType, null);
}
$exp = 10;
@@ -209,96 +211,39 @@ class che_장비매매 extends Command\GeneralCommand
continue;
}
$values[] = [
'id'=>$itemCode,
'name'=>$item->getName(),
'reqSecu'=>$item->getReqSecu(),
'cost'=>$item->getCost(),
'info'=>$item->getInfo(),
'isBuyable'=>$item->isBuyable(),//항상 true지만, 일관성을 위해
'id' => $itemCode,
'name' => $item->getName(),
'reqSecu' => $item->getReqSecu(),
'cost' => $item->getCost(),
'info' => $item->getInfo(),
'isBuyable' => $item->isBuyable(), //항상 true지만, 일관성을 위해
];
}
$itemList[$itemType] = [
'typeName'=>$typeName,
'values'=>$values
'typeName' => $typeName,
'values' => $values
];
}
$ownItem = [];
foreach($general->getItems() as $itemType => $item){
foreach ($general->getItems() as $itemType => $item) {
$ownItem[$itemType] = [
'id'=>$item->getRawClassName(),
'name'=>$item->getName(),
'reqSecu'=>$item->getReqSecu(),
'cost'=>$item->getCost(),
'info'=>$item->getInfo(),
'isBuyable'=>$item->isBuyable(),
'id' => $item->getRawClassName(),
'name' => $item->getName(),
'reqSecu' => $item->getReqSecu(),
'cost' => $item->getCost(),
'info' => $item->getInfo(),
'isBuyable' => $item->isBuyable(),
];
}
return [
'procRes' => [
'citySecu'=>$citySecu,
'gold'=>$general->getVar('gold'),
'itemList'=>$itemList,
'ownItem'=>$ownItem,
'citySecu' => $citySecu,
'gold' => $general->getVar('gold'),
'itemList' => $itemList,
'ownItem' => $ownItem,
]
];
}
public function getForm(): string
{
$form = [];
$db = DB::db();
$citySecu = $db->queryFirstField('SELECT secu FROM city WHERE city = %i', $this->generalObj->getCityID());
$gold = $this->generalObj->getVar('gold');
ob_start();
?>
<script>
function updateItemType() {
$('#itemType').val($('#itemCode option:selected').data('item_type'));
}
$(function() {
$('#customSubmit').click(function() {
updateItemType();
submitAction();
});
});
</script>
<input type="hidden" class="formInput" name="itemType" id="itemType" value="item">
장비를 구입하거나 매각합니다.<br>
현재 구입 불가능한 것은 <font color=red>붉은색</font>으로 표시됩니다.<br>
현재 도시 치안 : <?= $citySecu ?> &nbsp;&nbsp;&nbsp;현재 자금 : <?= $gold ?><br>
장비 : <select class='formInput' name="itemCode" id="itemCode" onchange='updateItemType();' size='1' style='color:white;background-color:black;'>
<?php foreach (GameConst::$allItems as $itemType => $itemCategories) :
//매각
$typeName = static::$itemMap[$itemType];
?>
<option value='None' data-item_type='<?= $itemType ?>' style='color:skyblue'>_____<?= $typeName ?>매각(반값)____</option>
<?php foreach ($itemCategories as $itemCode => $cnt) :
if ($cnt > 0) {
continue;
}
$itemClass = buildItemClass($itemCode);
if (!$itemClass->isBuyable()) {
continue;
}
$itemName = $itemClass->getName();
$reqSecu = $itemClass->getReqSecu();
$reqGold = $itemClass->getCost();
$css = '';
if ($reqSecu > $citySecu) {
$css = 'color:red;';
}
?>
<option value='<?= $itemCode ?>' data-item_type='<?= $itemType ?>' style='<?= $css ?>'><?= $itemName ?> 가격: <?= $reqGold ?></option>
<?php endforeach; ?>
<?php endforeach; ?>
</select>
<input type=button id="customSubmit" value="<?= $this->getName() ?>"><br>
<?php
return ob_get_clean();
}
}