From 6df34baf6ab78b4ce8f62cb02e9616c129bcb374 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Tue, 27 Feb 2007 19:04:17 +0000 Subject: [PATCH] * implemented basic targeting. new DefScript command: "target ". works only on players for now, and name must be exact. --- src/Client/DefScript/DefScript.cpp | 1 + src/Client/DefScript/DefScript.h | 1 + src/Client/DefScriptInterface.cpp | 30 ++++++++++++++++++++++++++++ src/Client/World/CMSGConstructor.cpp | 9 +++++++++ src/Client/World/WorldSession.h | 1 + 5 files changed, 42 insertions(+) diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index 74bfb40..8c6a154 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -79,6 +79,7 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const {"logdebug",&DefScriptPackage::SClogdebug}, {"castspell", &DefScriptPackage::SCcastspell}, {"queryitem", &DefScriptPackage::SCqueryitem}, + {"target", &DefScriptPackage::SCtarget}, // table termination {NULL,NULL} diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index bfa9811..d7ea620 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -162,6 +162,7 @@ private: bool SClogerror(CmdSet); bool SCcastspell(CmdSet); bool SCqueryitem(CmdSet); + bool SCtarget(CmdSet); // Own variable declarations std::map my_usrPermissionMap; diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index d99e728..b91c287 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -8,6 +8,7 @@ #include "SharedDefines.h" #include "WorldSession.h" #include "Channel.h" +#include "CacheHandler.h" bool DefScriptPackage::SCshdn(CmdSet Set) { @@ -208,6 +209,35 @@ bool DefScriptPackage::SCqueryitem(CmdSet Set){ return true; } +bool DefScriptPackage::SCtarget(CmdSet Set) +{ + // TODO: special targets: _self _pet _nearest ... + + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + logerror("Invalid Script call: SCtarget: WorldSession not valid"); + return false; + } + + if(Set.defaultarg.empty()) + { + ((PseuInstance*)parentMethod)->GetWSession()->SendSetSelection(0); // no target + return true; + } + + // TODO: search through all objects. for now only allow to target player + uint64 guid = (((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetGuid(Set.defaultarg)); + + if( guid && ((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetObj(guid) ) // object must be near + ((PseuInstance*)parentMethod)->GetWSession()->SendSetSelection(guid); + else + logdetail("Target '%s' not found!",Set.defaultarg.c_str()); + + return true; +} + + + void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) { static char *prefix = "USERS::"; diff --git a/src/Client/World/CMSGConstructor.cpp b/src/Client/World/CMSGConstructor.cpp index a955d2b..6606de9 100644 --- a/src/Client/World/CMSGConstructor.cpp +++ b/src/Client/World/CMSGConstructor.cpp @@ -77,6 +77,15 @@ void WorldSession::SendQueryItem(uint32 id, uint64 guid) // is it a guid? not su // to prevent opcode spam, we need to make a list with already requested items } +void WorldSession::SendSetSelection(uint64 guid) +{ + // TODO: MyCharacter.SetTarget(guid); + logdebug("SetSelection GUID="I64FMT,guid); + WorldPacket packet; + packet << guid; + packet.SetOpcode(CMSG_SET_SELECTION); + SendWorldPacket(packet); +} diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index f1b0344..0d5ca81 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -60,6 +60,7 @@ public: void SendPing(uint32); void SendEmote(uint32); void SendQueryItem(uint32, uint64); + void SendSetSelection(uint64); PlayerNameCache plrNameCache; ObjMgr objmgr;