Skip to content

Instantly share code, notes, and snippets.

@Natureknight
Created December 24, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natureknight/2f9ec6d61d402804b6d0 to your computer and use it in GitHub Desktop.
Save Natureknight/2f9ec6d61d402804b6d0 to your computer and use it in GitHub Desktop.
diff --git a/src/server/scripts/Custom/copyGearCommands.cpp b/src/server/scripts/Custom/copyGearCommands.cpp
index 49884d8..8ec7bd5 100644
--- a/src/server/scripts/Custom/copyGearCommands.cpp
+++ b/src/server/scripts/Custom/copyGearCommands.cpp
@@ -11,6 +11,9 @@
#include "ScriptPCH.h"
+const uint32 MIN_ITEM_LEVEL_AVAILABLE_FOR_COPY = 232;
+const uint32 MAX_ITEM_LEVEL_AVAILABLE_FOR_COPY = 284;
+
enum ArmorSpells
{
PLATE_MAIL = 750,
@@ -85,25 +88,31 @@ public:
{
if (target == player)
{
- handler->GetSession()->SendAreaTriggerMessage("You can't copy your own gear.");
+ handler->PSendSysMessage("You can't copy your own gear.");
return false;
}
if (player->getClass() != target->getClass())
{
- handler->GetSession()->SendAreaTriggerMessage("Target's class doesn't match your class.");
+ handler->PSendSysMessage("Target's class doesn't match your class.");
return false;
}
// Restrict copying from the opposite faction
if (player->GetTeam() != target->GetTeam())
{
- handler->GetSession()->SendAreaTriggerMessage("You can only copy talents from players thats in opposite faction.");
+ handler->PSendSysMessage("You can only copy talents from players thats in opposite faction.");
+ return false;
+ }
+ else if (target->getRace() == RACE_HUMAN && player->getRace() != RACE_HUMAN)
+ {
+ handler->PSendSysMessage("You also have to be human in order to copy gear from %s",
+ target->GetName());
return false;
}
CopyGear(player, target);
- handler->GetSession()->SendAreaTriggerMessage("Successfuly copied gear of %s",
+ handler->PSendSysMessage("Successfuly copied gear of %s",
target->GetName());
LearnPlateMailSpells(player);
@@ -113,7 +122,7 @@ public:
return true;
}
else
- player->GetSession()->SendAreaTriggerMessage("You must have a target.");
+ handler->PSendSysMessage("You must have a target.");
return true;
}
@@ -142,18 +151,24 @@ public:
{
if (target == player)
{
- handler->GetSession()->SendAreaTriggerMessage("You can't copy your own talents.");
+ handler->PSendSysMessage("You can't copy your own talents.");
+ return false;
+ }
+
+ if (player->GetFreeTalentPoints() < 71)
+ {
+ handler->PSendSysMessage("You need to reset your talents first.");
return false;
}
if (player->getClass() != target->getClass())
{
- handler->GetSession()->SendAreaTriggerMessage("Target's class doesn't match your class.");
+ handler->PSendSysMessage("Target's class doesn't match your class.");
return false;
}
CopyTalents(player, target);
- handler->GetSession()->SendAreaTriggerMessage("Successfuly copied talents of %s",
+ handler->PSendSysMessage("Successfuly copied talents of %s",
target->GetName());
player->UpdateSkillsForLevel();
@@ -161,7 +176,7 @@ public:
return true;
}
else
- player->GetSession()->SendAreaTriggerMessage("You must have a target.");
+ handler->PSendSysMessage("You must have a target.");
return true;
}
@@ -190,27 +205,38 @@ public:
{
if (target == player)
{
- handler->GetSession()->SendAreaTriggerMessage("You can't copy your own gear/talents.");
+ handler->PSendSysMessage("You can't copy your own gear/talents.");
+ return false;
+ }
+
+ if (player->GetFreeTalentPoints() < 71)
+ {
+ handler->PSendSysMessage("You need to reset your talents first.");
return false;
}
if (player->getClass() != target->getClass())
{
- handler->GetSession()->SendAreaTriggerMessage("Target's class doesn't match your class.");
+ handler->PSendSysMessage("Target's class doesn't match your class.");
return false;
}
// Restrict copying from the opposite faction
if (player->GetTeam() != target->GetTeam())
{
- handler->GetSession()->SendAreaTriggerMessage("You can only copy talents from players thats in opposite faction.");
+ handler->PSendSysMessage("You can only copy talents from players thats in opposite faction.");
+ return false;
+ }
+ else if (target->getRace() == RACE_HUMAN && player->getRace() != RACE_HUMAN)
+ {
+ handler->PSendSysMessage("You also have to be human in order to copy gear from %s",
+ target->GetName());
return false;
}
-
CopyGear(player, target);
CopyTalents(player, target);
- handler->GetSession()->SendAreaTriggerMessage("Successfuly copied gear and talents of %s",
+ handler->PSendSysMessage("Successfuly copied gear and talents of %s",
target->GetName());
LearnPlateMailSpells(player);
@@ -220,7 +246,7 @@ public:
return true;
}
else
- player->GetSession()->SendAreaTriggerMessage("You must have a target.");
+ handler->PSendSysMessage("You must have a target.");
return true;
}
@@ -249,7 +275,9 @@ private:
if (Item* equippedItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
- // TODO: Implement checks for items here
+ // Additional checks for some forbidden items
+ if (!IsAllowedItem(equippedItem))
+ continue;
player->EquipNewItem(i, target->GetItemByPos(INVENTORY_SLOT_BAG_0, i)->GetEntry(), true);
ApplyBonus(player, player->GetItemByPos(INVENTORY_SLOT_BAG_0, i),
@@ -270,21 +298,13 @@ private:
static void CopyTalents(Player* player, Player* target)
{
- // Reset current talents first
- if (player->GetFreeTalentPoints() < 71)
- {
- player->resetTalents(true);
- player->SendTalentsInfoData(false);
- }
-
target->SaveToDB();
-
QueryResult result = CharacterDatabase.PQuery("SELECT spell FROM character_talent WHERE guid = '%u' "
"AND spec = '%u';", target->GetGUID(), target->GetActiveSpec());
if (!result)
{
- player->GetSession()->SendAreaTriggerMessage("%s doesn't have any talents yet.",
+ ChatHandler(player).PSendSysMessage("%s doesn't have any talents yet.",
target->GetName());
return;
}
@@ -350,6 +370,27 @@ private:
}
}
+ static bool IsAllowedItem(Item* item)
+ {
+ ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(item->GetEntry());
+
+ if (!itemProto)
+ return false;
+
+ if (itemProto->ItemLevel > MAX_ITEM_LEVEL_AVAILABLE_FOR_COPY || itemProto->ItemLevel < MIN_ITEM_LEVEL_AVAILABLE_FOR_COPY)
+ return false;
+
+ if (itemProto->Quality > 4)
+ return false;
+
+ // Tabards and shirts are items with level lower
+ // than 232, so we don't have to implement a separate
+ // check for gladiator's tabards or any shirts which
+ // players won't be able to copy
+
+ return true;
+ }
+
static void LearnWeaponSkills(Player* player)
{
WeaponProficiencies wepSkills[] = {
warning: LF will be replaced by CRLF in src/server/scripts/Custom/copyGearCommands.cpp.
The file will have its original line endings in your working directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment