159 lines
4.8 KiB
PHP
159 lines
4.8 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];
|
|
|
|
public static function find($id,$level)
|
|
{
|
|
$meta = array();
|
|
foreach (self::getMetaList() as $value){
|
|
if ($value['gun_id'] == $id && $value['level'] == $level){
|
|
$meta = $value;
|
|
}
|
|
}
|
|
return $meta;
|
|
}
|
|
|
|
public static function addRandAttr($meta,$type){
|
|
$attr = array();
|
|
if ($meta){
|
|
if ($type == 1) {
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_Atk,
|
|
'val' => self::getRandValue($meta,'attr_weight')
|
|
));
|
|
if ($meta['clip_volume']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_Volume,
|
|
'val' => self::getRandValue($meta,'clip_volume')
|
|
));
|
|
}
|
|
if ($meta['reload_time']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_ReloadTime,
|
|
'val' => self::getRandValue($meta,'reload_time')
|
|
));
|
|
}
|
|
if ($meta['fire_rate']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_FireRate,
|
|
'val' => self::getRandValue($meta,'fire_rate')
|
|
));
|
|
}
|
|
if ($meta['bullet_speed']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_BulletSpeed,
|
|
'val' => self::getRandValue($meta,'bullet_speed')
|
|
));
|
|
}
|
|
if ($meta['range']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_ShotRange,
|
|
'val' => self::getRandValue($meta,'range')
|
|
));
|
|
}
|
|
|
|
}else{
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_Atk,
|
|
'val' => self::getRandValueMin($meta,'attr_weight')
|
|
));
|
|
if ($meta['clip_volume']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_Volume,
|
|
'val' => self::getRandValueMin($meta,'clip_volume')
|
|
));
|
|
}
|
|
if ($meta['reload_time']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_ReloadTime,
|
|
'val' => self::getRandValueMin($meta,'reload_time')
|
|
));
|
|
}
|
|
if ($meta['fire_rate']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_FireRate,
|
|
'val' => self::getRandValueMin($meta,'fire_rate')
|
|
));
|
|
}
|
|
if ($meta['bullet_speed']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_BulletSpeed,
|
|
'val' => self::getRandValueMin($meta,'bullet_speed')
|
|
));
|
|
}
|
|
if ($meta['range']){
|
|
array_push($attr,array(
|
|
'attr_id' => kHAT_ShotRange,
|
|
'val' => self::getRandValueMin($meta,'range')
|
|
));
|
|
}
|
|
}
|
|
|
|
}
|
|
return $attr;
|
|
}
|
|
|
|
protected static function getRandValue($meta,$key)
|
|
{
|
|
$strs = explode('|', $meta[$key]);
|
|
|
|
$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 getRandValueMin($meta,$key)
|
|
{
|
|
$strs = explode('|', $meta[$key]);
|
|
foreach ($strs as $tmpStr) {
|
|
$strs2 = explode(':', $tmpStr);
|
|
return $strs2[0];
|
|
}
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static $metaList;
|
|
}
|