Added a Player and PlayerSettings class.

Added castspell to defscript.
This commit is contained in:
Mini 2007-01-29 20:47:35 +00:00
parent ed8bddb17a
commit 826019f889
7 changed files with 168 additions and 9 deletions

View File

@ -73,6 +73,7 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
{"log",&DefScriptPackage::SClog}, {"log",&DefScriptPackage::SClog},
{"logdetail",&DefScriptPackage::SClogdetail}, {"logdetail",&DefScriptPackage::SClogdetail},
{"logdebug",&DefScriptPackage::SClogdebug}, {"logdebug",&DefScriptPackage::SClogdebug},
{"castspell", &DefScriptPackage::SCcastspell},
// table termination // table termination
{NULL,NULL} {NULL,NULL}

View File

@ -154,6 +154,7 @@ private:
bool SClog(CmdSet); bool SClog(CmdSet);
bool SClogdetail(CmdSet); bool SClogdetail(CmdSet);
bool SClogdebug(CmdSet); bool SClogdebug(CmdSet);
bool SCcastspell(CmdSet);
// Own variable declarations // Own variable declarations
std::map<std::string, unsigned char> my_usrPermissionMap; std::map<std::string, unsigned char> my_usrPermissionMap;

View File

@ -155,6 +155,36 @@ bool DefScriptPackage::SClogdebug(CmdSet Set){
return true; 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) void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
{ {
static char *prefix = "USERS::"; static char *prefix = "USERS::";

View File

@ -7,6 +7,7 @@
#include "Player.h" #include "Player.h"
#include "NameTables.h" #include "NameTables.h"
#include "DefScript/DefScript.h" #include "DefScript/DefScript.h"
#include "WorldSession.h"
bool PlayerNameCache::AddInfo(uint64 guid, std::string name){ bool PlayerNameCache::AddInfo(uint64 guid, std::string name){
PlayerNameCacheItem *cacheItem=new PlayerNameCacheItem; PlayerNameCacheItem *cacheItem=new PlayerNameCacheItem;
@ -113,3 +114,73 @@ bool PlayerNameCache::ReadFromFile(void){
uint32 PlayerNameCache::GetSize(void){ uint32 PlayerNameCache::GetSize(void){
return _cache.size(); 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);
}

View File

@ -2,6 +2,14 @@
#define _PLAYER_H #define _PLAYER_H
#include <vector> #include <vector>
#include "WorldPacket.h"
#include "SysDefs.h"
struct PlayerItem
{
uint32 itemID;
uint8 inventorytype;
};
struct PlayerNameCacheItem { struct PlayerNameCacheItem {
uint64 _guid; uint64 _guid;
@ -44,12 +52,49 @@ public:
uint32 _petInfoId; uint32 _petInfoId;
uint32 _petLevel; uint32 _petLevel;
uint32 _petFamilyId; uint32 _petFamilyId;
// more to come...[items] PlayerItem _items[20];
private: 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 { class PlayerCache {
public: public:

View File

@ -24,6 +24,7 @@ WorldSession::WorldSession(PseuInstance *in)
plrNameCache.ReadFromFile(); // load names/guids of known players plrNameCache.ReadFromFile(); // load names/guids of known players
_deleteme = false; _deleteme = false;
_channels = new Channel(this); _channels = new Channel(this);
_playerSettings->Init(this);
//... //...
} }
@ -111,7 +112,7 @@ void WorldSession::Update(void)
|| ((!known) && GetInstance()->GetConf()->showopcodes==2) || ((!known) && GetInstance()->GetConf()->showopcodes==2)
|| (GetInstance()->GetConf()->showopcodes==3) ) || (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}, {MSG_MOVE_TELEPORT_ACK, &WorldSession::_HandleTelePortAckOpcode},
{SMSG_CAST_RESULT, &WorldSession::_HandleCastResultOpcode},
// table termination // table termination
{ 0, NULL } { 0, NULL }
}; };
@ -271,7 +274,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
uint8 num; uint8 num;
PlayerEnum plr[10]; // max characters per realm is 10 PlayerEnum plr[10]; // max characters per realm is 10
uint8 dummy8; uint8 dummy8;
uint32 dummy32; //uint32 dummy32; // Unused
recvPacket >> num; recvPacket >> num;
if(num==0){ if(num==0){
@ -305,7 +308,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
recvPacket >> plr[i]._petLevel; recvPacket >> plr[i]._petLevel;
recvPacket >> plr[i]._petFamilyId; recvPacket >> plr[i]._petFamilyId;
for(unsigned int inv=0;inv<20;inv++){ 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); plrNameCache.AddInfo(plr[i]._guid, plr[i]._name);
} }
@ -330,7 +333,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
return; return;
} else { } else {
log("Entering World with Character \"%s\"...",GetInstance()->GetConf()->charname.c_str()); log("Entering World with Character \"%s\"...",GetInstance()->GetConf()->charname.c_str());
_player = plr[i]; _player->Init(plr[i]);
WorldPacket pkt; WorldPacket pkt;
pkt.SetOpcode(CMSG_PLAYER_LOGIN); 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); 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; WorldPacket response;
response.SetOpcode(MSG_MOVE_FALL_LAND); response.SetOpcode(MSG_MOVE_FALL_LAND);
response << uint32(0) << uint32(0) << x << y << z << o << uint32(0); response << uint32(0) << uint32(0) << x << y << z << o << uint32(0);
@ -547,3 +549,8 @@ void WorldSession::_HandleChannelNotifyOpcode(WorldPacket& recvPacket)
{ {
_channels->HandleNotifyOpcode(recvPacket); _channels->HandleNotifyOpcode(recvPacket);
} }
void WorldSession::_HandleCastResultOpcode(WorldPacket& recvPacket)
{
_playerSettings->HandleCastResultOpcode(recvPacket);
}

View File

@ -47,6 +47,8 @@ public:
uint64 GetFollowTarget(void) { return _followGUID; } uint64 GetFollowTarget(void) { return _followGUID; }
uint64 GetGuid(void) { return _myGUID; } uint64 GetGuid(void) { return _myGUID; }
Channel *GetChannels(void) { return _channels; } Channel *GetChannels(void) { return _channels; }
Player *GetPlayer(void) { return _player; }
PlayerSettings *GetPlayerSettings(void) { return _playerSettings; }
// CMSGConstructor // CMSGConstructor
@ -78,9 +80,11 @@ private:
void _HandleGroupInviteOpcode(WorldPacket& recvPacket); void _HandleGroupInviteOpcode(WorldPacket& recvPacket);
void _HandleTelePortAckOpcode(WorldPacket& recvPacket); void _HandleTelePortAckOpcode(WorldPacket& recvPacket);
void _HandleChannelNotifyOpcode(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; PseuInstance *_instance;
WorldSocket *_socket; WorldSocket *_socket;