Implement Triggers and Scarring
This commit is contained in:
parent
cbc8c8b6cd
commit
265c24ea1c
18 changed files with 247 additions and 5 deletions
|
|
@ -103,6 +103,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
|
||||
private void StartHeroTurn() {
|
||||
this.heroTurn = true;
|
||||
|
||||
this.damageTriggers.RemoveAll(t => t.Expiration == TriggerExpiration.StartOfNextHeroTurn);
|
||||
|
||||
this.energy = this.maxEnergy;
|
||||
foreach (BattleHero hero in this.heroes) {
|
||||
|
|
@ -126,7 +128,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
monster.ResetBlock();
|
||||
}
|
||||
|
||||
heroes[this.enemyTarget].DealDamage(2);
|
||||
this.Apply(new DealDamageEffect(heroes[this.enemyTarget], 2));
|
||||
|
||||
DecideEnemyTarget();
|
||||
StartHeroTurn();
|
||||
|
|
@ -196,6 +198,10 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.maxEnergy += delta;
|
||||
}
|
||||
|
||||
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
|
||||
effect.Target.IncreaseMaxHP(effect.Amount);
|
||||
}
|
||||
|
||||
public void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner) {
|
||||
foreach (CardId cardId in cardIds) {
|
||||
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, owner);
|
||||
|
|
@ -213,11 +219,38 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
}
|
||||
|
||||
public void DealDamage(BattleParticipant target, int amount) {
|
||||
target.DealDamage(amount);
|
||||
private List<Trigger> activatedTriggers = new List<Trigger>();
|
||||
private List<DamageTrigger> damageTriggers = new List<DamageTrigger>();
|
||||
|
||||
public void DealDamage(DealDamageEffect effect) {
|
||||
effect.Target.DealDamage(effect.Amount);
|
||||
foreach (DamageTrigger dt in this.damageTriggers) {
|
||||
if (dt.IsTriggeredBy(effect)) {
|
||||
EnqueueActivatedTrigger(dt);
|
||||
}
|
||||
}
|
||||
RunActivatedTriggers();
|
||||
}
|
||||
|
||||
public void AddBlock(BattleParticipant target, int amount) {
|
||||
target.AddBlock(amount);
|
||||
}
|
||||
|
||||
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
||||
this.damageTriggers.Add(damageTrigger);
|
||||
}
|
||||
|
||||
private void EnqueueActivatedTrigger(Trigger trigger) {
|
||||
this.activatedTriggers.Add(trigger);
|
||||
}
|
||||
|
||||
private void RunActivatedTriggers() {
|
||||
foreach (Trigger t in this.activatedTriggers) {
|
||||
t.Run(this);
|
||||
}
|
||||
this.activatedTriggers.Clear();
|
||||
|
||||
// Cleanup expired triggers
|
||||
this.damageTriggers.RemoveAll(t => t.Expired);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,4 +56,11 @@ public class BattleParticipant
|
|||
public bool IsHero() {
|
||||
return this.isHero;
|
||||
}
|
||||
|
||||
public void IncreaseMaxHP(int amount) {
|
||||
this.maxHP += amount;
|
||||
if (this.hp > 0) {
|
||||
this.hp += amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ public enum CardId {
|
|||
CrashingPunch,
|
||||
Cover,
|
||||
LightningStrike,
|
||||
Scarring,
|
||||
Thunderstorm,
|
||||
}
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ public class CardDatabase
|
|||
{CardId.CrashingPunch, HeroId.Brute},
|
||||
{CardId.Cover, HeroId.Brute},
|
||||
{CardId.LightningStrike, HeroId.Shaman},
|
||||
{CardId.Scarring, HeroId.Brute},
|
||||
{CardId.Thunderstorm, HeroId.Shaman},
|
||||
};
|
||||
|
||||
|
|
@ -27,6 +29,8 @@ public class CardDatabase
|
|||
return new CardCover(owner);
|
||||
case CardId.LightningStrike:
|
||||
return new CardLightningStrike(owner);
|
||||
case CardId.Scarring:
|
||||
return new CardScarring(owner);
|
||||
case CardId.Thunderstorm:
|
||||
return new CardThunderstorm(owner);
|
||||
default:
|
||||
|
|
|
|||
29
Assets/Battle/Cards/CardScarring.cs
Normal file
29
Assets/Battle/Cards/CardScarring.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardScarring : BaseCard
|
||||
{
|
||||
public CardScarring(BattleParticipant owner)
|
||||
: base(owner, CardId.Scarring, "Scarring", 2, CardType.Skill,
|
||||
"Block 4 damage. The next time damage is taken until next turn, gain 1 Max HP.") {
|
||||
}
|
||||
|
||||
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
||||
effectApplier.Apply(new BlockEffect(this.owner, 4));
|
||||
// TODO: Trigger only until end of turn.
|
||||
DamageTrigger trigger = new DamageTrigger(
|
||||
new List<BattleParticipant>() {this.owner},
|
||||
this.NotifyDamageDealt,
|
||||
TriggerExpiration.StartOfNextHeroTurn,
|
||||
TriggerRepetition.Once);
|
||||
effectApplier.Apply(new ArmDamageTriggerEffect(trigger));
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void NotifyDamageDealt(IBattleEffectApplier effectApplier) {
|
||||
Debug.Log("NotifyDamageDealt ");
|
||||
IncreaseMaxHPEffect effect = new IncreaseMaxHPEffect(this.owner, 1);
|
||||
effectApplier.Apply(effect);
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/Cards/CardScarring.cs.meta
Normal file
11
Assets/Battle/Cards/CardScarring.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fe7304b59bb0af4281311fce96c1218
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Battle/Effects/ArmDamageTriggerEffect.cs
Normal file
16
Assets/Battle/Effects/ArmDamageTriggerEffect.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ArmDamageTriggerEffect : IBattleEffect
|
||||
{
|
||||
private DamageTrigger damageTrigger;
|
||||
|
||||
public ArmDamageTriggerEffect(DamageTrigger damageTrigger) {
|
||||
this.damageTrigger = damageTrigger;
|
||||
}
|
||||
|
||||
public void Apply(IBattleEffectResolver resolver) {
|
||||
resolver.ArmDamageTrigger(this.damageTrigger);
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/Effects/ArmDamageTriggerEffect.cs.meta
Normal file
11
Assets/Battle/Effects/ArmDamageTriggerEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7658a09c682e8545a141aa3ac050649
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -13,6 +13,9 @@ public class DealDamageEffect : IBattleEffect
|
|||
}
|
||||
|
||||
public void Apply(IBattleEffectResolver resolver) {
|
||||
resolver.DealDamage(this.target, this.amount);
|
||||
resolver.DealDamage(this);
|
||||
}
|
||||
|
||||
public BattleParticipant Target {get => this.target;}
|
||||
public int Amount {get => this.amount;}
|
||||
}
|
||||
|
|
|
|||
21
Assets/Battle/Effects/IncreaseMaxHPEffect.cs
Normal file
21
Assets/Battle/Effects/IncreaseMaxHPEffect.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class IncreaseMaxHPEffect : IBattleEffect
|
||||
{
|
||||
private BattleParticipant target;
|
||||
private int amount;
|
||||
|
||||
public IncreaseMaxHPEffect(BattleParticipant target, int amount) {
|
||||
this.target = target;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void Apply(IBattleEffectResolver resolver) {
|
||||
resolver.IncreaseMaxHP(this);
|
||||
}
|
||||
|
||||
public BattleParticipant Target {get => this.target;}
|
||||
public int Amount {get => this.amount;}
|
||||
}
|
||||
11
Assets/Battle/Effects/IncreaseMaxHPEffect.cs.meta
Normal file
11
Assets/Battle/Effects/IncreaseMaxHPEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1dd7732e862a6e40b5221f85a09b56d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
public interface IBattleEffectResolver {
|
||||
void DealDamage(BattleParticipant target, int amount);
|
||||
void DealDamage(DealDamageEffect effect);
|
||||
void AddBlock(BattleParticipant target, int amount);
|
||||
void IncreaseHeroMaxEnergy(int delta);
|
||||
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
|
||||
void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner);
|
||||
void ArmDamageTrigger(DamageTrigger damageTrigger);
|
||||
}
|
||||
|
|
|
|||
36
Assets/Battle/Trigger.cs
Normal file
36
Assets/Battle/Trigger.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
public enum TriggerExpiration {
|
||||
Never,
|
||||
StartOfNextHeroTurn,
|
||||
}
|
||||
|
||||
public enum TriggerRepetition {
|
||||
Once,
|
||||
Multiple,
|
||||
}
|
||||
|
||||
public class Trigger {
|
||||
|
||||
private TriggeredEffect callback;
|
||||
private TriggerExpiration expiration;
|
||||
private TriggerRepetition repetition;
|
||||
private bool expired;
|
||||
|
||||
public Trigger(TriggeredEffect callback, TriggerExpiration expiration,
|
||||
TriggerRepetition repetition) {
|
||||
this.callback = callback;
|
||||
this.expiration = expiration;
|
||||
this.repetition = repetition;
|
||||
}
|
||||
|
||||
public void Run(IBattleEffectApplier effectApplier) {
|
||||
if (this.expired) return;
|
||||
callback(effectApplier);
|
||||
if (this.repetition == TriggerRepetition.Once) {
|
||||
this.expired = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Expired {get => this.expired;}
|
||||
public TriggerExpiration Expiration {get => this.expiration;}
|
||||
public TriggerRepetition Repetition {get => this.repetition;}
|
||||
}
|
||||
11
Assets/Battle/Trigger.cs.meta
Normal file
11
Assets/Battle/Trigger.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67697df27ab54e043aca7550c896b6fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1
Assets/Battle/TriggeredEffect.cs
Normal file
1
Assets/Battle/TriggeredEffect.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
public delegate void TriggeredEffect(IBattleEffectApplier effectApplier);
|
||||
11
Assets/Battle/TriggeredEffect.cs.meta
Normal file
11
Assets/Battle/TriggeredEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 727217e2ab0988d46b1d4532964b0cf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Battle/Triggers.meta
Normal file
8
Assets/Battle/Triggers.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5bf11c7ef8a0e044fbc4bf500c4d3770
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Battle/Triggers/DamageTrigger.cs
Normal file
16
Assets/Battle/Triggers/DamageTrigger.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
public class DamageTrigger : Trigger {
|
||||
|
||||
private List<BattleParticipant> observedParticipants;
|
||||
|
||||
public DamageTrigger(List<BattleParticipant> observedParticipants, TriggeredEffect callback,
|
||||
TriggerExpiration expiration, TriggerRepetition repetition)
|
||||
: base(callback, expiration, repetition) {
|
||||
this.observedParticipants = observedParticipants;
|
||||
}
|
||||
|
||||
public bool IsTriggeredBy(DealDamageEffect effect) {
|
||||
return effect.Amount > 0 && this.observedParticipants.Contains(effect.Target);
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/Triggers/DamageTrigger.cs.meta
Normal file
11
Assets/Battle/Triggers/DamageTrigger.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6d53e7c1da2653f45a48f309980a7ca4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue