cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), m_PickupState(psInSurvivalOrCreative), m_DamageCoeff(2), m_IsCritical((a_Force >= 1)) { }
void cSheep::OnRightClicked(cPlayer & a_Player) { const cItem & EquippedItem = a_Player.GetEquippedItem(); if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby()) { m_IsSheared = true; m_World->BroadcastEntityMetadata(*this); a_Player.UseEquippedItem(); cItems Drops; int NumDrops = m_World->GetTickRandomNumber(2) + 1; Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); m_World->BroadcastSoundEffect("mob.sheep.shear", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f); } else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage)) { m_WoolColor = 15 - EquippedItem.m_ItemDamage; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } m_World->BroadcastEntityMetadata(*this); } }
void cRideableMinecart::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); if (m_Attachee != NULL) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) { // This player is already sitting in, they want out. a_Player.Detach(); return; } if (m_Attachee->IsPlayer()) { // Another player is already sitting in here, cannot attach return; } // Detach whatever is sitting in this minecart now: m_Attachee->Detach(); } // Attach the player to this minecart a_Player.AttachTo(this); }
void cSlotArea::DblClicked(cPlayer & a_Player, int a_SlotNum) { cItem & Dragging = a_Player.GetDraggingItem(); if (Dragging.IsEmpty()) { // Move the item in the dblclicked slot into hand: Dragging = *GetSlot(a_SlotNum, a_Player); cItem EmptyItem; SetSlot(a_SlotNum, a_Player, EmptyItem); } if (Dragging.IsEmpty()) { LOGD("%s DblClicked with an empty hand over empty slot, ignoring", a_Player.GetName().c_str()); return; } // Add as many items from the surrounding area into hand as possible: // First skip full stacks, then if there's still space, process full stacks as well: if (!m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, false)) { m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, true); } m_ParentWindow.BroadcastWholeWindow(); // We need to broadcast, in case the window was a chest opened by multiple players }
void cItemFrame::OnRightClicked(cPlayer & a_Player) { if (!m_Item.IsEmpty()) { // Item not empty, rotate, clipping values to zero to three inclusive m_Rotation++; if (m_Rotation >= 4) { m_Rotation = 0; } } else if (!a_Player.GetEquippedItem().IsEmpty()) { // Item empty, and player held item not empty - add this item to self m_Item = a_Player.GetEquippedItem(); m_Item.m_ItemCount = 1; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } } GetWorld()->BroadcastEntityMetadata(*this); // Update clients }
void cBeaconWindow::OpenedByPlayer(cPlayer & a_Player) { super::OpenedByPlayer(a_Player); a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel()); a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryEffect()); a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryEffect()); }
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; } ); }
void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) { int PixelWidth = static_cast<int>(GetPixelWidth()); int PixelX = static_cast<int>(a_Player.GetPosX() - m_CenterX) / PixelWidth + static_cast<int>(m_Width / 2); int PixelZ = static_cast<int>(a_Player.GetPosZ() - m_CenterZ) / PixelWidth + static_cast<int>(m_Height / 2); UpdateRadius(PixelX, PixelZ, a_Radius); }
void checkCatch() { if ((player_1.getPlayerPosX() == aRabbit[0]->getRabbitPosX()) && (player_1.getPlayerPosY() == aRabbit[0]->getRabbitPosY())) { cout << "\nRabbit Caught!!!\n"; aRabbit[0]->setisCaught(true); } }
void cMooshroom::OnRightClicked(cPlayer & a_Player) { switch (a_Player.GetEquippedItem().m_ItemType) { case E_ITEM_BUCKET: { if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); a_Player.GetInventory().AddItem(E_ITEM_MILK); } } break; case E_ITEM_BOWL: { if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); } } break; case E_ITEM_SHEARS: { if (!a_Player.IsGameModeCreative()) { a_Player.UseEquippedItem(); } cItems Drops; Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), mtCow, false); Destroy(); } break; } }
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); } }
cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), m_PickupState(psInSurvivalOrCreative), m_DamageCoeff(2), m_IsCritical((a_Force >= 1)), m_Timer(0), m_HitGroundTimer(0), m_bIsCollected(false), m_HitBlockPos(0, 0, 0) { }
bool cArrowEntity::CanPickup(const cPlayer & a_Player) const { switch (m_PickupState) { case psNoPickup: return false; case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); case psInCreative: return a_Player.IsGameModeCreative(); } ASSERT(!"Unhandled pickup state"); return false; }
void cCow::OnRightClicked(cPlayer & a_Player) { if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) { if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); a_Player.GetInventory().AddItem(E_ITEM_MILK); } } }
cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer & a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) { AStringVector Split(StringSplit(a_Command, " ")); if (Split.empty()) { return crUnknownCommand; } CommandMap::iterator cmd = m_Commands.find(Split[0]); if (cmd == m_Commands.end()) { // Command not found // If it started with a slash, ask the plugins if they still want to handle it: if (!a_Command.empty() && (a_Command[0] == '/')) { CommandResult Result = crUnknownCommand; CallHookExecuteCommand(&a_Player, Split, a_Command, Result); return Result; } return crUnknownCommand; } // Ask plugins first if a command is okay to execute the command: CommandResult Result = crBlocked; if (CallHookExecuteCommand(&a_Player, Split, a_Command, Result)) { if (Result == crBlocked) { LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player.GetName().c_str(), Split[0].c_str()); } return Result; } if ( a_ShouldCheckPermissions && !cmd->second.m_Permission.empty() && !a_Player.HasPermission(cmd->second.m_Permission) ) { LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player.GetName().c_str(), Split[0].c_str()); return crNoPermission; } ASSERT(cmd->second.m_Handler != nullptr); if (!cmd->second.m_Handler->ExecuteCommand(Split, &a_Player, a_Command, nullptr)) { return crError; } return crExecuted; }
void cMinecartWithFurnace::OnRightClicked(cPlayer & a_Player) { if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_COAL) { if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } m_IsFueled = true; m_World->BroadcastEntityMetadata(*this); } }
void cSlotArea::MiddleClicked(cPlayer & a_Player, int a_SlotNum) { cItem Slot(*GetSlot(a_SlotNum, a_Player)); cItem & DraggingItem = a_Player.GetDraggingItem(); if (!a_Player.IsGameModeCreative() || Slot.IsEmpty() || !DraggingItem.IsEmpty()) { return; } DraggingItem = Slot; DraggingItem.m_ItemCount = DraggingItem.GetMaxStackSize(); }
void movePlayer(char A, short d) { if (A == 'H') //H for horizontal { short newY = player_1.getPlayerPosY() + d; if (maze[player_1.getPlayerPosX()][newY] == 1) { cout << "Sorry, wall! \n"; } else { player_1.setPlayerPosY(player_1.getPlayerPosY() + d); } } if (A == 'V') //V for vertical { short newX = player_1.getPlayerPosX() + d; if (maze[newX][player_1.getPlayerPosY()] == 1) { cout << "Sorry, wall! \n"; } else { player_1.setPlayerPosX(player_1.getPlayerPosX() + d); } } }
void cSheep::OnRightClicked(cPlayer & a_Player) { if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) { m_IsSheared = true; m_World->BroadcastEntityMetadata(*this); if (!a_Player.IsGameModeCreative()) { a_Player.UseEquippedItem(); } cItems Drops; int NumDrops = m_World->GetTickRandomNumber(2) + 1; Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); } if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - a_Player.GetEquippedItem().m_ItemDamage)) { m_WoolColor = 15 - a_Player.GetEquippedItem().m_ItemDamage; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } m_World->BroadcastEntityMetadata(*this); } }
void cCreeper::OnRightClicked(cPlayer & a_Player) { if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL)) { if (!a_Player.IsGameModeCreative()) { a_Player.UseEquippedItem(); } m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); m_BurnedWithFlintAndSteel = true; } }
void cMonster::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); const cItem & EquippedItem = a_Player.GetEquippedItem(); if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty()) { SetCustomName(EquippedItem.m_CustomName); if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } } }
void cProtocol132::SendLogin(const cPlayer & a_Player, const cWorld & a_World) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_LOGIN); WriteInt (a_Player.GetUniqueID()); // EntityID of the player WriteString("default"); // Level type WriteByte ((Byte)a_Player.GetGameMode()); WriteByte ((Byte)(a_World.GetDimension())); WriteByte (2); // TODO: Difficulty WriteByte (0); // Unused, used to be world height WriteByte (8); // Client list width or something Flush(); m_LastSentDimension = a_World.GetDimension(); SendCompass(a_World); }
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); } }
void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) { const cItem * ResultSlot = GetSlot(0, a_Player); cItem & DraggingItem = a_Player.GetDraggingItem(); // Get the current recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); // If possible, craft: if (DraggingItem.IsEmpty()) { DraggingItem = Recipe.GetResult(); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } else if (DraggingItem.IsEqual(Recipe.GetResult())) { cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType); if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize()) { DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } } // Get the new recipe and update the result slot: UpdateRecipe(a_Player); // We're done. Send all changes to the client and bail out: m_ParentWindow.BroadcastWholeWindow(); }
void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) { UNUSED(a_World); cCSLock Lock(m_CSPacket); WriteByte (PACKET_LOGIN); WriteInt (a_Player.GetUniqueID()); // EntityID of the player WriteString(""); // Username, not used WriteString("default"); // Level type WriteInt ((int)a_Player.GetGameMode()); WriteInt ((int)(a_World.GetDimension())); WriteByte (2); // TODO: Difficulty WriteByte (0); // Unused WriteByte (60); // Client list width or something Flush(); }
void cProtocol125::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_COLLECT_PICKUP); WriteInt (a_Pickup.GetUniqueID()); WriteInt (a_Player.GetUniqueID()); Flush(); }
void cMinecartWithFurnace::OnRightClicked(cPlayer & a_Player) { if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_COAL) { if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); } if (!m_IsFueled) // We don't want to change the direction by right clicking it. { AddSpeed(a_Player.GetLookVector().x, 0, a_Player.GetLookVector().z); } m_IsFueled = true; m_FueledTimeLeft = m_FueledTimeLeft + 600; // The minecart will be active 600 more ticks. m_World->BroadcastEntityMetadata(*this); } }
void cProtocol132::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_COLLECT_PICKUP); WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Player.GetUniqueID()); Flush(); }
void cSlotAreaCrafting::HandleCraftItem(const cItem & a_Result, cPlayer & a_Player) { switch (a_Result.m_ItemType) { case E_BLOCK_WORKBENCH: a_Player.AwardAchievement(achCraftWorkbench); break; case E_BLOCK_FURNACE: a_Player.AwardAchievement(achCraftFurnace); break; case E_BLOCK_CAKE: a_Player.AwardAchievement(achBakeCake); break; case E_BLOCK_ENCHANTMENT_TABLE: a_Player.AwardAchievement(achCraftEnchantTable); break; case E_BLOCK_BOOKCASE: a_Player.AwardAchievement(achBookshelf); break; case E_ITEM_WOODEN_PICKAXE: a_Player.AwardAchievement(achCraftPickaxe); break; case E_ITEM_WOODEN_SWORD: a_Player.AwardAchievement(achCraftSword); break; case E_ITEM_STONE_PICKAXE: a_Player.AwardAchievement(achCraftBetterPick); break; case E_ITEM_WOODEN_HOE: a_Player.AwardAchievement(achCraftHoe); break; case E_ITEM_BREAD: a_Player.AwardAchievement(achMakeBread); break; default: break; } }
void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { cCSLock Lock(m_CSPacket); AString PlayerName(a_Player.GetColor()); PlayerName.append(a_Player.GetName()); if (PlayerName.length() > 14) { PlayerName.erase(14); } PlayerName += cChatColor::White; WriteByte ((unsigned char)PACKET_PLAYER_LIST_ITEM); WriteString(PlayerName); WriteBool (a_IsOnline); WriteShort (a_IsOnline ? a_Player.GetClientHandle()->GetPing() : 0); Flush(); }