这套代码主要是用在定义玩家角色获得经验的控制上面的。。
首先是第一部分:内核部分,你需要在下面的Player.cpp和Player.h中加入对应的代码。
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 8283285..58d8ed3 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -3004,6 +3004,9 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate)
else
bonus_xp = victim ? GetXPRestBonus(xp) : 0; // XP resting bonus
+ //Checks the players XP rate
+ xp *= GetXPRate();
+
SendLogXPGain(xp, victim, bonus_xp, recruitAFriend, group_rate);
uint32 curXP = GetUInt32Value(PLAYER_XP);
@@ -18881,6 +18884,33 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
return true;
}
+/**********************END***************************/
+
+void Player::SetXPRate(uint32 rate)
+{
+ XPRate = rate;
+}
+
+uint32 Player::GetXPRate()
+{
+ return XPRate;
+}
+
+void Player::SetRate(uint32 rate)
+{
+ if (GetXPRate() >= 2)
+ {
+ GetSession()->SendAreaTriggerMessage("You can't set your xp rate more than once!");
+ }
+}
+
+void Player::UpdateXPRate(uint32 rate)
+{
+ CharacterDatabase.PExecute("UPDATE characters set XPRate='%u' where guid='%u';", rate, GetGUIDLow());
+}
+
/*********************************************************/
/*** SAVE SYSTEM ***/
/*********************************************************/
@@ -26320,4 +26350,4 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
//ObjectAccessor::UpdateObjectVisibility(pet);
return pet;
-}
+}
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 1c0fa4e..2b7e1ea 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1457,6 +1457,16 @@ class Player : public Unit, public GridObject<Player>
static bool IsValidGender(uint8 Gender) { return Gender <= GENDER_FEMALE; }
+ /***********************END*************************/
+
+ //XP Rates Script
+ void SetRate(uint32 rate);
+ void SetXPRate(uint32 rate);
+ void UpdateXPRate(uint32 rate);
+ uint32 GetXPRate();
+ uint32 XPRate;
+ uint32 rate;
+
/*********************************************************/
/*** SAVE SYSTEM ***/
/*********************************************************/
diff --git a/src/server/game/Scripting/ScriptLoader.cpp b/src/server/game/Scripting/ScriptLoader.cpp
index edabc7b..4dd28bb 100644
--- a/src/server/game/Scripting/ScriptLoader.cpp
+++ b/src/server/game/Scripting/ScriptLoader.cpp
@@ -1291,13 +1291,13 @@ void AddBattlegroundScripts()
#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */
-
+ void AddSC_XP_Rate_Load();
#endif
void AddCustomScripts()
{
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
-
+ AddSC_XP_Rate_Load();
#endif
}
diff --git a/src/server/scripts/Custom/CMakeLists.txt b/src/server/scripts/Custom/CMakeLists.txt
index 99cf026..f43d2f6 100644
--- a/src/server/scripts/Custom/CMakeLists.txt
+++ b/src/server/scripts/Custom/CMakeLists.txt
@@ -10,6 +10,7 @@
set(scripts_STAT_SRCS
${scripts_STAT_SRCS}
+ Custom/XPRates.cpp
)
message(" -> Prepared: Custom")
然后是第二部分,脚本部分。这里主要实现命令和数据库载入
//Edit this to your desired default rate.
//REMEMBER TO SET ALL XP RATES TO 1 IN THE CONFIG!
uint32 DefaultRate = 1;
uint32 MaxRate = 20;
//Don't edit below this.
class XP_Rate_Load : public PlayerScript
{
public:
XP_Rate_Load() : PlayerScript("XP_Rate_Load") {}
void OnLogin(Player* player)
{
QueryResult XPRateCheck = CharacterDatabase.PQuery("SELECT XPRate FROM characters WHERE GUID = %u", player->GetGUIDLow());
Field* fields = XPRateCheck->Fetch();
uint32 XPRate = fields[0].GetUInt32();
if(XPRateCheck)
{
Field* fields = XPRateCheck->Fetch();
uint32 XPRate = fields[0].GetUInt32();
if (XPRate == 0)
{
player->SetXPRate(DefaultRate);
player->UpdateXPRate(DefaultRate);
}
else
player->SetXPRate(XPRate);
}
else
{
player->UpdateXPRate(DefaultRate);
player->SetXPRate(DefaultRate);
}
}
};
class XP_Rate_Command : public CommandScript
{
public:
XP_Rate_Command() : CommandScript("XP_Rate_Command") { }
ChatCommand* GetCommands() const
{
static ChatCommand IngameCommandTable[] =
{
{ "setxprate", SEC_PLAYER, true, &HandleBuffCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
return IngameCommandTable;
}
static bool HandleBuffCommand(ChatHandler * handler, const char * args)
{
Player * player = handler->GetSession()->GetPlayer();
if (!*args)
{
handler->PSendSysMessage("You must write a number.");
return false;
}
uint32 newrate = (uint32)atoi((char*)args);
if (newrate > MaxRate || newrate == 0)
{
handler->PSendSysMessage("The value is too high!");
}
else
{
player->SetXPRate(newrate);
player->UpdateXPRate(newrate);
handler->PSendSysMessage("Your XP rate is now set to: %u.", newrate);
}
return true;
}
};
void AddSC_XP_Rate_Load()
{
new XP_Rate_Load();
new XP_Rate_Command();
}
下面是两个部分的完整代码下载
内核部分代码下载
脚本部分代码下载
|