Merge branch '28-quickly-compare-newest-tfs-branch-to-fix-important-bugs' into 'master'

Resolve "Quickly compare newest TFS branch to fix important bugs"

Closes #28

See merge request ErikasKontenis/Sabrehaven!24
This commit is contained in:
Erikas Kontenis 2020-01-02 21:20:25 +00:00
commit dd17e6c42e
15 changed files with 190 additions and 168 deletions

View File

@ -1,6 +1,7 @@
-- Combat settings
-- NOTE: valid values for worldType are: "pvp", "no-pvp" and "pvp-enforced"
worldType = "pvp"
hotkeyAimbotEnabled = true
protectionLevel = 1
pzLocked = 60000
removeChargesFromRunes = true
@ -65,7 +66,7 @@ mysqlSock = ""
-- Misc.
allowChangeOutfit = true
freePremium = false
freePremium = true
kickIdlePlayerAfterMinutes = 15
maxMessageBuffer = 4
showMonsterLoot = false

View File

@ -30,6 +30,7 @@ SET time_zone = "+00:00";
CREATE TABLE `accounts` (
`id` int(11) NOT NULL,
`name` int(11) NOT NULL,
`password` char(40) NOT NULL,
`type` int(11) NOT NULL DEFAULT '1',
`premdays` int(11) NOT NULL DEFAULT '0',
@ -40,8 +41,8 @@ CREATE TABLE `accounts` (
-- Dumping data for table `accounts`
--
INSERT INTO `accounts` (`id`, `password`, `type`, `premdays`, `lastday`) VALUES
(1234567, '41da8bef22aaef9d7c5821fa0f0de7cccc4dda4d', 5, 497, 1547320555);
INSERT INTO `accounts` (`id`, `name`, `password`, `type`, `premdays`, `lastday`) VALUES
(1, 1234567, '41da8bef22aaef9d7c5821fa0f0de7cccc4dda4d', 5, 497, 1547320555);
-- --------------------------------------------------------
@ -7638,7 +7639,8 @@ INSERT INTO `tile_store` (`house_id`, `data`) VALUES
-- Indexes for table `accounts`
--
ALTER TABLE `accounts`
ADD PRIMARY KEY (`id`);
ADD PRIMARY KEY (`id`)
ADD UNIQUE KEY `name` (`name`);
--
-- Indexes for table `account_bans`

View File

@ -24,6 +24,7 @@
struct Account {
std::vector<std::string> characters;
uint32_t name;
time_t lastDay = 0;
uint32_t id = 0;
uint16_t premiumDays = 0;

View File

@ -1235,12 +1235,11 @@ bool ConditionLight::executeCondition(Creature* creature, int32_t interval)
if (internalLightTicks >= lightChangeInterval) {
internalLightTicks = 0;
LightInfo creatureLight;
creature->getCreatureLight(creatureLight);
LightInfo lightInfo = creature->getCreatureLight();
if (creatureLight.level > 0) {
--creatureLight.level;
creature->setCreatureLight(creatureLight);
if (lightInfo.level > 0) {
--lightInfo.level;
creature->setCreatureLight(lightInfo);
g_game.changeLight(creature);
}
}

View File

@ -129,6 +129,19 @@ enum FluidTypes_t : uint8_t
FLUID_FRUITJUICE,
};
const uint8_t reverseFluidMap[] = {
FLUID_NONE,
FLUID_WATER,
FLUID_MANAFLUID,
FLUID_BEER,
FLUID_NONE,
FLUID_LIFEFLUID,
FLUID_SLIME,
FLUID_NONE,
FLUID_LEMONADE,
FLUID_MILK,
};
enum FluidColor_t : uint8_t
{
FLUID_COLOR_NONE = 0,

View File

@ -1085,7 +1085,7 @@ void Creature::onGainExperience(uint64_t gainExp, Creature* target)
void Creature::addSummon(Creature* creature)
{
creature->setDropLoot(false);
creature->setLossSkill(false);
creature->setSkillLoss(false);
creature->setMaster(this);
creature->incrementReferenceCounter();
summons.push_back(creature);
@ -1096,7 +1096,7 @@ void Creature::removeSummon(Creature* creature)
auto cit = std::find(summons.begin(), summons.end(), creature);
if (cit != summons.end()) {
creature->setDropLoot(true);
creature->setLossSkill(true);
creature->setSkillLoss(true);
creature->setMaster(nullptr);
creature->decrementReferenceCounter();
summons.erase(cit);
@ -1364,9 +1364,9 @@ int64_t Creature::getEventStepTicks(bool onlyDelay) const
return ret;
}
void Creature::getCreatureLight(LightInfo& light) const
LightInfo Creature::getCreatureLight() const
{
light = internalLight;
return internalLight;
}
void Creature::setNormalCreatureLight()

View File

@ -355,7 +355,7 @@ class Creature : virtual public Thing
virtual void onAttackedCreatureChangeZone(ZoneType_t zone);
virtual void onIdleStatus();
virtual void getCreatureLight(LightInfo& light) const;
virtual LightInfo getCreatureLight() const;
virtual void setNormalCreatureLight();
void setCreatureLight(LightInfo light) {
internalLight = light;
@ -395,7 +395,7 @@ class Creature : virtual public Thing
void setDropLoot(bool lootDrop) {
this->lootDrop = lootDrop;
}
void setLossSkill(bool skillLoss) {
void setSkillLoss(bool skillLoss) {
this->skillLoss = skillLoss;
}

View File

@ -232,7 +232,7 @@ Thing* Game::internalGetThing(Player* player, const Position& pos, int32_t index
}
case STACKPOS_USETARGET: {
thing = tile->getTopCreature();
thing = tile->getTopVisibleCreature(player);
if (!thing) {
thing = tile->getUseItem(index);
}
@ -280,9 +280,10 @@ Thing* Game::internalGetThing(Player* player, const Position& pos, int32_t index
}
int32_t subType;
if (it.isFluidContainer()) {
subType = static_cast<FluidTypes_t>(index);
} else {
if (it.isFluidContainer() && index < static_cast<int32_t>(sizeof(reverseFluidMap) / sizeof(uint8_t))) {
subType = reverseFluidMap[index];
}
else {
subType = -1;
}
@ -501,15 +502,15 @@ bool Game::placeCreature(Creature* creature, const Position& pos, bool extendedP
return false;
}
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true);
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), true);
}
}
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
spectator->onCreatureAppear(creature, true);
}
@ -530,9 +531,9 @@ bool Game::removeCreature(Creature* creature, bool isLogout/* = true*/)
std::vector<int32_t> oldStackPosVector;
SpectatorVec list;
map.getSpectators(list, tile->getPosition(), true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, tile->getPosition(), true);
for (Creature* spectator : spectators) {
if (Player* player = spectator->getPlayer()) {
oldStackPosVector.push_back(player->canSeeCreature(creature) ? tile->getStackposOfCreature(player, creature) : -1);
}
@ -544,14 +545,14 @@ bool Game::removeCreature(Creature* creature, bool isLogout/* = true*/)
//send to client
size_t i = 0;
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* player = spectator->getPlayer()) {
player->sendRemoveTileThing(tilePosition, oldStackPosVector[i++]);
}
}
//event method
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
spectator->onRemoveCreature(creature, isLogout);
}
@ -564,7 +565,7 @@ bool Game::removeCreature(Creature* creature, bool isLogout/* = true*/)
removeCreatureCheck(creature);
for (Creature* summon : creature->summons) {
summon->setLossSkill(false);
summon->setSkillLoss(false);
removeCreature(summon);
}
return true;
@ -1823,6 +1824,11 @@ void Game::playerOpenPrivateChannel(uint32_t playerId, std::string& receiver)
return;
}
if (player->getName() == receiver) {
player->sendCancelMessage("You cannot set up a private message channel with yourself.");
return;
}
player->sendOpenPrivateChannel(receiver);
}
@ -2450,10 +2456,10 @@ void Game::playerAcceptTrade(uint32_t playerId)
player->setTradeState(TRADE_ACCEPT);
if (tradePartner->getTradeState() == TRADE_ACCEPT) {
Item* tradeItem1 = player->tradeItem;
Item* tradeItem2 = tradePartner->tradeItem;
Item* playerTradeItem = player->tradeItem;
Item* partnerTradeItem = tradePartner->tradeItem;
if (!g_events->eventPlayerOnTradeAccept(player, tradePartner, tradeItem1, tradeItem2)) {
if (!g_events->eventPlayerOnTradeAccept(player, tradePartner, playerTradeItem, partnerTradeItem)) {
internalCloseTrade(player);
return;
}
@ -2461,13 +2467,13 @@ void Game::playerAcceptTrade(uint32_t playerId)
player->setTradeState(TRADE_TRANSFER);
tradePartner->setTradeState(TRADE_TRANSFER);
auto it = tradeItems.find(tradeItem1);
auto it = tradeItems.find(playerTradeItem);
if (it != tradeItems.end()) {
ReleaseItem(it->first);
tradeItems.erase(it);
}
it = tradeItems.find(tradeItem2);
it = tradeItems.find(partnerTradeItem);
if (it != tradeItems.end()) {
ReleaseItem(it->first);
tradeItems.erase(it);
@ -2475,24 +2481,24 @@ void Game::playerAcceptTrade(uint32_t playerId)
bool isSuccess = false;
ReturnValue ret1 = internalAddItem(tradePartner, tradeItem1, INDEX_WHEREEVER, 0, true);
ReturnValue ret2 = internalAddItem(player, tradeItem2, INDEX_WHEREEVER, 0, true);
if (ret1 == RETURNVALUE_NOERROR && ret2 == RETURNVALUE_NOERROR) {
ret1 = internalRemoveItem(tradeItem1, tradeItem1->getItemCount(), true);
ret2 = internalRemoveItem(tradeItem2, tradeItem2->getItemCount(), true);
if (ret1 == RETURNVALUE_NOERROR && ret2 == RETURNVALUE_NOERROR) {
Cylinder* cylinder1 = tradeItem1->getParent();
Cylinder* cylinder2 = tradeItem2->getParent();
ReturnValue tradePartnerRet = internalAddItem(tradePartner, playerTradeItem, INDEX_WHEREEVER, 0, true);
ReturnValue playerRet = internalAddItem(player, partnerTradeItem, INDEX_WHEREEVER, 0, true);
if (tradePartnerRet == RETURNVALUE_NOERROR && playerRet == RETURNVALUE_NOERROR) {
tradePartnerRet = internalRemoveItem(playerTradeItem, playerTradeItem->getItemCount(), true);
playerRet = internalRemoveItem(partnerTradeItem, partnerTradeItem->getItemCount(), true);
if (tradePartnerRet == RETURNVALUE_NOERROR && playerRet == RETURNVALUE_NOERROR) {
Cylinder* cylinder1 = playerTradeItem->getParent();
Cylinder* cylinder2 = partnerTradeItem->getParent();
uint32_t count1 = tradeItem1->getItemCount();
uint32_t count2 = tradeItem2->getItemCount();
uint32_t count1 = playerTradeItem->getItemCount();
uint32_t count2 = partnerTradeItem->getItemCount();
ret1 = internalMoveItem(cylinder1, tradePartner, INDEX_WHEREEVER, tradeItem1, count1, nullptr, FLAG_IGNOREAUTOSTACK, nullptr, tradeItem2);
if (ret1 == RETURNVALUE_NOERROR) {
internalMoveItem(cylinder2, player, INDEX_WHEREEVER, tradeItem2, count2, nullptr, FLAG_IGNOREAUTOSTACK);
tradePartnerRet = internalMoveItem(cylinder1, tradePartner, INDEX_WHEREEVER, playerTradeItem, count1, nullptr, FLAG_IGNOREAUTOSTACK, nullptr, partnerTradeItem);
if (tradePartnerRet == RETURNVALUE_NOERROR) {
internalMoveItem(cylinder2, player, INDEX_WHEREEVER, partnerTradeItem, count2, nullptr, FLAG_IGNOREAUTOSTACK);
tradeItem1->onTradeEvent(ON_TRADE_TRANSFER, tradePartner);
tradeItem2->onTradeEvent(ON_TRADE_TRANSFER, player);
playerTradeItem->onTradeEvent(ON_TRADE_TRANSFER, tradePartner);
partnerTradeItem->onTradeEvent(ON_TRADE_TRANSFER, player);
isSuccess = true;
}
@ -2503,13 +2509,13 @@ void Game::playerAcceptTrade(uint32_t playerId)
std::string errorDescription;
if (tradePartner->tradeItem) {
errorDescription = getTradeErrorDescription(ret1, tradeItem1);
errorDescription = getTradeErrorDescription(tradePartnerRet, playerTradeItem);
tradePartner->sendTextMessage(MESSAGE_EVENT_ADVANCE, errorDescription);
tradePartner->tradeItem->onTradeEvent(ON_TRADE_CANCEL, tradePartner);
}
if (player->tradeItem) {
errorDescription = getTradeErrorDescription(ret2, tradeItem2);
errorDescription = getTradeErrorDescription(playerRet, partnerTradeItem);
player->sendTextMessage(MESSAGE_EVENT_ADVANCE, errorDescription);
player->tradeItem->onTradeEvent(ON_TRADE_CANCEL, player);
}
@ -3004,13 +3010,13 @@ bool Game::playerSaySpell(Player* player, SpeakClasses type, const std::string&
void Game::playerWhisper(Player* player, const std::string& text)
{
SpectatorVec list;
map.getSpectators(list, player->getPosition(), false, false,
SpectatorVec spectators;
map.getSpectators(spectators, player->getPosition(), false, false,
Map::maxClientViewportX, Map::maxClientViewportX,
Map::maxClientViewportY, Map::maxClientViewportY);
//send to client
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* spectatorPlayer = spectator->getPlayer()) {
if (!Position::areInRange<1, 1>(player->getPosition(), spectatorPlayer->getPosition())) {
spectatorPlayer->sendCreatureSay(player, TALKTYPE_WHISPER, "pspsps");
@ -3021,7 +3027,7 @@ void Game::playerWhisper(Player* player, const std::string& text)
}
//event method
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
spectator->onCreatureSay(player, TALKTYPE_WHISPER, text);
}
}
@ -3094,16 +3100,16 @@ bool Game::internalCreatureTurn(Creature* creature, Direction dir)
creature->setDirection(dir);
//send to client
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureTurn(creature);
}
return true;
}
bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std::string& text,
bool ghostMode, SpectatorVec* listPtr/* = nullptr*/, const Position* pos/* = nullptr*/)
bool ghostMode, SpectatorVec* spectatorsPtr/* = nullptr*/, const Position* pos/* = nullptr*/)
{
if (text.empty()) {
return false;
@ -3113,26 +3119,26 @@ bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std:
pos = &creature->getPosition();
}
SpectatorVec list;
SpectatorVec spectators;
if (!listPtr || listPtr->empty()) {
if (!spectatorsPtr || spectatorsPtr->empty()) {
// This somewhat complex construct ensures that the cached SpectatorVec
// is used if available and if it can be used, else a local vector is
// used (hopefully the compiler will optimize away the construction of
// the temporary when it's not used).
if (type != TALKTYPE_YELL && type != TALKTYPE_MONSTER_YELL) {
map.getSpectators(list, *pos, false, false,
map.getSpectators(spectators, *pos, false, false,
Map::maxClientViewportX, Map::maxClientViewportX,
Map::maxClientViewportY, Map::maxClientViewportY);
} else {
map.getSpectators(list, *pos, true, false, 30, 30, 30, 30);
map.getSpectators(spectators, *pos, true, false, 30, 30, 30, 30);
}
} else {
list = (*listPtr);
spectators = (*spectatorsPtr);
}
//send to client
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
if (!ghostMode || tmpPlayer->canSeeCreature(creature)) {
tmpPlayer->sendCreatureSay(creature, type, text, pos);
@ -3141,7 +3147,7 @@ bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std:
}
//event method
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
spectator->onCreatureSay(creature, type, text);
}
return true;
@ -3225,9 +3231,9 @@ void Game::changeSpeed(Creature* creature, int32_t varSpeedDelta)
creature->setSpeed(varSpeedDelta);
//send to clients
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), false, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), false, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed());
}
}
@ -3245,9 +3251,9 @@ void Game::internalCreatureChangeOutfit(Creature* creature, const Outfit_t& outf
}
//send to clients
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureChangeOutfit(creature, outfit);
}
}
@ -3255,9 +3261,9 @@ void Game::internalCreatureChangeOutfit(Creature* creature, const Outfit_t& outf
void Game::internalCreatureChangeVisible(Creature* creature, bool visible)
{
//send to clients
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureChangeVisible(creature, visible);
}
}
@ -3265,9 +3271,9 @@ void Game::internalCreatureChangeVisible(Creature* creature, bool visible)
void Game::changeLight(const Creature* creature)
{
//send to clients
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureLight(creature);
}
}
@ -3464,7 +3470,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
return true;
}
Player* targetPlayer = target->getPlayer();
SpectatorVec list;
SpectatorVec spectators;
if (target->hasCondition(CONDITION_MANASHIELD) && damage.type != COMBAT_UNDEFINEDDAMAGE) {
int32_t manaDamage = std::min<int32_t>(targetPlayer->getMana(), healthChange);
if (manaDamage != 0) {
@ -3482,8 +3488,8 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
}
}
targetPlayer->drainMana(attacker, manaDamage);
map.getSpectators(list, targetPos, true, true);
addMagicEffect(list, targetPos, CONST_ME_LOSEENERGY);
map.getSpectators(spectators, targetPos, true, true);
addMagicEffect(spectators, targetPos, CONST_ME_LOSEENERGY);
std::string damageString = std::to_string(manaDamage);
@ -3501,7 +3507,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
targetPlayer->sendTextMessage(MESSAGE_EVENT_DEFAULT, ss.str());
}
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
Player* tmpPlayer = spectator->getPlayer();
tmpPlayer->sendAnimatedText(targetPos, TEXTCOLOR_BLUE, damageString);
}
@ -3528,8 +3534,8 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
return true;
}
if (list.empty()) {
map.getSpectators(list, targetPos, true, true);
if (spectators.empty()) {
map.getSpectators(spectators, targetPos, true, true);
}
TextColor_t color = TEXTCOLOR_NONE;
@ -3537,7 +3543,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
if (damage.value) {
combatGetTypeInfo(damage.type, target, color, hitEffect);
if (hitEffect != CONST_ME_NONE) {
addMagicEffect(list, targetPos, hitEffect);
addMagicEffect(spectators, targetPos, hitEffect);
}
}
@ -3558,7 +3564,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
}
std::string realDamageStr = std::to_string(realDamage);
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
Player* tmpPlayer = spectator->getPlayer();
tmpPlayer->sendAnimatedText(targetPos, color, realDamageStr);
}
@ -3573,7 +3579,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage
}
target->drainHealth(attacker, realDamage);
addCreatureHealth(list, target);
addCreatureHealth(spectators, target);
}
return true;
@ -3642,8 +3648,8 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage&
std::string damageString = std::to_string(manaLoss);
SpectatorVec list;
map.getSpectators(list, targetPos, false, true);
SpectatorVec spectators;
map.getSpectators(spectators, targetPos, false, true);
if (targetPlayer) {
std::stringstream ss;
if (!attacker) {
@ -3658,7 +3664,7 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage&
targetPlayer->sendTextMessage(MESSAGE_EVENT_DEFAULT, ss.str());
}
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
Player* tmpPlayer = spectator->getPlayer();
tmpPlayer->sendAnimatedText(targetPos, TEXTCOLOR_BLUE, damageString);
}
@ -3669,14 +3675,14 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage&
void Game::addCreatureHealth(const Creature* target)
{
SpectatorVec list;
map.getSpectators(list, target->getPosition(), true, true);
addCreatureHealth(list, target);
SpectatorVec spectators;
map.getSpectators(spectators, target->getPosition(), true, true);
addCreatureHealth(spectators, target);
}
void Game::addCreatureHealth(const SpectatorVec& list, const Creature* target)
void Game::addCreatureHealth(const SpectatorVec& spectators, const Creature* target)
{
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendCreatureHealth(target);
}
@ -3685,14 +3691,14 @@ void Game::addCreatureHealth(const SpectatorVec& list, const Creature* target)
void Game::addMagicEffect(const Position& pos, uint8_t effect)
{
SpectatorVec list;
map.getSpectators(list, pos, true, true);
addMagicEffect(list, pos, effect);
SpectatorVec spectators;
map.getSpectators(spectators, pos, true, true);
addMagicEffect(spectators, pos, effect);
}
void Game::addMagicEffect(const SpectatorVec& list, const Position& pos, uint8_t effect)
void Game::addMagicEffect(const SpectatorVec& spectators, const Position& pos, uint8_t effect)
{
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendMagicEffect(pos, effect);
}
@ -3701,15 +3707,15 @@ void Game::addMagicEffect(const SpectatorVec& list, const Position& pos, uint8_t
void Game::addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect)
{
SpectatorVec list;
map.getSpectators(list, fromPos, false, true);
map.getSpectators(list, toPos, false, true);
addDistanceEffect(list, fromPos, toPos, effect);
SpectatorVec spectators;
map.getSpectators(spectators, fromPos, false, true);
map.getSpectators(spectators, toPos, false, true);
addDistanceEffect(spectators, fromPos, toPos, effect);
}
void Game::addDistanceEffect(const SpectatorVec& list, const Position& fromPos, const Position& toPos, uint8_t effect)
void Game::addDistanceEffect(const SpectatorVec& spectators, const Position& fromPos, const Position& toPos, uint8_t effect)
{
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendDistanceShoot(fromPos, toPos, effect);
}
@ -3718,14 +3724,14 @@ void Game::addDistanceEffect(const SpectatorVec& list, const Position& fromPos,
void Game::addAnimatedText(const Position& pos, uint8_t color, const std::string& text)
{
SpectatorVec list;
map.getSpectators(list, pos, false, true);
addAnimatedText(list, pos, color, text);
SpectatorVec spectators;
map.getSpectators(spectators, pos, false, true);
addAnimatedText(spectators, pos, color, text);
}
void Game::addAnimatedText(const SpectatorVec& list, const Position& pos, uint8_t color, const std::string& text)
void Game::addAnimatedText(const SpectatorVec& spectators, const Position& pos, uint8_t color, const std::string& text)
{
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendAnimatedText(pos, color, text);
}
@ -3734,10 +3740,10 @@ void Game::addAnimatedText(const SpectatorVec& list, const Position& pos, uint8_
void Game::addMonsterSayText(const Position& pos, const std::string& text)
{
SpectatorVec list;
map.getSpectators(list, pos, false, true);
SpectatorVec spectators;
map.getSpectators(spectators, pos, false, true);
for (Creature* spectator : list) {
for (Creature* spectator : spectators) {
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendCreatureSay(tmpPlayer, TALKTYPE_MONSTER_SAY, text, &pos);
}
@ -3867,8 +3873,7 @@ void Game::checkLight()
}
if (lightChange) {
LightInfo lightInfo;
getWorldLightInfo(lightInfo);
LightInfo lightInfo = getWorldLightInfo();
for (const auto& it : players) {
it.second->sendWorldLight(lightInfo);
@ -3876,10 +3881,9 @@ void Game::checkLight()
}
}
void Game::getWorldLightInfo(LightInfo& lightInfo) const
LightInfo Game::getWorldLightInfo() const
{
lightInfo.level = lightLevel;
lightInfo.color = 0xD7;
return { lightLevel, 0xD7 };
}
void Game::shutdown()
@ -3952,18 +3956,18 @@ void Game::updateCreatureSkull(const Creature* creature)
return;
}
SpectatorVec list;
map.getSpectators(list, creature->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureSkull(creature);
}
}
void Game::updatePlayerShield(Player* player)
{
SpectatorVec list;
map.getSpectators(list, player->getPosition(), true, true);
for (Creature* spectator : list) {
SpectatorVec spectators;
map.getSpectators(spectators, player->getPosition(), true, true);
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendCreatureShield(player);
}
}
@ -4137,6 +4141,10 @@ bool Game::loadExperienceStages()
void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId)
{
if (playerId == invitedId) {
return;
}
Player* player = getPlayerByID(playerId);
if (!player) {
return;

View File

@ -244,7 +244,7 @@ class Game
return playersRecord;
}
void getWorldLightInfo(LightInfo& lightInfo) const;
LightInfo getWorldLightInfo() const;
ReturnValue internalMoveCreature(Creature* creature, Direction direction, uint32_t flags = 0);
ReturnValue internalMoveCreature(Creature& creature, Tile& toTile, uint32_t flags = 0);
@ -322,7 +322,7 @@ class Game
* \param text The text to say
*/
bool internalCreatureSay(Creature* creature, SpeakClasses type, const std::string& text,
bool ghostMode, SpectatorVec* listPtr = nullptr, const Position* pos = nullptr);
bool ghostMode, SpectatorVec* spectatorsPtr = nullptr, const Position* pos = nullptr);
void loadPlayersRecord();
void checkPlayersRecord();

View File

@ -31,13 +31,14 @@ Account IOLoginData::loadAccount(uint32_t accno)
Account account;
std::ostringstream query;
query << "SELECT `id`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `id` = " << accno;
query << "SELECT `id`, `name`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `id` = " << accno;
DBResult_ptr result = Database::getInstance()->storeQuery(query.str());
if (!result) {
return account;
}
account.id = result->getNumber<uint32_t>("id");
account.name = result->getNumber<uint32_t>("name");
account.accountType = static_cast<AccountType_t>(result->getNumber<int32_t>("type"));
account.premiumDays = result->getNumber<uint16_t>("premdays");
account.lastDay = result->getNumber<time_t>("lastday");
@ -51,12 +52,12 @@ bool IOLoginData::saveAccount(const Account& acc)
return Database::getInstance()->executeQuery(query.str());
}
bool IOLoginData::loginserverAuthentication(uint32_t accountNumber, const std::string& password, Account& account)
bool IOLoginData::loginserverAuthentication(uint32_t accountName, const std::string& password, Account& account)
{
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `id`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `id` = " << accountNumber;
query << "SELECT `id`, `name`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `name` = " << accountName;
DBResult_ptr result = db->storeQuery(query.str());
if (!result) {
return false;
@ -67,6 +68,7 @@ bool IOLoginData::loginserverAuthentication(uint32_t accountNumber, const std::s
}
account.id = result->getNumber<uint32_t>("id");
account.name = result->getNumber<uint32_t>("name");
account.accountType = static_cast<AccountType_t>(result->getNumber<int32_t>("type"));
account.premiumDays = result->getNumber<uint16_t>("premdays");
account.lastDay = result->getNumber<time_t>("lastday");
@ -85,12 +87,12 @@ bool IOLoginData::loginserverAuthentication(uint32_t accountNumber, const std::s
return true;
}
uint32_t IOLoginData::gameworldAuthentication(uint32_t accountNumber, const std::string& password, std::string& characterName)
uint32_t IOLoginData::gameworldAuthentication(uint32_t accountName, const std::string& password, std::string& characterName)
{
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `id`, `password` FROM `accounts` WHERE `id` = " << accountNumber;
query << "SELECT `id`, `password` FROM `accounts` WHERE `name` = " << accountName;
DBResult_ptr result = db->storeQuery(query.str());
if (!result) {
return 0;

View File

@ -32,8 +32,8 @@ class IOLoginData
static Account loadAccount(uint32_t accno);
static bool saveAccount(const Account& acc);
static bool loginserverAuthentication(uint32_t accountNumber, const std::string& password, Account& account);
static uint32_t gameworldAuthentication(uint32_t accountNumber, const std::string& password, std::string& characterName);
static bool loginserverAuthentication(uint32_t accountName, const std::string& password, Account& account);
static uint32_t gameworldAuthentication(uint32_t accountName, const std::string& password, std::string& characterName);
static AccountType_t getAccountType(uint32_t accountId);
static void setAccountType(uint32_t accountId, AccountType_t accountType);

View File

@ -2796,8 +2796,7 @@ int LuaScriptInterface::luaGetWorldTime(lua_State* L)
int LuaScriptInterface::luaGetWorldLight(lua_State* L)
{
//getWorldLight()
LightInfo lightInfo;
g_game.getWorldLightInfo(lightInfo);
LightInfo lightInfo = g_game.getWorldLightInfo();
lua_pushnumber(L, lightInfo.level);
lua_pushnumber(L, lightInfo.color);
return 2;
@ -6481,10 +6480,9 @@ int LuaScriptInterface::luaCreatureGetLight(lua_State* L)
return 1;
}
LightInfo light;
creature->getCreatureLight(light);
lua_pushnumber(L, light.level);
lua_pushnumber(L, light.color);
LightInfo lightInfo = creature->getCreatureLight();
lua_pushnumber(L, lightInfo.level);
lua_pushnumber(L, lightInfo.color);
return 2;
}

View File

@ -1768,7 +1768,7 @@ void Player::death(Creature* lastHitCreature)
}
}
} else {
setLossSkill(true);
setSkillLoss(true);
auto it = conditions.begin(), end = conditions.end();
while (it != end) {
@ -2911,13 +2911,12 @@ void Player::stopWalk()
cancelNextWalk = true;
}
void Player::getCreatureLight(LightInfo& light) const
LightInfo Player::getCreatureLight() const
{
if (internalLight.level > itemsLight.level) {
light = internalLight;
} else {
light = itemsLight;
return internalLight;
}
return itemsLight;
}
void Player::updateItemsLight(bool internal /*=false*/)
@ -3140,7 +3139,7 @@ bool Player::onKilledCreature(Creature* target, bool lastHit/* = true*/)
if (Player* targetPlayer = target->getPlayer()) {
if (targetPlayer && targetPlayer->getZone() == ZONE_PVP) {
targetPlayer->setDropLoot(false);
targetPlayer->setLossSkill(false);
targetPlayer->setSkillLoss(false);
} else if (!hasFlag(PlayerFlag_NotGainInFight) && !isPartner(targetPlayer)) {
if (!Combat::isInPvpZone(this, targetPlayer) && hasAttacked(targetPlayer) && !targetPlayer->hasAttacked(this) && targetPlayer != this) {
if (targetPlayer->getSkull() == SKULL_NONE && !isInWar(targetPlayer)) {
@ -3392,26 +3391,29 @@ Skulls_t Player::getSkullClient(const Creature* creature) const
}
const Player* player = creature->getPlayer();
if (player && player->getSkull() == SKULL_NONE) {
if (isInWar(player)) {
return SKULL_GREEN;
}
if (!player || player->getSkull() != SKULL_NONE) {
return Creature::getSkullClient(creature);
}
if (!player->getGuildWarList().empty() && guild == player->getGuild()) {
return SKULL_GREEN;
}
if (isInWar(player)) {
return SKULL_GREEN;
}
if (player->hasAttacked(this)) {
return SKULL_YELLOW;
}
if (!player->getGuildWarList().empty() && guild == player->getGuild()) {
return SKULL_GREEN;
}
if (isPartner(player)) {
return SKULL_GREEN;
}
if (player->hasAttacked(this)) {
return SKULL_YELLOW;
}
if (isPartner(player)) {
return SKULL_GREEN;
}
return Creature::getSkullClient(creature);
}
bool Player::hasAttacked(const Player* attacked) const
{
if (hasFlag(PlayerFlag_NotGainInFight) || !attacked) {
@ -3634,7 +3636,7 @@ bool Player::isInviting(const Player* player) const
bool Player::isPartner(const Player* player) const
{
if (!player || !party) {
if (!player || !party || player == this) {
return false;
}
return party == player->party;

View File

@ -559,7 +559,7 @@ class Player final : public Creature, public Cylinder
void onIdleStatus() final;
void onPlacedCreature() final;
void getCreatureLight(LightInfo& light) const final;
LightInfo getCreatureLight() const override;
Skulls_t getSkull() const final;
Skulls_t getSkullClient(const Creature* creature) const final;

View File

@ -1594,9 +1594,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos
sendSkills();
//gameworld light-settings
LightInfo lightInfo;
g_game.getWorldLightInfo(lightInfo);
sendWorldLight(lightInfo);
sendWorldLight(g_game.getWorldLightInfo());
//player light level
sendCreatureLight(creature);
@ -1871,8 +1869,7 @@ void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bo
AddOutfit(msg, outfit);
}
LightInfo lightInfo;
creature->getCreatureLight(lightInfo);
LightInfo lightInfo = creature->getCreatureLight();
msg.addByte(player->isAccessPlayer() ? 0xFF : lightInfo.level);
msg.addByte(lightInfo.color);
@ -1941,8 +1938,7 @@ void ProtocolGame::AddWorldLight(NetworkMessage& msg, const LightInfo& lightInfo
void ProtocolGame::AddCreatureLight(NetworkMessage& msg, const Creature* creature)
{
LightInfo lightInfo;
creature->getCreatureLight(lightInfo);
LightInfo lightInfo = creature->getCreatureLight();
msg.addByte(0x8D);
msg.add<uint32_t>(creature->getID());