Compare commits

...

3 Commits

Author SHA1 Message Date
jacky_cai 2901e91e17 Assign ref. 2022-03-20 21:57:19 -07:00
Frank Xu 04539851c2 First draft of CombatManager and Ability 2022-03-21 12:31:59 +08:00
Frank Xu 00e1d7968a Added Ability and UnitClass; Cleaned up CardTag 2022-03-21 10:42:48 +08:00
34 changed files with 521 additions and 104 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5d08decdacf201b45a16e73a769a8f51
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 29138ff75042d784e83244ddb11034ed
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,9 +9,10 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3}
m_Name: Cavalry
m_Script: {fileID: 11500000, guid: 1bc96940f74c4ce4581f5cdec90d1e0b, type: 3}
m_Name: ArcherClass
m_EditorClassIdentifier:
name: Cavalry
name:
description:
artwork: {fileID: 0}
extraAttackRange: 2

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: cf728e5d8a62fa3418d2f3daa01f93df
guid: 9c0ba6b77d1ad844d957f6d66b24dd1f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@ -9,9 +9,10 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3}
m_Name: Infantry
m_Script: {fileID: 11500000, guid: e099c37da90ac1b46ac0a5ee6f79f507, type: 3}
m_Name: CavalryClass
m_EditorClassIdentifier:
name: Infantry
name:
description:
artwork: {fileID: 0}
extraMovement: 1

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 099176a69eb9a6d408b4d4dba5232c84
guid: 2c8cf65dbf365874ca1c1dee59e831c2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@ -9,9 +9,9 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c090164f177918042b3be10f378e9b5f, type: 3}
m_Name: Archer
m_Script: {fileID: 11500000, guid: 52ce9ab65798e6c46a62ac364d881763, type: 3}
m_Name: InfantryClass
m_EditorClassIdentifier:
name: Archer
name:
description:
artwork: {fileID: 0}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 53185ea05ebfbd843b009cb14101377a
guid: 548b88e44eb600c4fa3a63033e23be30
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@ -18,6 +18,7 @@ MonoBehaviour:
cost: 1
attack: 5
defense: 10
movement: 1
cardTags:
- {fileID: 11400000, guid: 099176a69eb9a6d408b4d4dba5232c84, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 9c0ba6b77d1ad844d957f6d66b24dd1f, type: 2}
abilities: []

View File

@ -18,6 +18,7 @@ MonoBehaviour:
cost: 1
attack: 5
defense: 20
movement: 1
cardTags:
- {fileID: 11400000, guid: cf728e5d8a62fa3418d2f3daa01f93df, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 548b88e44eb600c4fa3a63033e23be30, type: 2}
abilities: []

View File

@ -18,5 +18,7 @@ MonoBehaviour:
cost: 1
attack: 10
defense: 10
cardTags:
- {fileID: 11400000, guid: 53185ea05ebfbd843b009cb14101377a, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 2c8cf65dbf365874ca1c1dee59e831c2, type: 2}
abilities: []

View File

@ -18,6 +18,7 @@ MonoBehaviour:
cost: 1
attack: 5
defense: 10
movement: 1
cardTags:
- {fileID: 11400000, guid: 099176a69eb9a6d408b4d4dba5232c84, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 9c0ba6b77d1ad844d957f6d66b24dd1f, type: 2}
abilities: []

View File

@ -18,6 +18,7 @@ MonoBehaviour:
cost: 1
attack: 3
defense: 18
movement: 1
cardTags:
- {fileID: 11400000, guid: cf728e5d8a62fa3418d2f3daa01f93df, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 548b88e44eb600c4fa3a63033e23be30, type: 2}
abilities: []

View File

@ -18,5 +18,7 @@ MonoBehaviour:
cost: 1
attack: 7
defense: 8
cardTags:
- {fileID: 11400000, guid: 53185ea05ebfbd843b009cb14101377a, type: 2}
tags: []
unitClasses:
- {fileID: 11400000, guid: 2c8cf65dbf365874ca1c1dee59e831c2, type: 2}
abilities: []

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 29138ff75042d784e83244ddb11034ed
guid: d079f30f575342145b9a2e5b0204e326
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -321,6 +321,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 675490af7d7c9c142ae76d1b2e4920b1, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -688,6 +692,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 675490af7d7c9c142ae76d1b2e4920b1, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -823,6 +831,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 675490af7d7c9c142ae76d1b2e4920b1, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -1279,6 +1291,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175 (4)"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 5d7c6bbedeba24e4f98ea1ca65fc5c0a, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: standingCell
value:
@ -1823,6 +1839,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175 (3)"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 9eb62481994b51e4897a57499081c3db, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -2164,6 +2184,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 9eb62481994b51e4897a57499081c3db, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -2249,6 +2273,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 675490af7d7c9c142ae76d1b2e4920b1, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -2645,6 +2673,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175 (2)"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: adc3952bb833a224895877477b4ce92e, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -3102,6 +3134,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 9eb62481994b51e4897a57499081c3db, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -3297,6 +3333,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175 (5)"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 9eb62481994b51e4897a57499081c3db, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -3521,6 +3561,10 @@ PrefabInstance:
propertyPath: side
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 9eb62481994b51e4897a57499081c3db, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: cardData
value:
@ -3741,6 +3785,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175 (1)"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: adc3952bb833a224895877477b4ce92e, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: standingCell
value:
@ -3811,6 +3859,10 @@ PrefabInstance:
propertyPath: m_Name
value: "\u5C0F\u5175"
objectReference: {fileID: 0}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: baseData
value:
objectReference: {fileID: 11400000, guid: 5d7c6bbedeba24e4f98ea1ca65fc5c0a, type: 2}
- target: {fileID: 2394601694276102747, guid: 81eab03836e5b52448e4ad61de8f2406, type: 3}
propertyPath: standingCell
value:

41
Assets/Scripts/Ability.cs Normal file
View File

@ -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 OnPlaceUnit(Unit unit) { }
public virtual void OnBeginRound(Unit unit) { }
public virtual void OnEndRound(Unit unit) { }
public virtual void OnBeginMovePhase(Unit unit) { }
public virtual void OnMove(Unit unit, int travelDistance) { }
public virtual void OnEndMovePhase(Unit unit) { }
public virtual void OnBeginAttackPhase(Unit unit) { }
public virtual void OnBeginAttack(Unit unit, List<Unit> targets) { }
public virtual void OnAttack(Unit unit, List<Unit> targets) { }
public virtual void OnEndAttack(Unit unit, List<Unit> targets) { }
public virtual void OnEndAttackPhase(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 OnCastStragedy(List<Unit> targets) { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27a2e411b169b994891c431e7a183368
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bebb282b5d98d3649bcb4e43de3f2de3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1bc96940f74c4ce4581f5cdec90d1e0b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e099c37da90ac1b46ac0a5ee6f79f507
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "InfantryClass", menuName = "Card Class/Infantry Class Data")]
public class InfantryClass : UnitClass
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 52ce9ab65798e6c46a62ac364d881763
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}

View File

@ -7,6 +7,4 @@ public class CardTag : ScriptableObject
{
public new string name;
public string description;
public Sprite artwork;
}

View File

@ -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()
{
@ -42,4 +41,9 @@ public class CellMap : MonoBehaviour
{
return cellMapData[y].cells[x];
}
public bool IsCellEmpty(int x, int y)
{
return GetCell(x, y).standingUnit == null;
}
}

View File

@ -0,0 +1,162 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Left is Player, right is enemy.
public enum Side { left = 1, right = -1 }
public class CombatManager : MonoBehaviour
{
[SerializeField] private List<Unit> leftSideUnits = new List<Unit>();
[SerializeField] private List<Unit> rightSideUnits = new List<Unit>();
[SerializeField] private CellMap cellMap;
// Start is called before the first frame update
void Start()
{
// hack
cellMap = FindObjectOfType<CellMap>();
foreach (var unit in rightSideUnits)
{
foreach (var ability in unit.Abilities)
{
ability.OnPlaceUnit(unit);
}
}
foreach (var unit in rightSideUnits)
{
foreach (var ability in unit.Abilities)
{
ability.OnEnterBattleGround(unit);
}
}
}
List<Unit> QueryTargets(Unit attacker)
{
// TO DO:
return new List<Unit>();
}
// Called once before drawing cards
void BeginFight()
{
}
void BeginRound(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnBeginRound(unit);
}
}
}
void BeginMovePhase(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnBeginMovePhase(unit);
}
}
}
void EndMovePhase(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnEndMovePhase(unit);
}
}
}
void BeginAttackPhase(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnBeginAttackPhase(unit);
}
}
}
void UnitAttack(Unit unit, List<Unit> targets)
{
foreach (var ability in unit.Abilities)
{
ability.OnBeginAttack(unit, targets);
}
foreach (var ability in unit.Abilities)
{
ability.OnAttack(unit, targets);
}
foreach (var ability in unit.Abilities)
{
ability.OnEndAttack(unit, targets);
}
foreach (var target in targets)
{
foreach (var ability in target.Abilities)
{
ability.OnCounterAttack(target, unit);
}
}
}
void Attack(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
UnitAttack(unit, QueryTargets(unit));
}
}
void EndAttackPhase(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnEndAttackPhase(unit);
}
}
}
void EndRound(Side side)
{
List<Unit> units = side == Side.left ? leftSideUnits : rightSideUnits;
foreach (var unit in units)
{
foreach (var ability in unit.Abilities)
{
ability.OnEndRound(unit);
}
}
}
// Called once after result
void EndFight()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ab8c50f6a5fd9be488ffeb604ccbc9fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,13 +7,10 @@ using TMPro;
public enum CurrentCommand { defend, moveForward, retreat }
// Left is Player, Enemy is right.
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 +24,42 @@ public class Unit : MonoBehaviour
private int finalMaxDefense;
[SerializeField]
private CardTag[] cardTags;
private List<CardTag> cardTags;
[SerializeField]
private int attackRange = 1;
private List<UnitClass> unitClasses;
[SerializeField]
private List<Ability> abilities;
public List<Ability> Abilities
{
get { return abilities; }
set { abilities = value; }
}
[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 +80,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 +93,19 @@ 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();
abilities = baseData.abilities.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<SpriteRenderer>().sprite = cardData.artwork;
modelArt.GetComponent<SpriteRenderer>().sprite = baseData.artwork;
var camps = FindObjectsOfType<Camp>();
foreach (var camp in camps)
@ -94,8 +121,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 +140,22 @@ public class Unit : MonoBehaviour
//Debug.Log("Arrived.");
}
}
}
finalAttack = basicAttack; // For now.
void UpdateText()
{
attackText.GetComponent<TextMeshProUGUI>().text = finalAttack.ToString();
defenseText.GetComponent<TextMeshProUGUI>().text = currentDefense.ToString();
}
// Update is called once per frame
void Update()
{
UpdateAnimation();
finalAttack = basicAttack; // For now.
UpdateText();
}
public void MoveAndAttack()
{
MoveAction();
@ -133,39 +168,34 @@ public class Unit : MonoBehaviour
{
return;
}
foreach (var tag in cardData.cardTags)
// hack
if (rangedAttackRange > 0)
{
if (tag.name == "Archer")
for (int i = 0; i < rangedAttackRange; ++i)
{
for (int i = 0; i < attackRange; ++i)
int attackXPos = standingCell.xPos + (i + 1) * (int)side;
if (attackXPos >= cellMap.column || attackXPos < 0)
{
int attackXPos = standingCell.xPos + (i + 1) * (int)side;
if (attackXPos >= cellMap.column || attackXPos < 0)
// Attack Camp
currentCommand = CurrentCommand.defend;
break;
}
Cell nextCellInRange = cellMap.GetCell(attackXPos, standingCell.yPos);
Unit targetUnit = nextCellInRange.standingUnit;
if (targetUnit)
{
if (targetUnit.side != side)
{
// Attack Camp
// Add units to attack list.
currentCommand = CurrentCommand.defend;
break;
}
Cell nextCellInRange = cellMap.GetCell(attackXPos, standingCell.yPos);
Unit targetUnit = nextCellInRange.standingUnit;
if (targetUnit)
{
if (targetUnit.side != side)
{
// Add units to attack list.
currentCommand = CurrentCommand.defend;
break;
}
}
currentCommand = CurrentCommand.moveForward;
}
break;
currentCommand = CurrentCommand.moveForward;
}
}
//Debug.Log("Call MoveAction().");
switch (currentCommand)
{
@ -233,21 +263,14 @@ public class Unit : MonoBehaviour
public void AttackAction()
{
// Check Attack Range
if (inDogFight(this))
// Check if this unit is ranged unit
if (rangedAttackRange > 0)
{
foreach (var tag in cardData.cardTags)
{
if (tag.name == "Archer")
{
// Archer can't dog fight.
return;
}
}
return;
}
List<Unit> unitsInRange = new List<Unit>();
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 +330,6 @@ public class Unit : MonoBehaviour
}
}
public bool isUnitAlive()
{
return currentDefense > 0;
}
bool checkDestinationCellEmpty(bool retreat = false)
{
int currentXPos = standingCell.xPos;

View File

@ -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) { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7d6c417b0c9236b4a915f410e56db822
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -25,12 +25,6 @@ public class UnitManager : MonoBehaviour
}
}
// Update is called once per frame
void Update()
{
}
public void handleDiedUnit(Unit unit)
{
if (unit.side == Side.left)
@ -39,7 +33,7 @@ public class UnitManager : MonoBehaviour
}
else if (unit.side == Side.right)
{
leftSideUnits.Remove(unit);
rightSideUnits.Remove(unit);
}
}