SCards setCardIndex(SCard card, int index = 0, params CardPredicat[] filters) { // use for set a card first or last // in deck or maybe board // to do this required: // get all indices // then found in them a required card // make its index first // and reshuffle them // List <int> indexes = selectIndices(filters); List <int> newIndexes = new List <int>(indexes); int wasCardIndex = _cards.IndexOf(card); // now in range item has ind = wasRangeINdex // but required its place in param 'index' // change it if it exists int wasRangeIndex = newIndexes.IndexOf(wasCardIndex); // try to change a place of card in group // but grpup doesnt contain this card if (wasRangeIndex < 0) { return(this); } newIndexes.RemoveAt(wasRangeIndex); newIndexes.Insert(index, wasCardIndex); setCards(range(newIndexes), indexes); return(this); }
public SCards boost(int X, SCard source = null) { // boost all cards // then in order trigger // their onBoost foreachCard((c) => { c.power.boost(X); }); foreachCard((c) => { c.trigger(STType.onBoost, source, X); }); return(this); }
// if card is shown before // then it has format X, where X - is its id // otherwise // card has format <cY>, where Y - index in its // current place string cardView(SCard card, int p) { //return isVisible(card, p) || card.host == p ? // String.Format("[id={0}]", card.id.ToString()) // : String.Format("[c{0}]", card.game.cards.select(SFilter.located(card.location.place), SFilter.hostBy(card.host)).indexOf(card)); string place = String.Format("{0}st card in p{1}'s {2}", card.game.cards.select(SFilter.located(card.location.place), SFilter.hostBy(card.host)).indexOf(card), card.host, card.location); string id = isVisible(card, p)? String.Format("id={0} ", card.id) : ""; return(String.Format("{0}{1}", id, place)); }
// default copy with clear status and default basepower // remains all triggers // remains a host index // remains pointer to game // remains timer, resets _now param // has none place and none row public SCard defaultCopy() { SCard copy = new SCard(_name, _clan, _rarity, _power.defaultPower, _tags.ToArray()); copy._triggers = _triggers; copy._player = _player; copy._game = _game; copy._timer = _timer.defaultCopy(); return(copy); }
void viewAction(STType triggerType, SCard source, int param) { if (triggerType == STType.onDraw) { game.logger.show(this, this.host); } if (triggerType == STType.onDeploy) { game.logger.show(this); } }
public void hide(SCard card, int player = -1) { if (player < 0) { foreachPlayer((p) => { hide(card, p); }); return; } if (!isVisible(card, player)) { return; } _views[player].Remove(card.id); log(String.Format("unsh {0}", card.id)); }
public void show(SCard card, int player = -1) { if (player < 0) { foreachPlayer((p) => { show(card, p); }); return; } if (isVisible(card, player)) { return; } _views[player].Add(card.id, card.view()); log(String.Format("sh {0} <{1}>", cardView(card, player), card.name.ToString()), player); }
// damage all selected units by specified X // returns count of units died this way public SCards damage(int X, SCard source = null) { SCards banish = new SCards(); SCards dead = new SCards(); SCards armorLost = new SCards(); List <int> recived = new List <int>(); foreachCard((c) => { SHitResult hitResult = c.power.damage(X); recived.Add(hitResult.healthLost); if (hitResult.shouldBeDead) { (c.containsTag(STag.doomed)? banish : dead).addCard(c); } else if (hitResult.armorWasBroken) { armorLost.addCard(c); } }); // (using foreachCard of daed/armorLost) // move dead group to graveyard // trigger their deathwishes // if dead, but has doomed // move it to banish instead // and do not trigger deathwish // trigger all armorLost units // on armorlost triggers // rest non-dead and non-banished // trigger for damaged // then return all killed cards // killed = banished + dead foreachCard((c) => { int damagedFor = recived[_cards.IndexOf(c)]; if (!dead.contains(c) && !banish.contains(c) && damagedFor > 0) { c.trigger(STType.onDamaged, source, damagedFor); } if (armorLost.contains(c)) { c.trigger(STType.onArmorLost); } }); dead.move(SPlace.graveyard); banish.move(SPlace.banish); return(dead.addCards(banish)); }
void mulliganCard(SCard card) { // currently solving for Mulligan-problem // if you swap a card you will always // draw from deck the first card // with a different name // (if all deck has only theese names) // then drop it bool allSameName = _cards .select(SFilter.hostBy(card.host), SFilter.located(SPlace.deck)) .isAll(SFilter.withName(card.name)); var deck = _cards.select(SFilter.hostBy(card.host), SFilter.located(SPlace.deck)); // then select first or first // with different name // and move it yto your hand (allSameName ? deck.first() : deck.first(1, SFilter.mulliganName(card.name))) .move(SPlace.hand); }
public void trigger(STType triggerType, SCard source = null, int param = 0) { if (containsTrigger(triggerType)) { _triggers[triggerType](this, source, param); } // then show it to someone // or hide from someone viewAction(triggerType, source, param); // if a trigger from range 20..100 // then its a trigger, what will trigger // other cards with %OtherTrigger% case int triggerNum = (int)triggerType; if (triggerNum < 20 || triggerNum > 100) { return; } foreach (SCard otherCard in _game.cards.select(SFilter.inGame(), SFilter.otherThen(this)).cards) { otherCard.trigger((STType)(triggerNum + 100), this); } }
public bool isVisible(SCard card, int player) { return(_views[player].ContainsKey(card.id)); }
SCards deck(SCard playersCard) { return(deck(playersCard.host)); }
// shuffle a card from somewhere to a deck // puts it to deck // then put it to random position in deck public SCard shuffleCard(SCard card) { card.maybe.move(SPlace.deck); _cards.putRandom(_random, card, SFilter.hostBy(card.host), SFilter.located(SPlace.deck)); return(card); }
public bool Equals(SCard card) { return(_id == card._id); }
public SCards addCard(SCard card) { _cards.Add(card); return(this); }
public bool contains(SCard card) { return(_cards.Contains(card)); }
public void damage(SCard card, SCard source, int dmg) { logAction(card, source, dmg, "dmg"); }
public SCards putLast(SCard card, params CardPredicat[] filters) { int count = selectIndices(filters).Count; return(setCardIndex(card, count - 1, filters)); }
public static CardPredicat ally(SCard card) { return((c) => { return c.host == card.host; }); }
public static CardPredicat otherThen(SCard card) { return(otherThen(new SCards(card))); }
public SCards putRandom(Random shuffler, SCard card, params CardPredicat[] filters) { int count = selectIndices(filters).Count; return(setCardIndex(card, shuffler.Next(count), filters)); }
public SCards putFirst(SCard card, params CardPredicat[] filters) { return(setCardIndex(card, 0, filters)); }
public static CardPredicat enemy(SCard card) { return((c) => { return c.host != card.host; }); }
public SCards targetOneCard(SCard source, string requestString) { SRequestSelectOneCard request = new SRequestSelectOneCard(requestString, this, source); return(select(SFilter.hasId(source.game.players.solve(request, source.game.logger).value))); }
public void move(SCard card, SLocation moveTo) { foreachPlayer((p) => { log(String.Format("mv {0} {1}←{2} p{3}", cardView(card, p), moveTo, card.location, card.host), p); }); }
public SRequestSelectOneCard(string requestQestion, SCards cards, SCard source) : base(requestQestion, cards, source.host) { sourceId = source.id; }
void logAction(SCard card, SCard source, int dmg, string word) { foreachPlayer((p) => { log(String.Format("{3} {0}←{1} by {2}", cardView(card, p), cardView(source, p), dmg, word), p); }); }
public int indexOf(SCard card) { return(_cards.IndexOf(card)); }