mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 10:09:39 +00:00
Reorder functions in LocalPlayer and make their names more consistent
This commit is contained in:
parent
6650b74498
commit
728a09e423
7 changed files with 413 additions and 416 deletions
|
@ -606,7 +606,7 @@ namespace MWClass
|
|||
if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
{
|
||||
mwmp::Main::get().getLocalPlayer()->GetAttack()->success = false;
|
||||
mwmp::Main::get().getLocalPlayer()->SendAttack(0);
|
||||
mwmp::Main::get().getLocalPlayer()->sendAttack(0);
|
||||
}
|
||||
|
||||
othercls.onHit(victim, 0.0f, false, weapon, ptr, osg::Vec3f(), false);
|
||||
|
@ -850,7 +850,7 @@ namespace MWClass
|
|||
_atk->attacker = mwmp::Main::get().getLocalPlayer()->guid;
|
||||
_atk->target = mwmp::Players::GetPlayer(ptr)->guid;
|
||||
_atk->knockdown = getCreatureStats(ptr).getKnockedDown();
|
||||
mwmp::Main::get().getLocalPlayer()->SendAttack(0); // todo: make this sensitive to different weapon types
|
||||
mwmp::Main::get().getLocalPlayer()->sendAttack(0); // todo: make this sensitive to different weapon types
|
||||
}
|
||||
|
||||
if(ptr == MWMechanics::getPlayer())
|
||||
|
|
|
@ -1036,7 +1036,7 @@ namespace MWMechanics
|
|||
{
|
||||
bool state = MWBase::Environment::get().getWorld()->getPlayer().getAttackingOrSpell();
|
||||
iter->second->getCharacterController()->setAttackingOrSpell(state);
|
||||
mwmp::Main::get().getLocalPlayer()->PrepareAttack(2, state);
|
||||
mwmp::Main::get().getLocalPlayer()->prepareAttack(2, state);
|
||||
}
|
||||
|
||||
if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first))
|
||||
|
|
|
@ -855,9 +855,9 @@ namespace MWMechanics
|
|||
|
||||
if(mCaster == getPlayer())
|
||||
{
|
||||
mwmp::Main::get().getLocalPlayer()->SendAttack(1);
|
||||
mwmp::Main::get().getLocalPlayer()->sendAttack(1);
|
||||
mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = false;
|
||||
mwmp::Main::get().getLocalPlayer()->SendAttack(1);
|
||||
mwmp::Main::get().getLocalPlayer()->sendAttack(1);
|
||||
}
|
||||
|
||||
if (fail)
|
||||
|
|
|
@ -41,6 +41,16 @@ LocalPlayer::~LocalPlayer()
|
|||
|
||||
}
|
||||
|
||||
Networking *LocalPlayer::GetNetworking()
|
||||
{
|
||||
return mwmp::Main::get().getNetworking();
|
||||
}
|
||||
|
||||
MWWorld::Ptr LocalPlayer::GetPlayerPtr()
|
||||
{
|
||||
return MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
}
|
||||
|
||||
void LocalPlayer::Update()
|
||||
{
|
||||
updateCell();
|
||||
|
@ -55,9 +65,72 @@ void LocalPlayer::Update()
|
|||
updateLevel();
|
||||
}
|
||||
|
||||
MWWorld::Ptr LocalPlayer::GetPlayerPtr()
|
||||
void LocalPlayer::charGen(int stageFirst, int stageEnd)
|
||||
{
|
||||
return MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
CharGenStage()->current = stageFirst;
|
||||
CharGenStage()->end = stageEnd;
|
||||
}
|
||||
|
||||
bool LocalPlayer::charGenThread() // todo: need fix
|
||||
{
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
if (windowManager->isGuiMode())
|
||||
return false;
|
||||
|
||||
if (CharGenStage()->current >= CharGenStage()->end)
|
||||
{
|
||||
|
||||
if (GetNetworking()->isConnected() && CharGenStage()->current == CharGenStage()->end &&
|
||||
CharGenStage()->end != 0)
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
(*Npc()) = *player.get<ESM::NPC>()->mBase;
|
||||
(*BirthSign()) = world->getPlayer().getBirthSign();
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server with my CharGen info");
|
||||
GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Send(this);
|
||||
|
||||
if (CharGenStage()->end != 1)
|
||||
{
|
||||
updateDynamicStats(true);
|
||||
updateAttributes(true);
|
||||
updateSkills(true);
|
||||
updateLevel(true);
|
||||
sendClass();
|
||||
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
|
||||
}
|
||||
CharGenStage()->end = 0;
|
||||
/*RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);*/
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (CharGenStage()->current)
|
||||
{
|
||||
case 0:
|
||||
windowManager->pushGuiMode(MWGui::GM_Name);
|
||||
break;
|
||||
case 1:
|
||||
windowManager->pushGuiMode(MWGui::GM_Race);
|
||||
break;
|
||||
case 2:
|
||||
windowManager->pushGuiMode(MWGui::GM_Class);
|
||||
break;
|
||||
case 3:
|
||||
windowManager->pushGuiMode(MWGui::GM_Birth);
|
||||
break;
|
||||
default:
|
||||
windowManager->pushGuiMode(MWGui::GM_Review);
|
||||
break;
|
||||
}
|
||||
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
|
||||
CharGenStage()->current++;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocalPlayer::updateDynamicStats(bool forceUpdate)
|
||||
|
@ -161,7 +234,8 @@ void LocalPlayer::updateLevel(bool forceUpdate)
|
|||
CreatureStats()->mLevel = ptrNpcStats.getLevel();
|
||||
GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this);
|
||||
|
||||
// Also update skills to refresh level progress
|
||||
// Also update skills to refresh level progress and attribute bonuses
|
||||
// for next level up
|
||||
updateSkills(true);
|
||||
}
|
||||
}
|
||||
|
@ -214,115 +288,71 @@ void LocalPlayer::updatePosition(bool forceUpdate)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void LocalPlayer::setPosition()
|
||||
void LocalPlayer::updateCell(bool forceUpdate)
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
const ESM::Cell *ptrCell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell();
|
||||
bool shouldUpdate = false;
|
||||
|
||||
world->getPlayer().setTeleported(true);
|
||||
world->moveObject(player, Position()->pos[0], Position()->pos[1], Position()->pos[2]);
|
||||
world->rotateObject(player, Position()->rot[0], Position()->rot[1], Position()->rot[2]);
|
||||
// Send a packet to server to update this LocalPlayer's cell if:
|
||||
// 1) forceUpdate is true
|
||||
// 2) The LocalPlayer's cell name does not equal the World Player's cell name
|
||||
// 3) The LocalPlayer's exterior cell coordinates do not equal the World Player's
|
||||
// exterior cell coordinates
|
||||
if (forceUpdate)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (!Misc::StringUtils::ciEqual(ptrCell->mName, GetCell()->mName))
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (ptrCell->isExterior())
|
||||
{
|
||||
if (ptrCell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (ptrCell->mCellId.mIndex.mY != GetCell()->mCellId.mIndex.mY)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldUpdate)
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_CELL to server");
|
||||
|
||||
LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s",
|
||||
GetCell()->getDescription().c_str(),
|
||||
ptrCell->getDescription().c_str());
|
||||
|
||||
(*GetCell()) = *ptrCell;
|
||||
|
||||
// Make sure the position is updated before a cell packet is sent, or else
|
||||
// cell change events in server scripts will have the wrong player position
|
||||
updatePosition(true);
|
||||
}
|
||||
|
||||
void LocalPlayer::setCell()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
ESM::Position pos;
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
|
||||
world->getPlayer().setTeleported(true);
|
||||
|
||||
int x = GetCell()->mCellId.mIndex.mX;
|
||||
int y = GetCell()->mCellId.mIndex.mY;
|
||||
|
||||
if (GetCell()->isExterior())
|
||||
{
|
||||
world->indexToPosition(x, y, pos.pos[0], pos.pos[1], true);
|
||||
pos.pos[2] = 0;
|
||||
|
||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||
|
||||
world->changeToExteriorCell(pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else if (world->findExteriorPosition(GetCell()->mName, pos))
|
||||
{
|
||||
world->changeToExteriorCell(pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
world->findInteriorPosition(GetCell()->mName, pos);
|
||||
world->changeToInteriorCell(GetCell()->mName, pos, true);
|
||||
}
|
||||
|
||||
updateCell(true);
|
||||
}
|
||||
|
||||
void LocalPlayer::setDynamicStats()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
MWMechanics::DynamicStat<float> dynamicStat;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
dynamicStat = ptrCreatureStats->getDynamic(i);
|
||||
dynamicStat.setBase(CreatureStats()->mDynamic[i].mBase);
|
||||
dynamicStat.setCurrent(CreatureStats()->mDynamic[i].mCurrent);
|
||||
ptrCreatureStats->setDynamic(i, dynamicStat);
|
||||
// Also update skill progress
|
||||
updateSkills(true);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::setAttributes()
|
||||
void LocalPlayer::updateChar()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
|
||||
Npc()->mRace,
|
||||
Npc()->isMale(),
|
||||
Npc()->mHead,
|
||||
Npc()->mHair
|
||||
);
|
||||
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
MWMechanics::AttributeValue attributeValue;
|
||||
MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(*BirthSign());
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
attributeValue.readState(CreatureStats()->mAttributes[i]);
|
||||
ptrCreatureStats->setAttribute(i, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::setSkills()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player);
|
||||
MWMechanics::SkillValue skillValue;
|
||||
|
||||
for (int i = 0; i < 27; ++i)
|
||||
{
|
||||
skillValue.readState(NpcStats()->mSkills[i]);
|
||||
ptrNpcStats->setSkill(i, skillValue);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
ptrNpcStats->setSkillIncrease(i, NpcStats()->mSkillIncrease[i]);
|
||||
}
|
||||
|
||||
ptrNpcStats->setLevelProgress(NpcStats()->mLevelProgress);
|
||||
}
|
||||
|
||||
void LocalPlayer::setLevel()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
ptrCreatureStats->setLevel(CreatureStats()->mLevel);
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar();
|
||||
}
|
||||
|
||||
void LocalPlayer::updateInventory(bool forceUpdate)
|
||||
|
@ -435,118 +465,6 @@ void LocalPlayer::updateDeadState(bool forceUpdate)
|
|||
isDead = false;
|
||||
}
|
||||
|
||||
Networking *LocalPlayer::GetNetworking()
|
||||
{
|
||||
return mwmp::Main::get().getNetworking();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocalPlayer::PrepareAttack(char type, bool state)
|
||||
{
|
||||
if (GetAttack()->pressed == state)
|
||||
return;
|
||||
|
||||
MWMechanics::DrawState_ dstate = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState();
|
||||
|
||||
if (dstate == MWMechanics::DrawState_Spell)
|
||||
{
|
||||
const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
|
||||
|
||||
GetAttack()->refid = spell;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GetAttack()->pressed = state;
|
||||
GetAttack()->type = type;
|
||||
GetAttack()->knockdown = false;
|
||||
GetAttack()->success = false;
|
||||
GetAttack()->block = false;
|
||||
GetAttack()->target = RakNet::RakNetGUID();
|
||||
GetAttack()->attacker = guid;
|
||||
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
}
|
||||
|
||||
|
||||
void LocalPlayer::SendAttack(char type)
|
||||
{
|
||||
MWMechanics::DrawState_ state = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState();
|
||||
|
||||
if (state == MWMechanics::DrawState_Spell)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
GetAttack()->type = type;
|
||||
GetAttack()->pressed = false;
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
}
|
||||
|
||||
|
||||
void LocalPlayer::updateCell(bool forceUpdate)
|
||||
{
|
||||
const ESM::Cell *ptrCell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell();
|
||||
bool shouldUpdate = false;
|
||||
|
||||
// Send a packet to server to update this LocalPlayer's cell if:
|
||||
// 1) forceUpdate is true
|
||||
// 2) The LocalPlayer's cell name does not equal the World Player's cell name
|
||||
// 3) The LocalPlayer's exterior cell coordinates do not equal the World Player's
|
||||
// exterior cell coordinates
|
||||
if (forceUpdate)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (!Misc::StringUtils::ciEqual(ptrCell->mName, GetCell()->mName))
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (ptrCell->isExterior())
|
||||
{
|
||||
if (ptrCell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
else if (ptrCell->mCellId.mIndex.mY != GetCell()->mCellId.mIndex.mY)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldUpdate)
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_CELL to server");
|
||||
|
||||
LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s",
|
||||
GetCell()->getDescription().c_str(),
|
||||
ptrCell->getDescription().c_str());
|
||||
|
||||
(*GetCell()) = *ptrCell;
|
||||
|
||||
// Make sure the position is updated before a cell packet is sent, or else
|
||||
// cell change events in server scripts will have the wrong player position
|
||||
updatePosition(true);
|
||||
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
|
||||
// Also update skill progress
|
||||
updateSkills(true);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate)
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
@ -612,89 +530,117 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate)
|
|||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::CharGen(int stageFirst, int stageEnd)
|
||||
{
|
||||
CharGenStage()->current = stageFirst;
|
||||
CharGenStage()->end = stageEnd;
|
||||
}
|
||||
|
||||
bool LocalPlayer::CharGenThread() // ToDo: need fix
|
||||
{
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
if (windowManager->isGuiMode())
|
||||
return false;
|
||||
|
||||
if (CharGenStage()->current >= CharGenStage()->end)
|
||||
{
|
||||
|
||||
if (GetNetworking()->isConnected() && CharGenStage()->current == CharGenStage()->end &&
|
||||
CharGenStage()->end != 0)
|
||||
void LocalPlayer::setDynamicStats()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
(*Npc()) = *player.get<ESM::NPC>()->mBase;
|
||||
(*BirthSign()) = world->getPlayer().getBirthSign();
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server with my CharGen info");
|
||||
GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Send(this);
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
MWMechanics::DynamicStat<float> dynamicStat;
|
||||
|
||||
if (CharGenStage()->end != 1)
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
updateDynamicStats(true);
|
||||
updateAttributes(true);
|
||||
updateSkills(true);
|
||||
updateLevel(true);
|
||||
SendClass();
|
||||
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
|
||||
dynamicStat = ptrCreatureStats->getDynamic(i);
|
||||
dynamicStat.setBase(CreatureStats()->mDynamic[i].mBase);
|
||||
dynamicStat.setCurrent(CreatureStats()->mDynamic[i].mCurrent);
|
||||
ptrCreatureStats->setDynamic(i, dynamicStat);
|
||||
}
|
||||
CharGenStage()->end = 0;
|
||||
/*RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);*/
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (CharGenStage()->current)
|
||||
void LocalPlayer::setAttributes()
|
||||
{
|
||||
case 0:
|
||||
windowManager->pushGuiMode(MWGui::GM_Name);
|
||||
break;
|
||||
case 1:
|
||||
windowManager->pushGuiMode(MWGui::GM_Race);
|
||||
break;
|
||||
case 2:
|
||||
windowManager->pushGuiMode(MWGui::GM_Class);
|
||||
break;
|
||||
case 3:
|
||||
windowManager->pushGuiMode(MWGui::GM_Birth);
|
||||
break;
|
||||
default:
|
||||
windowManager->pushGuiMode(MWGui::GM_Review);
|
||||
break;
|
||||
}
|
||||
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
|
||||
CharGenStage()->current++;
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
return false;
|
||||
}
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
MWMechanics::AttributeValue attributeValue;
|
||||
|
||||
void LocalPlayer::updateChar()
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
|
||||
Npc()->mRace,
|
||||
Npc()->isMale(),
|
||||
Npc()->mHead,
|
||||
Npc()->mHair
|
||||
);
|
||||
|
||||
MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(*BirthSign());
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar();
|
||||
attributeValue.readState(CreatureStats()->mAttributes[i]);
|
||||
ptrCreatureStats->setAttribute(i, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::SetClass()
|
||||
void LocalPlayer::setSkills()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player);
|
||||
MWMechanics::SkillValue skillValue;
|
||||
|
||||
for (int i = 0; i < 27; ++i)
|
||||
{
|
||||
skillValue.readState(NpcStats()->mSkills[i]);
|
||||
ptrNpcStats->setSkill(i, skillValue);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
ptrNpcStats->setSkillIncrease(i, NpcStats()->mSkillIncrease[i]);
|
||||
}
|
||||
|
||||
ptrNpcStats->setLevelProgress(NpcStats()->mLevelProgress);
|
||||
}
|
||||
|
||||
void LocalPlayer::setLevel()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player);
|
||||
ptrCreatureStats->setLevel(CreatureStats()->mLevel);
|
||||
}
|
||||
|
||||
void LocalPlayer::setPosition()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
world->getPlayer().setTeleported(true);
|
||||
world->moveObject(player, Position()->pos[0], Position()->pos[1], Position()->pos[2]);
|
||||
world->rotateObject(player, Position()->rot[0], Position()->rot[1], Position()->rot[2]);
|
||||
|
||||
updatePosition(true);
|
||||
}
|
||||
|
||||
void LocalPlayer::setCell()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
ESM::Position pos;
|
||||
|
||||
world->getPlayer().setTeleported(true);
|
||||
|
||||
int x = GetCell()->mCellId.mIndex.mX;
|
||||
int y = GetCell()->mCellId.mIndex.mY;
|
||||
|
||||
if (GetCell()->isExterior())
|
||||
{
|
||||
world->indexToPosition(x, y, pos.pos[0], pos.pos[1], true);
|
||||
pos.pos[2] = 0;
|
||||
|
||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||
|
||||
world->changeToExteriorCell(pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else if (world->findExteriorPosition(GetCell()->mName, pos))
|
||||
{
|
||||
world->changeToExteriorCell(pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
world->findInteriorPosition(GetCell()->mName, pos);
|
||||
world->changeToInteriorCell(GetCell()->mName, pos, true);
|
||||
}
|
||||
|
||||
updateCell(true);
|
||||
}
|
||||
|
||||
void LocalPlayer::setClass()
|
||||
{
|
||||
if (charClass.mId.empty()) // custom class
|
||||
{
|
||||
|
@ -713,7 +659,7 @@ void LocalPlayer::SetClass()
|
|||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::SendClass()
|
||||
void LocalPlayer::sendClass()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
const ESM::NPC *cpl = world->getPlayerPtr().get<ESM::NPC>()->mBase;
|
||||
|
@ -731,3 +677,53 @@ void LocalPlayer::SendClass()
|
|||
|
||||
GetNetworking()->GetPacket(ID_GAME_CHARCLASS)->Send(this);
|
||||
}
|
||||
|
||||
void LocalPlayer::sendAttack(char type)
|
||||
{
|
||||
MWMechanics::DrawState_ state = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState();
|
||||
|
||||
if (state == MWMechanics::DrawState_Spell)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
GetAttack()->type = type;
|
||||
GetAttack()->pressed = false;
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
}
|
||||
|
||||
void LocalPlayer::prepareAttack(char type, bool state)
|
||||
{
|
||||
if (GetAttack()->pressed == state)
|
||||
return;
|
||||
|
||||
MWMechanics::DrawState_ dstate = GetPlayerPtr().getClass().getNpcStats(GetPlayerPtr()).getDrawState();
|
||||
|
||||
if (dstate == MWMechanics::DrawState_Spell)
|
||||
{
|
||||
const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
|
||||
|
||||
GetAttack()->refid = spell;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GetAttack()->pressed = state;
|
||||
GetAttack()->type = type;
|
||||
GetAttack()->knockdown = false;
|
||||
GetAttack()->success = false;
|
||||
GetAttack()->block = false;
|
||||
GetAttack()->target = RakNet::RakNetGUID();
|
||||
GetAttack()->attacker = guid;
|
||||
|
||||
RakNet::BitStream bs;
|
||||
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true);
|
||||
GetNetworking()->SendData(&bs);
|
||||
}
|
||||
|
|
|
@ -20,38 +20,39 @@ namespace mwmp
|
|||
|
||||
void Update();
|
||||
|
||||
void charGen(int stageFirst, int stageEnd);
|
||||
bool charGenThread(); // return true if CGStage::current == CGStage::end
|
||||
|
||||
void updateDynamicStats(bool forceUpdate = false);
|
||||
void updatePosition(bool forceUpdate = false);
|
||||
void updateInventory(bool forceUpdate = false);
|
||||
void updateAttackState(bool forceUpdate = false);
|
||||
void updateDeadState(bool forceUpdate = false);
|
||||
void updateAttributes(bool forceUpdate = false);
|
||||
void updateSkills(bool forceUpdate = false);
|
||||
void updateLevel(bool forceUpdate = false);
|
||||
void updatePosition(bool forceUpdate = false);
|
||||
void updateCell(bool forceUpdate = false);
|
||||
void updateChar();
|
||||
void updateInventory(bool forceUpdate = false);
|
||||
void updateAttackState(bool forceUpdate = false);
|
||||
void updateDeadState(bool forceUpdate = false);
|
||||
void updateDrawStateAndFlags(bool forceUpdate = false);
|
||||
|
||||
void setPosition();
|
||||
void setCell();
|
||||
void setDynamicStats();
|
||||
void setAttributes();
|
||||
void setSkills();
|
||||
void setLevel();
|
||||
void setPosition();
|
||||
void setCell();
|
||||
void setClass();
|
||||
|
||||
void SetClass();
|
||||
void SendClass();
|
||||
void CharGen(int stageFirst, int stageEnd);
|
||||
void sendClass();
|
||||
void sendAttack(char type);
|
||||
|
||||
bool CharGenThread(); // return true if CGStage::current == CGStage::end
|
||||
void prepareAttack(char type, bool state);
|
||||
|
||||
void updateChar();
|
||||
|
||||
void SendAttack(char type);
|
||||
void PrepareAttack(char type, bool state);
|
||||
|
||||
private:
|
||||
MWWorld::Ptr GetPlayerPtr();
|
||||
Networking *GetNetworking();
|
||||
MWWorld::Ptr GetPlayerPtr();
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ void Main::Frame(float dt)
|
|||
void Main::UpdateWorld(float dt) const
|
||||
{
|
||||
|
||||
if (!mLocalPlayer->CharGenThread())
|
||||
if (!mLocalPlayer->charGenThread())
|
||||
return;
|
||||
|
||||
static bool init = true;
|
||||
|
|
|
@ -583,11 +583,11 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
|
|||
if (id == myid)
|
||||
{
|
||||
if (packet->length == myPacket->headerSize())
|
||||
getLocalPlayer()->SendClass();
|
||||
getLocalPlayer()->sendClass();
|
||||
else
|
||||
{
|
||||
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
||||
getLocalPlayer()->SetClass();
|
||||
getLocalPlayer()->setClass();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue