1
0

Add clicks, exp subtraction, item check, ...

This commit is contained in:
Howaner 2014-05-03 23:42:26 +02:00
parent 6ac332cd06
commit 7fe6e40bf7
7 changed files with 210 additions and 18 deletions

View File

@ -27,7 +27,7 @@ public:
virtual void 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) override
{
cWindow * Window = new cAnvilWindow();
cWindow * Window = new cAnvilWindow(a_BlockX, a_BlockY, a_BlockZ);
a_Player->OpenWindow(Window);
}

View File

@ -798,7 +798,7 @@ void cClientHandle::HandleAnvilItemName(const char * a_Data, unsigned int a_Leng
if (Name.length() <= 30)
{
((cAnvilWindow&)*m_Player->GetWindow()).SetRepairedItemName(Name);
((cAnvilWindow&)*m_Player->GetWindow()).SetRepairedItemName(Name, m_Player);
}
}

View File

@ -254,6 +254,10 @@ void cSandSimulator::FinishFalling(
{
// Rematerialize the material here:
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_FallingBlockType, a_FallingBlockMeta);
if (a_FallingBlockType == E_BLOCK_ANVIL)
{
a_World->BroadcastSoundParticleEffect(1022, a_BlockX, a_BlockY, a_BlockZ, 0);
}
return;
}

View File

@ -609,9 +609,152 @@ cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) :
void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
{
ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
if (a_SlotNum != 2)
{
super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
UpdateResult(a_Player);
return;
}
bool bAsync = false;
if (GetSlot(a_SlotNum, a_Player) == NULL)
{
LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
return;
}
if (a_ClickAction == caDblClick)
{
return;
}
cItem Slot(*GetSlot(a_SlotNum, a_Player));
if (!Slot.IsSameType(a_ClickedItem))
{
LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots);
LOGWARNING("My item: %s", ItemToFullString(Slot).c_str());
LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str());
bAsync = true;
}
cItem & DraggingItem = a_Player.GetDraggingItem();
if (Slot.IsEmpty())
{
return;
}
if (!DraggingItem.IsEmpty())
{
if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize())))
{
return;
}
}
if (!CanTakeResultItem(a_Player))
{
return;
}
cItem NewItem = cItem(Slot);
NewItem.m_ItemCount += DraggingItem.m_ItemCount;
Slot.Empty();
DraggingItem.Empty();
SetSlot(a_SlotNum, a_Player, Slot);
DraggingItem = NewItem;
OnTakeResult(a_Player, NewItem);
if (bAsync)
{
m_ParentWindow.BroadcastWholeWindow();
}
}
void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player, cItem a_ResultItem)
{
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;
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("", false);
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 var4 = 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, var4 | AnvilDamage << 2);
a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0);
}
}
else
{
a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0);
}
}
bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player)
{
return (
(
a_Player.IsGameModeCreative()
|| a_Player.GetXpLevel() >= m_MaximumCost
)
&& !GetSlot(2, a_Player)->IsEmpty()
&& m_MaximumCost > 0
);
}
@ -620,7 +763,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player)
{
TossItems(a_Player, 0, 3);
TossItems(a_Player, 0, 2);
super::OnPlayerRemoved(a_Player);
}
@ -642,6 +785,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
return;
}
m_MaximumCost = 0;
m_StackSizeToBeUsedInRepair = 0;
int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost();
int NeedExp = 0;
if (!SecondInput.IsEmpty())
@ -670,6 +815,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
++x;
}
m_StackSizeToBeUsedInRepair = x;
}
else
{
@ -731,18 +877,18 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// TODO: Add enchantment exp cost.
int MaximumCost = RepairCost + NeedExp;
m_MaximumCost = RepairCost + NeedExp;
if (NeedExp < 0)
{
Input.Empty();
}
if (NameChangeExp == NeedExp && NameChangeExp > 0 && MaximumCost >= 40)
if (NameChangeExp == NeedExp && NameChangeExp > 0 && m_MaximumCost >= 40)
{
MaximumCost = 39;
m_MaximumCost = 39;
}
if (MaximumCost >= 40 && !a_Player.IsGameModeCreative())
if (m_MaximumCost >= 40 && !a_Player.IsGameModeCreative())
{
Input.Empty();
}
@ -760,7 +906,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
}*/
SetSlot(2, a_Player, Input);
m_ParentWindow.SetProperty(0, MaximumCost, a_Player);
m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player);
}

View File

@ -274,12 +274,19 @@ public:
// cSlotAreaTemporary overrides:
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
protected:
bool CanTakeResultItem(cPlayer & a_Player);
void OnTakeResult(cPlayer & a_Player, cItem a_ResultItem);
/** Handles a click in the item slot. */
void UpdateResult(cPlayer & a_Player);
protected:
/** The maximum cost of repairing/renaming in the anvil. */
int m_MaximumCost;
/** The stack size of the second item where was used for repair */
char m_StackSizeToBeUsedInRepair;
} ;

View File

@ -807,11 +807,15 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cAnvilWindow:
cAnvilWindow::cAnvilWindow() :
cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
cWindow(wtAnvil, "Repair"),
m_RepairedItemName("")
m_RepairedItemName(""),
m_BlockX(a_BlockX),
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
{
m_SlotAreas.push_back(new cSlotAreaAnvil(*this));
m_AnvilSlotArea = new cSlotAreaAnvil(*this);
m_SlotAreas.push_back(m_AnvilSlotArea);
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
}
@ -820,6 +824,31 @@ cAnvilWindow::cAnvilWindow() :
void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
{
m_RepairedItemName = a_Name;
if (a_Player != NULL)
{
m_AnvilSlotArea->UpdateResult(*a_Player);
}
}
void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
{
a_PosX = m_BlockX;
a_PosY = m_BlockY;
a_PosZ = m_BlockZ;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cEnchantingWindow:

View File

@ -24,6 +24,7 @@ class cEnderChestEntity;
class cFurnaceEntity;
class cHopperEntity;
class cSlotArea;
class cSlotAreaAnvil;
class cWorld;
typedef std::list<cPlayer *> cPlayerList;
@ -236,16 +237,21 @@ class cAnvilWindow :
{
typedef cWindow super;
public:
cAnvilWindow();
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
/** Gets the repaired item name. */
AString GetRepairedItemName(void) const { return m_RepairedItemName; }
/** Set the repaired item name. */
void SetRepairedItemName(const AString & a_Name) { m_RepairedItemName = a_Name; }
void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player);
/** Get the Position from the Enchantment Table */
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
protected:
cSlotAreaAnvil * m_AnvilSlotArea;
AString m_RepairedItemName;
int m_BlockX, m_BlockY, m_BlockZ;
} ;
@ -264,7 +270,7 @@ public:
/** Return the Value of a Property */
int GetPropertyValue(int a_Property);
/** Set the Position Values to the Position of the Enchantment Table */
/** Get the Position from the Enchantment Table */
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
cSlotArea * m_SlotArea;