379 lines
9.7 KiB
PHP
379 lines
9.7 KiB
PHP
<?php
|
||
|
||
namespace mt;
|
||
|
||
require_once('mt/StrHelper.php');
|
||
require_once('mt/AttrHelper.php');
|
||
|
||
use phpcommon;
|
||
|
||
class Item {
|
||
|
||
/*
|
||
0 无功能
|
||
1 不进背包道具(数值道具)
|
||
2 礼包
|
||
3 英雄
|
||
4 英雄皮肤
|
||
5 头像
|
||
6 头像框
|
||
7 枪械
|
||
8 枪械皮肤
|
||
9 功能性道具
|
||
10 材料
|
||
11 碎片
|
||
12 盲盒
|
||
13 芯片
|
||
15 碎片透明箱子
|
||
16 降落伞皮肤
|
||
19 赛季戒指
|
||
23 随机宝箱
|
||
24 Gacha
|
||
26 晶体
|
||
29 外饰装扮
|
||
30 活动宝箱
|
||
31 金砖
|
||
*/
|
||
|
||
/*
|
||
type类型为1时,配置一下子类id
|
||
1.金币
|
||
2.钻石
|
||
3.角色账号经验
|
||
4.日活跃
|
||
5.周活跃
|
||
6.工会经验
|
||
7.手册经验
|
||
8.英雄熟练度
|
||
|
||
type类型为2时,配置一下子类id
|
||
1.自动打开
|
||
2.手动打开
|
||
|
||
type类型为7时,配置一下子类id
|
||
1.冲锋枪
|
||
2.散弹枪
|
||
3.狙击枪
|
||
4.火箭筒
|
||
5.激光枪
|
||
6.冰冻枪
|
||
7.火焰枪
|
||
|
||
type类型为9时,配置一下子类id
|
||
1.改名卡
|
||
2.喇叭
|
||
3.战队改名卡
|
||
4.体力药剂
|
||
5.耐久药剂
|
||
6.赏金门票
|
||
7.英雄升阶道具
|
||
8.幸运符
|
||
9.战斗内药剂
|
||
|
||
type类型为10时,配置一下子类id
|
||
1.角色材料
|
||
2.科研材料
|
||
|
||
type类型为11时,配置一下子类id
|
||
1.角色碎片
|
||
2.枪械碎片
|
||
|
||
type类型为13时,配置一下子类id
|
||
1.角色芯片
|
||
2.枪械芯片
|
||
|
||
type类型为15时,配置一下子类id
|
||
1.角色碎片
|
||
2.枪械碎片
|
||
*/
|
||
const NONE_TYPE = 0;
|
||
const VIRTUAL_TYPE = 1;
|
||
const GIFT_PACKAGE_TYPE = 2;
|
||
const HERO_TYPE = 3;
|
||
const HERO_SKIN_TYPE = 4;
|
||
const HEAD_TYPE = 5;
|
||
const HEAD_FRAME_TYPE = 6;
|
||
const GUN_TYPE = 7;
|
||
const GUN_SKIN_TYPE = 8;
|
||
const FUNC_TYPE = 9;
|
||
const MATERIAL_TYPE = 10;
|
||
const FRAGMENT_TYPE = 11;
|
||
const BLIND_BOX_TYPE = 12;
|
||
const CHIP_TYPE = 13;
|
||
const FRAGMENT_BOX_TYPE = 15;
|
||
const PARACHUTE_TYPE = 16;
|
||
const CHIP_BOX_TYPE = 17;
|
||
const RING_TYPE = 19;
|
||
const EMOJI_TYPE = 20;
|
||
const RANDOM_BOX_TYPE = 21;
|
||
const HONOR_TYPE = 24;
|
||
const CRYSTAL_TYPE = 26;
|
||
|
||
const CHEST_BOX_TYPE = 23;
|
||
const PLANET_TYPE = 28;
|
||
const AVATAR_TYPE = 29;
|
||
const TREASURE_BOX = 30;
|
||
const GOLD_SYN = 31;
|
||
const BATTLE_REWARD_BOX = 32;
|
||
const TIMING_PROP_TYPE = 33;
|
||
const APPOINT_PROP_TYPE = 40;
|
||
|
||
const FUNC_RENAME_CARD_SUBTYPE = 1;
|
||
const FUNC_GUILD_CARD_SUBTYPE = 3;
|
||
const RECOVER_DRUG_SUBTYPE = 4;
|
||
const PACKAGING_SUBTYPE = 5;
|
||
|
||
const ROLE_CHIP_SUBTYPE = 1;
|
||
const GUN_CHIP_SUBTYPE = 2;
|
||
const MATERIAL_CHIP_SUBTYPE = 3;
|
||
|
||
const HERO_FRAGMENT_SUBTYPE = 1;
|
||
const CHIP_FRAGMENT_SUBTYPE = 2;
|
||
const SKIN_FRAGMENT_SUBTYPE = 4;
|
||
|
||
|
||
const APPOINT_HERO_SUBTYPE = 1;
|
||
const APPOINT_CHIP_SUBTYPE = 2;
|
||
const APPOINT_SKIN_SUBTYPE = 3;
|
||
|
||
const LUCKY_SYMBOL_SUBTYPE = 8;
|
||
const BATTLE_POTION_SUBTYPE = 9;
|
||
|
||
const LUCKY_SYMBOL_ITEM_ID = 900007;
|
||
|
||
public static function get($id)
|
||
{
|
||
return getXVal(self::getMetaList(), $id, null);
|
||
}
|
||
|
||
public static function isType($meta, $type)
|
||
{
|
||
return $meta['type'] == $type;
|
||
}
|
||
|
||
public static function inTypes($meta, $types)
|
||
{
|
||
return in_array($meta['type'], $types);
|
||
}
|
||
|
||
public static function filter($cb)
|
||
{
|
||
foreach (self::getMetaList() as $meta) {
|
||
if (!$cb($meta)) {
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
public static function getPriceInfo($meta)
|
||
{
|
||
$info = array(
|
||
'item_id' => $meta['id'],
|
||
'price_info' => array(
|
||
'cost_list' => array(),
|
||
'discount_begin_time' => phpcommon\datetimeToTimestamp($meta['discount_begin']),
|
||
'discount_end_time' => phpcommon\datetimeToTimestamp($meta['discount_end'])
|
||
)
|
||
);
|
||
$discount = splitStr1($meta['discount']);
|
||
if ($meta['gold'] > 0) {
|
||
array_push($info['price_info']['cost_list'],
|
||
array(
|
||
array(
|
||
'item_id' => V_ITEM_GOLD,
|
||
'item_num' => $meta['gold'],
|
||
'discount' => count($discount) > 0 ? (int)$discount[0] : 0
|
||
)));
|
||
}
|
||
if ($meta['diamond'] > 0) {
|
||
array_push($info['price_info']['cost_list'],
|
||
array(
|
||
array(
|
||
'item_id' => V_ITEM_DIAMOND,
|
||
'item_num' => $meta['diamond'],
|
||
'discount' => count($discount) > 1 ? (int)$discount[1] : 0
|
||
)
|
||
));
|
||
}
|
||
return $info;
|
||
}
|
||
|
||
public static function getCostItems($priceInfo, $costItemId)
|
||
{
|
||
$costGroup = null;
|
||
array_walk($priceInfo['cost_list'], function ($val) use(&$costGroup, $costItemId) {
|
||
if ($costGroup) {
|
||
return;
|
||
}
|
||
if (count($val) > 0 && $val[0]['item_id'] == $costItemId) {
|
||
$costGroup = $val;
|
||
return;
|
||
}
|
||
});
|
||
if (!$costGroup) {
|
||
return null;
|
||
}
|
||
$costItems = array();
|
||
array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) {
|
||
if ($val['discount'] > 0 &&
|
||
myself()->_getNowTime() >= $priceInfo['discount_begin_time'] &&
|
||
myself()->_getNowTime() <= $priceInfo['discount_end_time']
|
||
) {
|
||
array_push($costItems, array(
|
||
'item_id' => $val['item_id'],
|
||
'item_num' => (int)($val['item_num'] * ($priceInfo['discount'] / 100)),
|
||
));
|
||
} else {
|
||
array_push($costItems, array(
|
||
'item_id' => $val['item_id'],
|
||
'item_num' => $val['item_num'],
|
||
));
|
||
}
|
||
});
|
||
return $costItems;
|
||
}
|
||
|
||
public static function getUseCostItems($itemMeta)
|
||
{
|
||
$costItems = array();
|
||
foreach (splitStr2($itemMeta['use_cost']) as $arr) {
|
||
if (count($arr) >= 2) {
|
||
array_push($costItems, array(
|
||
'item_id' => $arr[0],
|
||
'item_num' => $arr[1]
|
||
));
|
||
}
|
||
}
|
||
return $costItems;
|
||
}
|
||
|
||
public static function isRandAttrItem($itemMeta)
|
||
{
|
||
return $itemMeta['type'] == self::MATERIAL_TYPE &&
|
||
$itemMeta['sub_type'] == self::MATERIAL_CHIP_SUBTYPE;
|
||
}
|
||
|
||
public static function isRoleChipItem($itemMeta)
|
||
{
|
||
return $itemMeta['type'] == self::CHIP_TYPE &&
|
||
$itemMeta['sub_type'] == self::ROLE_CHIP_SUBTYPE;
|
||
}
|
||
|
||
public static function isGunChipItem($itemMeta)
|
||
{
|
||
return $itemMeta['type'] == self::CHIP_TYPE &&
|
||
$itemMeta['sub_type'] == self::GUN_CHIP_SUBTYPE;
|
||
}
|
||
|
||
public static function getBaseAttrs($meta)
|
||
{
|
||
$cfgAttrs = StrHelper::parseList($meta['attrs'], array('|', ':'));
|
||
$attrs = array();
|
||
foreach ($cfgAttrs as $cfgAttr) {
|
||
array_push($attrs, array(
|
||
'attr_id' => $cfgAttr[0],
|
||
'type' => $cfgAttr[1],
|
||
'val' => $cfgAttr[2],
|
||
));
|
||
}
|
||
return $attrs;
|
||
}
|
||
|
||
public static function isBagItem($type, $subType)
|
||
{
|
||
return in_array($type, array(
|
||
self::GIFT_PACKAGE_TYPE,
|
||
self::FUNC_TYPE,
|
||
self::MATERIAL_TYPE,
|
||
self::FRAGMENT_TYPE,
|
||
14,
|
||
self::FRAGMENT_BOX_TYPE,
|
||
self::CHEST_BOX_TYPE,
|
||
self::CRYSTAL_TYPE,
|
||
self::TREASURE_BOX,
|
||
self::BATTLE_REWARD_BOX,
|
||
));
|
||
}
|
||
|
||
public static function getMetaListByType($type)
|
||
{
|
||
$metaList = array();
|
||
foreach (self::getMetaList() as $meta){
|
||
if ($meta['type'] == $type){
|
||
array_push($metaList,$meta);
|
||
}
|
||
}
|
||
return $metaList;
|
||
}
|
||
|
||
public static function isFragment($itemMeta)
|
||
{
|
||
return $itemMeta['type'] == self::FRAGMENT_TYPE;
|
||
}
|
||
|
||
public static function groupFragment($tokenIds, &$heros, &$guns, &$specHeros, &$specGuns)
|
||
{
|
||
$heroItemIds = array(
|
||
110110,
|
||
110120,
|
||
110130,
|
||
110140,
|
||
110150,
|
||
110160,
|
||
110170,
|
||
110180
|
||
);
|
||
$gunItemIds = array(
|
||
110210,
|
||
110220,
|
||
110230,
|
||
110240,
|
||
110250,
|
||
110260,
|
||
110270,
|
||
110280
|
||
);
|
||
foreach ($tokenIds as $tokenId) {
|
||
if (in_array($tokenId, $heroItemIds)) {
|
||
array_push($heros, $tokenId);
|
||
}
|
||
if (in_array($tokenId, $gunItemIds)) {
|
||
array_push($guns, $tokenId);
|
||
}
|
||
switch ($tokenId) {
|
||
case 110100:
|
||
{
|
||
array_push($specHeros, $tokenId);
|
||
}
|
||
break;
|
||
case 110200:
|
||
{
|
||
array_push($specGuns, $tokenId);
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
}
|
||
}
|
||
}
|
||
$heros = array_unique($heros);
|
||
$guns = array_unique($guns);
|
||
}
|
||
|
||
public static function getLuckySymbolMeta()
|
||
{
|
||
return self::get(self::LUCKY_SYMBOL_ITEM_ID);
|
||
}
|
||
|
||
protected static function getMetaList()
|
||
{
|
||
if (!self::$metaList) {
|
||
self::$metaList = getMetaTable('item@item.php');
|
||
}
|
||
return self::$metaList;
|
||
}
|
||
|
||
protected static $metaList;
|
||
|
||
}
|