我正在研究 Bungie API,想知道 Destiny Collectible 的 3 、 5 、 9 、 13 、 65 和 69 状态意味着什么?我无法在Official Bungie API Documentation Page上找到 3 、 5 、 9 、 13 、 65 和 69。它只有 0 、 1 、 2 、 4 、 8 、 16 、 32 和 64 作为状态枚举。
可能是我看错了地方。
URL:https://www.bungie.net/Platform/Destiny2/{membershiptype}/Profile/{destinyMembershipid}/?components=100,102,103,104,200,201,202,204,205,300,301,302,303,304,305,306,307,308,309,310,800,900,1100
我从这里得到的值:Response.profileCollectibles.data.collectibles
任何帮助是赞赏。
如文档中所述,返回的state
值是一个位掩码。位掩码本质上是一个数字,它使用数字的二进制表示形式充当布尔值。例如,二进制中的数字 5 是0101
,这意味着在这个数字表示的 4 个布尔值 (又名标志) 中,第二个和最后一个布尔值 / 标志是真的,第一个和第三个掩码仍然是假的。
要将上下文添加到此响应,以下是使用的值,它们的二进制表示形式及其定义(Bungie.NET API):
1 - 000 0001 - Not yet acquired/collected
2 - 000 0010 - Obscured (Use a different hash to display this collectible)
4 - 000 0100 - Invisible and should not be shown to the user
8 - 000 1000 - User cannot afford to recreate this collectible
16 - 001 0000 - User doesn't have the inventory space to create this collectible
32 - 010 0000 - The user already has this collectible, and cannot create a second one
64 - 100 0000 - Creating this collectible has been disabled (for whatever reason)
利用位掩码如何工作的知识,我们现在可以推导出在这个列表中找不到的状态的含义。为此,我们需要将我们的状态转换为二进制表示形式,并确定哪些“标志”是活动的。
所以对于状态 13,我们可以将其表示为000 1101
。
000 1101 - 13 is our returned state!
--------
000 0001 - The collectible hasn't be acquired yet
000 0100 - The collectible is invisible and should not be shown to the user
000 1000 - The collectible is too expensive for the user
您可以使用按位 AND操作(通常表示为单个&
)在应用程序中测试这些标志。
let state = 13; // 0b0001101 - Taken from the response JSON
let invisible = 4; // 0b0000100 - You'd probably have this as a global constant
if(state & invisible == invisible) hideThisItemFromPlayer();
就像我上面说的,你可能想要谷歌更多关于比特掩码深入了解他们,但这个运行下来应该给你一个想法。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(56条)