public FairyTwins(IGameEnvironment env) { effects = new Effect[] { new GeneratedEffect("Field", "onUse", "return true", "engine.createToken(player, card.define, player[\"Field\"].indexOf(card) + 1);") }; }
public THHGame(IGameEnvironment env, bool shuffle = true, params CardDefine[] cards) : base(env, new HeartStoneRule(env), (int)DateTime.Now.ToBinary()) { engine = new CardEngine(env, new HeartStoneRule(env), (int)DateTime.Now.ToBinary()); engine.setProp("shuffle", shuffle); engine.afterEvent += afterEvent; }
public HeartStoneRule(IGameEnvironment env, params CardDefine[] cards) { pool = new CardPool(); //加载卡池 //加载内置卡池 Dictionary <int, CardDefine> dicCards = typeof(HeartStoneRule).Assembly.GetTypes(). Where(t => { return(!t.IsAbstract && t.IsSubclassOf(typeof(CardDefine)) && (t.GetConstructor(new Type[0]) != null || t.GetConstructor(new Type[] { typeof(IGameEnvironment) }) != null)); }). Select(t => { ConstructorInfo constructor = t.GetConstructor(new Type[0]); if (constructor != null) { return(constructor.Invoke(new object[0]) as CardDefine); } else { constructor = t.GetConstructor(new Type[] { typeof(IGameEnvironment) }); return(constructor.Invoke(new object[] { env }) as CardDefine); } }).ToDictionary(d => { return(d.id); }); //加载参数卡池 for (int i = 0; i < cards.Length; i++) { if (!dicCards.ContainsKey(cards[i].id)) { dicCards.Add(cards[i].id, cards[i]); } else { throw new ArgumentException("存在重复的卡片定义id" + cards[i].id); } } //加载外置卡池 if (env != null) { foreach (string path in env.getFiles("Cards", "*.thcd")) { using (TextReader reader = env.getFileReader(path)) { GeneratedCardDefine card = CardFileHelper.read(reader); if (dicCards.ContainsKey(card.id)) { throw new ArgumentException("存在重复的卡片定义id" + card.id); } else { dicCards.Add(card.id, card); } } } } pool = new CardPool(dicCards.Values.ToArray()); }