Permalink
Browse files

simplified elemental resist/damage

  • Loading branch information...
turleypol committed Oct 22, 2017
1 parent 09d5da5 commit 32ddea28cb98cf0cd04ad657e05b8aa999cba37a
@@ -48,6 +48,7 @@ SET (SOURCES # sorted !
dice.cpp
door.cpp
dropitem.cpp
dynproperties.cpp
eqpitem.cpp
equipdsc.cpp
exscrobj.cpp
@@ -0,0 +1,16 @@
#include "dynproperties.h"
namespace Pol
{
namespace Core
{
const ValueModPack ValueModPack::DEFAULT = ValueModPack();
const MovementCostMod MovementCostMod::DEFAULT = MovementCostMod( 1.0, 1.0, 1.0, 1.0 );
const ExtStatBarFollowers ExtStatBarFollowers::DEFAULT = ExtStatBarFollowers( 0, 0 );
const SkillStatCap SkillStatCap::DEFAULT = SkillStatCap( 225, 700 );
} // namespace Core
} // namespace Pol
@@ -105,16 +105,16 @@ enum DynPropTypes : u8
PROP_DAMAGE_PHYSICAL = 17, // UObject
PROP_DMG_MOD = 18, // UWeapon
PROP_SPEED_MOD = 19, // UWeapon
PROP_CURR_RESIST_FIRE = 20, // Npc
PROP_CURR_RESIST_COLD = 21, // Npc
PROP_CURR_RESIST_ENERGY = 22, // Npc
PROP_CURR_RESIST_POISON = 23, // Npc
PROP_CURR_RESIST_PHYSICAL = 24, // Npc
PROP_CURR_DAMAGE_FIRE = 25, // Npc
PROP_CURR_DAMAGE_COLD = 26, // Npc
PROP_CURR_DAMAGE_ENERGY = 27, // Npc
PROP_CURR_DAMAGE_POISON = 28, // Npc
PROP_CURR_DAMAGE_PHYSICAL = 29, // Npc
PROP_ORIG_RESIST_FIRE = 20, // Npc
PROP_ORIG_RESIST_COLD = 21, // Npc
PROP_ORIG_RESIST_ENERGY = 22, // Npc
PROP_ORIG_RESIST_POISON = 23, // Npc
PROP_ORIG_RESIST_PHYSICAL = 24, // Npc
PROP_ORIG_DAMAGE_FIRE = 25, // Npc
PROP_ORIG_DAMAGE_COLD = 26, // Npc
PROP_ORIG_DAMAGE_ENERGY = 27, // Npc
PROP_ORIG_DAMAGE_POISON = 28, // Npc
PROP_ORIG_DAMAGE_PHYSICAL = 29, // Npc
PROP_STATCAP_SKILLCAP = 30, // Character
PROP_EXT_STATBAR_LUCK = 31, // Character
PROP_EXT_STATBAR_FOLLOWERS = 32, // Character
@@ -149,20 +149,24 @@ enum DynPropTypes : u8
PROP_FLAG_SIZE // used for bitset size
};
// struct definition for the resist/damage properties (value & mod) at the same time
struct AosValuePack
// value & mod struct definition for e.g. the resist/damage properties
struct ValueModPack
{
s16 value;
s16 mod;
AosValuePack( s16 value_ );
AosValuePack();
bool operator==( const AosValuePack& other ) const;
AosValuePack& addToValue( const AosValuePack& other );
AosValuePack& addToValue( s16 other );
AosValuePack& addToMod( s16 other );
AosValuePack& setAsMod( s16 other );
ValueModPack( s16 value_ );
ValueModPack();
bool operator==( const ValueModPack& other ) const;
ValueModPack& addToValue( const ValueModPack& other );
ValueModPack& addToValue( s16 other );
ValueModPack& addToMod( s16 other );
ValueModPack& setAsMod( s16 other );
ValueModPack& resetModAsValue();
s16 sum() const;
static const ValueModPack DEFAULT;
};
static_assert( sizeof( AosValuePack ) == sizeof( u32 ), "size missmatch" );
static_assert( sizeof( ValueModPack ) == sizeof( u32 ), "size missmatch" );
// combination of skill and stat cap
struct SkillStatCap
@@ -172,6 +176,8 @@ struct SkillStatCap
SkillStatCap();
SkillStatCap( s16 statcap_, u16 skillcap_ );
bool operator==( const SkillStatCap& other ) const;
static const SkillStatCap DEFAULT;
};
static_assert( sizeof( SkillStatCap ) == sizeof( u32 ), "size missmatch" );
@@ -183,6 +189,8 @@ struct ExtStatBarFollowers
ExtStatBarFollowers();
ExtStatBarFollowers( s8 followers_, s8 followers_max_ );
bool operator==( const ExtStatBarFollowers& other ) const;
static const ExtStatBarFollowers DEFAULT;
};
static_assert( sizeof( ExtStatBarFollowers ) == sizeof( u16 ), "size missmatch" );
@@ -196,21 +204,23 @@ struct MovementCostMod
MovementCostMod();
MovementCostMod( double walk_, double run_, double walk_mounted_, double run_mounted_ );
bool operator==( const MovementCostMod& other ) const;
static const MovementCostMod DEFAULT;
};
template <typename Storage>
class PropHolderContainer;
// small property type no types above size 4, for bigger types boost::any will be used
typedef boost::variant<u8, u16, u32, s8, s16, s32, AosValuePack, SkillStatCap, ExtStatBarFollowers,
typedef boost::variant<u8, u16, u32, s8, s16, s32, ValueModPack, SkillStatCap, ExtStatBarFollowers,
gameclock_t> variant_storage;
template <typename T>
struct can_be_used_in_variant
{
static const bool value =
std::is_same<T, u8>::value || std::is_same<T, u16>::value || std::is_same<T, u32>::value ||
std::is_same<T, s8>::value || std::is_same<T, s16>::value || std::is_same<T, s32>::value ||
std::is_same<T, AosValuePack>::value || std::is_same<T, SkillStatCap>::value ||
std::is_same<T, ValueModPack>::value || std::is_same<T, SkillStatCap>::value ||
std::is_same<T, ExtStatBarFollowers>::value || std::is_same<T, gameclock_t>::value;
};
@@ -315,38 +325,47 @@ class DynamicPropsHolder
////////////////////////////
////////////////
// AosValuePack
// ValueModPack
inline AosValuePack::AosValuePack( s16 value_ ) : value( value_ ), mod( 0 )
inline ValueModPack::ValueModPack( s16 value_ ) : value( value_ ), mod( 0 )
{
}
inline AosValuePack::AosValuePack() : value( 0 ), mod( 0 )
inline ValueModPack::ValueModPack() : value( 0 ), mod( 0 )
{
}
inline bool AosValuePack::operator==( const AosValuePack& other ) const
inline bool ValueModPack::operator==( const ValueModPack& other ) const
{
return value == other.value && mod == other.mod;
}
inline AosValuePack& AosValuePack::addToValue( const AosValuePack& other )
inline ValueModPack& ValueModPack::addToValue( const ValueModPack& other )
{
value += other.value + other.mod;
return *this;
}
inline AosValuePack& AosValuePack::addToValue( s16 other )
inline ValueModPack& ValueModPack::addToValue( s16 other )
{
value += other;
return *this;
}
inline AosValuePack& AosValuePack::addToMod( s16 other )
inline ValueModPack& ValueModPack::addToMod( s16 other )
{
mod += other;
return *this;
}
inline AosValuePack& AosValuePack::setAsMod( s16 other )
inline ValueModPack& ValueModPack::setAsMod( s16 other )
{
mod = other;
return *this;
}
inline ValueModPack& ValueModPack::resetModAsValue()
{
value = mod;
return *this;
}
inline s16 ValueModPack::sum() const
{
return value + mod;
}
////////////////
// SkillStatCap
View
@@ -1163,88 +1163,6 @@ bool Item::check_unequiptest_scripts()
}
}
s16 Item::calc_element_resist( Core::ElementalType element ) const
{
Core::AosValuePack curr;
switch ( element )
{
case Core::ELEMENTAL_FIRE:
curr = fire_resist();
break;
case Core::ELEMENTAL_COLD:
curr = cold_resist();
break;
case Core::ELEMENTAL_ENERGY:
curr = energy_resist();
break;
case Core::ELEMENTAL_POISON:
curr = poison_resist();
break;
case Core::ELEMENTAL_PHYSICAL:
curr = physical_resist();
break;
}
return curr.value + curr.mod;
}
s16 Item::calc_element_damage( Core::ElementalType element ) const
{
Core::AosValuePack curr;
switch ( element )
{
case Core::ELEMENTAL_FIRE:
curr = fire_damage();
break;
case Core::ELEMENTAL_COLD:
curr = cold_damage();
break;
case Core::ELEMENTAL_ENERGY:
curr = energy_damage();
break;
case Core::ELEMENTAL_POISON:
curr = poison_damage();
break;
case Core::ELEMENTAL_PHYSICAL:
curr = physical_damage();
break;
}
return curr.value + curr.mod;
}
bool Item::has_resistance( Mobile::Character* /*chr*/ )
{
if ( ( calc_element_resist( Core::ELEMENTAL_FIRE ) != 0 ) ||
( calc_element_resist( Core::ELEMENTAL_COLD ) != 0 ) ||
( calc_element_resist( Core::ELEMENTAL_ENERGY ) != 0 ) ||
( calc_element_resist( Core::ELEMENTAL_POISON ) != 0 ) ||
( calc_element_resist( Core::ELEMENTAL_PHYSICAL ) != 0 ) )
return true;
else
{
// double new_ar = 0.0;
UArmor* armor = static_cast<UArmor*>( this ); // Not sure if I like this method.
if ( armor != NULL )
{
if ( armor->ar() > 0 )
return true;
}
}
return false;
}
bool Item::has_element_damage()
{
if ( ( calc_element_damage( Core::ELEMENTAL_FIRE ) != 0 ) ||
( calc_element_damage( Core::ELEMENTAL_COLD ) != 0 ) ||
( calc_element_damage( Core::ELEMENTAL_ENERGY ) != 0 ) ||
( calc_element_damage( Core::ELEMENTAL_POISON ) != 0 ) ||
( calc_element_damage( Core::ELEMENTAL_PHYSICAL ) != 0 ) )
{
return true;
}
return false;
}
/**
* Shortcut function to get a pointer to the owner character
*
View
@@ -255,11 +255,6 @@ class Item : public Core::UObject
unsigned short hp_;
unsigned short maxhp() const;
s16 calc_element_resist( Core::ElementalType element ) const;
s16 calc_element_damage( Core::ElementalType element ) const;
bool has_resistance( Mobile::Character* chr );
bool has_element_damage();
DYN_PROPERTY( maxhp_mod, s16, Core::PROP_MAXHP_MOD, 0 );
DYN_PROPERTY( name_suffix, std::string, Core::PROP_NAME_SUFFIX, "" );
DYN_PROPERTY_POINTER( gotten_by, Mobile::Character*, Core::PROP_GOTTEN_BY );
Oops, something went wrong.

0 comments on commit 32ddea2

Please sign in to comment.