예제 #1
0
void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
{
	if (!a_Player.IsGameModeCreative())
	{
		a_Player.DeltaExperience(-cPlayer::XpForLevel(m_MaximumCost));
	}
	SetSlot(0, a_Player, cItem());

	if (m_StackSizeToBeUsedInRepair > 0)
	{
		const cItem * Item = GetSlot(1, a_Player);
		if (!Item->IsEmpty() && (Item->m_ItemCount > m_StackSizeToBeUsedInRepair))
		{
			cItem NewSecondItem(*Item);
			NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair;
			m_StackSizeToBeUsedInRepair = 0;
			SetSlot(1, a_Player, NewSecondItem);
		}
		else
		{
			SetSlot(1, a_Player, cItem());
		}
	}
	else
	{
		SetSlot(1, a_Player, cItem());
	}
	m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player);

	m_MaximumCost = 0;
	((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", NULL);

	int PosX, PosY, PosZ;
	((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ);

	BLOCKTYPE Block;
	NIBBLETYPE BlockMeta;
	a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta);

	cFastRandom Random;
	if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F))
	{
		NIBBLETYPE Orientation = BlockMeta & 0x3;
		NIBBLETYPE AnvilDamage = BlockMeta >> 2;
		++AnvilDamage;

		if (AnvilDamage > 2)
		{
			// Anvil will break
			a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, (NIBBLETYPE)0);
			a_Player.GetWorld()->BroadcastSoundParticleEffect(1020, PosX, PosY, PosZ, 0);
			a_Player.CloseWindow(false);
		}
		else
		{
			a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, Orientation | (AnvilDamage << 2));
			a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0);
		}
	}
예제 #2
0
파일: SlotArea.cpp 프로젝트: l0ud/MCServer
void cSlotAreaTemporary::TossItems(cPlayer & a_Player, int a_Begin, int a_End)
{
	cItemMap::iterator itr = m_Items.find(a_Player.GetUniqueID());
	if (itr == m_Items.end())
	{
		LOGWARNING("Player tossing items (%s) not found in the item map", a_Player.GetName().c_str());
		return;
	}
	
	cItems Drops;
	for (int i = a_Begin; i < a_End; i++)
	{
		cItem & Item = itr->second[i];
		if (!Item.IsEmpty())
		{
			Drops.push_back(Item);
		}
		Item.Empty();
	}  // for i - itr->second[]
	
	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-a_Player.GetRotation(), a_Player.GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 2, vY * 2, vZ * 2);
}
예제 #3
0
void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
{
	cItem Item = *GetSlot(0, a_Player);

	if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty())
	{
		m_ParentWindow.SetProperty(0, 0, a_Player);
		m_ParentWindow.SetProperty(1, 0, a_Player);
		m_ParentWindow.SetProperty(2, 0, a_Player);
	}
	else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK)
	{
		int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15);

		cFastRandom Random;
		int base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves));
		int topSlot = std::max(base / 3, 1);
		int middleSlot = (base * 2) / 3 + 1;
		int bottomSlot = std::max(base, Bookshelves * 2);

		m_ParentWindow.SetProperty(0, topSlot, a_Player);
		m_ParentWindow.SetProperty(1, middleSlot, a_Player);
		m_ParentWindow.SetProperty(2, bottomSlot, a_Player);
	}
	else
	{
		m_ParentWindow.SetProperty(0, 0, a_Player);
		m_ParentWindow.SetProperty(1, 0, a_Player);
		m_ParentWindow.SetProperty(2, 0, a_Player);
	}
}
예제 #4
0
void cBlockBedHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange)
{
	a_Player.GetWorld()->DoWithBedAt(a_BlockChange.GetX(), a_BlockChange.GetY(), a_BlockChange.GetZ(), [&](cBedEntity & a_Bed)
		{
			a_Bed.SetColor(a_Player.GetEquippedItem().m_ItemDamage);
			return true;
		}
	);
}
예제 #5
0
bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
	Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ);
	if (a_WorldInterface.GetDimension() != dimOverworld)
	{
		a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords);
	}
	else if (!((a_WorldInterface.GetTimeOfDay() > 12541) && (a_WorldInterface.GetTimeOfDay() < 23458)))  // Source: https://minecraft.gamepedia.com/Bed#Sleeping
	{
		a_Player.SendMessageFailure("You can only sleep at night");
	}
	else
	{
		NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(Coords);
		if ((Meta & 0x4) == 0x4)
		{
			a_Player.SendMessageFailure("This bed is occupied");
		}
		else
		{
			auto FindMobs = [](cEntity & a_Entity)
			{
				return (
					(a_Entity.GetEntityType() == cEntity::etMonster) &&
					(static_cast<cMonster&>(a_Entity).GetMobFamily() == cMonster::mfHostile)
				);
			};

			if (!a_Player.GetWorld()->ForEachEntityInBox(cBoundingBox(a_Player.GetPosition() - Vector3i(0, 5, 0), 8, 10), FindMobs))
			{
				a_Player.SendMessageFailure("You may not rest now, there are monsters nearby");
			}
			else
			{
				Vector3i PillowDirection(0, 0, 0);

				if ((Meta & 0x8) == 0x8)
				{
					// Is pillow
					a_WorldInterface.GetBroadcastManager().BroadcastUseBed(a_Player, { a_BlockX, a_BlockY, a_BlockZ });
				}
				else
				{
					// Is foot end
					VERIFY((Meta & 0x4) != 0x4);  // Occupied flag should never be set, else our compilator (intended) is broken

					PillowDirection = MetaDataToDirection(Meta & 0x3);
					if (a_ChunkInterface.GetBlock(Coords + PillowDirection) == E_BLOCK_BED)  // Must always use pillow location for sleeping
					{
						a_WorldInterface.GetBroadcastManager().BroadcastUseBed(a_Player, Vector3i{ a_BlockX, a_BlockY, a_BlockZ } + PillowDirection);
					}
				}

				a_Player.SetBedPos(Coords);
				SetBedOccupationState(a_ChunkInterface, a_Player.GetLastBedPos(), true);
				a_Player.SetIsInBed(true);
				a_Player.SendMessageSuccess("Home position set successfully");

				auto TimeFastForwardTester = [](cPlayer & a_OtherPlayer)
				{
					if (!a_OtherPlayer.IsInBed())
					{
						return true;
					}
					return false;
				};

				if (a_WorldInterface.ForEachPlayer(TimeFastForwardTester))
				{
					a_WorldInterface.ForEachPlayer([&](cPlayer & a_OtherPlayer)
						{
							cBlockBedHandler::SetBedOccupationState(a_ChunkInterface, a_OtherPlayer.GetLastBedPos(), false);
							a_OtherPlayer.SetIsInBed(false);
							return false;
						}
					);
					a_WorldInterface.SetTimeOfDay(0);
					a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x0b);  // Clear the "occupied" bit of the bed's block
				}
			}
		}
	}
	return true;
}