Просмотр исходного кода

remove unneeded dialogId function from Chest block

Kolja Strohm 5 месяцев назад
Родитель
Сommit
7d326d1801
2 измененных файлов с 29 добавлено и 37 удалено
  1. 29 36
      FactoryCraft/Chest.cpp
  2. 0 1
      FactoryCraft/Chest.h

+ 29 - 36
FactoryCraft/Chest.cpp

@@ -18,29 +18,18 @@ Chest::Chest(int typeId, Framework::Vec3<int> pos, int dimensionId)
 
 void Chest::onDialogClosed(Framework::Text dialogId)
 {
-    if (dialogId.istGleich(getDialogId()))
-    {
-        open = 0;
-        userEntityId = 0;
-        NetworkMessage* msg = new NetworkMessage();
-        msg->animateBlockBone(getDimensionId(),
-            Game::getChunkCenter(getPos().x, getPos().y),
-            Chunk::index(Dimension::chunkCoordinates(getPos())),
-            1,
-            1.0,
-            Framework::Vec3<float>(0.5f, 0.f, 0.45f),
-            Framework::Vec3<float>(
-                0.0f, 0.f, 0.f)); // close the chest over one second
-        broadcastMessage(msg);
-    }
-}
-
-Framework::Text Chest::getDialogId() const
-{
-    Framework::Text dialogId = "chest_inventory_";
-    dialogId.append() << getDimensionId() << "," << getPos().x << ","
-                      << getPos().y << "," << getPos().z;
-    return dialogId;
+    open = 0;
+    userEntityId = 0;
+    NetworkMessage* msg = new NetworkMessage();
+    msg->animateBlockBone(getDimensionId(),
+        Game::getChunkCenter(getPos().x, getPos().y),
+        Chunk::index(Dimension::chunkCoordinates(getPos())),
+        1,
+        1.0,
+        Framework::Vec3<float>(0.5f, 0.f, 0.45f),
+        Framework::Vec3<float>(
+            0.0f, 0.f, 0.f)); // close the chest over one second
+    broadcastMessage(msg);
 }
 
 bool Chest::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
@@ -49,7 +38,7 @@ bool Chest::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
     {
         if (!Game::INSTANCE->zEntity(userEntityId))
         {
-            onDialogClosed(getDialogId());
+            onDialogClosed("");
         }
     }
     return open;
@@ -65,19 +54,23 @@ bool Chest::interact(Item* zItem, Entity* zActor, bool& itemChanged)
     }
     if (!open)
     {
-        userEntityId = zActor->getId();
-        open = 1;
         result = Block::interact(zItem, zActor, itemChanged);
-        NetworkMessage* msg = new NetworkMessage();
-        msg->animateBlockBone(getDimensionId(),
-            Game::getChunkCenter(getPos().x, getPos().y),
-            Chunk::index(Dimension::chunkCoordinates(getPos())),
-            1,
-            1.0,
-            Framework::Vec3<float>(0.5f, 0.f, 0.45f),
-            Framework::Vec3<float>(
-                0.0f, (float)(PI / 2.0), 0.f)); // open the chest over 1 second
-        broadcastMessage(msg);
+        if (result)
+        {
+            userEntityId = zActor->getId();
+            open = 1;
+            NetworkMessage* msg = new NetworkMessage();
+            msg->animateBlockBone(getDimensionId(),
+                Game::getChunkCenter(getPos().x, getPos().y),
+                Chunk::index(Dimension::chunkCoordinates(getPos())),
+                1,
+                1.0,
+                Framework::Vec3<float>(0.5f, 0.f, 0.45f),
+                Framework::Vec3<float>(0.0f,
+                    (float)(PI / 2.0),
+                    0.f)); // open the chest over 1 second
+            broadcastMessage(msg);
+        }
     }
     unlock();
     return result;

+ 0 - 1
FactoryCraft/Chest.h

@@ -9,7 +9,6 @@ private:
     int userEntityId;
 
     virtual void onDialogClosed(Framework::Text dialogId) override;
-    Framework::Text getDialogId() const;
 
 protected:
     virtual bool onTick(