116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
|
|
|
|
namespace mt;
|
|
|
|
require_once('mt/AttributeList.php');
|
|
|
|
class EconomyAttribute
|
|
{
|
|
|
|
public static function getAttribute($index,$quality){
|
|
$meta = self::findByGrade($index,$quality);
|
|
$attribute = array();
|
|
if ($meta){
|
|
$attrs = explode("|",$meta['attribute']);
|
|
foreach ($attrs as $attr){
|
|
$temp = explode(":",$attr);
|
|
switch ($temp[0]){
|
|
case AttributeList::WEALTH_ABS : {
|
|
array_push($attribute,array(
|
|
"attr_id" => AttributeList::WEALTH_ABS,
|
|
"val" => rand($temp[1],$temp[2])
|
|
));
|
|
}
|
|
break;
|
|
case AttributeList::WEALTH_RATE : {
|
|
array_push($attribute,array(
|
|
"attr_id" => AttributeList::WEALTH_RATE,
|
|
"val" => rand($temp[1]*10000,$temp[2]*10000)/10000
|
|
));
|
|
}
|
|
break;
|
|
case AttributeList::LUCKY_ABS : {
|
|
array_push($attribute,array(
|
|
"attr_id" => AttributeList::LUCKY_ABS,
|
|
"val" => rand($temp[1],$temp[2])
|
|
));
|
|
}
|
|
break;
|
|
case AttributeList::LUCKY_RATE : {
|
|
array_push($attribute,array(
|
|
"attr_id" => AttributeList::LUCKY_RATE,
|
|
"val" => rand($temp[1]*10000,$temp[2]*10000)/10000
|
|
));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return $attribute;
|
|
}
|
|
|
|
public static function getAttrValue($attribute){
|
|
$wealth = 0;
|
|
$wealth_rate = 0;
|
|
$lucky = 0;
|
|
$lucky_rate = 0;
|
|
foreach ($attribute as $value){
|
|
switch ($value['attr_id']){
|
|
case AttributeList::WEALTH_ABS :{
|
|
$wealth += $value['val'];
|
|
}
|
|
break;
|
|
case AttributeList::WEALTH_RATE:{
|
|
$wealth_rate += $value['val'];
|
|
}
|
|
break;
|
|
case AttributeList::LUCKY_ABS :{
|
|
$lucky += $value['val'];
|
|
}
|
|
break;
|
|
case AttributeList::LUCKY_RATE:{
|
|
$lucky_rate += $value['val'];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
// $wealthVal = floor($wealth * (1+$wealth_rate));
|
|
// $luckyVal = floor($lucky * (1+$lucky_rate));
|
|
return array(
|
|
"wealth" => $wealth,
|
|
"wealth_rate" => $wealth_rate,
|
|
"lucky" => $lucky,
|
|
"lucky_rate" => $lucky_rate,
|
|
);
|
|
}
|
|
|
|
public static function findByGrade($index,$quality){
|
|
foreach (self::getMetaList() as $meta){
|
|
if ($meta['invoke'] == $index && $meta['grade'] == $quality){
|
|
return $meta;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getByIndex($index){
|
|
$metaList = array();
|
|
foreach (self::getMetaList() as $meta){
|
|
if ($meta['invoke'] == $index){
|
|
array_push($metaList,$meta);
|
|
}
|
|
}
|
|
return $metaList;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('economyAttribute@economyAttribute.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static $metaList;
|
|
} |