2014-02-02 02:25:06 +01:00
--[[
Illarion Server
This program is free software : you can redistribute it and / or modify it under
the terms of the GNU Affero General Public License as published by the Free
Software Foundation , either version 3 of the License , or ( at your option ) any
later version .
This program is distributed in the hope that it will be useful , but WITHOUT ANY
WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE . See the GNU Affero General Public License for more
details .
You should have received a copy of the GNU Affero General Public License along
2014-06-03 13:35:04 +02:00
with this program . If not , see < http : // www.gnu . org / licenses /> .
2014-02-02 02:25:06 +01:00
] ]
2014-09-17 03:50:05 +02:00
local factions = require ( " base.factions " )
2016-09-09 11:49:00 -04:00
local character = require ( " base.character " )
2014-09-17 03:50:05 +02:00
local common = require ( " base.common " )
local licence = require ( " base.licence " )
2017-07-25 21:47:04 +02:00
local collectionchest = require ( " content.collectionchest " )
2022-02-18 15:41:08 +01:00
local money = require ( " base.money " )
2022-07-14 22:05:55 +02:00
local utility = require ( " housing.utility " )
2014-10-28 20:25:00 +01:00
local M = { }
2014-02-02 02:25:06 +01:00
2014-06-03 13:35:04 +02:00
-- Cadomyr, Runewick, Galmair
2024-02-19 12:45:16 +01:00
M.townManagmentItemPos = factions.townManagmentItemPos
2014-06-03 13:35:04 +02:00
2020-05-10 05:27:12 +02:00
local TownAnnouncement
local TownAnnouncementShow
local TownAnnouncementInput
2016-04-25 21:07:33 +02:00
local TownGuard
local TownLicence
local TownKey
2017-07-25 21:47:04 +02:00
local TownMaterial
2022-02-18 15:41:08 +01:00
local townProperties
2014-02-02 02:25:06 +01:00
2014-10-28 20:25:00 +01:00
function M . townManagmentUseItem ( User , SourceItem )
2014-02-02 02:25:06 +01:00
2016-04-25 21:07:33 +02:00
local toolTown
for j = 1 , # M.townManagmentItemPos do
2015-10-29 19:13:08 +01:00
if ( SourceItem.pos == M.townManagmentItemPos [ j ] ) then
toolTown = j
end
end
2016-04-25 21:07:33 +02:00
local requiredRank = { 8 , 8 , 8 }
2025-01-20 11:37:32 +01:00
local allowed = User : getQuestProgress ( 199 ) == toolTown and User : getQuestProgress ( 200 ) >= requiredRank [ toolTown ] or User : isAdmin ( ) == true
2016-04-25 21:07:33 +02:00
if not allowed then
2019-08-18 06:14:18 +02:00
-- common.InformNLS(User, "Du hast keine Befugnis hierzu.", "You are not supposed to use this.")
TownAnnouncementShow ( User , toolTown )
2016-04-25 21:07:33 +02:00
return
end
2015-10-29 19:13:08 +01:00
2016-04-25 21:07:33 +02:00
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
end
local selected = dialog : getSelectedIndex ( ) + 1
if selected == 1 then
2019-08-18 06:14:18 +02:00
TownAnnouncement ( User , toolTown )
2016-04-25 21:07:33 +02:00
elseif selected == 2 then
2019-08-18 06:14:18 +02:00
TownGuard ( User , toolTown )
2016-04-25 21:07:33 +02:00
elseif selected == 3 then
2024-02-19 12:45:16 +01:00
TownLicence ( User , toolTown , SourceItem )
2017-07-25 21:47:04 +02:00
elseif selected == 4 then
2019-08-18 06:14:18 +02:00
TownKey ( User , toolTown )
elseif selected == 5 then
2022-06-21 15:16:08 +02:00
townProperties ( User , toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
elseif selected == 6 then
2017-07-25 21:47:04 +02:00
TownMaterial ( User , toolTown )
2015-10-29 19:13:08 +01:00
end
end
2016-04-25 21:07:33 +02:00
local dialogTitle = common.GetNLS ( User , " Stadtmanagement " , " Town Management " )
2019-08-18 06:14:18 +02:00
local dialogText = common.GetNLS ( User , " Instrument zur Verwaltung der Stadt und Ank<6E> ndigungen. " , " Instrument for town management and announcements. " )
2016-04-25 21:07:33 +02:00
local dialog = SelectionDialog ( dialogTitle , dialogText , callback )
2015-10-29 19:13:08 +01:00
2021-05-31 15:48:15 +02:00
local toolUse
2017-07-25 21:47:04 +02:00
if collectionchest.isCollectionChestExists ( toolTown ) then
2022-12-13 11:59:05 +01:00
toolUse = common.GetNLS ( User , { " Ank<EFBFBD> ndigung " , " Verbannung " , " Lizenz " , " Schl<EFBFBD> ssel " , " Grundst<EFBFBD> cksverwaltung " , " Materialsammlung " } , { " Announcement " , " Ban a character " , " Licence " , " Key " , " Property Management " , " Material collection " } )
2017-07-25 21:47:04 +02:00
else
2022-12-13 11:59:05 +01:00
toolUse = common.GetNLS ( User , { " Ank<EFBFBD> ndigung " , " Verbannung " , " Lizenz " , " Schl<EFBFBD> ssel " , " Grundst<EFBFBD> cksverwaltung " } , { " Announcement " , " Ban a character " , " Licence " , " Key " , " Property Management " } )
2017-07-25 21:47:04 +02:00
end
2020-12-06 23:34:30 +01:00
2016-04-25 21:07:33 +02:00
for i = 1 , # toolUse do
2015-10-29 19:13:08 +01:00
dialog : addOption ( 0 , toolUse [ i ] )
end
2016-04-25 21:07:33 +02:00
dialog : setCloseOnMove ( )
User : requestSelectionDialog ( dialog )
2014-02-02 02:25:06 +01:00
end
2022-02-18 15:41:08 +01:00
local function getTown ( toolTown )
if toolTown == 1 then
return " Cadomyr "
elseif toolTown == 2 then
return " Runewick "
elseif toolTown == 3 then
return " Galmair "
end
end
2022-06-21 15:16:08 +02:00
local function getRentAmount ( toolTown , SourceItem )
local rent = SourceItem : getData ( " rent " )
if rent ~= " " then
return tonumber ( rent )
2022-02-18 15:41:08 +01:00
else
return 0
end
end
2022-06-21 15:16:08 +02:00
local function collectedRentIntoMoney ( toolTown , SourceItem )
local coins = getRentAmount ( toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
local gCoins , sCoins , cCoins = money.MoneyToCoins ( coins )
if gCoins > 0 and sCoins == 0 and cCoins == 0 then
return ( gCoins .. " gold coins. " )
elseif gCoins > 0 and sCoins > 0 and cCoins == 0 then
return ( gCoins .. " gold and " .. sCoins .. " silver coins " )
elseif gCoins > 0 and sCoins == 0 and cCoins > 0 then
return ( gCoins .. " gold and " .. cCoins .. " copper coins " )
elseif gCoins == 0 and sCoins > 0 and cCoins == 0 then
return ( sCoins .. " silver coins " )
elseif gCoins == 0 and sCoins > 0 and cCoins > 0 then
return ( sCoins .. " silver and " .. cCoins .. " copper coins " )
elseif gCoins == 0 and sCoins == 0 and cCoins > 0 then
return ( cCoins .. " copper coins " )
elseif gCoins > 0 and sCoins > 0 and cCoins > 0 then
return ( gCoins .. " gold, " .. sCoins .. " silver and " .. cCoins .. " copper coins " )
else
return ( " no money " )
end
end
2022-06-21 15:16:08 +02:00
local function collectedRentIntoMoneyDE ( toolTown , SourceItem )
local coins = getRentAmount ( toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
local gCoins , sCoins , cCoins = money.MoneyToCoins ( coins )
if gCoins > 0 and sCoins == 0 and cCoins == 0 then
return ( gCoins .. " Goldst<73> cke " )
elseif gCoins > 0 and sCoins > 0 and cCoins == 0 then
return ( gCoins .. " Gold- and " .. sCoins .. " Silberst<73> cke " )
elseif gCoins > 0 and sCoins == 0 and cCoins > 0 then
return ( gCoins .. " Gold- and " .. cCoins .. " Kupferst<73> cke " )
elseif gCoins == 0 and sCoins > 0 and cCoins == 0 then
return ( sCoins .. " Silberst<73> cke " )
elseif gCoins == 0 and sCoins > 0 and cCoins > 0 then
return ( sCoins .. " Silber- and " .. cCoins .. " Kupferst<73> cke " )
elseif gCoins == 0 and sCoins == 0 and cCoins > 0 then
return ( cCoins .. " Kupferst<73> cke " )
elseif gCoins > 0 and sCoins > 0 and cCoins > 0 then
return ( gCoins .. " Gold-, " .. sCoins .. " Silber- and " .. cCoins .. " Kupferst<73> cke " )
else
return ( " kein Geld " )
end
end
2022-07-11 18:22:19 +02:00
2022-06-21 15:16:08 +02:00
local function withdrawRent ( User , toolTown , SourceItem )
local rent = getRentAmount ( toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
local town = getTown ( toolTown )
2022-07-11 18:22:19 +02:00
local _
2022-02-18 15:41:08 +01:00
local callback = function ( dialog )
if ( not dialog : getSuccess ( ) ) then
return
end
local input = dialog : getInput ( )
2022-07-11 18:22:19 +02:00
if string.find ( input , " (%d+) " ) ~= nil then
_ , _ , input = string.find ( input , " (%d+) " )
input = tonumber ( input )
if input <= 0 then
2022-02-18 15:41:08 +01:00
User : inform ( common.GetNLS ( User , " Die Zahl muss gr<67> <72> er als 0 sein. " , " You must set a number higher than 0. " ) )
2022-07-11 18:22:19 +02:00
elseif input > rent then
User : inform ( common.GetNLS ( User , " Die Zahl kann nicht gr<67> <72> er sein als die Anzahl der M<> nzen in der Schatzkiste. " , " The amount can not be larger than the amount in the treasury. " ) )
2022-02-18 15:41:08 +01:00
else
local coins = input
local gCoins , sCoins , cCoins = money.MoneyToCoins ( coins )
money.GiveCoinsToChar ( User , gCoins , sCoins , cCoins )
2022-07-11 18:49:24 +02:00
SourceItem : setData ( " rent " , ( rent - input ) )
world : changeItem ( SourceItem )
2022-07-11 18:22:19 +02:00
local inputIntoMoneyDe , inputIntoMoneyEn = money.MoneyToString ( input )
User : inform ( common.GetNLS ( User , " Du entnimmst " .. inputIntoMoneyDe .. " aus der Schatzkiste der Stadt. " , " You withdraw " .. inputIntoMoneyEn .. " from the town's treasury. " ) )
log ( User.name .. " withdrew " .. inputIntoMoneyEn .. " from the " .. town .. " rent treasury. " )
2022-02-18 15:41:08 +01:00
end
else
User : inform ( common.GetNLS ( User , " Hier muss eine Zahl eingetragen werden. " , " Input must be a number. " ) )
end
end
User : requestInputDialog ( InputDialog ( common.GetNLS ( User , " Mietenentnahme " , " Rent Withdrawal " ) , common.GetNLS ( User , " Gib an, wie viele Kupferm<72> nzen du entnehmen m<> chtest. " , " Type in how much money you want to withdraw in copper coins. " ) , false , 255 , callback ) )
end
2022-06-21 15:16:08 +02:00
local function rentCollection ( User , toolTown , SourceItem )
local rent = collectedRentIntoMoney ( toolTown , SourceItem )
local rentDE = collectedRentIntoMoneyDE ( toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
local callback = function ( dialog )
2022-06-21 15:16:08 +02:00
if getRentAmount ( toolTown , SourceItem ) ~= 0 then --the below code only matters for selectionDialog and not messageDialog
if not dialog : getSuccess ( ) then
return
end
local selected = dialog : getSelectedIndex ( ) + 1
if selected == 1 then
withdrawRent ( User , toolTown , SourceItem )
else
2023-03-05 10:33:39 +01:00
User : inform ( common.GetNLS ( User , " Du entscheidest dich gegen das Entnehmen der Miete f<> r den Augenblick. " , " You decide against withdrawing any rent for now. " ) )
2022-06-21 15:16:08 +02:00
end
2022-02-18 15:41:08 +01:00
end
end
2022-06-21 15:16:08 +02:00
if getRentAmount ( toolTown , SourceItem ) == 0 then
2023-03-05 10:33:39 +01:00
local dialog = MessageDialog ( common.GetNLS ( User , " Grundst<EFBFBD> cksmiete " , " Property Rent " ) , common.GetNLS ( User , " Es sind keine Mieteinnahmen in der Schatzkiste. " , " There is currently no rental payment available for collection. " ) , callback )
2022-02-18 15:41:08 +01:00
User : requestMessageDialog ( dialog )
else
2023-03-05 10:33:39 +01:00
local dialog = SelectionDialog ( common.GetNLS ( User , " Grundst<EFBFBD> cksmiete " , " Property Rent " ) , common.GetNLS ( User , " Derzeit sind Mieteinnahmen von " .. rentDE .. " in der Schatzkiste. M<> chtest du sie entnehmen? " , " There's currently " .. rent .. " in the treasury for rental payments. \n Do you want to withdraw any? " ) , callback )
dialog : addOption ( 0 , common.GetNLS ( User , " Geld entnehmen " , " Withdraw money " ) )
2022-02-18 15:41:08 +01:00
dialog : addOption ( 0 , common.GetNLS ( User , " Nichts entnehmen " , " Do not withdraw any " ) )
User : requestSelectionDialog ( dialog )
end
end
2022-06-21 15:16:08 +02:00
function townProperties ( user , toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
local town = getTown ( toolTown )
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
end
local selected = dialog : getSelectedIndex ( ) + 1
if selected == 1 then
2022-06-21 15:16:08 +02:00
rentCollection ( user , toolTown , SourceItem )
2022-02-18 15:41:08 +01:00
else
2022-07-14 22:05:55 +02:00
utility.allowAllAutomaticRentExtension ( user , town )
2022-02-18 15:41:08 +01:00
end
end
local title = {
english = " Property Management " ,
2022-12-13 11:59:05 +01:00
german = " Grundst<EFBFBD> cksverwaltung "
2022-02-18 15:41:08 +01:00
}
local text = {
english = " Select what you want to do " ,
2022-12-13 11:59:05 +01:00
german = " Was m<> chtest du tun? "
2022-02-18 15:41:08 +01:00
}
local dialog = SelectionDialog ( common.GetNLS ( user , title.german , title.english ) , common.GetNLS ( user , text.german , text.english ) , callback )
2022-12-13 11:59:05 +01:00
dialog : addOption ( 0 , common.GetNLS ( user , " Miete abkassieren " , " Collect Rent " ) )
dialog : addOption ( 0 , common.GetNLS ( user , " Unbeaufsichtigte Mietverl<72> ngerung f<> r alle Grundst<73> cke zulassen " , " Allow Unsupervised Rent Extension for All properties " ) )
2022-02-18 15:41:08 +01:00
user : requestSelectionDialog ( dialog )
end
2023-10-02 20:00:05 +02:00
local function messageSeen ( user , toolTown )
2023-01-18 20:37:23 +01:00
local townNames = { " Cadomyr " , " Runewick " , " Galmair " }
local townBoardQuestIds = { Runewick = 256 , Cadomyr = 257 , Galmair = 258 }
local townQuestId = townBoardQuestIds [ townNames [ toolTown ] ]
local lastSeen = user : getQuestProgress ( townQuestId )
local foundLatest , latest = ScriptVars : find ( " latestMessage " .. townNames [ toolTown ] )
if foundLatest and tonumber ( latest ) ~= lastSeen then
user : setQuestProgress ( townQuestId , tonumber ( latest ) )
end
2023-10-02 20:00:05 +02:00
end
function TownAnnouncement ( user , toolTown )
messageSeen ( user , toolTown )
2019-08-18 06:14:18 +02:00
-- selection dialog
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
end
local selected = dialog : getSelectedIndex ( ) + 1
if selected == 1 then
2023-01-18 20:37:23 +01:00
TownAnnouncementShow ( user , toolTown )
2019-08-18 06:14:18 +02:00
elseif selected == 2 then
2023-01-18 20:37:23 +01:00
TownAnnouncementInput ( user , toolTown )
2019-08-18 06:14:18 +02:00
end
end
2020-12-06 23:34:30 +01:00
2023-01-18 20:37:23 +01:00
local dialogTitle = common.GetNLS ( user , " Ank<EFBFBD> ndigung " , " Announcement " )
local dialogText = common.GetNLS ( user , " W<EFBFBD> hle eine Option. " , " Chose an option. " )
2019-08-18 06:14:18 +02:00
local dialog = SelectionDialog ( dialogTitle , dialogText , callback )
2023-01-18 20:37:23 +01:00
local options = common.GetNLS ( user , { " Ank<EFBFBD> ndigung lesen " , " Ank<EFBFBD> ndigung schreiben " } , { " Read announcement " , " Write new announcement " } )
2020-12-06 23:34:30 +01:00
2019-08-18 06:14:18 +02:00
for i = 1 , # options do
dialog : addOption ( 0 , options [ i ] )
end
dialog : setCloseOnMove ( )
2023-01-18 20:37:23 +01:00
user : requestSelectionDialog ( dialog )
2020-12-06 23:34:30 +01:00
2019-08-18 06:14:18 +02:00
end
function TownAnnouncementShow ( User , toolTown )
2023-10-02 20:00:05 +02:00
messageSeen ( User , toolTown )
2019-08-18 06:14:18 +02:00
-- message dialog
local callback = function ( ) end --empty callback
local title = common.GetNLS ( User , " Derzeitige Ank<6E> ndigung " , " Current announcement " )
2020-12-06 23:34:30 +01:00
2019-08-18 06:14:18 +02:00
--read
2020-05-10 05:27:12 +02:00
local options = { " announcementCadomyr " , " announcementRunewick " , " announcementGalmair " }
2020-05-16 14:54:58 +02:00
local text
2020-12-06 23:34:30 +01:00
if options [ toolTown ] then
2020-05-16 14:54:58 +02:00
local found , value = ScriptVars : find ( options [ toolTown ] )
2019-08-18 06:14:18 +02:00
if found then
text = value
else
text = common.GetNLS ( User , " Keine Ank<6E> ndigungen. " , " No current announcement. " )
end
else
text = common.GetNLS ( User , " Fehler. Bitte informiere einen Entwickler. " , " Error. Please inform a developer. " )
end
2020-12-06 23:34:30 +01:00
2019-08-18 06:14:18 +02:00
local dialog = MessageDialog ( title , text , callback )
User : requestMessageDialog ( dialog )
end
2023-01-18 20:37:23 +01:00
function TownAnnouncementInput ( user , toolTown )
2019-08-18 06:14:18 +02:00
-- input dialog
2023-01-18 20:37:23 +01:00
local title = common.GetNLS ( user , " Ank<EFBFBD> ndigung schreiben " , " Write new announcement " )
2023-09-06 10:35:56 +02:00
local text = common.GetNLS ( user , " Schreibe deine neue Ank<6E> ndigung. Abbruch f<> hrt dazu, dass die derzeitige Ank<6E> ndigung beibehalten wird. " , " Write your new announcement. Cancel to keep current announcement. " )
2019-08-18 06:14:18 +02:00
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
else
local writtenText = dialog : getInput ( )
2020-04-26 11:01:49 +02:00
if string.len ( writtenText ) > 986 then
2023-01-18 20:37:23 +01:00
user : inform ( " Deine Ank<6E> ndigung ist zu lang. " , " The announcement is too long. " , Character.highPriority )
2019-08-18 06:14:18 +02:00
else
--write
2020-05-10 05:27:12 +02:00
local options = { " announcementCadomyr " , " announcementRunewick " , " announcementGalmair " }
local townNames = { " Cadomyr " , " Runewick " , " Galmair " }
2023-01-18 20:37:23 +01:00
local townBoardQuestIds = { Runewick = 256 , Cadomyr = 257 , Galmair = 258 }
local townQuestId = townBoardQuestIds [ townNames [ toolTown ] ]
2020-12-06 23:34:30 +01:00
if options [ toolTown ] then
2019-08-18 06:14:18 +02:00
ScriptVars : set ( options [ toolTown ] , writtenText )
2023-01-18 20:37:23 +01:00
local foundLatest , latest = ScriptVars : find ( " latestMessage " .. townNames [ toolTown ] )
if not foundLatest then
latest = 0
end
latest = tonumber ( latest ) + 1
ScriptVars : set ( " latestMessage " .. townNames [ toolTown ] , tostring ( latest ) )
2019-08-18 06:14:18 +02:00
ScriptVars : save ( )
2023-01-18 20:37:23 +01:00
user : setQuestProgress ( townQuestId , latest )
2019-08-18 06:14:18 +02:00
world : broadcast ( " In " .. townNames [ toolTown ] .. " wurde eine neue Ank<6E> ndigung ver<65> ffentlicht. " , " A new announcement has been published in " .. townNames [ toolTown ] .. " . " )
2020-12-06 23:34:30 +01:00
else
2023-01-18 20:37:23 +01:00
common.InformNLS ( user , " Ung<EFBFBD> ltige Stadt. Bitte informiere einen Entwickler. " , " Invalid town. Please report to a developer. " )
2019-08-18 06:14:18 +02:00
end
end
end
end
2020-04-26 11:01:49 +02:00
local dialog = InputDialog ( title , text , false , 986 , callback )
2023-01-18 20:37:23 +01:00
user : requestInputDialog ( dialog )
2019-08-18 06:14:18 +02:00
end
2014-02-02 02:25:06 +01:00
function TownGuard ( User , toolTown )
2014-05-12 11:19:22 +02:00
2015-10-29 19:13:08 +01:00
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
common.InformNLS ( User , " Abbruch. Niemand wurde gebannt. " , " Aborted. No one was banned. " )
return
2016-04-25 21:07:33 +02:00
end
local myString = dialog : getInput ( )
local myCharId
local myCharName
local allFound = false
2021-05-31 15:48:15 +02:00
local a , b , _
2016-04-25 21:07:33 +02:00
if string.find ( myString , " (%d+) " ) then
2021-05-31 15:48:15 +02:00
_ , _ , myCharId = string.find ( myString , " (%d+) " )
2016-04-25 21:07:33 +02:00
myCharId = tonumber ( myCharId )
allFound = true
elseif string.find ( myString , " .* " ) then
a , b = string.find ( myString , " .* " )
myCharName = string.sub ( myString , a , b )
allFound = true
end
if allFound then
local onlineChars = world : getPlayersOnline ( )
local theChar
for i = 1 , # onlineChars do
local checkChar = onlineChars [ i ]
if myCharId then
if checkChar.id == myCharId then
theChar = checkChar
break
2015-10-29 19:13:08 +01:00
end
else
2016-04-25 21:07:33 +02:00
if checkChar.name == myCharName then
theChar = checkChar
break
end
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
end
if not theChar then
common.InformNLS ( User , " Charakter wurde nicht gefunden. " , " Character was not found. " )
2015-10-29 19:13:08 +01:00
else
2016-04-25 21:07:33 +02:00
local townId = toolTown
factions.setIndividualPlayerRelation ( theChar , townId , factions.RELATION_HOSTILE , 3 ) ;
2017-01-03 12:58:33 -06:00
common.InformNLS ( User , theChar.name .. " ist f<> r einen Zwergentag gebannt. " , theChar.name .. " is banned for one dwarven day. " )
2016-04-25 21:07:33 +02:00
User : logAdmin ( " bans " .. theChar.name .. " for one day from " .. factions.getTownNameByID ( townId ) ) ;
2016-09-09 11:49:00 -04:00
log ( string.format ( " [Town Management] %s bans %s for one day from " .. factions.getTownNameByID ( townId ) ,
character.LogText ( User ) , theChar.name ) ) ;
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
else
common.InformNLS ( User , " Du hast nicht alle notwendige Information angegeben. " , " You haven't put in all necessary information. " )
2015-10-29 19:13:08 +01:00
end
end
2014-02-02 02:25:06 +01:00
2016-04-25 21:07:33 +02:00
local dialogTitle = common.GetNLS ( User , " Charakter bannen " , " Ban a character " )
local dialogText = common.GetNLS ( User , " Um einen Charakter einen Zwergentag zu bannen, gib folgendes an: [Name|ID] Beispiel: Max Mustermann " , " To ban a character for one dwarven day, please insert: [Name|ID] Example: John Doe " )
local dialog = InputDialog ( dialogTitle , dialogText , false , 255 , callback )
2020-12-06 23:34:30 +01:00
2016-04-25 21:07:33 +02:00
User : requestInputDialog ( dialog )
2014-02-02 02:25:06 +01:00
end
2024-02-19 12:45:16 +01:00
local function statusCheckAndConfirmation ( user , targetId , toolTown , townTool , name )
local statuses = {
2024-08-05 10:02:51 +02:00
granted = { english = " granted " , german = " Erteilt " } ,
restricted = { english = " restricted " , german = " Eingeschr<EFBFBD> nkt " } ,
default = { english = " the town default " , german = " Standard der Stadt " }
2024-02-19 12:45:16 +01:00
}
local oldStatus = townTool : getData ( " licence " .. targetId )
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
end
local selected = dialog : getSelectedIndex ( ) + 1
local chosenText
local noChange = false
local newStatus
if selected == 1 then
chosenText = common.GetNLS ( user , statuses.granted . german , statuses.granted . english )
if oldStatus == " granted " then
noChange = true
end
newStatus = statuses.granted . english
elseif selected == 2 then
chosenText = common.GetNLS ( user , statuses.restricted . german , statuses.restricted . english )
if oldStatus == " restricted " then
noChange = true
end
newStatus = statuses.restricted . english
elseif selected == 3 then
chosenText = common.GetNLS ( user , statuses.default . german , statuses.default . english )
if common.IsNilOrEmpty ( oldStatus ) then
noChange = true
end
newStatus = " "
end
if noChange then
2024-08-05 10:02:51 +02:00
user : inform ( " Die Rechte von " .. name .. " , die Werkzeuge der Stadt zu verwenden, sind bereit auf ' " .. chosenText .. " ' gesetzt. " , name .. " 's rights to use the town tools are already set to be " .. chosenText )
2024-02-19 12:45:16 +01:00
else
townTool : setData ( " licence " .. targetId , newStatus )
world : changeItem ( townTool )
2024-08-05 10:02:51 +02:00
user : inform ( " Die Rechte von " .. name .. " , die Werkzeuge der Stadt zu verwenden, wurde zu ' " .. chosenText .. " ' ge<67> ndert. " , name .. " 's rights to use the town tools have been changed to be " .. chosenText .. " . " )
2024-02-19 12:45:16 +01:00
end
end
--Check the status of the person, get confirmation for changing the status to the opposite status, save that new status in the townTool as item variable
2024-08-05 10:02:51 +02:00
local title = common.GetNLS ( user , " W<EFBFBD> hle den neuen Status " , " Select new status " )
local text = common.GetNLS ( user , " Bitte w<> hle den neuen Status aus, den du bez<65> glich der Lizenzen f<> r " .. name .. " festlegen m<> chtest. " , " Please select the new status you want to set in regards to licences for " .. name .. " . " )
2024-02-19 12:45:16 +01:00
local dialog = SelectionDialog ( title , text , callback )
2024-08-05 10:02:51 +02:00
dialog : addOption ( 0 , common.GetNLS ( user , " Erteilt " , " Granted " ) )
dialog : addOption ( 0 , common.GetNLS ( user , " Eingeschr<EFBFBD> nkt " , " Restricted " ) )
dialog : addOption ( 0 , common.GetNLS ( user , " Standard der Stadt " , " The town default " ) )
2024-02-19 12:45:16 +01:00
dialog : setCloseOnMove ( )
user : requestSelectionDialog ( dialog )
end
local function setIndividualsLicence ( user , toolTown , townTool )
local callback = function ( dialog )
if not dialog : getSuccess ( ) then
return
end
local input = dialog : getInput ( )
local targetExists , targetId = world : getPlayerIdByName ( input )
if not targetExists then
2024-08-05 10:02:51 +02:00
user : inform ( " Niemand in Illarion tr<74> gt diesen Namen. " , " No one by that name exists, at least not within the realms of Illarion. " )
2024-02-19 12:45:16 +01:00
return
end
statusCheckAndConfirmation ( user , targetId , toolTown , townTool , input )
end
2024-08-05 10:02:51 +02:00
local dialog = InputDialog ( common.GetNLS ( user , " Namenseingabe " , " Enter The Individuals Name " ) , common.GetNLS ( user , " Gib den Namen der Person ein, f<> r die du den Lizenzstatus innerhalb der Stadt <20> ndern m<> chtest. " , " Enter the name of the individual you wish to change the town's tool license status for. " ) , false , 255 , callback )
2024-02-19 12:45:16 +01:00
user : requestInputDialog ( dialog )
end
function TownLicence ( user , toolTown , townTool )
2014-05-12 11:19:22 +02:00
2016-04-25 21:07:33 +02:00
local factionIds = { 0 , 1 , 2 , 3 }
local FirstLicence = toolTown
local licenceStrings = { }
2024-02-19 12:45:16 +01:00
licenceStrings [ licence.PERMISSION_NONE ] = common.GetNLS ( user , " Benutzung von statischen Werkzeugen ist verboten. " , " Permission for static tools is restricted. " )
licenceStrings [ licence.PERMISSION_ACTIVE ] = common.GetNLS ( user , " Benutzung von statischen Werkzeugen ist erlaubt. " , " Permission for static tools is granted. " )
local TextWithRespctToA = common.GetNLS ( user , " f<> r " , " with respect to " )
local TextWithRespctToB = common.GetNLS ( user , " f<> r ... " , " with respect to ... " )
local TextSetLicenceOf = common.GetNLS ( user , " Setze die Lizenz von " , " Set licence of " )
local TextTo = common.GetNLS ( user , " auf ... " , " to ... " )
local TextLicence = common.GetNLS ( user , " Lizenz " , " Licence " )
local TextSetLicence = common.GetNLS ( user , " Setze Lizenz " , " Set licence " )
2016-04-25 21:07:33 +02:00
local licenceValues = { licence.PERMISSION_NONE , licence.PERMISSION_ACTIVE }
2015-10-29 19:13:08 +01:00
local cbSecondLicence = function ( dialog )
2016-04-25 21:07:33 +02:00
if not dialog : getSuccess ( ) then
return
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
local SecondLicence = factionIds [ dialog : getSelectedIndex ( ) + 1 ]
2024-02-19 12:45:16 +01:00
if dialog : getSelectedIndex ( ) + 1 == 5 then
setIndividualsLicence ( user , toolTown , townTool )
return
end
2021-05-31 15:48:15 +02:00
local cbSetLicence = function ( subdialog )
if not subdialog : getSuccess ( ) then
2016-04-25 21:07:33 +02:00
return
2015-10-29 19:13:08 +01:00
end
2021-05-31 15:48:15 +02:00
local newLicence = licenceValues [ subdialog : getSelectedIndex ( ) + 1 ]
2016-04-25 21:07:33 +02:00
licence.SetLicence ( FirstLicence , SecondLicence , newLicence )
licenceStrings [ licence.PERMISSION_NONE ] = " restricted "
licenceStrings [ licence.PERMISSION_ACTIVE ] = " granted "
2024-02-19 12:45:16 +01:00
user : logAdmin ( " sets license of " .. factions.getTownNameByID ( FirstLicence ) .. " with respect to " .. factions.getTownNameByID ( SecondLicence ) .. " to " .. licenceStrings [ newLicence ] )
2016-09-09 11:49:00 -04:00
log ( string.format ( " [Town Management] %s sets license of %s with respect to %s to " .. licenceStrings [ newLicence ] ,
2024-02-19 12:45:16 +01:00
character.LogText ( user ) , factions.getTownNameByID ( FirstLicence ) , factions.getTownNameByID ( SecondLicence ) ) ) ;
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
local sd = SelectionDialog ( TextSetLicence , TextSetLicenceOf .. factions.getTownNameByID ( FirstLicence ) .. TextWithRespctToA .. factions.getTownNameByID ( SecondLicence ) .. TextTo , cbSetLicence )
2015-10-29 19:13:08 +01:00
for _ , m in ipairs ( licenceValues ) do
2016-04-25 21:07:33 +02:00
sd : addOption ( 0 , licenceStrings [ m ] )
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
sd : setCloseOnMove ( )
2024-02-19 12:45:16 +01:00
user : requestSelectionDialog ( sd )
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
local sd = SelectionDialog ( TextLicence , TextSetLicenceOf .. factions.getTownNameByID ( FirstLicence ) .. TextWithRespctToB , cbSecondLicence )
2015-10-29 19:13:08 +01:00
for _ , f in ipairs ( factionIds ) do
2016-04-25 21:07:33 +02:00
sd : addOption ( 0 , factions.getTownNameByID ( f ) .. " : " .. licenceStrings [ licence.GetLicenceByFaction ( FirstLicence , f ) ] )
2015-10-29 19:13:08 +01:00
end
2024-08-05 10:02:51 +02:00
sd : addOption ( 0 , common.GetNLS ( user , " Setze Lizenz f<> r eine Person " , " Set licence for individual " ) )
2016-04-25 21:07:33 +02:00
sd : setCloseOnMove ( )
2024-02-19 12:45:16 +01:00
user : requestSelectionDialog ( sd )
2014-02-02 02:25:06 +01:00
end
2015-02-14 12:25:21 +01:00
local keyID = { }
2024-01-03 13:15:08 +01:00
keyID [ 1 ] = { 3054 , 3054 , 3054 , 2558 , 2558 , 2558 , 2558 , 2558 }
2015-05-10 16:03:20 -05:00
keyID [ 2 ] = { 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 }
2017-01-11 22:04:17 -06:00
keyID [ 3 ] = { 3056 , 3055 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 , 2558 }
2014-02-02 15:43:18 +01:00
2015-02-14 12:25:21 +01:00
local keydoorsID = { }
2024-01-03 13:15:08 +01:00
keydoorsID [ 1 ] = { 340 , 341 , 342 , 343 , 361 , 363 , 365 , 367 }
2015-05-10 20:21:33 +02:00
keydoorsID [ 2 ] = { 240 , 241 , 242 , 251 , 211 , 210 , 236 , 233 , 235 , 234 , 230 , 231 , 243 }
2017-01-11 22:04:17 -06:00
keydoorsID [ 3 ] = { 110 , 111 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 128 , 113 , 114 , 115 , 131 , 132 , 133 }
2014-02-02 15:43:18 +01:00
2015-02-14 12:25:21 +01:00
local keydoorsnameDE = { }
local keydoorsnameEN = { }
2024-01-03 13:15:08 +01:00
keydoorsnameDE [ 1 ] = { " Villa Annabeth " , " Villa Edward " , " Villa Reginald " , " Villa Annabeth Keller " , " Wohnungsquartier - Glaube & Gehorsam " , " Wohnungsquartier - Ehrlichkeit & Gerechtigkeit " , " Wohnungsquartier - Patriarchat " , " Schlangenturm " }
keydoorsnameEN [ 1 ] = { " Villa Annabeth " , " Villa Edward " , " Villa Reginald " , " Villa Annabeth Basement " , " Flat quarter - Faith & Obedience " , " Flat quarter - Truth & Justice " , " Flat quarter - Patriarchy " , " Serpent Tower " }
2015-05-10 20:21:33 +02:00
keydoorsnameDE [ 2 ] = { " Insel des Feuers Appartement 1 " , " Insel des Feuers Appartement 2 " , " Insel des Feuers Appartement 3 " , " Landhaus " , " Insel der Luft Appartement 2 " , " Insel der Luft Appartement 1 " , " Insel der Erde Appartement 6 " , " Insel der Erde Appartement 3 " , " Insel der Erde Appartement 5 " , " Insel der Erde Appartement 4 " , " Insel der Erde Appartement 1 " , " Insel der Erde Appartement 2 " , " Insel des Feuers Appartement 4 " }
keydoorsnameEN [ 2 ] = { " Island of Fire Apartment 1 " , " Island of Fire Apartment 2 " , " Island of Fire Apartment 3 " , " Cottage " , " Island of Air Apartment 2 " , " Island of Air Apartment 1 " , " Island of Earth Apartment 6 " , " Island of Earth Apartment 3 " , " Island of Earth Apartment 5 " , " Island of Earth Apartment 4 " , " Island of Earth Apartment 1 " , " Island of Earth Apartment 2 " , " Island of Fire Apartment 4 " }
2017-01-11 22:04:17 -06:00
keydoorsnameDE [ 3 ] = { " Malachite Haus " , " Villa Goldader " , " Wohnung Irmorom " , " Wohnung Elara " , " Wohnung Adron " , " Wohnung Malachin " , " Wohnung Oldra " , " Wohnung Nargun " , " Wohnung Ronagan " , " Wohnung Sirani " , " Wohnung Zhambra " , " Gl<EFBFBD> ckskupfer " , " Silberner Verdienst " , " Goldener Abschluss " , " Wohnung Saphir " , " Wohnung Diamant " , " Wohnung Obsidian " }
keydoorsnameEN [ 3 ] = { " House of Malachite " , " Villa Goldvein " , " Flat Irmorom " , " Flat Elara " , " Flat Adron " , " Flat Malachin " , " Flat Oldra " , " Flat Nargun " , " Flat Ronagan " , " Flat Sirani " , " Flat Zhambra " , " Lucky Copper " , " Silver Profit " , " Golden Deal " , " Flat Sapphire " , " Flat Diamond " , " Flat Obisidian " }
2014-02-02 15:43:18 +01:00
2014-02-02 02:25:06 +01:00
function TownKey ( User , toolTown )
2015-10-29 19:13:08 +01:00
local callback = function ( dialog )
2016-04-25 21:07:33 +02:00
if not dialog : getSuccess ( ) then
return
2015-10-29 19:13:08 +01:00
end
2016-04-25 21:07:33 +02:00
local selected = dialog : getSelectedIndex ( ) + 1
common.CreateItem ( User , keyID [ toolTown ] [ selected ] , 1 , 999 , { [ " lockId " ] = keydoorsID [ toolTown ] [ selected ] , [ " descriptionDe " ] = keydoorsnameDE [ toolTown ] [ selected ] , [ " descriptionEn " ] = keydoorsnameEN [ toolTown ] [ selected ] } )
User : logAdmin ( " creates a key for " .. keydoorsnameEN [ toolTown ] [ selected ] )
2016-09-09 11:49:00 -04:00
log ( string.format ( " [Town Management] %s creates a key for %s " ,
character.LogText ( User ) , keydoorsnameEN [ toolTown ] [ selected ] ) ) ;
2015-10-29 19:13:08 +01:00
end
2017-01-03 12:58:33 -06:00
local dialogTitle = common.GetNLS ( User , " Schl<EFBFBD> sselgenerator " , " Key-Generator " )
local dialogText = common.GetNLS ( User , " Erstelle einen Schl<68> ssel f<> r folgende Türen. " , " Create a key for following doors. " )
2016-04-25 21:07:33 +02:00
local dialog = SelectionDialog ( dialogTitle , dialogText , callback )
local keydoorsname = common.GetNLS ( User , keydoorsnameDE [ toolTown ] , keydoorsnameEN [ toolTown ] )
for i = 1 , # keydoorsname do
2015-10-29 19:13:08 +01:00
dialog : addOption ( 0 , keydoorsname [ i ] )
end
2016-04-25 21:07:33 +02:00
dialog : setCloseOnMove ( )
2015-10-29 19:13:08 +01:00
User : requestSelectionDialog ( dialog )
2014-02-02 02:25:06 +01:00
end
2017-07-25 21:47:04 +02:00
function TownMaterial ( User , townId )
collectionchest.manageCollections ( User , townId )
end
2014-11-13 18:54:08 +01:00
return M