94 lines
1.9 KiB
PHP
94 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace metatable;
|
|
|
|
use phpcommon;
|
|
|
|
/*
|
|
配置表规范
|
|
getXXXConf:获取表所有数据
|
|
getXxxById():通过id获取单个数据
|
|
_internalGetXXXConf:获取表所有数据内部实现不对外开放
|
|
|
|
使用方式
|
|
require_once 'metatable/XXXX.php';
|
|
|
|
!!!注意必须使用require_once
|
|
*/
|
|
|
|
function getActPlusConf()
|
|
{
|
|
return _internalGetActPlusConf();
|
|
}
|
|
|
|
function getActPlusById($act_id)
|
|
{
|
|
$conf = getActPlusConf();
|
|
$act_id = (int)$act_id;
|
|
return array_key_exists($act_id, $conf) ? $conf[$act_id] : null;
|
|
}
|
|
|
|
function _internalGetActPlusConf()
|
|
{
|
|
global $g_act_table;
|
|
if (!$g_act_table) {
|
|
$g_act_table = require(getConfigBaseDir() . 'activityplus@activityplus.php');
|
|
}
|
|
return $g_act_table;
|
|
}
|
|
|
|
function getActPlusInfo($type)
|
|
{
|
|
$conf = getActPlusConf();
|
|
$info_list = array();
|
|
for ($i = 1; $i <= count($conf); $i++) {
|
|
$act = getActPlusById($i);
|
|
if ($act['type'] != $type) {
|
|
continue;
|
|
}
|
|
array_push($info_list, array(
|
|
'id' => $act['id'],
|
|
));
|
|
}
|
|
return $info_list;
|
|
}
|
|
|
|
|
|
class ActivityPlus
|
|
{
|
|
|
|
public static function get($id)
|
|
{
|
|
return self::getMeta()[$id];
|
|
}
|
|
|
|
public static function getCondIdx($actMeta, $cond)
|
|
{
|
|
$condConf = explode('|', $actMeta['condition']);
|
|
$idx = 0;
|
|
foreach ($condConf as $c) {
|
|
if ($c == $cond) {
|
|
return $idx;
|
|
}
|
|
++$idx;;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static function getReward($actMeta, $condIdx)
|
|
{
|
|
$rewardConf = explode('|', $actMeta['reward']);
|
|
return $rewardConf[$condIdx];
|
|
}
|
|
|
|
protected static function getMeta()
|
|
{
|
|
if (!self::$meta) {
|
|
self::$meta = getMetaTable('activityplus@activityplus.php');
|
|
}
|
|
return self::$meta;
|
|
}
|
|
|
|
private static $meta = null;
|
|
}
|