牌库读取的修复
问题
这个问题已经出现很久了,在缓存了卡组的情况下,牌库的读取总是只能读到自带的卡牌在牌库中的情况,所有衍生卡、后洗入的卡都无法读取,由于灵魂残片必须要借助牌库才能完美写好,所以今天把它修复了。
定位问题
首先在 silverfish_HB.cs 中添加输出代码,检查牌库的更新情况。
Helpfunctions.Instance.ErrorLog("——————tmpDeck——————");
foreach (var item in tmpDeck)
{
Helpfunctions.Instance.ErrorLog(item.Key + "\t\t" + item.Value);
}
Helpfunctions.Instance.ErrorLog("——————extraDeck——————");
foreach (var item in extraDeck)
{
Helpfunctions.Instance.ErrorLog(item.Key + "\t\t" + item.Value);
}
Helpfunctions.Instance.ErrorLog("——————turnDeck——————");
foreach (var item in turnDeck)
{
Helpfunctions.Instance.ErrorLog(item.Key + "\t\t" + item.Value);
}
结果发现 extraDeck
总是空的。
定位到 extraDeck
的更新处,以下摘抄和牌库相关的部分:
// HREngine.Bots.Silverfish.getDecks
Dictionary<string, int> tmpDeck = new Dictionary<string, int>(startDeck);
//...
turnDeck.Clear();
List<HSCard> allcards = TritonHs.GetAllCards();
int allcardscount = allcards.Count;
for (int i = 0; i < allcardscount; i++)
{
HSCard entity = allcards[i];
if (entity.Id == null || entity.Id == "") continue;
//...
string entityId = entity.Id;
Triton.Game.Mapping.TAG_ZONE entZone = entity.GetZone();
if (i < 60)
{
if (entityId != "")
{
if (entZone == Triton.Game.Mapping.TAG_ZONE.DECK) continue;
if (tmpDeck.ContainsKey(entityId)) tmpDeck[entityId]--;
}
}
else if (i >= 60 && entity.ControllerId == owncontroler)
{
if (extraDeck.ContainsKey(i))
{
if (entityId != "" && entityId != extraDeck[i].id) extraDeck[i].setId(entityId);
if ((entZone == Triton.Game.Mapping.TAG_ZONE.DECK) != extraDeck[i].isindeck) extraDeck[i].setisindeck(entZone == Triton.Game.Mapping.TAG_ZONE.DECK);
}
else if (entZone == Triton.Game.Mapping.TAG_ZONE.DECK)
{
extraDeck.Add(i, new extraCard(entityId, true));
}
}
}
可以注意到,对于把 allcards
写入 tmpDeck
和 extraDeck
时,分成了 2 部分,分别是 i < 60 和 i >= 60。
其中,i < 60 更新的为牌库中的自带卡牌,是在原来自带卡牌(tmpDeck
)的基础上寻找到已经不在牌库中的牌然后一一剔除,通过刚才的输出知道,这部分是正常的。
i >= 60 部分根据名字来看,就是牌库中额外的部分,但是这部分却不起作用了。所以我猜测是 allcards
无法读取衍生牌。
于是准备通过炉石兄弟的开发模式来查看一下 allcards
的情况。
开发模式代码如下:
using Triton.Game;
using Triton.Game.Mapping;
using log4net;
using Logger = Triton.Common.LogUtilities.Logger;
public class RuntimeCode
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
public void Execute()
{
using (TritonHs.AcquireFrame())
{
var allcards = TritonHs.GetAllCards();
foreach (var item in allcards)
Log.DebugFormat(item.Card.GetEntity().ToString());
}
}
}
在开局打出一张精魂狱卒的情况下,读取到的 allcards
情况如下:
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=4 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=5 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=6 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=7 zone=DECK zonePos=0 cardId= player=1]
[entityName=精魂狱卒 id=8 zone=PLAY zonePos=1 cardId=SCH_700 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=9 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=10 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=11 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=12 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=13 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=14 zone=DECK zonePos=0 cardId= player=1]
[entityName=魔法幻象 id=15 zone=DECK zonePos=0 cardId= player=1]
[entityName=精魂狱卒 id=16 zone=HAND zonePos=2 cardId=SCH_700 player=1]
[entityName=伊莉斯·逐星 id=17 zone=HAND zonePos=3 cardId=LOE_079 player=1]
[entityName=铸魂宝石匠 id=18 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=19 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=20 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=21 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=22 zone=DECK zonePos=0 cardId= player=1]
[entityName=可靠的灯泡 id=23 zone=HAND zonePos=1 cardId=BOT_079 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=24 zone=DECK zonePos=0 cardId= player=1]
[entityName=远古暗影 id=25 zone=HAND zonePos=5 cardId=LOE_110 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=26 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=27 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=28 zone=DECK zonePos=0 cardId= player=1]
[entityName=冰川裂片 id=29 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=30 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=31 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=32 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=33 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=34 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=35 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=36 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=37 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=38 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=39 zone=HAND zonePos=3 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=40 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=41 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=42 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=43 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=44 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=45 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=46 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=47 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=48 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=49 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=50 zone=HAND zonePos=2 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=51 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=52 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=53 zone=HAND zonePos=4 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=54 zone=HAND zonePos=1 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=55 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=56 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=57 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=58 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=59 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=60 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=61 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=62 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=63 zone=DECK zonePos=0 cardId= player=2]
[entityName=恶魔形态伊利丹 id=64 zone=PLAY zonePos=0 cardId=HERO_10a player=1]
[entityName=恶魔之爪 id=65 zone=PLAY zonePos=0 cardId=HERO_10bp player=1]
[entityName=玛法里奥·怒风 id=66 zone=PLAY zonePos=0 cardId=HERO_06 player=2]
[entityName=变形 id=67 zone=PLAY zonePos=0 cardId=HERO_06bp player=2]
[entityName=幸运币 id=68 zone=HAND zonePos=4 cardId=GAME_005 player=1]
简单分析一下,在 id=4 到 id=33 之间为 player=1,id=34 到 id=63 之间为 player=2。显然,都是 30 张牌,必然是双方开局自带的卡牌了。从 id=64 到 id=68 之间,则是两个英雄与两个英雄技能,还有一张最后的幸运币。
看到这里有两个疑惑:
- id=4 之前的内容呢
- 牌库中的灵魂残片呢
显然,这个 allcards
并不是真正的 “allcards”。追踪下主程序内 allcards
的来源。
//Triton.Game.TritonHs
public static List<HSCard> GetAllCards() =>
((List<HSCard>)(perFrameCachedValue_1 ?? (perFrameCachedValue_1 = new PerFrameCachedValue<List<HSCard>>(Class246.abc__77_0 ?? (Class246.abc__77_0 = new Func<List<HSCard>>(Class246.abc.method_5))))));
//Triton.Game.TritonHs.Class246
internal List<HSCard> method_5()
{
List<HSCard> list = new List<HSCard>();
Triton.Game.Mapping.Entity entity = null;
int id = 4;
while (true)
{
entity = TritonHs.GameState.GetEntity(id);
id++;
if (entity != null)
{
list.Add(new HSCard(entity));
}
if (entity == null)
{
return list;
}
}
}
可以看到,它是从 4 开始的,然后一旦遇到 null 就停下。
于是我仿照这个写一段输出从 0 开始的,遇到 null 也不停下,一直到寻找到 id=99 的 entity 的开发模式代码:
using Triton.Game;
using Triton.Game.Mapping;
using log4net;
using Logger = Triton.Common.LogUtilities.Logger;
public class RuntimeCode
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
public void Execute()
{
using(TritonHs.AcquireFrame())
{
for (int i = 0; i < 100; i++)
if (GameState.Get().GetEntity(i)!=null)
Log.DebugFormat(GameState.Get().GetEntity(i).ToString());
}
}
}
这次,读取到的结果如下:
GameEntity
沼泽
旅店老板
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=4 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=5 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=6 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=7 zone=DECK zonePos=0 cardId= player=1]
[entityName=精魂狱卒 id=8 zone=PLAY zonePos=1 cardId=SCH_700 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=9 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=10 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=11 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=12 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=13 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=14 zone=DECK zonePos=0 cardId= player=1]
[entityName=魔法幻象 id=15 zone=DECK zonePos=0 cardId= player=1]
[entityName=精魂狱卒 id=16 zone=HAND zonePos=2 cardId=SCH_700 player=1]
[entityName=伊莉斯·逐星 id=17 zone=HAND zonePos=3 cardId=LOE_079 player=1]
[entityName=铸魂宝石匠 id=18 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=19 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=20 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=21 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=22 zone=DECK zonePos=0 cardId= player=1]
[entityName=可靠的灯泡 id=23 zone=HAND zonePos=1 cardId=BOT_079 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=24 zone=DECK zonePos=0 cardId= player=1]
[entityName=远古暗影 id=25 zone=HAND zonePos=5 cardId=LOE_110 player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=26 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=27 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=28 zone=DECK zonePos=0 cardId= player=1]
[entityName=冰川裂片 id=29 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=30 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=31 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=32 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=33 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=34 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=35 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=36 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=37 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=38 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=39 zone=HAND zonePos=3 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=40 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=41 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=42 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=43 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=44 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=45 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=46 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=47 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=48 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=49 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=50 zone=HAND zonePos=2 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=51 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=52 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=53 zone=HAND zonePos=4 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=54 zone=HAND zonePos=1 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=55 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=56 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=57 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=58 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=59 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=60 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=61 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=62 zone=DECK zonePos=0 cardId= player=2]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=63 zone=DECK zonePos=0 cardId= player=2]
[entityName=恶魔形态伊利丹 id=64 zone=PLAY zonePos=0 cardId=HERO_10a player=1]
[entityName=恶魔之爪 id=65 zone=PLAY zonePos=0 cardId=HERO_10bp player=1]
[entityName=玛法里奥·怒风 id=66 zone=PLAY zonePos=0 cardId=HERO_06 player=2]
[entityName=变形 id=67 zone=PLAY zonePos=0 cardId=HERO_06bp player=2]
[entityName=幸运币 id=68 zone=HAND zonePos=4 cardId=GAME_005 player=1]
[entityName=灵魂残片 id=78 zone=DECK zonePos=0 cardId= player=1]
[entityName=灵魂残片 id=79 zone=DECK zonePos=0 cardId= player=1]
和之前输出的 allcards
相比,前面多了 3 项,分别是 GameEntity
和两个玩家的名字。实际上是游戏实体和玩家实体(通过后续测试,GameEntity
的 id 为 1,两个玩家分别为 2 和 3)。具体见灰机wiki的描述:实体
重要的部分是后面,在最后终于输出了两个灵魂残片。但是发现这里的 id 已经是 78 和 79 了,并不是紧接着幸运币的 68,所以才会导致 allcards
读取不到后续的衍生牌了。
解决思路
在调试的过程中,发现了一个方法: GameState.Get().GetFriendlySidePlayer().GetDeckZone().GetCards()
看起来是和牌库相关的。这个方法会返回一个 List<Card>
类型。写了一段开发模式代码来看一下会返回什么结果。
using Triton.Game;
using Triton.Game.Mapping;
using log4net;
using Logger = Triton.Common.LogUtilities.Logger;
public class RuntimeCode
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
public void Execute()
{
using (TritonHs.AcquireFrame())
{
var cards = GameState.Get().GetFriendlySidePlayer().GetDeckZone().GetCards();
foreach (var item in cards)
{
Log.DebugFormat(item.GetEntity().ToString());
}
}
}
}
由于刚刚那局掉了线,所以重新开了一局。输出结果如下:
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=4 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=5 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=6 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=7 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=8 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=9 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=10 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=11 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=12 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=13 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=14 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=15 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=19 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=20 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=21 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=24 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=25 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=26 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=27 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=28 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=29 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=32 zone=DECK zonePos=0 cardId= player=1]
[entityName=UNKNOWN ENTITY [cardType=INVALID] id=33 zone=DECK zonePos=0 cardId= player=1]
[entityName=厄运鼹鼠 id=31 zone=DECK zonePos=0 cardId= player=1]
[entityName=冰川裂片 id=18 zone=DECK zonePos=0 cardId= player=1]
[entityName=灵魂残片 id=80 zone=DECK zonePos=0 cardId= player=1]
[entityName=灵魂残片 id=81 zone=DECK zonePos=0 cardId= player=1]
其中,厄运鼹鼠和冰川裂片是我在开局留牌时候换掉的卡牌。可以看到,这个方法看起来能读取出整个牌库,也能读取到衍生牌,但是只能读到自己看到过的,并不能读取到自己带的但是还没抽到过的牌。
所以到了现在,所有的牌都能掌握了。缺的就是把他们放在一起构成一个完整的牌库。所以思路就是在原来能正确读取自带卡牌在牌库中情况的基础上,添加上衍生牌的识别。但是,由于 GameState.Get().GetFriendlySidePlayer().GetDeckZone().GetCards()
能够读取到的并且能够识别的不仅有衍生卡,还有见过的自带的卡牌,所以为了只取到衍生卡,我想到了一开始调试 alcards
部分时的代码,即双方玩家的自带卡牌所占的 id 都是在 64 之前,所以在这个方法中,就可以以 64 为分界线来挑选出衍生卡了。
具体解决
解决很简单,只要在把 tmpDeck
导入 turnDeck
的代码后添加这样一段代码,挑选出我方牌库中 id 大于 64 的可识别的部分(即衍生卡)加入到 turnDeck
中,用于后续使用。
foreach (var item in GameState.Get().GetFriendlySidePlayer().GetDeckZone().GetCards())
{
var entity = item.GetEntity();
int entityId = entity.GetEntityId();
if (entityId < 64) continue;
var entityDef = entity.GetEntityDef();
if (entityDef.GetCardId() == null) continue;
string idEnum_str = entityDef.GetCardId();
CardDB.cardIDEnum idEnum = CardDB.Instance.cardIdstringToEnum(idEnum_str);
if (idEnum == CardDB.cardIDEnum.None) continue;
if (turnDeck.ContainsKey(idEnum)) turnDeck[idEnum]++;
else turnDeck.Add(idEnum, 1);
}
最后就是删除 extraDeck
、extraCard
等已经不起作用的相关内容。此处不再赘述。
附带结果: