2014-01-04 15:39:52 +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
2015-05-12 00:13:34 +02:00
with this program . If not , see < http : // www.gnu . org / licenses /> .
2014-01-04 15:39:52 +01:00
] ]
2010-06-09 17:17:34 +00:00
--- Base NPC script for basic NPCs
--
-- This script bundles the functions the most other specific components of the
-- NPC require to work. Its the basic script of the NPC framework and the only
-- one that requires regular from the actual NPC script.
--
-- Author: Martin Karing
2014-09-17 03:50:05 +02:00
local common = require ( " base.common " )
local class = require ( " base.class " )
2010-06-09 17:17:34 +00:00
2020-02-27 10:07:51 +01:00
local mutedNPCs = { }
2014-09-22 23:18:12 +02:00
local langCodeToSkill
local displayLanguageConfusion
2016-04-25 21:04:15 +02:00
local isAdminOnField
2010-06-09 17:17:34 +00:00
--- Constructor for the baseNPC. This does not take any paramters.
--
-- The sole purpose is to prepare all required values in the NPC script.
2015-05-12 00:13:34 +02:00
local baseNPC = class ( function ( self )
2014-09-24 11:55:33 +02:00
--- Constant for the state value of the NPC.
--- If this constant is set the NPC is currently in the normal mode.
self.stateNormal = 0
--- Constant for the state value of the NPC.
--- If this constant is set the NPC is currently busy talking with a specified
--- character and is not to walk around or anything like this.
self.stateBusyTalking = 1
2010-06-09 17:17:34 +00:00
-- The state of the NPC. This value can be used to have the special parts
-- of the NPC communicating with each other.
2014-09-24 11:55:33 +02:00
self [ " state " ] = self.stateNormal
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
-- The cycle functions are called during the next cycle method of this base
-- NPC struct. Each special NPC class is able to register functions in this
-- class.
2014-09-22 23:18:12 +02:00
self [ " _cycleFunctions " ] = nil
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
-- The receive text functions are called during the receive text method of
2015-05-12 00:13:34 +02:00
-- the NPC. Each special NPC class is able to register functions in this
2010-06-09 17:17:34 +00:00
-- class.
2014-09-22 23:18:12 +02:00
self [ " _receiveTextFunctions " ] = nil
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
-- The cycle counter counts the calls of the next cycle method in order to
-- find out when to execute the next time all the next cycle methods. This
-- is used to reduce the server load caused by this method.
2014-09-22 23:18:12 +02:00
self [ " _cycleCounter " ] = 0
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
-- This variable stores then to call the cycle methods the next time in
-- order to execute all functions of the NPC properly.
2014-09-22 23:18:12 +02:00
self [ " _nextCycleCalls " ] = 0
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable holds a list that stores the constants of the languages
-- the NPC is able to use.
2014-09-22 23:18:12 +02:00
self [ " _npcLanguages " ] = { }
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable holds the amount of languages added to the list of
-- languages of this NPC.
2014-09-22 23:18:12 +02:00
self [ " _npcLanguageCount " ] = 0
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the language the NPC is expected to use by default.
2014-09-22 23:18:12 +02:00
self [ " _defaultLanguage " ] = 0
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the german lookAt message of the NPC.
2014-09-22 23:18:12 +02:00
self [ " _lookAtMsgDE " ] = " "
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the english lookAt message of the NPC.
2014-09-22 23:18:12 +02:00
self [ " _lookAtMsgUS " ] = " "
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the german message that is said by the NPC in case
-- the player performs a use operation on the NPC.
2014-09-22 23:18:12 +02:00
self [ " _useMsgDE " ] = " "
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the english message that is said by the NPC in case
-- the player performs a use operation on the NPC.
2014-09-22 23:18:12 +02:00
self [ " _useMsgUS " ] = " "
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the german message that is shown in case the players
-- talk to the NPC in a language the NPC does not understand.
2014-09-22 23:18:12 +02:00
self [ " _confusedDE " ] = " "
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
-- This variable stores the english message that is shown in case the
-- players talk to the NPC in a language the NPC does not understand.
2014-09-22 23:18:12 +02:00
self [ " _confusedUS " ] = " "
2015-05-12 00:13:34 +02:00
2010-08-14 07:42:07 +00:00
-- This list is used to store the equipment that shall be set to the NPC at
-- the first run. Once the equipment is set, the list is destroyed.
2014-09-22 23:18:12 +02:00
self [ " _equipmentList " ] = { }
2015-05-12 00:13:34 +02:00
-- The town this NPC is affiliated to.
self [ " _affiliation " ] = 0
2014-09-22 23:18:12 +02:00
end )
2010-06-09 17:17:34 +00:00
--- This method adds one function to the functions that are called during the
2010-07-22 22:23:51 +00:00
--- next cycles.
2010-06-09 17:17:34 +00:00
--
-- @param receiver the receiver is a object that defines a nextCycle function
-- that is called in given time intervals. The only paramter
-- of this function is the time since the last call. The return
-- value has to be the time when the next call of this function
-- is expected. Its possible that the function is called ealier
-- but not later.
function baseNPC : addCycle ( receiver )
if ( type ( receiver ) ~= " table " ) then
2014-09-22 23:18:12 +02:00
return
end
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
if ( type ( receiver.nextCycle ) ~= " function " ) then
2014-09-22 23:18:12 +02:00
return
end
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
if ( self._cycleFunctions == nil ) then
2014-09-22 23:18:12 +02:00
self._cycleFunctions = { }
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
table.insert ( self._cycleFunctions , receiver )
end
2010-06-09 17:17:34 +00:00
--- This method adds one function to the functions that are called during when
2010-07-22 22:23:51 +00:00
--- a text is received by the NPC.
2010-06-09 17:17:34 +00:00
--
-- @param receiver the receiver is a object that defines a receiveText function
-- that is called all times the basic npc receives a text. The
-- receive text function has to take as first paramter the
-- character who is talking and as second parameter the text
-- that was spoken. In case the receiveText function returns
-- true the spoken text is not forwarded to any more possible
-- receivers.
function baseNPC : addRecvText ( receiver )
if ( type ( receiver ) ~= " table " ) then
2014-09-22 23:18:12 +02:00
return
end
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
if ( type ( receiver.receiveText ) ~= " function " ) then
2014-09-22 23:18:12 +02:00
return
end
2015-05-12 00:13:34 +02:00
2010-06-09 17:17:34 +00:00
if ( self._receiveTextFunctions == nil ) then
2014-09-22 23:18:12 +02:00
self._receiveTextFunctions = { }
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
table.insert ( self._receiveTextFunctions , receiver )
end
2010-06-09 17:17:34 +00:00
2012-11-20 20:34:11 +01:00
--- This method has to be called during each next cycle call of an NPC. It
2010-07-22 22:23:51 +00:00
--- manages and calls the functions registered this NPC. This function will be
--- removed during its first call. Instead the function originally named
--- baseNPC:nextCycle2() will take its place and serve its actual purpose.
2012-08-18 00:45:14 +02:00
--
-- @param npcChar the NPC character
function baseNPC : nextCycle ( npcChar )
2010-07-22 22:23:51 +00:00
if ( self.initLanguages ~= nil ) then
2014-09-22 23:18:12 +02:00
self : initLanguages ( npcChar )
end
2015-05-12 00:13:34 +02:00
2010-08-14 07:42:07 +00:00
if ( self._equipmentList ~= nil ) then
2014-09-22 23:18:12 +02:00
local tempList = self._equipmentList
self [ " _equipmentList " ] = nil
2015-05-12 00:13:34 +02:00
2014-08-18 10:58:18 +02:00
for _ , value in pairs ( tempList ) do
2014-09-22 23:18:12 +02:00
npcChar : createAtPos ( value [ 1 ] , value [ 2 ] , 1 )
local item = npcChar : getItemAt ( value [ 1 ] )
item.wear = 255
item.quality = 999
2015-05-12 00:13:34 +02:00
world : changeItem ( item )
2014-08-18 10:58:18 +02:00
end
2014-09-22 23:18:12 +02:00
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
self.nextCycle = self.nextCycle2
self.nextCycle2 = nil
end
2010-07-22 22:23:51 +00:00
2012-11-20 20:34:11 +01:00
--- This method has to be called during each next cycle call of an NPC. It
2010-07-22 22:23:51 +00:00
--- manages and calls the functions registered this NPC. This function will be
--- copied to baseNPC:nextCycle() once the initialization is done.
2012-08-18 00:45:14 +02:00
--
-- @param npcChar the NPC character
2015-05-12 00:13:34 +02:00
function baseNPC : nextCycle2 ( npcChar )
2010-06-09 17:17:34 +00:00
if ( self._cycleFunctions == nil ) then
2014-09-22 23:18:12 +02:00
return
end
2015-05-12 00:13:34 +02:00
2016-04-25 21:04:15 +02:00
if isAdminOnField ( npcChar.pos ) then
return
end
2010-06-09 17:17:34 +00:00
if ( self._cycleCounter < self._nextCycleCalls ) then
2014-09-22 23:18:12 +02:00
self._cycleCounter = self._cycleCounter + 1
return
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
npcChar.activeLanguage = self._defaultLanguage
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
local oldCycle = self._cycleCounter
self._cycleCounter = 0
self._nextCycleCalls = 2147483648
2015-05-12 00:13:34 +02:00
2014-08-18 10:58:18 +02:00
for _ , value in pairs ( self._cycleFunctions ) do
2021-05-31 15:48:15 +02:00
local nextRequestedCall = value : nextCycle ( npcChar , oldCycle )
2010-06-09 17:17:34 +00:00
if ( nextRequestedCall ~= nil and nextRequestedCall >= 0 ) then
2014-09-22 23:18:12 +02:00
self._nextCycleCalls = math.min ( self._nextCycleCalls , nextRequestedCall )
end
2014-08-18 10:58:18 +02:00
end
2014-09-22 23:18:12 +02:00
end
2010-06-09 17:17:34 +00:00
2015-05-12 00:13:34 +02:00
--- This method should be called at each call of the receive text method. This
2010-07-22 22:23:51 +00:00
--- method will maintain all functions registered to this class and call them
--- properly in case its needed.
2010-06-09 17:17:34 +00:00
--
2012-08-18 00:45:14 +02:00
-- @param npcChar the NPC character
2013-01-03 23:10:07 +01:00
-- @param textType the type that was used to send the text
2010-06-09 17:17:34 +00:00
-- @param speaker the character struct who said some text
-- @param text the text that was spoken
2010-08-13 10:25:36 +00:00
-- @return true in case the text was handled properly by one of the receive text handlers
2013-01-03 23:10:07 +01:00
function baseNPC : receiveText ( npcChar , texttype , speaker , text )
2020-03-01 09:55:58 +01:00
if not npcChar : isInRange ( speaker , 2 ) then
return false
end
2020-12-06 23:34:30 +01:00
2020-02-27 10:07:51 +01:00
if speaker : isAdmin ( ) then
2020-03-01 09:55:58 +01:00
local npcName = npcChar.name
2020-02-27 10:07:51 +01:00
if string.find ( text , " unmute " ) then
mutedNPCs [ npcChar.id ] = nil
2020-03-01 09:55:58 +01:00
speaker : inform ( " You unmute " .. npcName )
return false
2020-02-27 10:07:51 +01:00
elseif string.find ( text , " mute " ) then
mutedNPCs [ npcChar.id ] = true
2020-03-01 09:55:58 +01:00
speaker : inform ( " You mute " .. npcName )
return false
2020-02-27 10:07:51 +01:00
end
end
2020-12-06 23:34:30 +01:00
2020-02-27 10:07:51 +01:00
if mutedNPCs [ npcChar.id ] == true then
local npcName = npcChar.name
speaker : inform ( npcName .. " scheint heute nicht sehr gespr<70> chig. " , npcName .. " doesn't seem to be in a chatty mood today. " )
2020-03-01 09:55:58 +01:00
return false
2020-02-27 10:07:51 +01:00
end
2020-12-06 23:34:30 +01:00
2010-06-09 17:17:34 +00:00
if ( self._receiveTextFunctions == nil ) then
2014-09-22 23:18:12 +02:00
return false
end
2015-05-12 00:13:34 +02:00
2016-04-25 21:04:15 +02:00
if isAdminOnField ( npcChar.pos ) then
2014-09-22 23:18:12 +02:00
return false
end
2015-05-12 00:13:34 +02:00
2012-08-18 00:45:14 +02:00
if not npcChar : isInRange ( speaker , 2 ) then
2014-09-22 23:18:12 +02:00
return false
end
2010-07-23 21:32:37 +00:00
2012-08-18 00:45:14 +02:00
if ( speaker.id == npcChar.id ) then
2014-09-22 23:18:12 +02:00
return false
end
2010-07-23 21:32:37 +00:00
2011-07-25 16:18:09 +02:00
if ( speaker : getType ( ) ~= 0 ) then
2014-09-22 23:18:12 +02:00
return false
end
2010-07-23 21:32:37 +00:00
2010-08-13 10:31:57 +00:00
if not self : checkLanguageOK ( speaker ) then
2014-09-22 23:18:12 +02:00
displayLanguageConfusion ( npcChar , self )
return false
end
npcChar.activeLanguage = speaker.activeLanguage
text = string.lower ( text )
2015-05-12 00:13:34 +02:00
2014-08-18 10:58:18 +02:00
for _ , value in pairs ( self._receiveTextFunctions ) do
2013-01-03 23:10:07 +01:00
if ( value : receiveText ( npcChar , texttype , speaker , text ) ) then
2014-09-22 23:18:12 +02:00
return true
end
2014-08-18 10:58:18 +02:00
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
return false
end
2010-07-22 22:23:51 +00:00
--- This function checks if the language currently spoken by a character is
--- valid to be used by this NPC.
--
-- @param speak the character who is speaking
-- @return true in case the NPC is able to speak the language of the player
function baseNPC : checkLanguageOK ( speaker )
if ( speaker.activeLanguage == self._defaultLanguage ) then
2014-09-22 23:18:12 +02:00
return true
end
2015-05-12 00:13:34 +02:00
2010-07-22 22:23:51 +00:00
for i = 1 , self._npcLanguageCount do
if ( speaker.activeLanguage == self._npcLanguages [ i ] ) then
2014-09-22 23:18:12 +02:00
return true
end
end
2015-05-12 00:13:34 +02:00
2014-09-22 23:18:12 +02:00
return false
end
2010-07-22 22:23:51 +00:00
--- This function adds a language constant to the list of enabled languages of
--- this NPC.
--
-- @param langCode the code of the language the NPC is supposed to know
function baseNPC : addLanguage ( langCode )
table.insert ( self._npcLanguages , langCode )
2014-09-22 23:18:12 +02:00
self._npcLanguageCount = self._npcLanguageCount + 1
end
2010-07-22 22:23:51 +00:00
--- This function sets the language the NPC is supposed to use by default. The
--- only case it is switching the language is, in case he answeres to a player
--- talking in another language.
--
-- @param langCode the code value of the language to use
function baseNPC : setDefaultLanguage ( langCode )
2014-09-22 23:18:12 +02:00
self._defaultLanguage = langCode
end
2010-07-22 22:23:51 +00:00
--- This function sets the texts that are displayed when someone is looking at
--- the NPC.
--
-- @param german the german message
-- @param english the english message
function baseNPC : setLookat ( german , english )
2014-09-22 23:18:12 +02:00
self._lookAtMsgDE = german
self._lookAtMsgUS = english
end
2010-07-22 22:23:51 +00:00
--- This function sets the text that are displayed when someone is using the
--- NPC.
--
-- @param german the german message
-- @param english the english message
function baseNPC : setUseMessage ( german , english )
2014-09-22 23:18:12 +02:00
self._useMsgDE = german
self._useMsgUS = english
end
2010-07-22 22:23:51 +00:00
--- This function sets the text that is displayed in case a player is talking
--- in the wrong language with the NPC.
--
-- @param german the german message
-- @param english the english message
function baseNPC : setConfusedMessage ( german , english )
2014-09-22 23:18:12 +02:00
self._confusedDE = german
self._confusedUS = english
end
2010-07-22 22:23:51 +00:00
--- This method handles the lookat requests that are send to the NPC. If set
--- properly a message will be returned describing the appearance of the NPC.
--
2012-08-18 00:45:14 +02:00
-- @param npcChar the NPC character
2010-07-22 22:23:51 +00:00
-- @param char the character who is looking at the NPC
-- @param mode the mode used to look at the NPC (no effect)
2012-08-18 00:45:14 +02:00
function baseNPC : lookAt ( npcChar , char , mode )
2014-09-22 23:18:12 +02:00
char : sendCharDescription ( npcChar.id , common.GetNLS ( char , self._lookAtMsgDE , self._lookAtMsgUS ) )
end
2010-07-22 22:23:51 +00:00
--- This method handles all use methods that are done to the NPC. When ever a
--- NPC is used by the player this one is called.
--
2012-08-18 00:45:14 +02:00
-- @param npcChar the NPC character
2010-07-22 22:23:51 +00:00
-- @param char the character who is looking at the NPC
-- @param mode the mode used to look at the NPC (no effect)
2012-08-18 00:45:14 +02:00
function baseNPC : use ( npcChar , char )
2015-03-31 20:40:45 +02:00
2020-02-27 10:07:51 +01:00
if char : isAdmin ( ) then
local lastSpoken = char.lastSpokenText
if string.find ( string.lower ( lastSpoken ) , " teleport " ) then
local coords = { }
2020-12-06 23:34:30 +01:00
for coord in lastSpoken : gmatch ( " %-?%d+ " ) do
table.insert ( coords , tonumber ( coord ) )
2020-02-27 10:07:51 +01:00
end
if coords [ 1 ] and coords [ 2 ] and coords [ 3 ] then
npcChar : forceWarp ( position ( coords [ 1 ] , coords [ 2 ] , coords [ 3 ] ) )
end
end
end
2020-12-06 23:34:30 +01:00
2020-02-27 10:07:51 +01:00
if mutedNPCs [ npcChar.id ] == true then
local npcName = npcChar.name
char : inform ( npcName .. " scheint heute nicht sehr gespr<70> chig. " , npcName .. " doesn't seem to be in a chatty mood today. " )
return
end
2016-04-25 21:04:15 +02:00
if isAdminOnField ( npcChar.pos ) then
return
end
2014-09-22 23:18:12 +02:00
npcChar.activeLanguage = self._defaultLanguage
2015-05-12 00:13:34 +02:00
local getText = function ( deText , enText ) return common.GetNLS ( char , deText , enText ) end
2015-03-31 20:40:45 +02:00
local callback = function ( dialog )
local success = dialog : getSuccess ( )
if success then
local selected = dialog : getSelectedIndex ( )
2015-05-12 00:13:34 +02:00
if selected == 5 then --free input
local callbackInput = function ( dialogInput )
if not dialogInput : getSuccess ( ) then
return ;
else
local text = dialogInput : getInput ( )
char : talk ( Character.say , text , text )
end
end
local dialogInput
2017-04-06 10:13:28 +02:00
dialogInput = InputDialog ( npcChar.name , getText ( " <EFBFBD> ber welches Thema m<> chtest du sprechen?" , " Select the topic you want to talk about. " ) , false , 255 , callbackInput )
2015-05-12 00:13:34 +02:00
char : requestInputDialog ( dialogInput )
else
local textDE = { }
local textEN = { }
textDE [ 0 ] = " Seid gegr<67> <72> t. "
textEN [ 0 ] = " Be greeted. "
textDE [ 1 ] = " Ich ben<65> tige Hilfe. "
textEN [ 1 ] = " Please help me. "
textDE [ 2 ] = " Habt Ihr eine Aufgabe f<> r mich? "
textEN [ 2 ] = " Do you have a task for me? "
textDE [ 3 ] = " Ich m<> chte Waren handeln. "
textEN [ 3 ] = " I'd like to trade some goods. "
textDE [ 4 ] = " Auf wiedersehen. "
textEN [ 4 ] = " Farewell. "
2016-10-31 18:59:30 +01:00
char : talk ( Character.say , getText ( textDE [ selected ] , textEN [ selected ] ) )
2015-05-12 00:13:34 +02:00
end
2015-03-31 20:40:45 +02:00
end
end
2015-05-12 00:13:34 +02:00
local dialog = SelectionDialog ( npcChar.name , getText ( " <EFBFBD> ber welches Thema m<> chtest du sprechen?" , " Select the topic you want to talk about. " ) , callback )
2015-03-31 20:40:45 +02:00
dialog : setCloseOnMove ( )
dialog : addOption ( 0 , getText ( " Begr<EFBFBD> <EFBFBD> en " , " Greetings " ) )
2015-05-12 00:13:34 +02:00
dialog : addOption ( 0 , getText ( " Hilfe " , " Help " ) )
dialog : addOption ( 0 , getText ( " Quest " , " Quest " ) )
dialog : addOption ( 0 , getText ( " Handel " , " Trade " ) )
dialog : addOption ( 0 , getText ( " Verabschieden " , " Farewell " ) )
dialog : addOption ( 0 , getText ( " (Etwas anderes) " , " (Other) " ) )
2015-04-17 17:23:10 +02:00
char : requestSelectionDialog ( dialog )
2014-09-22 23:18:12 +02:00
end
2010-07-22 22:23:51 +00:00
2012-11-20 20:34:11 +01:00
--- This equipment sets the equipment an NPC gets at first start. This is needed
2010-08-14 07:42:07 +00:00
--- so the NPC looks good with paperdolling.
--
-- @param slot the slot the item is to be placed in
-- @param item the item ID that shall be created
function baseNPC : setEquipment ( slot , item )
2014-09-22 23:18:12 +02:00
table.insert ( self [ " _equipmentList " ] , { slot , item } )
end
2010-08-14 07:42:07 +00:00
2014-01-12 14:48:07 +01:00
--- This function is used to set the affiliation of the NPC.
--
-- @param affiliation the index of the town this NPC is assigned to
function baseNPC : setAffiliation ( affiliation )
2015-05-12 00:13:34 +02:00
self [ " _affiliation " ] = affiliation
2014-09-22 23:18:12 +02:00
end
2014-01-12 14:48:07 +01:00
2010-07-22 22:23:51 +00:00
--- This is a cleanup function that should be called once the initialization of
--- the NPC is done. It will free the memory taken by all the functions that are
--- needed to fill data into the NPC.
function baseNPC : initDone ( )
2014-09-22 23:18:12 +02:00
self [ " addCycle " ] = nil
self [ " addRecvText " ] = nil
self [ " addLanguageCode " ] = nil
self [ " setDefaultLanguage " ] = nil
self [ " setLookat " ] = nil
self [ " setUseMessage " ] = nil
self [ " setConfusedMessage " ] = nil
self [ " setEquipment " ] = nil
self [ " initDone " ] = nil
end
2010-07-22 22:23:51 +00:00
2012-12-30 12:29:53 +01:00
function baseNPC : setAutoIntroduceMode ( autointroduce )
2014-09-22 23:18:12 +02:00
end
2012-12-30 12:29:53 +01:00
2010-07-22 22:23:51 +00:00
--- This function learns the NPC the languages skills needed to work properly.
--- Check if this function is not nil before you call it, because it destructs
--- itself after it was called once.
2012-08-18 00:45:14 +02:00
--
-- @param npcChar the NPC character
function baseNPC : initLanguages ( npcChar )
2014-08-18 10:58:18 +02:00
for _ , value in pairs ( self._npcLanguages ) do
2014-09-22 23:18:12 +02:00
npcChar : increaseSkill ( langCodeToSkill ( value ) , 100 )
2014-08-18 10:58:18 +02:00
end
2014-09-22 23:18:12 +02:00
self [ " initLanguages " ] = nil
end
2010-07-22 22:23:51 +00:00
--- This function translates a language code value to the skill that belongs to
--- this number. This skill name is needed to set the skill value of the NPC in
--- so the NPC is able to talk in the needed language perfectly.
--
-- @param langCode the language code
2012-10-28 16:05:39 +01:00
-- @return the skill fitting to the language code
function langCodeToSkill ( langCode )
2010-07-22 22:23:51 +00:00
if ( langCode == 0 ) then
2014-09-22 23:18:12 +02:00
return Character.commonLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 1 ) then
2014-09-22 23:18:12 +02:00
return Character.humanLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 2 ) then
2014-09-22 23:18:12 +02:00
return Character.dwarfLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 3 ) then
2014-09-22 23:18:12 +02:00
return Character.elfLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 4 ) then
2014-09-22 23:18:12 +02:00
return Character.lizardLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 5 ) then
2014-09-22 23:18:12 +02:00
return Character.orcLanguage
2010-07-22 22:23:51 +00:00
elseif ( langCode == 10 ) then
2014-09-22 23:18:12 +02:00
return Character.ancientLanguage
2010-07-22 22:23:51 +00:00
else
2014-09-22 23:18:12 +02:00
return Character.commonLanguage
end
end
--- This function is used to display the message that the NPC is not able to
--- understand the language the player character is speaking. It should be
--- called every time the languageOK check is failing because it has its own
--- protection against spamming.
--
-- @param npcChar the NPC character
-- @param npc the baseNPC instance that is referred to
function displayLanguageConfusion ( npcChar , npc )
2016-04-04 21:35:39 +02:00
if not common.spamProtect ( npcChar , 60 ) then
2014-09-22 23:18:12 +02:00
npcChar.activeLanguage = npc._defaultLanguage
npcChar : talk ( Character.say , npc._confusedDE , npc._confusedUS )
end
end
2016-04-25 21:04:15 +02:00
-- check if there is a GM "possessing" the NPC
function isAdminOnField ( pos )
local stackedChar = world : getCharacterOnField ( pos )
if stackedChar : isAdmin ( ) then
return true
end
return false
end
2015-05-12 00:13:34 +02:00
return baseNPC