浏览代码

Add NFT ratios to wallet

Kirk Trombley 3 年之前
父节点
当前提交
1c11b23be1
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      commands/commands/rollcoin.py

+ 10 - 4
commands/commands/rollcoin.py

@@ -53,9 +53,14 @@ class RollcoinWallet:
             s += f"Investments: {self.holdings}\n\t(cost basis {self.cost_basis})\n"
         if (num_nfts := len(self.nfts)) > 0:
             s += f"NFTs: {num_nfts}\n"
-        # writing out all of them produces a TON of spam
-        # for nft in self.nfts:
-        #     s += f"\t{nft}\n"
+        # writing out all of them produces a TON of spam, so just write ratios
+        if len(self.nfts) > 0:
+            counts = {
+                rarity: len([nft for nft in self.nfts if rarity in nft])
+                for rarity in [NFT_MAX_RARITY, *NFT_RARITY[1:]]
+            }
+            counts[NFT_RARITY[0]] = len(self.nfts) - sum(counts.values())
+            s += "\t" + "\n\t".join(f"{k}: {100 * v / len(self.nfts):.02f}%" for k, v in counts.items())
         return s.strip()
 
 
@@ -86,6 +91,7 @@ NFT_RARITY_LOOKUP = {
     NFT_ULTRA: 3,
 }
 NFT_RARITY = ["common", "uncommon", "rare!", "ultra rare!"]
+NFT_MAX_RARITY = "legendary!"
 
 # injection values
 State = Data(RollcoinState).For(Const(GLOBAL_STATE_KEY), treasury=0, mining_puzzle=None, market_state=0)
@@ -483,7 +489,7 @@ async def gacha(
         rarity += 1
     else:
         color_info = f"{color1} and {color2}"
-    rarity_info = "legendary!" if rarity >= len(NFT_RARITY) else NFT_RARITY[rarity]
+    rarity_info = NFT_MAX_RARITY if rarity >= len(NFT_RARITY) else NFT_RARITY[rarity]
 
     info = f"{name} ({color_info}) ({rarity_info})"