From 1afba34aaf6c3379208b61b111cd6e182f35443a Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 28 Sep 2011 22:58:09 +0200 Subject: Added the chr_set_gender() script function. Reviewed-by: Ablu. --- src/scripting/lua.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index a322a3f9..5f316488 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1805,6 +1805,25 @@ static int chr_get_gender(lua_State *s) return 1; } +/** + * mana.chr_set_gender(Character*, int gender): void + * Set the gender of the character. + */ +static int chr_set_gender(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "chr_set_gender called for nonexistent character."); + return 0; + } + + const int gender = luaL_checkinteger(s, 2); + c->setGender(gender); + + return 0; +} + /** * mana.chr_give_special(Character*, int special): void * Enables a special for a character. @@ -2299,6 +2318,7 @@ LuaScript::LuaScript(): { "chr_get_hair_color", &chr_get_hair_color }, { "chr_get_kill_count", &chr_get_kill_count }, { "chr_get_gender", &chr_get_gender }, + { "chr_set_gender", &chr_set_gender }, { "chr_give_special", &chr_give_special }, { "chr_has_special", &chr_has_special }, { "chr_take_special", &chr_take_special }, -- cgit v1.2.3-70-g09d2 From 22afb99c7977176474f81546bca6b114b05e818f Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 28 Sep 2011 22:39:00 +0200 Subject: Added the chr_get_level script function. Reviewed-by: Ablu. --- example/serverdata/scripts/maps/desert.lua | 1 + src/scripting/lua.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua index 57b4533d..54c219d9 100644 --- a/example/serverdata/scripts/maps/desert.lua +++ b/example/serverdata/scripts/maps/desert.lua @@ -56,6 +56,7 @@ function Harmony(npc, ch, list) mana.chr_money_change(ch, 100) do_message(npc, ch, string.format("You now have %d shiny coins!", mana.chr_money(ch))) harmony_have_talked_to_someone = true + do_message(npc, ch, string.format("Try to come back with a better level than %i.", mana.chr_get_level(ch))) end do_message(npc, ch, "Have fun!") mana.effect_create(EMOTE_HAPPY, npc) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 5f316488..fb71a2a0 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -475,6 +475,23 @@ static int chr_inv_count(lua_State *s) return nb_items; } +/** + * mana.chr_get_level(): int level + * Tells the character current level. + */ +static int chr_get_level(lua_State *s) +{ + Character *ch = getCharacter(s, 1); + if (!ch) + { + raiseScriptError(s, "chr_get_level " + "called for nonexistent character."); + } + + lua_pushinteger(s, ch->getLevel()); + return 1; +} + /** * mana.npc_trade(NPC*, Character*, bool sell, table items): int * Callback for trading between a player and an NPC. @@ -2302,6 +2319,7 @@ LuaScript::LuaScript(): { "chr_warp", &chr_warp }, { "chr_inv_change", &chr_inv_change }, { "chr_inv_count", &chr_inv_count }, + { "chr_get_level", &chr_get_level }, { "chr_get_quest", &chr_get_quest }, { "chr_set_quest", &chr_set_quest }, { "getvar_map", &getvar_map }, -- cgit v1.2.3-70-g09d2 From 3a79ff0eae322e69efc11e1a5f60c911308eea7e Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sat, 22 Oct 2011 21:15:41 +0200 Subject: Officially added the being gender to the protocol. Reviewed-by: o11c. --- scripts/lua/libmana-constants.lua | 1 + src/common/manaserv_protocol.h | 14 +++++++++++++- src/game-server/character.cpp | 17 ++++++++++++++++- src/game-server/character.h | 7 +++---- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/scripts/lua/libmana-constants.lua b/scripts/lua/libmana-constants.lua index 912216c9..08d26c5c 100644 --- a/scripts/lua/libmana-constants.lua +++ b/scripts/lua/libmana-constants.lua @@ -39,6 +39,7 @@ DIRECTION_RIGHT = 8; GENDER_MALE = 0; GENDER_FEMALE = 1; +GENDER_UNSPECIFIED = 2; DAMAGE_PHYSICAL = 0; DAMAGE_MAGICAL = 1; diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index dc7e47b4..cbe7a0b9 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -165,7 +165,7 @@ enum { GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }* GPMSG_CREATE_EFFECT_POS = 0x0320, // W effect id, W*2 position GPMSG_CREATE_EFFECT_BEING = 0x0321, // W effect id, W BeingID - GPMSG_SHAKE = 0x0330, // W intensityX, W intensityY, [W decay_times_10000, [W duration]] + GPMSG_SHAKE = 0x0330, // W intensityX, W intensityY, [W decay_times_10000, [W duration]] // Guild PCMSG_GUILD_CREATE = 0x0350, // S name @@ -443,6 +443,18 @@ enum SpriteLayer SPRITE_VECTOREND }; +/** + * Beings Genders + * WARNING: Has to be in sync with the same enum in the Being class + * of the client! + */ +enum BeingGender +{ + GENDER_MALE = 0, + GENDER_FEMALE, + GENDER_UNSPECIFIED +}; + } // namespace ManaServ #endif // MANASERV_PROTOCOL_H diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index ef001638..d3cc20ba 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -58,7 +58,7 @@ Character::Character(MessageIn &msg): mRechargePerSpecial(0), mSpecialUpdateNeeded(false), mDatabaseID(-1), - mGender(0), + mGender(GENDER_UNSPECIFIED), mHairStyle(0), mHairColor(0), mLevel(1), @@ -295,6 +295,21 @@ void Character::cancelTransaction() } } +void Character::setGender(int gender) +{ + switch (gender) + { + case 0: + mGender = GENDER_MALE; + break; + case 1: + mGender = GENDER_FEMALE; + break; + default: + mGender = GENDER_UNSPECIFIED; + } +} + Trade *Character::getTrading() const { return mTransaction == TRANS_TRADE diff --git a/src/game-server/character.h b/src/game-server/character.h index 83445916..30e39633 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -174,12 +174,11 @@ class Character : public Being void setDatabaseID(int id) { mDatabaseID = id; } /** Gets the gender of the character (male or female). */ - int getGender() const + BeingGender getGender() const { return mGender; } /** Sets the gender of the character (male or female). */ - void setGender(int gender) - { mGender = gender; } + void setGender(int gender); int getHairStyle() const { return mHairStyle; } void setHairStyle(int style) { mHairStyle = style; } @@ -443,7 +442,7 @@ class Character : public Being bool mSpecialUpdateNeeded; int mDatabaseID; /**< Character's database ID. */ - unsigned char mGender; /**< Gender of the character. */ + BeingGender mGender; /**< Gender of the character. */ unsigned char mHairStyle; /**< Hair Style of the character. */ unsigned char mHairColor; /**< Hair Color of the character. */ int mLevel; /**< Level of the character. */ -- cgit v1.2.3-70-g09d2 From 680ff9e09be0f5192fbd1c1166b25fe99f4c2d74 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sat, 22 Oct 2011 21:17:26 +0200 Subject: Fixed the get_level doxygen documentation. Thanks to Ablu. --- src/scripting/lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index fb71a2a0..77cfd339 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -476,7 +476,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) -- cgit v1.2.3-70-g09d2 From 8d20dc6b593f4d3b1c28b274a8f126b4299b73e4 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 28 Sep 2011 23:36:52 +0200 Subject: Added a default skill id getter in the skill manager. I also added a link to the skillmanager object in its header file. This will later be used to get info from elsewhere than the server main loop. Reviewed-by: Bjorn. --- example/clientdata/skills.xml | 2 +- src/game-server/skillmanager.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/example/clientdata/skills.xml b/example/clientdata/skills.xml index ace8b444..340d9033 100644 --- a/example/clientdata/skills.xml +++ b/example/clientdata/skills.xml @@ -1,7 +1,7 @@ - + diff --git a/src/game-server/skillmanager.h b/src/game-server/skillmanager.h index 1912e2fc..e789c89d 100644 --- a/src/game-server/skillmanager.h +++ b/src/game-server/skillmanager.h @@ -53,6 +53,8 @@ class SkillManager const std::string getSkillName(unsigned int id) const; const std::string getSetName(unsigned int id) const; + unsigned int getDefaultSkillId() const + { return mDefaultSkillId; } private: struct SkillInfo { SkillInfo(): @@ -86,4 +88,6 @@ class SkillManager unsigned int mDefaultSkillId; }; +extern SkillManager *skillManager; + #endif // SKILLMANAGER_H -- cgit v1.2.3-70-g09d2 From 328f9dbb01b63c1a0651980fbdec39b34930f379 Mon Sep 17 00:00:00 2001 From: jurkan Date: Sat, 22 Oct 2011 22:41:33 +0200 Subject: Added function to determine the script engine by the file name extension Reviewed-by: Bjorn, Bertram. --- src/game-server/itemmanager.cpp | 5 ++++- src/game-server/mapcomposite.cpp | 39 +++++++++++++++++++++++++++++++-------- src/game-server/monster.cpp | 4 +++- src/game-server/statusmanager.cpp | 4 +++- src/scripting/script.cpp | 18 ++++++++++++++++++ src/scripting/script.h | 1 + 6 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 0a428e51..32f48762 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -416,7 +416,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 ecd39569..4d0581ad 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 d0c55073..1eb72aef 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -334,7 +334,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 77519754..66c2642a 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/script.cpp b/src/scripting/script.cpp index 490abf09..b6121bb8 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 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 44a8b7ac..e2ab3afa 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 recipe); + static std::string determineEngineByFilename(const std::string &filename); protected: static Script *globalEventScript; -- cgit v1.2.3-70-g09d2 From 8dbd93183c71616742f5ba55b85b780f364dd3e2 Mon Sep 17 00:00:00 2001 From: seeseekey Date: Fri, 14 Oct 2011 16:40:32 +0800 Subject: Add jurkan to AUTHORS file. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 8594740d..4db57875 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,6 +6,7 @@ Erik Schilling Eugenio Favalli Guillaume Melquiond Huynh Ngoc Chau Tran aka kindjal +jurkan Philipp Sehmisch seeseekey Yohann Ferreira -- cgit v1.2.3-70-g09d2 From 5c54e6bb22c7ecfd7c0dd69932f0ee7bd10ce50d Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 23 Oct 2011 22:30:43 +0800 Subject: Made @money functional again. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer. --- src/game-server/commandhandler.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 0cde9891..6064811e 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", " ", "Drops a stack of items on the ground at your current location", &handleDrop}, -/* {"money", " ", - "Changes the money a character possesses", &handleMoney},*/ + {"money", " ", + "Changes the money a character possesses", &handleMoney}, {"spawn", " ", "Creates a number of monsters near your location", &handleSpawn}, {"attribute", " ", @@ -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) { -- cgit v1.2.3-70-g09d2 From a5895b1655be3e81f451844a911eab8b798fa7ab Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Tue, 25 Oct 2011 21:14:13 +0200 Subject: End the confusion about the missing upgrade script Version 15 was skipped, and we'll never go back. Renamed the 15_to_16 update scripts to 14_to_16 to avoid confusing everybody who wants to update their DBs. Reviewed-by: Yohann Ferreira --- src/sql/mysql/updates/update_14_to_16.sql | 7 +++++++ src/sql/mysql/updates/update_15_to_16.sql | 7 ------- src/sql/sqlite/updates/update_14_to_16.sql | 7 +++++++ src/sql/sqlite/updates/update_15_to_16.sql | 7 ------- 4 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 src/sql/mysql/updates/update_14_to_16.sql delete mode 100644 src/sql/mysql/updates/update_15_to_16.sql create mode 100644 src/sql/sqlite/updates/update_14_to_16.sql delete mode 100644 src/sql/sqlite/updates/update_15_to_16.sql diff --git a/src/sql/mysql/updates/update_14_to_16.sql b/src/sql/mysql/updates/update_14_to_16.sql new file mode 100644 index 00000000..df94f995 --- /dev/null +++ b/src/sql/mysql/updates/update_14_to_16.sql @@ -0,0 +1,7 @@ +ALTER TABLE mana_characters CHANGE map_id map_id smallint(5); + +-- Update database version. +UPDATE mana_world_states +SET value = '16', +moddate = UNIX_TIMESTAMP() +WHERE state_name = 'database_version'; diff --git a/src/sql/mysql/updates/update_15_to_16.sql b/src/sql/mysql/updates/update_15_to_16.sql deleted file mode 100644 index df94f995..00000000 --- a/src/sql/mysql/updates/update_15_to_16.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE mana_characters CHANGE map_id map_id smallint(5); - --- Update database version. -UPDATE mana_world_states -SET value = '16', -moddate = UNIX_TIMESTAMP() -WHERE state_name = 'database_version'; diff --git a/src/sql/sqlite/updates/update_14_to_16.sql b/src/sql/sqlite/updates/update_14_to_16.sql new file mode 100644 index 00000000..aa5d4646 --- /dev/null +++ b/src/sql/sqlite/updates/update_14_to_16.sql @@ -0,0 +1,7 @@ +-- No changes required. It was only an issue with mysql. + +-- Update the database version, and set date of update +UPDATE mana_world_states + SET value = '16', + moddate = strftime('%s','now') + WHERE state_name = 'database_version'; diff --git a/src/sql/sqlite/updates/update_15_to_16.sql b/src/sql/sqlite/updates/update_15_to_16.sql deleted file mode 100644 index aa5d4646..00000000 --- a/src/sql/sqlite/updates/update_15_to_16.sql +++ /dev/null @@ -1,7 +0,0 @@ --- No changes required. It was only an issue with mysql. - --- Update the database version, and set date of update -UPDATE mana_world_states - SET value = '16', - moddate = strftime('%s','now') - WHERE state_name = 'database_version'; -- cgit v1.2.3-70-g09d2