Commit c317c721 authored by Connor Price's avatar Connor Price 🤣

Added `reverse_bullet_objects`, `unique_bullet_objects`, and `advanced_bullet_objects`.

Added `step` to `bullet_objects`, `reverse_bullet_objects`, and `unique_bullet_objects`.
Added `keep_last` to `bullet_objects` and `reverse_bullet_objects`.
parent af8be899
......@@ -15,16 +15,30 @@ function NewRaycastWeaponBase:clbk_assembly_complete(clbk, parts, blueprint)
self:set_timer(self._setup.timer)
end
self._bullet_objects_step = 1
self._bullet_objects = {}
self._reverse_bullet_objects_step = 1
self._reverse_bullet_objects = {}
self._unique_bullet_objects_step = 1
self._unique_bullet_objects = {}
self._advanced_bullet_objects = {}
for part_id, part in pairs(self._parts) do
local part_data = managers.weapon_factory:get_part_data_by_part_id_from_weapon( part_id, self._factory_id, self._blueprint )
local bullet_objects = part_data.bullet_objects
local reverse_bullet_objects = part_data.reverse_bullet_objects
local unique_bullet_objects = part_data.unique_bullet_objects
local advanced_bullet_objects = part_data.advanced_bullet_objects
if bullet_objects then
local prefix = bullet_objects.prefix
local last_object = nil
local last_valid_amount = nil
for i = 1, bullet_objects.amount, 1 do
for i = bullet_objects.amount, 1, -1 do
local object = part.unit:get_object(Idstring(prefix .. i))
if object then
......@@ -34,6 +48,116 @@ function NewRaycastWeaponBase:clbk_assembly_complete(clbk, parts, blueprint)
object,
part.unit
})
last_object = object
last_valid_amount = i
end
end
if last_object and last_valid_amount then
for i = last_valid_amount-1, 1, -1 do
self._bullet_objects[i] = self._bullet_objects[i] or {}
table.insert(self._bullet_objects[i], {
last_object,
part.unit
})
end
end
if bullet_objects.step then
self._bullet_objects_step = bullet_objects.step
end
end
if reverse_bullet_objects then
local prefix = reverse_bullet_objects.prefix
for i = 1, reverse_bullet_objects.amount, 1 do
local object = part.unit:get_object(Idstring(prefix .. i))
if object then
self._reverse_bullet_objects[i] = self._reverse_bullet_objects[i] or {}
table.insert(self._reverse_bullet_objects[i], {
object,
part.unit
})
end
end
if reverse_bullet_objects.step then
self._reverse_bullet_objects_step = reverse_bullet_objects.step
end
end
if unique_bullet_objects then
local prefix = unique_bullet_objects.prefix
local last_object = nil
local last_valid_amount = nil
for i = unique_bullet_objects.amount, 1, -1 do
local object = part.unit:get_object(Idstring(prefix .. i))
if object then
self._unique_bullet_objects[i] = self._unique_bullet_objects[i] or {}
table.insert(self._unique_bullet_objects[i], {
object,
part.unit
})
last_object = object
last_valid_amount = i
end
end
log("go check")
if last_object and last_valid_amount then
log("last valid = " .. tostring(last_valid_amount))
for i = last_valid_amount-1, 1, -1 do
log(tostring(i))
self._unique_bullet_objects[i] = self._unique_bullet_objects[i] or {}
table.insert(self._unique_bullet_objects[i], {
last_object,
part.unit
})
end
end
if unique_bullet_objects.step then
self._unique_bullet_objects_step = unique_bullet_objects.step
end
end
if advanced_bullet_objects then
for index, object_set in pairs(advanced_bullet_objects) do
index = math.floor(tonumber(index))
self._advanced_bullet_objects[index] = self._advanced_bullet_objects[index] or {}
local objects = {}
if type(object_set) == "string" then
local object = part.unit:get_object(Idstring(object_set))
if object then
table.insert(self._advanced_bullet_objects[index], {
object,
part.unit
})
end
else
for _, object_id in pairs(object_set) do
local object = part.unit:get_object(Idstring(object_id))
if object then
table.insert(self._advanced_bullet_objects[index], {
object,
part.unit
})
end
end
end
end
end
......@@ -369,4 +493,71 @@ function NewRaycastWeaponBase:reload_speed_stat()
else
return self._reload
end
end
function NewRaycastWeaponBase:_update_bullet_objects(ammo_func)
if self._bullet_objects then
for i, objects in table.reverse_ipairs(self._bullet_objects) do
for _, object in ipairs(objects) do
local ammo_base = self:ammo_base()
local ammo = ammo_base[ammo_func](ammo_base)
local step = self._bullet_objects_step
ammo = math.floor(ammo/step)*step
object[1]:set_visibility(i <= ammo)
end
end
end
if self._reverse_bullet_objects then
for i, objects in ipairs(self._reverse_bullet_objects) do
for _, object in ipairs(objects) do
local ammo_base = self:ammo_base()
local ammo = ammo_base[ammo_func](ammo_base)
local step = self._reverse_bullet_objects_step
ammo = math.floor(ammo/step)*step
object[1]:set_visibility(i >= ammo)
end
end
end
if self._unique_bullet_objects then
for i, objects in table.reverse_ipairs(self._unique_bullet_objects) do
for _, object in ipairs(objects) do
object[1]:set_visibility(false)
end
end
local ammo_base = self:ammo_base()
local ammo = ammo_base[ammo_func](ammo_base)
local step = self._unique_bullet_objects_step
ammo = math.floor(ammo/step)*step
if self._unique_bullet_objects[ammo] then
for _, object in ipairs(self._unique_bullet_objects[ammo]) do
object[1]:set_visibility(true)
end
end
end
if self._advanced_bullet_objects then
for i, objects in table.reverse_ipairs(self._advanced_bullet_objects) do
for _, object in ipairs(objects) do
object[1]:set_visibility(false)
end
end
local ammo_base = self:ammo_base()
local ammo = ammo_base[ammo_func](ammo_base)
if self._advanced_bullet_objects[ammo] then
for _, object in ipairs(self._advanced_bullet_objects[ammo]) do
object[1]:set_visibility(true)
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment