summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-19 23:17:18 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-19 23:17:18 +0200
commit14b048899065054bf2a8171a566616607479c09f (patch)
tree3e531350fdcff72e33dde66bed3574b2e882bd06 /src/net
parent1b21442b5eb6dcc41a585715d07c73ed3ad59a1b (diff)
downloadmana-client-14b048899065054bf2a8171a566616607479c09f.tar.gz
mana-client-14b048899065054bf2a8171a566616607479c09f.tar.bz2
mana-client-14b048899065054bf2a8171a566616607479c09f.tar.xz
mana-client-14b048899065054bf2a8171a566616607479c09f.zip
Heavy GUI fixes related to stats for Manaserv.
Also tested to be compatible with tA. Now the Status window is much more nicer when using Manaserv. HP, max hp, ... are now working fine along with corrections made in the attributes.xml file (in next commit.) Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/manaserv/attributes.cpp104
-rw-r--r--src/net/manaserv/attributes.h7
-rw-r--r--src/net/manaserv/playerhandler.cpp24
3 files changed, 114 insertions, 21 deletions
diff --git a/src/net/manaserv/attributes.cpp b/src/net/manaserv/attributes.cpp
index 67c52788..a65dc01f 100644
--- a/src/net/manaserv/attributes.cpp
+++ b/src/net/manaserv/attributes.cpp
@@ -21,6 +21,7 @@
#include "net/manaserv/attributes.h"
#include "log.h"
+#include "playerinfo.h"
#include "gui/statuswindow.h"
@@ -46,20 +47,26 @@ namespace Attributes {
unsigned int id;
std::string name;
std::string description;
+ /** Whether the attribute value can be modified by the player */
bool modifiable;
+ /**< Attribute scope. */
+ std::string scope;
+ /** The playerInfo core Id the attribute is linked with or -1 if not */
+ int playerInfoId;
} Attribute;
- // tag -> effect
- typedef std::map< std::string, std::string > TagMap;
-
+ /** Map for attributes. */
typedef std::map<unsigned int, Attribute> AttributeMap;
- AttributeMap attributes;
+ static AttributeMap attributes;
- TagMap tags;
+ /** tags = effects on attributes. */
+ typedef std::map< std::string, std::string > TagMap;
+ static TagMap tags;
- // List of modifiable attribute names used at character's creation.
+ /** List of modifiable attribute names used at character's creation. */
static std::vector<std::string> attributeLabels;
+ /** Characters creation points. */
static unsigned int creationPoints = 0;
static unsigned int attributeMinimum = 0;
static unsigned int attributeMaximum = 0;
@@ -95,11 +102,62 @@ namespace Attributes {
for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
it++)
{
- if (it->second.modifiable)
+ if (it->second.modifiable &&
+ (it->second.scope == "character" || it->second.scope == "being"))
attributeLabels.push_back(it->second.name + ":");
}
}
+ /**
+ * Fills the list of base attribute labels.
+ */
+ static int getPlayerInfoIdFromAttrType(std::string attrType)
+ {
+ toLower(attrType);
+ if (attrType == "level")
+ return ::LEVEL;
+ else if (attrType == "hp")
+ return ::HP;
+ else if (attrType == "max-hp")
+ return ::MAX_HP;
+ else if (attrType == "mp")
+ return ::MP;
+ else if (attrType == "max-mp")
+ return ::MAX_MP;
+ else if (attrType == "exp")
+ return ::EXP;
+ else if (attrType == "exp-needed")
+ return ::EXP_NEEDED;
+ else if (attrType == "money")
+ return ::MONEY;
+ else if (attrType == "total-weight")
+ return ::TOTAL_WEIGHT;
+ else if (attrType == "max-weight")
+ return ::MAX_WEIGHT;
+ else if (attrType == "skill-points")
+ return ::SKILL_POINTS;
+ else if (attrType == "char-points")
+ return ::CHAR_POINTS;
+ else if (attrType == "corr-points")
+ return ::CORR_POINTS;
+ else if (attrType == "none")
+ return -2; // Used to hide the attribute display.
+
+ return -1; // Not linked to a playerinfo stat.
+ }
+
+ int getPlayerInfoIdFromAttrId(int attrId)
+ {
+ AttributeMap::const_iterator it = attributes.find(attrId);
+
+ if (it != attributes.end())
+ {
+ return it->second.playerInfoId;
+ }
+
+ return -1;
+ }
+
static void loadBuiltins()
{
{
@@ -108,6 +166,8 @@ namespace Attributes {
a.name = _("Strength");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("str", _("Strength %+.1f")));
@@ -119,6 +179,8 @@ namespace Attributes {
a.name = _("Agility");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("agi", _("Agility %+.1f")));
@@ -130,6 +192,8 @@ namespace Attributes {
a.name = _("Dexterity");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("dex", _("Dexterity %+.1f")));
@@ -141,6 +205,8 @@ namespace Attributes {
a.name = _("Vitality");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("vit", _("Vitality %+.1f")));
@@ -152,6 +218,8 @@ namespace Attributes {
a.name = _("Intelligence");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("int", _("Intelligence %+.1f")));
@@ -163,6 +231,8 @@ namespace Attributes {
a.name = _("Willpower");
a.description = "";
a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
attributes[a.id] = a;
tags.insert(std::make_pair("wil", _("Willpower %+.1f")));
@@ -211,12 +281,15 @@ namespace Attributes {
continue;
}
+ // Create the attribute.
Attribute a;
a.id = id;
a.name = name;
a.description = XML::getProperty(node, "desc", "");
- a.modifiable = XML::getProperty(node, "modifiable", "false")
- == "true";
+ a.modifiable = XML::getBoolProperty(node, "modifiable", false);
+ a.scope = XML::getProperty(node, "scope", "none");
+ a.playerInfoId = getPlayerInfoIdFromAttrType(
+ XML::getProperty(node, "player-info", ""));
attributes[id] = a;
@@ -319,9 +392,16 @@ namespace Attributes {
AttributeMap::const_iterator it, it_end;
for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
it++)
- statusWindow->addAttribute(it->second.id, it->second.name,
- it->second.modifiable,
- it->second.description);
+ {
+ if (it->second.playerInfoId == -1 &&
+ (it->second.scope == "character" || it->second.scope == "being"))
+ {
+ statusWindow->addAttribute(it->second.id,
+ it->second.name,
+ it->second.modifiable,
+ it->second.description);
+ }
+ }
}
} // namespace Attributes
diff --git a/src/net/manaserv/attributes.h b/src/net/manaserv/attributes.h
index 9791d2cb..aced85ec 100644
--- a/src/net/manaserv/attributes.h
+++ b/src/net/manaserv/attributes.h
@@ -26,6 +26,7 @@
namespace ManaServ {
namespace Attributes {
+
void load();
void unload();
@@ -40,6 +41,12 @@ namespace Attributes {
std::vector<std::string>& getLabels();
/**
+ * Give back the corresponding playerinfo Id from the attribute id
+ * defined in the xml file.
+ */
+ int getPlayerInfoIdFromAttrId(int attrId);
+
+ /**
* Give the attribute points given to a character
* at its creation.
*/
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 5bacce49..a579517f 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -43,6 +43,7 @@
#include "net/manaserv/messagein.h"
#include "net/manaserv/messageout.h"
#include "net/manaserv/protocol.h"
+#include "net/manaserv/attributes.h"
/**
* Max. distance we are willing to scroll after a teleport;
@@ -112,18 +113,23 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
{
while (msg.getUnreadLength())
{
- int attr = msg.readInt16();
+ int attrId = msg.readInt16();
double base = msg.readInt32() / 256.0;
double value = msg.readInt32() / 256.0;
- /* TODO handle HP
- if (attr == ATTR_HP)
- PlayerInfo::setAttribute(HP, value);
- else if (attr == ATTR_MAX_HP)
- PlayerInfo::setAttribute(MAX_HP, value);*/
-
- PlayerInfo::setStatBase(attr, base);
- PlayerInfo::setStatMod(attr, value - base);
+ // Set the core player attribute the stat
+ // depending on attribute link.
+ int playerInfoId =
+ Attributes::getPlayerInfoIdFromAttrId(attrId);
+ if (playerInfoId > -1)
+ {
+ PlayerInfo::setAttribute(playerInfoId, value);
+ }
+ else
+ {
+ PlayerInfo::setStatBase(attrId, base);
+ PlayerInfo::setStatMod(attrId, value - base);
+ }
}
} break;