diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-11-01 04:07:56 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-11-01 04:07:56 +0100 |
commit | 22142fd2cc8dd262ca1202ffeb5f4ef714870c4c (patch) | |
tree | ca0a1eaeb781baec2c4e5b22cf9df60fa89f2982 /src | |
parent | 5bd0ddb6e2d1b002372541f911a2764ed2e54e6c (diff) | |
parent | a5895b1655be3e81f451844a911eab8b798fa7ab (diff) | |
download | manaserv-22142fd2cc8dd262ca1202ffeb5f4ef714870c4c.tar.gz manaserv-22142fd2cc8dd262ca1202ffeb5f4ef714870c4c.tar.xz manaserv-22142fd2cc8dd262ca1202ffeb5f4ef714870c4c.zip |
Merge github.com:mana/manaserv
Conflicts:
src/game-server/character.cpp
src/scripting/lua.cpp
Diffstat (limited to 'src')
-rw-r--r-- | src/common/manaserv_protocol.h | 2 | ||||
-rw-r--r-- | src/game-server/character.cpp | 8 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 11 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 5 | ||||
-rw-r--r-- | src/game-server/mapcomposite.cpp | 39 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 4 | ||||
-rw-r--r-- | src/game-server/statusmanager.cpp | 4 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 2 | ||||
-rw-r--r-- | src/scripting/script.cpp | 18 | ||||
-rw-r--r-- | src/scripting/script.h | 1 | ||||
-rw-r--r-- | src/sql/mysql/updates/update_14_to_16.sql (renamed from src/sql/mysql/updates/update_15_to_16.sql) | 0 | ||||
-rw-r--r-- | src/sql/sqlite/updates/update_14_to_16.sql (renamed from src/sql/sqlite/updates/update_15_to_16.sql) | 0 |
12 files changed, 71 insertions, 23 deletions
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 4cca951..8946a39 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -433,8 +433,6 @@ enum BeingDirection /** * Beings Genders - * WARNING: Has to be in sync with the same enum in the Being class - * of the client! */ enum BeingGender { diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 0cdd57b..41d0545 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -301,9 +301,11 @@ void Character::setGender(int gender) { switch (gender) { - case GENDER_MALE: - case GENDER_FEMALE: - mGender = (BeingGender)gender; + case 0: + mGender = GENDER_MALE; + break; + case 1: + mGender = GENDER_FEMALE; break; default: mGender = GENDER_UNSPECIFIED; diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 0cde989..6064811 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -60,7 +60,7 @@ static void handleRecall(Character*, std::string&); static void handleBan(Character*, std::string&); static void handleItem(Character*, std::string&); static void handleDrop(Character*, std::string&); -//static void handleMoney(Character*, std::string&); +static void handleMoney(Character*, std::string&); static void handleSpawn(Character*, std::string&); static void handleAttribute(Character*, std::string&); static void handleReload(Character*, std::string&); @@ -102,8 +102,8 @@ static CmdRef const cmdRef[] = "Creates a number of items in the inventory of a character", &handleItem}, {"drop", "<item id> <amount>", "Drops a stack of items on the ground at your current location", &handleDrop}, -/* {"money", "<character> <amount>", - "Changes the money a character possesses", &handleMoney},*/ + {"money", "<character> <amount>", + "Changes the money a character possesses", &handleMoney}, {"spawn", "<monster id> <number>", "Creates a number of monsters near your location", &handleSpawn}, {"attribute", "<character> <attribute> <value>", @@ -594,7 +594,7 @@ static void handleDrop(Character *player, std::string &args) str << "User created item " << ic->getDatabaseID(); accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_DROP, str.str()); } -/* + static void handleMoney(Character *player, std::string &args) { Character *other; @@ -639,13 +639,12 @@ static void handleMoney(Character *player, std::string &args) value = utils::stringToInt(valuestr); // change how much money the player has - Inventory(other).changeMoney(value); + other->setAttribute(ATTR_GP , other->getAttribute(ATTR_GP) + value); // log transaction std::string msg = "User created " + valuestr + " money"; accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_MONEY, msg); } -*/ static void handleSpawn(Character *player, std::string &args) { diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index be405b8..ffbdce8 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -432,7 +432,10 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item) } LOG_INFO("Loading item script: " << filename.str()); - Script *script = Script::create("lua"); + + std::string engineName = + Script::determineEngineByFilename(filename.str()); + Script *script = Script::create(engineName); if (!script->loadFile(filename.str())) { // Delete the script as it's invalid. diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index ecd3956..4d0581a 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -727,14 +727,23 @@ void MapComposite::initializeContent() } else if (utils::compareStrI(type, "NPC") == 0) { + int npcId = utils::stringToInt(object->getProperty("NPC_ID")); + std::string scriptText = object->getProperty("SCRIPT"); + if (!mScript) { - mScript = Script::create("lua"); + // Determine script engine by xml property + std::string scriptEngineName = object->getProperty("ENGINE"); + if (scriptEngineName.empty()) + { + // Set engine to default value and print warning + scriptEngineName = Configuration::getValue("defaultScriptEngine", "lua"); + LOG_WARN("No script engine specified for map script \"" + + mName + "\", falling back to default"); + } + mScript = Script::create(scriptEngineName); } - int npcId = utils::stringToInt(object->getProperty("NPC_ID")); - std::string scriptText = object->getProperty("SCRIPT"); - if (npcId && !scriptText.empty()) { mScript->loadNPC(object->getName(), npcId, @@ -748,14 +757,28 @@ void MapComposite::initializeContent() } else if (utils::compareStrI(type, "SCRIPT") == 0) { + std::string scriptFilename = object->getProperty("FILENAME"); + std::string scriptText = object->getProperty("TEXT"); + if (!mScript) { - mScript = Script::create("lua"); + // Determine script engine by xml property + std::string scriptEngineName = object->getProperty("ENGINE"); + if (!scriptFilename.empty() && scriptEngineName.empty()) + { + // Engine property is empty - determine by filename + scriptEngineName = Script::determineEngineByFilename(scriptFilename); + } + else if (scriptEngineName.empty()) + { + // Set engine to default value and print warning + scriptEngineName = Configuration::getValue("defaultScriptEngine", "lua"); + LOG_WARN("No script engine specified for map script \"" + + mName + "\", falling back to default"); + } + mScript = Script::create(scriptEngineName); } - std::string scriptFilename = object->getProperty("FILENAME"); - std::string scriptText = object->getProperty("TEXT"); - if (!scriptFilename.empty()) { mScript->loadFile(scriptFilename); diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 0f38791..a976b81 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -335,7 +335,9 @@ void Monster::loadScript(const std::string &scriptName) if (ResourceManager::exists(filename.str())) { LOG_INFO("Loading monster script: " << filename.str()); - mScript = Script::create("lua"); + std::string engineName = + Script::determineEngineByFilename(filename.str()); + mScript = Script::create(engineName); mScript->loadFile(filename.str()); } else diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp index 7751975..66c2642 100644 --- a/src/game-server/statusmanager.cpp +++ b/src/game-server/statusmanager.cpp @@ -89,7 +89,9 @@ void StatusManager::reload() if (ResourceManager::exists(filename.str())) // file exists! { LOG_INFO("Loading status script: " << filename.str()); - Script *s = Script::create("lua"); + std::string engineName = + Script::determineEngineByFilename(filename.str()); + Script *s = Script::create(engineName); s->loadFile(filename.str()); statusEffect->setScript(s); } else { diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 03d0877..1bb7513 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -477,7 +477,7 @@ static int chr_inv_count(lua_State *s) } /** - * mana.chr_get_level(): int level + * mana.chr_get_level(Character*): int level * Tells the character current level. */ static int chr_get_level(lua_State *s) diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index 490abf0..b6121bb 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -20,6 +20,7 @@ #include "scripting/script.h" +#include "common/configuration.h" #include "common/resourcemanager.h" #include "game-server/being.h" #include "utils/logger.h" @@ -172,3 +173,20 @@ bool Script::performCraft(Being* crafter, std::list<InventoryItem> recipe) } return true; } + +std::string Script::determineEngineByFilename(const std::string &filename) +{ + std::string ext = filename.substr(filename.find_last_of(".") + 1); + + if (ext == "lua") + { + return "lua"; + } + else + { + // Set to default engine and print warning + LOG_WARN("Unknown file extension for script \"" + + filename + "\", falling back to default script engine"); + return Configuration::getValue("defaultScriptEngine", "lua"); + } +} diff --git a/src/scripting/script.h b/src/scripting/script.h index 44a8b7a..e2ab3af 100644 --- a/src/scripting/script.h +++ b/src/scripting/script.h @@ -143,6 +143,7 @@ class Script static bool performSpecialAction(int specialId, Being *caster); static bool performCraft(Being* crafter, std::list<InventoryItem> recipe); + static std::string determineEngineByFilename(const std::string &filename); protected: static Script *globalEventScript; diff --git a/src/sql/mysql/updates/update_15_to_16.sql b/src/sql/mysql/updates/update_14_to_16.sql index df94f99..df94f99 100644 --- a/src/sql/mysql/updates/update_15_to_16.sql +++ b/src/sql/mysql/updates/update_14_to_16.sql diff --git a/src/sql/sqlite/updates/update_15_to_16.sql b/src/sql/sqlite/updates/update_14_to_16.sql index aa5d464..aa5d464 100644 --- a/src/sql/sqlite/updates/update_15_to_16.sql +++ b/src/sql/sqlite/updates/update_14_to_16.sql |