From b4dd6c3496a2ce347741b9acec7a8cf17e27ba38 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Sat, 19 Sep 2020 00:55:36 -0400 Subject: [PATCH] Add Cover card and implement block --- Assets/Battle/BattleController.cs | 7 + Assets/Battle/BattleParticipant.cs | 21 ++- Assets/Battle/BattleScene.unity | 2 +- Assets/Battle/CardDatabase.cs | 5 +- Assets/Battle/Cards/CardCover.cs | 17 +++ Assets/Battle/Cards/CardCover.cs.meta | 11 ++ Assets/Battle/HeroInfoUI.cs | 14 ++ Assets/Battle/HeroUI.prefab | 192 ++++++++++++++++++++++++++ 8 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 Assets/Battle/Cards/CardCover.cs create mode 100644 Assets/Battle/Cards/CardCover.cs.meta diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 3032674..ba4279c 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -94,11 +94,18 @@ public class BattleController : MonoBehaviour private void StartHeroTurn() { this.heroTurn = true; this.energy = this.maxEnergy; + foreach (BattleHero hero in this.heroes) { + hero.ResetBlock(); + } } private void StartEnemyTurn() { this.heroTurn = false; + foreach (BattleMonster monster in this.monsters) { + monster.ResetBlock(); + } + heroes[this.enemyTarget].DealDamage(2); DecideEnemyTarget(); diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index 58d6eb4..57f0936 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -7,6 +8,7 @@ public class BattleParticipant protected string displayName; protected int hp; protected int maxHP; + protected int block; public void Init() { this.hp = this.maxHP; @@ -25,7 +27,24 @@ public class BattleParticipant } public void DealDamage(int damage) { + int blockedDamage = Math.Min(damage, this.block); + if (blockedDamage > 0) { + this.block -= blockedDamage; + damage -= blockedDamage; + } this.hp -= damage; if (this.hp < 0) this.hp = 0; } + + public void AddBlock(int block) { + this.block += block; + } + + public void ResetBlock() { + this.block = 0; + } + + public int GetBlock() { + return this.block; + } } diff --git a/Assets/Battle/BattleScene.unity b/Assets/Battle/BattleScene.unity index a204302..5dbc922 100644 --- a/Assets/Battle/BattleScene.unity +++ b/Assets/Battle/BattleScene.unity @@ -304,7 +304,7 @@ MonoBehaviour: heroIds: 010000000000000002000000 monsterIds: 000000000100000000000000 maxEnergy: 6 - cardIds: 0000000000000000000000000000000000000000 + cardIds: 0000000000000000000000000000000001000000 heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00, type: 3} uiCanvas: {fileID: 35522588} diff --git a/Assets/Battle/CardDatabase.cs b/Assets/Battle/CardDatabase.cs index d31ae78..af073c9 100644 --- a/Assets/Battle/CardDatabase.cs +++ b/Assets/Battle/CardDatabase.cs @@ -3,7 +3,8 @@ using System.Collections.Generic; using UnityEngine; public enum CardId { - CrashingPunch + CrashingPunch, + Cover } public class CardDatabase @@ -13,6 +14,8 @@ public class CardDatabase { case CardId.CrashingPunch: return new CardCrashingPunch(); + case CardId.Cover: + return new CardCover(); default: throw new System.ArgumentException("CardId unknown", "id"); } diff --git a/Assets/Battle/Cards/CardCover.cs b/Assets/Battle/Cards/CardCover.cs new file mode 100644 index 0000000..b1ad411 --- /dev/null +++ b/Assets/Battle/Cards/CardCover.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CardCover : BaseCard +{ + public CardCover() : base(CardId.Cover, "Cover", 1, CardType.Action, "Block 3 damage on another target ally.") { + + } + + public override IEnumerator Use(BattlePlayerControls playerControls) { + List target = new List(); + yield return playerControls.StartCoroutine(playerControls.ChooseTarget((t) => {target.Add(t);})); + Debug.Log("Covering " + target[0]); + target[0].AddBlock(3); + } +} diff --git a/Assets/Battle/Cards/CardCover.cs.meta b/Assets/Battle/Cards/CardCover.cs.meta new file mode 100644 index 0000000..f84ba41 --- /dev/null +++ b/Assets/Battle/Cards/CardCover.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: adec885589bc619409ad04df50ddd568 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/HeroInfoUI.cs b/Assets/Battle/HeroInfoUI.cs index d0cc264..ec7cd14 100644 --- a/Assets/Battle/HeroInfoUI.cs +++ b/Assets/Battle/HeroInfoUI.cs @@ -11,9 +11,12 @@ public class HeroInfoUI : MonoBehaviour public Image healthBarBgImage; public Image healthBarFgImage; public Text hpText; + public GameObject blockGroup; + public Text blockText; private int renderedHP = -1; private int renderedMaxHP = -1; + private int renderedBlock = -1; private Camera mainCamera; private static Color HIGH_HP_COLOR = new Color(0f, 0.8f, 0f); @@ -56,5 +59,16 @@ public class HeroInfoUI : MonoBehaviour } this.hpText.text = "" + hp + " / " + maxHP; } + + int block = this.battleParticipant.GetBlock(); + if (this.renderedBlock != block) { + this.renderedBlock = block; + if (block == 0) { + this.blockGroup.SetActive(false); + } else { + this.blockGroup.SetActive(true); + this.blockText.text = "" + block; + } + } } } diff --git a/Assets/Battle/HeroUI.prefab b/Assets/Battle/HeroUI.prefab index 68931da..25afd88 100644 --- a/Assets/Battle/HeroUI.prefab +++ b/Assets/Battle/HeroUI.prefab @@ -1,5 +1,83 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &1970939329566987749 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7186401048428393162} + - component: {fileID: 7203125139980703040} + - component: {fileID: 1400733402613879005} + m_Layer: 5 + m_Name: BlockText + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &7186401048428393162 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1970939329566987749} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1054158240845704231} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -36, y: 0} + m_SizeDelta: {x: 17, y: 14.8} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &7203125139980703040 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1970939329566987749} + m_CullTransparentMesh: 0 +--- !u!114 &1400733402613879005 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1970939329566987749} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.6226415, g: 0.6226415, b: 0.6226415, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 12 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 1 + m_MaxSize: 40 + m_Alignment: 4 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: 56 --- !u!1 &5172729878808660606 GameObject: m_ObjectHideFlags: 0 @@ -78,6 +156,117 @@ MonoBehaviour: m_VerticalOverflow: 0 m_LineSpacing: 1 m_Text: 12 / 34 +--- !u!1 &5194869534592792291 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1054158240845704231} + m_Layer: 5 + m_Name: Block + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1054158240845704231 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5194869534592792291} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1373189589245154165} + - {fileID: 7186401048428393162} + m_Father: {fileID: 6071241564507600362} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 60} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &5574000899179897583 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1373189589245154165} + - component: {fileID: 8600655002061634105} + - component: {fileID: 2205983270256308677} + m_Layer: 5 + m_Name: BG + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1373189589245154165 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5574000899179897583} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1054158240845704231} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -36, y: 0} + m_SizeDelta: {x: 17, y: 12} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &8600655002061634105 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5574000899179897583} + m_CullTransparentMesh: 0 +--- !u!114 &2205983270256308677 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5574000899179897583} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0.360829, b: 0.6603774, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: ff1a435c8e6ef4a46aeb34ba613ce13d, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 0 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!1 &6071241563652651137 GameObject: m_ObjectHideFlags: 0 @@ -372,6 +561,7 @@ RectTransform: m_Children: - {fileID: 6071241564363553667} - {fileID: 6071241564411437881} + - {fileID: 1054158240845704231} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -396,3 +586,5 @@ MonoBehaviour: healthBarBgImage: {fileID: 6071241563652651135} healthBarFgImage: {fileID: 6071241564068399931} hpText: {fileID: 2548384344736816241} + blockGroup: {fileID: 5194869534592792291} + blockText: {fileID: 1400733402613879005}