Code: Select all
---------------------------
---------- v1.10 ----------
---------------------------
-- Scope - Can now be used to see further with a right click!
defineObject{
name = "scope",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/scope.fbx",
staticShadow = true,
},
{
class = "Item",
uiName = "Scope",
gfxIndex = 336,
weight = 0.7,
primaryAction = "zoomIn",
secondaryAction = "adjustZoom",
description = "A delicate instrument that greatly enhances clarity of sight.",
},
{
class = "ItemAction",
name = "zoomIn",
gameEffect = "See further in the parties current direction.",
cooldown = 2.5,
onAttack = function(self, champion, slot, chainIndex)
local camera = findEntity("scope_camera")
if camera then
if party.isScoped:isEnabled() then
camera.script.disableCamera()
else
camera.script.enableCamera()
end
else
print("ERROR - Missing 'scope_camera' object!")
end
end,
},
{
class = "ItemAction",
name = "adjustZoom",
uiName = "Adjust Zoom",
gameEffect = "Adjust how far can you see through the scope. Zoom level - 3",
cooldown = 0.2,
buildup = 0.25,
onAttack = function(self, champion, slot, chainIndex)
playSound("zoom")
local camera = findEntity("scope_camera")
if camera then
local zoom = camera.zoomLevel:getValue()
if zoom == 5 then
camera.zoomLevel:setValue(2)
self:setGameEffect("Adjust how far can you see through the scope. Zoom level - ".. 2)
else
camera.zoomLevel:setValue(zoom + 1)
self:setGameEffect("Adjust how far can you see through the scope. Zoom level - "..zoom+1)
end
else
print("ERROR - Missing 'scope_camera' object!")
end
end,
},
},
}
-- Scope Camera - Used by the scope
-- Due to how this works, you will not see anything between you and the party,
defineObject{
name = "scope_camera",
components = {
{
class = "Camera",
name = "camera",
fov = 50,
onInit = function(self) self.go:setSubtileOffset(0, 0) end,
onUpdate = function(self)
local t = math.noise(Time.currentTime() * 0.1) * 0.2
local face = math.noise(Time.currentTime() * 0.1) * 1 + party.facing * -90
local offsetX, offsetY = self.go:getSubtileOffset()
self.go:setPosition(self.go.x, self.go.y, self.go.facing, party.elevation + 0.5 + t, self.go.level)
self.go:setWorldRotationAngles(0, face, 0)
end,
},
{
class = "Null",
name = "cameraState",
enabled = false,
},
{
class = "Counter",
name = "zoomLevel",
value = 3,
},
{
class = "ScriptController",
name = "controller",
},
{
class = "Script",
source = [[
function enableCamera() -- Start
local x,y,f,e,l = party.x, party.y, party.facing, party.elevation, party.level
local dx,dy = getForward(f)
self.go:setPosition(x, y, f, e, l)
for i = 1,self.go.zoomLevel:getValue() do
local o = party.map:checkObstacle(self.go, f)
if not o then
if not party.map:isBlocked(self.go.x + dx, self.go.y + dy, e) then
self.go:setPosition(self.go.x+dx, self.go.y+dy, f, e, l)
end
end
end
GameMode.fadeOut(000000, 0.5)
party.isScoped:enable()
delayedCall(self.go.id, 0.75, "setCamera")
end
function setCamera() -- Set camera
playSound("zoom")
GameMode.fadeIn(000000, 0.5)
GameMode.setCamera(self.go.camera)
end
function disableCamera() -- Camera fadeout
GameMode.fadeOut(000000, 0.5)
delayedCall(self.go.id, 0.75, "resetCamera")
end
function resetCamera() -- End
playSound("zoom")
GameMode.setGameFlag("DisableMouseLook", false)
GameMode.fadeIn(000000, 0.5)
party.isScoped:disable()
GameMode.setCamera(nil)
end
]]
},
},
placement = "floor",
editorIcon = 32,
}