summaryrefslogtreecommitdiff
path: root/src/scripting/luascript.cpp
AgeCommit message (Collapse)AuthorFilesLines
2013-09-08Renamed character.cpp to charactercomponent.cppErik Schilling1-1/+1
Now we do not have two character.cpp files in the repository.
2013-08-26Moved AttributeInfo into a seperate fileErik Schilling1-1/+1
2013-08-26Allowed to push attributeinfos for the attribute recalculationErik Schilling1-0/+7
While on it I replaced the id usage in the server with the usage of the AttributeInfo directly. Next steps: - Dehardcode the core attribute ids and store their attributeinfos somewhere in AttributeManager (for now i simply wrapped the ids with getAttributeInfo(). - Move AttributeInfo out of AttributeManager to shorten the usage + to allow using a pointer in ModifierLocation without forward declaring it.
2013-05-02Fixed a bunch of cppcheck warningsErik Schilling1-5/+3
2013-04-27Use nullptr instead of NULL everywhereErik Schilling1-1/+1
2013-04-14Use a full user data for Entity referencesThorbjørn Lindeijer1-6/+3
Only moved a single script function to a member for now, will do others in a separate commit.
2013-04-11Converted Being into a ComponentErik Schilling1-3/+3
I did not really care too much about staying consistent with the use of static_casts to Actors since they are only temporary anyway until Actor is a component too.
2013-04-11Converted the Character class into a componentErik Schilling1-6/+8
A CharacterData was created as a proxy class in order to allow using the old serialization method.
2013-02-21Introduced Script::ContextErik Schilling1-10/+15
This should allow to finally call functions to lua without having to care about working around situations where a lua call causes a c++ call which needs to call to lua again. Tested against the source of tales repository data.
2013-01-09Replaced EventListener with signals based on libsigc++Thorbjørn Lindeijer1-2/+0
This replaces the rather hard to understand event dispatcher with a probably even harder to understand templated library, but fortunately we can rely on the available documentation. Hopefully it will also help with the readability of our code and with adding additional signals to other classes. Added libsigc++ to README and Travis CI configuration. Reviewed-by: Erik Schilling
2013-01-09Micro-optimizations for pushing strings to LuaThorbjørn Lindeijer1-1/+1
Use lua_pushliteral and lua_pushlstring instead of lua_pushstring, which avoids Lua having to determine the length of the string.
2013-01-09Added support for Lua 5.2Thorbjørn Lindeijer1-0/+4
Should still work against Lua 5.1 as well.
2013-01-07Set the current map when executing being callbacksThorbjørn Lindeijer1-0/+2
The on_death and on_remove callbacks where not being executed in the context of any map. Now they execute in the context of the map of the being. Reviewed-by: Erik Schilling
2012-08-05Fixed the atinit functionErik Schilling1-0/+1
Previously each map had its own scope. They got merged now but the atinit function was forgotten to adapt. Reviewed-by: bjorn.
2012-07-11Made sure the map is set for trigger scriptsErik Schilling1-0/+1
Also unsetted maps after execution of scripts to make finding this mistakes easier. Reviewed-by: bjorn.
2012-04-04Renamed Thing to EntityThorbjørn Lindeijer1-6/+6
In preparation for using an entity/component system for the entities in the game world, this name will be more recognizable and easier to talk about. Reviewed-by: Yohann Ferreira
2012-04-04Enhanced special supportErik Schilling1-1/+4
- Made the current charge being saved. - Added script binds: - chr_set_special_recharge_speed - chr_get_special_recharge_speed - chr_set_special_mana - chr_get_special_mana - get_special_info - Added special info lua class. Functions: - name - needed_mana - rechargeable - on_use - on_recharged - category Further the engine no longer sets charge to 0 after using of specials this allows more flexbilillity (like failing specials). Changes on the xml database: - recharge renamed to rechargeable (needed by client and server) - needed - the needed mana to trigger a special (server only) - rechargespeed - the defailt recharge speed in mana per tick (server only) - target - the type of target (either being or point) (server and client) I also made the lua engine pushing nil instead of a 0 light userdata when the pointer was 0. Database update needed. Change is tested. Mana-Mantis: #167, #156 Reviewed-by: bjorn.
2012-03-11Removed the create_npc wrapper and the last two NPC callbacksThorbjørn Lindeijer1-2/+11
When creating an NPC, you now provide its optional talk and update functions directly rather than them being stored in a table on the Lua side and then called in response to a global callback. Also fixed an issue with a missing gender parameter to the delayed NPC creation callback used by NPCs defined on the map (found by Erik while reviewing this patch). Reviewed-by: Erik Schilling
2012-03-11Added callbacks for map/worldvar changesErik Schilling1-3/+5
Reviewed-by: bjorn.
2012-03-10Moved the managing of NPC script coroutines into C++Thorbjørn Lindeijer1-48/+135
Rather than wrapping NPC functions up in coroutines in the Lua side, they are now managed on the C++ side as "script threads", which are essentially the same thing. The main purpose is that the server can now know whether any of these long running script interactions are still active, which will probably be useful when adding the ability to reload scripts. Reviewed-by: Erik Schilling
2012-03-07Added a function that returns the current map or raises an errorThorbjørn Lindeijer1-0/+2
The new function 'checkCurrentMap' will raise an error when no current map has been set, eliminating the need to do custom error handling all over the place. This also fixes several functions that would otherwise have simply crashed when there was no current map. Also cleaned up some "empty string parameter" checks. Reviewed-by: Erik Schilling
2012-03-03Removed the last direct call to global script functionThorbjørn Lindeijer1-11/+0
The ScriptAction of the TriggerArea (which can be created by mana.trigger_create) was still using a named global function for its callback. Now it also uses a reference to a script function. Since it was the last occurrence of a call to a global script function, I've also removed the Script::prepare(std::string) overload. Reviewed-by: Erik Schilling Mantis-issue: 299
2012-03-02Converted functions called by LuaScript to callbacksThorbjørn Lindeijer1-35/+46
This includes the quest reply, post reply, death notification and remove notification. Also, Script::Ref was changed from a typedef to a small class, automating initialization and making the check for validness clearer. Reviewed-by: Erik Schilling
2012-03-02Use callbacks for handling character death and respawnThorbjørn Lindeijer1-0/+20
Rather than relying on the availability of global functions with certain predefined names, the Lua script now calls API functions to set which function should be called on these global events. This mechanism should make it easier to avoid name collisions in the global namespace, which is important now that there is only a single script state. For these global events this was not likely to become a problem, but this solution can also be used for callbacks on specific item or monster types, or even allow setting callbacks on certain instances. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
2012-03-02Simplified some of the Lua backendThorbjørn Lindeijer1-3/+1
Mainly introduced a helper function for getting to the Script instance for the current Lua state. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
2011-11-07Merged three global script states into oneThorbjørn Lindeijer1-33/+0
These scripts could trivially share one script state, since the methods called on them from the server are not overlapping. This does leave them open to access each other's global variables, but that's the problem with global variables. The one remaining global script file name is now configurable, so that it may also be set to a script in a different scripting language. The two related script options are: script_mainFile (default: scripts/main.lua) script_defaultEngine (default: lua) - renamed from defaultScriptEngine Reviewed-by: jurkan Reviewed-by: Yohann Ferreira
2011-04-27Added a simple crafting systemPhilipp Sehmisch1-0/+38
A client can craft something using the @craft command. The command needs a list of item names and amounts. The gameserver checks if the character has these items in the inventory and then passes the list together with the character handle to the lua script function on_craft in the script file scripts/crafting.lua. This function can then be used to evaluate if the list is a valid crafting combination and when this is the case take or give items. Implemented two example crafting scripts there, one which enforces exact item order and amount and one which doesn't. Both are disabled per default and one needs to be enabled by uncommenting a line. Also gave the player group permission to use the @craft command in permissions.xml and added two new items (wood and iron) required for the example crafting combination. Resolves: #333 Reviewed-by: bcs86, Bertram
2011-03-17Micro-optimizations related to std::stringThorbjørn Lindeijer1-1/+1
* Rely on the fact that a std::string is empty by default * Use std::string::empty() rather than comparing to "" * Construct with std::string() rather than from "" Reviewed-by: Bertram
2010-11-14Renamed .hpp files into .h for consistency.Yohann Ferreira1-2/+2
Also added an header to the autoattack.{h,cpp} files. Big but trivial fix.
2010-08-22Pass a script name to Lua for proper reporting of error locationsThorbjørn Lindeijer1-5/+5
Now the Lua file name shows up in the error message and stack traceback, or the map file and object name in case of a script embedded in a map file.
2010-08-22Rename some stuff to conform to naming conventionsThorbjørn Lindeijer1-8/+8
2010-08-22Print out a backtrace when a Lua error is raisedThorbjørn Lindeijer1-19/+19
The backtrace is printed by using debug.traceback as error handler when calling Lua functions. At the moment it still looks pretty ugly since Lua is not aware of the file names of the scripts (to be fixed). Reviewed-by: Jared Adams
2010-08-22Print out the actual error message in case of a syntax errorThorbjørn Lindeijer1-3/+7
Should help to locate the problem. Reviewed-by: Jared Adams
2010-07-09Added LUA script bindings for manipulating the specials available to a ↵Philipp Sehmisch1-0/+11
character. Added script call for getting the cost of a special (recharge only for now) Deleting specials works server-sided but the client isn't informed about it properly. Specials without recharge cost don't appear for the player. Both of these features require an additional netcode message. Reviewed-by: Freeyorp
2010-04-11Implemented handler for on_chr_death and put the loading of the global ↵Philipp Sehmisch1-0/+11
script into a method of class LuaScript Reviewed-by: Jared Adams <Jaxad0127@gmail.com>
2010-02-07Update Copyright date for Manaserv.Bertram1-1/+1
2009-12-06Fixed name of the project in copyright headersThorbjørn Lindeijer1-7/+6
Also updated the headers to refer to the GPL by URL instead of suggesting to contact the FSF by snail mail, as per the latest GPL usage instructions.
2009-04-26Standardize on the position of the const keywordBjørn Lindeijer1-8/+8
Same as for the client.
2009-01-31Added on_remove callback to lua APIPhilipp Sehmisch1-1/+10
2009-01-22Reduced the size of lua.cpp by putting the class LuaScript and the utility ↵Philipp Sehmisch1-0/+150
functions in separate files leaving only the script bindings themself. Unified internal and external names of lua script bindings.