summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-05-01 00:47:57 +0200
committerHowaner <franzi.moos@googlemail.com>2014-05-05 17:34:17 +0200
commit3c102870f600178b7cabf6714f83e06fc05b42fd (patch)
treea9e022f5405de9c59b70ea7e664e1f5df758e3fc /src/UI
parentMerge pull request #978 from mc-server/VectorAssignmentOperator (diff)
downloadcuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar.gz
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar.bz2
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar.lz
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar.xz
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.tar.zst
cuberite-3c102870f600178b7cabf6714f83e06fc05b42fd.zip
Diffstat (limited to '')
-rw-r--r--src/UI/SlotArea.cpp173
-rw-r--r--src/UI/SlotArea.h29
-rw-r--r--src/UI/Window.cpp15
-rw-r--r--src/UI/Window.h12
4 files changed, 229 insertions, 0 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 87b4032e0..eac8257ec 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -596,6 +596,179 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cSlotAreaAnvil:
+
+cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) :
+ cSlotAreaTemporary(3, a_ParentWindow),
+ m_MaximumCost(0),
+ m_RepairedItemName("")
+{
+}
+
+
+
+
+
+void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
+{
+ super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
+ UpdateResult(a_Player);
+}
+
+
+
+
+
+void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player)
+{
+ TossItems(a_Player, 0, 3);
+ super::OnPlayerRemoved(a_Player);
+}
+
+
+
+
+
+void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
+{
+ cItem Input(*GetSlot(0, a_Player));
+ cItem SecondInput(*GetSlot(1, a_Player));
+ cItem Output(*GetSlot(2, a_Player));
+
+ if (Input.IsEmpty() && !Output.IsEmpty())
+ {
+ Output.Empty();
+ SetSlot(2, a_Player, Output);
+ m_ParentWindow.SetProperty(0, 0, a_Player);
+ return;
+ }
+
+ int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost();
+ int NeedExp = 0;
+ if (!SecondInput.IsEmpty())
+ {
+ RepairCost += cItemHandler::GetItemHandler(SecondInput)->GetRepairCost();
+
+ if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithItem(SecondInput))
+ {
+ // Tool and armor repair with special item (iron / gold / diamond / ...)
+ int DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4);
+ if (DamageDiff < 0)
+ {
+ // No enchantment
+ Output.Empty();
+ SetSlot(2, a_Player, Output);
+ m_ParentWindow.SetProperty(0, 0, a_Player);
+ return;
+ }
+
+ int x = 0;
+ while ((DamageDiff > 0) && (x < SecondInput.m_ItemCount))
+ {
+ Input.m_ItemDamage -= DamageDiff;
+ NeedExp += std::max(1, DamageDiff / 100) + Input.m_Enchantments.Size();
+ DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4);
+
+ ++x;
+ }
+ }
+ else
+ {
+ // Tool and armor repair with two tools / armors
+ if (!Input.IsSameType(SecondInput) || !Input.IsDamageable())
+ {
+ // No enchantment
+ Output.Empty();
+ SetSlot(2, a_Player, Output);
+ m_ParentWindow.SetProperty(0, 0, a_Player);
+ return;
+ }
+
+ int FirstDamageDiff = Input.GetMaxDamage() - Input.m_ItemDamage;
+ int SecondDamageDiff = SecondInput.GetMaxDamage() - SecondInput.m_ItemDamage;
+ int Damage = SecondDamageDiff + Input.GetMaxDamage() * 12 / 100;
+
+ int NewItemDamage = Input.GetMaxDamage() - (FirstDamageDiff + Damage);
+ if (NewItemDamage > 0)
+ {
+ NewItemDamage = 0;
+ }
+
+ if (NewItemDamage < Input.m_ItemDamage)
+ {
+ Input.m_ItemDamage = NewItemDamage;
+ NeedExp += std::max(1, Damage / 100);
+ }
+
+ // TODO: Add enchantments.
+ }
+ }
+
+ int NameChangeExp = 0;
+ if (m_RepairedItemName.empty())
+ {
+ // Remove custom name
+ if (!Input.m_CustomName.empty())
+ {
+ NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5);
+ NeedExp += NameChangeExp;
+ Input.m_CustomName = "";
+ }
+ }
+ else if (m_RepairedItemName != Input.m_CustomName)
+ {
+ // Change custom name
+ NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5);
+ NeedExp += NameChangeExp;
+
+ if (!Input.m_CustomName.empty())
+ {
+ RepairCost += NameChangeExp / 2;
+ }
+
+ Input.m_CustomName = m_RepairedItemName;
+ }
+
+ // TODO: Add enchantment exp cost.
+
+ int MaximumCost = RepairCost + NeedExp;
+
+ if (NeedExp < 0)
+ {
+ Input.Empty();
+ }
+
+ if (NameChangeExp == NeedExp && NameChangeExp > 0 && MaximumCost >= 40)
+ {
+ MaximumCost = 39;
+ }
+ if (MaximumCost >= 40 && !a_Player.IsGameModeCreative())
+ {
+ Input.Empty();
+ }
+
+ /* TODO: Add repair cost to cItem and not ItemHandler. This is required for this function!
+ if (!Input.IsEmpty())
+ {
+ RepairCost = max(cItemHandler::GetItemHandler(Input)->GetRepairCost(), cItemHandler::GetItemHandler(SecondInput)->GetRepairCost());
+ if (!Input.m_CustomName.empty())
+ {
+ RepairCost -= 9;
+ }
+ RepairCost = max(RepairCost, 0);
+ RepairCost += 2;
+ }*/
+
+ SetSlot(2, a_Player, Input);
+ m_ParentWindow.SetProperty(0, MaximumCost, a_Player);
+}
+
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting:
cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) :
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 254722822..a316480c6 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -9,6 +9,7 @@
#pragma once
#include "../Inventory.h"
+#include "Window.h"
@@ -259,6 +260,34 @@ protected:
+class cSlotAreaAnvil :
+ public cSlotAreaTemporary
+{
+ typedef cSlotAreaTemporary super;
+
+public:
+ cSlotAreaAnvil(cAnvilWindow & a_ParentWindow);
+
+ // cSlotArea overrides:
+ virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
+
+ // cSlotAreaTemporary overrides:
+ virtual void OnPlayerRemoved(cPlayer & a_Player) override;
+
+protected:
+ /** Handles a click in the item slot. */
+ void UpdateResult(cPlayer & a_Player);
+
+ /** The maximum cost of repairing/renaming in the anvil. */
+ int m_MaximumCost;
+
+ AString m_RepairedItemName;
+} ;
+
+
+
+
+
class cSlotAreaEnchanting :
public cSlotAreaTemporary
{
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 0a78578fc..eb105f8ab 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -805,6 +805,21 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cAnvilWindow:
+
+cAnvilWindow::cAnvilWindow() :
+ cWindow(wtAnvil, "Repair")
+{
+ m_SlotAreas.push_back(new cSlotAreaAnvil(*this));
+ m_SlotAreas.push_back(new cSlotAreaInventory(*this));
+ m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cEnchantingWindow:
cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 1ca67bfd8..c08b36f9b 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -231,6 +231,18 @@ public:
+class cAnvilWindow :
+ public cWindow
+{
+ typedef cWindow super;
+public:
+ cAnvilWindow();
+} ;
+
+
+
+
+
class cEnchantingWindow :
public cWindow
{