@@ -397,46 +397,6 @@ class mod_zone_difficulty_unitscript : public UnitScript
397
397
}
398
398
};
399
399
400
- class mod_zone_difficulty_playerscript : public PlayerScript
401
- {
402
- public:
403
- mod_zone_difficulty_playerscript () : PlayerScript(" mod_zone_difficulty_playerscript" ) { }
404
-
405
- void OnMapChanged (Player* player) override
406
- {
407
- uint32 mapId = player->GetMapId ();
408
- if (sZoneDifficulty ->DisallowedBuffs .find (mapId) != sZoneDifficulty ->DisallowedBuffs .end ())
409
- {
410
- for (auto aura : sZoneDifficulty ->DisallowedBuffs [mapId])
411
- {
412
- player->RemoveAura (aura);
413
- }
414
- }
415
- }
416
-
417
- void OnLogin (Player* player) override
418
- {
419
- if (sZoneDifficulty ->MythicmodeScore .empty ())
420
- return ;
421
-
422
- if (sZoneDifficulty ->MythicmodeScore .find (player->GetGUID ().GetCounter ()) != sZoneDifficulty ->MythicmodeScore .end ())
423
- {
424
- for (int i = 1 ; i <= 16 ; ++i)
425
- {
426
- uint32 availableScore = 0 ;
427
-
428
- if (sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()].find (i) != sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()].end ())
429
- availableScore = sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()][i];
430
-
431
- player->UpdatePlayerSetting (ModZoneDifficultyString + " score" , i, availableScore);
432
- }
433
-
434
- sZoneDifficulty ->MythicmodeScore .erase (player->GetGUID ().GetCounter ());
435
- CharacterDatabase.Execute (" DELETE FROM zone_difficulty_mythicmode_score WHERE GUID = {}" , player->GetGUID ().GetCounter ());
436
- }
437
- }
438
- };
439
-
440
400
class mod_zone_difficulty_petscript : public PetScript
441
401
{
442
402
public:
@@ -470,6 +430,7 @@ class mod_zone_difficulty_worldscript : public WorldScript
470
430
sZoneDifficulty ->MythicmodeHpModifier = sConfigMgr ->GetOption <float >(" ModZoneDifficulty.Mythicmode.HpModifier" , 2 );
471
431
sZoneDifficulty ->MythicmodeEnable = sConfigMgr ->GetOption <bool >(" ModZoneDifficulty.Mythicmode.Enable" , false );
472
432
sZoneDifficulty ->MythicmodeInNormalDungeons = sConfigMgr ->GetOption <bool >(" ModZoneDifficulty.Mythicmode.InNormalDungeons" , false );
433
+ sZoneDifficulty ->UseVendorInterface = sConfigMgr ->GetOption <bool >(" ModZoneDifficulty.UseVendorInterface" , false );
473
434
sZoneDifficulty ->LoadMapDifficultySettings ();
474
435
}
475
436
@@ -749,6 +710,12 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
749
710
}
750
711
// LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Building gossip with category {} and counter {}", category, counter);
751
712
713
+ if (sZoneDifficulty ->UseVendorInterface )
714
+ {
715
+ ShowItemsInFakeVendor (player, creature, category, counter);
716
+ return true ;
717
+ }
718
+
752
719
for (size_t i = 0 ; i < sZoneDifficulty ->Rewards [category][counter].size (); ++i)
753
720
{
754
721
// LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Adding gossip option for entry {}", sZoneDifficulty->Rewards[category][counter][i].Entry);
@@ -831,29 +798,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
831
798
counter = counter - 100 ;
832
799
}
833
800
834
- // Check (again) if the player has enough score in the respective category.
835
- uint32 availableScore = player->GetPlayerSetting (ModZoneDifficultyString + " score" , category).value ;
836
-
837
- if (availableScore < sZoneDifficulty ->Rewards [category][itemType][counter].Price )
838
- return true ;
839
-
840
- // Check if the player has the neccesary achievement
841
- if (sZoneDifficulty ->Rewards [category][itemType][counter].Achievement )
842
- {
843
- if (!player->HasAchieved (sZoneDifficulty ->Rewards [category][itemType][counter].Achievement ))
844
- {
845
- std::string gossip = " You do not have the required achievement with ID " ;
846
- gossip.append (std::to_string (sZoneDifficulty ->Rewards [category][itemType][counter].Achievement ));
847
- gossip.append (" to receive this item. Before i can give it to you, you need to complete the whole dungeon where it can be obtained." );
848
- creature->Whisper (gossip, LANG_UNIVERSAL, player);
849
- CloseGossipMenuFor (player);
850
- return true ;
851
- }
852
- }
853
-
854
- // LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Sending item with category {}, itemType {}, counter {}", category, itemType, counter);
855
- sZoneDifficulty ->DeductMythicmodeScore (player, category, sZoneDifficulty ->Rewards [category][itemType][counter].Price );
856
- sZoneDifficulty ->SendItem (player, category, itemType, counter);
801
+ sZoneDifficulty ->RewardItem (player, category, itemType, counter, creature, 0 );
857
802
}
858
803
859
804
SendGossipMenuFor (player, npcText, creature);
@@ -878,6 +823,53 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
878
823
SendGossipMenuFor (player, npcText, creature);
879
824
return true ;
880
825
}
826
+
827
+ static void ShowItemsInFakeVendor (Player* player, Creature* creature, uint8 category, uint8 slot)
828
+ {
829
+ auto const & itemList = sZoneDifficulty ->Rewards [category][slot];
830
+
831
+ uint32 itemCount = itemList.size ();
832
+
833
+ WorldPacket data (SMSG_LIST_INVENTORY, 8 + 1 + itemCount * 8 * 4 );
834
+ data << uint64 (creature->GetGUID ().GetRawValue ());
835
+
836
+ uint8 count = 0 ;
837
+ size_t count_pos = data.wpos ();
838
+ data << uint8 (count);
839
+
840
+ for (uint32 i = 0 ; i < itemCount && count < MAX_VENDOR_ITEMS; ++i)
841
+ {;
842
+ EncodeItemToPacket (
843
+ data, sObjectMgr ->GetItemTemplate (itemList[i].Entry ), count,
844
+ itemList[i].Price );
845
+ }
846
+
847
+ for (uint32 i = 0 ; i < itemCount && count < MAX_VENDOR_ITEMS; ++i)
848
+ {
849
+ if (ItemTemplate const * _proto = sObjectMgr ->GetItemTemplate (itemList[i].Entry ))
850
+ EncodeItemToPacket (data, _proto, count, itemList[i].Price );
851
+ }
852
+
853
+ data.put (count_pos, count);
854
+ player->GetSession ()->SendPacket (&data);
855
+ VendorSelectionData vendorData;
856
+ vendorData.category = category;
857
+ vendorData.slot = slot;
858
+ sZoneDifficulty ->SelectionCache [player->GetGUID ()] = vendorData;
859
+ }
860
+
861
+ static void EncodeItemToPacket (WorldPacket& data, ItemTemplate const * proto, uint8& slot, uint32 price)
862
+ {
863
+ data << uint32 (slot + 1 );
864
+ data << uint32 (proto->ItemId );
865
+ data << uint32 (proto->DisplayInfoID );
866
+ data << int32 (-1 ); // Infinite Stock
867
+ data << uint32 (price);
868
+ data << uint32 (proto->MaxDurability );
869
+ data << uint32 (1 ); // Buy Count of 1
870
+ data << uint32 (0 );
871
+ slot++;
872
+ }
881
873
};
882
874
883
875
class mod_zone_difficulty_dungeonmaster : public CreatureScript
@@ -1152,15 +1144,75 @@ class mod_zone_difficulty_allcreaturescript : public AllCreatureScript
1152
1144
}
1153
1145
};
1154
1146
1147
+ class mod_zone_difficulty_playerscript : public PlayerScript
1148
+ {
1149
+ public:
1150
+ mod_zone_difficulty_playerscript () : PlayerScript(" mod_zone_difficulty_playerscript" ) { }
1151
+
1152
+ void OnMapChanged (Player* player) override
1153
+ {
1154
+ uint32 mapId = player->GetMapId ();
1155
+ if (sZoneDifficulty ->DisallowedBuffs .find (mapId) != sZoneDifficulty ->DisallowedBuffs .end ())
1156
+ {
1157
+ for (auto aura : sZoneDifficulty ->DisallowedBuffs [mapId])
1158
+ {
1159
+ player->RemoveAura (aura);
1160
+ }
1161
+ }
1162
+ }
1163
+
1164
+ void OnLogin (Player* player) override
1165
+ {
1166
+ if (sZoneDifficulty ->MythicmodeScore .empty ())
1167
+ return ;
1168
+
1169
+ if (sZoneDifficulty ->MythicmodeScore .find (player->GetGUID ().GetCounter ()) != sZoneDifficulty ->MythicmodeScore .end ())
1170
+ {
1171
+ for (int i = 1 ; i <= 16 ; ++i)
1172
+ {
1173
+ uint32 availableScore = 0 ;
1174
+
1175
+ if (sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()].find (i) != sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()].end ())
1176
+ availableScore = sZoneDifficulty ->MythicmodeScore [player->GetGUID ().GetCounter ()][i];
1177
+
1178
+ player->UpdatePlayerSetting (ModZoneDifficultyString + " score" , i, availableScore);
1179
+ }
1180
+
1181
+ sZoneDifficulty ->MythicmodeScore .erase (player->GetGUID ().GetCounter ());
1182
+ CharacterDatabase.Execute (" DELETE FROM zone_difficulty_mythicmode_score WHERE GUID = {}" , player->GetGUID ().GetCounter ());
1183
+ }
1184
+ }
1185
+
1186
+ void OnLogout (Player* player) override
1187
+ {
1188
+ sZoneDifficulty ->SelectionCache .erase (player->GetGUID ());
1189
+ }
1190
+
1191
+ void OnBeforeBuyItemFromVendor (Player* player, ObjectGuid vendorguid, uint32 vendorslot, uint32& itemEntry, uint8 /* count*/ , uint8 /* bag*/ , uint8 /* slot*/ ) override
1192
+ {
1193
+ Creature* vendor = player->GetMap ()->GetCreature (vendorguid);
1194
+
1195
+ if (!vendor)
1196
+ return ;
1197
+ if (vendor->GetEntry () != NPC_REWARD_CHROMIE)
1198
+ return ;
1199
+
1200
+ auto const & data = sZoneDifficulty ->SelectionCache [player->GetGUID ()];
1201
+
1202
+ sZoneDifficulty ->RewardItem (player, data.category , data.slot , 0 , vendor, itemEntry);
1203
+ itemEntry = 0 ; // Prevents the handler from proceeding to core vendor handling
1204
+ }
1205
+ };
1206
+
1155
1207
// Add all scripts in one
1156
1208
void AddModZoneDifficultyScripts ()
1157
1209
{
1158
1210
new mod_zone_difficulty_unitscript ();
1159
- new mod_zone_difficulty_playerscript ();
1160
1211
new mod_zone_difficulty_petscript ();
1161
1212
new mod_zone_difficulty_worldscript ();
1162
1213
new mod_zone_difficulty_globalscript ();
1163
1214
new mod_zone_difficulty_rewardnpc ();
1164
1215
new mod_zone_difficulty_dungeonmaster ();
1165
1216
new mod_zone_difficulty_allcreaturescript ();
1217
+ new mod_zone_difficulty_playerscript ();
1166
1218
}
0 commit comments