Skip to content

Commit

Permalink
Merge branch 'development' into lua-writable-collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Dec 7, 2024
2 parents d839f65 + 186d4c8 commit 2f2d38a
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 62 deletions.
4 changes: 0 additions & 4 deletions Data/Base.rte/Devices/Shared/Scripts/MuzzleSmoke.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function Create(self)

if self.Magazine then
local particleCount = self.Magazine.NextRound.ParticleCount;
local particleMass = self.Magazine.NextRound.NextParticle.Mass;
Expand Down Expand Up @@ -30,16 +29,13 @@ function Create(self)
self.fireSmokeEffect.GravMult = 1;

self.particleUtility = require("Scripts/Utility/ParticleUtility");

end

function OnFire(self)

local flip = self.HFlipped and math.pi or 0;
local angle = self.RotAngle + flip;
self.fireSmokeEffect.Position = self.MuzzlePos;
self.fireSmokeEffect.RadAngle = angle;

self.particleUtility:CreateDirectionalSmokeEffect(self.fireSmokeEffect);

end
15 changes: 13 additions & 2 deletions Data/Base.rte/Devices/Shared/Scripts/RevolverCylinderReload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ function Create(self)
self.shellMOSRotating = self:StringValueExists("CylinderShellMOSRotating") and self:GetStringValue("CylinderShellMOSRotating") or nil;
end

function Update(self)
function ThreadedUpdate(self)
if self.Magazine then
self.shellsToEject = self.Magazine.Capacity - self.Magazine.RoundCount;
elseif self.shellsToEject > 0 then
self.ejectingShells = {};
for i = 1, self.shellsToEject do
local shell = self.shellMOSRotating and CreateMOSRotating(self.shellMOSRotating) or CreateMOSParticle(self.shellMOSParticle);
shell.Pos = self.Pos;
shell.Vel = self.Vel + Vector(RangeRand(-3, 0) * self.FlipFactor, 0):RadRotate(self.RotAngle + RangeRand(-0.3, 0.3));
shell.AngularVel = RangeRand(-1, 1);
MovableMan:AddParticle(shell);
table.insert(self.ejectingShells, shell);
end

self.shellsToEject = 0;
self:RequestSyncedUpdate();
end
end

function SyncedUpdate(self)
if self.ejectingShells then
for i = 1, #self.ejectingShells do
MovableMan:AddParticle(self.ejectingShells[i]);
end
self.ejectingShells = nil;
end
end
2 changes: 0 additions & 2 deletions Data/Browncoats.rte/Devices/Weapons/Extinction/Extinction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function Create(self)

-- for some reason if this is added to sim while facing leftwards, StanceOffset will actually be flipped.
-- but not sharpstanceoffset...............


self.origStanceOffset = Vector(self.StanceOffset.X*self.FlipFactor, self.StanceOffset.Y);
self.origSharpStanceOffset = Vector(self.SharpStanceOffset.X, self.SharpStanceOffset.Y);

Expand Down
26 changes: 17 additions & 9 deletions Data/Browncoats.rte/Devices/Weapons/Flash/Flash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function Create(self)

self.targetLockSound = CreateSoundContainer("Mine Activate", "Base.rte");
end
function Update(self)

function ThreadedUpdate(self)
local parent = self:GetRootParent();
if IsActor(parent) then
parent = ToActor(parent);
Expand Down Expand Up @@ -91,10 +92,11 @@ function Update(self)
parent = nil;
self.targets = {};
end

if self.FiredFrame then
local rocketNumber = self.RoundInMagCount + 1;

local rocket = CreateAEmitter("Particle Browncoat Rocket", "Browncoats.rte");
self.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);
Expand All @@ -104,12 +106,18 @@ function Update(self)
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);
self.rocket.Pos = self.MuzzlePos + Vector(0, (rocketNumber - self.RoundInMagCapacity * 0.5)):RadRotate(self.RotAngle);
self.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);
self.rocket.RotAngle = rocket.Vel.AbsRadAngle;
self.rocket.AngularVel = math.cos(rocket.Vel.AbsRadAngle) * 5;
self.rocket.Team = self.Team;
self.rocket.IgnoresTeamHits = true;
end
end

function SyncedUpdate(self)
if self.rocket then
MovableMan:AddParticle(self.rocket);
self.rocket = nil;
end
end
56 changes: 37 additions & 19 deletions Data/Dummy.rte/Devices/Weapons/Destroyer/DestroyerCannon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Create(self)
self.activeSound = CreateSoundContainer("Destroyer Emission Sound", "Dummy.rte");
end

function Update(self)
function ThreadedUpdate(self)
if self.Magazine then
if self.inventorySwapTimer:IsPastSimTimeLimit() then
self.activeSound:Stop();
Expand All @@ -28,18 +28,18 @@ function Update(self)
self.animTimer:Reset();
self.Frame = self.Frame < (self.FrameCount - 1) and self.Frame + 1 or 0;
if self.Frame == 1 then
local effect = CreateMOPixel("Destroyer Muzzle Glow");
effect.Pos = self.MuzzlePos;
effect.Vel = self.Vel * 0.5;
MovableMan:AddParticle(effect);

local damagePar = CreateMOPixel("Dummy.rte/Destroyer Emission Particle 2");
damagePar.Pos = self.MuzzlePos;
damagePar.Vel = self.Vel * 0.5 + Vector(math.random(5) * (1 + self.charge), 0):RadRotate(6.28 * math.random());
damagePar.Team = self.Team;
damagePar.IgnoresTeamHits = true;
damagePar.Lifetime = 100 * (1 + self.charge);
MovableMan:AddParticle(damagePar);
self.effect = CreateMOPixel("Destroyer Muzzle Glow");
self.effect.Pos = self.MuzzlePos;
self.effect.Vel = self.Vel * 0.5;

self.damagePar = CreateMOPixel("Dummy.rte/Destroyer Emission Particle 2");
self.damagePar.Pos = self.MuzzlePos;
self.damagePar.Vel = self.Vel * 0.5 + Vector(math.random(5) * (1 + self.charge), 0):RadRotate(6.28 * math.random());
self.damagePar.Team = self.Team;
self.damagePar.IgnoresTeamHits = true;
self.damagePar.Lifetime = 100 * (1 + self.charge);

self:RequestSyncedUpdate();
end
end

Expand Down Expand Up @@ -83,13 +83,14 @@ function Update(self)
else
self.Frame = 0;
end

if self.FiredFrame then
local par = CreateAEmitter("Destroyer Cannon Shot");
par.Team = self.Team;
par.IgnoresTeamHits = true;
par.Pos = self.MuzzlePos;
par.Vel = Vector((self.minFireVel + (self.maxFireVel - self.minFireVel) * self.charge) * self.FlipFactor, 0):RadRotate(self.RotAngle);
MovableMan:AddParticle(par);
self.par = CreateAEmitter("Destroyer Cannon Shot");
self.par.Team = self.Team;
self.par.IgnoresTeamHits = true;
self.par.Pos = self.MuzzlePos;
self.par.Vel = Vector((self.minFireVel + (self.maxFireVel - self.minFireVel) * self.charge) * self.FlipFactor, 0):RadRotate(self.RotAngle);
self:RequestSyncedUpdate();

self.charge = 0;
self.activeSound:Stop();
Expand All @@ -98,6 +99,23 @@ function Update(self)
end
end

function SyncedUpdate(self)
if self.effect then
MovableMan:AddParticle(self.effect);
self.effect = nil;
end

if self.damagePar then
MovableMan:AddParticle(self.par);
self.damagePar = nil;
end

if self.par then
MovableMan:AddParticle(self.par);
self.par = nil;
end
end

function Destroy(self)
self.activeSound:Stop();
end
3 changes: 2 additions & 1 deletion Data/Dummy.rte/Devices/Weapons/Repeater/RepeaterShot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ function Create(self)
self.endPar = CreateMOSParticle("Tiny Smoke Ball 1 Glow Yellow");
end

function Update(self)
function ThreadedUpdate(self)
if not self.ToDelete then
-- Touching other things in non-synced update is bad, but because we know that nothing else is gonna be running scripts on it, we can get away with this
for i = 1, self.trailParCount do
if self.trailPar[i] and MovableMan:IsParticle(self.trailPar[i]) then
self.trailPar[i].Pos = self.Pos + Vector(RangeRand(-0.5, 0.5), RangeRand(-0.5, 0.5)) - Vector(self.PrevVel.X, self.PrevVel.Y):SetMagnitude(math.min(self.PrevVel.Magnitude, self.trailLength + 1) * i/self.trailParCount);
Expand Down
2 changes: 1 addition & 1 deletion Data/Imperatus.rte/Devices/Weapons/Marauder/Marauder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function Create(self)
self.fireTimer = Timer();
end

function Update(self)
function ThreadedUpdate(self)
if self.FiredFrame or self:IsReloading() then
self.fireTimer:Reset();
end
Expand Down
17 changes: 12 additions & 5 deletions Data/Ronin.rte/Devices/Weapons/357Magnum/357Magnum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Create(self)
self.drawGun = false;
end

function Update(self)
function ThreadedUpdate(self)
--Read RateOfFire on Update() to take Global Scripts to account
if self.rof == nil then
self.rof = self.RateOfFire;
Expand All @@ -17,12 +17,9 @@ function Update(self)
self:SetOneHanded(false);
self:SetDualWieldable(false);
if MovableMan:IsOfActor(self.ID) then
actor = ToActor(MovableMan:GetMOFromID(self.RootID));
local actor = ToActor(MovableMan:GetMOFromID(self.RootID));

ToActor(actor):GetController():SetState(Controller.AIM_SHARP, false);
ToActor(actor):GetController():SetState(Controller.BODY_PRONE, false);
if ToActor(actor):GetController():IsState(Controller.WEAPON_FIRE) then

if self:GetNumberValue("CowboyMode") < 3 then
self:Deactivate();
self.triggerPulled = true;
Expand Down Expand Up @@ -94,4 +91,14 @@ function Update(self)
self.StanceOffset = Vector(12, 0);
self.drawGunAngle = 0;
end
end

function SyncedUpdate(self)
if self:NumberValueExists("CowboyMode") then
if MovableMan:IsOfActor(self.ID) then
local actor = ToActor(MovableMan:GetMOFromID(self.RootID));
ToActor(actor):GetController():SetState(Controller.AIM_SHARP, false);
ToActor(actor):GetController():SetState(Controller.BODY_PRONE, false);
end
end
end
12 changes: 9 additions & 3 deletions Data/Ronin.rte/Devices/Weapons/K98K/K98K.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Create(self)
self.boltPullSound = CreateSoundContainer("Ronin Kar98 Bolt Pull Sound", "Ronin.rte");
end

function Update(self)
function ThreadedUpdate(self)
local parent;
local actor = self:GetRootParent();
if actor and IsAHuman(actor) then
Expand All @@ -30,8 +30,7 @@ function Update(self)
self.shell.Pos = self.Pos;
self.shell.Vel = self.Vel + Vector(-6 * self.FlipFactor, -4):RadRotate(self.RotAngle);
self.shell.Team = self.Team;
MovableMan:AddParticle(self.shell);
self.shell = nil;
self.RequestSyncedUpdate();
end

--Animate the gun to signify the bolt being pulled
Expand All @@ -55,4 +54,11 @@ function Update(self)
else
self.pullTimer:Reset();
end
end

function SyncedUpdate(self)
if self.shell then
MovableMan:AddParticle(self.shell);
self.shell = nil;
end;
end
12 changes: 9 additions & 3 deletions Data/Ronin.rte/Devices/Weapons/Model590/Model590.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Create(self)
self.cockSound = CreateSoundContainer("Ronin Model 590 Cock Sound", "Ronin.rte");
end

function Update(self)
function ThreadedUpdate(self)
local actor = self:GetRootParent();
if not (actor and IsAHuman(actor)) then
self.pullTimer:Reset();
Expand All @@ -29,8 +29,7 @@ function Update(self)
self.shell.Pos = self.Pos;
self.shell.Vel = self.Vel + Vector(-6 * self.FlipFactor, -4):RadRotate(self.RotAngle);
self.shell.Team = self.Team;
MovableMan:AddParticle(self.shell);
self.shell = nil;
self:RequestSyncedUpdate();
end
self.Frame = 1;
self.SupportOffset = Vector(-2, 4);
Expand All @@ -50,4 +49,11 @@ function Update(self)
else
self.pullTimer:Reset();
end
end

function SyncedUpdate(self)
if self.shell then
MovableMan:AddParticle(self.shell);
self.shell = nil;
end
end
2 changes: 1 addition & 1 deletion Data/Ronin.rte/Devices/Weapons/SPAS12/SPAS12.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Create(self)
self.cockSound = CreateSoundContainer("Ronin SPAS 12 Cock Sound", "Ronin.rte");
end

function Update(self)
function ThreadedUpdate(self)
local actor = self:GetRootParent();
if not (actor and IsAHuman(actor)) then
self.pullTimer:Reset();
Expand Down
17 changes: 12 additions & 5 deletions Data/Techion.rte/Devices/Weapons/GigaPulsar/GigaPulsar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ function Update(self)
self.lastMag.Sharpness = 1;
self.lastMag.Vel = self.lastMag.Vel + Vector(-10 * self.FlipFactor, 0):RadRotate(self.RotAngle);

local effect = self.ejectEffect:Clone();
effect.Pos = self.lastMag.Pos;
effect.RotAngle = self.RotAngle;
effect.HFlipped = self.HFlipped;
MovableMan:AddParticle(effect);
self.effect = self.ejectEffect:Clone();
self.effect.Pos = self.lastMag.Pos;
self.effect.RotAngle = self.RotAngle;
self.effect.HFlipped = self.HFlipped;
self:RequestSyncedUpdate();
end
end

self.dingSound = true;
end
end

function SyncedUpdate(self)
if self.effect then
MovableMan:AddParticle(self.effect);
self.effect = nil;
end
end
19 changes: 13 additions & 6 deletions Data/Techion.rte/Devices/Weapons/GigaPulsar/GigaPulsarMagazine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ function Create(self)
self.smokeDelay = 25;
end

function Update(self)
function ThreadedUpdate(self)
if self.Sharpness == 1 and self.smokeTimer:IsPastSimMS(self.smokeDelay) then
self.smokeTimer:Reset();
self.smokeDelay = self.smokeDelay * (1 + self.RoundCount/self.Capacity) + 1;

local smoke = CreateMOSParticle("Tiny Smoke Ball 1");
smoke.Pos = self.Pos + Vector(math.random(-1, 1), math.random(-1, 1));
smoke.Vel = self.Vel + Vector(RangeRand(-2, 2), RangeRand(-2, 2));
smoke.Lifetime = smoke.Lifetime * RangeRand(0.5, 1.0);
MovableMan:AddParticle(smoke);
self.smoke = CreateMOSParticle("Tiny Smoke Ball 1");
self.smoke.Pos = self.Pos + Vector(math.random(-1, 1), math.random(-1, 1));
self.smoke.Vel = self.Vel + Vector(RangeRand(-2, 2), RangeRand(-2, 2));
self.smoke.Lifetime = smoke.Lifetime * RangeRand(0.5, 1.0);
self:RequestSyncedUpdate();
end
end

function SyncedUpdate(self)
if self.smoke then
MovableMan:AddParticle(self.smoke);
self.smoke = nil;
end
end
Loading

0 comments on commit 2f2d38a

Please sign in to comment.