Skip to content

Commit

Permalink
made a little fix with maxPlayers beeing default 0 in config.lua
Browse files Browse the repository at this point in the history
so players couldn't login, if it was set to 0.

added attributes for items (for upgrading systems)
attack/defense/extradefense/armor/shootrange/hitchance
:setAttribute("extradefense", 50)
It currently doesn't support the attribute name/article/pluralname but I'll add that soon.
  • Loading branch information
EvilHero90 committed Jul 25, 2014
1 parent 524edca commit e09d04e
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/enums.h
Expand Up @@ -34,7 +34,13 @@ enum itemAttrTypes {
ITEM_ATTRIBUTE_CORPSEOWNER = 524288,
ITEM_ATTRIBUTE_CHARGES = 1048576,
ITEM_ATTRIBUTE_FLUIDTYPE = 2097152,
ITEM_ATTRIBUTE_DOORID = 4194304
ITEM_ATTRIBUTE_DOORID = 4194304,
ITEM_ATTRIBUTE_ATTACK = 4194305,
ITEM_ATTRIBUTE_DEFENSE = 4194306,
ITEM_ATTRIBUTE_EXTRA_DEFENSE = 4194307,
ITEM_ATTRIBUTE_ARMOR = 4194308,
ITEM_ATTRIBUTE_SHOOTRANGE = 4194309,
ITEM_ATTRIBUTE_HITCHANCE = 4194310
};

enum VipStatus_t {
Expand Down
120 changes: 111 additions & 9 deletions src/item.cpp
Expand Up @@ -470,6 +470,66 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream& propStream)
break;
}

case ATTR_ATTACK: {
int32_t _attack;
if (!propStream.GET_VALUE(_attack)) {
return ATTR_READ_ERROR;
}

setAttack(_attack);
break;
}

case ATTR_DEFENSE: {
int32_t _defense;
if (!propStream.GET_VALUE(_defense)) {
return ATTR_READ_ERROR;
}

setDefense(_defense);
break;
}

case ATTR_EXTRA_DEFENSE: {
int32_t _extraDefense;
if (!propStream.GET_VALUE(_extraDefense)) {
return ATTR_READ_ERROR;
}

setExtraDefense(_extraDefense);
break;
}

case ATTR_ARMOR: {
int32_t _armor;
if (!propStream.GET_VALUE(_armor)) {
return ATTR_READ_ERROR;
}

setArmor(_armor);
break;
}

case ATTR_SHOOTRANGE: {
int32_t _shootRange;
if (!propStream.GET_VALUE(_shootRange)) {
return ATTR_READ_ERROR;
}

setShootRange(_shootRange);
break;
}

case ATTR_HITCHANCE: {
int32_t _hitChance;
if (!propStream.GET_VALUE(_hitChance)) {
return ATTR_READ_ERROR;
}

setHitChance(_hitChance);
break;
}

//these should be handled through derived classes
//If these are called then something has changed in the items.xml since the map was saved
//just read the values
Expand Down Expand Up @@ -616,6 +676,42 @@ bool Item::serializeAttr(PropWriteStream& propWriteStream) const
propWriteStream.ADD_UCHAR(decayState);
}

int32_t attack = getIntAttr(ITEM_ATTRIBUTE_ATTACK);
if (attack != 0) {
propWriteStream.ADD_UCHAR(ATTR_ATTACK);
propWriteStream.ADD_ULONG(attack);
}

int32_t defense = getIntAttr(ITEM_ATTRIBUTE_DEFENSE);
if (defense != 0) {
propWriteStream.ADD_UCHAR(ATTR_DEFENSE);
propWriteStream.ADD_ULONG(defense);
}

int32_t extraDefense = getIntAttr(ITEM_ATTRIBUTE_EXTRA_DEFENSE);
if (extraDefense != 0) {
propWriteStream.ADD_UCHAR(ATTR_EXTRA_DEFENSE);
propWriteStream.ADD_ULONG(extraDefense);
}

int32_t armor = getIntAttr(ITEM_ATTRIBUTE_ARMOR);
if (armor != 0) {
propWriteStream.ADD_UCHAR(ATTR_ARMOR);
propWriteStream.ADD_ULONG(armor);
}

int32_t shootRange = getIntAttr(ITEM_ATTRIBUTE_SHOOTRANGE);
if (shootRange != 0) {
propWriteStream.ADD_UCHAR(ATTR_SHOOTRANGE);
propWriteStream.ADD_ULONG(shootRange);
}

int32_t hitChance = getIntAttr(ITEM_ATTRIBUTE_HITCHANCE);
if (hitChance != 0) {
propWriteStream.ADD_UCHAR(ATTR_HITCHANCE);
propWriteStream.ADD_ULONG(hitChance);
}

return true;
}

Expand Down Expand Up @@ -689,14 +785,14 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
}
} else if (it.weaponType != WEAPON_NONE) {
if (it.weaponType == WEAPON_DISTANCE && it.ammoType != AMMO_NONE) {
s << " (Range:" << it.shootRange;
s << " (Range:" << item->getShootRange();

if (it.attack != 0) {
s << ", Atk" << std::showpos << it.attack << std::noshowpos;
s << ", Atk" << std::showpos << (item->getAttack() == 0 ? it.attack : item->getAttack()) << std::noshowpos;
}

if (it.hitChance != 0) {
s << ", Hit%" << std::showpos << it.hitChance << std::noshowpos;
s << ", Hit%" << std::showpos << (item->getHitChance() == 0 ? it.hitChance : item->getHitChance()) << std::noshowpos;
}

s << ')';
Expand All @@ -705,7 +801,7 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,

if (it.attack != 0) {
begin = false;
s << " (Atk:" << it.attack;
s << " (Atk:" << (item->getAttack() == 0 ? it.attack : item->getAttack());

if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) {
s << " physical + " << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType);
Expand All @@ -720,10 +816,10 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
s << ", ";
}

s << "Def:" << it.defense;
s << "Def:" << (item->getDefense() == 0 ? it.defense : item->getDefense());

if (it.extraDefense != 0 || (item && item->getExtraDefense() != 0)) {
s << ' ' << std::showpos << it.extraDefense << std::noshowpos;
if (it.extraDefense != 0) {
s << ' ' << std::showpos << (item->getExtraDefense() == 0 ? it.extraDefense : item->getExtraDefense()) << std::noshowpos;
}
}

Expand Down Expand Up @@ -864,10 +960,10 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
s << ')';
}
}
} else if (it.armor || (item && item->getArmor()) || it.showAttributes) {
} else if (it.armor || it.showAttributes) {
int32_t tmp = it.armor;

if (item) {
if (item->getArmor() != 0) {
tmp = item->getArmor();
}

Expand Down Expand Up @@ -1426,6 +1522,12 @@ bool ItemAttributes::validateIntAttrType(itemAttrTypes type)
case ITEM_ATTRIBUTE_CHARGES:
case ITEM_ATTRIBUTE_FLUIDTYPE:
case ITEM_ATTRIBUTE_DOORID:
case ITEM_ATTRIBUTE_ATTACK:
case ITEM_ATTRIBUTE_DEFENSE:
case ITEM_ATTRIBUTE_EXTRA_DEFENSE:
case ITEM_ATTRIBUTE_ARMOR:
case ITEM_ATTRIBUTE_SHOOTRANGE:
case ITEM_ATTRIBUTE_HITCHANCE:
return true;

default:
Expand Down
122 changes: 115 additions & 7 deletions src/item.h
Expand Up @@ -86,7 +86,13 @@ enum AttrTypes_t {
ATTR_SLEEPERGUID = 20,
ATTR_SLEEPSTART = 21,
ATTR_CHARGES = 22,
ATTR_CONTAINER_ITEMS = 23
ATTR_CONTAINER_ITEMS = 23,
ATTR_ATTACK = 24,
ATTR_DEFENSE = 25,
ATTR_EXTRA_DEFENSE = 26,
ATTR_ARMOR = 27,
ATTR_SHOOTRANGE = 28,
ATTR_HITCHANCE = 29
};

enum Attr_ReadValue {
Expand Down Expand Up @@ -204,6 +210,48 @@ class ItemAttributes
return (ItemDecayState_t)getIntAttr(ITEM_ATTRIBUTE_DECAYSTATE);
}

void setAttack(int32_t attack) {
setIntAttr(ITEM_ATTRIBUTE_ATTACK, attack);
}
int32_t getAttack() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_ATTACK);
}

void setDefense(int32_t defense) {
setIntAttr(ITEM_ATTRIBUTE_DEFENSE, defense);
}
int32_t getDefense() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_DEFENSE);
}

void setExtraDefense(int32_t extraDefense) {
setIntAttr(ITEM_ATTRIBUTE_EXTRA_DEFENSE, extraDefense);
}
int32_t getExtraDefense() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_EXTRA_DEFENSE);
}

void setArmor(int32_t armor) {
setIntAttr(ITEM_ATTRIBUTE_ARMOR, armor);
}
int32_t getArmor() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_ARMOR);
}

void setShootRange(int32_t shootRange) {
setIntAttr(ITEM_ATTRIBUTE_SHOOTRANGE, shootRange);
}
int32_t getShootRange() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_SHOOTRANGE);
}

void setHitChance(int32_t hitChance) {
setIntAttr(ITEM_ATTRIBUTE_DEFENSE, hitChance);
}
int32_t getHitChance() const {
return (uint16_t)getIntAttr(ITEM_ATTRIBUTE_HITCHANCE);
}

protected:
inline bool hasAttribute(itemAttrTypes type) const {
return (type & attributeBits) != 0;
Expand Down Expand Up @@ -507,6 +555,66 @@ class Item : virtual public Thing
return (ItemDecayState_t)getIntAttr(ITEM_ATTRIBUTE_DECAYSTATE);
}

void setAttack(int32_t attack) {
setIntAttr(ITEM_ATTRIBUTE_ATTACK, attack);
}
int32_t getAttack() const {
if (!hasAttribute(ITEM_ATTRIBUTE_ATTACK)) {
return items[id].attack;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_ATTACK);
}

void setDefense(int32_t defense) {
setIntAttr(ITEM_ATTRIBUTE_DEFENSE, defense);
}
int32_t getDefense() const {
if (!hasAttribute(ITEM_ATTRIBUTE_DEFENSE)) {
return items[id].defense;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_DEFENSE);
}

void setExtraDefense(int32_t extraDefense) {
setIntAttr(ITEM_ATTRIBUTE_EXTRA_DEFENSE, extraDefense);
}
int32_t getExtraDefense() const {
if (!hasAttribute(ITEM_ATTRIBUTE_EXTRA_DEFENSE)) {
return items[id].extraDefense;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_EXTRA_DEFENSE);
}

void setArmor(int32_t armor) {
setIntAttr(ITEM_ATTRIBUTE_ARMOR, armor);
}
int32_t getArmor() const {
if (!hasAttribute(ITEM_ATTRIBUTE_ARMOR)) {
return items[id].armor;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_ARMOR);
}

void setShootRange(int32_t shootRange) {
setIntAttr(ITEM_ATTRIBUTE_SHOOTRANGE, shootRange);
}
int32_t getShootRange() const {
if (!hasAttribute(ITEM_ATTRIBUTE_SHOOTRANGE)) {
return items[id].shootRange;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_SHOOTRANGE);
}

void setHitChance(int32_t hitChance) {
setIntAttr(ITEM_ATTRIBUTE_HITCHANCE, hitChance);
}
int32_t getHitChance() const {
if (!hasAttribute(ITEM_ATTRIBUTE_HITCHANCE)) {
return items[id].hitChance;
}
return (int32_t)getIntAttr(ITEM_ATTRIBUTE_HITCHANCE);
}

static std::string getDescription(const ItemType& it, int32_t lookDistance, const Item* item = nullptr, int32_t subType = -1, bool addArticle = true);
static std::string getNameDescription(const ItemType& it, const Item* item = nullptr, int32_t subType = -1, bool addArticle = true);
static std::string getWeightDescription(const ItemType& it, double weight, uint32_t count = 1);
Expand Down Expand Up @@ -550,12 +658,12 @@ class Item : virtual public Thing
Ammo_t getAmmoType() const {
return items[id].ammoType;
}
int32_t getShootRange() const {
/*int32_t getShootRange() const {
return items[id].shootRange;
}
}*/

virtual double getWeight() const;
int32_t getAttack() const {
/*int32_t getAttack() const {
return items[id].attack;
}
int32_t getArmor() const {
Expand All @@ -566,13 +674,13 @@ class Item : virtual public Thing
}
int32_t getExtraDefense() const {
return items[id].extraDefense;
}
}*/
int32_t getSlotPosition() const {
return items[id].slotPosition;
}
int32_t getHitChance() const {
/*int32_t getHitChance() const {
return items[id].hitChance;
}
}*/

bool isReadable() const {
return items[id].canReadText;
Expand Down
8 changes: 7 additions & 1 deletion src/luascript.cpp
Expand Up @@ -1499,6 +1499,12 @@ void LuaScriptInterface::registerFunctions()
registerEnum(ITEM_ATTRIBUTE_CHARGES)
registerEnum(ITEM_ATTRIBUTE_FLUIDTYPE)
registerEnum(ITEM_ATTRIBUTE_DOORID)
registerEnum(ITEM_ATTRIBUTE_ATTACK)
registerEnum(ITEM_ATTRIBUTE_DEFENSE)
registerEnum(ITEM_ATTRIBUTE_EXTRA_DEFENSE)
registerEnum(ITEM_ATTRIBUTE_ARMOR)
registerEnum(ITEM_ATTRIBUTE_SHOOTRANGE)
registerEnum(ITEM_ATTRIBUTE_HITCHANCE)

registerEnum(ITEM_TYPE_DEPOT)
registerEnum(ITEM_TYPE_MAILBOX)
Expand Down Expand Up @@ -12392,7 +12398,7 @@ int32_t LuaScriptInterface::luaPartySetSharedExperience(lua_State* L)
//
LuaEnvironment::LuaEnvironment() :
LuaScriptInterface("Main Interface"), m_testInterface(nullptr),
m_lastEventTimerId(0), m_lastCombatId(0), m_lastConditionId(0), m_lastAreaId(0)
m_lastEventTimerId(1), m_lastCombatId(0), m_lastConditionId(0), m_lastAreaId(0)
{
//
}
Expand Down

0 comments on commit e09d04e

Please sign in to comment.