-
Notifications
You must be signed in to change notification settings - Fork 3
Splash damage #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
1f354aa
6db46c2
e7cd2fa
7cf3a3d
66c3d6e
5c2cc11
a84078e
86fa2ab
ff11530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ""; | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uma pequena melhoria aqui seria comparar as distancias ao quadrado com |
||
{ | ||
var damageable = enemy.GetComponent<IDamageable>(); | ||
if (damageable != null) | ||
{ | ||
damageables.Add(damageable); | ||
} | ||
} | ||
|
||
} | ||
return damageables; | ||
|
||
} | ||
|
||
protected override void Awake() | ||
{ | ||
|
@@ -62,7 +101,11 @@ void Update() | |
_attackTimer += Time.deltaTime; | ||
if (_attackTimer > CooldownInSeconds) | ||
{ | ||
Attack(); | ||
if(isAreaAttack){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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; | ||
} | ||
} | ||
|
@@ -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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
{ | ||
public enum CardType | ||
{ | ||
Warrior | ||
Warrior, | ||
SplashDamage | ||
} | ||
} |
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} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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 chamarmyTeam.Opposite()
que este método retornará o time oposto.