1
This commit is contained in:
parent
9f53849c7d
commit
f242f30c86
@ -2,121 +2,159 @@
|
||||
|
||||
namespace models;
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Gun.php');
|
||||
require_once('mt/GunLevel.php');
|
||||
require_once('mt/GunQuality.php');
|
||||
require_once('models/GunSkin.php');
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class Gun extends BaseModel {
|
||||
|
||||
public static function find($itemId)
|
||||
const GETED_STATE = 0;
|
||||
const TRY_STATE = 1;
|
||||
|
||||
const NO_LOCK = 1;
|
||||
const LEVEL_LOCK = 1;
|
||||
const QUALITY_LOCK = 2;
|
||||
|
||||
public static function find($gunUniId)
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getSelfMysql(),
|
||||
't_gun',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'gun_id' => $itemId,
|
||||
'idx' => $gunUniId,
|
||||
)
|
||||
);
|
||||
if ($row) {
|
||||
$row['gun_uniid'] = $row['idx'];
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function getValidGun($gunId)
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getSelfMysql(),
|
||||
't_gun',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'gun_id' => $gunId,
|
||||
'state' => self::GETED_STATE,
|
||||
)
|
||||
);
|
||||
if ($row) {
|
||||
$row['gun_uniid'] = $row['idx'];
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function toDto($row)
|
||||
{
|
||||
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
|
||||
return 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(
|
||||
'gun_uniid' => $row['idx'],
|
||||
'gun_id' => $row['gun_id'],
|
||||
'state' => $row['state'],
|
||||
'gun_lv' => $row['gun_lv'],
|
||||
'gun_tili' => $row['gun_tili'],
|
||||
'state' => $row['state'],
|
||||
'quality' => $row['quality'],
|
||||
'attr' => $attr,
|
||||
'try_count' => $row['try_count'],
|
||||
'lock_type' => $lockType,
|
||||
'lock_time' => $lockTime,
|
||||
'trade_locktime' => $tradeLocktime,
|
||||
'attr' => $attr,
|
||||
);
|
||||
return $dto;
|
||||
}
|
||||
|
||||
public static function all()
|
||||
public static function addGun($gunMeta)
|
||||
{
|
||||
$itemList = array();
|
||||
SqlHelper::ormSelect(
|
||||
myself()->_getSelfMysql(),
|
||||
't_bag',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId()
|
||||
),
|
||||
function ($row) use(&$itemList) {
|
||||
if ($row['item_num'] > 0) {
|
||||
array_push($itemList, Bag::toDto($row));
|
||||
}
|
||||
}
|
||||
);
|
||||
return $itemList;
|
||||
}
|
||||
|
||||
public static function getItemCount($itemId)
|
||||
{
|
||||
$itemDb = self::find($itemId);
|
||||
return $itemDb ? $itemDb['item_num'] : 0;
|
||||
}
|
||||
|
||||
public static function addItem($itemId, $itemNum)
|
||||
{
|
||||
if (myself()->_isVirtualItem($itemId)) {
|
||||
return;
|
||||
}
|
||||
if ($itemNum <= 0) {
|
||||
return;
|
||||
}
|
||||
$itemMeta = mt\Item::get($itemId);
|
||||
if (!$itemMeta) {
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['cannot_stack']) {
|
||||
$realGunMeta = mt\Gun::get($gunMeta['id']);
|
||||
$randAttr = array();
|
||||
if (mt\Item::isRandAttrItem($itemMeta)) {
|
||||
$qualityMeta = mt\ChipQuality::getByQuality($itemMeta['quality']);
|
||||
if ($qualityMeta) {
|
||||
$randAttr = mt\ChipQuality::getRandAttr($qualityMeta);
|
||||
{
|
||||
$initQualityMeta = mt\GunQuality::getByQuality(1);
|
||||
if ($initQualityMeta) {
|
||||
$randAttr = mt\GunQuality::getRandAttr($initQualityMeta);
|
||||
}
|
||||
}
|
||||
SqlHelper::insert
|
||||
(myself()->_getSelfMysql(),
|
||||
't_bag',
|
||||
SqlHelper::insert(
|
||||
myself()->_getSelfMysql(),
|
||||
't_gun',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId,
|
||||
'item_num' => 1,
|
||||
'gun_id' => $gunMeta['id'],
|
||||
'gun_lv' => 1,
|
||||
'quality' => 1,
|
||||
'state' => self::GETED_STATE,
|
||||
'rand_attr' => json_encode($randAttr),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
SqlHelper::upsert
|
||||
(myself()->_getSelfMysql(),
|
||||
't_bag',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId
|
||||
),
|
||||
array(
|
||||
'item_num' => function () use($itemNum) { return "item_num + {$itemNum}";},
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
),
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId,
|
||||
'item_num' => $itemNum,
|
||||
'lock_type' => self::NO_LOCK,
|
||||
'unlock_time' => 0,
|
||||
'unlock_trade_time' => 0,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addTryGun($gunMeta, $tryCount)
|
||||
{
|
||||
$realGunMeta = mt\Gun::get($gunMeta['id']);
|
||||
$randAttr = array();
|
||||
{
|
||||
$initQualityMeta = mt\GunQuality::getByQuality(1);
|
||||
if ($initQualityMeta) {
|
||||
$randAttr = mt\GunQuality::getRandAttr($initQualityMeta);
|
||||
}
|
||||
}
|
||||
SqlHelper::upsert(
|
||||
myself()->_getSelfMysql(),
|
||||
't_gun',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'gun_id' => $gunMeta['id']
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'gun_id' => $gunMeta['id'],
|
||||
'gun_lv' => 1,
|
||||
'quality' => 1,
|
||||
'gun_tili' => $realGunMeta ? $realGunMeta['tili'] : 0,
|
||||
'state' => self::TRY_STATE,
|
||||
'try_count' => $tryCount,
|
||||
'rand_attr' => json_encode($randAttr),
|
||||
'lock_type' => self::NO_LOCK,
|
||||
'unlock_time' => 0,
|
||||
'unlock_trade_time' => 0,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function update($gunUniId, $fieldsKv)
|
||||
{
|
||||
SqlHelper::update
|
||||
(myself()->_getSelfMysql(),
|
||||
't_gun',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'idx' => $gunUniId,
|
||||
),
|
||||
$fieldsKv
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class Hero extends BaseModel {
|
||||
'try_count' => $tryCount,
|
||||
'skill_lv1' => 1,
|
||||
'skill_lv2' => 1,
|
||||
'rand_attr' => '[]',
|
||||
'rand_attr' => json_encode($randAttr),
|
||||
'lock_type' => self::NO_LOCK,
|
||||
'unlock_time' => 0,
|
||||
'unlock_trade_time' => 0,
|
||||
|
61
webapp/mt/GunLevel.php
Normal file
61
webapp/mt/GunLevel.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
require_once('mt/AttrHelper.php');
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class GunLevel {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return getXVal(self::getMetaList(), $id);
|
||||
}
|
||||
|
||||
public static function getByQualityLevel($quality, $level)
|
||||
{
|
||||
self::mustBeQualityLevelHash();
|
||||
return getXVal(self::$qualityLevelHash, $quality . '_' . $level, null);
|
||||
}
|
||||
|
||||
public static function addRandAttr($levelMeta, &$attrs)
|
||||
{
|
||||
$attrArr = StrHelper::parseList($levelMeta['rand_attrs'], array('|', ':'));
|
||||
foreach ($attrArr as $tuple) {
|
||||
$attrId = $tuple[0];
|
||||
$type = $tuple[1];
|
||||
$val = rand($tuple[2], $tuple[3]);
|
||||
foreach ($attrs as &$attr) {
|
||||
if ($attr['attr_id'] == $attrId &&
|
||||
$attr['type'] == $type) {
|
||||
$attr['val'] += $val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static function mustBeQualityLevelHash()
|
||||
{
|
||||
if (!self::$qualityLevelHash) {
|
||||
self::$qualityLevelHash = array();
|
||||
foreach (self::getMetaList() as $meta) {
|
||||
self::$qualityLevelHash[$meta['quality'] . '_' . $meta['level']] = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static $metaList;
|
||||
protected static $qualityLevelHash;
|
||||
|
||||
}
|
63
webapp/mt/GunQuality.php
Normal file
63
webapp/mt/GunQuality.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class GunQuality {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return getXVal(self::getMetaList(), $id);
|
||||
}
|
||||
|
||||
public static function getByQuality($quality)
|
||||
{
|
||||
self::mustBeQualityHash();
|
||||
return getXVal(self::$qualityHash, $quality, null);
|
||||
}
|
||||
|
||||
public static function getRandAttr($qualityMeta)
|
||||
{
|
||||
$nums = explode(':', $qualityMeta['rand_attrs_num']);
|
||||
$attrs = StrHelper::parseList($qualityMeta['rand_attrs'], array('|', ':'));
|
||||
$num = rand($nums[0], $nums[1]);
|
||||
shuffle($attrs);
|
||||
$result = array();
|
||||
$i = 0;
|
||||
foreach ($attrs as $item) {
|
||||
if ($i < $num) {
|
||||
array_push($result,
|
||||
array(
|
||||
'attr_id' => $item[0],
|
||||
'type' => $item[1],
|
||||
'val' => rand($item[2], $item[3])
|
||||
));
|
||||
}
|
||||
++$i;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('gunQuality@gunQuality.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static function mustBeQualityHash()
|
||||
{
|
||||
if (!self::$qualityHash) {
|
||||
self::$qualityHash = array();
|
||||
foreach (self::getMetaList() as $meta) {
|
||||
self::$qualityHash[$meta['quality']] = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static $metaList;
|
||||
protected static $qualityHash;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user