2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2013-01-08 19:21:54 +01:00
|
|
|
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
#include "localplayer.h"
|
2011-11-05 21:34:49 +01:00
|
|
|
#include "map.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "tile.h"
|
2012-06-03 21:28:17 +02:00
|
|
|
#include <framework/core/eventdispatcher.h>
|
2013-01-19 03:18:29 +01:00
|
|
|
#include <framework/graphics/graphics.h>
|
2011-08-15 23:02:52 +02:00
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
LocalPlayer::LocalPlayer()
|
|
|
|
{
|
2012-02-09 04:45:19 +01:00
|
|
|
m_states = 0;
|
2012-07-23 17:11:53 +02:00
|
|
|
m_vocation = 0;
|
2012-08-02 09:58:49 +02:00
|
|
|
m_walkLockExpiration = 0;
|
2012-08-25 21:11:54 +02:00
|
|
|
m_lastWalkPing = -1;
|
2012-02-09 04:45:19 +01:00
|
|
|
|
|
|
|
m_skillsLevel.fill(-1);
|
2012-08-19 03:19:43 +02:00
|
|
|
m_skillsBaseLevel.fill(-1);
|
2012-02-09 04:45:19 +01:00
|
|
|
m_skillsLevelPercent.fill(-1);
|
2012-01-20 06:45:56 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
m_health = -1;
|
|
|
|
m_maxHealth = -1;
|
|
|
|
m_freeCapacity = -1;
|
|
|
|
m_experience = -1;
|
|
|
|
m_level = -1;
|
|
|
|
m_levelPercent = -1;
|
|
|
|
m_mana = -1;
|
|
|
|
m_maxMana = -1;
|
|
|
|
m_magicLevel = -1;
|
|
|
|
m_magicLevelPercent = -1;
|
2012-08-19 03:19:43 +02:00
|
|
|
m_baseMagicLevel = -1;
|
2012-02-09 04:45:19 +01:00
|
|
|
m_soul = -1;
|
|
|
|
m_stamina = -1;
|
2012-08-19 03:19:43 +02:00
|
|
|
m_baseSpeed = -1;
|
|
|
|
m_regenerationTime = -1;
|
|
|
|
m_offlineTrainingTime = -1;
|
|
|
|
m_totalCapacity = -1;
|
2012-01-19 05:12:53 +01:00
|
|
|
}
|
|
|
|
|
2013-01-19 03:18:29 +01:00
|
|
|
void LocalPlayer::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView)
|
|
|
|
{
|
|
|
|
Creature::draw(dest, scaleFactor, animate, lightView);
|
|
|
|
|
|
|
|
// This is a test to rotation, translate and scale transformations.
|
|
|
|
/*
|
2013-01-19 16:44:27 +01:00
|
|
|
Point rotateOffset = dest;
|
|
|
|
rotateOffset += ((animate ? m_walkOffset : Point(0,0)) + Point(16,16)) * scaleFactor;
|
|
|
|
g_painter->rotate(rotateOffset, Fw::pi * std::sin(g_clock.millis()/1000.0f));
|
2013-01-19 03:18:29 +01:00
|
|
|
Creature::draw(dest, scaleFactor, animate, lightView);
|
2013-01-19 16:44:27 +01:00
|
|
|
g_painter->resetTransformMatrix();
|
2013-01-19 03:18:29 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2012-07-30 12:59:08 +02:00
|
|
|
void LocalPlayer::lockWalk(int millis)
|
2012-01-19 05:12:53 +01:00
|
|
|
{
|
2012-08-02 09:58:49 +02:00
|
|
|
m_walkLockExpiration = std::max(m_walkLockExpiration, (ticks_t) g_clock.millis() + millis);
|
2012-01-19 05:12:53 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
bool LocalPlayer::canWalk(Otc::Direction direction)
|
|
|
|
{
|
2012-08-02 09:58:49 +02:00
|
|
|
// cannot walk while locked
|
|
|
|
if(m_walkLockExpiration != 0 && g_clock.millis() < m_walkLockExpiration)
|
|
|
|
return false;
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-08-09 05:51:13 +02:00
|
|
|
// paralyzed
|
|
|
|
if(m_speed == 0)
|
|
|
|
return false;
|
|
|
|
|
2012-08-02 09:58:49 +02:00
|
|
|
// last walk is not done yet
|
2012-08-09 05:51:13 +02:00
|
|
|
if(m_walkTimer.ticksElapsed() < getStepDuration())
|
2012-02-09 04:45:19 +01:00
|
|
|
return false;
|
|
|
|
|
2012-08-02 09:58:49 +02:00
|
|
|
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
|
2012-08-09 05:51:13 +02:00
|
|
|
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + PREWALK_TIMEOUT;
|
2012-08-02 09:58:49 +02:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
// avoid doing more walks than wanted when receiving a lot of walks from server
|
|
|
|
if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted)
|
|
|
|
return false;
|
|
|
|
|
2012-08-02 09:58:49 +02:00
|
|
|
// cannot walk while already walking
|
|
|
|
if(m_walking && !prewalkTimeouted)
|
2012-02-09 04:45:19 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
void LocalPlayer::walk(const Position& oldPos, const Position& newPos)
|
|
|
|
{
|
|
|
|
// a prewalk was going on
|
|
|
|
if(m_preWalking) {
|
2012-08-02 09:58:49 +02:00
|
|
|
if(m_waitingWalkPong) {
|
2012-08-25 21:11:54 +02:00
|
|
|
if(newPos == m_lastPrewalkDestionation)
|
|
|
|
m_lastWalkPing = m_walkPingTimer.ticksElapsed();
|
2012-08-02 09:58:49 +02:00
|
|
|
|
|
|
|
m_waitingWalkPong = false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
// switch to normal walking
|
|
|
|
m_preWalking = false;
|
|
|
|
m_lastPrewalkDone = true;
|
2012-01-19 17:23:24 +01:00
|
|
|
// if is to the last prewalk destination, updates the walk preserving the animation
|
2012-01-19 05:12:53 +01:00
|
|
|
if(newPos == m_lastPrewalkDestionation) {
|
|
|
|
updateWalk();
|
|
|
|
// was to another direction, replace the walk
|
|
|
|
} else
|
|
|
|
Creature::walk(oldPos, newPos);
|
2012-06-03 21:28:17 +02:00
|
|
|
}
|
|
|
|
// no prewalk was going on, this must be an server side automated walk
|
|
|
|
else {
|
2012-08-25 21:11:54 +02:00
|
|
|
m_walkPingTimer.restart();
|
2012-06-03 21:28:17 +02:00
|
|
|
m_autoWalking = true;
|
|
|
|
if(m_autoWalkEndEvent)
|
|
|
|
m_autoWalkEndEvent->cancel();
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
Creature::walk(oldPos, newPos);
|
2012-06-03 21:28:17 +02:00
|
|
|
}
|
2012-01-19 05:12:53 +01:00
|
|
|
}
|
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
void LocalPlayer::preWalk(Otc::Direction direction)
|
2011-08-30 16:37:48 +02:00
|
|
|
{
|
2012-01-30 19:18:10 +01:00
|
|
|
Position newPos = m_position.translatedToDirection(direction);
|
2012-08-02 09:58:49 +02:00
|
|
|
|
|
|
|
// avoid reanimating prewalks
|
|
|
|
if(m_preWalking && m_lastPrewalkDestionation == newPos)
|
|
|
|
return;
|
|
|
|
|
2012-08-25 21:11:54 +02:00
|
|
|
m_waitingWalkPong = false;
|
|
|
|
if(m_walkPingTimer.ticksElapsed() > getStepDuration() && m_idleTimer.ticksElapsed() > getStepDuration()*2) {
|
|
|
|
m_waitingWalkPong = true;
|
|
|
|
m_walkPingTimer.restart();
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
m_preWalking = true;
|
2012-06-03 21:28:17 +02:00
|
|
|
|
|
|
|
if(m_autoWalkEndEvent)
|
|
|
|
m_autoWalkEndEvent->cancel();
|
|
|
|
|
2012-08-02 09:58:49 +02:00
|
|
|
// start walking to direction
|
2012-01-19 05:12:53 +01:00
|
|
|
m_lastPrewalkDone = false;
|
|
|
|
m_lastPrewalkDestionation = newPos;
|
2012-01-30 01:00:12 +01:00
|
|
|
Creature::walk(m_position, newPos);
|
2011-11-05 21:34:49 +01:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
void LocalPlayer::cancelWalk(Otc::Direction direction)
|
|
|
|
{
|
|
|
|
// only cancel client side walks
|
|
|
|
if(m_walking && m_preWalking)
|
|
|
|
stopWalk();
|
|
|
|
|
|
|
|
m_lastPrewalkDone = true;
|
2012-08-02 09:58:49 +02:00
|
|
|
m_waitingWalkPong = false;
|
2012-08-25 21:11:54 +02:00
|
|
|
m_walkPingTimer.restart();
|
|
|
|
m_idleTimer.restart();
|
2012-01-19 05:12:53 +01:00
|
|
|
|
|
|
|
// turn to the cancel direction
|
|
|
|
if(direction != Otc::InvalidDirection)
|
|
|
|
setDirection(direction);
|
2013-01-07 18:17:01 +01:00
|
|
|
|
2013-01-08 16:32:37 +01:00
|
|
|
updateAutoWalkSteps(true);
|
|
|
|
|
2013-01-07 18:17:01 +01:00
|
|
|
callLuaField("onCancelWalk", direction);
|
2012-01-19 05:12:53 +01:00
|
|
|
}
|
|
|
|
|
2013-01-08 16:32:37 +01:00
|
|
|
void LocalPlayer::updateAutoWalkSteps(bool walkFailed)
|
|
|
|
{
|
|
|
|
if(!m_autoWalking) {
|
|
|
|
m_autoWalkSteps.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!m_lastAutoWalkDestination.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for now this cannot be done from lua, due to bot protection
|
|
|
|
m_autoWalkSteps.push_back(m_lastAutoWalkDestination);
|
|
|
|
if(m_autoWalkSteps.size() >= Otc::MAX_AUTOWALK_STEPS_RETRY || walkFailed) {
|
|
|
|
autoWalk(m_lastAutoWalkDestination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalPlayer::autoWalk(const Position& destination)
|
|
|
|
{
|
|
|
|
m_autoWalkSteps.clear();
|
|
|
|
|
|
|
|
m_lastAutoWalkDestination = destination;
|
|
|
|
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result = g_map.findPath(m_position, destination, 127, Otc::PathFindAllowNullTiles);
|
|
|
|
|
|
|
|
std::vector<Otc::Direction> dirs = std::get<0>(result);
|
|
|
|
if(dirs.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
g_game.autoWalk(dirs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::stopAutoWalkUpdate()
|
|
|
|
{
|
|
|
|
m_lastAutoWalkDestination = Position();
|
|
|
|
m_autoWalkSteps.clear();
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
void LocalPlayer::stopWalk()
|
|
|
|
{
|
2012-06-03 21:28:17 +02:00
|
|
|
Creature::stopWalk(); // will call terminateWalk
|
2013-01-08 16:32:37 +01:00
|
|
|
|
2012-01-20 16:00:24 +01:00
|
|
|
m_lastPrewalkDone = true;
|
2012-01-19 05:12:53 +01:00
|
|
|
m_lastPrewalkDestionation = Position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
|
|
|
|
{
|
|
|
|
// pre walks offsets are calculated in the oposite direction
|
|
|
|
if(m_preWalking) {
|
|
|
|
m_walkOffset = Point(0,0);
|
|
|
|
if(m_direction == Otc::North || m_direction == Otc::NorthEast || m_direction == Otc::NorthWest)
|
|
|
|
m_walkOffset.y = -totalPixelsWalked;
|
|
|
|
else if(m_direction == Otc::South || m_direction == Otc::SouthEast || m_direction == Otc::SouthWest)
|
|
|
|
m_walkOffset.y = totalPixelsWalked;
|
|
|
|
|
|
|
|
if(m_direction == Otc::East || m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
|
|
|
|
m_walkOffset.x = totalPixelsWalked;
|
|
|
|
else if(m_direction == Otc::West || m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
|
|
|
|
m_walkOffset.x = -totalPixelsWalked;
|
|
|
|
} else
|
|
|
|
Creature::updateWalkOffset(totalPixelsWalked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::updateWalk()
|
|
|
|
{
|
2012-08-09 05:51:13 +02:00
|
|
|
int stepDuration = getStepDuration();
|
2012-12-29 18:41:14 +01:00
|
|
|
float walkTicksPerPixel = getStepDuration(true) / 32.0f;
|
2012-01-19 05:12:53 +01:00
|
|
|
int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
|
|
|
|
|
|
|
|
// update walk animation and offsets
|
|
|
|
updateWalkAnimation(totalPixelsWalked);
|
|
|
|
updateWalkOffset(totalPixelsWalked);
|
2012-01-30 22:28:08 +01:00
|
|
|
updateWalkingTile();
|
2012-01-19 05:12:53 +01:00
|
|
|
|
2012-08-09 05:51:13 +02:00
|
|
|
// terminate walk only when client and server side walk are completed
|
|
|
|
if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration)
|
2012-01-19 05:12:53 +01:00
|
|
|
terminateWalk();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::terminateWalk()
|
|
|
|
{
|
|
|
|
Creature::terminateWalk();
|
|
|
|
m_preWalking = false;
|
2012-08-25 21:11:54 +02:00
|
|
|
m_idleTimer.restart();
|
2012-06-03 21:28:17 +02:00
|
|
|
|
|
|
|
auto self = asLocalPlayer();
|
|
|
|
|
|
|
|
if(m_autoWalking) {
|
|
|
|
if(m_autoWalkEndEvent)
|
|
|
|
m_autoWalkEndEvent->cancel();
|
2012-06-26 00:13:30 +02:00
|
|
|
m_autoWalkEndEvent = g_dispatcher.scheduleEvent([self] {
|
2012-06-03 21:28:17 +02:00
|
|
|
self->m_autoWalking = false;
|
|
|
|
}, 100);
|
|
|
|
}
|
2012-01-19 05:12:53 +01:00
|
|
|
}
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-08-02 09:58:49 +02:00
|
|
|
void LocalPlayer::onAppear()
|
|
|
|
{
|
|
|
|
Creature::onAppear();
|
|
|
|
|
|
|
|
// on teleports lock the walk
|
|
|
|
if(!m_oldPosition.isInRange(m_position,1,1))
|
|
|
|
lockWalk();
|
|
|
|
}
|
|
|
|
|
2013-01-08 16:32:37 +01:00
|
|
|
void LocalPlayer::onPositionChange(const Position& newPos, const Position& oldPos)
|
|
|
|
{
|
|
|
|
Creature::onPositionChange(newPos, oldPos);
|
|
|
|
|
|
|
|
updateAutoWalkSteps();
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void LocalPlayer::setStates(int states)
|
|
|
|
{
|
|
|
|
if(m_states != states) {
|
|
|
|
int oldStates = m_states;
|
|
|
|
m_states = states;
|
|
|
|
callLuaField("onStatesChange", states, oldStates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setSkill(Otc::Skill skill, int level, int levelPercent)
|
|
|
|
{
|
2012-06-26 01:48:36 +02:00
|
|
|
if(skill >= Otc::LastSkill) {
|
|
|
|
g_logger.traceError("invalid skill");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
int oldLevel = m_skillsLevel[skill];
|
|
|
|
int oldLevelPercent = m_skillsLevelPercent[skill];
|
|
|
|
|
2012-03-29 21:25:04 +02:00
|
|
|
if(level != oldLevel || levelPercent != oldLevelPercent) {
|
2012-02-09 04:45:19 +01:00
|
|
|
m_skillsLevel[skill] = level;
|
|
|
|
m_skillsLevelPercent[skill] = levelPercent;
|
|
|
|
|
|
|
|
callLuaField("onSkillChange", skill, level, levelPercent, oldLevel, oldLevelPercent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 03:19:43 +02:00
|
|
|
void LocalPlayer::setBaseSkill(Otc::Skill skill, int baseLevel)
|
|
|
|
{
|
|
|
|
if(skill >= Otc::LastSkill) {
|
|
|
|
g_logger.traceError("invalid skill");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int oldBaseLevel = m_skillsBaseLevel[skill];
|
|
|
|
if(baseLevel != oldBaseLevel) {
|
|
|
|
m_skillsBaseLevel[skill] = baseLevel;
|
|
|
|
|
|
|
|
callLuaField("onBaseSkillChange", skill, baseLevel, oldBaseLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void LocalPlayer::setHealth(double health, double maxHealth)
|
|
|
|
{
|
|
|
|
if(m_health != health || m_maxHealth != maxHealth) {
|
|
|
|
double oldHealth = m_health;
|
|
|
|
double oldMaxHealth = m_maxHealth;
|
|
|
|
m_health = health;
|
|
|
|
m_maxHealth = maxHealth;
|
|
|
|
|
|
|
|
callLuaField("onHealthChange", health, maxHealth, oldHealth, oldMaxHealth);
|
|
|
|
|
|
|
|
// cannot walk while dying
|
|
|
|
if(health == 0) {
|
|
|
|
if(isPreWalking())
|
|
|
|
stopWalk();
|
|
|
|
lockWalk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setFreeCapacity(double freeCapacity)
|
|
|
|
{
|
|
|
|
if(m_freeCapacity != freeCapacity) {
|
|
|
|
double oldFreeCapacity = m_freeCapacity;
|
|
|
|
m_freeCapacity = freeCapacity;
|
|
|
|
|
|
|
|
callLuaField("onFreeCapacityChange", freeCapacity, oldFreeCapacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 03:19:43 +02:00
|
|
|
void LocalPlayer::setTotalCapacity(double totalCapacity)
|
|
|
|
{
|
|
|
|
if(m_totalCapacity != totalCapacity) {
|
|
|
|
double oldTotalCapacity = m_totalCapacity;
|
|
|
|
m_totalCapacity = totalCapacity;
|
|
|
|
|
|
|
|
callLuaField("onTotalCapacityChange", totalCapacity, oldTotalCapacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void LocalPlayer::setExperience(double experience)
|
|
|
|
{
|
|
|
|
if(m_experience != experience) {
|
|
|
|
double oldExperience = m_experience;
|
|
|
|
m_experience = experience;
|
|
|
|
|
|
|
|
callLuaField("onExperienceChange", experience, oldExperience);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setLevel(double level, double levelPercent)
|
|
|
|
{
|
2012-03-30 11:51:34 +02:00
|
|
|
if(m_level != level || m_levelPercent != levelPercent) {
|
2012-02-09 04:45:19 +01:00
|
|
|
double oldLevel = m_level;
|
|
|
|
double oldLevelPercent = m_levelPercent;
|
|
|
|
m_level = level;
|
|
|
|
m_levelPercent = levelPercent;
|
|
|
|
|
|
|
|
callLuaField("onLevelChange", level, levelPercent, oldLevel, oldLevelPercent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setMana(double mana, double maxMana)
|
|
|
|
{
|
|
|
|
if(m_mana != mana || m_maxMana != maxMana) {
|
|
|
|
double oldMana = m_mana;
|
|
|
|
double oldMaxMana;
|
|
|
|
m_mana = mana;
|
|
|
|
m_maxMana = maxMana;
|
|
|
|
|
|
|
|
callLuaField("onManaChange", mana, maxMana, oldMana, oldMaxMana);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setMagicLevel(double magicLevel, double magicLevelPercent)
|
|
|
|
{
|
|
|
|
if(m_magicLevel != magicLevel || m_magicLevelPercent != magicLevelPercent) {
|
|
|
|
double oldMagicLevel = m_magicLevel;
|
|
|
|
double oldMagicLevelPercent = m_magicLevelPercent;
|
|
|
|
m_magicLevel = magicLevel;
|
|
|
|
m_magicLevelPercent = magicLevelPercent;
|
|
|
|
|
|
|
|
callLuaField("onMagicLevelChange", magicLevel, magicLevelPercent, oldMagicLevel, oldMagicLevelPercent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 03:19:43 +02:00
|
|
|
void LocalPlayer::setBaseMagicLevel(double baseMagicLevel)
|
|
|
|
{
|
|
|
|
if(m_baseMagicLevel != baseMagicLevel) {
|
|
|
|
double oldBaseMagicLevel = m_baseMagicLevel;
|
|
|
|
m_baseMagicLevel = baseMagicLevel;
|
|
|
|
|
|
|
|
callLuaField("onBaseMagicLevelChange", baseMagicLevel, oldBaseMagicLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
void LocalPlayer::setSoul(double soul)
|
|
|
|
{
|
|
|
|
if(m_soul != soul) {
|
|
|
|
double oldSoul = m_soul;
|
|
|
|
m_soul = soul;
|
|
|
|
|
|
|
|
callLuaField("onSoulChange", soul, oldSoul);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setStamina(double stamina)
|
|
|
|
{
|
|
|
|
if(m_stamina != stamina) {
|
|
|
|
double oldStamina = m_stamina;
|
|
|
|
m_stamina = stamina;
|
|
|
|
|
|
|
|
callLuaField("onStaminaChange", stamina, oldStamina);
|
|
|
|
}
|
|
|
|
}
|
2012-04-27 08:30:54 +02:00
|
|
|
|
2012-07-18 08:04:57 +02:00
|
|
|
void LocalPlayer::setInventoryItem(Otc::InventorySlot inventory, const ItemPtr& item)
|
2012-04-27 08:30:54 +02:00
|
|
|
{
|
2012-07-18 08:04:57 +02:00
|
|
|
if(inventory >= Otc::LastInventorySlot) {
|
2012-06-26 01:48:36 +02:00
|
|
|
g_logger.traceError("invalid slot");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
if(m_inventoryItems[inventory] != item) {
|
|
|
|
ItemPtr oldItem = m_inventoryItems[inventory];
|
|
|
|
m_inventoryItems[inventory] = item;
|
|
|
|
|
|
|
|
callLuaField("onInventoryChange", inventory, item, oldItem);
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 17:11:53 +02:00
|
|
|
|
|
|
|
void LocalPlayer::setVocation(int vocation)
|
|
|
|
{
|
|
|
|
if(m_vocation != vocation) {
|
|
|
|
int oldVocation = m_vocation;
|
|
|
|
m_vocation = vocation;
|
|
|
|
|
|
|
|
callLuaField("onVocationChange", vocation, oldVocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setPremium(bool premium)
|
|
|
|
{
|
|
|
|
if(m_premium != premium) {
|
|
|
|
m_premium = premium;
|
|
|
|
|
|
|
|
callLuaField("onPremiumChange", premium);
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 09:58:49 +02:00
|
|
|
|
2012-08-19 03:19:43 +02:00
|
|
|
void LocalPlayer::setBaseSpeed(double baseSpeed)
|
|
|
|
{
|
|
|
|
if(m_baseSpeed != baseSpeed) {
|
|
|
|
double oldBaseSpeed = m_baseSpeed;
|
|
|
|
m_baseSpeed = baseSpeed;
|
|
|
|
|
|
|
|
callLuaField("onBaseSpeedChange", baseSpeed, oldBaseSpeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setRegenerationTime(double regenerationTime)
|
|
|
|
{
|
|
|
|
if(m_regenerationTime != regenerationTime) {
|
|
|
|
double oldRegenerationTime = m_regenerationTime;
|
|
|
|
m_regenerationTime = regenerationTime;
|
|
|
|
|
|
|
|
callLuaField("onRegenerationChange", regenerationTime, oldRegenerationTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPlayer::setOfflineTrainingTime(double offlineTrainingTime)
|
|
|
|
{
|
|
|
|
if(m_offlineTrainingTime != offlineTrainingTime) {
|
|
|
|
double oldOfflineTrainingTime = m_offlineTrainingTime;
|
|
|
|
m_offlineTrainingTime = offlineTrainingTime;
|
|
|
|
|
|
|
|
callLuaField("onOfflineTrainingChange", offlineTrainingTime, oldOfflineTrainingTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 11:46:24 +02:00
|
|
|
void LocalPlayer::setSpells(const std::vector<int>& spells)
|
|
|
|
{
|
|
|
|
if(m_spells != spells) {
|
|
|
|
std::vector<int> oldSpells = m_spells;
|
|
|
|
m_spells = spells;
|
|
|
|
|
|
|
|
callLuaField("onSpellsChange", spells, oldSpells);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-03 07:05:09 +02:00
|
|
|
bool LocalPlayer::hasSight(const Position& pos)
|
|
|
|
{
|
2013-01-09 20:29:58 +01:00
|
|
|
return m_position.isInRange(pos, g_map.getAwareRange().left - 1, g_map.getAwareRange().top - 1);
|
2012-08-03 07:05:09 +02:00
|
|
|
}
|