TrinityCore
item_scripts.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19SDName: Item_Scripts
20SD%Complete: 100
21SDComment: Items for a range of different items. See content below (in script)
22SDCategory: Items
23EndScriptData */
24
25/* ContentData
26item_flying_machine(i34060, i34061) Engineering crafted flying machines
27item_gor_dreks_ointment(i30175) Protecting Our Own(q10488)
28item_only_for_flight Items which should only useable while flying
29EndContentData */
30
31#include "ScriptMgr.h"
32#include "GameObject.h"
33#include "Item.h"
34#include "Map.h"
35#include "Player.h"
36#include "ScriptedCreature.h"
37#include "Spell.h"
38#include "SpellMgr.h"
39#include "TemporarySummon.h"
40
41/*#####
42# item_only_for_flight
43#####*/
44
46{
48};
49
51{
52public:
53 item_only_for_flight() : ItemScript("item_only_for_flight") { }
54
55 bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/, ObjectGuid castId) override
56 {
57 uint32 itemId = item->GetEntry();
58 bool disabled = false;
59
60 //for special scripts
61 switch (itemId)
62 {
63 case 24538:
64 if (player->GetAreaId() != 3628)
65 disabled = true;
66 break;
67 case 34489:
68 if (player->GetZoneId() != 4080)
69 disabled = true;
70 break;
71 case 34475:
72 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(SPELL_ARCANE_CHARGES, player->GetMap()->GetDifficultyID()))
73 Spell::SendCastResult(player, spellInfo, {}, castId, SPELL_FAILED_NOT_ON_GROUND);
74 break;
75 }
76
77 // allow use in flight only
78 if (player->IsInFlight() && !disabled)
79 return false;
80
81 // error
82 player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, nullptr);
83 return true;
84 }
85};
86
87/*#####
88# item_gor_dreks_ointment
89#####*/
90
92{
93public:
94 item_gor_dreks_ointment() : ItemScript("item_gor_dreks_ointment") { }
95
96 bool OnUse(Player* player, Item* item, SpellCastTargets const& targets, ObjectGuid /*castId*/) override
97 {
98 if (targets.GetUnitTarget() && targets.GetUnitTarget()->GetTypeId() == TYPEID_UNIT &&
99 targets.GetUnitTarget()->GetEntry() == 20748 && !targets.GetUnitTarget()->HasAura(32578))
100 return false;
101
102 player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, nullptr);
103 return true;
104 }
105};
106
107/*#####
108# item_mysterious_egg
109#####*/
110
112{
113public:
114 item_mysterious_egg() : ItemScript("item_mysterious_egg") { }
115
116 bool OnExpire(Player* player, ItemTemplate const* /*pItemProto*/) override
117 {
118 ItemPosCountVec dest;
119 uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 39883, 1); // Cracked Egg
120 if (msg == EQUIP_ERR_OK)
121 player->StoreNewItem(dest, 39883, true, GenerateItemRandomBonusListId(39883));
122
123 return true;
124 }
125};
126
127/*#####
128# item_disgusting_jar
129#####*/
130
132{
133public:
134 item_disgusting_jar() : ItemScript("item_disgusting_jar") { }
135
136 bool OnExpire(Player* player, ItemTemplate const* /*pItemProto*/) override
137 {
138 ItemPosCountVec dest;
139 uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 44718, 1); // Ripe Disgusting Jar
140 if (msg == EQUIP_ERR_OK)
141 player->StoreNewItem(dest, 44718, true, GenerateItemRandomBonusListId(44718));
142
143 return true;
144 }
145};
146
147/*#####
148# item_petrov_cluster_bombs
149#####*/
150
152{
155 ZONE_ID_HOWLING = 495
157
159{
160public:
161 item_petrov_cluster_bombs() : ItemScript("item_petrov_cluster_bombs") { }
162
163 bool OnUse(Player* player, Item* /*item*/, SpellCastTargets const& /*targets*/, ObjectGuid castId) override
164 {
165 if (player->GetZoneId() != ZONE_ID_HOWLING)
166 return false;
167
168 if (!player->GetTransport() || player->GetAreaId() != AREA_ID_SHATTERED_STRAITS)
169 {
170 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(SPELL_PETROV_BOMB, DIFFICULTY_NONE))
171 Spell::SendCastResult(player, spellInfo, {}, castId, SPELL_FAILED_NOT_HERE);
172
173 return true;
174 }
175
176 return false;
177 }
178};
179
181{
185
187{
188public:
189 item_captured_frog() : ItemScript("item_captured_frog") { }
190
191 bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/, ObjectGuid /*castId*/) override
192 {
194 {
196 return false;
197 else
198 player->SendEquipError(EQUIP_ERR_OUT_OF_RANGE, item, nullptr);
199 }
200 else
201 player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, nullptr);
202 return true;
203 }
204};
205
206// Only used currently for
207// 19169: Nightfall
209{
210 public:
211 item_generic_limit_chance_above_60() : ItemScript("item_generic_limit_chance_above_60") { }
212
213 bool OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo const* /*spellInfo*/, Item* /*item*/) override
214 {
215 // spell proc chance gets severely reduced on victims > 60 (formula unknown)
216 if (victim->GetLevel() > 60)
217 {
218 // gives ~0.1% proc chance at lvl 70
219 float const lvlPenaltyFactor = 9.93f;
220 float const failureChance = (victim->GetLevelForTarget(player) - 60) * lvlPenaltyFactor;
221
222 // base ppm chance was already rolled, only roll success chance
223 return !roll_chance_f(failureChance);
224 }
225
226 return true;
227 }
228};
229
231{
237 new item_captured_frog();
239}
@ DIFFICULTY_NONE
Definition: DBCEnums.h:874
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
@ EQUIP_ERR_OUT_OF_RANGE
Definition: ItemDefines.h:51
@ EQUIP_ERR_CLIENT_LOCKED_OUT
Definition: ItemDefines.h:66
@ EQUIP_ERR_OK
Definition: ItemDefines.h:26
ItemRandomBonusListId GenerateItemRandomBonusListId(uint32 item_id)
@ TYPEID_UNIT
Definition: ObjectGuid.h:40
std::vector< ItemPosCount > ItemPosCountVec
Definition: Player.h:750
@ QUEST_STATUS_INCOMPLETE
Definition: QuestDef.h:145
bool roll_chance_f(float chance)
Definition: Random.h:53
@ SPELL_FAILED_NOT_HERE
@ SPELL_FAILED_NOT_ON_GROUND
#define sSpellMgr
Definition: SpellMgr.h:849
@ NULL_BAG
Definition: Unit.h:62
@ NULL_SLOT
Definition: Unit.h:63
Definition: Item.h:170
Difficulty GetDifficultyID() const
Definition: Map.h:324
TypeID GetTypeId() const
Definition: Object.h:173
uint32 GetEntry() const
Definition: Object.h:161
void SendEquipError(InventoryResult msg, Item const *item1=nullptr, Item const *item2=nullptr, uint32 itemId=0) const
Definition: Player.cpp:13254
Item * StoreNewItem(ItemPosCountVec const &pos, uint32 itemId, bool update, ItemRandomBonusListId randomBonusListId=0, GuidSet const &allowedLooters=GuidSet(), ItemContext context=ItemContext::NONE, std::vector< int32 > const *bonusListIDs=nullptr, bool addToCollection=true)
Definition: Player.cpp:11537
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition: Player.cpp:16050
InventoryResult CanStoreNewItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, uint32 item, uint32 count, uint32 *no_space_count=nullptr) const
Definition: Player.cpp:10032
Unit * GetUnitTarget() const
Definition: Spell.cpp:218
static void SendCastResult(Player *caster, SpellInfo const *spellInfo, SpellCastVisual spellVisual, ObjectGuid cast_count, SpellCastResult result, SpellCustomErrors customError=SPELL_CUSTOM_ERROR_NONE, int32 *param1=nullptr, int32 *param2=nullptr)
Definition: Spell.cpp:4643
Definition: Unit.h:627
bool IsInFlight() const
Definition: Unit.h:1012
uint8 GetLevelForTarget(WorldObject const *) const override
Definition: Unit.h:747
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition: Unit.cpp:4664
uint8 GetLevel() const
Definition: Unit.h:746
Map * GetMap() const
Definition: Object.h:624
TransportBase * GetTransport() const
Definition: Object.h:750
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition: Object.cpp:2148
uint32 GetAreaId() const
Definition: Object.h:546
uint32 GetZoneId() const
Definition: Object.h:545
bool OnUse(Player *player, Item *item, SpellCastTargets const &, ObjectGuid) override
bool OnExpire(Player *player, ItemTemplate const *) override
bool OnCastItemCombatSpell(Player *player, Unit *victim, SpellInfo const *, Item *) override
bool OnUse(Player *player, Item *item, SpellCastTargets const &targets, ObjectGuid) override
bool OnExpire(Player *player, ItemTemplate const *) override
bool OnUse(Player *player, Item *item, SpellCastTargets const &, ObjectGuid castId) override
bool OnUse(Player *player, Item *, SpellCastTargets const &, ObjectGuid castId) override
CapturedFrog
@ NPC_VANIRAS_SENTRY_TOTEM
@ QUEST_THE_PERFECT_SPIES
void AddSC_item_scripts()
PetrovClusterBombs
@ ZONE_ID_HOWLING
@ SPELL_PETROV_BOMB
@ AREA_ID_SHATTERED_STRAITS
OnlyForFlight
@ SPELL_ARCANE_CHARGES