182 lines
5.1 KiB
PHP
182 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/DressAttribute.php');
|
|
require_once('mt/BattleRandAttribute.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class HeroSkin extends BaseModel {
|
|
|
|
const USED = 1;
|
|
const NO_USE = 0;
|
|
|
|
const LOCK = 0;
|
|
const NO_LOCK = 1;
|
|
|
|
public static function allSkinList($cb){
|
|
SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
),
|
|
function ($row) use($cb) {
|
|
$cb($row);
|
|
}
|
|
);
|
|
}
|
|
|
|
public static function getSkinList($skinId,$cb){
|
|
SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'skin_id' => $skinId
|
|
),
|
|
function ($row) use($cb) {
|
|
$cb($row);
|
|
}
|
|
);
|
|
}
|
|
|
|
public static function find($uniid)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $uniid,
|
|
)
|
|
);
|
|
if ($row && $row['account_id'] != myself()->_getAccountId()) {
|
|
$row = null;
|
|
}
|
|
return $row;
|
|
}
|
|
|
|
public static function findEx($uniid)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $uniid,
|
|
)
|
|
);
|
|
return $row;
|
|
}
|
|
|
|
public static function findByAccountId($accountId, $uniid)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $uniid,
|
|
)
|
|
);
|
|
if ($row && $row['account_id'] != $accountId) {
|
|
$row = null;
|
|
}
|
|
return $row;
|
|
}
|
|
|
|
public static function update($skinUniid,$fieldsKv){
|
|
if (self::find($skinUniid)){
|
|
SqlHelper::update(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'idx' => $skinUniid,
|
|
),
|
|
$fieldsKv
|
|
);
|
|
}
|
|
}
|
|
|
|
public static function toDto($row)
|
|
{
|
|
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
|
|
|
|
return array(
|
|
'idx' => $row['idx'],
|
|
'skin_uniid' => $row['idx'],
|
|
'account_id' => $row['account_id'],
|
|
'skin_id' => $row['skin_id'],
|
|
'hero_uniid' => $row['hero_uniid'],
|
|
'skin_state' => $row['skin_state'],
|
|
'used' => $row['used'],
|
|
'is_old' => $row['is_old'],
|
|
'rand_attr' => $attr,
|
|
'lucky' => self::getSkinLucky($row),
|
|
'wealth' => self::getSkinWealth($row),
|
|
);
|
|
}
|
|
|
|
public static function addSkin($itemMeta)
|
|
{
|
|
$rand_attr = array();
|
|
$wealth_attr = array();
|
|
$dressMeta = mt\DressAttribute::get($itemMeta['id']);
|
|
if ($dressMeta) {
|
|
$randMeta = mt\BattleRandAttribute::getByWeight($dressMeta['battleAttribute'],1);
|
|
$rand_attr = mt\BattleRandAttribute::getRandAttr($randMeta);
|
|
$wealth_attr = \mt\EconomyAttribute::getAttribute($dressMeta['economyAttribute'], 1);
|
|
}
|
|
SqlHelper::insert(
|
|
myself()->_getSelfMysql(),
|
|
't_hero_skin',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'skin_id' => $itemMeta['id'],
|
|
'skin_state' => self::LOCK,
|
|
'used' => self::NO_USE,
|
|
'get_from' => 0,
|
|
'consume_num' => 0,
|
|
'try_expire_at' => 0,
|
|
'rand_attr' => json_encode($rand_attr),
|
|
'wealth_attr' => json_encode($wealth_attr),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
myself()->_addTgLog("addSkin",array(
|
|
'item_id'=>$itemMeta['id'],
|
|
'item_num'=>1,
|
|
));
|
|
}
|
|
|
|
public static function getSkinWealth($row){
|
|
return self::celEconomyAttribute($row)["wealth"];
|
|
}
|
|
|
|
public static function getSkinLucky($row){
|
|
return self::celEconomyAttribute($row)["lucky"];
|
|
}
|
|
|
|
private static function celEconomyAttribute($row){
|
|
|
|
//最大财富值和幸运值计算
|
|
$wealth = 0;
|
|
$wealth_rate = 0;
|
|
$lucky = 0;
|
|
$lucky_rate = 0;
|
|
$heroAttrs = emptyReplace(json_decode($row['wealth_attr'], true), array());
|
|
$heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs);
|
|
$wealth += $heroResult['wealth'];
|
|
$wealth_rate += $heroResult['wealth_rate'];
|
|
$lucky += $heroResult['lucky'];
|
|
$lucky_rate += $heroResult['lucky_rate'];
|
|
return array(
|
|
"wealth" => floor($wealth * (1+$wealth_rate)),
|
|
"lucky" => floor($lucky * (1+$lucky_rate)),
|
|
);
|
|
}
|
|
}
|