TrinityCore
Loading...
Searching...
No Matches
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_only_for_flight Items which should only useable while flying
28EndContentData */
29
30#include "ScriptMgr.h"
31#include "GameObject.h"
32#include "Item.h"
33#include "Player.h"
34#include "ScriptedCreature.h"
35#include "Spell.h"
36#include "SpellMgr.h"
37#include "TemporarySummon.h"
38
39/*#####
40# item_only_for_flight
41#####*/
42
47
49{
50public:
51 item_only_for_flight() : ItemScript("item_only_for_flight") { }
52
53 bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
54 {
55 uint32 itemId = item->GetEntry();
56 bool disabled = false;
57
58 //for special scripts
59 switch (itemId)
60 {
61 case 24538:
62 if (player->GetAreaId() != 3628)
63 disabled = true;
64 break;
65 case 34489:
66 if (player->GetZoneId() != 4080)
67 disabled = true;
68 break;
69 case 34475:
70 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(SPELL_ARCANE_CHARGES))
72 break;
73 }
74
75 // allow use in flight only
76 if (player->IsInFlight() && !disabled)
77 return false;
78
79 // error
80 player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, nullptr);
81 return true;
82 }
83};
84
85/*#####
86# item_mysterious_egg
87#####*/
88
90{
91public:
92 item_mysterious_egg() : ItemScript("item_mysterious_egg") { }
93
94 bool OnExpire(Player* player, ItemTemplate const* /*pItemProto*/) override
95 {
96 ItemPosCountVec dest;
97 uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 39883, 1); // Cracked Egg
98 if (msg == EQUIP_ERR_OK)
99 player->StoreNewItem(dest, 39883, true, GenerateItemRandomPropertyId(39883));
100
101 return true;
102 }
103};
104
105/*#####
106# item_disgusting_jar
107#####*/
108
110{
111public:
112 item_disgusting_jar() : ItemScript("item_disgusting_jar") { }
113
114 bool OnExpire(Player* player, ItemTemplate const* /*pItemProto*/) override
115 {
116 ItemPosCountVec dest;
117 uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 44718, 1); // Ripe Disgusting Jar
118 if (msg == EQUIP_ERR_OK)
119 player->StoreNewItem(dest, 44718, true, GenerateItemRandomPropertyId(44718));
120
121 return true;
122 }
123};
124
125/*#####
126# item_petrov_cluster_bombs
127#####*/
128
135
137{
138public:
139 item_petrov_cluster_bombs() : ItemScript("item_petrov_cluster_bombs") { }
140
141 bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
142 {
143 if (player->GetZoneId() != ZONE_ID_HOWLING)
144 return false;
145
146 if (!player->GetTransport() || player->GetAreaId() != AREA_ID_SHATTERED_STRAITS)
147 {
148 player->SendEquipError(EQUIP_ERR_NONE, item, nullptr);
149
150 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(SPELL_PETROV_BOMB))
151 Spell::SendCastResult(player, spellInfo, 1, SPELL_FAILED_NOT_HERE);
152
153 return true;
154 }
155
156 return false;
157 }
158};
159
165
167{
168public:
169 item_captured_frog() : ItemScript("item_captured_frog") { }
170
171 bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
172 {
174 {
176 return false;
177 else
178 player->SendEquipError(EQUIP_ERR_OUT_OF_RANGE, item, nullptr);
179 }
180 else
181 player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, nullptr);
182 return true;
183 }
184};
185
186// Only used currently for
187// 19169: Nightfall
189{
190 public:
191 item_generic_limit_chance_above_60() : ItemScript("item_generic_limit_chance_above_60") { }
192
193 bool OnCastItemCombatSpell(Player* /*player*/, Unit* victim, SpellInfo const* /*spellInfo*/, Item* /*item*/) override
194 {
195 // spell proc chance gets severely reduced on victims > 60 (formula unknown)
196 if (victim->GetLevel() > 60)
197 {
198 // gives ~0.1% proc chance at lvl 70
199 float const lvlPenaltyFactor = 9.93f;
200 float const failureChance = (victim->GetLevel() - 60) * lvlPenaltyFactor;
201
202 // base ppm chance was already rolled, only roll success chance
203 return !roll_chance_f(failureChance);
204 }
205
206 return true;
207 }
208};
209
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
@ EQUIP_ERR_OUT_OF_RANGE
Definition ItemDefines.h:51
@ EQUIP_ERR_CLIENT_LOCKED_OUT
Definition ItemDefines.h:65
@ EQUIP_ERR_OK
Definition ItemDefines.h:26
@ EQUIP_ERR_NONE
int32 GenerateItemRandomPropertyId(uint32 item_id)
std::vector< ItemPosCount > ItemPosCountVec
Definition Player.h:624
@ QUEST_STATUS_INCOMPLETE
Definition QuestDef.h:107
bool roll_chance_f(float chance)
Definition Random.h:53
@ SPELL_FAILED_NOT_HERE
@ SPELL_FAILED_NOT_ON_GROUND
#define sSpellMgr
Definition SpellMgr.h:738
@ NULL_BAG
Definition Unit.h:61
@ NULL_SLOT
Definition Unit.h:62
Definition Item.h:62
uint32 GetEntry() const
Definition Object.h:81
Item * StoreNewItem(ItemPosCountVec const &pos, uint32 item, bool update, int32 randomPropertyId=0, GuidSet const &allowedLooters=GuidSet())
Definition Player.cpp:11621
void SendEquipError(InventoryResult msg, Item *pItem, Item *pItem2=nullptr, uint32 itemid=0) const
Definition Player.cpp:13075
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition Player.cpp:15642
InventoryResult CanStoreNewItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, uint32 item, uint32 count, uint32 *no_space_count=nullptr) const
Definition Player.cpp:9989
static void SendCastResult(Player *caster, SpellInfo const *spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError=SPELL_CUSTOM_ERROR_NONE, uint32 *param1=nullptr, uint32 *param2=nullptr)
Definition Spell.cpp:4177
Definition Unit.h:769
bool IsInFlight() const
Definition Unit.h:1119
uint8 GetLevel() const
Definition Unit.h:889
Transport * GetTransport() const
Definition Object.h:564
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:2099
uint32 GetAreaId() const
Definition Object.h:374
uint32 GetZoneId() const
Definition Object.h:373
bool OnUse(Player *player, Item *item, SpellCastTargets const &) override
bool OnExpire(Player *player, ItemTemplate const *) override
bool OnCastItemCombatSpell(Player *, Unit *victim, SpellInfo const *, Item *) override
bool OnExpire(Player *player, ItemTemplate const *) override
bool OnUse(Player *player, Item *item, SpellCastTargets const &) override
bool OnUse(Player *player, Item *item, SpellCastTargets const &) 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