@@ -594,6 +594,7 @@ class script_bot_commands : public CommandScript
594
594
static ChatCommandTable npcbotOrderCommandTable =
595
595
{
596
596
{ " cast" , HandleNpcBotOrderCastCommand, rbac::RBAC_PERM_COMMAND_NPCBOT_ORDER_CAST, Console::No },
597
+ { " pull" , HandleNpcBotOrderPullCommand, rbac::RBAC_PERM_COMMAND_NPCBOT_ORDER_CAST, Console::No },
597
598
};
598
599
599
600
static ChatCommandTable npcbotVehicleCommandTable =
@@ -1728,6 +1729,155 @@ class script_bot_commands : public CommandScript
1728
1729
return true ;
1729
1730
}
1730
1731
1732
+ static bool HandleNpcBotOrderPullCommand (ChatHandler* handler, Optional<std::string> bot_name, Optional<std::string_view> target_token)
1733
+ {
1734
+ Player* owner = handler->GetSession ()->GetPlayer ();
1735
+ if (!owner->HaveBot () || !bot_name)
1736
+ {
1737
+ handler->SendSysMessage (" .npcbot order pull #bot_name #[target_token]" );
1738
+ handler->SendSysMessage (" Orders bot to pull target immediately" );
1739
+ return true ;
1740
+ }
1741
+
1742
+ if (owner->GetBotMgr ()->IsPartyInCombat ())
1743
+ {
1744
+ handler->SendSysMessage (" Can't do that while in combat!" );
1745
+ return true ;
1746
+ }
1747
+
1748
+ for (std::decay_t <decltype (*bot_name)>::size_type i = 0u ; i < bot_name->size (); ++i)
1749
+ if ((*bot_name)[i] == ' _' )
1750
+ (*bot_name)[i] = ' ' ;
1751
+
1752
+ Creature* bot = owner->GetBotMgr ()->GetBotByName (*bot_name);
1753
+ if (bot)
1754
+ {
1755
+ if (!bot->IsInWorld ())
1756
+ {
1757
+ handler->PSendSysMessage (" Bot {} is not found!" , *bot_name);
1758
+ return true ;
1759
+ }
1760
+ if (!bot->IsAlive ())
1761
+ {
1762
+ handler->PSendSysMessage (" {} is dead!" , bot->GetName ());
1763
+ return true ;
1764
+ }
1765
+ if (!bot->GetBotAI ()->HasRole (BOT_ROLE_DPS) || bot->GetVictim () || bot->IsInCombat () || !bot->getAttackers ().empty ())
1766
+ {
1767
+ handler->PSendSysMessage (" {} cannot pull target! Must be idle and have DPS role" , bot->GetName ());
1768
+ return true ;
1769
+ }
1770
+ }
1771
+ else
1772
+ {
1773
+ auto const & class_name = *bot_name;
1774
+ for (auto const c : class_name)
1775
+ {
1776
+ if (!std::islower (c))
1777
+ {
1778
+ handler->SendSysMessage (" Bot class name must be in lower case!" );
1779
+ return true ;
1780
+ }
1781
+ }
1782
+
1783
+ uint8 bot_class = BotMgr::BotClassByClassName (class_name);
1784
+ if (bot_class == BOT_CLASS_NONE)
1785
+ {
1786
+ handler->PSendSysMessage (" Unknown bot name or class {}!" , class_name);
1787
+ return true ;
1788
+ }
1789
+
1790
+ std::list<Creature*> cBots = owner->GetBotMgr ()->GetAllBotsByClass (bot_class);
1791
+
1792
+ if (cBots.empty ())
1793
+ {
1794
+ handler->PSendSysMessage (" No bots of class {} found!" , bot_class);
1795
+ return true ;
1796
+ }
1797
+
1798
+ bot = cBots.size () == 1 ? cBots.front () : Acore::Containers::SelectRandomContainerElement (cBots);
1799
+
1800
+ if (!bot)
1801
+ {
1802
+ handler->SendSysMessage (" None of {} found bots can use pull yet!" , cBots.size ());
1803
+ return true ;
1804
+ }
1805
+ }
1806
+
1807
+ ObjectGuid target_guid = ObjectGuid::Empty;
1808
+ bool token_valid = true ;
1809
+ if (!target_token || target_token == " mytarget" )
1810
+ target_guid = owner->GetTarget ();
1811
+ else if (Group const * group = owner->GetGroup ())
1812
+ {
1813
+ if (target_token == " star" )
1814
+ target_guid = group->GetTargetIcons ()[0 ];
1815
+ else if (target_token == " circle" )
1816
+ target_guid = group->GetTargetIcons ()[1 ];
1817
+ else if (target_token == " diamond" )
1818
+ target_guid = group->GetTargetIcons ()[2 ];
1819
+ else if (target_token == " triangle" )
1820
+ target_guid = group->GetTargetIcons ()[3 ];
1821
+ else if (target_token == " moon" )
1822
+ target_guid = group->GetTargetIcons ()[4 ];
1823
+ else if (target_token == " square" )
1824
+ target_guid = group->GetTargetIcons ()[5 ];
1825
+ else if (target_token == " cross" )
1826
+ target_guid = group->GetTargetIcons ()[6 ];
1827
+ else if (target_token == " skull" )
1828
+ target_guid = group->GetTargetIcons ()[7 ];
1829
+ else if (target_token->size () == 1u && std::isdigit (target_token->front ()))
1830
+ {
1831
+ uint8 digit = static_cast <uint8>(std::stoi (std::string (*target_token)));
1832
+ switch (digit)
1833
+ {
1834
+ case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : case 8 :
1835
+ target_guid = group->GetTargetIcons ()[digit - 1 ];
1836
+ break ;
1837
+ default :
1838
+ token_valid = false ;
1839
+ break ;
1840
+ }
1841
+ }
1842
+ else
1843
+ token_valid = false ;
1844
+ }
1845
+ else
1846
+ token_valid = false ;
1847
+
1848
+ if (!token_valid)
1849
+ {
1850
+ handler->PSendSysMessage (" Invalid target token '{}'!" , *target_token);
1851
+ handler->SendSysMessage (" Valid target tokens:\n '','mytarget', "
1852
+ " 'star','1', 'circle','2', 'diamond','3', 'triangle','4', 'moon','5', 'square','6', 'cross','7', 'skull','8'"
1853
+ " \n Note that target icons tokens are only available while in group" );
1854
+ return true ;
1855
+ }
1856
+
1857
+ Unit* target = target_guid ? ObjectAccessor::GetUnit (*owner, target_guid) : nullptr ;
1858
+ if (!target || !bot->FindMap () || target->FindMap () != bot->FindMap ())
1859
+ {
1860
+ handler->PSendSysMessage (" Invalid target '{}'!" , target ? target->GetName ().c_str () : " unknown" );
1861
+ return true ;
1862
+ }
1863
+
1864
+ bot_ai::BotOrder order (BOT_ORDER_PULL);
1865
+ order.params .pullParams .targetGuid = target_guid.GetRawValue ();
1866
+
1867
+ if (bot->GetBotAI ()->AddOrder (std::move (order)))
1868
+ {
1869
+ if (DEBUG_BOT_ORDERS)
1870
+ handler->PSendSysMessage (" Order given: {}: pull {}" , bot->GetName (), target ? target->GetName ().c_str () : " unknown" );
1871
+ }
1872
+ else
1873
+ {
1874
+ if (DEBUG_BOT_ORDERS)
1875
+ handler->PSendSysMessage (" Order failed: {}: pull {}" , bot->GetName (), target ? target->GetName ().c_str () : " unknown" );
1876
+ }
1877
+
1878
+ return true ;
1879
+ }
1880
+
1731
1881
static bool HandleNpcBotOrderCastCommand (ChatHandler* handler, Optional<std::string> bot_name, Optional<std::string> spell_name, Optional<std::string_view> target_token)
1732
1882
{
1733
1883
Player* owner = handler->GetSession ()->GetPlayer ();
0 commit comments