void RemoveDropHandler::handle(InPacket& recv) const
	{
		int8_t mode = recv.readbyte();
		int32_t oid = recv.readint();

		using Gameplay::PhysicsObject;
		Optional<PhysicsObject> looter;
		if (mode > 1)
		{
			int32_t cid = recv.readint();
			if (recv.length() > 0)
			{
				recv.readbyte(); // pet
			}
			else
			{
				looter = Stage::get().getcharacter(cid)
					.transform(&Char::getphobj);
			}

			AudioPlayer::get().playsound(AudioPlayer::PICKUP);
		}
		Stage::get().getdrops().removedrop(oid, mode, looter.get());
	}
Пример #2
0
	void ModifyInventoryHandler::handle(InPacket& recv) const
	{
		recv.read_bool(); // 'updatetick'

		Inventory& inventory = Stage::get().getplayer().getinvent();

		struct Mod
		{
			int8_t mode;
			Inventory::Type type;
			int16_t pos;
			int16_t arg;
		};
		std::vector<Mod> mods;

		int8_t size = recv.read_byte();
		for (int8_t i = 0; i < size; i++)
		{
			Mod mod;
			mod.mode = recv.read_byte();
			mod.type = Inventory::typebyvalue(recv.read_byte());
			mod.pos = recv.read_short();

			mod.arg = 0;
			switch (mod.mode)
			{
			case 0:
				ItemParser::parseitem(recv, mod.type, mod.pos, inventory);
				break;
			case 1:
				mod.arg = recv.read_short();
				if (inventory.changecount(mod.type, mod.pos, mod.arg))
					mod.mode = 4;
				break;
			case 2:
				mod.arg = recv.read_short();
				break;
			case 3:
				inventory.modify(mod.type, mod.pos, mod.mode, mod.arg, Inventory::MOVE_INTERNAL);
				break;
			}

			mods.push_back(mod);
		}

		Inventory::Movement move = (recv.length() > 0) ?
			Inventory::movementbyvalue(recv.read_byte()) :
			Inventory::MOVE_INTERNAL;

		for (Mod& mod : mods)
		{
			if (mod.mode == 2)
			{
				inventory.modify(mod.type, mod.pos, mod.mode, mod.arg, move);
			}

			UI::get().with_element<UIShop>([&mod](auto& s) {
				s.modify(mod.type);
			});

			auto eqinvent = UI::get().get_element<UIEquipInventory>();
			auto itinvent = UI::get().get_element<UIItemInventory>();
			switch (move)
			{
			case Inventory::MOVE_INTERNAL:
				switch (mod.type)
				{
				case Inventory::EQUIPPED:
					if (eqinvent)
						eqinvent->modify(mod.pos, mod.mode, mod.arg);

					Stage::get().getplayer().changecloth(-mod.pos);
					Stage::get().getplayer().changecloth(-mod.arg);
					break;
				case Inventory::EQUIP:
				case Inventory::USE:
				case Inventory::SETUP:
				case Inventory::ETC:
				case Inventory::CASH:
					if (itinvent)
						itinvent->modify(mod.type, mod.pos, mod.mode, mod.arg);
					break;
				}
				break;
			case Inventory::MOVE_EQUIP:
			case Inventory::MOVE_UNEQUIP:
				if (mod.pos < 0)
				{
					if (eqinvent)
						eqinvent->modify(-mod.pos, 3, 0);

					if (itinvent)
						itinvent->modify(Inventory::EQUIP, mod.arg, 0, 0);

					Stage::get().getplayer().changecloth(-mod.pos);
				}
				else if (mod.arg < 0)
				{
					if (eqinvent)
						eqinvent->modify(-mod.arg, 0, 0);

					if (itinvent)
						itinvent->modify(Inventory::EQUIP, mod.pos, 3, 0);

					Stage::get().getplayer().changecloth(-mod.arg);
				}
				break;
			}
		}

		Stage::get().getplayer().recalcstats(true);
		UI::get().enable();
	}