0

I have the following specification of bitmask values:

// 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

Here's an example usage of the bitmask:

SC_ENDURE, 21

The above means:

SC_ENDURE: cannot be removed by death and dispel and considered as buff. (16 + 4 + 1 = 21)

I have a CSV list (trimmed for example) to check, which looks like this:

SC_PROVOKE, 32
SC_ENDURE, 21
SC_HIDING, 4
SC_CLOAKING, 6
SC_TWOHANDQUICKEN, 24
SC_CONCENTRATION, 16
SC_ENCHANTPOISON, 16
SC_ORCISH, 2

What I want to do is go through the list select all effects that are considered as buff 16 into one list and the others into a separate list.

Using the example above; how do you check, if 16 exists in the sum of bit masks 21?

This is what I tried so far (with my lack of knowledge about bitmask) and not having any luck:

<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);

The code I tried is putting all effects into $buff_list, I am not sure if I am doing this right.

Latheesan
  • 23,247
  • 32
  • 107
  • 201

1 Answers1

1

Replace

(16 | $bitmask_value)

with

(16 & $bitmask_value)

Edit to help clarify:

(16 | $bitmask_value) = All of the flags in &bitmask_value as well as 16.
Example: (1 | 16) = 17, ((4 | 16) | 16) = (4 | 16) = 20

(16 & $bitmask_value) = All of the flags in the &bitmask_value also in 16.
Example: (1 & 16) = 0, ((4 | 16) & 16) = 16, ((1 | 2 | 4) & (2 | 4 | 8)) = (2 | 4) = 6

Doc
  • 281
  • 3
  • 5