forked from Da-Teach/Questor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Defense.cs
98 lines (84 loc) · 3.9 KB
/
Defense.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
// ------------------------------------------------------------------------------
// <copyright from='2010' to='2015' company='THEHACKERWITHIN.COM'>
// Copyright (c) TheHackerWithin.COM. All Rights Reserved.
//
// Please look in the accompanying license.htm file for the license that
// applies to this source code. (a copy can also be found at:
// http://www.thehackerwithin.com/license.htm)
// </copyright>
// -------------------------------------------------------------------------------
namespace Questor.Modules
{
using System.Linq;
public class Defense
{
private void ActivateOnce()
{
foreach (var module in Cache.Instance.Modules)
{
if (!module.IsActivatable)
continue;
var activate = false;
activate |= module.GroupId == (int) Group.ShieldHardeners;
activate |= module.GroupId == (int) Group.DamageControl;
activate |= module.GroupId == (int) Group.ArmorHardeners;
activate |= module.GroupId == (int) Group.SensorBooster;
activate |= module.GroupId == (int) Group.TrackingComputer;
activate |= module.GroupId == (int) Group.ECCM;
if (!activate)
continue;
if (module.IsActive)
continue;
module.Activate();
}
}
private void ActivateRepairModules()
{
foreach (var module in Cache.Instance.Modules)
{
double perc;
if (module.GroupId == (int) Group.ShieldBoosters)
perc = Cache.Instance.DirectEve.ActiveShip.ShieldPercentage;
else if (module.GroupId == (int) Group.ArmorRepairer)
perc = Cache.Instance.DirectEve.ActiveShip.ArmorPercentage;
else
continue;
var inCombat = Cache.Instance.TargetedBy.Count() > 0;
if (!module.IsActive && !module.IsDeactivating && ((inCombat && perc < Settings.Instance.ActivateRepairModules) || (!inCombat && perc < Settings.Instance.DeactivateRepairModules && Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage > Settings.Instance.SafeCapacitorPct)))
module.Activate();
else if (module.IsActive && !module.IsDeactivating && perc >= Settings.Instance.DeactivateRepairModules)
module.Deactivate();
}
}
private void ActivateAfterburner()
{
foreach (var module in Cache.Instance.Modules)
{
if (module.GroupId != (int) Group.Afterburner)
continue;
if (Cache.Instance.Approaching != null && !module.IsActive && !module.IsDeactivating)
module.Activate();
else if (Cache.Instance.Approaching == null && module.IsActive && !module.IsDeactivating && (!Cache.Instance.Entities.Any(e => e.IsAttacking) || !Settings.Instance.SpeedTank))
module.Deactivate();
}
}
public void ProcessState()
{
// Thank god stations are safe ! :)
if (Cache.Instance.InStation)
return;
// What? No ship entity?
if (Cache.Instance.DirectEve.ActiveShip.Entity == null)
return;
// There is no better defense then being cloaked ;)
if (Cache.Instance.DirectEve.ActiveShip.Entity.IsCloaked)
return;
// Cap is SO low that we shouldn't care about hardeners/boosters as we arent being targeted anyhow
if (Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage < 10 && Cache.Instance.TargetedBy.Count() == 0)
return;
ActivateOnce();
ActivateRepairModules();
ActivateAfterburner();
}
}
}