예제 #1
0
    public BattleState Init()
    {
        var id     = 1;
        var heroes = Party.Heroes;

        memberNames       = new string[EnemyStartingIndex + enemies.Enemies.Length + 3];
        _uiTransformsById = new Dictionary <int, Transform>();
        _enemiesById      = new Dictionary <int, Enemy>();
        for (var i = 0; i < enemies.Enemies.Length; i++)
        {
            id++;
            _enemiesById[id]      = enemies.Enemies[i];
            _uiTransformsById[id] = enemies.EnemyUiPositions[i];
            memberNames[id]       = enemies.Enemies[i].name;
        }

        _heroesById = new Dictionary <int, Hero>();
        for (var i = 0; i < 3; i++)
        {
            id++;
            _heroesById[id]       = heroes[i];
            _uiTransformsById[id] = partyArea.UiPositions[i];
            memberNames[id]       = heroes[i].name;
        }

        _membersById = _heroesById.Select(h => new Member(h.Key, h.Value.name, h.Value.ClassName.Value, TeamType.Party, h.Value.Stats))
                       .Concat(_enemiesById.Select(e => e.Value.AsMember(e.Key)))
                       .ToDictionary(x => x.Id, x => x);

        uiPositions = _uiTransformsById.Values.Select(x => x.position).ToArray();

        BattleLog.Write("Finished Battle State Init");
        return(this);
    }
    public IEnumerator Begin()
    {
        BattleLog.Write($"Card Resolution Began");
        yield return(ui.BeginResolutionPhase());

        ResolveNext();
    }
예제 #3
0
    private void SetupEnemyEncounter()
    {
        BattleLog.Write("Setting Up Enemies");
        if (state.HasCustomEnemyEncounter)
        {
            BattleLog.Write("Setting Up Custom Encounter");
            state.SetupEnemyEncounter();
        }

        if (enemyArea.Enemies.Length == 0)
        {
            BattleLog.Write("Setting Up Fallback Random Encounter");
            enemyArea = enemyArea.Initialized(encounterBuilder.Generate(3));
        }

        foreach (var enemy in enemyArea.Enemies)
        {
            if (!enemy.IsReadyForPlay)
            {
                throw new Exception($"{enemy.Name}'s is not ready for play.");
            }
            if (enemy.Deck.Cards.All(c => c.Cost.Amount > 0))
            {
                throw new Exception($"{enemy.Name}'s Deck does not contain a 0-Cost Card.");
            }
        }
    }
예제 #4
0
    private IEnumerator AwaitAnimationFinish(BattleVFX f)
    {
        yield return(new WaitForSeconds(f.DurationSeconds));

        BattleLog.Write($"Finished {f.EffectName} in {f.DurationSeconds} seconds.");
        Message.Publish(new Finished <BattleEffectAnimationRequested>());
    }
예제 #5
0
 private void LogProcessStep(string message)
 {
     if (logProcessSteps)
     {
         BattleLog.Write(message);
     }
 }
예제 #6
0
    public static void Apply(EffectData effectData, EffectContext ctx)
    {
        var effect = Create(effectData);

        BattleLog.Write($"Applying Effect of {effectData.EffectType} to {ctx.Target.MembersDescriptions()}");
        effect.Apply(ctx);
    }
    private void StartResolvingOneCard(IPlayedCard played)
    {
        BattleLog.Write($"Began resolving {played.Card.Name}");
        if (physicalZone.Count == 0)
        {
            Log.Info($"Weird Physical Zone Draw bug.");
        }
        else
        {
            physicalZone.DrawOneCard();
        }

        var card = played.Card;

        if (card.Owner.IsStunnedForCard())
        {
            BattleLog.Write($"{card.Owner.Name} was stunned, so {card.Name} does not resolve.");
            card.Owner.Apply(m => m.ApplyTemporaryAdditive(AdjustedStats.CreateIndefinite(new StatAddends().With(TemporalStatType.CardStun, -1), true)));
            WrapupCard(played, card);
            Message.Publish(new CardResolutionFinished());
        }
        else
        {
            AllConditions.InitCardPlaying(battleState.GetSnapshot());
            played.Perform();
            WrapupCard(played, card);
        }
    }
예제 #8
0
    public List <Enemy> Generate(int difficulty)
    {
        BattleLog.Write($"Started generating encounter of difficulty {difficulty}");

        var currentDifficulty        = 0;
        var numRemainingMustIncludes = numMustIncludes;
        var enemies = new List <Enemy>();

        while (numRemainingMustIncludes > 0)
        {
            var nextEnemy = mustIncludePossibilities.Random();
            enemies.Add(nextEnemy);
            BattleLog.Write($"Added \"Must Include\" {nextEnemy.Name} to Encounter");
            numRemainingMustIncludes--;
            currentDifficulty = currentDifficulty + Math.Max(nextEnemy.PowerLevel, 1);
        }

        while (currentDifficulty < difficulty && enemies.Count < 7)
        {
            var maximum   = difficulty - currentDifficulty;
            var nextEnemy = possible.Where(
                enemy => enemy.PowerLevel <= maximum
                ).Random();
            enemies.Add(nextEnemy);
            BattleLog.Write($"Added {nextEnemy.Name} to Encounter");
            currentDifficulty = currentDifficulty + Math.Max(nextEnemy.PowerLevel, 1);
        }

        BattleLog.Write("Finished generating encounter");
        return(enemies);
    }
예제 #9
0
    /**
     * @todo #361:30min We sdhould be able to chain effects conditionally, as in MarkOfSalvation paladin card.
     */

    public static void Apply(EffectData effectData, Member source, Target target)
    {
        var effect = Create(effectData);

        BattleLog.Write($"Applying Effect of {effectData.EffectType} to {target.Members} members");
        effect.Apply(source, target);
        target.Members.ForEach(m => BattleEvent.Publish(new MemberStateChanged(m)));
    }
예제 #10
0
    public IEnumerator ResolveNext(float delay)
    {
        BattleLog.Write("Requested Resolve Next Card");
        isResolving = true;
        var move = moves[0];

        moves = moves.Skip(1).ToList();
        yield return(new WaitForSeconds(delay));

        StartResolvingOneCard(move);
    }
예제 #11
0
    public void CleanupIfNeeded()
    {
        if (!NeedsCleanup)
        {
            return;
        }

        EnemyArea.Clear();
        needsCleanup = false;
        BattleLog.Write("Finished Battle State Cleanup");
    }
예제 #12
0
 public void Add(IPlayedCard played)
 {
     moves.Add(played);
     physicalZone.PutOnBottom(played.Card);
     played.Member.Apply(m =>
     {
         m.Lose(played.Spent);
         m.Gain(played.Gained);
     });
     BattleLog.Write($"{played.Member.Name} Played {played.Card.Name} - Spent {played.Spent} - Gained {played.Gained}");
 }
예제 #13
0
 private void ResolveUnconsciousMember(Member member, BattleState state)
 {
     if (member.TeamType == TeamType.Enemies)
     {
         state.AddRewardCredits(state.GetEnemyById(member.Id).RewardCredits);
     }
     else
     {
         BattleLog.Write($"{member.Name} - {member.Id} is unconscious");
     }
     Message.Publish(new MemberUnconscious(member));
 }
    public void Confirm()
    {
        if (!CanConfirm)
        {
            return;
        }

        _confirmRequested = false;
        playArea.Clear();
        BattleLog.Write("Player Confirmed Turn");
        Message.Publish(new PlayerTurnConfirmed());
    }
예제 #15
0
    public void Add(PlayedCard played)
    {
        if (_isResolving)
        {
            return;
        }

        moves.Add(played);
        physicalZone.PutOnBottom(played.Card);
        played.Member.Apply(m => m.Pay(played.Card.Cost));
        BattleLog.Write($"{played.Member.Name} Played {played.Card.name}");
    }
예제 #16
0
    private IEnumerator ResolveAll(float delay)
    {
        _isResolving = true;
        BattleLog.Write($"Num Cards To Resolve: {moves.Count}");
        yield return(new WaitForSeconds(delay));

        foreach (var move in moves.ToList())
        {
            yield return(ResolveOneCard(move));

            yield return(new WaitForSeconds(1.1f));
        }

        _isResolving = false;
        moves.Clear();
        onFinished.Publish();
    }
예제 #17
0
    private IEnumerator ResolveOneCard(PlayedCard played)
    {
        BattleLog.Write($"Began resolving {played.Card.Name}");
        if (physicalZone.Count == 0)
        {
            Debug.Log($"Weird Physical Zone Draw bug.");
            yield break;
        }
        var card = physicalZone.DrawOneCard();

        played.Perform();
        LastPlayed = played;
        if (played.Member.TeamType.Equals(TeamType.Party))
        {
            playedDiscardZone.PutOnBottom(card);
        }
        onCardResolved.Publish();
    }
예제 #18
0
    public BattleState FinishSetup()
    {
        var id = 0;

        memberNames       = new string[EnemyStartingIndex + enemies.Enemies.Length + 3];
        _uiTransformsById = new Dictionary <int, Transform>();

        var heroes = Party.Heroes;

        _heroesById = new Dictionary <int, Hero>();
        for (var i = 0; i < Party.BaseHeroes.Length; i++)
        {
            id++;
            _heroesById[id]       = heroes[i];
            _uiTransformsById[id] = partyArea.UiPositions[i];
            memberNames[id]       = heroes[i].Character.Name;
        }

        id           = EnemyStartingIndex - 1;
        _enemiesById = new Dictionary <int, Enemy>();
        for (var i = 0; i < enemies.Enemies.Length; i++)
        {
            id++;
            _enemiesById[id]      = enemies.Enemies[i];
            _uiTransformsById[id] = enemies.EnemyUiPositions[i];
            memberNames[id]       = enemies.Enemies[i].name;
        }

        _membersById = _heroesById.Select(m => m.Value.AsMember(m.Key))
                       .Concat(_enemiesById.Select(e => e.Value.AsMember(e.Key)))
                       .ToDictionary(x => x.Id, x => x);

        _playerState = new PlayerState();

        _numberOfRecyclesRemainingThisTurn = _playerState.CurrentStats.CardCycles();
        rewardCredits       = 0;
        rewardCards         = new CardType[0];
        needsCleanup        = true;
        _queuedEffects      = new Queue <Effect>();
        _unconsciousMembers = new Dictionary <int, Member>();

        BattleLog.Write("Finished Battle State Init");
        return(this);
    }
예제 #19
0
    public void RemoveLastPlayedCard()
    {
        if (moves.None() || isResolving)
        {
            return;
        }

        var played = moves.Last();

        BattleLog.Write($"Canceled playing {played.Card.Name}");
        Message.Publish(new PlayerCardCanceled());
        moves.RemoveAt(moves.Count - 1);
        var card = physicalZone.Take(physicalZone.Count - 1);

        playerPlayArea.Take(playerPlayArea.Count - 1);
        playerHand.PutOnBottom(card);

        played.Member.Apply(m => m.LoseResource(played.Gained.ResourceType, played.Gained.Amount));
        played.Member.Apply(m => m.GainResource(played.Spent.ResourceType, played.Spent.Amount));
    }
예제 #20
0
 public void Apply(EffectContext ctx)
 {
     ctx.Target.Members.ForEach(m =>
     {
         var amount = Mathf.CeilToInt(_damage.Calculate(ctx.Source, m) * m.State.Damagability());
         if (m.State.Damagability() < 0.01)
         {
             BattleLog.Write($"{m.Name} is Invincible");
         }
         else if (amount < 1)
         {
             BattleLog.Write($"Dealing {amount} to {m.Name}");
         }
         else
         {
             BattleLog.Write($"Dealing {amount} to {m.Name}");
         }
         m.State.TakeDamage(amount);
     });
 }
예제 #21
0
    protected override void Execute(CharacterAnimationRequested e)
    {
        if (!state.IsHero(e.MemberId))
        {
            return;
        }

        var hero     = state.GetHeroById(e.MemberId);
        var animator = _animators[hero];

        if (animator == null)
        {
            Debug.LogWarning($"No Animator found for {state.GetHeroById(e.MemberId).Name}");
        }
        else
        {
            StartCoroutine(animator.PlayAnimationUntilFinished(e.Animation, elapsed =>
            {
                BattleLog.Write($"Finished {e.Animation} Animation in {elapsed} seconds.");
                Message.Publish(new Finished <CharacterAnimationRequested>());
            }));
        }
    }
예제 #22
0
    public void ExpirePlayedCards(Func <IPlayedCard, bool> condition)
    {
        var movesCopy = moves.ToArray();

        for (var i = movesCopy.Length - 1; i > -1; i--)
        {
            var played = movesCopy[i];
            if (!condition(played))
            {
                continue;
            }

            BattleLog.Write($"Expired played card {played.Card.Name} by {played.Member.Name}");
            if (moves.Count > i)
            {
                moves.RemoveAt(i);
            }
            physicalZone.Take(i);
            if (played.Member.TeamType == TeamType.Party)
            {
                playerHand.PutOnBottom(playerPlayArea.Take(i));
            }
        }
    }
예제 #23
0
 public void Resolve(MonoBehaviour host, float delay)
 {
     BattleLog.Write($"Card Resolution Began");
     host.StartCoroutine(ResolveAll(delay));
 }