finish market system

This commit is contained in:
ErikasKontenis 2022-04-10 22:15:53 +03:00
parent fadbf8b64d
commit 6e6b2dc4a6
25 changed files with 2670 additions and 1166 deletions

View File

@ -740,19 +740,6 @@ local function onMarketMessage(messageMode, message)
Market.displayMessage(message) Market.displayMessage(message)
end end
local function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local function initMarketItems(items) local function initMarketItems(items)
for c = MarketCategory.First, MarketCategory.Last do for c = MarketCategory.First, MarketCategory.Last do
marketItems[c] = {} marketItems[c] = {}

View File

@ -24,7 +24,7 @@ local function readMarketOffer(msg, action, var)
end end
local amount = msg:getU16() local amount = msg:getU16()
local price = msg:getU32() local price = msg:getU64()
local playerName local playerName
local state = MarketOfferState.Active local state = MarketOfferState.Active
if var == MarketRequest.MyHistory then if var == MarketRequest.MyHistory then
@ -52,14 +52,12 @@ end
-- parsing protocols -- parsing protocols
local function parseMarketEnter(protocol, msg) local function parseMarketEnter(protocol, msg)
local version = 981
local items = {} local items = {}
table.insert(items, {
table.insert(items, { id = 3264,
id = 3264, category = 20,
category = 20, name = "sword"
name = "sword" })
})
local vocation = -1 local vocation = -1
local offers = msg:getU8() local offers = msg:getU8()
@ -73,9 +71,7 @@ table.insert(items, {
depotItems[itemId] = itemCount depotItems[itemId] = itemCount
end end
print(dump(depotItems))
signalcall(Market.onMarketEnter, depotItems, offers, balance, vocation, items) signalcall(Market.onMarketEnter, depotItems, offers, balance, vocation, items)
--signalcall(Market.onMarketEnter, depotItems, offers, balance, vocation, items)
return true return true
end end
@ -85,11 +81,8 @@ local function parseMarketLeave(protocol, msg)
end end
local function parseMarketDetail(protocol, msg) local function parseMarketDetail(protocol, msg)
print("DETAILS")
local itemId = msg:getU16() local itemId = msg:getU16()
print (itemId + "assadsd")
local descriptions = {} local descriptions = {}
table.insert(descriptions, {2, "28"})
for i = MarketItemDescription.First, MarketItemDescription.Last do for i = MarketItemDescription.First, MarketItemDescription.Last do
if msg:peekU16() ~= 0x00 then if msg:peekU16() ~= 0x00 then
table.insert(descriptions, {i, msg:getString()}) -- item descriptions table.insert(descriptions, {i, msg:getString()}) -- item descriptions
@ -112,9 +105,9 @@ print("DETAILS")
local count = msg:getU8() local count = msg:getU8()
for i=1, count do for i=1, count do
local transactions = msg:getU32() -- transaction count local transactions = msg:getU32() -- transaction count
local totalPrice = msg:getU32() -- total price local totalPrice = msg:getU64() -- total price
local highestPrice = msg:getU32() -- highest price local highestPrice = msg:getU64() -- highest price
local lowestPrice = msg:getU32() -- lowest price local lowestPrice = msg:getU64() -- lowest price
local tmp = time - statistics.SECONDS_PER_DAY local tmp = time - statistics.SECONDS_PER_DAY
table.insert(purchaseStats, OfferStatistic.new(tmp, MarketAction.Buy, transactions, totalPrice, highestPrice, lowestPrice)) table.insert(purchaseStats, OfferStatistic.new(tmp, MarketAction.Buy, transactions, totalPrice, highestPrice, lowestPrice))
@ -124,9 +117,9 @@ print("DETAILS")
count = msg:getU8() count = msg:getU8()
for i=1, count do for i=1, count do
local transactions = msg:getU32() -- transaction count local transactions = msg:getU32() -- transaction count
local totalPrice = msg:getU32() -- total price local totalPrice = msg:getU64() -- total price
local highestPrice = msg:getU32() -- highest price local highestPrice = msg:getU64() -- highest price
local lowestPrice = msg:getU32() -- lowest price local lowestPrice = msg:getU64() -- lowest price
local tmp = time - statistics.SECONDS_PER_DAY local tmp = time - statistics.SECONDS_PER_DAY
table.insert(saleStats, OfferStatistic.new(tmp, MarketAction.Sell, transactions, totalPrice, highestPrice, lowestPrice)) table.insert(saleStats, OfferStatistic.new(tmp, MarketAction.Sell, transactions, totalPrice, highestPrice, lowestPrice))
@ -242,7 +235,7 @@ function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, ano
msg:addU8(type) msg:addU8(type)
msg:addU16(spriteId) msg:addU16(spriteId)
msg:addU16(amount) msg:addU16(amount)
msg:addU32(price) msg:addU64(price)
msg:addU8(anonymous) msg:addU8(anonymous)
send(msg) send(msg)
else else

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -25,4 +25,5 @@
<event class="Player" method="onGainExperience" enabled="1" /> <event class="Player" method="onGainExperience" enabled="1" />
<event class="Player" method="onLoseExperience" enabled="0" /> <event class="Player" method="onLoseExperience" enabled="0" />
<event class="Player" method="onGainSkillTries" enabled="1" /> <event class="Player" method="onGainSkillTries" enabled="1" />
<event class="Player" method="onLookInMarket" enabled="1" />
</events> </events>

View File

@ -218,6 +218,293 @@ function Player:onLookInTrade(partner, item, distance)
self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance)) self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
end end
local showAtkWeaponTypes = {WEAPON_CLUB, WEAPON_SWORD, WEAPON_AXE, WEAPON_DISTANCE}
local showDefWeaponTypes = {WEAPON_CLUB, WEAPON_SWORD, WEAPON_AXE, WEAPON_DISTANCE, WEAPON_SHIELD}
function Player:onLookInMarket(itemType)
local response = NetworkMessage()
response:addByte(0xF8)
response:addU16(itemType:getId())
-- armor
do
local armor = itemType:getArmor()
if armor > 0 then
response:addString(armor)
else
response:addU16(0)
end
end
-- weapon data (will be reused)
local weaponType = itemType:getWeaponType()
-- attack
do
local showAtk = table.contains(showAtkWeaponTypes, weaponType)
if showAtk then
local atkAttrs = {}
local atk = itemType:getAttack()
if itemType:isBow() then
if atk ~= 0 then
atkAttrs[#atkAttrs + 1] = string.format("%+d", atk)
end
local hitChance = itemType:getHitChance()
if hitChance ~= 0 then
atkAttrs[#atkAttrs + 1] = string.format("chance to hit %+d%%", hitChance)
end
atkAttrs[#atkAttrs + 1] = string.format("%d fields", itemType:getShootRange())
else
atkAttrs[#atkAttrs + 1] = atk
local elementDmg = 0
if elementDmg ~= 0 then
atkAttrs[#atkAttrs] = string.format("%d physical %+d %s", atkAttrs[#atkAttrs], elementDmg, getCombatName(itemType:getElementType()))
end
end
response:addString(table.concat(atkAttrs, ", "))
else
response:addU16(0)
end
end
-- container slots
do
if itemType:isContainer() then
response:addString(itemType:getCapacity())
else
response:addU16(0)
end
end
-- defense
do
local showDef = table.contains(showDefWeaponTypes, weaponType)
if showDef then
local def = itemType:getDefense()
if weaponType == WEAPON_DISTANCE then
-- throwables
if ammoType ~= AMMO_ARROW and ammoType ~= AMMO_BOLT then
response:addString(def)
else
response:addU16(0)
end
else
-- extra def
--local xD = itemType:getExtraDefense()
--if xD ~= 0 then
-- def = string.format("%d %+d", def, xD)
--end
response:addString(def)
end
else
response:addU16(0)
end
end
-- description
do
local desc = itemType:getDescription()
if desc and #desc > 0 then
response:addString(desc:sub(1, -2))
else
response:addU16(0)
end
end
-- duration
do
local duration = itemType:getDuration()
if duration == 0 then
local transferType = itemType:getTransformEquipId()
if transferType ~= 0 then
transferType = ItemType(transferType)
duration = transferType and transferType:getDuration() or duration
end
end
if duration > 0 then
response:addString(Game.getCountdownString(duration, true, true))
else
response:addU16(0)
end
end
-- item abilities (will be reused)
local abilities = itemType:getAbilities()
-- element protections
do
local protections = {}
for element, value in pairs(abilities.absorbPercent) do
if value ~= 0 then
protections[#protections + 1] = string.format("%s %+d%%", getCombatName(2 ^ (element - 1)), value)
end
end
if #protections > 0 then
response:addString(table.concat(protections, ", "))
else
response:addU16(0)
end
end
-- level req
do
local minLevel = itemType:getMinReqLevel()
if minLevel > 0 then
response:addString(minLevel)
else
response:addU16(0)
end
end
-- magic level req
do
local minMagicLevel = itemType:getMinReqMagicLevel()
if minMagicLevel > 0 then
response:addString(minMagicLevel)
else
response:addU16(0)
end
end
-- vocation
do
local vocations = itemType:getVocationString()
if vocations and vocations:len() > 0 then
response:addString(vocations)
else
response:addU16(0)
end
end
-- rune words
do
local spellName = itemType:getRuneSpellName()
if spellName and spellName:len() > 0 then
response:addString(spellName)
else
response:addU16(0)
end
end
-- "skill boost" category
do
-- skill boost
local skillBoosts = {}
if abilities.manaGain > 0 or abilities.healthGain > 0 or abilities.regeneration then
skillBoosts[#skillBoosts + 1] = "faster regeneration"
end
-- invisibility
if abilities.invisible then
skillBoosts[#skillBoosts + 1] = "invisibility"
end
-- magic shield (classic)
if abilities.manaShield then
skillBoosts[#skillBoosts + 1] = "magic shield"
end
-- stats (hp/mp/soul/ml)
for stat, value in pairs(abilities.stats) do
if value ~= 0 then
skillBoosts[#skillBoosts + 1] = string.format("%s %+d", getStatName(stat - 1), value)
end
end
-- stats but in %
for stat, value in pairs(abilities.statsPercent) do
if value ~= 0 then
skillBoosts[#skillBoosts + 1] = string.format("%s %+d%%", getStatName(stat - 1), value)
end
end
-- speed
if abilities.speed ~= 0 then
skillBoosts[#skillBoosts + 1] = string.format("speed %+d", math.floor(abilities.speed / 2))
end
-- skills
for skill, value in pairs(abilities.skills) do
if value ~= 0 then
skillBoosts[#skillBoosts + 1] = string.format("%s %+d", getSkillName(skill - 1), value)
end
end
-- add to response
if #skillBoosts > 0 then
response:addString(table.concat(skillBoosts, ", "))
else
response:addU16(0)
end
end
-- charges
do
if itemType:hasShowCharges() then
response:addString(itemType:getCharges())
else
response:addU16(0)
end
end
-- weapon type
do
if itemType:isWeapon() then
response:addString(itemType:getWeaponString())
else
response:addU16(0)
end
end
-- weight
response:addString(string.format("%0.2f", itemType:getWeight() / 100))
-- to do
response:addU16(0) -- Imbuement Slots
response:addU16(0) -- Magic Shield Capacity
response:addU16(0) -- Cleave
response:addU16(0) -- Damage Reflection
response:addU16(0) -- Perfect Shot
response:addU16(0) -- Classification
response:addU16(0) -- Tier
-- buy stats
do
local stats = itemType:getMarketBuyStatistics()
if stats then
response:addByte(0x01)
response:addU32(stats.numTransactions)
response:addU64(stats.totalPrice)
response:addU64(stats.highestPrice)
response:addU64(stats.lowestPrice)
else
response:addByte(0x00)
end
end
-- sell stats
do
local stats = itemType:getMarketSellStatistics()
if stats then
response:addByte(0x01)
response:addU32(stats.numTransactions)
response:addU64(stats.totalPrice)
response:addU64(stats.highestPrice)
response:addU64(stats.lowestPrice)
else
response:addByte(0x00)
end
end
response:sendToPlayer(self)
end
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder) function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
return true return true
end end

View File

@ -138,7 +138,8 @@ function onStartup()
db.asyncQuery("DELETE FROM `guild_wars` WHERE `status` = 0") db.asyncQuery("DELETE FROM `guild_wars` WHERE `status` = 0")
db.asyncQuery("DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < " .. os.time()) db.asyncQuery("DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < " .. os.time())
db.asyncQuery("DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time()) db.asyncQuery("DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
db.asyncQuery("DELETE FROM `market_history` WHERE `inserted` <= " .. (os.time() - configManager.getNumber(configKeys.MARKET_OFFER_DURATION)))
-- Move expired bans to ban history -- Move expired bans to ban history
local resultId = db.storeQuery("SELECT * FROM `account_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time()) local resultId = db.storeQuery("SELECT * FROM `account_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
if resultId ~= false then if resultId ~= false then

View File

@ -14,3 +14,105 @@ local slotBits = {
function ItemType.usesSlot(self, slot) function ItemType.usesSlot(self, slot)
return bit.band(self:getSlotPosition(), slotBits[slot] or 0) ~= 0 return bit.band(self:getSlotPosition(), slotBits[slot] or 0) ~= 0
end end
function ItemType.isHelmet(self)
return self:usesSlot(CONST_SLOT_HEAD)
end
function ItemType.isArmor(self)
return self:usesSlot(CONST_SLOT_ARMOR)
end
function ItemType.isLegs(self)
return self:usesSlot(CONST_SLOT_LEGS)
end
function ItemType.isBoots(self)
return self:usesSlot(CONST_SLOT_FEET)
end
local notWeapons = {WEAPON_NONE, WEAPON_SHIELD, WEAPON_AMMO}
function ItemType.isWeapon(self)
return not table.contains(notWeapons, self:getWeaponType())
end
function ItemType.isTwoHanded(self)
return bit.band(self:getSlotPosition(), SLOTP_TWO_HAND) ~= 0
end
function ItemType.isBow(self)
local ammoType = self:getAmmoType()
return self:getWeaponType() == WEAPON_DISTANCE and (ammoType == AMMO_ARROW or ammoType == AMMO_BOLT)
end
function ItemType.isMissile(self)
local ammoType = self:getAmmoType()
return self:getWeaponType() == WEAPON_DISTANCE and ammoType ~= AMMO_ARROW and ammoType ~= AMMO_BOLT
end
function ItemType.isWand(self)
return self:getWeaponType() == WEAPON_WAND
end
function ItemType.isShield(self)
return self:getWeaponType() == WEAPON_SHIELD
end
function ItemType.isBackpack(self)
return self:usesSlot(CONST_SLOT_BACKPACK)
end
function ItemType.isNecklace(self)
return self:usesSlot(CONST_SLOT_NECKLACE)
end
function ItemType.isRing(self)
return self:usesSlot(CONST_SLOT_RING)
end
function ItemType.isAmmo(self)
return self:getWeaponType() == WEAPON_AMMO
end
function ItemType.isTrinket(self)
return self:usesSlot(CONST_SLOT_AMMO) and self:getWeaponType() == WEAPON_NONE
end
function ItemType.isKey(self)
return self:getType() == ITEM_TYPE_KEY
end
function ItemType.isBed(self)
return self:getType() == ITEM_TYPE_BED
end
function ItemType.isSplash(self)
return self:getGroup() == ITEM_GROUP_SPLASH
end
function ItemType.isPodium(self)
return self:getGroup() == ITEM_GROUP_PODIUM
end
function ItemType.getWeaponString(self)
local weaponType = self:getWeaponType()
local weaponString = "unknown"
if weaponType == WEAPON_CLUB then
weaponString = "blunt instrument"
elseif weaponType == WEAPON_SWORD then
weaponString = "stabbing weapon"
elseif weaponType == WEAPON_AXE then
weaponString = "cutting weapon"
elseif weaponType == WEAPON_DISTANCE then
weaponString = self:isBow() and "firearm" or "missile"
elseif weaponType == WEAPON_WAND then
weaponString = "wand/rod"
end
if self:isTwoHanded() then
weaponString = string.format("%s, two-handed", weaponString)
end
return weaponString
end

View File

@ -283,7 +283,6 @@ enum item_t : uint16_t {
ITEM_DEPOT = 3502, ITEM_DEPOT = 3502,
ITEM_LOCKER1 = 3497, ITEM_LOCKER1 = 3497,
ITEM_INBOX = 7476,
ITEM_MARKET = 7477, ITEM_MARKET = 7477,
ITEM_MALE_CORPSE = 4240, ITEM_MALE_CORPSE = 4240,

View File

@ -19,8 +19,6 @@
#include "otpch.h" #include "otpch.h"
#include "depotchest.h"
#include "inbox.h"
#include "container.h" #include "container.h"
#include "iomap.h" #include "iomap.h"
#include "game.h" #include "game.h"
@ -273,10 +271,6 @@ ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t coun
return RETURNVALUE_THISISIMPOSSIBLE; return RETURNVALUE_THISISIMPOSSIBLE;
} }
if (dynamic_cast<const Inbox*>(cylinder)) {
return RETURNVALUE_CONTAINERNOTENOUGHROOM;
}
cylinder = cylinder->getParent(); cylinder = cylinder->getParent();
} }

View File

@ -23,7 +23,6 @@
#include "creature.h" #include "creature.h"
#include "player.h" #include "player.h"
#include "tools.h" #include "tools.h"
#include "inbox.h"
DepotLocker::DepotLocker(uint16_t type) : DepotLocker::DepotLocker(uint16_t type) :
Container(type, 30), depotId(0) {} Container(type, 30), depotId(0) {}
@ -87,13 +86,4 @@ void DepotLocker::postRemoveNotification(Thing* thing, const Cylinder* newParent
if (parent != nullptr) { if (parent != nullptr) {
parent->postRemoveNotification(thing, newParent, index, LINK_PARENT); parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
} }
} }
void DepotLocker::removeInbox(Inbox* inbox)
{
auto cit = std::find(itemlist.begin(), itemlist.end(), inbox);
if (cit == itemlist.end()) {
return;
}
itemlist.erase(cit);
}

View File

@ -22,8 +22,6 @@
#include "container.h" #include "container.h"
class Inbox;
class DepotLocker final : public Container class DepotLocker final : public Container
{ {
public: public:
@ -53,8 +51,6 @@ class DepotLocker final : public Container
void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) final; void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) final; void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
void removeInbox(Inbox* inbox);
bool canRemove() const final { bool canRemove() const final {
return false; return false;
} }

View File

@ -69,8 +69,8 @@ enum MarketAction_t {
}; };
enum MarketRequest_t { enum MarketRequest_t {
MARKETREQUEST_OWN_HISTORY = 1, MARKETREQUEST_OWN_HISTORY = 65535,
MARKETREQUEST_OWN_OFFERS = 2, MARKETREQUEST_OWN_OFFERS = 65534,
MARKETREQUEST_ITEM = 3, MARKETREQUEST_ITEM = 3,
}; };

View File

@ -38,8 +38,6 @@
#include "scheduler.h" #include "scheduler.h"
#include "databasetasks.h" #include "databasetasks.h"
#include "movement.h" #include "movement.h"
#include "inbox.h"
#include "depotchest.h"
extern ConfigManager g_config; extern ConfigManager g_config;
extern Actions* g_actions; extern Actions* g_actions;
@ -4580,7 +4578,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t spr
return; return;
} }
std::forward_list<Item*> itemList = getMarketItemList(it.id, amount, depotLocker, player->getInbox()); std::forward_list<Item*> itemList = getMarketItemList(it.id, amount, depotLocker);
if (itemList.empty()) { if (itemList.empty()) {
return; return;
} }
@ -4660,7 +4658,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
while (tmpAmount > 0) { while (tmpAmount > 0) {
int32_t stackCount = std::min<int32_t>(100, tmpAmount); int32_t stackCount = std::min<int32_t>(100, tmpAmount);
Item* item = Item::CreateItem(it.id, stackCount); Item* item = Item::CreateItem(it.id, stackCount);
if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4679,7 +4677,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
for (uint16_t i = 0; i < offer.amount; ++i) { for (uint16_t i = 0; i < offer.amount; ++i) {
Item* item = Item::CreateItem(it.id, subType); Item* item = Item::CreateItem(it.id, subType);
if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4737,7 +4735,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
return; return;
} }
std::forward_list<Item*> itemList = getMarketItemList(it.id, amount, depotLocker, player->getInbox()); std::forward_list<Item*> itemList = getMarketItemList(it.id, amount, depotLocker);
if (itemList.empty()) { if (itemList.empty()) {
return; return;
} }
@ -4776,7 +4774,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
while (tmpAmount > 0) { while (tmpAmount > 0) {
uint16_t stackCount = std::min<uint16_t>(100, tmpAmount); uint16_t stackCount = std::min<uint16_t>(100, tmpAmount);
Item* item = Item::CreateItem(it.id, stackCount); Item* item = Item::CreateItem(it.id, stackCount);
if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(buyerPlayer->getDepotLocker(buyerPlayer->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4795,7 +4793,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
for (uint16_t i = 0; i < amount; ++i) { for (uint16_t i = 0; i < amount; ++i) {
Item* item = Item::CreateItem(it.id, subType); Item* item = Item::CreateItem(it.id, subType);
if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(buyerPlayer->getDepotLocker(buyerPlayer->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4807,25 +4805,22 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
delete buyerPlayer; delete buyerPlayer;
} }
else { else {
buyerPlayer->onReceiveMail(); buyerPlayer->onReceiveMail(buyerPlayer->getLastDepotId());
} }
} }
else { else {
if (totalPrice > (player->getMoney() + player->bankBalance)) { if (totalPrice > player->bankBalance) {
return; return;
} }
const auto debitCash = std::min(player->getMoney(), totalPrice); player->bankBalance -= totalPrice;
const auto debitBank = totalPrice - debitCash;
removeMoney(player, debitCash);
player->bankBalance -= debitBank;
if (it.stackable) { if (it.stackable) {
uint16_t tmpAmount = amount; uint16_t tmpAmount = amount;
while (tmpAmount > 0) { while (tmpAmount > 0) {
uint16_t stackCount = std::min<uint16_t>(100, tmpAmount); uint16_t stackCount = std::min<uint16_t>(100, tmpAmount);
Item* item = Item::CreateItem(it.id, stackCount); Item* item = Item::CreateItem(it.id, stackCount);
if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4844,7 +4839,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
for (uint16_t i = 0; i < amount; ++i) { for (uint16_t i = 0; i < amount; ++i) {
Item* item = Item::CreateItem(it.id, subType); Item* item = Item::CreateItem(it.id, subType);
if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -4859,7 +4854,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
IOLoginData::increaseBankBalance(offer.playerId, totalPrice); IOLoginData::increaseBankBalance(offer.playerId, totalPrice);
} }
player->onReceiveMail(); player->onReceiveMail(player->getLastDepotId());
} }
const int32_t marketOfferDuration = g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION); const int32_t marketOfferDuration = g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION);
@ -4882,12 +4877,12 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
player->sendMarketAcceptOffer(offer); player->sendMarketAcceptOffer(offer);
} }
std::forward_list<Item*> Game::getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker, Inbox* inbox) std::forward_list<Item*> Game::getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker)
{ {
std::forward_list<Item*> itemList; std::forward_list<Item*> itemList;
uint16_t count = 0; uint16_t count = 0;
std::list<Container*> containers{ depotLocker, inbox }; std::list<Container*> containers{ depotLocker };
do { do {
Container* container = containers.front(); Container* container = containers.front();
containers.pop_front(); containers.pop_front();

View File

@ -413,7 +413,7 @@ class Game
void playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t spriteId, uint16_t amount, uint64_t price, bool anonymous); void playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t spriteId, uint16_t amount, uint64_t price, bool anonymous);
void playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter); void playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter);
void playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount); void playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount);
std::forward_list<Item*> getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker, Inbox* inbox); std::forward_list<Item*> getMarketItemList(uint16_t wareId, uint16_t sufficientCount, DepotLocker* depotLocker);
void closeRuleViolationReport(Player* player); void closeRuleViolationReport(Player* player);
void cancelRuleViolationReport(Player* player); void cancelRuleViolationReport(Player* player);

View File

@ -26,7 +26,6 @@
#include "game.h" #include "game.h"
#include "configmanager.h" #include "configmanager.h"
#include "bed.h" #include "bed.h"
#include "inbox.h"
extern ConfigManager g_config; extern ConfigManager g_config;
extern Game g_game; extern Game g_game;

View File

@ -22,8 +22,6 @@
#include "iologindata.h" #include "iologindata.h"
#include "configmanager.h" #include "configmanager.h"
#include "game.h" #include "game.h"
#include "depotchest.h"
#include "inbox.h"
#include <fmt/core.h> #include <fmt/core.h>
extern ConfigManager g_config; extern ConfigManager g_config;
@ -498,35 +496,6 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
} }
} }
//load inbox items
itemMap.clear();
if ((result = db->storeQuery(fmt::format("SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_inboxitems` WHERE `player_id` = {:d} ORDER BY `sid` DESC", player->getGUID())))) {
loadItems(itemMap, result);
for (ItemMap::const_reverse_iterator it = itemMap.rbegin(), end = itemMap.rend(); it != end; ++it) {
const std::pair<Item*, int32_t>& pair = it->second;
Item* item = pair.first;
int32_t pid = pair.second;
if (pid >= 0 && pid < 100) {
player->getInbox()->internalAddThing(item);
}
else {
ItemMap::const_iterator it2 = itemMap.find(pid);
if (it2 == itemMap.end()) {
continue;
}
Container* container = it2->second.first->getContainer();
if (container) {
container->internalAddThing(item);
}
}
}
}
//load storage map //load storage map
query.str(std::string()); query.str(std::string());
query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID(); query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
@ -794,41 +763,28 @@ bool IOLoginData::savePlayer(Player* player)
return false; return false;
} }
if (player->lastDepotId != -1) { //save depot items
//save depot items query.str(std::string());
if (!db->executeQuery(fmt::format("DELETE FROM `player_depotitems` WHERE `player_id` = {:d}", player->getGUID()))) { query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID();
return false;
}
DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); if (!db->executeQuery(query.str())) {
itemList.clear();
for (const auto& it : player->depotLockerMap) {
itemList.emplace_back(it.first, it.second);
}
if (!saveItems(player, itemList, depotQuery, propWriteStream)) {
return false;
}
}
//save inbox items
if (!db->executeQuery(fmt::format("DELETE FROM `player_inboxitems` WHERE `player_id` = {:d}", player->getGUID()))) {
return false; return false;
} }
DBInsert inboxQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
itemList.clear(); itemList.clear();
for (Item* item : player->getInbox()->getItemList()) { for (const auto& it : player->depotLockerMap) {
itemList.emplace_back(0, item); itemList.emplace_back(it.first, it.second);
} }
if (!saveItems(player, itemList, inboxQuery, propWriteStream)) { if (!saveItems(player, itemList, depotQuery, propWriteStream)) {
return false; return false;
} }
query.str(std::string()); query.str(std::string());
query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID();
if (!db->executeQuery(query.str())) { if (!db->executeQuery(query.str())) {
return false; return false;

View File

@ -8,7 +8,6 @@
#include "configmanager.h" #include "configmanager.h"
#include "databasetasks.h" #include "databasetasks.h"
#include "game.h" #include "game.h"
#include "inbox.h"
#include "iologindata.h" #include "iologindata.h"
#include "scheduler.h" #include "scheduler.h"
#include <fmt/core.h> #include <fmt/core.h>
@ -128,7 +127,7 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool)
while (tmpAmount > 0) { while (tmpAmount > 0) {
uint16_t stackCount = std::min<uint16_t>(100, tmpAmount); uint16_t stackCount = std::min<uint16_t>(100, tmpAmount);
Item* item = Item::CreateItem(itemType.id, stackCount); Item* item = Item::CreateItem(itemType.id, stackCount);
if (g_game.internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (g_game.internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }
@ -147,7 +146,7 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool)
for (uint16_t i = 0; i < amount; ++i) { for (uint16_t i = 0; i < amount; ++i) {
Item* item = Item::CreateItem(itemType.id, subType); Item* item = Item::CreateItem(itemType.id, subType);
if (g_game.internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { if (g_game.internalAddItem(player->getDepotLocker(player->getLastDepotId(), false), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) {
delete item; delete item;
break; break;
} }

View File

@ -36,8 +36,6 @@
#include "monster.h" #include "monster.h"
#include "scheduler.h" #include "scheduler.h"
#include "databasetasks.h" #include "databasetasks.h"
#include "inbox.h"
#include "depotchest.h"
extern Chat* g_chat; extern Chat* g_chat;
extern Game g_game; extern Game g_game;
@ -1996,7 +1994,6 @@ void LuaScriptInterface::registerFunctions()
registerMethod("Player", "getFreeCapacity", LuaScriptInterface::luaPlayerGetFreeCapacity); registerMethod("Player", "getFreeCapacity", LuaScriptInterface::luaPlayerGetFreeCapacity);
registerMethod("Player", "getDepotChest", LuaScriptInterface::luaPlayerGetDepotChest); registerMethod("Player", "getDepotChest", LuaScriptInterface::luaPlayerGetDepotChest);
registerMethod("Player", "getInbox", LuaScriptInterface::luaPlayerGetInbox);
registerMethod("Player", "getMurderTimestamps", LuaScriptInterface::luaPlayerGetMurderTimestamps); registerMethod("Player", "getMurderTimestamps", LuaScriptInterface::luaPlayerGetMurderTimestamps);
registerMethod("Player", "getPlayerKillerEnd", LuaScriptInterface::luaPlayerGetPlayerKillerEnd); registerMethod("Player", "getPlayerKillerEnd", LuaScriptInterface::luaPlayerGetPlayerKillerEnd);
@ -2307,6 +2304,13 @@ void LuaScriptInterface::registerFunctions()
registerMethod("ItemType", "getDecayId", LuaScriptInterface::luaItemTypeGetDecayId); registerMethod("ItemType", "getDecayId", LuaScriptInterface::luaItemTypeGetDecayId);
registerMethod("ItemType", "getNutrition", LuaScriptInterface::luaItemTypeGetNutrition); registerMethod("ItemType", "getNutrition", LuaScriptInterface::luaItemTypeGetNutrition);
registerMethod("ItemType", "getRequiredLevel", LuaScriptInterface::luaItemTypeGetRequiredLevel); registerMethod("ItemType", "getRequiredLevel", LuaScriptInterface::luaItemTypeGetRequiredLevel);
registerMethod("ItemType", "getDuration", LuaScriptInterface::luaItemTypeGetDuration);
registerMethod("ItemType", "getMinReqLevel", LuaScriptInterface::luaItemTypeGetMinReqLevel);
registerMethod("ItemType", "getMinReqMagicLevel", LuaScriptInterface::luaItemTypeGetMinReqMagicLevel);
registerMethod("ItemType", "getRuneSpellName", LuaScriptInterface::luaItemTypeGetRuneSpellName);
registerMethod("ItemType", "getVocationString", LuaScriptInterface::luaItemTypeGetVocationString);
registerMethod("ItemType", "hasShowCharges", LuaScriptInterface::luaItemTypeHasShowCharges);
registerMethod("ItemType", "getAbilities", LuaScriptInterface::luaItemTypeGetAbilities);
registerMethod("ItemType", "getMarketBuyStatistics", LuaScriptInterface::luaItemTypeGetMarketBuyStatistics); registerMethod("ItemType", "getMarketBuyStatistics", LuaScriptInterface::luaItemTypeGetMarketBuyStatistics);
registerMethod("ItemType", "getMarketSellStatistics", LuaScriptInterface::luaItemTypeGetMarketSellStatistics); registerMethod("ItemType", "getMarketSellStatistics", LuaScriptInterface::luaItemTypeGetMarketSellStatistics);
@ -7281,25 +7285,6 @@ int LuaScriptInterface::luaPlayerGetDepotChest(lua_State* L)
pushUserdata<Item>(L, depotLocker); pushUserdata<Item>(L, depotLocker);
setItemMetatable(L, -1, depotLocker); setItemMetatable(L, -1, depotLocker);
} else {
pushBoolean(L, false);
}
return 1;
}
int LuaScriptInterface::luaPlayerGetInbox(lua_State* L)
{
// player:getInbox()
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}
Inbox* inbox = player->getInbox();
if (inbox) {
pushUserdata<Item>(L, inbox);
setItemMetatable(L, -1, inbox);
} }
else { else {
pushBoolean(L, false); pushBoolean(L, false);
@ -7307,6 +7292,7 @@ int LuaScriptInterface::luaPlayerGetInbox(lua_State* L)
return 1; return 1;
} }
int LuaScriptInterface::luaPlayerGetMurderTimestamps(lua_State * L) int LuaScriptInterface::luaPlayerGetMurderTimestamps(lua_State * L)
{ {
// player:getMurderTimestamps() // player:getMurderTimestamps()
@ -10687,6 +10673,149 @@ int LuaScriptInterface::luaItemTypeGetRequiredLevel(lua_State* L)
return 1; return 1;
} }
int LuaScriptInterface::luaItemTypeGetDuration(lua_State* L)
{
// itemType:getDuration()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType) {
lua_pushinteger(L, itemType->decayTime);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetMinReqLevel(lua_State* L)
{
// itemType:getMinReqLevel()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType) {
lua_pushinteger(L, itemType->minReqLevel);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetMinReqMagicLevel(lua_State* L)
{
// itemType:getMinReqMagicLevel()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType) {
lua_pushinteger(L, itemType->minReqMagicLevel);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetRuneSpellName(lua_State* L)
{
// itemType:getRuneSpellName()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType && itemType->isRune()) {
pushString(L, itemType->runeSpellName);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetVocationString(lua_State* L)
{
// itemType:getVocationString()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType) {
pushString(L, itemType->vocationString);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeHasShowCharges(lua_State* L)
{
// itemType:hasShowCharges()
const ItemType* itemType = getUserdata<const ItemType>(L, 1);
if (itemType) {
pushBoolean(L, itemType->showCharges);
}
else {
lua_pushnil(L);
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetAbilities(lua_State* L)
{
// itemType:getAbilities()
ItemType* itemType = getUserdata<ItemType>(L, 1);
if (itemType) {
Abilities& abilities = itemType->getAbilities();
lua_createtable(L, 6, 12);
setField(L, "healthGain", abilities.healthGain);
setField(L, "healthTicks", abilities.healthTicks);
setField(L, "manaGain", abilities.manaGain);
setField(L, "manaTicks", abilities.manaTicks);
setField(L, "conditionImmunities", abilities.conditionImmunities);
setField(L, "conditionSuppressions", abilities.conditionSuppressions);
setField(L, "speed", abilities.speed);
lua_pushboolean(L, abilities.manaShield);
lua_setfield(L, -2, "manaShield");
lua_pushboolean(L, abilities.invisible);
lua_setfield(L, -2, "invisible");
lua_pushboolean(L, abilities.regeneration);
lua_setfield(L, -2, "regeneration");
// Stats
lua_createtable(L, 0, STAT_LAST + 1);
for (int32_t i = STAT_FIRST; i <= STAT_LAST; i++) {
lua_pushnumber(L, abilities.stats[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "stats");
// Stats percent
lua_createtable(L, 0, STAT_LAST + 1);
for (int32_t i = STAT_FIRST; i <= STAT_LAST; i++) {
lua_pushnumber(L, abilities.statsPercent[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "statsPercent");
// Skills
lua_createtable(L, 0, SKILL_LAST + 1);
for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; i++) {
lua_pushnumber(L, abilities.skills[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "skills");
// Field absorb percent
lua_createtable(L, 0, COMBAT_COUNT);
for (int32_t i = 0; i < COMBAT_COUNT; i++) {
lua_pushnumber(L, abilities.fieldAbsorbPercent[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "fieldAbsorbPercent");
// Absorb percent
lua_createtable(L, 0, COMBAT_COUNT);
for (int32_t i = 0; i < COMBAT_COUNT; i++) {
lua_pushnumber(L, abilities.absorbPercent[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "absorbPercent");
}
return 1;
}
int LuaScriptInterface::luaItemTypeGetMarketBuyStatistics(lua_State* L) int LuaScriptInterface::luaItemTypeGetMarketBuyStatistics(lua_State* L)
{ {
// itemType:getMarketBuyStatistics() // itemType:getMarketBuyStatistics()

View File

@ -807,7 +807,6 @@ class LuaScriptInterface
static int luaPlayerGetFreeCapacity(lua_State* L); static int luaPlayerGetFreeCapacity(lua_State* L);
static int luaPlayerGetDepotChest(lua_State* L); static int luaPlayerGetDepotChest(lua_State* L);
static int luaPlayerGetInbox(lua_State* L);
static int luaPlayerGetMurderTimestamps(lua_State* L); static int luaPlayerGetMurderTimestamps(lua_State* L);
static int luaPlayerGetPlayerKillerEnd(lua_State* L); static int luaPlayerGetPlayerKillerEnd(lua_State* L);
@ -1110,6 +1109,13 @@ class LuaScriptInterface
static int luaItemTypeGetDecayId(lua_State* L); static int luaItemTypeGetDecayId(lua_State* L);
static int luaItemTypeGetNutrition(lua_State* L); static int luaItemTypeGetNutrition(lua_State* L);
static int luaItemTypeGetRequiredLevel(lua_State* L); static int luaItemTypeGetRequiredLevel(lua_State* L);
static int luaItemTypeGetDuration(lua_State* L);
static int luaItemTypeGetMinReqLevel(lua_State* L);
static int luaItemTypeGetMinReqMagicLevel(lua_State* L);
static int luaItemTypeGetRuneSpellName(lua_State* L);
static int luaItemTypeGetVocationString(lua_State* L);
static int luaItemTypeHasShowCharges(lua_State* L);
static int luaItemTypeGetAbilities(lua_State* L);
static int luaItemTypeGetMarketBuyStatistics(lua_State* L); static int luaItemTypeGetMarketBuyStatistics(lua_State* L);
static int luaItemTypeGetMarketSellStatistics(lua_State* L); static int luaItemTypeGetMarketSellStatistics(lua_State* L);

View File

@ -24,7 +24,6 @@
#include "player.h" #include "player.h"
#include "iologindata.h" #include "iologindata.h"
#include "town.h" #include "town.h"
#include "inbox.h"
extern Game g_game; extern Game g_game;
@ -95,23 +94,29 @@ bool Mailbox::sendItem(Item* item) const
{ {
std::string receiver; std::string receiver;
std::string townName; std::string townName;
townName = "thais";
if (!getDestination(item, receiver, townName)) { if (!getDestination(item, receiver, townName)) {
return false; return false;
} }
/**No need to continue if its still empty**/ if (receiver.empty() || townName.empty()) {
if (receiver.empty()) { return false;
}
Town* town = g_game.map.towns.getTown(townName);
if (!town) {
return false; return false;
} }
Player* player = g_game.getPlayerByName(receiver); Player* player = g_game.getPlayerByName(receiver);
if (player) { if (player) {
if (g_game.internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER, DepotLocker* depotLocker = player->getDepotLocker(town->getID(), true);
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { if (depotLocker) {
g_game.transformItem(item, item->getID() + 1); if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER,
player->onReceiveMail(); item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
return true; g_game.transformItem(item, item->getID() + 1);
player->onReceiveMail(town->getID());
return true;
}
} }
} }
else { else {
@ -120,17 +125,20 @@ bool Mailbox::sendItem(Item* item) const
return false; return false;
} }
if (g_game.internalMoveItem(item->getParent(), tmpPlayer.getInbox(), INDEX_WHEREEVER, DepotLocker* depotLocker = tmpPlayer.getDepotLocker(town->getID(), true);
item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { if (depotLocker) {
g_game.transformItem(item, item->getID() + 1); if (g_game.internalMoveItem(item->getParent(), depotLocker, INDEX_WHEREEVER,
IOLoginData::savePlayer(&tmpPlayer); item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) {
return true; g_game.transformItem(item, item->getID() + 1);
IOLoginData::savePlayer(&tmpPlayer);
return true;
}
} }
} }
return false; return false;
} }
bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) const bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) const
{ {
const Container* container = item->getContainer(); const Container* container = item->getContainer();
@ -156,9 +164,11 @@ bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) c
while (getline(iss, temp, '\n')) { while (getline(iss, temp, '\n')) {
if (currentLine == 1) { if (currentLine == 1) {
name = temp; name = temp;
} else if (currentLine == 2) { }
else if (currentLine == 2) {
town = temp; town = temp;
} else { }
else {
break; break;
} }
@ -170,6 +180,7 @@ bool Mailbox::getDestination(Item* item, std::string& name, std::string& town) c
return true; return true;
} }
bool Mailbox::canSend(const Item* item) bool Mailbox::canSend(const Item* item)
{ {
return item->getID() == ITEM_PARCEL || item->getID() == ITEM_LETTER; return item->getID() == ITEM_PARCEL || item->getID() == ITEM_LETTER;

View File

@ -32,8 +32,6 @@
#include "monster.h" #include "monster.h"
#include "movement.h" #include "movement.h"
#include "scheduler.h" #include "scheduler.h"
#include "depotchest.h"
#include "inbox.h"
extern ConfigManager g_config; extern ConfigManager g_config;
extern Game g_game; extern Game g_game;
@ -48,9 +46,9 @@ MuteCountMap Player::muteCountMap;
uint32_t Player::playerAutoID = 0x10000000; uint32_t Player::playerAutoID = 0x10000000;
Player::Player(ProtocolGame_ptr p) : Player::Player(ProtocolGame_ptr p) :
Creature(), lastPing(OTSYS_TIME()), lastPong(lastPing), client(std::move(p)), inbox(new Inbox(ITEM_INBOX)) Creature(), lastPing(OTSYS_TIME()), lastPong(lastPing), client(std::move(p))
{ {
inbox->incrementReferenceCounter();
} }
Player::~Player() Player::~Player()
@ -63,15 +61,14 @@ Player::~Player()
} }
for (const auto& it : depotLockerMap) { for (const auto& it : depotLockerMap) {
it.second->removeInbox(inbox); it.second->decrementReferenceCounter();
} }
inbox->decrementReferenceCounter();
setWriteItem(nullptr); setWriteItem(nullptr);
setEditHouse(nullptr); setEditHouse(nullptr);
} }
bool Player::setVocation(uint16_t vocId) bool Player::setVocation(uint16_t vocId)
{ {
Vocation* voc = g_vocations.getVocation(vocId); Vocation* voc = g_vocations.getVocation(vocId);
@ -584,14 +581,14 @@ bool Player::canSeeCreature(const Creature* creature) const
return true; return true;
} }
void Player::onReceiveMail() const void Player::onReceiveMail(uint32_t townId) const
{ {
if (isNearDepotBox()) { if (isNearDepotBox(townId)) {
sendTextMessage(MESSAGE_EVENT_ADVANCE, "New mail has arrived."); sendTextMessage(MESSAGE_EVENT_ADVANCE, "New mail has arrived.");
} }
} }
bool Player::isNearDepotBox() const bool Player::isNearDepotBox(uint32_t townId) const
{ {
const Position& pos = getPosition(); const Position& pos = getPosition();
for (int32_t cx = -1; cx <= 1; ++cx) { for (int32_t cx = -1; cx <= 1; ++cx) {
@ -602,43 +599,29 @@ bool Player::isNearDepotBox() const
} }
if (DepotLocker* depotLocker = tile->getDepotLocker()) { if (DepotLocker* depotLocker = tile->getDepotLocker()) {
return true; if (depotLocker->getDepotId() == townId) {
return true;
}
} }
} }
} }
return false; return false;
} }
DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate)
{
auto it = depotChests.find(depotId);
if (it != depotChests.end()) {
return it->second;
}
if (!autoCreate) {
return nullptr;
}
it = depotChests.emplace(depotId, new DepotChest(ITEM_DEPOT)).first;
it->second->setMaxDepotItems(getMaxDepotItems());
return it->second;
}
DepotLocker* Player::getDepotLocker(uint32_t depotId, bool autoCreate) DepotLocker* Player::getDepotLocker(uint32_t depotId, bool autoCreate)
{ {
auto it = depotLockerMap.find(depotId); auto it = depotLockerMap.find(depotId);
if (it != depotLockerMap.end()) { if (it != depotLockerMap.end()) {
inbox->setParent(it->second);
return it->second; return it->second;
} }
if (autoCreate) { if (autoCreate) {
DepotLocker* depotLocker = new DepotLocker(ITEM_LOCKER1); DepotLocker* depotLocker = new DepotLocker(ITEM_LOCKER1);
depotLocker->setDepotId(depotId); depotLocker->setDepotId(depotId);
depotLocker->internalAddThing(Item::CreateItem(ITEM_MARKET)); Item* marketItem = Item::CreateItem(ITEM_MARKET);
depotLocker->internalAddThing(inbox); if (marketItem) {
depotLocker->internalAddThing(marketItem);
}
Item* depotItem = Item::CreateItem(ITEM_DEPOT); Item* depotItem = Item::CreateItem(ITEM_DEPOT);
if (depotItem) { if (depotItem) {
depotLocker->internalAddThing(depotItem); depotLocker->internalAddThing(depotItem);

View File

@ -35,7 +35,6 @@
#include "town.h" #include "town.h"
class BehaviourDatabase; class BehaviourDatabase;
class DepotChest;
class House; class House;
class NetworkMessage; class NetworkMessage;
class Weapon; class Weapon;
@ -208,10 +207,6 @@ class Player final : public Creature, public Cylinder
bool isInWar(const Player* player) const; bool isInWar(const Player* player) const;
bool isInWarList(uint32_t guild_id) const; bool isInWarList(uint32_t guild_id) const;
Inbox* getInbox() const {
return inbox;
}
uint16_t getClientIcons() const; uint16_t getClientIcons() const;
const GuildWarList& getGuildWarList() const { const GuildWarList& getGuildWarList() const {
@ -322,6 +317,14 @@ class Player final : public Creature, public Cylinder
lastDepotId = newId; lastDepotId = newId;
} }
int16_t getLastDepotId() const { int16_t getLastDepotId() const {
if (lastDepotId == -1) {
if (town) {
return town->getID();
}
else {
return 1; // Thais
}
}
return lastDepotId; return lastDepotId;
} }
@ -473,10 +476,9 @@ class Player final : public Creature, public Cylinder
void addConditionSuppressions(uint32_t conditions); void addConditionSuppressions(uint32_t conditions);
void removeConditionSuppressions(uint32_t conditions); void removeConditionSuppressions(uint32_t conditions);
DepotChest* getDepotChest(uint32_t depotId, bool autoCreate);
DepotLocker* getDepotLocker(uint32_t depotId, bool autoCreate); DepotLocker* getDepotLocker(uint32_t depotId, bool autoCreate);
void onReceiveMail() const; void onReceiveMail(uint32_t townId) const;
bool isNearDepotBox() const; bool isNearDepotBox(uint32_t townId) const;
bool canSee(const Position& pos) const final; bool canSee(const Position& pos) const final;
bool canSeeCreature(const Creature* creature) const final; bool canSeeCreature(const Creature* creature) const final;
@ -1079,7 +1081,6 @@ class Player final : public Creature, public Cylinder
std::map<uint8_t, OpenContainer> openContainers; std::map<uint8_t, OpenContainer> openContainers;
std::map<uint32_t, DepotLocker*> depotLockerMap; std::map<uint32_t, DepotLocker*> depotLockerMap;
std::map<uint32_t, DepotChest*> depotChests;
std::map<uint32_t, int32_t> storageMap; std::map<uint32_t, int32_t> storageMap;
std::vector<OutfitEntry> outfits; std::vector<OutfitEntry> outfits;
@ -1118,7 +1119,6 @@ class Player final : public Creature, public Cylinder
Guild* guild = nullptr; Guild* guild = nullptr;
const GuildRank* guildRank = nullptr; const GuildRank* guildRank = nullptr;
Group* group = nullptr; Group* group = nullptr;
Inbox* inbox;
Item* tradeItem = nullptr; Item* tradeItem = nullptr;
Item* inventory[CONST_SLOT_LAST + 1] = {}; Item* inventory[CONST_SLOT_LAST + 1] = {};
Item* writeItem = nullptr; Item* writeItem = nullptr;

View File

@ -30,13 +30,11 @@
#include "configmanager.h" #include "configmanager.h"
#include "actions.h" #include "actions.h"
#include "game.h" #include "game.h"
#include "inbox.h"
#include "iomarket.h" #include "iomarket.h"
#include "iologindata.h" #include "iologindata.h"
#include "waitlist.h" #include "waitlist.h"
#include "ban.h" #include "ban.h"
#include "scheduler.h" #include "scheduler.h"
#include "depotchest.h"
extern ConfigManager g_config; extern ConfigManager g_config;
extern Actions actions; extern Actions actions;
@ -1012,7 +1010,7 @@ void ProtocolGame::parseMarketLeave()
void ProtocolGame::parseMarketBrowse(NetworkMessage& msg) void ProtocolGame::parseMarketBrowse(NetworkMessage& msg)
{ {
uint8_t browseId = msg.get<uint8_t>(); uint16_t browseId = msg.get<uint16_t>();
if (browseId == MARKETREQUEST_OWN_OFFERS) { if (browseId == MARKETREQUEST_OWN_OFFERS) {
addGameTask(&Game::playerBrowseMarketOwnOffers, player->getID()); addGameTask(&Game::playerBrowseMarketOwnOffers, player->getID());
} }
@ -1020,8 +1018,8 @@ void ProtocolGame::parseMarketBrowse(NetworkMessage& msg)
addGameTask(&Game::playerBrowseMarketOwnHistory, player->getID()); addGameTask(&Game::playerBrowseMarketOwnHistory, player->getID());
} }
else { else {
uint16_t spriteID = msg.get<uint16_t>(); //uint16_t spriteID = msg.get<uint16_t>();
addGameTask(&Game::playerBrowseMarket, player->getID(), spriteID); addGameTask(&Game::playerBrowseMarket, player->getID(), browseId);
} }
} }
@ -1034,10 +1032,6 @@ void ProtocolGame::parseMarketCreateOffer(NetworkMessage& msg)
if (it.id == 0) { if (it.id == 0) {
return; return;
} }
// TODO:
//else if (it.classification > 0) {
// msg.getByte(); // item tier
//}
uint16_t amount = msg.get<uint16_t>(); uint16_t amount = msg.get<uint16_t>();
uint64_t price = msg.get<uint64_t>(); uint64_t price = msg.get<uint64_t>();
@ -1332,7 +1326,7 @@ void ProtocolGame::sendMarketEnter(uint32_t depotId)
msg.add<uint64_t>(player->getBankBalance()); msg.add<uint64_t>(player->getBankBalance());
std::map<uint16_t, uint32_t> depotItems; std::map<uint16_t, uint32_t> depotItems;
std::forward_list<Container*> containerList{ depotLocker, player->getInbox() }; std::forward_list<Container*> containerList{ depotLocker };
do { do {
Container* container = containerList.front(); Container* container = containerList.front();
@ -1369,10 +1363,6 @@ void ProtocolGame::sendMarketEnter(uint32_t depotId)
for (std::map<uint16_t, uint32_t>::const_iterator it = depotItems.begin(); i < itemsToSend; ++it, ++i) { for (std::map<uint16_t, uint32_t>::const_iterator it = depotItems.begin(); i < itemsToSend; ++it, ++i) {
const ItemType& itemType = Item::items[it->first]; const ItemType& itemType = Item::items[it->first];
msg.add<uint16_t>(itemType.id); msg.add<uint16_t>(itemType.id);
// TODO
//if (itemType.classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(std::min<uint32_t>(0xFFFF, it->second)); msg.add<uint16_t>(std::min<uint32_t>(0xFFFF, it->second));
} }
writeToOutputBuffer(msg); writeToOutputBuffer(msg);
@ -1389,14 +1379,8 @@ void ProtocolGame::sendMarketBrowseItem(uint16_t itemId, const MarketOfferList&
{ {
NetworkMessage msg; NetworkMessage msg;
msg.addByte(0xF9); msg.addByte(0xF9);
msg.addByte(MARKETREQUEST_ITEM);
msg.addItemId(itemId); msg.addItemId(itemId);
// TODO
//if (Item::items[itemId].classification > 0) {
// msg.addByte(0); // item tier
//}
msg.add<uint32_t>(buyOffers.size()); msg.add<uint32_t>(buyOffers.size());
for (const MarketOffer& offer : buyOffers) { for (const MarketOffer& offer : buyOffers) {
msg.add<uint32_t>(offer.timestamp); msg.add<uint32_t>(offer.timestamp);
@ -1422,12 +1406,7 @@ void ProtocolGame::sendMarketAcceptOffer(const MarketOfferEx& offer)
{ {
NetworkMessage msg; NetworkMessage msg;
msg.addByte(0xF9); msg.addByte(0xF9);
msg.addByte(MARKETREQUEST_ITEM);
msg.addItemId(offer.itemId); msg.addItemId(offer.itemId);
// TODO
//if (Item::items[offer.itemId].classification > 0) {
// msg.addByte(0);
//}
if (offer.type == MARKETACTION_BUY) { if (offer.type == MARKETACTION_BUY) {
msg.add<uint32_t>(0x01); msg.add<uint32_t>(0x01);
@ -1455,17 +1434,13 @@ void ProtocolGame::sendMarketBrowseOwnOffers(const MarketOfferList& buyOffers, c
{ {
NetworkMessage msg; NetworkMessage msg;
msg.addByte(0xF9); msg.addByte(0xF9);
msg.addByte(MARKETREQUEST_OWN_OFFERS); msg.add<uint16_t>(MARKETREQUEST_OWN_OFFERS);
msg.add<uint32_t>(buyOffers.size()); msg.add<uint32_t>(buyOffers.size());
for (const MarketOffer& offer : buyOffers) { for (const MarketOffer& offer : buyOffers) {
msg.add<uint32_t>(offer.timestamp); msg.add<uint32_t>(offer.timestamp);
msg.add<uint16_t>(offer.counter); msg.add<uint16_t>(offer.counter);
msg.addItemId(offer.itemId); msg.addItemId(offer.itemId);
// TODO
//if (Item::items[offer.itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(offer.amount); msg.add<uint16_t>(offer.amount);
msg.add<uint64_t>(offer.price); msg.add<uint64_t>(offer.price);
} }
@ -1475,10 +1450,6 @@ void ProtocolGame::sendMarketBrowseOwnOffers(const MarketOfferList& buyOffers, c
msg.add<uint32_t>(offer.timestamp); msg.add<uint32_t>(offer.timestamp);
msg.add<uint16_t>(offer.counter); msg.add<uint16_t>(offer.counter);
msg.addItemId(offer.itemId); msg.addItemId(offer.itemId);
// TODO
//if (Item::items[offer.itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(offer.amount); msg.add<uint16_t>(offer.amount);
msg.add<uint64_t>(offer.price); msg.add<uint64_t>(offer.price);
} }
@ -1490,17 +1461,13 @@ void ProtocolGame::sendMarketCancelOffer(const MarketOfferEx& offer)
{ {
NetworkMessage msg; NetworkMessage msg;
msg.addByte(0xF9); msg.addByte(0xF9);
msg.addByte(MARKETREQUEST_OWN_OFFERS); msg.add<uint16_t>(MARKETREQUEST_OWN_OFFERS);
if (offer.type == MARKETACTION_BUY) { if (offer.type == MARKETACTION_BUY) {
msg.add<uint32_t>(0x01); msg.add<uint32_t>(0x01);
msg.add<uint32_t>(offer.timestamp); msg.add<uint32_t>(offer.timestamp);
msg.add<uint16_t>(offer.counter); msg.add<uint16_t>(offer.counter);
msg.addItemId(offer.itemId); msg.addItemId(offer.itemId);
// TODO
//if (Item::items[offer.itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(offer.amount); msg.add<uint16_t>(offer.amount);
msg.add<uint64_t>(offer.price); msg.add<uint64_t>(offer.price);
msg.add<uint32_t>(0x00); msg.add<uint32_t>(0x00);
@ -1511,10 +1478,6 @@ void ProtocolGame::sendMarketCancelOffer(const MarketOfferEx& offer)
msg.add<uint32_t>(offer.timestamp); msg.add<uint32_t>(offer.timestamp);
msg.add<uint16_t>(offer.counter); msg.add<uint16_t>(offer.counter);
msg.addItemId(offer.itemId); msg.addItemId(offer.itemId);
// TODO
//if (Item::items[offer.itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(offer.amount); msg.add<uint16_t>(offer.amount);
msg.add<uint64_t>(offer.price); msg.add<uint64_t>(offer.price);
} }
@ -1531,17 +1494,13 @@ void ProtocolGame::sendMarketBrowseOwnHistory(const HistoryMarketOfferList& buyO
NetworkMessage msg; NetworkMessage msg;
msg.addByte(0xF9); msg.addByte(0xF9);
msg.addByte(MARKETREQUEST_OWN_HISTORY); msg.add<uint16_t>(MARKETREQUEST_OWN_HISTORY);
msg.add<uint32_t>(buyOffersToSend); msg.add<uint32_t>(buyOffersToSend);
for (auto it = buyOffers.begin(); i < buyOffersToSend; ++it, ++i) { for (auto it = buyOffers.begin(); i < buyOffersToSend; ++it, ++i) {
msg.add<uint32_t>(it->timestamp); msg.add<uint32_t>(it->timestamp);
msg.add<uint16_t>(counterMap[it->timestamp]++); msg.add<uint16_t>(counterMap[it->timestamp]++);
msg.addItemId(it->itemId); msg.addItemId(it->itemId);
// TODO
//if (Item::items[it->itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(it->amount); msg.add<uint16_t>(it->amount);
msg.add<uint64_t>(it->price); msg.add<uint64_t>(it->price);
msg.addByte(it->state); msg.addByte(it->state);
@ -1555,10 +1514,6 @@ void ProtocolGame::sendMarketBrowseOwnHistory(const HistoryMarketOfferList& buyO
msg.add<uint32_t>(it->timestamp); msg.add<uint32_t>(it->timestamp);
msg.add<uint16_t>(counterMap[it->timestamp]++); msg.add<uint16_t>(counterMap[it->timestamp]++);
msg.addItemId(it->itemId); msg.addItemId(it->itemId);
// TODO
//if (Item::items[it->itemId].classification > 0) {
// msg.addByte(0);
//}
msg.add<uint16_t>(it->amount); msg.add<uint16_t>(it->amount);
msg.add<uint64_t>(it->price); msg.add<uint64_t>(it->price);
msg.addByte(it->state); msg.addByte(it->state);

View File

@ -159,7 +159,6 @@
<ClCompile Include="..\src\database.cpp" /> <ClCompile Include="..\src\database.cpp" />
<ClCompile Include="..\src\databasemanager.cpp" /> <ClCompile Include="..\src\databasemanager.cpp" />
<ClCompile Include="..\src\databasetasks.cpp" /> <ClCompile Include="..\src\databasetasks.cpp" />
<ClCompile Include="..\src\depotchest.cpp" />
<ClCompile Include="..\src\depotlocker.cpp" /> <ClCompile Include="..\src\depotlocker.cpp" />
<ClCompile Include="..\src\events.cpp" /> <ClCompile Include="..\src\events.cpp" />
<ClCompile Include="..\src\fileloader.cpp" /> <ClCompile Include="..\src\fileloader.cpp" />
@ -169,7 +168,6 @@
<ClCompile Include="..\src\guild.cpp" /> <ClCompile Include="..\src\guild.cpp" />
<ClCompile Include="..\src\house.cpp" /> <ClCompile Include="..\src\house.cpp" />
<ClCompile Include="..\src\housetile.cpp" /> <ClCompile Include="..\src\housetile.cpp" />
<ClCompile Include="..\src\inbox.cpp" />
<ClCompile Include="..\src\ioguild.cpp" /> <ClCompile Include="..\src\ioguild.cpp" />
<ClCompile Include="..\src\iologindata.cpp" /> <ClCompile Include="..\src\iologindata.cpp" />
<ClCompile Include="..\src\iomap.cpp" /> <ClCompile Include="..\src\iomap.cpp" />
@ -243,7 +241,6 @@
<ClInclude Include="..\src\databasemanager.h" /> <ClInclude Include="..\src\databasemanager.h" />
<ClInclude Include="..\src\databasetasks.h" /> <ClInclude Include="..\src\databasetasks.h" />
<ClInclude Include="..\src\definitions.h" /> <ClInclude Include="..\src\definitions.h" />
<ClInclude Include="..\src\depotchest.h" />
<ClInclude Include="..\src\depotlocker.h" /> <ClInclude Include="..\src\depotlocker.h" />
<ClInclude Include="..\src\events.h" /> <ClInclude Include="..\src\events.h" />
<ClInclude Include="..\src\enums.h" /> <ClInclude Include="..\src\enums.h" />
@ -254,7 +251,6 @@
<ClInclude Include="..\src\guild.h" /> <ClInclude Include="..\src\guild.h" />
<ClInclude Include="..\src\house.h" /> <ClInclude Include="..\src\house.h" />
<ClInclude Include="..\src\housetile.h" /> <ClInclude Include="..\src\housetile.h" />
<ClInclude Include="..\src\inbox.h" />
<ClInclude Include="..\src\ioguild.h" /> <ClInclude Include="..\src\ioguild.h" />
<ClInclude Include="..\src\iologindata.h" /> <ClInclude Include="..\src\iologindata.h" />
<ClInclude Include="..\src\iomap.h" /> <ClInclude Include="..\src\iomap.h" />