From 826019f88971d54b84139dc932551264c128f573 Mon Sep 17 00:00:00 2001 From: Mini Date: Mon, 29 Jan 2007 20:47:35 +0000 Subject: [PATCH] Added a Player and PlayerSettings class. Added castspell to defscript. --- src/Client/DefScript/DefScript.cpp | 1 + src/Client/DefScript/DefScript.h | 1 + src/Client/DefScriptInterface.cpp | 30 +++++++++++++ src/Client/World/Player.cpp | 71 ++++++++++++++++++++++++++++++ src/Client/World/Player.h | 47 +++++++++++++++++++- src/Client/World/WorldSession.cpp | 21 ++++++--- src/Client/World/WorldSession.h | 6 ++- 7 files changed, 168 insertions(+), 9 deletions(-) diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index 8bac42e..0b96998 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -73,6 +73,7 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const {"log",&DefScriptPackage::SClog}, {"logdetail",&DefScriptPackage::SClogdetail}, {"logdebug",&DefScriptPackage::SClogdebug}, + {"castspell", &DefScriptPackage::SCcastspell}, // table termination {NULL,NULL} diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index 523c85d..93c54d4 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -154,6 +154,7 @@ private: bool SClog(CmdSet); bool SClogdetail(CmdSet); bool SClogdebug(CmdSet); + bool SCcastspell(CmdSet); // Own variable declarations std::map my_usrPermissionMap; diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 1dc5394..69c27c8 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -155,6 +155,36 @@ bool DefScriptPackage::SClogdebug(CmdSet Set){ return true; } +bool DefScriptPackage::SCcastspell(CmdSet Set) +{ + if(Set.defaultarg.empty()) + return true; + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + log("Invalid Script call: SCcastspell: WorldSession not valid"); + return false; + } + + uint32 spellId = 0;// = atoi(Set.defaultarg.c_str()); + uint64 spellTarget = 0;// atoi(Set.arg[0]); + + spellId = atoi(Set.defaultarg.c_str()); + + if (spellId <= 0) + { + log("Invalid Script call: SCcastspell: SpellId not valid"); + return false; + } + + if (spellTarget <= 0) + { + spellTarget = ((PseuInstance*)parentMethod)->GetWSession()->GetGuid(); + } + + ((PseuInstance*)parentMethod)->GetWSession()->GetPlayerSettings()->CastSpell(spellId, spellTarget); + return true; +} + void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) { static char *prefix = "USERS::"; diff --git a/src/Client/World/Player.cpp b/src/Client/World/Player.cpp index 0ccbc1a..655aa34 100644 --- a/src/Client/World/Player.cpp +++ b/src/Client/World/Player.cpp @@ -7,6 +7,7 @@ #include "Player.h" #include "NameTables.h" #include "DefScript/DefScript.h" +#include "WorldSession.h" bool PlayerNameCache::AddInfo(uint64 guid, std::string name){ PlayerNameCacheItem *cacheItem=new PlayerNameCacheItem; @@ -113,3 +114,73 @@ bool PlayerNameCache::ReadFromFile(void){ uint32 PlayerNameCache::GetSize(void){ return _cache.size(); } + +void Player::Init(PlayerEnum player) +{ + this->player = player; +} + +void PlayerSettings::SetActionButtons(WorldPacket &data) +{ + if (!init) + return; + + // TODO: Implent this +} + +void PlayerSettings::SetSpells(WorldPacket &data) +{ + if (!init) + return; + + uint8 unk; + uint16 numSpells; + + data >> unk >> numSpells; + + logdetail("Got %d spells", numSpells); + + // TODO: Finish implenting this +} + +void PlayerSettings::CastSpell(uint32 spellId, uint64 target) +{ + if (castingSpell || !init) + return; + + castingSpell = !castingSpell; + + WorldPacket packet; + packet.SetOpcode(CMSG_CAST_SPELL); + packet << spellId << (uint16)2 /* TARGET_FLAG_UNIT */ << (uint8)1 /* guid stuff */ << (uint8)target; + // Can be bugged, not fully tested, probably doesn't work when the guid is high + // Damn packed guid stuff! xD + + _worldSession->SendWorldPacket(packet); +} + +void PlayerSettings::HandleCastResultOpcode(WorldPacket &packet) +{ + if (!init) + return; + + uint32 spellId; + uint8 statusFail; + uint8 failProblem; + char l[150]; + + packet >> spellId >> statusFail; + + castingSpell = false; + + sprintf(l, "Received cast result opcode. Spell = %d, statusFail = %d", spellId, statusFail); + + if (statusFail == 2) // Spell cast failed + { + packet >> failProblem; + sprintf(l, "%s, failProblem = %d", l, failProblem); + } + + + //logdetail(l); +} \ No newline at end of file diff --git a/src/Client/World/Player.h b/src/Client/World/Player.h index b03052f..7391baa 100644 --- a/src/Client/World/Player.h +++ b/src/Client/World/Player.h @@ -2,6 +2,14 @@ #define _PLAYER_H #include +#include "WorldPacket.h" +#include "SysDefs.h" + +struct PlayerItem +{ + uint32 itemID; + uint8 inventorytype; +}; struct PlayerNameCacheItem { uint64 _guid; @@ -44,12 +52,49 @@ public: uint32 _petInfoId; uint32 _petLevel; uint32 _petFamilyId; -// more to come...[items] + PlayerItem _items[20]; private: }; + +class Player +{ +public: + void Init(PlayerEnum player); + +private: + int hp; + int bar; // Mana/Energy/Rage + PlayerEnum player; +}; + +class PlayerSettings +{ +public: + PlayerSettings() + { + castingSpell = false; + init = false; + } + + void Init(WorldSession *worldSession) + { + _worldSession = worldSession; + } + + void SetActionButtons(WorldPacket &data); + void SetSpells(WorldPacket &data); + void CastSpell(uint32 spellId, uint64 target); + void HandleCastResultOpcode(WorldPacket &packet); + +private: + bool castingSpell; + WorldSession *_worldSession; + bool init; +}; + /* class PlayerCache { public: diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 430f313..32233d3 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -24,6 +24,7 @@ WorldSession::WorldSession(PseuInstance *in) plrNameCache.ReadFromFile(); // load names/guids of known players _deleteme = false; _channels = new Channel(this); + _playerSettings->Init(this); //... } @@ -111,7 +112,7 @@ void WorldSession::Update(void) || ((!known) && GetInstance()->GetConf()->showopcodes==2) || (GetInstance()->GetConf()->showopcodes==3) ) { - log(">> Opcode %u [%s]",packet->GetOpcode(),LookupName(packet->GetOpcode(),g_worldOpcodeNames)); + log(">> Opcode %u - %s - [%s]", packet->GetOpcode(), known ? "Known" : "UNKNOWN", LookupName(packet->GetOpcode(),g_worldOpcodeNames)); } @@ -159,6 +160,8 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const {MSG_MOVE_TELEPORT_ACK, &WorldSession::_HandleTelePortAckOpcode}, + {SMSG_CAST_RESULT, &WorldSession::_HandleCastResultOpcode}, + // table termination { 0, NULL } }; @@ -271,7 +274,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) uint8 num; PlayerEnum plr[10]; // max characters per realm is 10 uint8 dummy8; - uint32 dummy32; + //uint32 dummy32; // Unused recvPacket >> num; if(num==0){ @@ -305,7 +308,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) recvPacket >> plr[i]._petLevel; recvPacket >> plr[i]._petFamilyId; for(unsigned int inv=0;inv<20;inv++){ - recvPacket >> dummy32 >> dummy8; // item data are not relevant yet ( (uint32)itemID , (uint8)inventorytype ) + recvPacket >> plr[i]._items[inv].itemID >> plr[i]._items[inv].inventorytype; // item data are not relevant yet ( (uint32)itemID , (uint8)inventorytype ) } plrNameCache.AddInfo(plr[i]._guid, plr[i]._name); } @@ -330,7 +333,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) return; } else { log("Entering World with Character \"%s\"...",GetInstance()->GetConf()->charname.c_str()); - _player = plr[i]; + _player->Init(plr[i]); WorldPacket pkt; pkt.SetOpcode(CMSG_PLAYER_LOGIN); @@ -536,7 +539,6 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket) logdetail("DEBUG: Got teleport, data: x: %f, y: %f, z: %f, o: %f, guid: %d\n", x, y, z, o, guid); - // TODO: Still bugs with animation WorldPacket response; response.SetOpcode(MSG_MOVE_FALL_LAND); response << uint32(0) << uint32(0) << x << y << z << o << uint32(0); @@ -545,5 +547,10 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket) void WorldSession::_HandleChannelNotifyOpcode(WorldPacket& recvPacket) { - _channels->HandleNotifyOpcode(recvPacket); -} \ No newline at end of file + _channels->HandleNotifyOpcode(recvPacket); +} + +void WorldSession::_HandleCastResultOpcode(WorldPacket& recvPacket) +{ + _playerSettings->HandleCastResultOpcode(recvPacket); +} diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index 13b1738..c362d33 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -47,6 +47,8 @@ public: uint64 GetFollowTarget(void) { return _followGUID; } uint64 GetGuid(void) { return _myGUID; } Channel *GetChannels(void) { return _channels; } + Player *GetPlayer(void) { return _player; } + PlayerSettings *GetPlayerSettings(void) { return _playerSettings; } // CMSGConstructor @@ -78,9 +80,11 @@ private: void _HandleGroupInviteOpcode(WorldPacket& recvPacket); void _HandleTelePortAckOpcode(WorldPacket& recvPacket); void _HandleChannelNotifyOpcode(WorldPacket& recvPacket); + void _HandleCastResultOpcode(WorldPacket& recvPacket); - PlayerEnum _player; // The connected character + Player *_player; // The connected character + PlayerSettings *_playerSettings; // Settings for the connected character PseuInstance *_instance; WorldSocket *_socket;