Skip to content

Commit

Permalink
weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
sayterdarkwynd committed Oct 14, 2019
1 parent 8c7ca9a commit dba0180
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 46 deletions.
3 changes: 2 additions & 1 deletion items/active/weapons/ranged/gun.animation.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"fire2" : [],
"fire3" : [],
"cooldown" : [],
"crit" : [ "/sfx/melee/axe_kill_organic2.ogg" ]
"crit" : [ "/sfx/melee/axe_kill_organic2.ogg" ],
"fuReload" : [ "/sfx/weapons/pistolreloadfast2.ogg" ]
}
}

Expand Down
222 changes: 191 additions & 31 deletions items/active/weapons/ranged/gunfire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ require "/items/active/weapons/crits.lua"
GunFire = WeaponAbility:new()

function GunFire:init()
self.isReloader = config.getParameter("isReloader",0)
-- FU additions
--weapon types
self.isReloader = config.getParameter("isReloader",0) -- is this a shotgun style reload?
self.isCrossbow = config.getParameter("isCrossbow",0) -- is this a crossbow?
self.isSniper = config.getParameter("isSniper",0) -- is this a sniper rifle?
self.isAmmoBased = config.getParameter("isAmmoBased",0) -- is this a ammo based gun?
self.isMachinePistol = config.getParameter("isMachinePistol",0) -- is this a machine pistol?
self.isShotgun = config.getParameter("isShotgun",0) -- is this a shotgun?
-- params
self.countdownDelay = 0 -- how long till it regains damage bonus?
self.timeBeforeCritBoost = 2 -- how long before it starts accruing bonus again?
self.magazineSize = config.getParameter("magazineSize",1) -- total count of the magazine
self.magazineAmount = (self.magazineSize or 0) -- current number of bullets in the magazine
self.reloadTime = config.getParameter("reloadTime",1) -- how long does reloading mag take?

-- **** FR ADDITIONS
daytime = daytimeCheck()
underground = undergroundCheck()
Expand Down Expand Up @@ -53,6 +67,66 @@ end

function GunFire:update(dt, fireMode, shiftHeld)
WeaponAbility.update(self, dt, fireMode, shiftHeld)

-- *** FU Weapon Additions
if self.magazineAmount < 0 or not self.magazineAmount then --make certain that ammo never ends up in negative numbers
self.magazineAmount = 0
end

if self.timeBeforeCritBoost <= 0 then
self.isCrossbow = config.getParameter("isCrossbow",0) -- is this a crossbow?
if self.isCrossbow >= 1 then
self.countdownDelay = (self.countdownDelay or 0) + 1
self.weaponBonus = (self.weaponBonus or 0)
self.firedWeapon = (self.firedWeapon or 0)
if self.firedWeapon > 0 then
if self.countdownDelay > 20 then
self.weaponBonus = 0
self.countdownDelay = 0
self.firedWeapon = 0
end
else
if self.countdownDelay > 20 then
self.weaponBonus = (self.weaponBonus or 0) + (config.getParameter("critBonus") or 1)
self.countdownDelay = 0
end
end

if self.weaponBonus >= 50 then --limit max value for crits and let player know they maxed
self.weaponBonus = 50
status.setPersistentEffects("critCharged", {{stat = "isCharged", amount = 1}})
status.addEphemeralEffect("critReady", 0.25)
end
status.setPersistentEffects("weaponBonus", {{stat = "critChance", amount = self.weaponBonus}})
end
self.isSniper = config.getParameter("isSniper",0) -- is this a sniper rifle?
if self.isSniper >= 1 then
self.countdownDelay = (self.countdownDelay or 0) + 1
self.weaponBonus = (self.weaponBonus or 0)
self.firedWeapon = (self.firedWeapon or 0)
if self.firedWeapon > 0 then
if self.countdownDelay > 10 then
self.weaponBonus = 0
self.countdownDelay = 0
self.firedWeapon = 0
end
else
if self.countdownDelay > 10 then
self.weaponBonus = (self.weaponBonus or 0) + (config.getParameter("critBonus") or 1)
self.countdownDelay = 0
end
end

if self.weaponBonus >= 80 then --limit max value for crits and let player know they maxed
self.weaponBonus = 80
status.setPersistentEffects("critCharged", {{stat = "isCharged", amount = 1}})
status.addEphemeralEffect("critReady", 0.25)
end
status.setPersistentEffects("weaponBonus", {{stat = "critChance", amount = self.weaponBonus}})
end
else
self.timeBeforeCritBoost = self.timeBeforeCritBoost -dt
end

self.cooldownTimer = math.max(0, self.cooldownTimer - self.dt )

Expand All @@ -67,27 +141,58 @@ function GunFire:update(dt, fireMode, shiftHeld)
end

if animator.animationState("firing") ~= "fire" then
animator.setLightActive("muzzleFlash", false)
animator.setLightActive("muzzleFlash", false)
end

if self.fireMode == (self.activatingFireMode or self.abilitySlot)
and not self.weapon.currentAbility
and self.cooldownTimer == 0
and not status.resourceLocked("energy")
and not world.lineTileCollision(mcontroller.position(), self:firePosition()) then
if self.fireType == "auto" and status.overConsumeResource("energy", self:energyPerShot()) then
self:setState(self.auto)
elseif self.fireType == "burst" then
self:setState(self.burst)
end
if self.fireType == "auto" and status.overConsumeResource("energy", self:energyPerShot()) then
self:setState(self.auto)
elseif self.fireType == "burst" then
self:setState(self.burst)
end
end

end


function GunFire:auto()

self.reloadTime = config.getParameter("reloadTime") or 1 -- how long does reloading mag take?
-- ***********************************************************************************************************
-- FR SPECIALS (Weapon speed and other such things)
-- ***********************************************************************************************************

--Crossbows
self.isCrossbow = config.getParameter("isCrossbow",0) -- is this a crossbow?
if (self.isCrossbow) >= 1 then
self.firedWeapon = 1
self.timeBeforeCritBoost = 2
status.setPersistentEffects("critCharged", {{stat = "isCharged", amount = 0}})
end
--Snipers
self.isSniper = config.getParameter("isSniper",0) -- is this a sniper rifle?
if (self.isSniper) >= 1 then
self.firedWeapon = 1
self.timeBeforeCritBoost = 2
status.setPersistentEffects("critCharged", {{stat = "isCharged", amount = 0}})
end
--ammo
self.magazineSize = config.getParameter("magazineSize",1) -- total count of the magazine
self.magazineAmount = (self.magazineAmount or 0)-- current number of bullets in the magazine
self.isAmmoBased = config.getParameter("isAmmoBased",0)
if (self.isAmmoBased == 1) then
if self.magazineAmount <= 0 then
self.weapon:setStance(self.stances.cooldown)
self:setState(self.cooldown)
else
self.magazineAmount = self.magazineAmount - 1
end
sb.logInfo(self.magazineAmount)
end

local species = world.entitySpecies(activeItem.ownerEntityId())

if species then
Expand All @@ -105,26 +210,59 @@ function GunFire:auto()
self:muzzleFlash()

if self.stances.fire.duration then
util.wait(self.stances.fire.duration)
util.wait(self.stances.fire.duration)
end

if self.helper then self.helper:runScripts("gunfire-postauto", self) end

self.cooldownTimer = self.fireTime --* self.energymax
--sb.logInfo("lightLevel = "..lightLevel)
--sb.logInfo("energyMax = "..self.energyMax)
--sb.logInfo("cooldownTimer = "..self.cooldownTimer)


self.cooldownTimer = self.fireTime --* self.energymax

self.isReloader = config.getParameter("isReloader",0) -- is this a shotgun style reload?
if self.isReloader >= 1 then
animator.playSound("cooldown") -- adds sound to shotgun reload
if (self.isAmmoBased==1) and (self.magazineAmount <= 0) then
animator.playSound("fuReload") -- adds new sound to reload
end
end
if (self.isAmmoBased==1) and (self.magazineAmount <= 0) then
self.cooldownTimer = self.fireTime + self.reloadTime
status.addEphemeralEffect("reloadReady", 0.25)
self.magazineAmount = self.magazineSize
animator.playSound("fuReload") -- adds new sound to reload
end

self.weapon:setStance(self.stances.cooldown)
self:setState(self.cooldown)
self.isReloader = config.getParameter("isReloader",0)

if self.isReloader >= 1 then
animator.playSound("cooldown") -- adds new sound to reload
end
end

function GunFire:burst()

self.reloadTime = config.getParameter("reloadTime") or 1 -- how long does reloading mag take?
--Crossbows
self.isCrossbow = config.getParameter("isCrossbow",0) -- is this a crossbow?
if (self.isCrossbow) >= 1 then
self.firedWeapon = 1
self.timeBeforeCritBoost = 2
end
--Snipers
self.isSniper = config.getParameter("isSniper",0) -- is this a sniper rifle?
if (self.isSniper) >= 1 then
self.firedWeapon = 1
self.timeBeforeCritBoost = 2
end
--ammo
self.magazineAmount = (self.magazineAmount or 0)-- current number of bullets in the magazine
self.isAmmoBased = config.getParameter("isAmmoBased",0) -- is this a pistol?
if (self.isAmmoBased == 1) then
if self.magazineAmount <= 0 then
self.weapon:setStance(self.stances.cooldown)
self:setState(self.cooldown)
else
self.magazineAmount = self.magazineAmount - 1
end
end

local species = world.entitySpecies(activeItem.ownerEntityId())

if species then
Expand All @@ -139,26 +277,41 @@ function GunFire:burst()

local shots = self.burstCount
while shots > 0 and status.overConsumeResource("energy", self:energyPerShot()) do
self:fireProjectile()
self:muzzleFlash()
shots = shots - 1

self.weapon.relativeWeaponRotation = util.toRadians(interp.linear(1 - shots / self.burstCount, 0, self.stances.fire.weaponRotation))
self.weapon.relativeArmRotation = util.toRadians(interp.linear(1 - shots / self.burstCount, 0, self.stances.fire.armRotation))

util.wait(self.burstTime)
self:fireProjectile()
self:muzzleFlash()
shots = shots - 1
self.weapon.relativeWeaponRotation = util.toRadians(interp.linear(1 - shots / self.burstCount, 0, self.stances.fire.weaponRotation))
self.weapon.relativeArmRotation = util.toRadians(interp.linear(1 - shots / self.burstCount, 0, self.stances.fire.armRotation))
util.wait(self.burstTime)
end

self.cooldownTimer = (self.fireTime - self.burstTime) * self.burstCount
self.cooldownTimer = (self.fireTime - self.burstTime) * self.burstCount
self.isReloader = config.getParameter("isReloader",0) -- is this a shotgun style reload?
if self.isReloader >= 1 then
animator.playSound("cooldown") -- adds sound to shotgun reload
if (self.isAmmoBased==1) and (self.magazineAmount <= 0) then
animator.playSound("fuReload") -- adds new sound to reload
end
end
if (self.isAmmoBased==1) and (self.magazineAmount <= 0) then
self.cooldownTimer = ((self.fireTime - self.burstTime) * self.burstCount) + self.reloadTime
status.addEphemeralEffect("reloadReady", 0.25)
self.magazineAmount = self.magazineSize
animator.playSound("fuReload") -- adds new sound to reload
self.weapon:setStance(self.stances.cooldown)
self:setState(self.cooldown)
end

if self.helper then self.helper:runScripts("gunfire-postburst", self) end

if self.helper then self.helper:runScripts("gunfire-postburst", self) end
end

function GunFire:cooldown()
self.weapon:setStance(self.stances.cooldown)
self.weapon:updateAim()

local progress = 0

util.wait(self.stances.cooldown.duration, function()
local from = self.stances.cooldown.weaponOffset or {0,0}
local to = self.stances.idle.weaponOffset or {0,0}
Expand All @@ -181,6 +334,7 @@ function GunFire:muzzleFlash()
end

function GunFire:fireProjectile(projectileType, projectileParams, inaccuracy, firePosition, projectileCount)

local params = sb.jsonMerge(self.projectileParameters, projectileParams or {})
params.power = self:damagePerShot()
params.powerMultiplier = activeItem.ownerPowerMultiplier()
Expand Down Expand Up @@ -223,16 +377,22 @@ function GunFire:aimVector(inaccuracy)
end

function GunFire:energyPerShot()
return self.energyUsage * self.fireTime * (self.energyUsageMultiplier or 1.0)
-- if self.isAmmoBased then
-- return (self.energyUsage * self.fireTime * (self.energyUsageMultiplier or 1.0))/2
-- else
return self.energyUsage * self.fireTime * (self.energyUsageMultiplier or 1.0)
--end

end

function GunFire:damagePerShot()
return Crits.setCritDamage(self, self.baseDamage or self.baseDps * self.fireTime * (self.baseDamageMultiplier or 1.0) * config.getParameter("damageLevelMultiplier") / self.projectileCount)
return Crits.setCritDamage(self, self.baseDamage or self.baseDps * self.fireTime * (self.baseDamageMultiplier or 1.0) * config.getParameter("damageLevelMultiplier") / self.projectileCount)
end


function GunFire:uninit()
if self.helper then
self.helper:clearPersistent()
end
status.clearPersistentEffects("weaponBonus")
end
Loading

0 comments on commit dba0180

Please sign in to comment.