diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 94a6e05..ffcbe2b 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -3507,3 +3507,81 @@ void Human::UpdateViewObjects() } } } + +void Human::GMAddItem(int item_id, int item_num) +{ + MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(item_id); + if (!item_meta) { + return; + } + if (item_meta->i->_inventory_slot() >= 0 && + item_meta->i->_inventory_slot() < IS_END) { + if (GetInventory(item_meta->i->_inventory_slot()) >= + GetVolume(item_meta->i->_inventory_slot()) + ) { + /* + cs::SMPickup notifymsg; + notifymsg.set_error_code(1); + SendNotifyMsg(notifymsg); + */ + return; + } + int add_num = GetVolume(item_meta->i->_inventory_slot()) - + GetInventory(item_meta->i->_inventory_slot()); + add_num = std::min(item_num, add_num); + + AddInventory(item_meta->i->_inventory_slot(), add_num); + switch (item_meta->i->_inventory_slot()) { + case IS_FRAG: + case IS_SMOKE: + { + Weapon* weapon = &weapons[SPEC1_SLOT_BEGIN + + (item_meta->i->_inventory_slot() - SPEC1_IS_BEGIN) + ]; + weapon->weapon_id = item_id; + weapon->weapon_lv = 1; + weapon->ammo += item_num; + weapon->meta = item_meta; + weapon->Recalc(); + DecInventory(item_meta->i->_inventory_slot(), add_num); + } + break; + case IS_1XSCOPE: + case IS_2XSCOPE: + case IS_4XSCOPE: + case IS_8XSCOPE: + case IS_15XSCOPE: + { + if (item_meta->i->_inventory_slot() - IS_1XSCOPE > curr_scope_idx) { + curr_scope_idx = item_meta->i->_inventory_slot() - IS_1XSCOPE; + } + } + break; + case IS_POSION_GAS_BOMB: + case IS_MOLOTOR_COCKTAIL: + case IS_TRAP: + case IS_MINE: + { + Weapon* weapon = &weapons[SPEC2_SLOT_BEGIN + + (item_meta->i->_inventory_slot() - SPEC2_IS_BEGIN) + ]; + weapon->weapon_id = item_id; + weapon->weapon_lv = 1; + weapon->ammo += item_num; + weapon->meta = item_meta; + weapon->Recalc(); + DecInventory(item_meta->i->_inventory_slot(), add_num); + } + break; + default: + { +#if 0 + abort(); +#endif + } + break; + } + } + need_sync_active_player = true; + SyncAroundPlayers(__FILE__, __LINE__, __func__); +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index a503262..f548941 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -245,6 +245,7 @@ class Human : public Creature void DeadDrop(); virtual std::string GetName() override { return name;}; void UpdateViewObjects(); + void GMAddItem(int item_id, int item_num); protected: void _InternalUpdateMove(float speed); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 0a71baf..96d4948 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -1102,6 +1102,10 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg) std::string cmd = cmds[0]; if (cmd == "gps") { SendDebugMsg(a8::Format("%d %d", {GetPos().x, GetPos().y})); + }else if (cmd == "additem" && cmds.size() >= 2) { + int item_id = a8::XValue(cmds[1]); + int item_num = a8::XValue(cmds[2]); + GMAddItem(item_id, item_num); } }