Example #1
0
        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);
        }
Example #2
0
 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);
 }
Example #3
0
        // 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));
        }
Example #4
0
        // 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);
        }
Example #5
0
 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);
     }
 }
Example #6
0
 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));
 }
Example #7
0
 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);
 }
Example #8
0
        // 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));
        }
Example #9
0
        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);
        }
Example #10
0
        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);
            }
        }
Example #11
0
 public bool isVisible(SCard card, int player)
 {
     return(_views[player].ContainsKey(card.id));
 }
Example #12
0
 SCards deck(SCard playersCard)
 {
     return(deck(playersCard.host));
 }
Example #13
0
 // 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);
 }
Example #14
0
 public bool Equals(SCard card)
 {
     return(_id == card._id);
 }
Example #15
0
 public SCards addCard(SCard card)
 {
     _cards.Add(card); return(this);
 }
Example #16
0
 public bool contains(SCard card)
 {
     return(_cards.Contains(card));
 }
Example #17
0
 public void damage(SCard card, SCard source, int dmg)
 {
     logAction(card, source, dmg, "dmg");
 }
Example #18
0
 public SCards putLast(SCard card, params CardPredicat[] filters)
 {
     int count = selectIndices(filters).Count; return(setCardIndex(card, count - 1, filters));
 }
Example #19
0
 public static CardPredicat ally(SCard card)
 {
     return((c) => { return c.host == card.host; });
 }
Example #20
0
 public static CardPredicat otherThen(SCard card)
 {
     return(otherThen(new SCards(card)));
 }
Example #21
0
 public SCards putRandom(Random shuffler, SCard card, params CardPredicat[] filters)
 {
     int count = selectIndices(filters).Count; return(setCardIndex(card, shuffler.Next(count), filters));
 }
Example #22
0
 public SCards putFirst(SCard card, params CardPredicat[] filters)
 {
     return(setCardIndex(card, 0, filters));
 }
Example #23
0
 public static CardPredicat enemy(SCard card)
 {
     return((c) => { return c.host != card.host; });
 }
Example #24
0
        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)));
        }
Example #25
0
 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); });
 }
Example #26
0
 public SRequestSelectOneCard(string requestQestion, SCards cards, SCard source) : base(requestQestion, cards, source.host)
 {
     sourceId = source.id;
 }
Example #27
0
 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); });
 }
Example #28
0
 public int indexOf(SCard card)
 {
     return(_cards.IndexOf(card));
 }