public void CheckTriggers(TriggerEvent evt, GameState gameState, List<WaitingTrigger> TriggersFound)
        {
            if(type.triggers.Count == 0)
                return;

            EffectContext context = new EffectContext(gameState, this, evt, null);
            foreach (TriggeredAbility ability in type.triggers)
            {
                if (ability.WillTrigger(evt.type, context))
                {
                    TriggersFound.Add(new WaitingTrigger(evt, ability, this, position));
                }
            }
        }
        public GameState(LevelScript levelScript)
        {
            this.levelScript = levelScript;
            spawnIndices = new List<int>();
            for (int Idx = this.levelScript.spawnPoint.Count; Idx > 0; --Idx)
            {
                spawnIndices.Add(0);
            }

            parentState = null;
            minions = new Dictionary<Point, Minion>();
            ongoingEffects = new Dictionary<Point, Ongoing>();
            resources = new Dictionary<ResourceType, int>();
            turnNumber = 1;
            playableCards = new HashSet<Card>();
            gameEndState = GameEndState.GameRunning;
            cardTextChanges = new Dictionary<Card, TextChanges>();

            levelScript.InitState(this);
        }
        public GameState(GameState parentState)
        {
            this.gameEndState = parentState.gameEndState;
            this.parentState = parentState;
            this.levelScript = parentState.levelScript;
            turnNumber = parentState.turnNumber;

            spawnIndices = new List<int>();
            foreach (int spawnIndex in parentState.spawnIndices)
            {
                spawnIndices.Add(spawnIndex);
            }

            minions = new Dictionary<Point, Minion>();
            foreach (KeyValuePair<Point, Minion> kv in parentState.minions)
            {
                Minion newP = new Minion(kv.Value);
                minions[newP.position] = newP;

                if (kv.Value == parentState.wizard)
                {
                    wizard = newP;
                }
            }
            UpdateSpellSets();

            ongoingEffects = new Dictionary<Point, Ongoing>();
            foreach (KeyValuePair<Point, Ongoing> kv in parentState.ongoingEffects)
            {
                ongoingEffects.Add(kv.Key, new Ongoing(kv.Value));
            }

            resources = new Dictionary<ResourceType, int>(parentState.resources);
            cardTextChanges = new Dictionary<Card, TextChanges>();
            foreach (KeyValuePair<Card, TextChanges> kv in parentState.cardTextChanges)
            {
                cardTextChanges.Add(kv.Key, kv.Value);
            }
            playableCards = new HashSet<Card>();
        }
 public MinionAnimationBatch(GameState initialState, float duration)
 {
     this.initialState = initialState;
     animations = new Dictionary<MinionId, MinionAnimationElement>();
     this.duration = new TimeSpan((long)(duration*1E7));
     this.elapsedTime = new TimeSpan(0);
 }
 public GameState GetGameStateOnSkip()
 {
     GameState result = new GameState(this);
     result.TurnEffects(new MinionAnimationSequence());
     return result;
 }
 public virtual void WhenDies(GameState gameState, Point position)
 {
 }
 public void InitState(GameState gameState)
 {
     gameState.GainResources(startingResources);
     gameState.wizard = gameState.CreateMinion(MinionType.get("wizard"), false, wizardPos);
 }
 public bool FinishedSpawning(GameState gameState)
 {
     return (spawns.Count+1 < gameState.turnNumber);
 }
 public MinionAnimationBatch AddBatch(GameState initialState, float duration)
 {
     MinionAnimationBatch newBatch = new MinionAnimationBatch(initialState, duration);
     batches.Add(newBatch);
     return newBatch;
 }
        public void TakeDamage(GameState gameState, int amount, DamageType type, Permanent attacker)
        {
            if (type != DamageType.lightning && type != DamageType.acid)
            {
                amount -= stats.armor;
            }

            if (amount <= 0)
                return;

            if (stats.health > 0)
            {
                if (type == DamageType.fire)
                {
                    if (stats.hasKeyword(Keyword.fireproof))
                        return;

                    if (stats.hasKeyword(Keyword.fireform))
                    {
                        // fireform creatures are healed by fire
                        Heal(amount);
                        return;
                    }

                    if (stats.hasKeyword(Keyword.flammable))
                    {
                        permanentStats.burningNextTurn += amount;
                    }
                }

                if (type == DamageType.acid)
                {
                    stats.armor -= amount;
                    if (stats.armor < 0)
                    {
                        stats.health += stats.armor; // reduce health by the (negative) armor
                        stats.armor = 0;
                    }
                    permanentStats.armor = stats.armor;
                }
                else
                {
                    stats.health -= amount;
                }

                if (stats.health < 0)
                    stats.health = 0;
                permanentStats.health = stats.health;
                if (stats.health <= 0)
                {
                    gameState.Destroyed(position, attacker);
                }

                gameState.HandleTriggers(new TriggerEvent(TriggerType.onDamage, attacker, this));
            }
        }
        public bool CheckAttacks(GameState gameState, int bonusDamage, MinionAnimationBatch attack, MinionAnimationBatch recover, MinionAnimationSequence animation)
        {
            if (deleted || (stats.attack+bonusDamage) <= 0 || !gameState.CanPayCost(mtype.attackCost))
                return false;

            if (attack.HasAnimation(this))
                return false;

            Point[] attackOffsets = gameState.getOffsetsForRange(stats.range);

            if ((stats.attack+bonusDamage) > 0)
            {
                foreach (Point p in attackOffsets)
                {
                    if (CheckAttack(gameState, bonusDamage, new Point(position.X + p.X, position.Y + p.Y), attack, recover))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        public bool CheckAttack(GameState gameState, int bonusDamage, Point attackPos, MinionAnimationBatch attack, MinionAnimationBatch recover)
        {
            if (deleted)
                return false;

            Minion m = gameState.getMinionAt(attackPos);
            if (m == null || isEnemy == m.isEnemy || m.stats.health <= 0 || m.stats.hasKeyword(Keyword.attackproof))
                return false;

            Attack(gameState, m, bonusDamage, attack, recover);
            return true;
        }
        public void Attack(GameState gameState, Minion target, int bonusDamage, MinionAnimationBatch attackAnim, MinionAnimationBatch recoverAnim)
        {
            if (deleted)
                return;

            gameState.PayCost(mtype.attackCost);

            Vector2 basePos = drawPos;
            Vector2 targetPos = target.drawPos;
            targetPos = new Vector2(targetPos.X, targetPos.Y+target.type.texture.Height - type.texture.Height);
            Vector2 attackPos = basePos + (targetPos - basePos) * 0.5f;
            attackAnim.AddAnimation(this, basePos, attackPos);
            recoverAnim.AddAnimation(this, attackPos, basePos);

            DamageType damageType =
                stats.hasKeyword(Keyword.corrosive)? DamageType.acid:
                stats.hasKeyword(Keyword.fireform)? DamageType.fire:
                DamageType.attack;

            gameState.HandleTriggers(new TriggerEvent(TriggerType.onAttack, this, target));
            target.TakeDamage(gameState, stats.attack+bonusDamage, damageType, this);
        }
        public override void ApplyOngoingLateEffects(GameState gameState, MinionAnimationSequence animation)
        {
            base.ApplyOngoingLateEffects(gameState, animation);

            TakeDamage(gameState, permanentStats.burning, DamageType.fire, this);
            permanentStats.burning = permanentStats.burningNextTurn;
            permanentStats.burningNextTurn = 0;
        }
 public void Draw(SpriteBatch spriteBatch, GameState gameStateOnSkip)
 {
     initialState.Draw(spriteBatch, gameStateOnSkip, this);
 }
        public void Update(GameState playState, UISelectionState selectionState)
        {
            selectedCardUpgrade = false;

            if (cardList == null || !rect.Contains(Game1.inputState.MousePos))
            {
                selectedCardIdx = -1;
            }
            else
            {
                int cardListIdx = 0;
                int cardBottom = rect.Top;

                foreach (Card baseCard in cardList)
                {
                    if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet))
                    {
                        cardListIdx++;
                        continue;
                    }

                    Card c = GetUpgrade(baseCard);

                    cardBottom += cardHeight;

                    if (Game1.inputState.MousePos.Y < cardBottom)
                    {
                        selectedCardIdx = cardListIdx;
                        if ( Game1.inputState.MousePos.X > rect.Right - 16 && CanUpgrade(baseCard) )
                        {
                            selectedCardUpgrade = true;
                        }
                        break;
                    }
                    cardListIdx++;
                }

                if (Game1.inputState.MousePos.Y > cardBottom)
                {
                    selectedCardIdx = -1;
                }
            }

            if (Game1.inputState.WasMouseLeftJustPressed())
            {
                if (selectedCardIdx != -1)
                {
                    selectionState.ClickedCard(cardList[selectedCardIdx], selectedCardUpgrade);
                }
                else
                {
                    selectionState.ClickedPosition();
                }
            }
        }
 public void SetInitialGameState(GameState state)
 {
     initialState = state;
 }
 public UISelectionState(GameState playState)
 {
     this.playState = playState;
 }
 public void Draw(SpriteBatch spriteBatch, GameState gameStateOnSkip)
 {
     MinionAnimationBatch batch = batches[currentBatch];
     batch.Draw(spriteBatch, gameStateOnSkip);
 }
 public bool TryPlay(Game1 game, GameState gameState)
 {
     if (playing != null)
     {
         if (playTargetCard != null)
         {
             game.PlayTurn(playing, gameState.wizard, TriggerItem.create(playTargetCard));
             return true;
         }
         else
         {
             game.PlayTurn(playing, gameState.wizard, gameState.getItemAt(playPosition));
             return true;
         }
     }
     return false;
 }
 public void InitState(GameState gameState)
 {
     levelType.InitState(gameState);
     foreach (KeyValuePair<MinionType, Point> kv in scenery)
     {
         gameState.CreateMinion(kv.Key, false, kv.Value);
     }
     MinionAnimationSequence anim = new MinionAnimationSequence();
     foreach (KeyValuePair<Card, Point> kv in ongoingEffects)
     {
         gameState.PlayCard(kv.Key, null, TriggerItem.create(kv.Value), anim);
     }
 }
        public void Draw(SpriteBatch spriteBatch, GameState playState, UISelectionState selectionState)
        {
            int cardListIdx = 0;
            int visibleCardIdx = 0;
            //            int selectSize = 5;

            if (cardList == null)
                return;

            foreach (Card baseCard in cardList)
            {
                if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet))
                {
                    cardListIdx++;
                    continue;
                }

                Card c = GetUpgrade(baseCard);
                bool canUpgrade = CanUpgrade(baseCard);

                CardState state = selectionState.GetCardState(c);

                Rectangle frameRect = new Rectangle(rect.Left, rect.Top + visibleCardIdx * cardHeight, c.frameTexture.Width - (canUpgrade ? 16 : 0), cardHeight);

                c.Draw(spriteBatch, frameRect, state, (selectedCardIdx == cardListIdx));

                if (canUpgrade)
                {
                    Rectangle upgradeRect = new Rectangle(rect.Right-16, rect.Top + visibleCardIdx * cardHeight, 16, cardHeight);
                    bool selectedThisUpgrade = selectedCardUpgrade && (selectedCardIdx == cardListIdx);
                    spriteBatch.Draw(Game1.upgradeTexture, upgradeRect, selectedThisUpgrade? Color.Red: Color.White);
                }

                if (selectedCardIdx == cardListIdx && !selectedCardUpgrade)
                {
                    Card baseSelectedCard = cardList[selectedCardIdx];
                    Card selectedCard = GetUpgrade(baseSelectedCard);
                    TextChanges changes = playState.getTextChanges(baseSelectedCard);

                    Vector2 tooltipPos;
                    Tooltip.Align alignment;
                    if(rect.Left == 0)
                    {
                        tooltipPos = new Vector2(rect.Left + selectedCard.frameTexture.Width, rect.Top + visibleCardIdx * cardHeight);
                        alignment = Tooltip.Align.LEFT;
                    }
                    else
                    {
                        tooltipPos = new Vector2(rect.Left, rect.Top + visibleCardIdx * cardHeight);
                        alignment = Tooltip.Align.RIGHT;
                    }

                    Tooltip.DrawTooltip(spriteBatch, Game1.font, Game1.tooltipBG, changes.Apply(selectedCard.description), tooltipPos, alignment);
                }

                visibleCardIdx++;
                cardListIdx++;
            }
        }
 public void Apply(GameState gameState, MinionAnimationBatch moveAnim)
 {
     for (int Idx = 0; Idx < spawns.Count; ++Idx)
     {
         int index = gameState.spawnIndices[Idx];
         if (index < spawns[Idx].Count)
         {
             MinionType spawntype = spawns[Idx][index];
             if (spawntype != null)
             {
                 if (gameState.getMinionAt(levelType.spawnPoint[Idx]) == null)
                 {
                     gameState.CreateEnemy(spawntype, levelType.spawnPoint[Idx], moveAnim);
                     gameState.spawnIndices[Idx]++;
                 }
             }
             else
             {
                 gameState.spawnIndices[Idx]++;
             }
         }
     }
 }
Beispiel #24
0
        public void PlayTurn(Card c, Minion caster, TriggerItem target)
        {
            if (c.effect != null && c.effect is Effect_Rewind)
            {
                if (gameStates.Count <= 1)
                    return;
                // rewind isn't really a spell like everything else
                gameStates.RemoveAt(gameStates.Count - 1);
                gameStateOnSkip = gameStates.Last().GetGameStateOnSkip();
                selectionState = new UISelectionState(gameStates.Last());
            }
            else
            {
                GameState oldGameState = gameStates.Last();
                if (oldGameState.CanPlayCard(c, target))
                {
                    nextGameState = new GameState(gameStates.Last());

                    animation.Clear();
                    if (caster == null)
                        caster = nextGameState.wizard;

                    nextGameState.PlayCard(c, caster, nextGameState.Adapt(target), animation);
                    nextGameState.TurnEffects(animation);

                    gameStateOnSkip = nextGameState.GetGameStateOnSkip();
                }
            }
        }
 public virtual void ApplyOngoingLateEffects(GameState gameState, MinionAnimationSequence animation)
 {
     gameState.ApplyEffect(type.ongoing_late, new EffectContext(gameState, this, null, animation));
 }
Beispiel #26
0
 public void StartLevel(LevelState levelState)
 {
     currentLevel = levelState;
     showingWinScreen = null;
     if (levelState != null)
     {
         gameStates = new List<GameState>();
         GameState newState = new GameState(levelState.script);
         gameStateOnSkip = newState.GetGameStateOnSkip();
         gameStates.Add(newState);
         selectionState = new UISelectionState(newState);
     }
 }
 public bool TryPayUpkeep(GameState gameState)
 {
     if (gameState.CanPayCost(type.upkeep))
     {
         gameState.PayCost(type.upkeep);
         return true;
     }
     else
     {
         return false;
     }
 }
        public void Draw(SpriteBatch spriteBatch, GameState gameStateOnSkip, MinionAnimationBatch animation)
        {
            spriteBatch.DrawString(Game1.font, "Turn " + turnNumber, new Vector2(200, 20), Color.White);
            DrawResources(spriteBatch, resources, gameStateOnSkip.resources, new Vector2(250, 20));

            for (int X = 0; X < levelScript.levelSize.X; X++)
            {
                for (int Y = 0; Y < levelScript.levelSize.Y; Y++)
                {
                    Point pos = new Point(X, Y);

                    if (ongoingEffects.ContainsKey(pos))
                        ongoingEffects[pos].Draw(spriteBatch, animation);

                    if (minions.ContainsKey(pos))
                        minions[pos].Draw(spriteBatch, animation);
                }
            }
        }