public override void ModifyRolledAbility(BattleSide side, bool success, System.Random dice)
 {
     if (applyToSelf)
     {
         SwitchToSelfEffect(side);
     }
 }
Example #2
0
 private BattleCharacter Build(BattleSide loyalty, StartingStats stats)
 {
     return(BattleCharacter.Create(loyalty,
                                   _builder.WithName(Guid.NewGuid().ToString().Substring(0, 7))
                                   .WithStats(stats)
                                   .Build()));
 }
Example #3
0
 public void ApplyPostResolveEffects(BattleSide side, Monster target, System.Random dice)
 {
     if (successfulSpecial != null)
     {
         successfulSpecial.ApplyPostResolveEffects(side, target, dice);
     }
 }
Example #4
0
 public void UpdateHealth(BattleSide source)
 {
     for (int i = 0; i < list.Widgets.Count; i++)
     {
         list.Widgets[i].SetHealth(source.GetHealthRatio(i));
     }
 }
    public override void ApplyPreResolveEffects(BattleSide side, Monster target, System.Random dice)
    {
        effectToInflict.ApplyTo(target);

        if (effectToInflict is ElementShiftStatusEffect)
        {
            target.currentElement = side.selectedAbility.element;
        }
    }
Example #6
0
 void OnTriggerStay(Collider other)
 {
     if (other.tag == "Unit")
     {
         if (other.GetComponent<Unit>().Type == UnitType.Cruiser)
         {
             ContestedBy = other.GetComponent<Unit>().BattleSide;
         }
     }
 }
Example #7
0
    public virtual bool TryPersistAtEndOfRound(BattleSide side, System.Random dice)
    {
        if (dice.NextDouble() < chanceToWearOff)
        {
            RemoveFrom(side.currentMonster);
            return(false);
        }

        return(true);
    }
Example #8
0
    public void ApplyPreResolveEffects(BattleSide side, Monster target, System.Random dice)
    {
        if (successfulSpecial != null)
        {
            successfulSpecial.ApplyPreResolveEffects(side, target, dice);
        }

        statChanges.health = GetHealthChangeWithVulnerability(side, target);

        target.currentStats += statChanges;
    }
Example #9
0
 public override void ModifyRolledAbility(BattleSide side, bool success, System.Random dice)
 {
     if (success)
     {
         side.effectOnOpponent.statChanges.health *= damageMultiplierOnSuccess;
     }
     else
     {
         side.effectOnOpponent.statChanges.health *= damageMultiplierOnFail;
     }
 }
 private BattleCharacter(ILog log, string name, ICharStats stats, BattleSide loyalty, BattleDeck deck)
 {
     _log     = log;
     Name     = name;
     Hand     = new BattleHand(() => CurrentActionPoints, () => CurrentEnergy);
     _stats   = new BattleCharacterStats(stats);
     _effects = new BattleCharacterStatusEffects();
     Loyalty  = loyalty;
     Deck     = deck;
     DrawCards(_stats[BattleStat.StartingCards]);
 }
Example #11
0
    public override void ApplyPostResolveEffects(BattleSide side, Monster target, System.Random dice)
    {
        if (clearStatusEffect && target.status != null)
        {
            target.status.RemoveFrom(target);
        }

        foreach (var stat in statsToRestore)
        {
            target.currentStats[stat] = target.species.baseStats[stat];
        }
    }
Example #12
0
    public float GetHealthChangeWithVulnerability(BattleSide side, Monster target)
    {
        if (statChanges.health >= 0)
        {
            return(statChanges.health);
        }

        float vulnerability = (100f / target.currentStats.defense);

        vulnerability *= ElementCollection.Instance.GetAttackMultiplier(side.selectedAbility.element, target.currentElement);
        return(statChanges.health * vulnerability);
    }
Example #13
0
    public override void OnPostAbilitiesRolled(BattleSide side, Monster target, System.Random dice)
    {
        // No-op if both monsters use Copycat on each other. Nuke the matching effect.
        if (side.opponent.effectOnSelf.successfulSpecial is CopycatEffect)
        {
            side.opponent.effectOnSelf.successfulSpecial = null;
            return;
        }

        // Roll the opponent's ability as our own, but keep our stamina cost.
        side.opponent.selectedAbility.Roll(side, dice);
    }
Example #14
0
        public void Remove(ICombatGroup group, BattleSide side, ReportState state)
        {
            lock (battleLock)
            {
                // Remove from appropriate combat list
                if (side == BattleSide.Attack)
                {
                    if (!Attackers.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= AttackerGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= AttackerGroupOnCombatObjectRemoved;
                }
                else
                {
                    if (!Defenders.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= DefenderGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= DefenderGroupOnCombatObjectRemoved;
                }

                // If battle hasnt started then dont worry about cleaning anything up since nothing has happened to these objects
                if (!BattleStarted)
                {
                    return;
                }

                // Snap a report of exit
                BattleReport.WriteReportGroup(group, side == BattleSide.Attack, state);

                // Tell objects to exit from battle
                foreach (var co in group.Where(co => !co.Disposed))
                {
                    co.ExitBattle();
                }

                // Send exit events
                if (side == BattleSide.Attack)
                {
                    WithdrawAttacker(this, group);
                }
                else
                {
                    WithdrawDefender(this, group);
                }
            }
        }
Example #15
0
        public void Add(ICombatGroup combatGroup, BattleSide battleSide, bool allowReportAccess)
        {
            bool isAttacker = battleSide == BattleSide.Attack;

            lock (battleLock)
            {
                if (GetCombatGroup(combatGroup.Id) != null)
                {
                    throw new Exception(
                              string.Format("Trying to add a group to battle {0} with id {1} that already exists",
                                            BattleId,
                                            combatGroup.Id));
                }

                (battleSide == BattleSide.Attack ? Attackers : Defenders).Add(combatGroup);

                if (isAttacker)
                {
                    combatGroup.CombatObjectAdded   += AttackerGroupOnCombatObjectAdded;
                    combatGroup.CombatObjectRemoved += AttackerGroupOnCombatObjectRemoved;
                }
                else
                {
                    combatGroup.CombatObjectAdded   += DefenderGroupOnCombatObjectAdded;
                    combatGroup.CombatObjectRemoved += DefenderGroupOnCombatObjectRemoved;
                }

                if (BattleStarted)
                {
                    BattleReport.WriteReportGroup(combatGroup, isAttacker, ReportState.Entering);

                    if (isAttacker)
                    {
                        ReinforceAttacker(this, combatGroup);
                    }
                    else
                    {
                        ReinforceDefender(this, combatGroup);
                    }
                }

                if (allowReportAccess)
                {
                    BattleReport.AddAccess(combatGroup, battleSide);
                }

                if (combatGroup.Tribe != null)
                {
                    BattleReport.AddTribeToBattle(combatGroup.Tribe, battleSide);
                }
            }
        }
Example #16
0
        public void DbLoaderAddToCombatList(ICombatGroup group, BattleSide side)
        {
            if (side == BattleSide.Defense)
            {
                Defenders.Add(group, false);
            }
            else
            {
                Attackers.Add(group, false);
            }

            groupIdGen.Set(group.Id);
        }
Example #17
0
    public override bool TryPersistAtEndOfRound(BattleSide side, System.Random dice)
    {
        if (!base.TryPersistAtEndOfRound(side, dice))
        {
            return(false);
        }

        if (repeatEveryRound)
        {
            ChangeStat(side.currentMonster);
        }

        return(true);
    }
Example #18
0
    public override void ModifyRolledAbility(BattleSide side, bool success, System.Random dice)
    {
        if (!success)
        {
            return;
        }

        if (applyToSelf)
        {
            side.effectOnSelf.statChanges[statToModify] = GetChangeAmount(side.currentMonster);
        }
        else
        {
            side.effectOnOpponent.statChanges[statToModify] = GetChangeAmount(side.opponent.currentMonster);
        }
    }
Example #19
0
    public void Roll(BattleSide side, System.Random dice)
    {
        side.effectOnOpponent = default;
        side.effectOnSelf     = default;

        side.selectedAbility = this;
        side.effectOnOpponent.statChanges.health = -GetDamage(side.currentMonster, dice);

        if (special != null)
        {
            bool success = GetSpecialSuccess(side.currentMonster, dice);

            if (success)
            {
                side.effectOnOpponent.successfulSpecial = special;
            }

            special.ModifyRolledAbility(side, success, dice);
        }
    }
Example #20
0
    public Unit FindClosestUnit(Vector3 gridPos, BattleSide side)
    {
        Unit unitToReturn = null;
        Vector3 closestPos = -Vector3.one;

        foreach (var unit in GameObject.FindGameObjectsWithTag("Unit")) {
            var unitComp = unit.GetComponent<Unit>();

            if (unitComp.BattleSide == side) {
                var unitGridPos = WorldToGrid(unit.transform.position);

                if (closestPos == -Vector3.one || (unitGridPos - gridPos).sqrMagnitude < (closestPos - gridPos).sqrMagnitude) {
                    closestPos = unitGridPos;
                    unitToReturn = unitComp;
                }
            }
        }

        return unitToReturn;
    }
Example #21
0
    public override void OnPostAbilitiesRolled(BattleSide side, Monster target, System.Random dice)
    {
        // Can't redirect effects on yourself.
        if (target == side.currentMonster)
        {
            return;
        }

        foreach (var stat in Monster.STATS)
        {
            switch (ImpactOnStat(stat))
            {
            case Behaviour.Block:
                side.opponent.effectOnOpponent.statChanges[stat] = 0;
                break;

            case Behaviour.Reflect:
                side.opponent.effectOnSelf.statChanges[stat]    += side.opponent.effectOnOpponent.statChanges[stat];
                side.opponent.effectOnOpponent.statChanges[stat] = 0;
                break;
            }
        }

        switch (specialImpacts)
        {
        case Behaviour.Block:
            side.opponent.effectOnOpponent.successfulSpecial = null;
            break;

        case Behaviour.Reflect:
            if (side.opponent.effectOnOpponent.successfulSpecial != null)
            {
                side.effectOnOpponent.successfulSpecial          = side.opponent.effectOnOpponent.successfulSpecial;
                side.opponent.effectOnOpponent.successfulSpecial = null;
            }
            break;
        }

        return;
    }
    public override bool TryModifyRolledAbilities(BattleSide side, System.Random dice)
    {
        float roll = (float)dice.NextDouble();

        if (roll < chanceOfNoAction)
        {
            side.effectOnOpponent = default;
            side.effectOnSelf     = default;
            return(true);
        }

        roll -= chanceOfNoAction;

        if (roll < chanceToAttackSelf)
        {
            side.effectOnSelf     = side.effectOnOpponent;
            side.effectOnOpponent = default;
            return(true);
        }

        return(false);
    }
        /// <summary>
        /// Add card to hand
        /// </summary>
        /// <param name="battleCard"></param>
        /// <param name="side"></param>
        public void AddCardToDeck(BattleCard battleCard, BattleSide side)
        {
            // Load Card
            var cardGameObject = (GameObject)Instantiate(
                Resources.Load("Prefabs/Card", typeof(GameObject)), new Vector3(), Quaternion.identity,
                _pull.transform
                );

            // Set Z was zero position
            cardGameObject.transform.localPosition = new Vector3(cardGameObject.transform.localRotation.x,
                                                                 cardGameObject.transform.localRotation.y, 0);
            // Init Card
            var cardView = cardGameObject.GetComponent <CardView>();

            cardView.Side = side;
            cardView.MainParenTransform = _placeholderParenTransform;
            cardView.PlaceholderParent  = _handTransform;
            cardView.Init(battleCard);
            cardView.CreatePlaceholder();
            cardGameObject.SetActive(false);
            InitDeckCount();
        }
Example #24
0
        /// <summary>
        /// Add trate to hand
        /// </summary>
        /// <param name="battleTrate"></param>
        /// <param name="side"></param>
        public void AddTrateToDeck(BattleTrate battleTrate, BattleSide side)
        {
            // Load Card
            var trateGameObject = (GameObject)Instantiate(
                Resources.Load("Prefabs/Trate", typeof(GameObject)), new Vector3(), Quaternion.identity,
                _pull.transform
                );

            // Set Z was zero position
            trateGameObject.transform.localPosition = new Vector3(trateGameObject.transform.localRotation.x,
                                                                  trateGameObject.transform.localRotation.y, 0);
            // Init Trate
            var trateView = trateGameObject.GetComponent <TrateView>();

//            trateView.CanDroppable = false;
            trateView.Side = side;
            trateView.MainParenTransform = _placeholderParenTransform;
            trateView.PlaceholderParent  = _handTransform;
            trateView.Init(battleTrate);
            trateView.CreatePlaceholder();
            trateGameObject.SetActive(false);
            InitDeckCount();
        }
Example #25
0
        public void SetupNewBattle(BattleSide side, Position position)
        {
            this.side     = side;
            this.position = position;

            actionDeck.Clear();

            foreach (ActionCardData cardData in staticData.possibleActionCards)
            {
                ActionCard card = new ActionCard();
                card.Init(cardData, this);
                actionDeck.Add(card);
            }

            foreach (ResultCardData cardData in staticData.possibleResultCards)
            {
                ResultCard card = new ResultCard();
                card.Init(cardData, this);
                resultDeck.Add(card);
            }

            atbGauge.Clear();
        }
Example #26
0
    public override void ApplyPreResolveEffects(BattleSide side, Monster target, System.Random dice)
    {
        float change = 0f;

        switch (source)
        {
        case Source.DamageTaken:
            change = -side.opponent.effectOnOpponent.GetHealthChangeWithVulnerability(side.opponent, target);
            break;

        case Source.DamageDealt:
            change = -side.effectOnOpponent.GetHealthChangeWithVulnerability(side, side.opponent.currentMonster);
            break;

        case Source.StaminaSpentByOpponent:
            change = side.opponent.staminaSpent;
            break;
        }

        change = amountToBuff * Mathf.Max(change, 0f);

        side.effectOnSelf.statChanges[statToBuff] += change;
    }
Example #27
0
 protected void SwitchToSelfEffect(BattleSide side)
 {
     side.effectOnSelf.successfulSpecial     = side.effectOnOpponent.successfulSpecial;
     side.effectOnOpponent.successfulSpecial = null;
 }
Example #28
0
 // Effects that need to look at the opponent's ability (to block/reflect/copy it) apply here.
 public abstract void OnPostAbilitiesRolled(BattleSide side, Monster target, System.Random dice);
Example #29
0
 // Effects that need to have the last say (like clearing a status effect) apply here.
 public virtual void ApplyPostResolveEffects(BattleSide side, Monster target, System.Random dice)
 {
 }
Example #30
0
 // Simple effects like miss/critical or stat effects apply here.
 // Effects that affect the user take this opportunity to swap to the "effectOnSelf" channel.
 public virtual void ModifyRolledAbility(BattleSide side, bool success, System.Random dice)
 {
 }
Example #31
0
 public virtual bool TryModifyRolledAbilities(BattleSide side, System.Random dice)
 {
     return(false);
 }
Example #32
0
 public ModifierEffect(BattleSide side, bool self)
 {
     this.side = side;
     this.self = self;
 }
Example #33
0
 void OnTriggerExit(Collider other)
 {
     ContestedBy = BattleSide.None;
 }