Skip to content

Commit

Permalink
Allow sitting on any vanilla cushion
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaakma committed Jun 17, 2021
1 parent ad5207e commit 760856a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 30 deletions.
32 changes: 24 additions & 8 deletions Data Files/MWSE/mods/mer/ashfall/camping/cushions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ local function canRest()
return tes3.canRest()
end

local function cushionMenu(ref)
local message = ref.object.name
local function cushionMenu(e)
local ref = e.ref
local activator = e.activator
local message = ref.object.name or activator.name
local buttons = {
{
text = "Sit Down",
requirements = canRest,
callback = function()
if not cushions[ref.object.id:lower()] then
common.log:error("Cushion menu called on cushion that isn't in config somehow.")
return
end
-- if (not cushions[ref.object.id:lower()]) and (activator and not activator.ids[ref.object.id:lower()]) then
-- common.log:error("Cushion menu called on cushion that isn't in config somehow.")
-- return
-- end

local location = {
position = tes3vector3.new(
ref.position.x,
ref.position.y,
ref.position.z + cushions[ref.object.id:lower()].height
ref.position.z + common.helper.getObjectHeight(ref.object) - 7
),
orientation = {
0,--ref.orientation.x,
Expand All @@ -58,12 +61,15 @@ local function cushionMenu(ref)
},
cell = ref.cell
}
local collisionRef
if activator then collisionRef = ref end
animCtrl.showFastTimeMenu{
message = "Sit Down",
anim = "sitting",
location = location,
recovering = true,
speeds = { 2, 5, 10 }
speeds = { 2, 5, 10 },
collisionRef = collisionRef
}
end,
tooltipDisabled = {
Expand All @@ -72,6 +78,9 @@ local function cushionMenu(ref)
},
{
text = "Pick up",
showRequirements = function()
return not activator
end,
callback = function()
timer.delayOneFrame(function()
skipActivate = true
Expand Down Expand Up @@ -111,3 +120,10 @@ local function activateCushion(e)
end
end
event.register("activate", activateCushion)


event.register(
"Ashfall:ActivatorActivated",
cushionMenu,
{ filter = common.staticConfigs.activatorConfig.types.cushion }
)
3 changes: 3 additions & 0 deletions Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ function this.getGroundBelowRef(e)
return result
end

function this.getObjectHeight(obj)
return obj.boundingBox.max.z - obj.boundingBox.min.z
end

local function doIgnoreMesh(ref)
local objType = ref.object.objectType
Expand Down
27 changes: 26 additions & 1 deletion Data Files/MWSE/mods/mer/ashfall/config/activatorConfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ this.types = {
woodSource = "woodSource",
vegetation = "vegetation",
branch = "branch",
cauldron = "cauldron"
cauldron = "cauldron",
cushion = "cushion",
}

this.list = {}
Expand Down Expand Up @@ -290,6 +291,30 @@ this.list.campfire = Activator:new{
grillDistance = 40
}

this.list.cushion = Activator:new{
name = "Cushion",
type = this.types.cushion,
mcmSetting = nil,
ids = {
furn_de_cushion_round_01 = { height = 20 },
furn_de_cushion_round_02 = { height = 20 },
furn_de_cushion_round_03 = { height = 20 },
furn_de_cushion_round_04 = { height = 20 },
furn_de_cushion_round_05 = { height = 20 },
furn_de_cushion_round_06 = { height = 20 },
furn_de_cushion_round_07 = { height = 20 },
furn_de_cushion_square_01 = { height = 10 },
furn_de_cushion_square_02 = { height = 10 },
furn_de_cushion_square_03 = { height = 10 },
furn_de_cushion_square_04 = { height = 10 },
furn_de_cushion_square_05 = { height = 10 },
furn_de_cushion_square_06 = { height = 10 },
furn_de_cushion_square_07 = { height = 10 },
furn_de_cushion_square_08 = { height = 10 },
furn_de_cushion_square_09 = { height = 10 },
},
}

this.list.cauldron = Activator:new{
name = "Cauldron",
type = this.types.cauldron,
Expand Down
42 changes: 22 additions & 20 deletions Data Files/MWSE/mods/mer/ashfall/effects/animationController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ local data = {
fastTimer = nil,
originalTimeScale = nil,
speed = nil,
sleeping = nil
sleeping = nil,
collisionRef = nil
}
local animConfig = {
sitSlave = {
Expand Down Expand Up @@ -159,6 +160,13 @@ end
function this.doAnimation(e)
common.log:debug("do animation")
data = e
if data.collisionRef then
common.log:debug("Has Collision REF %s, setting NO Collision to TRUE", data.collisionRef )
data.collisionRef = tes3.makeSafeObjectHandle(data.collisionRef)
common.log:debug("hasNoCollision before: %s", data.collisionRef:getObject().hasNoCollision)
data.collisionRef:getObject().hasNoCollision = true
common.log:debug("hasNoCollision after: %s", data.collisionRef:getObject().hasNoCollision)
end
if data.usingBed then
event.trigger("Ashfall:SetBedTemp", { isUsingBed = true})
end
Expand Down Expand Up @@ -206,7 +214,7 @@ function this.doAnimation(e)
end
}
end

tes3.setVanityMode({ enabled = true })
helper.disableControls()
event.register("save", blockSave)
Expand Down Expand Up @@ -257,6 +265,12 @@ function this.cancel()
else
common.data.isWaiting = false
end
if data.collisionRef then
if data.collisionRef and data.collisionRef:valid() then
common.log:debug("Has Collision Ref, setting hasNoCollision to false")
data.collisionRef:getObject().hasNoCollision = false
end
end
common.log:debug("Enabling controls and setting vanity to false, unregistering events")
helper.enableControls()
tes3.setVanityMode({ enabled = false })
Expand Down Expand Up @@ -299,15 +313,9 @@ function this.showFastTimeMenu(e)
{
text = "Real Time",
callback = function()
buttonPressed{
anim = e.anim,
timeScaleMulti = 1,
location = e.location,
recovering = e.recovering,
sleeping = e.sleeping,
covered = e.covered,
usingBed = e.usingBed
}
local data = table.copy(e)
data.timeScaleMulti = 1
buttonPressed(data)
end
}
}
Expand All @@ -316,15 +324,9 @@ function this.showFastTimeMenu(e)
table.insert(buttons, {
text = string.format("%dx Speed", speed),
callback = function()
buttonPressed{
anim = e.anim,
timeScaleMulti = speed,
location = e.location,
recovering = e.recovering,
sleeping = e.sleeping,
covered = e.covered,
usingBed = e.usingBed
}
local data = table.copy(e)
data.timeScaleMulti = speed
buttonPressed(data)
end
})
end
Expand Down
2 changes: 1 addition & 1 deletion Data Files/MWSE/mods/mer/ashfall/objects/Activator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

function Activator:isActivator(id)
if self.ids then
if self.ids[string.lower(id)] == true then
if self.ids[string.lower(id)] then
return true
end
end
Expand Down

0 comments on commit 760856a

Please sign in to comment.