void Player::UpdateBlockPercentage() { // No block float value = 0.0f; if (CanBlock()) { // Base value value = 5.0f; // Increase from SPELL_AURA_MOD_BLOCK_PERCENT aura value += GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT); // Custom MoP Script // 76671 - Mastery : Divine Bulwark - Block Percentage if (GetTypeId() == TYPEID_PLAYER && HasAura(76671)) value += GetFloatValue(PLAYER_MASTERY); // Custom MoP Script // 76857 - Mastery : Critical Block - Block Percentage if (GetTypeId() == TYPEID_PLAYER && HasAura(76857)) value += GetFloatValue(PLAYER_MASTERY) / 2.0f; // Increase from rating value += GetRatingBonusValue(CR_BLOCK); if (sWorld->getBoolConfig(CONFIG_STATS_LIMITS_ENABLE)) value = value > sWorld->getFloatConfig(CONFIG_STATS_LIMITS_BLOCK) ? sWorld->getFloatConfig(CONFIG_STATS_LIMITS_BLOCK) : value; value = value < 0.0f ? 0.0f : value; } SetStatFloatValue(PLAYER_BLOCK_PERCENTAGE, value); }
TEST_F(TypeTests, GetInstanceTest) { for (auto col_type : typeTestTypes) { auto t = type::Type::GetInstance(col_type); EXPECT_NE(nullptr, t); EXPECT_EQ(col_type, t->GetTypeId()); } }
void Player::UpdateArmor() { float value = 0.0f; UnitMods unitMod = UNIT_MOD_ARMOR; value = GetModifierValue(unitMod, BASE_VALUE); // base armor (from items) value *= GetModifierValue(unitMod, BASE_PCT); // armor percent from items value += GetModifierValue(unitMod, TOTAL_VALUE); // Custom MoP Script // 77494 - Mastery : Nature's Guardian if (GetTypeId() == TYPEID_PLAYER && HasAura(77494)) { float Mastery = 1.0f + GetFloatValue(PLAYER_MASTERY) * 1.25f / 100.0f; value *= Mastery; } //add dynamic flat mods AuraEffectList const& mResbyIntellect = GetAuraEffectsByType(SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT); for (AuraEffectList::const_iterator i = mResbyIntellect.begin(); i != mResbyIntellect.end(); ++i) { if ((*i)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) value += CalculatePct(GetStat(Stats((*i)->GetMiscValueB())), (*i)->GetAmount()); } value *= GetModifierValue(unitMod, TOTAL_PCT); SetArmor(int32(value)); UpdateAttackPowerAndDamage(); // armor dependent auras update for SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR }
BOOL RecyclableObject::GetDiagTypeString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) { switch(GetTypeId()) { case TypeIds_Undefined: stringBuilder->AppendCppLiteral(_u("Undefined")); break; case TypeIds_Null: stringBuilder->AppendCppLiteral(_u("Null")); break; case TypeIds_Integer: case TypeIds_Number: stringBuilder->AppendCppLiteral(_u("Number")); break; case TypeIds_Boolean: stringBuilder->AppendCppLiteral(_u("Boolean")); break; case TypeIds_String: stringBuilder->AppendCppLiteral(_u("String")); break; default: stringBuilder->AppendCppLiteral(_u("Object, (Static Type)")); break; } return TRUE; }
///////////////////////////////////////////////// /// Interaction: Unit can interact with another unit (generic) /// /// @note Relations API Tier 1 /// /// Client-side counterpart: <tt>CGUnit_C::CanInteract(const CGUnit_C *this, const CGUnit_C *unit)</tt> ///////////////////////////////////////////////// bool Unit::CanInteract(const Unit* unit) const { // Simple sanity check if (!unit) return false; // Original logic // Unit must be selectable if (unit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)) return false; // Unit must have NPC flags so we can actually interact in some way if (!unit->GetUInt32Value(UNIT_NPC_FLAGS)) return false; // We can't interact with anyone as a ghost except specially flagged NPCs if (GetTypeId() == TYPEID_PLAYER && static_cast<const Player*>(this)->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) { if (unit->GetTypeId() != TYPEID_UNIT || !(static_cast<const Creature*>(unit)->GetCreatureInfo()->CreatureTypeFlags & CREATURE_TYPEFLAGS_GHOST_VISIBLE)) return false; } return (GetReactionTo(unit) > REP_UNFRIENDLY && unit->GetReactionTo(this) > REP_UNFRIENDLY); }
CmpBool BooleanType::CompareGreaterThanEquals(const Value& left, const Value& right) const { PL_ASSERT(GetTypeId() == TypeId::BOOLEAN); PL_ASSERT(left.CheckComparable(right)); if (left.IsNull() || right.IsNull()) return CMP_NULL; return BOOLEAN_COMPARE_FUNC(>=); }
std::string IntegerValue::ToString() const { CheckInteger(); switch(GetTypeId()) { case Type::TINYINT: if (IsNull()) return "tinyint_null"; return std::to_string(value_.tinyint); case Type::SMALLINT: if (IsNull()) return "smallint_null"; return std::to_string(value_.smallint); case Type::INTEGER: case Type::PARAMETER_OFFSET: if (IsNull()) return "integer_null"; return std::to_string(value_.integer); case Type::BIGINT: if (IsNull()) return "bigint_null"; return std::to_string(value_.bigint); default: break; } throw Exception("type error"); }
Value *BooleanValue::CompareGreaterThanEquals(const Value &o) const { PL_ASSERT(GetTypeId() == Type::BOOLEAN); CheckComparable(o); if (IsNull() || o.IsNull()) return new BooleanValue(PELOTON_BOOLEAN_NULL); return new BooleanValue(value_.boolean >= o.GetAs<int8_t>()); }
Value DecimalType::Modulo(const Value& left, const Value &right) const { PL_ASSERT(GetTypeId() == Type::DECIMAL); PL_ASSERT(left.CheckComparable(right)); if (left.IsNull() || right.IsNull()) return left.OperateNull(right); if (right.IsZero()) { throw Exception(EXCEPTION_TYPE_DIVIDE_BY_ZERO, "Division by zero."); } switch(right.GetTypeId()) { case Type::TINYINT: return ValueFactory::GetDecimalValue(ValMod(left.value_.decimal, right.GetAs<int8_t>())); case Type::SMALLINT: return ValueFactory::GetDecimalValue(ValMod(left.value_.decimal, right.GetAs<int16_t>())); case Type::INTEGER: return ValueFactory::GetDecimalValue(ValMod(left.value_.decimal, right.GetAs<int32_t>())); case Type::BIGINT: return ValueFactory::GetDecimalValue(ValMod(left.value_.decimal, right.GetAs<int64_t>())); case Type::DECIMAL: return ValueFactory::GetDecimalValue(ValMod(left.value_.decimal, right.GetAs<double>())); default: throw Exception("type error"); } }
///////////////////////////////////////////////// /// Interaction: Unit can interact with another unit (immediate response) /// /// @note Relations API Tier 1 /// /// Client-side counterpart: <tt>CGUnit_C::CanInteractNow(const CGUnit_C *this, const CGUnit_C *unit)</tt> ///////////////////////////////////////////////// bool Unit::CanInteractNow(const Unit* unit) const { // Simple sanity check if (!unit) return false; // Original logic // We can't intract while on taxi if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_TAXI_FLIGHT)) return false; // We can't interact while being charmed if (GetCharmerGuid()) return false; // We can't interact with anyone while being dead (this does not apply to player ghosts, which allow very limited interactions) if (!isAlive() && (GetTypeId() == TYPEID_UNIT || !(static_cast<const Player*>(this)->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)))) return false; // We can't interact with anyone while being shapeshifted, unless form flags allow us to do so if (IsShapeShifted()) { if (SpellShapeshiftFormEntry const* formEntry = sSpellShapeshiftFormStore.LookupEntry(GetShapeshiftForm())) { if (!(formEntry->flags1 & SHAPESHIFT_FORM_FLAG_ALLOW_NPC_INTERACT)) return false; } } // We can't interact with dead units, unless it's a creature with special flag if (!unit->isAlive()) { if (GetTypeId() != TYPEID_UNIT || !(static_cast<const Creature*>(unit)->GetCreatureInfo()->CreatureTypeFlags & CREATURE_TYPEFLAGS_INTERACT_DEAD)) return false; } // We can't interact with charmed units if (unit->GetCharmerGuid()) return false; // We can't interact with units who are currently fighting if (unit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT) || unit->getVictim()) return false; return CanInteract(unit); }
void Unit::DoPetCastSpell(Player* owner, uint8 cast_count, SpellCastTargets targets, const SpellEntry* spellInfo) { // chained if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) if (Pet *chainedPet = GetPet()) if (((Creature*)this)->GetEntry() == chainedPet->GetEntry()) chainedPet->DoPetCastSpell(owner, cast_count, targets, spellInfo); if(GetTypeId() != TYPEID_UNIT) return; Creature* pet = dynamic_cast<Creature*>(this); uint32 spellid = spellInfo->Id; clearUnitState(UNIT_STAT_MOVING); Spell *spell = new Spell(pet, spellInfo, false); spell->m_cast_count = cast_count; // probably pending spell cast spell->m_targets = targets; SpellCastResult result = spell->CheckPetCast(NULL); if (result == SPELL_CAST_OK) { pet->AddCreatureSpellCooldown(spellid); if (pet->isPet()) { //10% chance to play special pet attack talk, else growl //actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell if(((Pet*)pet)->getPetType() == SUMMON_PET && (urand(0, 100) < 10)) pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); else pet->SendPetAIReaction(pet->GetGUID()); } spell->prepare(&(spell->m_targets)); } else { pet->SendPetCastFail(spellid, result); if (!pet->HasSpellCooldown(spellid)) owner->SendClearCooldown(spellid, pet); spell->finish(false); delete spell; } }
BinaryObjectImpl BinaryObjectImpl::GetField(const char* name) const { CheckIdResolver(); int32_t fieldId = idRslvr->GetFieldId(GetTypeId(), name); int32_t pos = FindField(fieldId); return FromMemory(*mem, pos, metaMgr); }
void Creature::UpdateMaxHealth() { float value = GetTotalAuraModValue(UNIT_MOD_HEALTH); float hpDiff = GetMaxHealth() - GetHealth(); SetMaxHealth((uint32)value); if (GetTypeId() == TYPEID_UNIT) SetHealth((uint32)(value - hpDiff)); }
bool BinaryObjectImpl::HasField(const char* name) const { CheckIdResolver(); int32_t fieldId = idRslvr->GetFieldId(GetTypeId(), name); int32_t fieldPos = FindField(fieldId); return fieldPos >= 0; }
Value DecimalType::Sqrt(const Value& val) const { PL_ASSERT(GetTypeId() == Type::DECIMAL); if (val.IsNull()) return ValueFactory::GetDecimalValue(PELOTON_DECIMAL_NULL); if (val.value_.decimal < 0) { throw Exception(EXCEPTION_TYPE_DECIMAL, "Cannot take square root of a negative number."); } return ValueFactory::GetDecimalValue(sqrt(val.value_.decimal)); }
Value DecimalType::Max(const Value& left, const Value &right) const { PL_ASSERT(GetTypeId() == Type::DECIMAL); PL_ASSERT(left.CheckComparable(right)); if (left.IsNull() || right.IsNull()) return left.OperateNull(right); if (left.CompareGreaterThanEquals(right) == CMP_TRUE) return left.Copy(); return right.Copy(); }
void Corpse::RemoveFromWorld() { ///- Remove the corpse from the accessor if(IsInWorld()) sObjectAccessor.RemoveObject(this); Object::RemoveFromWorld(); if (GetMap()) GetMap()->AddProcessedObject(GetTypeId(), false); }
void Corpse::AddToWorld() { ///- Register the corpse for guid lookup if(!IsInWorld()) sObjectAccessor.AddObject(this); Object::AddToWorld(); if (GetMap()) GetMap()->AddProcessedObject(GetTypeId()); }
int asCScriptObject::CopyFrom(asIScriptObject *other) { if( other == 0 ) return asINVALID_ARG; if( GetTypeId() != other->GetTypeId() ) return asINVALID_TYPE; *this = *(asCScriptObject*)other; return 0; }
std::string VarlenType::ToString(const Value &val) const { uint32_t len = GetLength(val); if (val.IsNull()) return "varlen_null"; if (len == PELOTON_VARCHAR_MAX_LEN) return "varlen_max"; if (len == 0) { return ""; } if (GetTypeId() == TypeId::VARBINARY) return std::string(GetData(val), len); return std::string(GetData(val), len - 1); }
VTooltip* VTooltip::CloneTooltip() { VTooltip *pClone = (VTooltip *)GetTypeId()->CreateInstance(); COPY_MEMBER(m_pContext); COPY_MEMBER(m_fDelay); *pClone->m_pText = *m_pText; // assignment operator COPY_MEMBER(m_iBackgroundColor); COPY_MEMBER(m_iBorderColor); COPY_MEMBER(m_fBorderSize); COPY_MEMBER(m_fTextBorder); return pClone; }
///////////////////////////////////////////////// /// Interaction: Unit can interact with an object (generic) /// /// @note Relations API Tier 1 /// /// Client-side counterpart: <tt>CGUnit_C::CanInteract(const CGUnit_C *this, const CGGameObject_C *object)</tt> ///////////////////////////////////////////////// bool Unit::CanInteract(const GameObject* object) const { // Simple sanity check if (!object) return false; // Original logic // Can't interact with GOs as a ghost if (GetTypeId() == TYPEID_PLAYER && static_cast<const Player*>(this)->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) return false; return (object->GetReactionTo(this) > REP_UNFRIENDLY); }
TEST_F(TimestampValueTests, CastTest) { type::Value result; auto strNull = type::ValueFactory::GetNullValueByType(type::TypeId::VARCHAR); auto valNull = type::ValueFactory::GetNullValueByType(type::TypeId::TIMESTAMP); result = valNull.CastAs(type::TypeId::TIMESTAMP); EXPECT_TRUE(result.IsNull()); EXPECT_EQ(result.CompareEquals(valNull) == type::CMP_NULL, true); EXPECT_EQ(result.GetTypeId(), valNull.GetTypeId()); result = valNull.CastAs(type::TypeId::VARCHAR); EXPECT_TRUE(result.IsNull()); EXPECT_EQ(result.CompareEquals(strNull) == type::CMP_NULL, true); EXPECT_EQ(result.GetTypeId(), strNull.GetTypeId()); EXPECT_THROW(valNull.CastAs(type::TypeId::BOOLEAN), peloton::Exception); auto valValid = type::ValueFactory::GetTimestampValue(static_cast<uint64_t>(1481746648)); result = valValid.CastAs(type::TypeId::VARCHAR); EXPECT_FALSE(result.IsNull()); }
void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) { auto caster = GetCaster(); auto target = GetTarget(); if (!caster || !target) return; if (target->GetTypeId() == TYPEID_UNIT && target->GetEntry() == 60925 && !target->HasAura(106246)) { if (auto player = caster->ToPlayer()) player->KilledMonsterCredit(target->GetEntry()); target->CastSpell(target, 106246, true); } }
void Unit::CastSpell(Unit* victim, uint32 spellId) { SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); if (!spellInfo) { printf("CastSpell: unknown spell id %i by caster: %s\n", spellId, (GetTypeId() == TYPEID_PLAYER ? "player" : "creature")); return; } Spell* spell = new Spell(this, spellInfo); spell->prepare(victim); }
///////////////////////////////////////////////// /// Civilian: Unit counts as a dishonorable kill for another unit /// /// @note Relations API Tier 1 /// /// Client-side counterpart: <tt>static function (original symbol name unknown)</tt> ///////////////////////////////////////////////// bool Unit::IsCivilianForTarget(Unit const* pov) const { // Simple sanity check if (!pov) return false; // Original logic // PvP-enabled enemy npcs with civilian flag if (IsPvP() && GetTypeId() == TYPEID_UNIT && static_cast<const Creature*>(this)->IsCivilian()) return (IsTrivialForTarget(pov) && IsEnemy(pov)); return false; }
///////////////////////////////////////////////// /// Trivial: Unit does not count as a worthy target for another unit /// /// @note Relations API Tier 1 /// /// Based on client-side counterpart: <tt>static CGPlayer_C::UnitIsTrivial(const CGUnit_C *unit)</tt> /// Points of view are swapped to fit in with the rest of API, logic is preserved. ///////////////////////////////////////////////// bool Unit::IsTrivialForTarget(Unit const* pov) const { // Simple sanity check if (!pov) return false; // Original logic adapation for server (original function was operating as a local player PoV only) // Players are never seen as trivial if (GetTypeId() == TYPEID_PLAYER) return false; // Perform a level range query on the appropriate global constant NON_TRIVIAL_LEVEL_DIFFS array for the expansion return MaNGOS::XP::IsTrivialLevelDifference(pov->GetLevelForTarget(this), GetLevelForTarget(pov)); }
bool HandleCheckProc(ProcEventInfo &eventInfo) { if (!canProc) return false; auto const caster = eventInfo.GetActionTarget(); if (caster && caster->HasAura(SPELL_ULTIMATE_POWER)) return false; auto const target = eventInfo.GetActor(); if (!target || target->GetTypeId() != TYPEID_PLAYER) return false; return true; }
void Item::DeleteFromDB() { if( m_itemProto->ContainerSlots>0 && GetTypeId() == TYPEID_CONTAINER ) { /* deleting a container */ for( uint32 i = 0; i < m_itemProto->ContainerSlots; ++i ) { if( static_cast< Container* >( this )->GetItem( i ) != NULL ) { /* abort the delete */ return; } } } CharacterDatabase.Execute( "DELETE FROM playeritems WHERE guid = %u", m_uint32Values[OBJECT_FIELD_GUID] ); }
size_t IntegerValue::Hash() const { CheckInteger(); switch(GetTypeId()) { case Type::TINYINT: return std::hash<int8_t>{}(value_.tinyint); case Type::SMALLINT: return std::hash<int16_t>{}(value_.smallint); case Type::INTEGER: case Type::PARAMETER_OFFSET: return std::hash<int32_t>{}(value_.integer); case Type::BIGINT: return std::hash<int64_t>{}(value_.bigint); default: break; } throw Exception("type error"); }