From 4a53b1fbaac0a1531e38ba05ae2fbf090613de87 Mon Sep 17 00:00:00 2001
From: DarkGod <darkgod@net-core.org>
Date: Mon, 1 Dec 2014 13:02:29 +0100
Subject: [PATCH] Fixed a rare case of player-clone bug

---
 game/engines/default/engine/Actor.lua            | 5 +++--
 game/engines/default/engine/Map.lua              | 4 +++-
 game/modules/tome/class/WorldNPC.lua             | 2 --
 game/modules/tome/class/interface/Combat.lua     | 3 ---
 game/modules/tome/data/talents/cunning/dirty.lua | 2 --
 5 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/game/engines/default/engine/Actor.lua b/game/engines/default/engine/Actor.lua
index 5b5f092f28..174b22483f 100644
--- a/game/engines/default/engine/Actor.lua
+++ b/game/engines/default/engine/Actor.lua
@@ -193,7 +193,7 @@ function _M:move(x, y, force)
 	if not force and map:checkAllEntities(x, y, "block_move", self, true) then return true end
 
 	if self.x and self.y then
-		map:remove(self.x, self.y, Map.ACTOR)
+		map:remove(self.x, self.y, Map.ACTOR, self)
 	else
 --		print("[MOVE] actor moved without a starting position", self.name, x, y)
 	end
@@ -392,7 +392,8 @@ end
 
 function _M:deleteFromMap(map)
 	if self.x and self.y and map then
-		map:remove(self.x, self.y, engine.Map.ACTOR)
+		map:remove(self.x, self.y, engine.Map.ACTOR, self)
+		-- self.x, self.y = nil, nil
 		self:closeParticles()
 	end
 end
diff --git a/game/engines/default/engine/Map.lua b/game/engines/default/engine/Map.lua
index 759f523b7d..ef9a5c1ba9 100644
--- a/game/engines/default/engine/Map.lua
+++ b/game/engines/default/engine/Map.lua
@@ -545,9 +545,11 @@ end
 -- @param x position
 -- @param y position
 -- @param pos what kind of entity to set(Map.TERRAIN, Map.OBJECT, Map.ACTOR)
-function _M:remove(x, y, pos)
+-- @param only only remove if the value was equal to that entity
+function _M:remove(x, y, pos, only)
 	if self.map[x + y * self.w] then
 		local e = self.map[x + y * self.w][pos]
+		if only and only ~= e then return end
 		self.map[x + y * self.w][pos]= nil
 		self:updateMap(x, y)
 		self.changed = true
diff --git a/game/modules/tome/class/WorldNPC.lua b/game/modules/tome/class/WorldNPC.lua
index ebd6443dcb..7b0ef6f04a 100644
--- a/game/modules/tome/class/WorldNPC.lua
+++ b/game/modules/tome/class/WorldNPC.lua
@@ -53,8 +53,6 @@ function _M:bumpInto(target, x, y)
 		elseif target.cant_be_moved and self.cant_be_moved and target.x and target.y and self.x and self.y then
 			-- Displace
 			local tx, ty, sx, sy = target.x, target.y, self.x, self.y
-			target.x = nil target.y = nil
-			self.x = nil self.y = nil
 			target:move(sx, sy, true)
 			self:move(tx, ty, true)
 		end
diff --git a/game/modules/tome/class/interface/Combat.lua b/game/modules/tome/class/interface/Combat.lua
index 64761bbce8..af00e7a266 100644
--- a/game/modules/tome/class/interface/Combat.lua
+++ b/game/modules/tome/class/interface/Combat.lua
@@ -58,9 +58,6 @@ function _M:bumpInto(target, x, y)
 
 			-- Displace
 			local tx, ty, sx, sy = target.x, target.y, self.x, self.y
-			target.x = nil target.y = nil
-			self.x = nil self.y = nil
-
 			target:move(sx, sy, true)
 			self:move(tx, ty, true)
 			if target.describeFloor then target:describeFloor(target.x, target.y, true) end
diff --git a/game/modules/tome/data/talents/cunning/dirty.lua b/game/modules/tome/data/talents/cunning/dirty.lua
index f92b7e5ff3..dd488d79bb 100644
--- a/game/modules/tome/data/talents/cunning/dirty.lua
+++ b/game/modules/tome/data/talents/cunning/dirty.lua
@@ -109,9 +109,7 @@ newTalent{
 			self:setEffect(self.EFF_EVASION, t.getDuration(self, t), {chance=50})
 			-- Displace
 			if not target.dead then
-				self.x = nil self.y = nil
 				self:move(tx, ty, true)
-				target.x = nil target.y = nil
 				target:move(sx, sy, true)
 			end
 		end
-- 
GitLab