Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Assets/Data/Metagame/Items/Editor/*.csv.meta
# Visual Studio cache directory
.vs/
.history
.vscode/

# Gradle cache directory
.gradle/
Expand Down
4 changes: 4 additions & 0 deletions Assets/Card TCG Design 6/PNG/card/elements/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ViewState]
Mode=
Vid=
FolderType=Generic

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions Assets/Card TCG Design 6/PNG/cover/cover/eye_6.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion Assets/Gameplay/Behaviours/AttackBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,45 @@ public class AttackBehaviour : BaseBehaviour
bool HasValidTarget => CurrentTarget != null;

float _attackTimer = 0;
public bool isAreaAttack = false;

public float distanceSplashDamage = 3;
private List<IDamageable> getEnemies()
{
var myTeam = Entity.Team;
var enemyTeam = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui a gente pode usar um método de extensão do enum Team que já tá implementado no Team.cs. Basta chamar myTeam.Opposite() que este método retornará o time oposto.


switch (myTeam)
{
case Team.Home:
enemyTeam = "Visitor";
break;
case Team.Visitor:
enemyTeam = "Home";
break;
default:
break;
}

var enemies = GameObject.FindGameObjectsWithTag(enemyTeam);

var damageables = new List<IDamageable>();

foreach (var enemy in enemies)
{
if (Vector3.Distance(transform.position, enemy.transform.position) <= distanceSplashDamage)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uma pequena melhoria aqui seria comparar as distancias ao quadrado com (transform.position - enemy.transform.position).sqrMagnitude <= distanceSplashDamage * distanceSplashDamage com o ponto positivo de melhoria de performance por não ter que usar o método de raiz quadrada (internamente no Distance) que é razoavelmente mais lento que a comparação que eu sugeri, o que geralmente é importante na parte relacionada ao gameplay. Embora aqui não seja crítico dado que essa parte do código vai ser executada poucas vezes, quis aproveitar pra mostrar esse pequeno truque

{
var damageable = enemy.GetComponent<IDamageable>();
if (damageable != null)
{
damageables.Add(damageable);
}
}

}
return damageables;

}

protected override void Awake()
{
Expand Down Expand Up @@ -62,7 +101,11 @@ void Update()
_attackTimer += Time.deltaTime;
if (_attackTimer > CooldownInSeconds)
{
Attack();
if(isAreaAttack){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meninas, em primeiro lugar, parabéns! O código do splash damage está certo! Porém, uma crítica construtiva é a de que ele está no lugar errado.

Vou tentar esclarecer os problemas da implementação atual: imaginem que queremos criar um novo tipo de ataque com mecânica de knockback (empurra o alvo pra trás). Seguindo o modelo atual, nós teríamos que fazer uma nova variável booleana isKnockbackAttack e chegando aqui, faríamos if (isKnockbackAttack) { KnockbackAttack(); }

O problema é: e se quisermos uma carta que tenha splash damage E knockback? A gente começaria a ter problemas pq os diferentes ataques que deveriam se comportar como plugins vão ter que saber como o outro funciona.

Como eu disse, o código está certo, só está no lugar errado (na minha opinião)! O ideal seria criarmos uma nova classe pra esse novo ataque (por exemplo: SplashDamageAttackBehaviour) e movermos essa lógica pra lá. Essa nova classe implementa a interface IAttacker. Dessa forma, o AttackBehaviour vai acionar o método Attack do SplashDamageAttackBehaviour sempre que atacar um alvo, sem saber de seus detalhes de implementação (ele só armazena uma lista de IAttackers que cacheia em sua inicialização).

Daí entra a ideia de uma "arquitetura de plugins": quando quisermos criar uma nova mecânica de ataque, basta criarmos um script de ataque que implementa a interface IAttacker e nem vamos precisar mexer no AttackBehaviour, que tem única responsabilidade de acionar os behaviours de ataque (scripts que implementam o IAttacker).

Me avisem se tiver ficado confuso ou se discordarem de algo :)

Obs: tô muito feliz com o resultado, parabéns de novo!

AreaAttack();
} else {
Attack();
}
_attackTimer = 0f;
}
}
Expand All @@ -74,6 +117,14 @@ void Attack()
_attackers.ForEach(action: attacker => attacker.Attack(CurrentTarget));
}

void AreaAttack() {
var enemies = getEnemies();
foreach (var enemy in enemies)
{
enemy.ScheduleDamage(damage);

}
}
void ChooseTarget()
{
if (HasValidTarget)
Expand Down
3 changes: 2 additions & 1 deletion Assets/Gameplay/Behaviours/UI/CardView.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ MonoBehaviour:
rect: {fileID: 1234890418332635619}
imageCard: {fileID: 7843744602157141522}
cardSprites:
m_keys: 00000000
m_keys: 0000000001000000
m_values:
- {fileID: 21300000, guid: 9b7223aa726eb41ee9f4349249340e9b, type: 3}
- {fileID: 21300000, guid: 23ebed2390aa23d4f863a4ea731c3197, type: 3}
--- !u!114 &8570471700893772512
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
3 changes: 2 additions & 1 deletion Assets/Gameplay/Core/Cards/CardPrefabsMap.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
cardPrefabDict:
m_keys: 00000000
m_keys: 0000000001000000
m_values:
- {fileID: 3274150517216157666, guid: 77cd19d9dee0340bc973086d5d3a567c, type: 3}
- {fileID: 3615646017921554434, guid: 2087384702dcd44b39e1a49f38502dc3, type: 3}
3 changes: 2 additions & 1 deletion Assets/Gameplay/Core/Cards/CardType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum CardType
{
Warrior
Warrior,
SplashDamage
}
}
71 changes: 71 additions & 0 deletions Assets/Gameplay/Core/Cards/Mage.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &4208324368316942175
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3274150517216157666, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_Name
value: Warrior
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5836261650095805016, guid: 77cd19d9dee0340bc973086d5d3a567c,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 77cd19d9dee0340bc973086d5d3a567c, type: 3}
7 changes: 7 additions & 0 deletions Assets/Gameplay/Core/Cards/Mage.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading