Skip to content

Commit 4e91f45

Browse files
offlShauren
andauthored
Core/Conditions: Implement condition to check if player is in group (TrinityCore#31858)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
1 parent d1ebb09 commit 4e91f45

4 files changed

Lines changed: 85 additions & 24 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--
2+
DELETE FROM `spell_target_position` WHERE `ID` IN (12885,13142,27694);
3+
INSERT INTO `spell_target_position` (`ID`, `EffectIndex`, `MapID`, `PositionX`, `PositionY`, `PositionZ`, `Orientation`, `VerifiedBuild`) VALUES
4+
(12885,0,0,-11235.3,-2832.14,157.925,4.71,0),
5+
(13142,0,0,-11235.3,-2832.14,157.925,4.71,0),
6+
(27694,0,0,-11235.3,-2832.14,157.925,4.71,0);
7+
8+
DELETE FROM `gossip_menu_option` WHERE `MenuID` = 1541 AND `OptionID` = 1;
9+
INSERT INTO `gossip_menu_option` (`MenuID`,`OptionID`,`OptionIcon`,`OptionText`,`OptionBroadcastTextID`,`OptionType`,`OptionNpcFlag`,`ActionMenuID`,`ActionPoiID`,`BoxCoded`,`BoxMoney`,`BoxText`,`BoxBroadcastTextID`,`VerifiedBuild`) VALUES
10+
(1541,1,0,"We wish to face the Defiler.",11869,1,1,0,0,0,0,"",0,0);
11+
12+
DELETE FROM `smart_scripts` WHERE `entryorguid` = 8816 AND `source_type` = 0;
13+
INSERT INTO `smart_scripts` (`entryorguid`,`source_type`,`id`,`link`,`event_type`,`event_phase_mask`,`event_chance`,`event_flags`,`event_param1`,`event_param2`,`event_param3`,`event_param4`,`event_param5`,`action_type`,`action_param1`,`action_param2`,`action_param3`,`action_param4`,`action_param5`,`action_param6`,`target_type`,`target_param1`,`target_param2`,`target_param3`,`target_param4`,`target_x`,`target_y`,`target_z`,`target_o`,`comment`) VALUES
14+
(8816,0,0,0,62,0,100,0,1541,0,0,0,0,11,12885,0,0,0,0,0,7,0,0,0,0,0,0,0,0,"Deathly Usher - On Gossip Option 0 Selected - Cast 'Teleport to Razelikh'"),
15+
(8816,0,1,0,62,0,100,0,1541,1,0,0,0,11,27686,0,0,0,0,0,7,0,0,0,0,0,0,0,0,"Deathly Usher - On Gossip Option 1 Selected - Cast 'Teleport to Razelikh (GROUP)'");
16+
17+
DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId` = 15 AND `SourceGroup` = 1541;
18+
INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ConditionStringValue1`,`NegativeCondition`,`ErrorType`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES
19+
(15,1541,0,0,0,47,0,3628,10,0,'',0,0,0,'',"Group 0: Show Gossip Option 0 if player has taken quest 'You Are Rakh'likh, Demon'"),
20+
(15,1541,0,0,0,2,0,10757,1,0,'',0,0,0,'',"Group 0: Show Gossip Option 0 if player has item 'Ward of the Defiler'"),
21+
(15,1541,0,0,0,60,0,0,0,0,'',0,0,0,'',"Group 0: Show Gossip Option 0 if player is not in group"),
22+
23+
(15,1541,1,0,0,47,0,3628,10,0,'',0,0,0,'',"Group 0: Show Gossip Option 1 if player has taken quest 'You Are Rakh'likh, Demon'"),
24+
(15,1541,1,0,0,2,0,10757,1,0,'',0,0,0,'',"Group 0: Show Gossip Option 1 if player has item 'Ward of the Defiler'"),
25+
(15,1541,1,0,0,60,0,1,0,0,'',0,0,0,'',"Group 0: Show Gossip Option 1 if player is in group");
26+
27+
UPDATE `spell_script_names` SET `ScriptName` = 'spell_blasted_lands_teleport_to_razelikh_group' WHERE `ScriptName` = 'spell_razelikh_teleport_group';

src/server/game/Conditions/ConditionMgr.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "DatabaseEnv.h"
2222
#include "GameEventMgr.h"
2323
#include "GameObject.h"
24+
#include "Group.h"
2425
#include "InstanceScript.h"
2526
#include "Log.h"
2627
#include "LootMgr.h"
@@ -127,8 +128,28 @@ ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[COND
127128
{ "Private Object", false, false, false, false },
128129
{ "String ID", false, false, false, true },
129130
{ "Label", false, false, false, false },
131+
{ "Group status", true, false, false, false }
130132
};
131133

134+
static bool MeetsGroupStatusCondition(Player const* player, GroupStatusCondition status)
135+
{
136+
Group const* group = player->GetGroup();
137+
switch (status)
138+
{
139+
case GroupStatusCondition::NotInGroup:
140+
return group == nullptr;
141+
case GroupStatusCondition::InGroup:
142+
return group != nullptr;
143+
case GroupStatusCondition::InGroupButNotInRaid:
144+
return group && !group->isRaidGroup();
145+
case GroupStatusCondition::InRaid:
146+
return group && group->isRaidGroup();
147+
case GroupStatusCondition::NotInGroupOrNotInRaid:
148+
return !group || !group->isRaidGroup();
149+
}
150+
return false;
151+
}
152+
132153
// Checks if object meets the condition
133154
// Can have CONDITION_SOURCE_TYPE_NONE && !mReferenceId if called from a special event (ie: SmartAI)
134155
bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
@@ -548,6 +569,12 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
548569
condMeets = go->HasStringId(ConditionStringValue1);
549570
break;
550571
}
572+
case CONDITION_GROUP_STATUS:
573+
{
574+
if (Player const* player = object->ToPlayer())
575+
condMeets = MeetsGroupStatusCondition(player, GroupStatusCondition(ConditionValue1));
576+
break;
577+
}
551578
default:
552579
condMeets = false;
553580
break;
@@ -750,6 +777,9 @@ uint32 Condition::GetSearcherTypeMaskForCondition() const
750777
case CONDITION_STRING_ID:
751778
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_GAMEOBJECT;
752779
break;
780+
case CONDITION_GROUP_STATUS:
781+
mask |= GRID_MAP_TYPE_MASK_PLAYER;
782+
break;
753783
default:
754784
ABORT_MSG("Condition::GetSearcherTypeMaskForCondition - missing condition handling!");
755785
break;
@@ -2401,6 +2431,13 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const
24012431
return false;
24022432
}
24032433
break;
2434+
case CONDITION_GROUP_STATUS:
2435+
if (cond->ConditionValue1 > uint32(GroupStatusCondition::NotInGroupOrNotInRaid))
2436+
{
2437+
TC_LOG_ERROR("sql.sql", "{} has non invalid group status condition value1 ({}), skipped.", cond->ToString(true), cond->ConditionValue1);
2438+
return false;
2439+
}
2440+
break;
24042441
case CONDITION_IN_WATER:
24052442
case CONDITION_CHARMED:
24062443
case CONDITION_TAXI:

src/server/game/Conditions/ConditionMgr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ enum ConditionTypes
9595
CONDITION_PRIVATE_OBJECT = 57, // 0 0 0 true if entity is private object
9696
CONDITION_STRING_ID = 58,
9797
CONDITION_LABEL = 59, // only for master branch
98+
CONDITION_GROUP_STATUS = 60, // GroupStatus 0 0 true if player group status is (0 = not in group, 1 = in group, 2 = in group but not in raid, 3 = in raid group, 4 = not in group or not in raid)
9899
CONDITION_MAX
99100
};
100101

@@ -183,6 +184,15 @@ enum InstanceInfo
183184
INSTANCE_INFO_DATA64
184185
};
185186

187+
enum class GroupStatusCondition : uint32
188+
{
189+
NotInGroup = 0,
190+
InGroup = 1,
191+
InGroupButNotInRaid = 2,
192+
InRaid = 3,
193+
NotInGroupOrNotInRaid = 4
194+
};
195+
186196
enum MaxConditionTargets
187197
{
188198
MAX_CONDITION_TARGETS = 3

src/server/scripts/EasternKingdoms/zone_blasted_lands.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,39 @@
1717

1818
#include "ScriptMgr.h"
1919
#include "SpellScript.h"
20-
#include "Player.h"
21-
#include "Group.h"
20+
#include "Unit.h"
2221

2322
/*######
2423
## Quest 3628: You Are Rakh'likh, Demon
2524
######*/
2625

27-
enum TeleportToRazelikh
26+
enum YouAreRakhlikhDemon
2827
{
29-
SPELL_TELEPORT_SINGLE = 12885,
30-
SPELL_TELEPORT_SINGLE_IN_GROUP = 13142
28+
SPELL_TELEPORT_TO_RAZELIKH_GROUP = 27694
3129
};
3230

3331
// 27686 - Teleport to Razelikh (GROUP)
34-
class spell_razelikh_teleport_group : public SpellScript
32+
class spell_blasted_lands_teleport_to_razelikh_group : public SpellScript
3533
{
36-
PrepareSpellScript(spell_razelikh_teleport_group);
34+
PrepareSpellScript(spell_blasted_lands_teleport_to_razelikh_group);
3735

38-
bool Validate(SpellInfo const* /*spell*/) override
36+
bool Validate(SpellInfo const* /*spellInfo*/) override
3937
{
40-
return ValidateSpellInfo({ SPELL_TELEPORT_SINGLE, SPELL_TELEPORT_SINGLE_IN_GROUP });
38+
return ValidateSpellInfo({ SPELL_TELEPORT_TO_RAZELIKH_GROUP });
4139
}
4240

43-
void HandleScriptEffect(SpellEffIndex /* effIndex */)
41+
void HandleScript(SpellEffIndex /*effIndex*/)
4442
{
45-
if (Player* player = GetHitPlayer())
46-
{
47-
if (Group* group = player->GetGroup())
48-
{
49-
for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
50-
if (Player* member = itr->GetSource())
51-
if (member->IsWithinDistInMap(player, 20.0f) && !member->isDead())
52-
member->CastSpell(member, SPELL_TELEPORT_SINGLE_IN_GROUP, true);
53-
}
54-
else
55-
player->CastSpell(player, SPELL_TELEPORT_SINGLE, true);
56-
}
43+
GetHitUnit()->CastSpell(nullptr, SPELL_TELEPORT_TO_RAZELIKH_GROUP, true);
5744
}
5845

5946
void Register() override
6047
{
61-
OnEffectHitTarget += SpellEffectFn(spell_razelikh_teleport_group::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
48+
OnEffectHitTarget += SpellEffectFn(spell_blasted_lands_teleport_to_razelikh_group::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
6249
}
6350
};
6451

6552
void AddSC_blasted_lands()
6653
{
67-
RegisterSpellScript(spell_razelikh_teleport_group);
54+
RegisterSpellScript(spell_blasted_lands_teleport_to_razelikh_group);
6855
}

0 commit comments

Comments
 (0)