This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
/
ZackRanged.cs
91 lines (87 loc) · 2.75 KB
/
ZackRanged.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
using System;
using Game.States;
using SevenEngine.Mathematics;
using SevenEngine.DataStructures;
using SevenEngine.StaticModels;
using SevenEngine.Imaging;
namespace Game.Units
{
public class ZackRanged : Ranged
{
Unit _target;
float _time = 0;
const float _delay = 4000;
public ZackRanged(string id, StaticModel staticModel) : base(id, staticModel) { _time = 0; }
public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
{
if (_time < _delay)
_time += elapsedTime;
if (IsDead == false)
{
// Targeting
if (_target == null || _target.IsDead)
{
float shortest = float.MaxValue;
octree.Traverse
(
(Unit current) =>
{
if (current is KillemKamakazi && !current.IsDead)
{
if (_target == null || _target.IsDead || !(_target is KillemKamakazi))
{
_target = current;
shortest = (current.Position - Position).Length;
}
else
{
float length = (current.Position - Position).Length;
if (length < shortest)
{
_target = current;
shortest = length;
}
}
}
else if ((current is KillemMelee || current is KillemRanged) && !current.IsDead)
{
if (_target == null || _target.IsDead)
{
_target = current;
shortest = (current.Position - Position).Length;
}
else
{
float length = (current.Position - Position).Length;
if (length < shortest)
{
_target = current;
shortest = length;
}
}
}
}
);
}
// Attacking
else if (Foundations.Abs((Position - _target.Position).Length) < _attackRange)
{
AiBattle.lines.Add(new Link3<Vector, Vector, Color>(
new Vector(Position.X, Position.Y, Position.Z),
new Vector(_target.Position.X, _target.Position.Y, _target.Position.Z),
Color.Yellow));
if (Attack(_target))
_target = null;
}
// Moving
else if (_time > _delay)
{
Vector direction = _target.Position - Position;
Position.X += (direction.X / direction.Length) * MoveSpeed;
Position.Y += (direction.Y / direction.Length) * MoveSpeed;
Position.Z += (direction.Z / direction.Length) * MoveSpeed;
}
}
}
}
}