From 00e1d7968aa10c171eb5a45988a90710aca7c523 Mon Sep 17 00:00:00 2001 From: Frank Xu Date: Mon, 21 Mar 2022 10:42:48 +0800 Subject: [PATCH] Added Ability and UnitClass; Cleaned up CardTag --- .../Infantry.asset.meta => Ability.meta} | 6 +- .../Archer.asset.meta => CardClasses.meta} | 6 +- Assets/Prefabs/CardClasses/ArcherClass.cs | 14 +++ .../Prefabs/CardClasses/ArcherClass.cs.meta | 11 +++ Assets/Prefabs/CardClasses/CavalryClass.cs | 13 +++ .../Prefabs/CardClasses/CavalryClass.cs.meta | 11 +++ Assets/Prefabs/CardDatas/官军弓兵.asset | 1 - Assets/Prefabs/CardDatas/黄巾弓兵.asset | 1 - Assets/Prefabs/CardTags.meta | 2 +- Assets/Prefabs/CardTags/Archer.asset | 17 ---- Assets/Prefabs/CardTags/Cavalry.asset | 17 ---- Assets/Prefabs/CardTags/Cavalry.asset.meta | 8 -- Assets/Prefabs/CardTags/Infantry.asset | 17 ---- Assets/Scripts/Ability.cs | 41 +++++++++ Assets/Scripts/Ability.cs.meta | 11 +++ Assets/Scripts/CardData.cs | 5 +- Assets/Scripts/CardTag.cs | 2 - Assets/Scripts/CellMap.cs | 8 +- Assets/Scripts/Unit.cs | 85 ++++++++++++------- Assets/Scripts/UnitClass.cs | 12 +++ Assets/Scripts/UnitClass.cs.meta | 11 +++ 21 files changed, 196 insertions(+), 103 deletions(-) rename Assets/Prefabs/{CardTags/Infantry.asset.meta => Ability.meta} (52%) rename Assets/Prefabs/{CardTags/Archer.asset.meta => CardClasses.meta} (52%) create mode 100644 Assets/Prefabs/CardClasses/ArcherClass.cs create mode 100644 Assets/Prefabs/CardClasses/ArcherClass.cs.meta create mode 100644 Assets/Prefabs/CardClasses/CavalryClass.cs create mode 100644 Assets/Prefabs/CardClasses/CavalryClass.cs.meta delete mode 100644 Assets/Prefabs/CardTags/Archer.asset delete mode 100644 Assets/Prefabs/CardTags/Cavalry.asset delete mode 100644 Assets/Prefabs/CardTags/Cavalry.asset.meta delete mode 100644 Assets/Prefabs/CardTags/Infantry.asset create mode 100644 Assets/Scripts/Ability.cs create mode 100644 Assets/Scripts/Ability.cs.meta create mode 100644 Assets/Scripts/UnitClass.cs create mode 100644 Assets/Scripts/UnitClass.cs.meta diff --git a/Assets/Prefabs/CardTags/Infantry.asset.meta b/Assets/Prefabs/Ability.meta similarity index 52% rename from Assets/Prefabs/CardTags/Infantry.asset.meta rename to Assets/Prefabs/Ability.meta index 944d785..217f7cc 100644 --- a/Assets/Prefabs/CardTags/Infantry.asset.meta +++ b/Assets/Prefabs/Ability.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: cf728e5d8a62fa3418d2f3daa01f93df -NativeFormatImporter: +guid: 5d08decdacf201b45a16e73a769a8f51 +folderAsset: yes +DefaultImporter: externalObjects: {} - mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Prefabs/CardTags/Archer.asset.meta b/Assets/Prefabs/CardClasses.meta similarity index 52% rename from Assets/Prefabs/CardTags/Archer.asset.meta rename to Assets/Prefabs/CardClasses.meta index 6a1b5da..1fe41d1 100644 --- a/Assets/Prefabs/CardTags/Archer.asset.meta +++ b/Assets/Prefabs/CardClasses.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: 099176a69eb9a6d408b4d4dba5232c84 -NativeFormatImporter: +guid: 29138ff75042d784e83244ddb11034ed +folderAsset: yes +DefaultImporter: externalObjects: {} - mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Prefabs/CardClasses/ArcherClass.cs b/Assets/Prefabs/CardClasses/ArcherClass.cs new file mode 100644 index 0000000..0a5cf9b --- /dev/null +++ b/Assets/Prefabs/CardClasses/ArcherClass.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "ArcherClass", menuName = "Card Class/Archer Class Data")] +public class ArcherClass : UnitClass +{ + public int extraAttackRange = 2; + public override void ApplyClassSpecilization(Unit unit) + { + unit.MeleeAttackRange = 0; + unit.RangedAttackRange += extraAttackRange; + } +} diff --git a/Assets/Prefabs/CardClasses/ArcherClass.cs.meta b/Assets/Prefabs/CardClasses/ArcherClass.cs.meta new file mode 100644 index 0000000..0100b07 --- /dev/null +++ b/Assets/Prefabs/CardClasses/ArcherClass.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1bc96940f74c4ce4581f5cdec90d1e0b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/CardClasses/CavalryClass.cs b/Assets/Prefabs/CardClasses/CavalryClass.cs new file mode 100644 index 0000000..f31f089 --- /dev/null +++ b/Assets/Prefabs/CardClasses/CavalryClass.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "CavalryClass", menuName = "Card Class/Cavalry Class Data")] +public class CavalryClass : UnitClass +{ + public int extraMovement = 1; + public override void ApplyClassSpecilization(Unit unit) + { + unit.Movement += extraMovement; + } +} diff --git a/Assets/Prefabs/CardClasses/CavalryClass.cs.meta b/Assets/Prefabs/CardClasses/CavalryClass.cs.meta new file mode 100644 index 0000000..da10ce0 --- /dev/null +++ b/Assets/Prefabs/CardClasses/CavalryClass.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e099c37da90ac1b46ac0a5ee6f79f507 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/CardDatas/官军弓兵.asset b/Assets/Prefabs/CardDatas/官军弓兵.asset index 6b5afb9..123f412 100644 --- a/Assets/Prefabs/CardDatas/官军弓兵.asset +++ b/Assets/Prefabs/CardDatas/官军弓兵.asset @@ -18,6 +18,5 @@ MonoBehaviour: cost: 1 attack: 5 defense: 10 - movement: 1 cardTags: - {fileID: 11400000, guid: 099176a69eb9a6d408b4d4dba5232c84, type: 2} diff --git a/Assets/Prefabs/CardDatas/黄巾弓兵.asset b/Assets/Prefabs/CardDatas/黄巾弓兵.asset index 0c25f6b..bb13c1e 100644 --- a/Assets/Prefabs/CardDatas/黄巾弓兵.asset +++ b/Assets/Prefabs/CardDatas/黄巾弓兵.asset @@ -18,6 +18,5 @@ MonoBehaviour: cost: 1 attack: 5 defense: 10 - movement: 1 cardTags: - {fileID: 11400000, guid: 099176a69eb9a6d408b4d4dba5232c84, type: 2} diff --git a/Assets/Prefabs/CardTags.meta b/Assets/Prefabs/CardTags.meta index 1fe41d1..122bd91 100644 --- a/Assets/Prefabs/CardTags.meta +++ b/Assets/Prefabs/CardTags.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 29138ff75042d784e83244ddb11034ed +guid: d079f30f575342145b9a2e5b0204e326 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Prefabs/CardTags/Archer.asset b/Assets/Prefabs/CardTags/Archer.asset deleted file mode 100644 index 1430a17..0000000 --- a/Assets/Prefabs/CardTags/Archer.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3} - m_Name: Archer - m_EditorClassIdentifier: - name: Archer - description: - artwork: {fileID: 0} diff --git a/Assets/Prefabs/CardTags/Cavalry.asset b/Assets/Prefabs/CardTags/Cavalry.asset deleted file mode 100644 index 6f4800a..0000000 --- a/Assets/Prefabs/CardTags/Cavalry.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3} - m_Name: Cavalry - m_EditorClassIdentifier: - name: Cavalry - description: - artwork: {fileID: 0} diff --git a/Assets/Prefabs/CardTags/Cavalry.asset.meta b/Assets/Prefabs/CardTags/Cavalry.asset.meta deleted file mode 100644 index 1ac03ac..0000000 --- a/Assets/Prefabs/CardTags/Cavalry.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 53185ea05ebfbd843b009cb14101377a -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Prefabs/CardTags/Infantry.asset b/Assets/Prefabs/CardTags/Infantry.asset deleted file mode 100644 index 4b3fd70..0000000 --- a/Assets/Prefabs/CardTags/Infantry.asset +++ /dev/null @@ -1,17 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3} - m_Name: Infantry - m_EditorClassIdentifier: - name: Infantry - description: - artwork: {fileID: 0} diff --git a/Assets/Scripts/Ability.cs b/Assets/Scripts/Ability.cs new file mode 100644 index 0000000..96a3f95 --- /dev/null +++ b/Assets/Scripts/Ability.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Ability : ScriptableObject +{ + public new string name; + public string description; + + public virtual void OnSpawn(Unit unit) { } + public virtual void OnBeginRound(Unit unit) { } + public virtual void OnEndRound(Unit unit) { } + + public virtual void OnBeginMove(Unit unit) { } + public virtual void OnMove(Unit unit, int travelDistance) { } + public virtual void OnEndMove(Unit unit) { } + + public virtual void OnBeginAttackPhrase(Unit unit) { } + public virtual void OnBeginAttack(Unit unit, List targets) { } + public virtual void OnAttack(Unit unit, List targets) { } + public virtual void OnEndAttack(Unit unit, List targets) { } + public virtual void OnEndAttackPhrase(Unit unit) { } + public virtual void OnExecute(Unit unit, Unit target) { } + public virtual void OnAllyDeath(Unit unit) { } + public virtual void OnEnemyDeath(Unit unit) { } + public virtual void OnAnyDeath(Unit unit) { } + + public virtual void OnCounterAttack(Unit unit, Unit attacker) { } + public virtual void OnDamaged(Unit unit, Unit attacker) { } + public virtual void OnArmorBreak(Unit unit, Unit attacker) { } + public virtual void OnDefeat(Unit unit, Unit attacker) { } + + public virtual void OnEnterBattleGround(Unit unit) { } + public virtual void OnExitBattleGround(Unit unit) { } + public virtual void OnDraw(Unit unit) { } + public virtual void OnRecovered(Unit unit, Unit helper) { } + public virtual void OnEquippingArmor(Unit unit, int armorAmount) { } + public virtual void OnDiscard(Unit unit) { } + + public virtual void OnCasting(Unit unit) { } +} diff --git a/Assets/Scripts/Ability.cs.meta b/Assets/Scripts/Ability.cs.meta new file mode 100644 index 0000000..0efed3a --- /dev/null +++ b/Assets/Scripts/Ability.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27a2e411b169b994891c431e7a183368 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CardData.cs b/Assets/Scripts/CardData.cs index ac8d86a..ead64dc 100644 --- a/Assets/Scripts/CardData.cs +++ b/Assets/Scripts/CardData.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu(fileName = "New Card Data", menuName = "Card/Card Data")] public class CardData : ScriptableObject { public new string name; @@ -14,5 +13,7 @@ public class CardData : ScriptableObject public int attack; public int defense; - public CardTag[] cardTags; + public CardTag[] tags; + public UnitClass[] unitClasses; + public Ability[] abilities; } diff --git a/Assets/Scripts/CardTag.cs b/Assets/Scripts/CardTag.cs index aa7404d..bb7e175 100644 --- a/Assets/Scripts/CardTag.cs +++ b/Assets/Scripts/CardTag.cs @@ -7,6 +7,4 @@ public class CardTag : ScriptableObject { public new string name; public string description; - - public Sprite artwork; } diff --git a/Assets/Scripts/CellMap.cs b/Assets/Scripts/CellMap.cs index fac2ee8..2f0b633 100644 --- a/Assets/Scripts/CellMap.cs +++ b/Assets/Scripts/CellMap.cs @@ -15,7 +15,6 @@ public class CellMap : MonoBehaviour public int column = 0; public int row = 0; - // Start is called before the first frame update void Start() { @@ -35,11 +34,16 @@ public class CellMap : MonoBehaviour // Update is called once per frame void Update() { - + } public Cell GetCell(int x, int y) { return cellMapData[y].cells[x]; } + + public bool IsCellEmpty(int x, int y) + { + return GetCell(x, y).standingUnit == null; + } } diff --git a/Assets/Scripts/Unit.cs b/Assets/Scripts/Unit.cs index 351dab3..a76bc6b 100644 --- a/Assets/Scripts/Unit.cs +++ b/Assets/Scripts/Unit.cs @@ -13,7 +13,7 @@ public enum Side { left = 1, right = -1 } public class Unit : MonoBehaviour { public string unitName; - public CardData cardData; + public CardData baseData; [SerializeField] private int basicAttack; @@ -27,12 +27,37 @@ public class Unit : MonoBehaviour private int finalMaxDefense; [SerializeField] - private CardTag[] cardTags; + private List cardTags; [SerializeField] - private int attackRange = 1; + private List unitClasses; + + [SerializeField] + private List abilities; + + [SerializeField] + private int meleeAttackRange = 1; + public int MeleeAttackRange + { + get { return meleeAttackRange; } + set { meleeAttackRange = value; } + } + + [SerializeField] + private int rangedAttackRange = 1; + public int RangedAttackRange + { + get { return rangedAttackRange; } + set { rangedAttackRange = value; } + } + [SerializeField] private int movement = 1; + public int Movement + { + get { return movement; } + set { movement = value; } + } [SerializeField] private CurrentCommand currentCommand; @@ -53,6 +78,11 @@ public class Unit : MonoBehaviour Camp allyCamp; Camp enemyCamp; + public bool isUnitAlive() + { + return currentDefense > 0; + } + // Start is called before the first frame update void Start() { @@ -61,24 +91,18 @@ public class Unit : MonoBehaviour transform.position = new Vector3(transform.position.x, transform.position.y, -1); standingCell.standingUnit = this; - basicAttack = cardData.attack; - basicMaxDefense = cardData.defense; + basicAttack = baseData.attack; + basicMaxDefense = baseData.defense; currentDefense = basicMaxDefense; - cardTags = cardData.cardTags; + cardTags = baseData.tags.ToList(); + unitClasses = baseData.unitClasses.ToList(); - foreach (var tag in cardData.cardTags) + foreach (var unitClass in unitClasses) { - if (tag.name == "Archer") - { - attackRange += 2; - } - else if (tag.name == "Cavalry") - { - movement += 1; - } + unitClass.ApplyClassSpecilization(this); } - modelArt.GetComponent().sprite = cardData.artwork; + modelArt.GetComponent().sprite = baseData.artwork; var camps = FindObjectsOfType(); foreach (var camp in camps) @@ -94,8 +118,7 @@ public class Unit : MonoBehaviour } } - // Update is called once per frame - void Update() + void UpdateAnimation() { if (walkingToDestination && destinationCell && transform.position != destinationCell.transform.position) { @@ -114,13 +137,22 @@ public class Unit : MonoBehaviour //Debug.Log("Arrived."); } } + } - finalAttack = basicAttack; // For now. - + void UpdateText() + { attackText.GetComponent().text = finalAttack.ToString(); defenseText.GetComponent().text = currentDefense.ToString(); } + // Update is called once per frame + void Update() + { + UpdateAnimation(); + finalAttack = basicAttack; // For now. + UpdateText(); + } + public void MoveAndAttack() { MoveAction(); @@ -133,11 +165,11 @@ public class Unit : MonoBehaviour { return; } - foreach (var tag in cardData.cardTags) + foreach (var tag in cardTags) { if (tag.name == "Archer") { - for (int i = 0; i < attackRange; ++i) + for (int i = 0; i < meleeAttackRange; ++i) { int attackXPos = standingCell.xPos + (i + 1) * (int)side; if (attackXPos >= cellMap.column || attackXPos < 0) @@ -236,7 +268,7 @@ public class Unit : MonoBehaviour // Check Attack Range if (inDogFight(this)) { - foreach (var tag in cardData.cardTags) + foreach (var tag in cardTags) { if (tag.name == "Archer") { @@ -247,7 +279,7 @@ public class Unit : MonoBehaviour } List unitsInRange = new List(); - for (int i = 0; i < attackRange; ++i) + for (int i = 0; i < meleeAttackRange; ++i) { int attackXPos = standingCell.xPos + (i+1) * (int)side; if (attackXPos >= cellMap.column || attackXPos < 0) @@ -307,11 +339,6 @@ public class Unit : MonoBehaviour } } - public bool isUnitAlive() - { - return currentDefense > 0; - } - bool checkDestinationCellEmpty(bool retreat = false) { int currentXPos = standingCell.xPos; diff --git a/Assets/Scripts/UnitClass.cs b/Assets/Scripts/UnitClass.cs new file mode 100644 index 0000000..641ecbb --- /dev/null +++ b/Assets/Scripts/UnitClass.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UnitClass : ScriptableObject +{ + public new string name; + public string description; + + public Sprite artwork; + public virtual void ApplyClassSpecilization(Unit unit) { } +} diff --git a/Assets/Scripts/UnitClass.cs.meta b/Assets/Scripts/UnitClass.cs.meta new file mode 100644 index 0000000..f0cae10 --- /dev/null +++ b/Assets/Scripts/UnitClass.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7d6c417b0c9236b4a915f410e56db822 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: