Skip to content

Commit

Permalink
KeepAfterUse + DontUseAmmo
Browse files Browse the repository at this point in the history
****
Approved-by: Free Yorp <thefreeyorp+git@gmail.com>
Approved-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
  • Loading branch information
HoraK-FDF authored and Ledmitz committed Jun 6, 2024
1 parent 1841311 commit 04c17a5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
28 changes: 19 additions & 9 deletions src/map/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,18 +2060,28 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target,
// 攻撃対象となりうるので攻撃 | Attack because it can be attacked
if (sd && sd->status.weapon == ItemLook::W_BOW)
{
IOff0 aidx = sd->equip_index_maybe[EQUIP::ARROW];
if (aidx.ok())
{
if (battle_config.arrow_decrement)
pc_delitem(sd, aidx, 1, 0);
}
else
IOff0 widx = sd->equip_index_maybe[EQUIP::WEAPON];

OMATCH_BEGIN_SOME (sdidw, sd->inventory_data[widx])
{
clif_arrow_fail(sd, 0);
return ATK::ZERO;
if (!bool(sdidw->mode & ItemMode::DONT_USE_AMMO))
{
IOff0 aidx = sd->equip_index_maybe[EQUIP::ARROW];
if (aidx.ok())
{
if (battle_config.arrow_decrement)
pc_delitem(sd, aidx, 1, 0);
}
else
{
clif_arrow_fail(sd, 0);
return ATK::ZERO;
}
}
}
OMATCH_END ();
}

wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0);

// significantly increase injuries for hasted characters
Expand Down
23 changes: 17 additions & 6 deletions src/map/clif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4617,11 +4617,17 @@ RecvResult clif_parse_DropItem(Session *s, dumb_ptr<map_session_data> sd)
clif_displaymessage(sd->sess, "Can't drop items here."_s);
return rv;
}
if (bool(itemdb_search(sd->status.inventory[fixed.ioff2.unshift()].nameid)->mode & ItemMode::NO_DROP))

OMATCH_BEGIN_SOME (sdidn, sd->inventory_data[fixed.ioff2.unshift()])
{
clif_displaymessage(sd->sess, "This item can't be dropped."_s);
return rv;
if (bool(sdidn->mode & ItemMode::NO_DROP))
{
clif_displaymessage(sd->sess, "This item can't be dropped."_s);
return rv;
}
}
OMATCH_END ();

if (sd->npc_id
|| sd->opt1 != Opt1::ZERO)
{
Expand Down Expand Up @@ -4901,11 +4907,16 @@ RecvResult clif_parse_TradeAddItem(Session *s, dumb_ptr<map_session_data> sd)
if (fixed.zeny_or_ioff2.index != 0 && !fixed.zeny_or_ioff2.ok())
return RecvResult::Error;
if (fixed.zeny_or_ioff2.ok())
if (bool(itemdb_search(sd->status.inventory[fixed.zeny_or_ioff2.unshift()].nameid)->mode & ItemMode::NO_TRADE))
OMATCH_BEGIN_SOME (sdidn, sd->inventory_data[fixed.zeny_or_ioff2.unshift()])
{
clif_displaymessage(sd->sess, "This item can't be traded."_s);
return rv;
if (bool(sdidn->mode & ItemMode::NO_TRADE))
{
clif_displaymessage(sd->sess, "This item can't be traded."_s);
return rv;
}
}
OMATCH_END ();

trade_tradeadditem(sd, fixed.zeny_or_ioff2, fixed.amount);

return rv;
Expand Down
14 changes: 10 additions & 4 deletions src/map/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,18 @@ int npc_selllist(dumb_ptr<map_session_data> sd,
if (!nameid ||
sd->status.inventory[item_list[i].ioff2.unshift()].amount < item_list[i].count)
return 1;
if (bool(itemdb_search(nameid)->mode & ItemMode::NO_SELL_TO_NPC))

OMATCH_BEGIN_SOME (sdidn, sd->inventory_data[item_list[i].ioff2.unshift()])
{
//clif_displaymessage(sd->sess, "This item can't be sold to an NPC."_s);
// M+ already outputs "Unable to sell unsellable item." on return value 3.
return 3;
if (bool(sdidn->mode & ItemMode::NO_SELL_TO_NPC))
{
//clif_displaymessage(sd->sess, "This item can't be sold to an NPC."_s);
// M+ already outputs "Unable to sell unsellable item." on return value 3.
return 3;
}
}
OMATCH_END ();

if (sd->trade_partner)
return 2; // cant sell while trading
z += static_cast<double>(itemdb_value_sell(nameid)) * item_list[i].count;
Expand Down
8 changes: 6 additions & 2 deletions src/map/pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,8 +2404,12 @@ int pc_useitem(dumb_ptr<map_session_data> sd, IOff0 n)
}

P<const ScriptBuffer> script = borrow(*sdidn->use_script);
clif_useitemack(sd, n, amount - 1, 1);
pc_delitem(sd, n, 1, 1);

if (!bool(sdidn->mode & ItemMode::KEEP_AFTER_USE))
{
clif_useitemack(sd, n, amount - 1, 1);
pc_delitem(sd, n, 1, 1);
}

// activity
if (sd)
Expand Down
10 changes: 7 additions & 3 deletions src/map/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ int storage_storageadd(dumb_ptr<map_session_data> sd, IOff0 index, int amount)
if (amount < 1 || amount > sd->status.inventory[index].amount)
return 0;

if (bool(itemdb_search(sd->status.inventory[index].nameid)->mode & ItemMode::NO_STORAGE))
OMATCH_BEGIN_SOME (sdidn, sd->inventory_data[index])
{
clif_displaymessage(sd->sess, "This item can't be stored."_s);
return 0;
if (bool(sdidn->mode & ItemMode::NO_STORAGE))
{
clif_displaymessage(sd->sess, "This item can't be stored."_s);
return 0;
}
}
OMATCH_END ();

// log_tostorage(sd, index, 0);
if (storage_additem(sd, stor, &sd->status.inventory[index], amount) == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/mmo/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ enum class ItemMode : uint8_t
NO_TRADE = 2,
NO_SELL_TO_NPC = 4,
NO_STORAGE = 8,
KEEP_AFTER_USE = 16,
DONT_USE_AMMO = 32,
};
ENUM_BITWISE_OPERATORS(ItemMode)
}
Expand Down

0 comments on commit 04c17a5

Please sign in to comment.