Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------
- -- File : /mods/4DC_FAF_Release/lua/4D_defaultcollisionbeams.lua
- -- Author(s) : EbolaSoup, Resin Smoker, Optimus Prime, Vissroid, Eddy, Domino
- -- Copyright © 2015 4DC_FAF_Release, All rights reserved.
- ------------------------------------------------------------------------------
- local CollisionBeam = import('/lua/sim/CollisionBeam.lua').CollisionBeam
- local EffectTemplate = import('/lua/EffectTemplates.lua')
- local Custom_4D_EffectTemplate = import('/mods/4DC_FAF_Release/lua/4D_EffectTemplates.lua')
- local utilities = import('/lua/utilities.lua')
- EmtBpPath = '/effects/emitters/'
- ------------------------------
- -- Base class that defines all other 4DC beam types (Do not delete)
- ------------------------------
- CustomBeam = Class(CollisionBeam) {
- -- Default beam FX
- FxImpactUnit = EffectTemplate.DefaultProjectileLandUnitImpact,
- FxUnitHitScale = 0.3,
- FxImpactLand = EffectTemplate.DefaultProjectileLandImpact,
- FxLandHitScale = 0.3,
- FxImpactWater = EffectTemplate.DefaultProjectileWaterImpact,
- FxImpactUnderWater = EffectTemplate.DefaultProjectileUnderWaterImpact,
- FxImpactAirUnit = EffectTemplate.DefaultProjectileAirUnitImpact,
- FxImpactProp = {},
- FxImpactShield = {},
- FxImpactNone = {},
- OnImpact = function(self, impactType, targetEntity)
- local myDebug = false
- if myDebug then LOG('*** OnImpact ***') end
- if self then
- if impactType == 'Terrain' and self.ScorchSize then
- if self.Scorching == nil then
- self.Scorching = self:ForkThread( self.ScorchThread )
- end
- elseif not impactType == 'Unit' and self.ScorchSize then
- KillThread(self.Scorching)
- self.Scorching = nil
- end
- self.ImpactPos = self:GetPosition()
- CollisionBeam.OnImpact(self, impactType, targetEntity)
- end
- end,
- DoDamage = function(self, instigator, damageData, targetEntity)
- local myDebug = false
- if myDebug then LOG('*** DoDamage ***') end
- if self and damageData then
- if not instigator then
- instigator = self
- end
- if myDebug then LOG(' instigator: ', instigator:GetEntityId()) end
- if self.Weapon:GetBlueprint().ChainLighningSpec and targetEntity then
- if myDebug then LOG(' Calling Chain Lightning') end
- if self.ChainLightningThread then
- KillThread(self.ChainLightningThread)
- self.ChainLightningThread = nil
- end
- self.Bp = self.Weapon:GetBlueprint()
- self.ChainSpec = self.Bp.ChainLighningSpec
- self.ChainFx = {}
- self.DmgUnitsTable = {}
- self.ChainLightningThread = self:ForkThread( self.DoChainLightning, instigator, damageData, targetEntity )
- else
- if myDebug then LOG(' Normal beam, calling CollisionBeam.DoDamage') end
- CollisionBeam.DoDamage(self, instigator, damageData, targetEntity)
- end
- else
- if myDebug then LOG(' "self" or Damage.Data is Invalid') end
- end
- end,
- DoChainLightning = function(self, instigator, damageData, targetEntity)
- local myDebug = false
- if myDebug then LOG('*** DoChainLightning ***') end
- if myDebug then LOG(' instigator: ', instigator:GetEntityId()) end
- local army = self:GetArmy()
- local beamLifeTime
- if self.Bp.BeamLifetime > 0.25 then
- beamLifeTime = self.Bp.BeamLifetime
- elseif self.Bp.BeamCollisionDelay > 0.25 then
- beamLifeTime = self.Bp.BeamCollisionDelay
- else
- beamLifeTime = 0.25
- end
- if not self.ChainSpec.Forks or self.ChainSpec.Forks < 1 then
- self.ChainSpec.Forks = Random(2, 6)
- end
- if not self.ChainSpec.JumpRadius or self.ChainSpec.JumpRadius < 1 then
- self.ChainSpec.JumpRadius = Random(4, 10)
- end
- table.insert(self.DmgUnitsTable, targetEntity)
- local oldTarget = targetEntity
- local forkCounter = 1
- while self and forkCounter <= self.ChainSpec.Forks do
- if myDebug then LOG(' While do ForkLightning loop') end
- local targets = self:GetValidTargetsAlongScaledVector(instigator, oldTarget, (self.ChainSpec.JumpRadius))
- local tblSize = table.getsize(targets)
- if myDebug then LOG(' tblSize: ', tblSize) end
- if tblSize > 0 then
- local currentTarget
- if not self.ChainSpec.Branches or self.ChainSpec.Branches < 1 then
- self.ChainSpec.Branches = Random(2, 6)
- end
- for i = 1, self.ChainSpec.Branches do
- local ran = Random(1,tblSize)
- currentTarget = targets[ran].unit
- if currentTarget != nil and not currentTarget:BeenDestroyed() and currentTarget != instigator and currentTarget != targetEntity and currentTarget != oldTarget then
- if myDebug then LOG(' CurrentTarget Id: ', currentTarget.id) end
- self:ForkThread(self.ChainLightningFX, oldTarget, currentTarget, army, beamLifeTime)
- table.insert(self.DmgUnitsTable, currentTarget)
- end
- end
- oldTarget = currentTarget
- end
- targets = nil
- forkCounter = forkCounter + 1
- end
- local numTargets = table.getsize(self.DmgUnitsTable)
- if numTargets > 0 then
- if myDebug then
- for a, b in self.DmgUnitsTable do
- LOG(' unit to damage ID: ', b:GetEntityId())
- LOG(' instigator: ', instigator:GetEntityId())
- end
- end
- local dmgMod = damageData.DamageAmount
- if self.ChainSpec.DamageForm == 'Divide' then
- dmgMod = dmgMod / numTargets
- end
- if myDebug then LOG(' dmgMOD / units spread: ', repr(dmgMod), 'DamageForm: ', repr(self.ChainSpec.DamageForm)) end
- for a, b in self.DmgUnitsTable do
- if b and not b:BeenDestroyed() then
- Damage(instigator, self:GetPosition(), b, dmgMod, damageData.DamageType)
- end
- end
- end
- end,
- GetValidTargetsAlongScaledVector = function(self, instigator, oldTarget, scale)
- local myDebug = false
- if myDebug then LOG('GetValidTargetsAlongScaledVector') end
- if instigator and oldTarget and scale then
- --Get a list of avlaible targets in the direction the beam was originally fired
- local tPos = oldTarget:GetPosition()
- local vPos = utilities.GetScaledDirectionVector(tPos, self.ImpactPos, scale)
- local modPos = Vector(vPos[1] + tPos[1], tPos[2], vPos[3] + tPos[3])
- if myDebug then
- LOG('impact x: ', self.ImpactPos[1],'impact y: ', self.ImpactPos[2],'impact z: ', self.ImpactPos[3])
- LOG('tPos x: ', tPos[1],'tPos y: ', tPos[2],'tPos z: ', tPos[3])
- LOG('vPos x: ', vPos[1],'vPos y: ', vPos[2],'vPos z: ', vPos[3])
- LOG('modPos x: ', modPos[1],'modPos y: ', modPos[2],'modPos z: ', modPos[3], 'scale: ', scale)
- end
- --local targets = utilities.GetEnemyUnitsInSphere( self, modPos, scale )
- local targets = GetEntitiesInRect( Rect( modPos[1] - scale, modPos[3] - scale, modPos[1] + scale, modPos[3] + scale) )
- --Filter out targets we've already chained to if any
- if table.getsize(self.DmgUnitsTable) > 0 then
- for a, b in self.DmgUnitsTable do
- table.remove(targets, self.DmgUnitsTable[b])
- end
- end
- if myDebug then LOG(' Number of "filtered" targets found at range: ', scale, 'table size: ', table.getsize(targets)) end
- if table.getsize(targets) < 1 then return nil end
- --Sort the remaining targets by range
- local sortTargByDist = {}
- for a, b in targets do
- if not b:BeenDestroyed() and b:GetHealth() > 0 and b != instigator and b != oldTarget then
- table.insert(sortTargByDist, {dist = utilities.XZDistanceTwoVectors(self.ImpactPos, b:GetPosition()),id = b:GetEntityId() ,unit = b})
- end
- end
- table.sort(sortTargByDist, sort_by('dist'))
- if myDebug then
- LOG(' Number of sorted targets: ', table.getsize(sortTargByDist))
- for c, d in sortTargByDist do
- LOG(' Unit: ', d.id, ' Distance: ', utilities.XZDistanceTwoVectors(self.ImpactPos, d.unit:GetPosition()) )
- end
- end
- return sortTargByDist
- else
- if myDebug then LOG(' Data passed is missing or invalid, returning nil') end
- return nil
- end
- end,
- ChainLightningFX = function(self, target1, target2, army, duration)
- local myDebug = false
- if myDebug then LOG('*** ChainLightningFX ***') end
- for a, b in self.FxBeamEndPoint do
- if myDebug then LOG(' Impacts') end
- local fx = CreateAttachedEmitter(target2, -1, army, b ):ScaleEmitter(self.FxBeamEndPointScale)
- table.insert( self.BeamEffectsBag, fx)
- table.insert( self.ChainFx, fx)
- self.Trash:Add(fx)
- target2.Trash:Add(fx)
- end
- for c, d in self.FxBeam do
- if target1 and not target1:BeenDestroyed() and target2 and not target2:BeenDestroyed() then
- if myDebug then LOG(' Beams') end
- local beam = AttachBeamEntityToEntity(target1, -1, target2, -1, army, d)
- local offset = 0.1
- if IsUnit(target2) then
- offSet = (target2:GetBlueprint().Physics.SizeY or 1) / 2
- end
- beam:OffsetEmitter(0, offset, 0)
- table.insert(self.BeamEffectsBag, beam)
- table.insert(self.ChainFx, beam)
- self.Trash:Add(beam)
- target2.Trash:Add(beam)
- end
- end
- WaitSeconds(duration)
- if self.ChainFx then
- for e, f in self.ChainFx do
- f:Destroy()
- end
- end
- end,
- ScorchThread = function(self)
- local myDebug = false
- if myDebug then LOG('*** ScorchThread ***') end
- local army = self:GetArmy()
- local CurrentPosition = self:GetPosition(1)
- local LastPosition = Vector(0,0,0)
- local skipCount = 1
- while true do
- if utilities.GetDistanceBetweenTwoVectors( CurrentPosition, LastPosition ) > 0.25 or skipCount > 100 then
- local size = utilities.GetRandomFloat( -self.ScorchSize , self.ScorchSize )
- CreateSplat( CurrentPosition, utilities.GetRandomFloat(0,2*math.pi), self.ScorchTexture, size, size, 25, 25, army )
- LastPosition = CurrentPosition
- skipCount = 1
- else
- skipCount = skipCount + self.ScorchSplatDropTime
- end
- WaitSeconds( self.ScorchSplatDropTime or 0.1 )
- CurrentPosition = self:GetPosition(1)
- end
- end,
- OnDisable = function( self )
- local myDebug = false
- if myDebug then LOG('*** OnDisable ***') end
- CollisionBeam.OnDisable(self)
- KillThread(self.Scorching)
- KillThread(self.ChainLightningThread)
- self.Scorching = nil
- end,
- }
- ------------------------------
- -- Chain Lighting beam for the Seraphem transformable heavy bot
- ------------------------------
- xsl0310_LightningBeam = Class(CustomBeam) {
- FxBeamStartPoint = EffectTemplate.SExperimentalUnstablePhasonLaserMuzzle01,
- FxBeam = Custom_4D_EffectTemplate.LightingStrikeBeam,
- FxBeamEndPoint = EffectTemplate.OthuyElectricityStrikeHit,
- FxBeamEndPointScale = 0.1,
- ScorchSize = 0.5,
- ScorchSplatDropTime = 0.1,
- ScorchTexture = 'czar_mark01_albedo',
- TerrainImpactType = 'LargeBeam01',
- TerrainImpactScale = 1,
- }
- ------------------------------
- -- Green beam for the Cybran Vampire
- ------------------------------
- VampireGreenLaserCollisionBeam = Class(CustomBeam) {
- FxBeam = {'/mods/4DC_FAF_Release/effects/Emitters/green_laser_beam_02_emit.bp'},
- FxImpactUnit = {
- '/mods/4DC_FAF_Release/effects/Emitters/green_hit_unit_emit.bp',
- '/mods/4DC_FAF_Release/effects/Emitters/green_beam_hit_sparks_emit.bp',
- EmtBpPath .. 'beam_hit_smoke_01_emit.bp',
- },
- FxUnitHitScale = 0.5,
- FxImpactLand = {
- EmtBpPath .. 'dirtchunks_01_emit.bp',
- EmtBpPath .. 'dust_cloud_05_emit.bp',
- EmtBpPath .. 'beam_hit_smoke_01_emit.bp',
- },
- FxLandHitScale = 0.5,
- ScorchSplatDropTime = 1,
- ScorchSize = 0.25,
- ScorchTexture = 'czar_mark01_albedo',
- TerrainImpactType = 'LargeBeam01',
- TerrainImpactScale = 1,
- }
Advertisement
Add Comment
Please, Sign In to add comment