Browse Source

Do not send netpack inside netpack handler.

AlexVinS 9 years ago
parent
commit
7db7ece143
2 changed files with 19 additions and 4 deletions
  1. 14 4
      lib/mapObjects/CRewardableObject.cpp
  2. 5 0
      lib/mapObjects/CRewardableObject.h

+ 14 - 4
lib/mapObjects/CRewardableObject.cpp

@@ -440,10 +440,15 @@ void CRewardableObject::setPropertyDer(ui8 what, ui32 val)
 	}
 }
 
+void CRewardableObject::triggerRewardReset() const
+{
+	cb->setObjProperty(id, ObjProperty::REWARD_RESET, 0);
+}
+
 void CRewardableObject::newTurn(CRandomGenerator & rand) const
 {
 	if (resetDuration != 0 && cb->getDate(Date::DAY) > 1 && (cb->getDate(Date::DAY) % resetDuration) == 1)
-		cb->setObjProperty(id, ObjProperty::REWARD_RESET, 0);
+		triggerRewardReset();
 }
 
 CRewardableObject::CRewardableObject():
@@ -1042,6 +1047,14 @@ CGVisitableOPW::CGVisitableOPW()
 	resetDuration = 7;
 }
 
+void CGVisitableOPW::triggerRewardReset() const
+{
+	CRewardableObject::triggerRewardReset();
+
+	ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_CLEAR, id);
+	cb->sendAndApply(&cov);
+}
+
 void CGVisitableOPW::initObj(CRandomGenerator & rand)
 {
 	setRandomReward(rand);
@@ -1084,9 +1097,6 @@ void CGVisitableOPW::setPropertyDer(ui8 what, ui32 val)
 				reward = 500;
 			}
 		}
-
-		ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_CLEAR, id);
-		cb->sendAndApply(&cov); // that cause server hang
 	}
 
 	CRewardableObject::setPropertyDer(what, val);

+ 5 - 0
lib/mapObjects/CRewardableObject.h

@@ -191,6 +191,8 @@ protected:
 
 	virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const;
 
+	virtual void triggerRewardReset() const;
+
 	/// Rewards that can be granted by an object
 	std::vector<CVisitInfo> info;
 
@@ -315,6 +317,9 @@ public:
 
 class DLL_LINKAGE CGVisitableOPW : public CRewardableObject //objects visitable once per week
 {
+protected:
+	void triggerRewardReset() const override;
+
 public:
 	void initObj(CRandomGenerator & rand) override;