Skip to content

Commit

Permalink
Big ScriptMgr sync
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1arm committed Feb 5, 2023
1 parent 0639ac1 commit 39c30cf
Show file tree
Hide file tree
Showing 15 changed files with 623 additions and 104 deletions.
30 changes: 25 additions & 5 deletions src/game/Object/Object.cpp
Expand Up @@ -45,6 +45,7 @@
#include "CreatureLinkingMgr.h"
#include "Chat.h"
#include "GameTime.h"

#ifdef ENABLE_ELUNA
#include "LuaEngine.h"
#include "ElunaEventMgr.h"
Expand Down Expand Up @@ -206,6 +207,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c
buf << uint8(m_objectTypeId);

BuildMovementUpdate(&buf, updateFlags);

UpdateMask updateMask;
updateMask.SetCount(m_valuesCount);
_SetCreateBits(&updateMask, target);
Expand Down Expand Up @@ -458,6 +460,11 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, UpdateMask* u

if (GetTypeId() == TYPEID_UNIT)
{
if (!target->canSeeSpellClickOn((Creature*)this))
{
appendValue &= ~UNIT_NPC_FLAG_SPELLCLICK;
}

if (appendValue & UNIT_NPC_FLAG_TRAINER)
{
if (!((Creature*)this)->IsTrainerOf(target, false))
Expand Down Expand Up @@ -524,8 +531,10 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, UpdateMask* u

/* Initiate pointer to creature so we can check loot */
if (Creature* my_creature = (Creature*)this)
{
/* If the creature is NOT fully looted */
if (!my_creature->loot.isLooted())
{
/* If the lootable flag is NOT set */
if (!(send_value & UNIT_DYNFLAG_LOOTABLE))
{
Expand All @@ -534,13 +543,16 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, UpdateMask* u
/* Update it in the packet */
send_value = send_value | UNIT_DYNFLAG_LOOTABLE;
}

}
}
/* If we're not allowed to loot the target, destroy the lootable flag */
if (!target->isAllowedToLoot((Creature*)this))
{
if (send_value & UNIT_DYNFLAG_LOOTABLE)
{
send_value = send_value & ~UNIT_DYNFLAG_LOOTABLE;
}
}

/* If we are allowed to loot it and mob is tapped by us, destroy the tapped flag */
bool is_tapped = target->IsTappedByMeOrMyGroup((Creature*)this);
Expand All @@ -553,7 +565,7 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, UpdateMask* u

*data << send_value;
}
else
else // Unhandled index, just send
{
// send in current format (float as float, uint32 as uint32)
*data << m_uint32Values[index];
Expand Down Expand Up @@ -595,7 +607,8 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, UpdateMask* u
}
else
{
*data << uint32(0); // disable quest object
// disable quest object
*data << uint32(0);
}
}
else
Expand Down Expand Up @@ -943,7 +956,6 @@ bool Object::PrintEntryError(char const* descr) const
return false;
}


void Object::BuildUpdateDataForPlayer(Player* pl, UpdateDataMapType& update_players)
{
UpdateDataMapType::iterator iter = update_players.find(pl);
Expand Down Expand Up @@ -1431,6 +1443,10 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap
{
z = max_z;
}
else if (z < ground_z)
{
z = ground_z;
}
}
}
else
Expand All @@ -1456,6 +1472,10 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap
{
z = max_z;
}
else if (z < ground_z)
{
z = ground_z;
}
}
}
else
Expand Down Expand Up @@ -1716,7 +1736,7 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa

pCreature->SetRespawnCoord(pos);

//Set run/walk mode
// Set run or walk before any other movement starts
pCreature->SetWalk(!setRun);

// Active state set before added to map
Expand Down
1 change: 1 addition & 0 deletions src/game/Object/Object.h
Expand Up @@ -38,6 +38,7 @@
#define CONTACT_DISTANCE 0.5f
#define INTERACTION_DISTANCE 5.0f
#define ATTACK_DISTANCE 5.0f
#define TRADE_DISTANCE 11.11f // max distance for trading
#define MAX_VISIBILITY_DISTANCE 333.0f // max distance for visible object show, limited in 333 yards
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
#define DEFAULT_VISIBILITY_INSTANCE 120.0f // default visible distance in instances, 120 yards
Expand Down
28 changes: 28 additions & 0 deletions src/game/Object/ObjectMgr.cpp
Expand Up @@ -123,6 +123,34 @@ LanguageDesc const* GetLanguageDescByID(uint32 lang)
return NULL;
}

bool SpellClickInfo::IsFitToRequirements(Player const* player, Creature const* clickedCreature) const
{
if (conditionId)
{
return sObjectMgr.IsPlayerMeetToCondition(conditionId, player, player->GetMap(), clickedCreature, CONDITION_FROM_SPELLCLICK);
}

if (questStart)
{
// not in expected required quest state
if (!player || ((!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart)))
{
return false;
}
}

if (questEnd)
{
// not in expected forbidden quest state
if (!player || player->GetQuestRewardStatus(questEnd))
{
return false;
}
}

return true;
}

template<typename T>
T IdGenerator<T>::Generate()
{
Expand Down
25 changes: 24 additions & 1 deletion src/game/Object/ObjectMgr.h
Expand Up @@ -62,6 +62,22 @@ struct GameTele

typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;

struct SpellClickInfo
{
uint32 spellId;
uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
bool questStartCanActive; // if true then quest start can be active (not only rewarded)
uint8 castFlags;
uint16 conditionId; // intends to replace questStart, questEnd, questStartCanActive

// helpers
bool IsFitToRequirements(Player const* player, Creature const* clickedCreature) const;
};

typedef std::multimap<uint32 /*npcEntry*/, SpellClickInfo> SpellClickInfoMap;
typedef std::pair<SpellClickInfoMap::const_iterator, SpellClickInfoMap::const_iterator> SpellClickInfoMapBounds;

struct AreaTrigger
{
uint8 requiredLevel;
Expand Down Expand Up @@ -358,7 +374,7 @@ enum ConditionSource // From where was th
CONDITION_FROM_HARDCODED = 5, // Used to check a hardcoded event - not actually a condition
CONDITION_FROM_VENDOR = 6, // Used to check a condition from a vendor
CONDITION_FROM_SPELL_AREA = 7, // Used to check a condition from spell_area table
CONDITION_FROM_RESERVED_1 = 8, // reserved for 3.x and later
CONDITION_FROM_SPELLCLICK = 8, // Used to check a condition from npc_spellclick_spells table
CONDITION_FROM_DBSCRIPTS = 9, // Used to check a condition from DB Scripts Engine
CONDITION_AREA_TRIGGER = 10, // Used to check a condition from CMSG_AREATRIGGER
};
Expand Down Expand Up @@ -1146,6 +1162,11 @@ class ObjectMgr

int GetOrNewIndexForLocale(LocaleConstant loc);

SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
{
return mSpellClickInfoMap.equal_range(creature_id);
}

ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
{
return m_ItemRequiredTarget.equal_range(uiItemEntry);
Expand Down Expand Up @@ -1264,6 +1285,8 @@ class ObjectMgr

GameTeleMap m_GameTeleMap;

SpellClickInfoMap mSpellClickInfoMap;

ItemRequiredTargetMap m_ItemRequiredTarget;

typedef std::vector<LocaleConstant> LocalForIndex;
Expand Down
38 changes: 34 additions & 4 deletions src/game/Object/Player.cpp
Expand Up @@ -417,13 +417,15 @@ void TradeData::SetAccepted(bool state, bool crosssend /*= false*/)

if (!state)
{
TradeStatusInfo info;
info.Status = TRADE_STATUS_BACK_TO_TRADE;
if (crosssend)
{
m_trader->GetSession()->SendTradeStatus(TRADE_STATUS_BACK_TO_TRADE);
m_trader->GetSession()->SendTradeStatus(info);
}
else
{
m_player->GetSession()->SendTradeStatus(TRADE_STATUS_BACK_TO_TRADE);
m_player->GetSession()->SendTradeStatus(info);
}
}
}
Expand Down Expand Up @@ -676,11 +678,12 @@ Player::~Player()

// clean up player-instance binds, may unload some instance saves
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); ++itr)
{
itr->second.state->RemovePlayer(this);
}

}
delete m_declinedname;
}

Expand Down Expand Up @@ -1099,6 +1102,7 @@ int32 Player::getMaxTimer(MirrorTimerType timer)
default:
return 0;
}
return 0;
}

void Player::UpdateMirrorTimers()
Expand Down Expand Up @@ -1390,7 +1394,7 @@ void Player::Update(uint32 update_diff, uint32 p_time)
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
}
}
}
}// Speed collect rest bonus (section/in hour)

if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))
{
Expand Down Expand Up @@ -6956,6 +6960,15 @@ void Player::SendCinematicStart(uint32 CinematicSequenceId)
SendDirectMessage(&data);
}

#if defined (WOTLK) || defined (CATA) || defined (MISTS)
void Player::SendMovieStart(uint32 MovieId)
{
WorldPacket data(SMSG_TRIGGER_MOVIE, 4);
data << uint32(MovieId);
SendDirectMessage(&data);
}
#endif

void Player::CheckAreaExploreAndOutdoor()
{
if (!IsAlive())
Expand Down Expand Up @@ -24148,6 +24161,23 @@ void Player::ResummonPetTemporaryUnSummonedIfAny()
m_temporaryUnsummonedPetNumber = 0;
}

bool Player::canSeeSpellClickOn(Creature const* c) const
{
if (!c->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
{
return false;
}

SpellClickInfoMapBounds clickPair = sObjectMgr.GetSpellClickInfoMapBounds(c->GetEntry());
for (SpellClickInfoMap::const_iterator itr = clickPair.first; itr != clickPair.second; ++itr)
if (itr->second.IsFitToRequirements(this, c))
{
return true;
}

return false;
}

void Player::_SaveBGData()
{
// nothing save
Expand Down
37 changes: 30 additions & 7 deletions src/game/Object/Player.h
Expand Up @@ -429,6 +429,7 @@ enum PlayerFlags
PLAYER_FLAGS_SANCTUARY = 0x00010000, // player entered sanctuary
PLAYER_FLAGS_TAXI_BENCHMARK = 0x00020000, // taxi benchmark mode (on/off) (2.0.1)
PLAYER_FLAGS_PVP_TIMER = 0x00040000, // 3.0.2, pvp timer active (after you disable pvp manually)
PLAYER_FLAGS_XP_USER_DISABLED = 0x02000000,
};

// used for PLAYER__FIELD_KNOWN_TITLES field (uint64), (1<<bit_index) without (-1)
Expand Down Expand Up @@ -892,6 +893,19 @@ struct BGData
bool m_needSave; ///< true, if saved to DB fields modified after prev. save (marked as "saved" above)
};

struct TradeStatusInfo
{
TradeStatusInfo() : Status(TRADE_STATUS_BUSY), TraderGuid(), Result(EQUIP_ERR_OK),
IsTargetResult(false), ItemLimitCategoryId(0), Slot(0) { }

TradeStatus Status;
ObjectGuid TraderGuid;
InventoryResult Result;
bool IsTargetResult;
uint32 ItemLimitCategoryId;
uint8 Slot;
};

class TradeData
{
public: // constructors
Expand Down Expand Up @@ -1059,7 +1073,10 @@ class Player : public Unit
}

PlayerTaxi m_taxi;
void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(getRace(), getLevel()); }
void InitTaxiNodesForLevel()
{
m_taxi.InitTaxiNodesForLevel(getRace(), getLevel());
}
bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc = NULL, uint32 spellid = 0);
bool ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid = 0);
// mount_id can be used in scripting calls
Expand Down Expand Up @@ -1138,12 +1155,12 @@ class Player : public Unit
void SetRestBonus(float rest_bonus_new);

/**
* \brief: compute rest bonus
* \param: time_t timePassed > time from last check
* \param: bool offline > is the player was offline?
* \param: bool inRestPlace > if it was offline, is the player was in city/tavern/inn?
* \returns: float
**/
* \brief: compute rest bonus
* \param: time_t timePassed > time from last check
* \param: bool offline > is the player was offline?
* \param: bool inRestPlace > if it was offline, is the player was in city/tavern/inn?
* \returns: float
**/
float ComputeRest(time_t timePassed, bool offline = false, bool inRestPlace = false);

RestType GetRestType() const
Expand Down Expand Up @@ -1275,6 +1292,7 @@ class Player : public Unit
{
return m_ammoDPS;
}

bool CheckAmmoCompatibility(const ItemPrototype* ammo_proto) const;
void QuickEquipItem(uint16 pos, Item* pItem);
void VisualizeItem(uint8 slot, Item* pItem);
Expand Down Expand Up @@ -2367,6 +2385,9 @@ class Player : public Unit
bool IsPetNeedBeTemporaryUnsummoned() const { return !IsInWorld() || !IsAlive() || IsMounted() /*+in flight*/; }

void SendCinematicStart(uint32 CinematicSequenceId);
#if defined(WOTLK) || defined(CATA) || defined(MISTS)
void SendMovieStart(uint32 MovieId);
#endif

/*********************************************************/
/*** INSTANCE SYSTEM ***/
Expand Down Expand Up @@ -2429,6 +2450,8 @@ class Player : public Unit
bool HasTitle(CharTitlesEntry const* title) const { return HasTitle(title->bit_index); }
void SetTitle(CharTitlesEntry const* title, bool lost = false);

bool canSeeSpellClickOn(Creature const* creature) const;

#ifdef ENABLE_PLAYERBOTS
//EquipmentSets& GetEquipmentSets() { return m_EquipmentSets; }
void SetPlayerbotAI(PlayerbotAI* ai) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotAI = ai; }
Expand Down
2 changes: 2 additions & 0 deletions src/game/Server/DBCStores.cpp
Expand Up @@ -113,6 +113,8 @@ DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);

DBCStorage <MapEntry> sMapStore(MapEntryfmt);

DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);

DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);

DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
Expand Down

0 comments on commit 39c30cf

Please sign in to comment.