Commit 09b9678c authored by mercury233's avatar mercury233

update 4 ways to run WindBot

parent ad74a5cc
...@@ -130,27 +130,27 @@ namespace MycardBot.Game.AI.Decks ...@@ -130,27 +130,27 @@ namespace MycardBot.Game.AI.Decks
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable)
{ {
//Logger.WriteLine("OnSelectCard."); Logger.DebugWriteLine("OnSelectCard.");
if (max==2) if (max==2)
{ {
//Logger.WriteLine("龙觉醒检索."); Logger.DebugWriteLine("龙觉醒检索.");
IList<ClientCard> result = new List<ClientCard>(); IList<ClientCard> result = new List<ClientCard>();
if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙)) if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙))
{ {
//Logger.WriteLine("手里没有本体,拿一张."); Logger.DebugWriteLine("手里没有本体,拿一张.");
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
if (card.Id == (int)CardId.青眼白龙) if (card.Id == (int)CardId.青眼白龙)
{ {
result.Add(card); result.Add(card);
//Logger.WriteLine("拿到了."); Logger.DebugWriteLine("拿到了.");
break; break;
} }
} }
} }
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
//Logger.WriteLine("拿亚白龙."); Logger.DebugWriteLine("拿亚白龙.");
if (card.Id == (int)CardId.青眼亚白龙) if (card.Id == (int)CardId.青眼亚白龙)
{ {
result.Add(card); result.Add(card);
...@@ -160,7 +160,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -160,7 +160,7 @@ namespace MycardBot.Game.AI.Decks
{ {
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
//Logger.WriteLine("亚白龙不够了."); Logger.DebugWriteLine("亚白龙不够了.");
if (!result.Contains(card)) if (!result.Contains(card))
result.Add(card); result.Add(card);
if (result.Count >= min) if (result.Count >= min)
...@@ -169,23 +169,23 @@ namespace MycardBot.Game.AI.Decks ...@@ -169,23 +169,23 @@ namespace MycardBot.Game.AI.Decks
} }
while (result.Count > max) while (result.Count > max)
{ {
//Logger.WriteLine("拿多了."); Logger.DebugWriteLine("拿多了.");
result.RemoveAt(result.Count - 1); result.RemoveAt(result.Count - 1);
} }
return result; return result;
} }
//Logger.WriteLine("Use default."); Logger.DebugWriteLine("Use default.");
return null; return null;
} }
public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max) public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max)
{ {
Logger.WriteLine(cards.Count + " sync " + sum); Logger.DebugWriteLine(cards.Count + " sync " + sum);
IList<ClientCard> selected = new List<ClientCard>(); IList<ClientCard> selected = new List<ClientCard>();
int trysum = 0; int trysum = 0;
if (使用过的青眼亚白龙.Count > 0 && cards.IndexOf(使用过的青眼亚白龙[0])>0) if (使用过的青眼亚白龙.Count > 0 && cards.IndexOf(使用过的青眼亚白龙[0])>0)
{ {
Logger.WriteLine("优先用使用过的亚白龙同调."); Logger.DebugWriteLine("优先用使用过的亚白龙同调.");
ClientCard card = 使用过的青眼亚白龙[0]; ClientCard card = 使用过的青眼亚白龙[0];
使用过的青眼亚白龙.Remove(card); 使用过的青眼亚白龙.Remove(card);
cards.Remove(card); cards.Remove(card);
...@@ -193,14 +193,14 @@ namespace MycardBot.Game.AI.Decks ...@@ -193,14 +193,14 @@ namespace MycardBot.Game.AI.Decks
trysum = card.Level; trysum = card.Level;
if (trysum == sum) if (trysum == sum)
{ {
Logger.WriteLine(trysum + " dselected " + sum); Logger.DebugWriteLine(trysum + " dselected " + sum);
return selected; return selected;
} }
} }
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
// try level equal // try level equal
Logger.WriteLine("同调素材可以选择: " + card.Name); Logger.DebugWriteLine("同调素材可以选择: " + card.Name);
if (card.Level == sum) if (card.Level == sum)
{ {
return new[] { card }; return new[] { card };
...@@ -212,7 +212,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -212,7 +212,7 @@ namespace MycardBot.Game.AI.Decks
} }
selected.Add(card); selected.Add(card);
trysum += card.Level; trysum += card.Level;
Logger.WriteLine(trysum + " selected " + sum); Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum) if (trysum == sum)
{ {
return selected; return selected;
...@@ -229,8 +229,8 @@ namespace MycardBot.Game.AI.Decks ...@@ -229,8 +229,8 @@ namespace MycardBot.Game.AI.Decks
// try level sub // try level sub
selected2.Remove(card); selected2.Remove(card);
trysum -= card.Level; trysum -= card.Level;
//Logger.WriteLine(card.Id + ""); Logger.DebugWriteLine(card.Id + "");
Logger.WriteLine(trysum + " selected2 " + sum); Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum == sum) if (trysum == sum)
{ {
return selected2; return selected2;
...@@ -252,7 +252,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -252,7 +252,7 @@ namespace MycardBot.Game.AI.Decks
private bool 龙之灵庙效果() private bool 龙之灵庙效果()
{ {
Logger.WriteLine("龙之灵庙."); Logger.DebugWriteLine("龙之灵庙.");
AI.SelectCard(new[] AI.SelectCard(new[]
{ {
(int)CardId.白色灵龙, (int)CardId.白色灵龙,
...@@ -262,12 +262,12 @@ namespace MycardBot.Game.AI.Decks ...@@ -262,12 +262,12 @@ namespace MycardBot.Game.AI.Decks
}); });
if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙)) if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙))
{ {
Logger.WriteLine("手里没有本体,堆白石."); Logger.DebugWriteLine("手里没有本体,堆白石.");
AI.SelectNextCard((int)CardId.传说的白石); AI.SelectNextCard((int)CardId.传说的白石);
} }
else else
{ {
Logger.WriteLine("堆太古或灵龙或白石."); Logger.DebugWriteLine("堆太古或灵龙或白石.");
AI.SelectNextCard(new[] AI.SelectNextCard(new[]
{ {
(int)CardId.太古的白石, (int)CardId.太古的白石,
...@@ -280,7 +280,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -280,7 +280,7 @@ namespace MycardBot.Game.AI.Decks
private bool 龙觉醒旋律效果() private bool 龙觉醒旋律效果()
{ {
Logger.WriteLine("龙觉醒选要丢的卡."); Logger.DebugWriteLine("龙觉醒选要丢的卡.");
AI.SelectCard(new[] AI.SelectCard(new[]
{ {
(int)CardId.太古的白石, (int)CardId.太古的白石,
...@@ -296,20 +296,20 @@ namespace MycardBot.Game.AI.Decks ...@@ -296,20 +296,20 @@ namespace MycardBot.Game.AI.Decks
private bool 调和的宝札效果() private bool 调和的宝札效果()
{ {
Logger.WriteLine("调和选要丢的卡."); Logger.DebugWriteLine("调和选要丢的卡.");
if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙)) if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙))
{ {
Logger.WriteLine("手里没有本体,丢白石."); Logger.DebugWriteLine("手里没有本体,丢白石.");
AI.SelectCard((int)CardId.传说的白石); AI.SelectCard((int)CardId.传说的白石);
} }
else if (Duel.Fields[0].HasInHand((int)CardId.抵价购物)) else if (Duel.Fields[0].HasInHand((int)CardId.抵价购物))
{ {
Logger.WriteLine("手里有本体,再拿一个喂八抽."); Logger.DebugWriteLine("手里有本体,再拿一个喂八抽.");
AI.SelectCard((int)CardId.传说的白石); AI.SelectCard((int)CardId.传说的白石);
} }
else else
{ {
Logger.WriteLine("手里有本体,优先丢太古."); Logger.DebugWriteLine("手里有本体,优先丢太古.");
AI.SelectCard((int)CardId.太古的白石); AI.SelectCard((int)CardId.太古的白石);
} }
return true; return true;
...@@ -317,28 +317,28 @@ namespace MycardBot.Game.AI.Decks ...@@ -317,28 +317,28 @@ namespace MycardBot.Game.AI.Decks
private bool 抵价购物效果() private bool 抵价购物效果()
{ {
Logger.WriteLine("抵价购物发动."); Logger.DebugWriteLine("抵价购物发动.");
if (Duel.Fields[0].HasInHand((int)CardId.白色灵龙)) if (Duel.Fields[0].HasInHand((int)CardId.白色灵龙))
{ {
Logger.WriteLine("手里有白灵龙,优先丢掉."); Logger.DebugWriteLine("手里有白灵龙,优先丢掉.");
AI.SelectCard((int)CardId.白色灵龙); AI.SelectCard((int)CardId.白色灵龙);
return true; return true;
} }
else if (手里有2((int)CardId.青眼白龙)) else if (手里有2((int)CardId.青眼白龙))
{ {
Logger.WriteLine("手里有2个青眼白龙,丢1个."); Logger.DebugWriteLine("手里有2个青眼白龙,丢1个.");
AI.SelectCard((int)CardId.青眼白龙); AI.SelectCard((int)CardId.青眼白龙);
return true; return true;
} }
else if (手里有2((int)CardId.青眼亚白龙)) else if (手里有2((int)CardId.青眼亚白龙))
{ {
Logger.WriteLine("手里有2个青眼亚白龙,丢1个."); Logger.DebugWriteLine("手里有2个青眼亚白龙,丢1个.");
AI.SelectCard((int)CardId.青眼亚白龙); AI.SelectCard((int)CardId.青眼亚白龙);
return true; return true;
} }
else if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙) || !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙)) else if (!Duel.Fields[0].HasInHand((int)CardId.青眼白龙) || !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙))
{ {
Logger.WriteLine("手里没有成对的青眼和亚白,丢1个."); Logger.DebugWriteLine("手里没有成对的青眼和亚白,丢1个.");
AI.SelectCard(new[] AI.SelectCard(new[]
{ {
(int)CardId.青眼白龙, (int)CardId.青眼白龙,
...@@ -348,18 +348,18 @@ namespace MycardBot.Game.AI.Decks ...@@ -348,18 +348,18 @@ namespace MycardBot.Game.AI.Decks
} }
else else
{ {
Logger.WriteLine("手里只有一对,不能乱丢."); Logger.DebugWriteLine("手里只有一对,不能乱丢.");
return false; return false;
} }
} }
private bool 青眼亚白龙效果() private bool 青眼亚白龙效果()
{ {
Logger.WriteLine("亚白龙效果."); Logger.DebugWriteLine("亚白龙效果.");
ClientCard card = Duel.Fields[1].MonsterZone.GetInvincibleMonster(); ClientCard card = Duel.Fields[1].MonsterZone.GetInvincibleMonster();
if (card != null) if (card != null)
{ {
Logger.WriteLine("炸打不死的怪."); Logger.DebugWriteLine("炸打不死的怪.");
AI.SelectCard(card); AI.SelectCard(card);
使用过的青眼亚白龙.Add(Card); 使用过的青眼亚白龙.Add(Card);
return true; return true;
...@@ -367,7 +367,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -367,7 +367,7 @@ namespace MycardBot.Game.AI.Decks
card = Duel.Fields[1].MonsterZone.GetDangerousMonster(); card = Duel.Fields[1].MonsterZone.GetDangerousMonster();
if (card != null) if (card != null)
{ {
Logger.WriteLine("炸厉害的怪."); Logger.DebugWriteLine("炸厉害的怪.");
AI.SelectCard(card); AI.SelectCard(card);
使用过的青眼亚白龙.Add(Card); 使用过的青眼亚白龙.Add(Card);
return true; return true;
...@@ -375,7 +375,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -375,7 +375,7 @@ namespace MycardBot.Game.AI.Decks
card = AI.Utils.GetOneEnnemyBetterThanValue(Card.GetDefensePower(), false); card = AI.Utils.GetOneEnnemyBetterThanValue(Card.GetDefensePower(), false);
if (card != null) if (card != null)
{ {
Logger.WriteLine("炸比自己强的怪."); Logger.DebugWriteLine("炸比自己强的怪.");
AI.SelectCard(card); AI.SelectCard(card);
使用过的青眼亚白龙.Add(Card); 使用过的青眼亚白龙.Add(Card);
return true; return true;
...@@ -386,7 +386,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -386,7 +386,7 @@ namespace MycardBot.Game.AI.Decks
使用过的青眼亚白龙.Add(Card); 使用过的青眼亚白龙.Add(Card);
return true; return true;
} }
Logger.WriteLine("不炸."); Logger.DebugWriteLine("不炸.");
return false; return false;
} }
...@@ -394,7 +394,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -394,7 +394,7 @@ namespace MycardBot.Game.AI.Decks
{ {
if (Card.Location == CardLocation.Hand && CurrentChain.Count > 0) if (Card.Location == CardLocation.Hand && CurrentChain.Count > 0)
{ {
Logger.WriteLine("轰咆避免卡时点."); Logger.DebugWriteLine("轰咆避免卡时点.");
return false; return false;
} }
List<int> targets = new List<int> { List<int> targets = new List<int> {
...@@ -438,7 +438,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -438,7 +438,7 @@ namespace MycardBot.Game.AI.Decks
private bool 苍眼银龙效果() private bool 苍眼银龙效果()
{ {
Logger.WriteLine("苍眼银龙效果."); Logger.DebugWriteLine("苍眼银龙效果.");
if (Duel.Fields[1].GetSpellCount()>0) if (Duel.Fields[1].GetSpellCount()>0)
{ {
AI.SelectCard((int)CardId.白色灵龙); AI.SelectCard((int)CardId.白色灵龙);
...@@ -454,7 +454,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -454,7 +454,7 @@ namespace MycardBot.Game.AI.Decks
{ {
if (Card.Location == CardLocation.Hand) if (Card.Location == CardLocation.Hand)
{ {
Logger.WriteLine("贤士手卡效果."); Logger.DebugWriteLine("贤士手卡效果.");
return false; return false;
} }
AI.SelectCard(new[] AI.SelectCard(new[]
...@@ -468,26 +468,26 @@ namespace MycardBot.Game.AI.Decks ...@@ -468,26 +468,26 @@ namespace MycardBot.Game.AI.Decks
private bool 白色灵龙效果() private bool 白色灵龙效果()
{ {
//Logger.WriteLine("白色灵龙"+ActivateDescription); Logger.DebugWriteLine("白色灵龙"+ActivateDescription);
if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0)) if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0))
{ {
Logger.WriteLine("白色灵龙拆后场."); Logger.DebugWriteLine("白色灵龙拆后场.");
return true; return true;
} }
/*else if(Duel.Phase==DuelPhase.BattleStart) /*else if(Duel.Phase==DuelPhase.BattleStart)
{ {
Logger.WriteLine("白色灵龙战阶变身."); Logger.DebugWriteLine("白色灵龙战阶变身.");
return true; return true;
}*/ }*/
else else
{ {
//Logger.WriteLine("白色灵龙特招手卡. 对象数量"+Duel.ChainTargets.Count); Logger.DebugWriteLine("白色灵龙特招手卡. 对象数量"+Duel.ChainTargets.Count);
foreach (ClientCard card in Duel.ChainTargets) foreach (ClientCard card in Duel.ChainTargets)
{ {
// Logger.WriteLine("对象" + card.Id); // Logger.DebugWriteLine("对象" + card.Id);
if (Card.Equals(card)) if (Card.Equals(card))
{ {
Logger.WriteLine("白色灵龙被取对象,是否变身."); Logger.DebugWriteLine("白色灵龙被取对象,是否变身.");
return 手里有2((int)CardId.青眼白龙) || ( return 手里有2((int)CardId.青眼白龙) || (
Duel.Fields[0].HasInGraveyard((int)CardId.青眼白龙) Duel.Fields[0].HasInGraveyard((int)CardId.青眼白龙)
&& Duel.Fields[0].HasInGraveyard((int)CardId.太古的白石) && Duel.Fields[0].HasInGraveyard((int)CardId.太古的白石)
...@@ -500,28 +500,28 @@ namespace MycardBot.Game.AI.Decks ...@@ -500,28 +500,28 @@ namespace MycardBot.Game.AI.Decks
private bool 青眼精灵龙效果() private bool 青眼精灵龙效果()
{ {
//Logger.WriteLine("青眼精灵龙" + ActivateDescription); Logger.DebugWriteLine("青眼精灵龙" + ActivateDescription);
if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0)) if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0))
{ {
Logger.WriteLine("青眼精灵龙无效墓地."); Logger.DebugWriteLine("青眼精灵龙无效墓地.");
return LastChainPlayer == 1; return LastChainPlayer == 1;
} }
else if(Duel.Player == 1 && (Duel.Phase == DuelPhase.BattleStart || Duel.Phase == DuelPhase.End)) else if(Duel.Player == 1 && (Duel.Phase == DuelPhase.BattleStart || Duel.Phase == DuelPhase.End))
{ {
Logger.WriteLine("青眼精灵龙主动变身."); Logger.DebugWriteLine("青眼精灵龙主动变身.");
AI.SelectCard((int)CardId.苍眼银龙); AI.SelectCard((int)CardId.苍眼银龙);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
return true; return true;
} }
else else
{ {
//Logger.WriteLine("青眼精灵龙变身. 对象数量" + Duel.ChainTargets.Count); Logger.DebugWriteLine("青眼精灵龙变身. 对象数量" + Duel.ChainTargets.Count);
foreach (ClientCard card in Duel.ChainTargets) foreach (ClientCard card in Duel.ChainTargets)
{ {
// Logger.WriteLine("对象" + card.Id); // Logger.DebugWriteLine("对象" + card.Id);
if (Card.Equals(card)) if (Card.Equals(card))
{ {
Logger.WriteLine("青眼精灵龙被取对象,变身."); Logger.DebugWriteLine("青眼精灵龙被取对象,变身.");
AI.SelectCard((int)CardId.苍眼银龙); AI.SelectCard((int)CardId.苍眼银龙);
return true; return true;
} }
...@@ -532,10 +532,10 @@ namespace MycardBot.Game.AI.Decks ...@@ -532,10 +532,10 @@ namespace MycardBot.Game.AI.Decks
private bool 希望魁龙银河巨神效果() private bool 希望魁龙银河巨神效果()
{ {
Logger.WriteLine("希望魁龙银河巨神" + ActivateDescription); Logger.DebugWriteLine("希望魁龙银河巨神" + ActivateDescription);
if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0)) if (ActivateDescription == -1) // AI.Utils.GetStringId((int)CardId.白色灵龙, 0))
{ {
Logger.WriteLine("希望魁龙银河巨神无效魔法."); Logger.DebugWriteLine("希望魁龙银河巨神无效魔法.");
return LastChainPlayer == 1; return LastChainPlayer == 1;
} }
return LastChainPlayer == 1; return LastChainPlayer == 1;
...@@ -545,25 +545,25 @@ namespace MycardBot.Game.AI.Decks ...@@ -545,25 +545,25 @@ namespace MycardBot.Game.AI.Decks
{ {
if (ActivateDescription == AI.Utils.GetStringId((int)CardId.太古的白石, 0)) if (ActivateDescription == AI.Utils.GetStringId((int)CardId.太古的白石, 0))
{ {
Logger.WriteLine("太古白石回收效果."); Logger.DebugWriteLine("太古白石回收效果.");
if (Duel.Fields[0].HasInHand((int)CardId.抵价购物) if (Duel.Fields[0].HasInHand((int)CardId.抵价购物)
&& !Duel.Fields[0].HasInHand((int)CardId.青眼白龙) && !Duel.Fields[0].HasInHand((int)CardId.青眼白龙)
&& !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙)) && !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙))
{ {
Logger.WriteLine("回收喂八抽."); Logger.DebugWriteLine("回收喂八抽.");
AI.SelectCard((int)CardId.青眼白龙); AI.SelectCard((int)CardId.青眼白龙);
return true; return true;
} }
if (已特殊召唤青眼亚白龙) if (已特殊召唤青眼亚白龙)
{ {
Logger.WriteLine("已经跳过亚白龙,下回合再回收."); Logger.DebugWriteLine("已经跳过亚白龙,下回合再回收.");
return false; return false;
} }
if (Duel.Fields[0].HasInHand((int)CardId.青眼白龙) if (Duel.Fields[0].HasInHand((int)CardId.青眼白龙)
&& !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙) && !Duel.Fields[0].HasInHand((int)CardId.青眼亚白龙)
&& Duel.Fields[0].HasInGraveyard((int)CardId.青眼亚白龙)) && Duel.Fields[0].HasInGraveyard((int)CardId.青眼亚白龙))
{ {
Logger.WriteLine("缺亚白龙,回收."); Logger.DebugWriteLine("缺亚白龙,回收.");
AI.SelectCard((int)CardId.青眼亚白龙); AI.SelectCard((int)CardId.青眼亚白龙);
return true; return true;
} }
...@@ -571,26 +571,26 @@ namespace MycardBot.Game.AI.Decks ...@@ -571,26 +571,26 @@ namespace MycardBot.Game.AI.Decks
&& !Duel.Fields[0].HasInHand((int)CardId.青眼白龙) && !Duel.Fields[0].HasInHand((int)CardId.青眼白龙)
&& Duel.Fields[0].HasInGraveyard((int)CardId.青眼白龙)) && Duel.Fields[0].HasInGraveyard((int)CardId.青眼白龙))
{ {
Logger.WriteLine("有亚白龙缺本体,回收."); Logger.DebugWriteLine("有亚白龙缺本体,回收.");
AI.SelectCard((int)CardId.青眼白龙); AI.SelectCard((int)CardId.青眼白龙);
return true; return true;
} }
Logger.WriteLine("并没有应该回收的."); Logger.DebugWriteLine("并没有应该回收的.");
return false; return false;
} }
else else
{ {
Logger.WriteLine("太古白石特招效果."); Logger.DebugWriteLine("太古白石特招效果.");
List<ClientCard> spells = Duel.Fields[1].GetSpells(); List<ClientCard> spells = Duel.Fields[1].GetSpells();
if (spells.Count == 0) if (spells.Count == 0)
{ {
Logger.WriteLine("对面没坑,跳个本体."); Logger.DebugWriteLine("对面没坑,跳个本体.");
AI.SelectCard((int)CardId.青眼白龙); AI.SelectCard((int)CardId.青眼白龙);
//AI.SelectCard((int)CardId.白色灵龙); //AI.SelectCard((int)CardId.白色灵龙);
} }
else else
{ {
Logger.WriteLine("对面有坑,拆."); Logger.DebugWriteLine("对面有坑,拆.");
AI.SelectCard((int)CardId.白色灵龙); AI.SelectCard((int)CardId.白色灵龙);
} }
return true; return true;
...@@ -605,7 +605,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -605,7 +605,7 @@ namespace MycardBot.Game.AI.Decks
private bool 太古的白石通常召唤() private bool 太古的白石通常召唤()
{ {
Logger.WriteLine("白石通常召唤."); Logger.DebugWriteLine("白石通常召唤.");
return Duel.Fields[0].HasInMonstersZone(new List<int> return Duel.Fields[0].HasInMonstersZone(new List<int>
{ {
(int)CardId.青色眼睛的贤士, (int)CardId.青色眼睛的贤士,
...@@ -619,16 +619,16 @@ namespace MycardBot.Game.AI.Decks ...@@ -619,16 +619,16 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼光波龙超量召唤() private bool 银河眼光波龙超量召唤()
{ {
Logger.WriteLine("银河眼光波龙超量召唤."); Logger.DebugWriteLine("银河眼光波龙超量召唤.");
if (Duel.Turn == 1) if (Duel.Turn == 1)
{ {
Logger.WriteLine("先攻不叠银河眼,叠银河巨神."); Logger.DebugWriteLine("先攻不叠银河眼,叠银河巨神.");
return false; return false;
} }
List<ClientCard> monsters = Duel.Fields[1].GetMonsters(); List<ClientCard> monsters = Duel.Fields[1].GetMonsters();
if (monsters.Count == 1 && !monsters[0].IsFacedown() && ((monsters[0].IsDefense() && monsters[0].GetDefensePower() >= 3000) && monsters[0].HasType(CardType.Xyz))) if (monsters.Count == 1 && !monsters[0].IsFacedown() && ((monsters[0].IsDefense() && monsters[0].GetDefensePower() >= 3000) && monsters[0].HasType(CardType.Xyz)))
{ {
Logger.WriteLine("只有一个大怪兽,光波龙抢之."); Logger.DebugWriteLine("只有一个大怪兽,光波龙抢之.");
return true; return true;
} }
if (monsters.Count >= 3) if (monsters.Count >= 3)
...@@ -637,7 +637,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -637,7 +637,7 @@ namespace MycardBot.Game.AI.Decks
{ {
if(!monster.IsFacedown() && ((monster.IsDefense() && monster.GetDefensePower() >= 3000) || monster.HasType(CardType.Xyz))) if(!monster.IsFacedown() && ((monster.IsDefense() && monster.GetDefensePower() >= 3000) || monster.HasType(CardType.Xyz)))
{ {
Logger.WriteLine("貌似打不死,出个光波龙看看."); Logger.DebugWriteLine("貌似打不死,出个光波龙看看.");
return true; return true;
} }
} }
...@@ -647,15 +647,15 @@ namespace MycardBot.Game.AI.Decks ...@@ -647,15 +647,15 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼光子龙皇超量召唤() private bool 银河眼光子龙皇超量召唤()
{ {
Logger.WriteLine("银河眼光子龙皇超量召唤."); Logger.DebugWriteLine("银河眼光子龙皇超量召唤.");
if (Duel.Turn == 1) if (Duel.Turn == 1)
{ {
Logger.WriteLine("先攻不叠银河眼,叠银河巨神."); Logger.DebugWriteLine("先攻不叠银河眼,叠银河巨神.");
return false; return false;
} }
if (AI.Utils.IsOneEnnemyBetterThanValue(2999, false)) if (AI.Utils.IsOneEnnemyBetterThanValue(2999, false))
{ {
Logger.WriteLine("有高攻怪兽,出银河眼."); Logger.DebugWriteLine("有高攻怪兽,出银河眼.");
return true; return true;
} }
return false; return false;
...@@ -663,7 +663,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -663,7 +663,7 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼重铠光子龙超量召唤() private bool 银河眼重铠光子龙超量召唤()
{ {
Logger.WriteLine("银河眼重铠光子龙超量召唤."); Logger.DebugWriteLine("银河眼重铠光子龙超量召唤.");
if (Duel.Fields[0].HasInMonstersZone((int)CardId.银河眼光波龙)) if (Duel.Fields[0].HasInMonstersZone((int)CardId.银河眼光波龙))
{ {
List<ClientCard> monsters = Duel.Fields[0].GetMonsters(); List<ClientCard> monsters = Duel.Fields[0].GetMonsters();
...@@ -681,7 +681,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -681,7 +681,7 @@ namespace MycardBot.Game.AI.Decks
{ {
if (!AI.Utils.IsOneEnnemyBetterThanValue(4000, false)) if (!AI.Utils.IsOneEnnemyBetterThanValue(4000, false))
{ {
Logger.WriteLine("没有高攻怪兽,出重铠."); Logger.DebugWriteLine("没有高攻怪兽,出重铠.");
AI.SelectCard((int)CardId.银河眼光子龙皇); AI.SelectCard((int)CardId.银河眼光子龙皇);
return true; return true;
} }
...@@ -691,7 +691,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -691,7 +691,7 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼暗物质龙超量召唤() private bool 银河眼暗物质龙超量召唤()
{ {
Logger.WriteLine("银河眼重铠光子龙超量召唤."); Logger.DebugWriteLine("银河眼重铠光子龙超量召唤.");
if (Duel.Fields[0].HasInMonstersZone((int)CardId.银河眼重铠光子龙)) if (Duel.Fields[0].HasInMonstersZone((int)CardId.银河眼重铠光子龙))
{ {
AI.SelectCard((int)CardId.银河眼重铠光子龙); AI.SelectCard((int)CardId.银河眼重铠光子龙);
...@@ -707,7 +707,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -707,7 +707,7 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼光波龙效果() private bool 银河眼光波龙效果()
{ {
Logger.WriteLine("银河眼光波龙效果."); Logger.DebugWriteLine("银河眼光波龙效果.");
List<ClientCard> monsters = Duel.Fields[1].GetMonsters(); List<ClientCard> monsters = Duel.Fields[1].GetMonsters();
foreach (ClientCard monster in monsters) foreach (ClientCard monster in monsters)
{ {
...@@ -733,7 +733,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -733,7 +733,7 @@ namespace MycardBot.Game.AI.Decks
private bool 银河眼重铠光子龙效果() private bool 银河眼重铠光子龙效果()
{ {
Logger.WriteLine("重铠优先炸后场."); Logger.DebugWriteLine("重铠优先炸后场.");
List<ClientCard> spells = Duel.Fields[1].GetSpells(); List<ClientCard> spells = Duel.Fields[1].GetSpells();
foreach (ClientCard spell in spells) foreach (ClientCard spell in spells)
{ {
...@@ -754,7 +754,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -754,7 +754,7 @@ namespace MycardBot.Game.AI.Decks
List<ClientCard> monsters = Duel.Fields[1].GetMonsters(); List<ClientCard> monsters = Duel.Fields[1].GetMonsters();
if (monsters.Count >= 2) if (monsters.Count >= 2)
{ {
Logger.WriteLine("怪多就先炸守备的."); Logger.DebugWriteLine("怪多就先炸守备的.");
foreach (ClientCard monster in monsters) foreach (ClientCard monster in monsters)
{ {
if (monster.IsDefense()) if (monster.IsDefense())
...@@ -767,7 +767,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -767,7 +767,7 @@ namespace MycardBot.Game.AI.Decks
} }
if (monsters.Count == 2) if (monsters.Count == 2)
{ {
Logger.WriteLine("2只怪只炸打不过的,剩下留给暗物质打."); Logger.DebugWriteLine("2只怪只炸打不过的,剩下留给暗物质打.");
foreach (ClientCard monster in monsters) foreach (ClientCard monster in monsters)
{ {
if (monster.IsMonsterInvincible() || monster.IsMonsterDangerous() || monster.GetDefensePower() > 4000) if (monster.IsMonsterInvincible() || monster.IsMonsterDangerous() || monster.GetDefensePower() > 4000)
...@@ -808,22 +808,22 @@ namespace MycardBot.Game.AI.Decks ...@@ -808,22 +808,22 @@ namespace MycardBot.Game.AI.Decks
{ {
if (Duel.Phase == DuelPhase.Main1) if (Duel.Phase == DuelPhase.Main1)
{ {
Logger.WriteLine("主阶段1同调精灵龙."); Logger.DebugWriteLine("主阶段1同调精灵龙.");
if (使用过的青眼亚白龙.Count>0) if (使用过的青眼亚白龙.Count>0)
{ {
Logger.WriteLine("有用过的亚白需要同调."); Logger.DebugWriteLine("有用过的亚白需要同调.");
return true; return true;
} }
if (Duel.Turn==1) if (Duel.Turn==1)
{ {
Logger.WriteLine("先攻同调."); Logger.DebugWriteLine("先攻同调.");
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
return true; return true;
} }
} }
if (Duel.Phase == DuelPhase.Main2) if (Duel.Phase == DuelPhase.Main2)
{ {
Logger.WriteLine("主阶段2同调精灵龙."); Logger.DebugWriteLine("主阶段2同调精灵龙.");
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
return true; return true;
} }
...@@ -834,21 +834,21 @@ namespace MycardBot.Game.AI.Decks ...@@ -834,21 +834,21 @@ namespace MycardBot.Game.AI.Decks
{ {
if (Duel.Phase == DuelPhase.Main1) if (Duel.Phase == DuelPhase.Main1)
{ {
Logger.WriteLine("主阶段1超量银河巨神."); Logger.DebugWriteLine("主阶段1超量银河巨神.");
if (使用过的青眼亚白龙.Count > 0) if (使用过的青眼亚白龙.Count > 0)
{ {
Logger.WriteLine("有用过的亚白可以叠."); Logger.DebugWriteLine("有用过的亚白可以叠.");
return true; return true;
} }
if (Duel.Turn == 1) if (Duel.Turn == 1)
{ {
Logger.WriteLine("先攻超量银河巨神."); Logger.DebugWriteLine("先攻超量银河巨神.");
return true; return true;
} }
} }
if (Duel.Phase == DuelPhase.Main2) if (Duel.Phase == DuelPhase.Main2)
{ {
Logger.WriteLine("主阶段2超量银河巨神."); Logger.DebugWriteLine("主阶段2超量银河巨神.");
return true; return true;
} }
return false; return false;
...@@ -858,7 +858,7 @@ namespace MycardBot.Game.AI.Decks ...@@ -858,7 +858,7 @@ namespace MycardBot.Game.AI.Decks
{ {
if (Duel.Turn == 1) if (Duel.Turn == 1)
{ {
Logger.WriteLine("先攻可以超量森罗的姬芽宫."); Logger.DebugWriteLine("先攻可以超量森罗的姬芽宫.");
return true; return true;
} }
if (Duel.Phase == DuelPhase.Main1 && !Duel.Fields[0].HasInMonstersZone(new List<int> if (Duel.Phase == DuelPhase.Main1 && !Duel.Fields[0].HasInMonstersZone(new List<int>
...@@ -868,12 +868,12 @@ namespace MycardBot.Game.AI.Decks ...@@ -868,12 +868,12 @@ namespace MycardBot.Game.AI.Decks
(int)CardId.白色灵龙 (int)CardId.白色灵龙
})) }))
{ {
Logger.WriteLine("不能出L9,只能叠森罗的姬芽宫."); Logger.DebugWriteLine("不能出L9,只能叠森罗的姬芽宫.");
return true; return true;
} }
if (Duel.Phase == DuelPhase.Main2) if (Duel.Phase == DuelPhase.Main2)
{ {
Logger.WriteLine("主阶段2超量森罗的姬芽宫."); Logger.DebugWriteLine("主阶段2超量森罗的姬芽宫.");
return true; return true;
} }
return false; return false;
......
...@@ -366,8 +366,8 @@ namespace WindBot.Game ...@@ -366,8 +366,8 @@ namespace WindBot.Game
} }
selected.Add(card); selected.Add(card);
trysum += card.Level; trysum += card.Level;
//Logger.WriteLine(card.Id + ""); //Logger.DebugWriteLine(card.Id + "");
//Logger.WriteLine(trysum + " selected " + sum); //Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum) if (trysum == sum)
{ {
return selected; return selected;
...@@ -384,8 +384,8 @@ namespace WindBot.Game ...@@ -384,8 +384,8 @@ namespace WindBot.Game
// try level sub // try level sub
selected2.Remove(card); selected2.Remove(card);
trysum -= card.Level; trysum -= card.Level;
//Logger.WriteLine(card.Id + ""); //Logger.DebugWriteLine(card.Id + "");
//Logger.WriteLine(trysum + " selected2 " + sum); //Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum == sum) if (trysum == sum)
{ {
return selected2; return selected2;
......
...@@ -146,7 +146,7 @@ namespace WindBot.Game ...@@ -146,7 +146,7 @@ namespace WindBot.Game
private void OnPlayerEnter(BinaryReader packet) private void OnPlayerEnter(BinaryReader packet)
{ {
string name = packet.ReadUnicode(Program.PlayerNameSize); string name = packet.ReadUnicode(20);
int pos = packet.ReadByte(); int pos = packet.ReadByte();
if (pos < 8) if (pos < 8)
_room.Names[pos] = name; _room.Names[pos] = name;
...@@ -230,6 +230,7 @@ namespace WindBot.Game ...@@ -230,6 +230,7 @@ namespace WindBot.Game
private void OnRetry(BinaryReader packet) private void OnRetry(BinaryReader packet)
{ {
Connection.Close();
throw new Exception("Got MSG_RETRY."); throw new Exception("Got MSG_RETRY.");
} }
......
...@@ -16,19 +16,21 @@ namespace WindBot.Game ...@@ -16,19 +16,21 @@ namespace WindBot.Game
private string _serverHost; private string _serverHost;
private int _serverPort; private int _serverPort;
private short _proVersion;
private string _roomInfos;
private string _roomInfo;
private GameBehavior _behavior; private GameBehavior _behavior;
public GameClient(string username = "Windbot", string deck = "Blue-Eyes", string serverHost = "127.0.0.1", int serverPort = 7911, string dialog = "default", string roomInfos = "") public GameClient(WindBotInfo Info)
{ {
Username = username; Username = Info.Name;
Deck = deck; Deck = Info.Deck;
Dialog = dialog; Dialog = Info.Dialog;
_serverHost = serverHost; _serverHost = Info.Host;
_serverPort = serverPort; _serverPort = Info.Port;
_roomInfos = roomInfos; _roomInfo = Info.HostInfo;
_proVersion = (short)Info.Version;
} }
public void Start() public void Start()
...@@ -45,14 +47,14 @@ namespace WindBot.Game ...@@ -45,14 +47,14 @@ namespace WindBot.Game
private void OnConnected() private void OnConnected()
{ {
BinaryWriter packet = GamePacketFactory.Create(CtosMessage.PlayerInfo); BinaryWriter packet = GamePacketFactory.Create(CtosMessage.PlayerInfo);
packet.WriteUnicode(Username, Program.PlayerNameSize); packet.WriteUnicode(Username, 20);
Connection.Send(packet); Connection.Send(packet);
byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 }; byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 };
packet = GamePacketFactory.Create(CtosMessage.JoinGame); packet = GamePacketFactory.Create(CtosMessage.JoinGame);
packet.Write(Program.ProVersion); packet.Write(_proVersion);
packet.Write(junk); packet.Write(junk);
packet.WriteUnicode(_roomInfos, 30); packet.WriteUnicode(_roomInfo, 30);
Connection.Send(packet); Connection.Send(packet);
} }
......
...@@ -8,6 +8,11 @@ namespace WindBot ...@@ -8,6 +8,11 @@ namespace WindBot
{ {
Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message); Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message);
} }
public static void DebugWriteLine(string message)
{
if (Program.DebugMode)
Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message);
}
public static void WriteErrorLine(string message) public static void WriteErrorLine(string message)
{ {
Console.Error.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message); Console.Error.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + message);
......
...@@ -9,32 +9,133 @@ using System.Web; ...@@ -9,32 +9,133 @@ using System.Web;
namespace WindBot namespace WindBot
{ {
public class WindBotInfo
{
public string Name { get; set; }
public string Deck { get; set; }
public string Host { get; set; }
public string Dialog { get; set; }
public int Port { get; set; }
public int Version { get; set; }
}
public class Program public class Program
{ {
public static short ProVersion = 0x133A; #if DEBUG
public static int PlayerNameSize = 20; public static bool DebugMode = true;
#else
public static bool DebugMode = false;
#endif
internal static Random Rand; internal static Random Rand;
internal static void Main() internal static void Main(string[] args)
{
InitDatas("cards.cdb");
int argc = args.Length;
// If the first commandline parameter is DebugMode
if (argc > 0 && args[0] == "DebugMode")
{
DebugMode = true;
// Shift the args array to skip the first parameter
argc--;
Array.Copy(args, 1, args, 0, argc);
}
// Only one parameter will make Windbot run as a server, use the parameter as port
// provide a http interface to create bot.
// eg. http://127.0.0.1:2399/?name=%E2%91%A8&deck=Blue-Eyes&host=127.0.0.1&port=7911&dialog=cirno.zh-CN&version=4922
if (argc == 1)
{
RunAsServer(Int32.Parse(args[0]));
}
// Use all five parameters to run Windbot
// The parameters should be name, deck, server ip, server port, password
// eg. WindBot.exe "My Bot" "Zexal Weapons" 127.0.0.1 7911 ""
else if (argc == 5)
{
RunFromArgs(args);
}
// Use environment variables to run Windbot
// List of variables required:
// YGOPRO_HOST
// YGOPRO_PORT
// YGOPRO_NAME
// YGOPRO_DECK
//
// List of variables optional:
// YGOPRO_VERSION
// YGOPRO_DIALOG
// YGOPRO_PASSWORD
//
// eg. (cmd)
// set YGOPRO_VERSION=4922
// set YGOPRO_HOST=127.0.0.1
// set YGOPRO_PORT=7911
// set YGOPRO_NAME=Meow
// set YGOPRO_DECK=Blue-Eyes
// set YGOPRO_DIALOG=zh-CN
// WindBot.exe
else if (Environment.GetEnvironmentVariable("YGOPRO_NAME") != null)
{
RunFromEnv();
}
// Else, run from the default settings
else
{
WindBotInfo Info = new WindBotInfo();
Run(Info);
}
}
public static void InitDatas(string databasePath)
{
Rand = new Random();
DecksManager.Init();
string absolutePath = Path.GetFullPath(databasePath);
NamedCardsManager.Init(absolutePath);
}
private static void RunFromArgs(string[] args)
{
WindBotInfo Info = new WindBotInfo();
Info.Name = args[0];
Info.Deck = args[1];
Info.Host = args[2];
Info.Port = Int32.Parse(args[3]);
Info.HostInfo = args[4];
Run(Info);
}
private static void RunFromEnv()
{
WindBotInfo Info = new WindBotInfo();
Info.Name = Environment.GetEnvironmentVariable("YGOPRO_NAME");
Info.Deck = Environment.GetEnvironmentVariable("YGOPRO_DECK");
Info.Host = Environment.GetEnvironmentVariable("YGOPRO_HOST");
Info.Port = Int32.Parse(Environment.GetEnvironmentVariable("YGOPRO_PORT"));
string EnvDialog = Environment.GetEnvironmentVariable("YGOPRO_DIALOG");
if (EnvDialog != null)
Info.Dialog = EnvDialog;
string EnvVersion = Environment.GetEnvironmentVariable("YGOPRO_VERSION");
if (EnvVersion != null)
Info.Version = Int16.Parse(EnvVersion);
string EnvPassword = Environment.GetEnvironmentVariable("YGOPRO_PASSWORD");
if (EnvPassword != null)
Info.HostInfo = EnvPassword;
GameClient client = new GameClient(Info);
client.Start();
while (client.Connection.IsConnected)
{
client.Tick();
Thread.Sleep(30);
}
}
private static void RunAsServer(int ServerPort)
{ {
Init("cards.cdb");
using (HttpListener MainServer = new HttpListener()) using (HttpListener MainServer = new HttpListener())
{ {
MainServer.AuthenticationSchemes = AuthenticationSchemes.Anonymous; MainServer.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
MainServer.Prefixes.Add("http://127.0.0.1:2399/"); MainServer.Prefixes.Add("http://127.0.0.1:2399/");
MainServer.Start(); MainServer.Start();
Console.WriteLine("Windbot Server Start Successed."); Logger.WriteLine("Windbot Server Start Successed.");
while (true) while (true)
{ {
try try
...@@ -46,15 +147,20 @@ namespace WindBot ...@@ -46,15 +147,20 @@ namespace WindBot
Info.Name = HttpUtility.ParseQueryString(RawUrl).Get("name"); Info.Name = HttpUtility.ParseQueryString(RawUrl).Get("name");
Info.Deck = HttpUtility.ParseQueryString(RawUrl).Get("deck"); Info.Deck = HttpUtility.ParseQueryString(RawUrl).Get("deck");
Info.Host = HttpUtility.ParseQueryString(RawUrl).Get("host"); Info.Host = HttpUtility.ParseQueryString(RawUrl).Get("host");
Info.Dialog = HttpUtility.ParseQueryString(RawUrl).Get("dialog");
string port = HttpUtility.ParseQueryString(RawUrl).Get("port"); string port = HttpUtility.ParseQueryString(RawUrl).Get("port");
if (port != null) if (port != null)
Info.Port = Int32.Parse(port); Info.Port = Int32.Parse(port);
string dialog = HttpUtility.ParseQueryString(RawUrl).Get("dialog");
if (dialog != null)
Info.Dialog = dialog;
string version = HttpUtility.ParseQueryString(RawUrl).Get("version"); string version = HttpUtility.ParseQueryString(RawUrl).Get("version");
if (version != null) if (version != null)
Info.Version = Int16.Parse(version); Info.Version = Int16.Parse(version);
string password = HttpUtility.ParseQueryString(RawUrl).Get("password");
if (password != null)
Info.HostInfo = password;
if (Info.Name == null || Info.Deck == null || Info.Host == null || Info.Dialog == null || port == null || version == null) if (Info.Name == null || Info.Deck == null || Info.Host == null || port == null)
{ {
ctx.Response.StatusCode = 400; ctx.Response.StatusCode = 400;
ctx.Response.Close(); ctx.Response.Close();
...@@ -68,7 +174,10 @@ namespace WindBot ...@@ -68,7 +174,10 @@ namespace WindBot
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteErrorLine("Start Thread Error: " + ex); if (!DebugMode)
Logger.WriteErrorLine("Start Thread Error: " + ex);
else
throw ex;
} }
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
ctx.Response.Close(); ctx.Response.Close();
...@@ -76,35 +185,23 @@ namespace WindBot ...@@ -76,35 +185,23 @@ namespace WindBot
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteErrorLine("Parse Http Request Error: " + ex); if (!DebugMode)
Logger.WriteErrorLine("Parse Http Request Error: " + ex);
else
throw ex;
} }
} }
} }
} }
public static void Init(string databasePath)
{
Rand = new Random();
DecksManager.Init();
InitCardsManager(databasePath);
}
private static void InitCardsManager(string databasePath)
{
string currentPath = Path.GetFullPath(".");
string absolutePath = Path.Combine(currentPath, databasePath);
NamedCardsManager.Init(absolutePath);
}
private static void Run(object o) private static void Run(object o)
{ {
#if !DEBUG
try try
{ {
WindBotInfo Info = (WindBotInfo)o; WindBotInfo Info = (WindBotInfo)o;
GameClient client = new GameClient(Info.Name, Info.Deck, Info.Host, Info.Port, Info.Dialog); GameClient client = new GameClient(Info);
client.Start(); client.Start();
Logger.WriteLine(client.Username + " started."); Logger.DebugWriteLine(client.Username + " started.");
while (client.Connection.IsConnected) while (client.Connection.IsConnected)
{ {
try try
...@@ -114,32 +211,27 @@ namespace WindBot ...@@ -114,32 +211,27 @@ namespace WindBot
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteErrorLine("Tick Error: " + ex); if (!DebugMode)
Logger.WriteErrorLine("Tick Error: " + ex);
else
throw ex;
} }
} }
Logger.WriteLine(client.Username + " end."); Logger.DebugWriteLine(client.Username + " end.");
System.Threading.Thread.CurrentThread.Abort(); //System.Threading.Thread.CurrentThread.Abort();
}
catch (ThreadAbortException ex)
{
//Logger.WriteErrorLine("Run Error: " + ex);
} }
//catch (ThreadAbortException)
//{
//if (DebugMode)
// throw ex;
//}
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteErrorLine("Run Error: " + ex); if (!DebugMode)
Logger.WriteErrorLine("Run Error: " + ex);
else
throw ex;
} }
#else
WindBotInfo Info = (WindBotInfo)o;
GameClient client = new GameClient(Info.Name, Info.Deck, Info.Host, Info.Port, Info.Dialog);
client.Start();
Logger.WriteLine(client.Username + " started.");
while (client.Connection.IsConnected)
{
client.Tick();
Thread.Sleep(30);
}
Logger.WriteLine(client.Username + " end.");
#endif
} }
} }
} }
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
<Compile Include="Logger.cs" /> <Compile Include="Logger.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindBotInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
......
using System;
namespace WindBot
{
public class WindBotInfo
{
public string Name { get; set; }
public string Deck { get; set; }
public string Dialog { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string HostInfo { get; set; }
public int Version { get; set; }
public WindBotInfo()
{
Name = "WindBot";
Deck = "Blue-Eyes";
Dialog = "default";
Host = "127.0.0.1";
Port = 7911;
HostInfo = "";
Version = 0x133A;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment