Browse Source

introduce block placing cooldown

Kolja Strohm 2 years ago
parent
commit
42359dc55f
2 changed files with 16 additions and 3 deletions
  1. 15 3
      FactoryCraft/Entity.cpp
  2. 1 0
      FactoryCraft/Entity.h

+ 15 - 3
FactoryCraft/Entity.cpp

@@ -176,9 +176,16 @@ void Entity::useItem(int typeId, Item* zItem)
     }
     else if (zItem && zItem->isPlaceable())
     { // TODO: place item
-        cs.lock();
-        if (target) target->placeBlock(this, zItem);
-        cs.unlock();
+        if (placeBlockCooldown <= 0)
+        {
+            cs.lock();
+            if (target)
+            {
+                target->placeBlock(this, zItem);
+                placeBlockCooldown = 15;
+            }
+            cs.unlock();
+        }
     }
     else if (!zItem || zItem->isUsable())
     { // use item skill
@@ -351,6 +358,11 @@ void Entity::prepareTick(const Dimension* zDimension) {}
 
 void Entity::tick(const Dimension* zDimension)
 {
+    if (placeBlockCooldown > 0)
+    {
+        placeBlockCooldown--;
+    }
+    placeBlockCooldown--;
     if (time.isMeasuring())
     {
         time.messungEnde();

+ 1 - 0
FactoryCraft/Entity.h

@@ -68,6 +68,7 @@ protected:
     bool removed;
     float gravityMultiplier;
     int id;
+    int placeBlockCooldown;
     Framework::ZeitMesser time;
     Framework::Array<MovementFrame> movements;
     Framework::Critical cs;