【发布时间】:2016-07-28 22:45:38
【问题描述】:
我有以下位掩码值规范:
// Structure of Database:
// SC_NAME, flag
//
// flag 1 - SC cannot be removed by death.
// 2 - SC cannot be saved.
// 4 - SC cannot be reset by dispell.
// 8 - SC cannot be reset by clearance.
// 16 - SC considered as buff and be removed by Hermode and etc.
// 32 - SC considered as debuff and be removed by Gospel and etc.
// 64 - SC cannot be reset when MADO Gear is taken off.
// 128 - SC cannot be reset by 'sc_end SC_ALL' and status change clear.
// 256 - SC can be visible for all players
以下是位掩码的示例用法:
SC_ENDURE,21
以上意思是:
SC_ENDURE: cannot be removed by death and dispel and considered as buff. (16 + 4 + 1 = 21)
我有一个 CSV 列表(例如经过修剪)要检查,如下所示:
SC_PROVOKE, 32
SC_ENDURE, 21
SC_HIDING, 4
SC_CLOAKING, 6
SC_TWOHANDQUICKEN, 24
SC_CONCENTRATION, 16
SC_ENCHANTPOISON, 16
SC_ORCISH, 2
我想要做的是通过列表选择所有被认为是 buff 16 的效果到一个列表中,其他的到一个单独的列表中。
使用上面的例子;你如何检查,如果16 存在于位掩码21 的总和中?
这是我迄今为止尝试过的(由于我对位掩码缺乏了解)并且没有任何运气:
<pre>
<?php
$buff_list = [];
$not_buffs = [];
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
list ($effect_code, $bitmask_value) = $data;
$effect_code = trim($effect_code);
$bitmask_value = (int)trim($bitmask_value);
if (16 | $bitmask_value) {
$buff_list[] = $effect_code;
} else {
$not_buffs[] = $effect_code;
}
}
fclose($handle);
}
print_r($buff_list);
echo "<hr>";
print_r($not_buffs);
我尝试的代码是将所有效果放入$buff_list,我不确定我这样做是否正确。
【问题讨论】: