198 lines
5.9 KiB
PHP
198 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
require_once('mt/StrHelper.php');
|
|
require_once('mt/AttrHelper.php');
|
|
|
|
use phpcommon;
|
|
use mt;
|
|
|
|
class GunLevel {
|
|
|
|
private static $BASE_ATTR = [kHAT_Volume,kHAT_ReloadTime,kHAT_FireRate,kHAT_Atk,kHAT_BulletSpeed,kHAT_ShotRange,kHAT_Critical,kHAT_CriDamage];
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
public static function getByLevel( $level)
|
|
{
|
|
self::mustBeLevelHash();
|
|
return getXVal(self::$levelHash, $level, null);
|
|
}
|
|
|
|
public static function getByCoefficient($data,$index)
|
|
{
|
|
self::mustBeCoefficientHash($data);
|
|
return getXVal(self::$coefficientHash, $index, null);
|
|
}
|
|
|
|
public static function getCoefficientByLevel($level,$gun_id){
|
|
$meta = self::getByLevel($level);
|
|
return [
|
|
[
|
|
'attr_id'=>kHAT_Volume,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'clip_volume_rate')
|
|
], [
|
|
'attr_id'=>kHAT_ReloadTime,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'reload_time_rate')
|
|
], [
|
|
'attr_id'=>kHAT_FireRate,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'fire_rate_rate')
|
|
], [
|
|
'attr_id'=>kHAT_Atk,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'atk_rate')
|
|
], [
|
|
'attr_id'=>kHAT_BulletSpeed,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'bullet_speed_rate')
|
|
], [
|
|
'attr_id'=>kHAT_ShotRange,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'range')
|
|
], [
|
|
'attr_id'=>kHAT_Critical,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'crit_atk_rate')
|
|
], [
|
|
'attr_id'=>kHAT_CriDamage,
|
|
'val' => self::_getCoefficient($meta,$gun_id,'damage_rate')
|
|
],
|
|
];
|
|
}
|
|
|
|
private static function _getCoefficient($meta,$gun_id,$title){
|
|
if ($meta[$title.'2']){
|
|
$item = explode('|',$meta[$title.'2']);
|
|
foreach ($item as $val){
|
|
$item_1 = explode(':',$val);
|
|
if ($item_1[0] == $gun_id){
|
|
return $item_1[1];
|
|
}
|
|
}
|
|
return $meta[$title];
|
|
}
|
|
return $meta[$title];
|
|
}
|
|
|
|
public static function addRandAttrNew($gunDb,$type){
|
|
$itemMeta = Item::get($gunDb['gun_id']);
|
|
$gunMeta = Equip::get($itemMeta['relationship']);
|
|
$newAttrs = array();
|
|
if ($gunMeta) {
|
|
$meta = self::getByLevel($gunDb['gun_lv']+1);
|
|
foreach (self::$BASE_ATTR as $item){
|
|
if ($type == 1){
|
|
$val = self::getAttrValue($meta);
|
|
}else{
|
|
$val = self::getAttrValueMin($meta);
|
|
}
|
|
array_push(
|
|
$newAttrs,
|
|
[
|
|
'attr_id' => $item,
|
|
'val' => $val,
|
|
]);
|
|
}
|
|
}
|
|
$rand_attr = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
|
|
if (!$rand_attr){
|
|
foreach ($newAttrs as $item){
|
|
array_push(
|
|
$rand_attr,
|
|
[
|
|
'attr_id' => $item['attr_id'],
|
|
'val' => 1+$item['val'],
|
|
]);
|
|
}
|
|
}else{
|
|
foreach ($rand_attr as &$item){
|
|
foreach ($newAttrs as $v){
|
|
if ($item['attr_id'] == $v['attr_id']){
|
|
$item['val'] = $item['val']*(1+$v['val']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $rand_attr;
|
|
}
|
|
|
|
public static function addRandAttr($levelMeta, $baseAttrs, &$dbAttrs)
|
|
{
|
|
$nums = explode(':', $levelMeta['rand_attrs_num']);
|
|
$num = rand($nums[0], $nums[1]);
|
|
$cfgAttrs = StrHelper::parseList($levelMeta['rand_attrs'], array('|', ':'));
|
|
AttrHelper::addRandAttrs($cfgAttrs, $num, $baseAttrs, $dbAttrs);
|
|
return true;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static function mustBeLevelHash()
|
|
{
|
|
if (!self::$levelHash) {
|
|
self::$levelHash = array();
|
|
foreach (self::getMetaList() as $meta) {
|
|
self::$levelHash[$meta['level']] = $meta;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static function getAttrValue($meta)
|
|
{
|
|
$strs = explode('|', $meta['attr_weight']);
|
|
|
|
$totalSpace = 0;
|
|
foreach ($strs as $tmpStr) {
|
|
$strs2 = explode(':', $tmpStr);
|
|
if (count($strs2) == 2) {
|
|
$totalSpace += $strs2[1];
|
|
}
|
|
}
|
|
|
|
if ($totalSpace > 0) {
|
|
$randSpace = rand(0, $totalSpace);
|
|
$currSpace = 0;
|
|
foreach ($strs as $tmpStr) {
|
|
$strs2 = explode(':', $tmpStr);
|
|
if (count($strs2) == 2) {
|
|
$currSpace += $strs2[1];
|
|
}
|
|
if ($randSpace <= $currSpace) {
|
|
return $strs2[0];
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
protected static function getAttrValueMin($meta)
|
|
{
|
|
$strs = explode('|', $meta['attr_weight']);
|
|
foreach ($strs as $tmpStr) {
|
|
$strs2 = explode(':', $tmpStr);
|
|
return $strs2[0];
|
|
}
|
|
}
|
|
|
|
protected static function mustBeCoefficientHash($list)
|
|
{
|
|
if (!self::$coefficientHash) {
|
|
self::$coefficientHash = array();
|
|
foreach ($list as $val) {
|
|
self::$coefficientHash[$val['attr_id']] = $val;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static $metaList;
|
|
protected static $levelHash;
|
|
protected static $coefficientHash;
|
|
|
|
}
|