Implement TargetingPolicy, Cover can only target other allies
This commit is contained in:
parent
611601934d
commit
3e0004d4cb
21 changed files with 151 additions and 26 deletions
|
|
@ -8,13 +8,15 @@ public enum CardType {
|
|||
|
||||
public abstract class BaseCard
|
||||
{
|
||||
private CardId id;
|
||||
private string displayName;
|
||||
private int cost;
|
||||
private CardType type;
|
||||
private string effectText;
|
||||
protected BattleParticipant owner;
|
||||
protected CardId id;
|
||||
protected string displayName;
|
||||
protected int cost;
|
||||
protected CardType type;
|
||||
protected string effectText;
|
||||
|
||||
public BaseCard(CardId id, string displayName, int cost, CardType type, string effectText) {
|
||||
public BaseCard(BattleParticipant owner, CardId id, string displayName, int cost, CardType type, string effectText) {
|
||||
this.owner = owner;
|
||||
this.id = id;
|
||||
this.displayName = displayName;
|
||||
this.cost = cost;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ public class BattleController : MonoBehaviour
|
|||
private int energy;
|
||||
|
||||
void Awake() {
|
||||
this.heroDeck = new HeroDeck(cardIds);
|
||||
|
||||
heroes = new BattleHero[3];
|
||||
heroSprites = new GameObject[3];
|
||||
heroUIs = new HeroInfoUI[3];
|
||||
|
|
@ -69,12 +67,25 @@ public class BattleController : MonoBehaviour
|
|||
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
||||
}
|
||||
|
||||
BattleParticipant[] cardOwners = new BattleParticipant[this.cardIds.Length];
|
||||
for (int i = 0; i < this.cardIds.Length; i++) {
|
||||
cardOwners[i] = FindHeroByClass(CardDatabase.GetHeroIdOfCard(this.cardIds[i]));
|
||||
}
|
||||
this.heroDeck = new HeroDeck(this.cardIds, cardOwners);
|
||||
|
||||
this.battlePlayerControls.Init(this.heroDeck);
|
||||
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
||||
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
||||
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
|
||||
}
|
||||
|
||||
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
||||
foreach (BattleHero battleHero in this.heroes) {
|
||||
if (battleHero.GetId() == heroId) return battleHero;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ using UnityEngine;
|
|||
|
||||
public class BattleHero: BattleParticipant
|
||||
{
|
||||
public BattleHero(HeroId id) {
|
||||
HeroId id;
|
||||
|
||||
public BattleHero(HeroId id) : base(true) {
|
||||
this.id = id;
|
||||
switch (id)
|
||||
{
|
||||
case HeroId.Alchemist:
|
||||
|
|
@ -23,4 +26,8 @@ public class BattleHero: BattleParticipant
|
|||
throw new System.ArgumentException("HeroId unknown", "id");
|
||||
}
|
||||
}
|
||||
|
||||
public HeroId GetId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ using UnityEngine;
|
|||
|
||||
public class BattleMonster: BattleParticipant
|
||||
{
|
||||
public BattleMonster() {
|
||||
public BattleMonster() : base(false) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,16 @@ using UnityEngine;
|
|||
|
||||
public class BattleParticipant
|
||||
{
|
||||
protected bool isHero;
|
||||
protected string displayName;
|
||||
protected int hp;
|
||||
protected int maxHP;
|
||||
protected int block;
|
||||
|
||||
public BattleParticipant(bool isHero) {
|
||||
this.isHero = isHero;
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
this.hp = this.maxHP;
|
||||
}
|
||||
|
|
@ -47,4 +52,8 @@ public class BattleParticipant
|
|||
public int GetBlock() {
|
||||
return this.block;
|
||||
}
|
||||
|
||||
public bool IsHero() {
|
||||
return this.isHero;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class BattleParticipantSprite : MonoBehaviour
|
|||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (colorChanged && !this.playerControls.IsTargeting()) {
|
||||
if (colorChanged && !this.playerControls.CouldTarget(participant)) {
|
||||
OnMouseExit();
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ public class BattleParticipantSprite : MonoBehaviour
|
|||
private bool colorChanged;
|
||||
|
||||
void OnMouseEnter() {
|
||||
if (this.playerControls.IsTargeting()) {
|
||||
if (this.playerControls.CouldTarget(participant)) {
|
||||
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
||||
this.savedColor = sprite.color;
|
||||
sprite.color = Color.Lerp(this.savedColor, Color.white, .5f);
|
||||
|
|
|
|||
|
|
@ -88,8 +88,8 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsTargeting() {
|
||||
return this.singleTargeting != null;
|
||||
public bool CouldTarget(BattleParticipant participant) {
|
||||
return this.singleTargeting != null && this.singleTargeting.CanTarget(participant);
|
||||
}
|
||||
|
||||
public void NotifyHandPileChanged() {
|
||||
|
|
|
|||
|
|
@ -876,7 +876,7 @@ MonoBehaviour:
|
|||
m_HorizontalOverflow: 0
|
||||
m_VerticalOverflow: 0
|
||||
m_LineSpacing: 1
|
||||
m_Text: 'Draw pile: 5'
|
||||
m_Text: 'Discard pile: 5'
|
||||
--- !u!222 &1522237123
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -982,7 +982,7 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 2103461256}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b39e026c50828b04ab3d0627aaf962d6, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 077ba059e9689fa4990b9aea8bff3ded, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
text: {fileID: 1522237122}
|
||||
|
|
|
|||
|
|
@ -9,15 +9,24 @@ public enum CardId {
|
|||
|
||||
public class CardDatabase
|
||||
{
|
||||
public static BaseCard CreateCard(CardId id) {
|
||||
private static Dictionary<CardId, HeroId> CARD_TO_HERO = new Dictionary<CardId, HeroId>() {
|
||||
{CardId.CrashingPunch, HeroId.Brute},
|
||||
{CardId.Cover, HeroId.Brute},
|
||||
};
|
||||
|
||||
public static BaseCard CreateCard(CardId id, BattleParticipant owner) {
|
||||
switch (id)
|
||||
{
|
||||
case CardId.CrashingPunch:
|
||||
return new CardCrashingPunch();
|
||||
return new CardCrashingPunch(owner);
|
||||
case CardId.Cover:
|
||||
return new CardCover();
|
||||
return new CardCover(owner);
|
||||
default:
|
||||
throw new System.ArgumentException("CardId unknown", "id");
|
||||
}
|
||||
}
|
||||
|
||||
public static HeroId GetHeroIdOfCard(CardId id) {
|
||||
return CARD_TO_HERO[id];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ using UnityEngine;
|
|||
|
||||
public class CardCover : BaseCard
|
||||
{
|
||||
public CardCover() : base(CardId.Cover, "Cover", 1, CardType.Action, "Block 3 damage on another target ally.") {
|
||||
public CardCover(BattleParticipant owner)
|
||||
: base(owner, CardId.Cover, "Cover", 1, CardType.Action,
|
||||
"Block 3 damage on another target ally.") {
|
||||
|
||||
}
|
||||
|
||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||
SingleTargeting singleTargeting = new SingleTargeting();
|
||||
SingleTargeting singleTargeting = new SingleTargeting(new OtherHeroTargetPolicy(this.owner));
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||
BattleParticipant target = singleTargeting.GetTarget();
|
||||
Debug.Log("Covering " + target);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ using UnityEngine;
|
|||
|
||||
public class CardCrashingPunch : BaseCard
|
||||
{
|
||||
public CardCrashingPunch() : base(CardId.CrashingPunch, "Crashing Punch", 3, CardType.Action, "Deals 3 damage to target.") {
|
||||
|
||||
public CardCrashingPunch(BattleParticipant owner)
|
||||
: base(owner, CardId.CrashingPunch, "Crashing Punch", 3, CardType.Action,
|
||||
"Deals 3 damage to target.") {
|
||||
}
|
||||
|
||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
||||
SingleTargeting singleTargeting = new SingleTargeting();
|
||||
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||
BattleParticipant target = singleTargeting.GetTarget();
|
||||
Debug.Log("Punching " + target);
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ public class HeroDeck
|
|||
private List<BaseCard> handPile;
|
||||
private List<BaseCard> discardPile;
|
||||
|
||||
public HeroDeck(CardId[] cardIds) {
|
||||
public HeroDeck(CardId[] cardIds, BattleParticipant[] cardOwners) {
|
||||
this.drawPile = new List<BaseCard>();
|
||||
this.handPile = new List<BaseCard>();
|
||||
this.discardPile = new List<BaseCard>();
|
||||
|
||||
for (int i = 0; i < cardIds.Length; i++) {
|
||||
BaseCard newCard = CardDatabase.CreateCard(cardIds[i]);
|
||||
BaseCard newCard = CardDatabase.CreateCard(cardIds[i], cardOwners[i]);
|
||||
this.drawPile.Add(newCard);
|
||||
}
|
||||
this.drawPile.Shuffle();
|
||||
|
|
|
|||
8
Assets/Battle/Targeting.meta
Normal file
8
Assets/Battle/Targeting.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed34b9735ea39304baf50786bc06033d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Battle/Targeting/AnyTargetPolicy.cs
Normal file
10
Assets/Battle/Targeting/AnyTargetPolicy.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnyTargetPolicy: TargetingPolicy
|
||||
{
|
||||
public override bool CanTarget(BattleParticipant participant) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/Targeting/AnyTargetPolicy.cs.meta
Normal file
11
Assets/Battle/Targeting/AnyTargetPolicy.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 905e809c95dad9945b91b2a2f8906f54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Battle/Targeting/OtheHeroTargetPolicy.cs
Normal file
16
Assets/Battle/Targeting/OtheHeroTargetPolicy.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class OtherHeroTargetPolicy: TargetingPolicy
|
||||
{
|
||||
private BattleParticipant owner;
|
||||
|
||||
public OtherHeroTargetPolicy(BattleParticipant owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public override bool CanTarget(BattleParticipant participant) {
|
||||
return participant.IsHero() && participant != this.owner;
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/Targeting/OtheHeroTargetPolicy.cs.meta
Normal file
11
Assets/Battle/Targeting/OtheHeroTargetPolicy.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 929cb636783b68a4db231a06391a652e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -5,8 +5,17 @@ using UnityEngine.UI;
|
|||
|
||||
public class SingleTargeting
|
||||
{
|
||||
private TargetingPolicy targetingPolicy;
|
||||
private BattleParticipant participantClicked;
|
||||
|
||||
public SingleTargeting(TargetingPolicy targetingPolicy) {
|
||||
this.targetingPolicy = targetingPolicy;
|
||||
}
|
||||
|
||||
public bool CanTarget(BattleParticipant participant) {
|
||||
return this.targetingPolicy.CanTarget(participant);
|
||||
}
|
||||
|
||||
public IEnumerator ChooseTarget() {
|
||||
while (this.participantClicked == null) {
|
||||
yield return null;
|
||||
8
Assets/Battle/Targeting/TargetingPolicy.cs
Normal file
8
Assets/Battle/Targeting/TargetingPolicy.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class TargetingPolicy
|
||||
{
|
||||
public abstract bool CanTarget(BattleParticipant participant);
|
||||
}
|
||||
11
Assets/Battle/Targeting/TargetingPolicy.cs.meta
Normal file
11
Assets/Battle/Targeting/TargetingPolicy.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 532a5ac0339ee5a4fb5c9e7888f0dd5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue