forked from PeterQStarlord/Core-Rescue
/
ReviverMonsterBrain.cs
104 lines (88 loc) · 2.82 KB
/
ReviverMonsterBrain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using UnityEngine;
using System.Collections;
public class ReviverMonsterBrain : BaseMonsterBrain {
public enum ReviveMonsterState
{
eMonsterStateAttacking,
eMonsterStateReviving,
}
ReviveMonsterState mOurState = ReviveMonsterState.eMonsterStateAttacking;
public override void UpdateDesiredMovePoint()
{
float distanceTo = 0f;
ReviveSpawns closest = GameController.GetClosestReviveSpawn(transform.position, ref distanceTo);
if (closest)
{
Vector3 dir = Vector3.Normalize(transform.position - closest.transform.position);
Vector3 desiredPos = (closest.transform.position) + (m_MonsterAttackDistance * dir);
m_DesiredMovePosition = desiredPos;
mOurState = ReviveMonsterState.eMonsterStateReviving;
return;
}
mOurState = ReviveMonsterState.eMonsterStateAttacking;
base.UpdateDesiredMovePoint();
}
public override void UpdateMonsterBrain()
{
UpdateDesiredMovePoint();
UpdateMonsterMove();
switch( mOurState )
{
case ReviveMonsterState.eMonsterStateReviving:
{
UpdateRevive();
break;
}
case ReviveMonsterState.eMonsterStateAttacking:
{
UpdateAttack();
break;
}
default:
break;
}
}
public float m_ReviveMonsterDistance = 3f;
public void OnReviveStart()
{
// We need to do an animation
if (m_AnimComponent)
{
m_AnimComponent.SetTrigger("ReviveSpell");
}
m_BrainActive = false;
// once we get the animation event back, we'll resume
}
public void OnAnimationEnd()
{
if( mOurState == ReviveMonsterState.eMonsterStateReviving )
{
float distanceTo = 0f;
ReviveSpawns closest = GameController.GetClosestReviveSpawn(transform.position, ref distanceTo);
if (!closest)
{
return;
}
closest.SpawnRevive();
m_BrainActive = true;
}
}
public void UpdateRevive()
{
float distanceTo = 0f;
ReviveSpawns closest = GameController.GetClosestReviveSpawn(transform.position, ref distanceTo);
if (!closest)
{
mOurState = ReviveMonsterState.eMonsterStateAttacking;
return;
}
if( distanceTo <= m_ReviveMonsterDistance )
{
OnReviveStart();
}
}
public override void SetAttackingState(bool attacking)
{
//base.SetAttackingState(attacking);
}
}