Characters Class API

Added some new functions
pull/58/head
Koncord 8 years ago
parent 3405e36ce4
commit 11eae277a9

@ -51,7 +51,7 @@ set(SERVER
Script/Script.cpp Script/ScriptFunction.cpp
Script/ScriptFunctions.cpp
Script/Functions/Translocations.cpp Script/Functions/Stats.cpp Script/Functions/Items.cpp
Script/Functions/Timer.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp
Script/Functions/Timer.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp Script/Functions/CharClass.cpp Script/Functions/CharClass.hpp
Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp
${PawnScript_Sources}
${LuaScript_Sources}

@ -316,6 +316,13 @@ void Networking::Update(RakNet::Packet *packet)
break;
}
case ID_GAME_CHARCLASS:
{
DEBUG_PRINTF("ID_GAME_CHARCLASS\n");
myPacket->Read(player);
break;
}
default:
printf("Message with identifier %i has arrived.\n", packet->data[0]);
break;

@ -0,0 +1,134 @@
//
// Created by koncord on 29.08.16.
//
#include "CharClass.hpp"
#include <apps/openmw-mp/Networking.hpp>
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace std;
using namespace ESM;
void CharClassFunctions::SendClass(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CHARCLASS)->Send(player, false);
}
void CharClassFunctions::SetDefaultClass(unsigned short pid, const char *id) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->klass.mId = id;
}
void CharClassFunctions::SetClassName(unsigned short pid, const char *name) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->klass.mName = name;
player->klass.mId = "";
}
void CharClassFunctions::SetClassDesc(unsigned short pid, const char *desc) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->klass.mDescription = desc;
}
void CharClassFunctions::SetClassMajorAttribute(unsigned short pid, unsigned char slot, int attrId) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if(slot > 1)
throw invalid_argument("Incorrect attribute slot id");
player->klass.mData.mAttribute[slot] = attrId;
}
void CharClassFunctions::SetClassSpecialization(unsigned short pid, int spec) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->klass.mData.mSpecialization = spec;
}
void CharClassFunctions::SetClassMajorSkill(unsigned short pid, unsigned char slot, int skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if(slot > 4)
throw invalid_argument("Incorrect skill slot id");
player->klass.mData.mSkills[slot][1] = skillId;
}
void CharClassFunctions::SetClassMinorSkill(unsigned short pid, unsigned char slot, int skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if(slot > 4)
throw invalid_argument("Incorrect skill slot id");
player->klass.mData.mSkills[slot][0] = skillId;
}
int CharClassFunctions::IsClassDefault(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,0);
return !player->klass.mId.empty(); // true if default
}
const char *CharClassFunctions::GetDefaultClass(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,"");
return player->klass.mId.c_str();
}
const char *CharClassFunctions::GetClassName(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,"");
return player->klass.mName.c_str();
}
const char *CharClassFunctions::GetClassDesc(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,"");
return player->klass.mDescription.c_str();
}
int CharClassFunctions::GetClassMajorAttribute(unsigned short pid, unsigned char slot) noexcept
{
Player *player;
GET_PLAYER(pid, player,0);
if(slot > 1)
throw invalid_argument("Incorrect attribute slot id");
return player->klass.mData.mAttribute[slot];
}
int CharClassFunctions::GetClassSpecialization(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,0);
return player->klass.mData.mSpecialization;
}
int CharClassFunctions::GetClassMajorSkill(unsigned short pid, unsigned char slot) noexcept
{
Player *player;
GET_PLAYER(pid, player,0);
if(slot > 4)
throw invalid_argument("Incorrect skill slot id");
return player->klass.mData.mSkills[slot][1];
}
int CharClassFunctions::GetClassMinorSkill(unsigned short pid, unsigned char slot) noexcept
{
Player *player;
GET_PLAYER(pid, player,0);
if(slot > 4)
throw invalid_argument("Incorrect skill slot id");
return player->klass.mData.mSkills[slot][0];
}

@ -0,0 +1,82 @@
//
// Created by koncord on 29.08.16.
//
#ifndef OPENMW_CHARCLASS_HPP
#define OPENMW_CHARCLASS_HPP
#include "../Types.hpp"
#define CHARCLASSFUNCTIONS \
{"SetDefaultClass", CharClassFunctions::SetDefaultClass},\
{"SetClassName", CharClassFunctions::SetClassName},\
{"SetClassDesc", CharClassFunctions::SetClassDesc},\
{"SetClassMajorAttribute", CharClassFunctions::SetClassMajorAttribute},\
{"SetClassSpecialization", CharClassFunctions::SetClassSpecialization},\
{"SetClassMajorSkill", CharClassFunctions::SetClassMajorSkill},\
{"SetClassMinorSkill", CharClassFunctions::SetClassMinorSkill},\
{"GetDefaultClass", CharClassFunctions::GetDefaultClass},\
{"GetClassName", CharClassFunctions::GetClassName},\
{"GetClassDesc", CharClassFunctions::GetClassDesc},\
{"GetClassMajorAttribute", CharClassFunctions::GetClassMajorAttribute},\
{"GetClassSpecialization", CharClassFunctions::GetClassSpecialization},\
{"GetClassMajorSkill", CharClassFunctions::GetClassMajorSkill},\
{"GetClassMinorSkill", CharClassFunctions::GetClassMinorSkill},\
{"IsClassDefault", CharClassFunctions::IsClassDefault},\
{"SendClass", CharClassFunctions::SendClass}
class CharClassFunctions
{
public:
CharClassFunctions() {}
static void SetDefaultClass(unsigned short pid, const char *id) noexcept;
static void SetClassName(unsigned short pid, const char *name) noexcept;
static void SetClassDesc(unsigned short pid, const char *desc) noexcept;
/**
* \param pid
* \param slot 0 = first, 1 = second
* \param attrId
*/
static void SetClassMajorAttribute(unsigned short pid, unsigned char slot, int attrId) noexcept;
/**
* \param pid
* \param spec 0 = Combat, 1 = Magic, 2 = Stealth
*/
static void SetClassSpecialization(unsigned short pid, int spec) noexcept;
/**
* \param pid
* \param slot 0 to 4
* \param skillId
*/
static void SetClassMajorSkill(unsigned short pid, unsigned char slot, int skillId) noexcept;
static void SetClassMinorSkill(unsigned short pid, unsigned char slot, int skillId) noexcept;
static const char *GetDefaultClass(unsigned short pid) noexcept;
static const char *GetClassName(unsigned short pid) noexcept;
static const char *GetClassDesc(unsigned short pid) noexcept;
/**
* \param pid
* \param slot 0 = first, 1 = second
* \return attrId
*/
static int GetClassMajorAttribute(unsigned short pid, unsigned char slot) noexcept;
/**
* \param pid
* \return spec 0 = Combat, 1 = Magic, 2 = Stealth
*/
static int GetClassSpecialization(unsigned short pid) noexcept;
/**
* \param pid
* \param slot 0 to 4
* \return skillId
*/
static int GetClassMajorSkill(unsigned short pid, unsigned char slot) noexcept;
static int GetClassMinorSkill(unsigned short pid, unsigned char slot) noexcept;
static int IsClassDefault(unsigned short pid) noexcept;
static void SendClass(unsigned short pid) noexcept;
};
#endif //OPENMW_CHARCLASS_HPP

@ -5,6 +5,7 @@
#ifndef SOURCEPAWN_SCRIPTFUNCTIONS_HPP
#define SOURCEPAWN_SCRIPTFUNCTIONS_HPP
#include <Script/Functions/CharClass.hpp>
#include <RakNetTypes.h>
//#include <amx/amx.h>
#include <tuple>
@ -272,6 +273,10 @@ public:
{"SetMapVisibility", ScriptFunctions::SetMapVisibility},
{"SetMapVisibilityAll", ScriptFunctions::SetMapVisibilityAll},
CHARCLASSFUNCTIONS,
};
static constexpr ScriptCallbackData callbacks[]{

@ -535,7 +535,8 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix
{
updateBaseStats(true);
updateAttributesAndSkills(true);
GetNetworking()->GetPacket(ID_GAME_UPDATE_SKILLS)->Send(this);
//GetNetworking()->GetPacket(ID_GAME_UPDATE_SKILLS)->Send(this);
SendClass();
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
}
CharGenStage()->end = 0;
@ -580,7 +581,41 @@ void LocalPlayer::updateChar()
Npc()->mHair
);
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(Npc()->mClass);
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar();
}
void LocalPlayer::SetClass()
{
if(klass.mId.empty()) // custom class
{
klass.mData.mIsPlayable = 0x1;
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass);
MWBase::Environment::get().getWindowManager()->setPlayerClass(klass);
}
else
{
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(Npc()->mClass);
const ESM::Class *_klass = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find(Npc()->mClass);
if (_klass)
MWBase::Environment::get().getWindowManager()->setPlayerClass(klass);
}
}
void LocalPlayer::SendClass()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
const ESM::NPC *cpl = world->getPlayerPtr().get<ESM::NPC>()->mBase;
const ESM::Class *cls = world->getStore().get<ESM::Class>().find(cpl->mClass);
if(cpl->mClass.find("$dynamic") != string::npos) // custom class
{
klass.mId = "";
klass.mName = cls->mName;
klass.mDescription = cls->mDescription;
klass.mData = cls->mData;
}
else
klass.mId = cls->mId;
GetNetworking()->GetPacket(ID_GAME_CHARCLASS)->Send(this);
}

@ -32,6 +32,8 @@ namespace mwmp
void setPosition();
void setCell();
void SetClass();
void SendClass();
void CharGen(int stageFirst, int stageEnd);
bool CharGenThread(); // return true if CGStage::current == CGStage::end

@ -573,6 +573,20 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
}
break;
}
case ID_GAME_CHARCLASS:
{
if (id == myid)
{
if(packet->length == myPacket->headerSize())
getLocalPlayer()->SendClass();
else
{
myPacket->Packet(&bsIn, getLocalPlayer(), false);
getLocalPlayer()->SetClass();
}
}
break;
}
default:
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Custom message with identifier %i has arrived in initialization.", packet->data[0]);
}

Loading…
Cancel
Save