This commit is contained in:
aozhiwei 2021-12-30 17:16:25 +08:00
parent 96fd43af5f
commit 47cbe1b215
4 changed files with 54 additions and 51 deletions

View File

@ -84,7 +84,7 @@ CREATE TABLE `t_hero` (
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `account_id_hero_id` (`account_id`, `hero_id`)
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -51,10 +51,10 @@ class HeroController extends BaseAuthedController {
public function takeonSkin()
{
$heroId = getReqVal('hero_id', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$skinId = getReqVal('skin_id', 0);
$heroDb = Hero::find($heroId);
$heroSkinDb = Hero::find($skinId);
$heroDb = Hero::find($heroUniId);
$heroSkinDb = HeroSkin::find($skinId);
if (!$heroDb) {
$this->_rspErr(1, '你还没这个英雄');
return;
@ -63,15 +63,15 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(2, '你还没这个皮肤');
return;
}
Hero::takeonSkin($heroId, $skinId);
Hero::takeonSkin($heroUniId, $skinId);
$this->_rspOk();
}
public function upgradeSkill()
{
$heroId = getReqVal('hero_id', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$skillIdx = getReqVal('skill_idx', 0);
$heroDb = Hero::find($heroId);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, '你还没这个英雄');
return;
@ -80,15 +80,7 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1, 'skill_idx参数必须为0-1');
return;
}
Hero::upgradeSkill($heroId, $skillIdx);
$this->_rspOk();
}
public function useYokeItem()
{
$heroId = getReqVal('hero_id', 0);
$itemId = getReqVal('item_id', 0);
$itemNum = getReqVal('item_num', 0);
Hero::upgradeSkill($heroUniId, $skillIdx);
$this->_rspOk();
}

View File

@ -10,31 +10,55 @@ use phpcommon\SqlHelper;
class Hero extends BaseModel {
public static function find($heroId)
const GETED_STATE = 0;
const TRY_STATE = 1;
const NO_LOCK = 1;
const LEVEL_LOCK = 1;
const QUALITY_LOCK = 2;
public static function find($heroUniId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId,
'idx' => $heroUniId,
)
);
if ($row) {
$row['hero_uniid'] = $row['idx'];
}
return $row;
}
public static function toDto($row)
{
return array(
$attr = emptyReplace(json_decode($row['attr'], true), array());
$lockType = 0;
$lockTime = 0;
if ($row['lock_type'] != 0 && $row['unlock_time'] - myself()->_getNowTime() > 0) {
$lockType = $row['lock_type'];
$lockTime = $row['unlock_time'] - myself()->_getNowTime();
}
$tradeLocktime = max(0, $row['unlock_trade_time'] - myself()->_getNowTime());
$dto = array(
'hero_id' => $row['hero_id'],
'hero_lv' => $row['hero_lv'],
'hero_tili' => $row['hero_tili'],
'state' => $row['state'],
'skin_id' => $row['skin_id'],
'quality' => $row['quality'],
'skill_lv1' => $row['skill_lv1'],
'skill_lv2' => $row['skill_lv2'],
'yoke_lv' => $row['yoke_lv'],
'yoke_exp' => $row['yoke_exp'],
'attr' => $attr,
'try_count' => $row['try_count'],
'lock_type' => $lockType,
'lock_time' => $lockTime,
'trade_locktime' => $tradeLocktime,
);
return $dto;
}
public static function addHero($heroMeta)
@ -54,63 +78,50 @@ class Hero extends BaseModel {
'hero_id' => $heroMeta['id'],
'hero_lv' => 1,
'hero_tili' => $realHeroMeta ? $realHeroMeta['tili'] : 0,
'state' => self::GETED_STATE,
#'skin_id' => $defSkin,
'skill_lv1' => 1,
'skill_lv2' => 1,
'yoke_lv' => 0,
'yoke_exp' => 0,
'attr' => '[]',
'lock_type' => self::NO_LOCK,
'unlock_time' => 0,
'unlock_trade_time' => 0,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function takeonSkin($heroId, $skinId)
public static function takeonSkin($heroUniId, $skinId)
{
SqlHelper::update(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroMeta['id']
),
array(
'skin_id' => $skinId,
'modifytime' => myself()->_getNowTime()
)
);
self::update($heroUniId, array(
'skin_id' => $skinId,
'modifytime' => myself()->_getNowTime()
));
}
public static function upgradeSkill($heroId, $skillIdx)
public static function upgradeSkill($heroUniId, $skillIdx)
{
if (!in_array($skillIdx, array(0, 1))) {
return;
}
$fieldName = 'skill_lv' . ($skillIdx + 1);
SqlHelper::update(
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId
),
array(
self::update($heroUniId, array(
$fieldName => function () use($fieldName) {
return "${fieldName} + 1";
},
'modifytime' => myself()->_getNowTime()
)
);
));
}
public static function update($heroId, $fieldsKv)
public static function update($heroUniId, $fieldsKv)
{
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId,
'idx' => $heroUniId,
),
$fieldsKv
);

View File

@ -301,7 +301,7 @@ class BattleDataService extends BaseService {
private function decCost()
{
$heroDb = Hero::find(getReqVal('hero_id', 0));
$heroDb = Hero::find(getReqVal('hero_uniid', 0));
if (!$heroDb) {
return false;
}
@ -309,7 +309,7 @@ class BattleDataService extends BaseService {
if ($heroDb['hero_tili'] < $costTili) {
return false;
}
Hero::update($heroDb['hero_id'], array(
Hero::update($heroDb['hero_uniid'], array(
'hero_tili' => function () use($costTili) {
return "GREATEST(0, hero_tili - ${costTili})";
}