Caduceus
Unknown Member
- Joined
- May 10, 2010
- Messages
- 321
- Solutions
- 2
- Reaction score
- 24
Did I miss something here? I have all of the source edits in for currency changes. I can use all of the forms of currency to purchase goods from an npc. However, I cannot get scarab coin to convert back to gold bar. all other conversions work.
changegold.lua
item.cpp
luascript.cpp
player.cpp
const.h
game.cpp
changegold.lua
Code:
local config = {
[ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
[ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
[ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN, changeTo = ITEM_GOLD_BAR},
[ITEM_GOLD_BAR] = {changeBack = ITEM_CRYSTAL_COIN, changeTo = ITEM_SCARAB_COIN},
[ITEM_SCARAB_COIN] = {changeBack = ITEM_GOLD_BAR}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local coin = config[item:getId()]
if coin.changeTo and item.type == 100 then
item:remove()
player:addItem(coin.changeTo, 1)
elseif coin.changeBack then
item:remove(1)
player:addItem(coin.changeBack, 100)
else
return false
end
return true
end
item.cpp
Code:
int32_t Item::getWorth() const
{
switch (id) {
case ITEM_GOLD_COIN:
return count;
case ITEM_PLATINUM_COIN:
return count * 100;
case ITEM_CRYSTAL_COIN:
return count * 10000;
case ITEM_GOLD_BAR:
return count * 1000000;
case ITEM_SCARAB_COIN:
return count * 100000000;
default:
return 0;
}
}
luascript.cpp
Code:
registerEnum(ITEM_GOLD_BAR)
registerEnum(ITEM_SCARAB_COIN)
player.cpp
Code:
bool Player::updateSaleShopList(const Item* item)
{
uint16_t itemId = item->getID();
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_BAR && itemId != ITEM_SCARAB_COIN) {
auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
if (it == shopItemList.end()) {
const Container* container = item->getContainer();
if (!container) {
return false;
}
const auto& items = container->getItemList();
return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
return updateSaleShopList(containerItem);
});
}
const.h
Code:
ITEM_GOLD_BAR = 15515,
ITEM_SCARAB_COIN = 2159,
game.cpp
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
uint32_t scarab = money / 100000000;
money -= scarab * 100000000;
if (scarab > 0) {
Item* remaindItem = Item::CreateItem(ITEM_SCARAB_COIN, std::min<int32_t>(100, scarab));
ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
if (ret != RETURNVALUE_NOERROR) {
internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
}
scarab -= std::min<int32_t>(100, scarab);
}
uint32_t bar = money / 1000000;
money -= bar * 1000000;
if (bar > 0) {
Item* remaindItem = Item::CreateItem(ITEM_GOLD_BAR, std::min<int32_t>(100, bar));
ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
if (ret != RETURNVALUE_NOERROR) {
internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
}
bar -= std::min<int32_t>(100, bar);
}
Last edited: