-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlash.lua
More file actions
117 lines (105 loc) · 4.42 KB
/
Flash.lua
File metadata and controls
117 lines (105 loc) · 4.42 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
function Create(self)
self.fireVel = 17;
self.spread = math.rad(self.ShakeRange);
self.searchRange = 100 + FrameMan.PlayerScreenWidth * 0.3;
self.searchTimer = Timer();
self.searchTimer:SetSimTimeLimitMS(250);
self.lockThreshold = 2;
self.targets = {};
self.targetLockSound = CreateSoundContainer("Mine Activate", "Base.rte");
end
function OnFire(self)
local rocketNumber = self.RoundInMagCount + 1;
local rocket = CreateAEmitter("Particle Browncoat Rocket", "Browncoats.rte");
if #self.targets > 0 then
if self.targets[rocketNumber] and self.targets[rocketNumber].actor.ID ~= rte.NoMOID then
rocket:SetNumberValue("TargetID", self.targets[rocketNumber].actor.ID);
self.targets[rocketNumber].topLeft = self.targets[rocketNumber].topLeft * 1.5;
self.targets[rocketNumber].bottomRight = self.targets[rocketNumber].bottomRight * 1.5;
elseif rocketNumber > #self.targets then
rocket:SetNumberValue("TargetID", self.targets[math.random(#self.targets)].actor.ID);
end
end
rocket.Pos = self.MuzzlePos + Vector(0, (rocketNumber - self.RoundInMagCapacity * 0.5)):RadRotate(self.RotAngle);
rocket.Vel = self.Vel + Vector(self.fireVel * RangeRand(0.9, 1.1) * self.FlipFactor, 0):RadRotate(self.RotAngle - ((self.spread * 0.5) - (rocketNumber/self.RoundInMagCapacity) * self.spread) * self.FlipFactor);
rocket.RotAngle = rocket.Vel.AbsRadAngle;
rocket.AngularVel = math.cos(rocket.Vel.AbsRadAngle) * 5;
rocket.Team = self.Team;
rocket.IgnoresTeamHits = true;
MovableMan:AddParticle(rocket);
end
function ThreadedUpdate(self)
local parent = self:GetRootParent();
if IsActor(parent) then
parent = ToActor(parent);
local controller = parent:GetController();
if self.Magazine then
if self:DoneReloading() then
self.targets = {};
end
if self.Magazine.RoundCount > 0 then
if controller:IsState(Controller.AIM_SHARP) then
if self.searchTimer:IsPastSimTimeLimit() then
self.searchTimer:Reset();
local searchPos = parent.ViewPoint;
local lastTargetCount = #self.targets;
self.targets = {};
for actor in MovableMan.Actors do
if #self.targets < self.RoundInMagCapacity and actor.Team ~= self.Team and actor.GetsHitByMOs then
if (SceneMan:ShortestDistance(searchPos, actor.Pos, SceneMan.SceneWrapsX).Magnitude - actor.Radius) < self.searchRange
and (actor.Vel.Magnitude + math.abs(actor.AngularVel) + 1)/math.sqrt(actor.Radius) < self.lockThreshold
and SceneMan:CastObstacleRay(searchPos, SceneMan:ShortestDistance(searchPos, actor.Pos, SceneMan.SceneWrapsX), Vector(), Vector(), actor.ID, actor.Team, rte.airID, 10) < 0 then
--Measure the approximate corners of a box that the Actor is supposedly inside of
local topLeft = Vector(-actor.IndividualRadius, -actor.IndividualRadius);
local bottomRight = Vector(actor.IndividualRadius, actor.IndividualRadius);
for att in actor.Attachables do
if IsAttachable(att) then
local dist = SceneMan:ShortestDistance(actor.Pos, att.Pos, SceneMan.SceneWrapsX);
local reach = dist:SetMagnitude(dist.Magnitude + math.sqrt(att.Diameter));
if reach.X < topLeft.X then
topLeft.X = reach.X;
elseif reach.X > bottomRight.X then
bottomRight.X = reach.X;
end
if reach.Y < topLeft.Y then
topLeft.Y = reach.Y;
elseif reach.Y > bottomRight.Y then
bottomRight.Y = reach.Y;
end
end
end
table.insert(self.targets, {actor = actor, topLeft = topLeft, bottomRight = bottomRight});
end
end
end
if lastTargetCount < #self.targets then
self.targetLockSound:Play(self.Pos);
end
end
else
self.searchTimer:Reset();
end
else
self:Reload();
end
end
if parent:IsPlayerControlled() then
for _, target in pairs(self.targets) do
if target.actor and target.actor.ID ~= rte.NoMOID then
local screen = ActivityMan:GetActivity():ScreenOfPlayer(ToActor(parent):GetController().Player);
PrimitiveMan:DrawBoxPrimitive(screen, target.actor.Pos + target.topLeft, target.actor.Pos + target.bottomRight, 149);
if self.RoundInMagCount == 0 then
target.topLeft = target.topLeft * 0.9;
target.bottomRight = target.bottomRight * 0.9;
end
end
end
end
if controller:IsState(Controller.PIE_MENU_ACTIVE) then
self.targets = {};
end
else
parent = nil;
self.targets = {};
end
end