Skip to content

Commit

Permalink
Housing Demolition #358
Browse files Browse the repository at this point in the history
  • Loading branch information
brightrim committed Feb 19, 2024
1 parent ffcc5a5 commit 1234b3a
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 34 deletions.
8 changes: 6 additions & 2 deletions content/messenger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ local function convertContentsIntoString(contents)

for index, message in pairs(contents) do
if not message.sender then
message.sender = "script"
return false --script message not to be logged to avoid spam in the log
end
retString = retString.." (Sender "..index..": "..message.sender.." Message"..index..": "..garbleTheMessage(message.text)..")"
end
Expand All @@ -84,7 +84,11 @@ local function logThatMessagesWereReceived(recipient, contents)

loggedMessage = loggedMessage..convertContentsIntoString(contents)

log(loggedMessage)
if loggedMessage then

log(loggedMessage)

end
end

local function sendPlayerMessages(numberOfMessages, recipient)
Expand Down
26 changes: 13 additions & 13 deletions gm/items/id_99_lockpicks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1833,31 +1833,31 @@ function M.UseItem(user, SourceItem, ltstate)
teleporter(user, SourceItem)
elseif index == 3 then
summon(user, SourceItem)
elseif index == 3 then
godMode(user, SourceItem, ltstate)
elseif index == 4 then
settingsForChar(user)
godMode(user, SourceItem, ltstate)
elseif index == 5 then
ambientAction(user)
settingsForChar(user)
elseif index == 6 then
actionOnChar(user, SourceItem)
ambientAction(user)
elseif index == 7 then
actionOnGroup(user, SourceItem)
actionOnChar(user, SourceItem)
elseif index == 8 then
factionInfoOfCharsInRadius(user, SourceItem, ltstate)
actionOnGroup(user, SourceItem)
elseif index == 9 then
questEvents(user, SourceItem, ltstate)
factionInfoOfCharsInRadius(user, SourceItem, ltstate)
elseif index == 10 then
setuserTeleporter(user, SourceItem)
questEvents(user, SourceItem, ltstate)
elseif index == 11 then
setuserActionOnChar(user, SourceItem)
setuserTeleporter(user, SourceItem)
elseif index == 12 then
setuserActionOnGroup(user, SourceItem)
setuserActionOnChar(user, SourceItem)
elseif index == 13 then
testArea(user)
setuserActionOnGroup(user, SourceItem)
elseif index == 14 then
resetTutorial(user)
testArea(user)
elseif index == 15 then
resetTutorial(user)
elseif index == 16 then
changePersistence(user)
end
end
Expand Down
122 changes: 111 additions & 11 deletions housing/utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,44 @@ function M.checkIfWallOrWindow(user, suspectedWall)
return false
end

function M.isBuilder(user)

local frontPos = common.GetFrontPosition(user)

local propertyName = M.fetchPropertyName(user, frontPos)

local deed = M.getPropertyDeed(propertyName)

for i = 1, M.max_builder_number do

local builderID = deed:getData("builderID"..i)

if builderID ~= "" and tonumber(builderID) == user.id then
return true
end
end

return false
end

function M.isTenant(user)

local frontPos = common.GetFrontPosition(user)

local propertyName = M.fetchPropertyName(user, frontPos)

local deed = M.getPropertyDeed(propertyName)

local tenantID = deed:getData("tenantID")

if tenantID ~= "" and tonumber(tenantID) == user.id then
return true
end

return false
end



function M.allowBuilding(user, alternatePosition)

Expand All @@ -422,6 +460,11 @@ function M.allowBuilding(user, alternatePosition)
local propertyName = M.fetchPropertyName(user, frontPos)
local deed = M.getPropertyDeed(propertyName)

if deed:getData("demolishmentInProgress") == "true" then
user:inform("GERMAN TRANSLATION", "You can not build at an estate that is being demolished.")
return false
end

if M.fetchPropertyName(user, frontPos) then

local tenantID = deed:getData("tenantID")
Expand Down Expand Up @@ -577,7 +620,6 @@ end

function M.setPersistenceForProperties()
for _, property in pairs(propertyList.properties) do
log("Setting persistence for "..property.name)
for x = property.lower.x, property.upper.x do
for y = property.lower.y, property.upper.y do
for z = property.lower.z, property.upper.z do
Expand All @@ -587,19 +629,14 @@ function M.setPersistenceForProperties()
end
end
end
log("Done setting persistence for "..property.name)
end

log("Creating estate basements")
M.createEstateBasements() -- in case any estates are lacking basement tiles and walls, this function will fix that
log("Done creating estate basements")

log("Now checking that all property deeds are where they should be")
for i = 1, #propertyList.propertyTable do
local location = propertyList.propertyTable[i][3]

if not world:isPersistentAt(location) then
log("Setting persistence for property deed belonging to "..propertyList.propertyTable[i][1])
world:makePersistentAt(location)
end

Expand All @@ -614,7 +651,6 @@ function M.setPersistenceForProperties()
end

if not propertyDeedFound then
log("Creating missing property deed for property "..propertyList.propertyTable[i][1])
world:createItemFromId(3772, 1, location, true, 333, nil) --This will lead to some deeds that should be 3773 facing the wrong direction, but this is also only ever called if one is missing to begin with when a GM sets persistence
end
end
Expand Down Expand Up @@ -649,6 +685,74 @@ function M.createLock(user)
end
end

local function scheduleDemolishment(user, propertyName)

local callback = function(dialog)

if not dialog:getSuccess() then
return
end

local selected = dialog:getSelectedIndex()+1

if selected == 1 then
local deed = M.getPropertyDeed(propertyName)
deed:setData("demolish", "true") --Used to determine which property will be demolished when the scheduled script triggers

-- Below is a little hack since we do not use global variables, to not have to check every single property each time if there are none scheduled at all

local pauldronDeed = M.getPropertyDeed("Pauldron Estate") -- refresh in case the deed was changed above as one of the demolished properties

if deed.pos == pauldronDeed.pos then
deed:setData("newDemolishments", "true")
else
pauldronDeed:setData("newDemolishments", "true")
world:changeItem(pauldronDeed)
end

-- end of the hack

world:changeItem(deed)

user:inform("GERMAN TRANSLATION", "Upon your request of a demolition, a bunch of dwarves appear to demolish the estate. One by one they scurry off with the broken down material as their payment, at this rate they should be done in no time. ")
else
return
end
end

local dialog = SelectionDialog(common.GetNLS(user,"Bestätigung","Confirmation Check"), common.GetNLS(user,"GERMAN TRANSLATION", "Are you certain that you are absolutely positively sure you want to go through with this? This is the final warning. The demolition can not be stopped or undone after this, and will destroy everything on your property including items you made static or items that are not static!"), callback)
dialog:addOption(0,common.GetNLS(user,"Ja","Yes"))
dialog:addOption(0,common.GetNLS(user,"Nein, das ist Kunst.","No, I changed my mind."))
dialog:setCloseOnMove()
user:requestSelectionDialog(dialog)
end

function M.demolishConfirmation(user, propertyName)

local callback = function(dialog)

if not dialog:getSuccess() then
return
end

local selected = dialog:getSelectedIndex()+1

if selected == 1 then
scheduleDemolishment(user, propertyName)
else
return
end
end

local dialog = SelectionDialog(common.GetNLS(user,"Bestätigung","Confirmation Check"), common.GetNLS(user,"GERMAN TRANSLATION", "Are you certain you want to demolish your estate property? This can not be undone and once initiated, it can not stop."), callback)
dialog:addOption(0,common.GetNLS(user,"Ja","Yes"))
dialog:addOption(0,common.GetNLS(user,"Nein, das ist Kunst.","No, I changed my mind."))
dialog:setCloseOnMove()
user:requestSelectionDialog(dialog)

end


function M.createKey(user)

local propertyName = M.fetchPropertyName(user)
Expand Down Expand Up @@ -963,9 +1067,7 @@ function M.createEstateBasements()
for _, property in pairs(basementProperties) do
local tileID, wallID = M.getBasementTileWall(property.name)
if property.lower.z == -21 then --only for basement layers
log("Creating basement walls for property "..property.name)
placeBasementWalls(wallID, property.lower, property.upper)
log("Creating basement tiles for property "..property.name)
placeBasementTiles(tileID, property.lower, property.upper)
end
end
Expand Down Expand Up @@ -1167,7 +1269,6 @@ function M.deletePreviewItem(propertyName, bypassTTL)
local propertyDeed = M.getPropertyDeed(propertyName)

if propertyDeed == nil then
log("The property deed for "..propertyName.." is missing from the map, causing script errors.")
return
end

Expand Down Expand Up @@ -1244,7 +1345,6 @@ function M.ifNoSurroundingTilesDeleteStairTiles(tile1pos, tile2pos)
local field = world:getField(thePos)
local tileID = field:tile()
if tileID ~= 0 then
log("tileID: "..tostring(tileID).." at position: "..tostring(thePos))
deleteTiles = false
break
end
Expand Down
31 changes: 23 additions & 8 deletions item/builderstool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ local function carpentrySelection(user)
user:requestSelectionDialog(dialog)
end


local function craftSelection(user)

local skills = utility.getSkillsToShow(user)
Expand All @@ -72,7 +71,9 @@ local function craftSelection(user)
user:requestSelectionDialog(dialog)
end

local function destroySelection(user )
local function destroySelection(user)

local propertyName = utility.fetchPropertyName(user)

local callback = function(dialog)
local success = dialog:getSuccess()
Expand All @@ -84,8 +85,10 @@ local function destroySelection(user )
utility.destroyTile(user)
elseif selected == 3 then
utility.deleteRoofItemOrTile(user, false)
else
elseif selected == 4 then
utility.deleteRoofItemOrTile(user, true)
elseif selected == 5 then
utility.demolishConfirmation(user, propertyName)
end
end
end
Expand All @@ -94,8 +97,14 @@ local function destroySelection(user )
dialog:addOption(0,common.GetNLS(user,"Schindeln","Tiles"))
dialog:addOption(0,common.GetNLS(user,"Dachausrüstung","Roof Objects"))
dialog:addOption(0,common.GetNLS(user,"Dachschindeln","Roof Tiles"))
dialog:addOption(0, common.GetNLS(user, "GERMAN TRANSLATION", "Demolish the entire estate"))
dialog:setCloseOnMove()
user:requestSelectionDialog(dialog)

if utility.checkIfEstate(user) then
user:requestSelectionDialog(dialog)
else
utility.destroyItem(user)
end
end

local function miscDialog(user)
Expand Down Expand Up @@ -219,14 +228,20 @@ local function mainDialog(user, sourceItem)

dialog:setCloseOnMove()

user:requestSelectionDialog(dialog)
if utility.isTenant(user) then

user:requestSelectionDialog(dialog)

elseif utility.isBuilder(user) then

craftSelection(user, sourceItem)

end

end

function M.UseItem(user, sourceItem)

local thePosition = common.GetFrontPosition(user) --To prevent cheating by turning, the position is set at the very start(dialogue can only be set to close on movement)

if not utility.checkIfIsInHand(user, sourceItem) then
return
end
Expand All @@ -236,7 +251,7 @@ function M.UseItem(user, sourceItem)
if not propertyName then
user:inform("Du kannst nicht außerhalb eines Grundstückes bauen.","You can't build outside of property land.")
elseif utility.allowBuilding(user) then
mainDialog(user, sourceItem, thePosition)
mainDialog(user, sourceItem)
else
user:inform("Du musst ein Bewohner sein, um hier bauen zu dürfen, oder eine Genehmigung haben.","To build here you must be the tenant of the property or have their permission.")
end
Expand Down
Loading

0 comments on commit 1234b3a

Please sign in to comment.