tanghai 14 лет назад
Родитель
Сommit
b9cd8d37a2

+ 15 - 0
Src/Game/Event/ActionIf.h

@@ -0,0 +1,15 @@
+#ifndef EVENT_ACTIONIF_H
+#define EVENT_ACTIONIF_H
+
+namespace Egametang {
+
+class ActionIf
+{
+public:
+	virtual void Excute(ContexIf* contex) = 0;
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_ACTIONIF_H

+ 11 - 4
Src/Game/LogicTree/AndNode.cc → Src/Game/Event/AndNode.cc

@@ -1,14 +1,21 @@
 #include <boost/foreach.hpp>
 #include "Base/Marcos.h"
-#include "LogicTree/AndNode.h"
+#include "Event/AndNode.h"
 
-namespace Egametang {
+namespace Egametang {
+AndNode::~AndNode()
+{
+	foreach(LogicNodeIf* node, nodes)
+	{
+		delete node;
+	}
+}
 
-bool AndNode::Run(LogicContex* contex)
+bool AndNode::Check(ContexIf* contex)
 {
 	foreach(LogicNodeIf* node, nodes)
 	{
-		if (!node->Run(contex))
+		if (!node->Check(contex))
 		{
 			return false;
 		}

+ 21 - 0
Src/Game/Event/AndNode.h

@@ -0,0 +1,21 @@
+#ifndef EVENT_ANDNODE_H
+#define EVENT_ANDNODE_H
+
+#include "Event/LogicNodeIf.h"
+
+namespace Egametang {
+
+class AndNode: public LogicNodeIf
+{
+private:
+	std::list<LogicNodeIf*> nodes;
+
+public:
+	virtual ~AndNode();
+	virtual bool Check(ContexIf* contex);
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_ANDNODE_H

+ 32 - 0
Src/Game/Event/CMakeLists.txt

@@ -0,0 +1,32 @@
+PROTOBUF_GENERATE_CPP(proto_srcs proto_hdrs 
+	Echo.proto
+)
+
+SET(RpcSrc 
+	RpcCommunicator.cc
+	RpcController.cc
+	RequestHandler.cc
+	ResponseHandler.cc
+	RpcChannel.cc
+	RpcServer.cc
+	RpcSession.cc
+	${proto_srcs}
+)
+
+
+ADD_LIBRARY(Rpc ${RpcSrc})
+
+ADD_EXECUTABLE(RpcCommunicatorTest RpcCommunicatorTest.cc)
+
+SET(Excutes 
+	RpcCommunicatorTest
+)
+
+FOREACH(Excute ${Excutes})
+	TARGET_LINK_LIBRARIES(${Excute}
+		Rpc
+		Thread
+		${ThirdPartyLibs}
+	)
+	ADD_TEST(${Excute} ${Excute})
+ENDFOREACH()

+ 3 - 3
Src/Game/LogicTree/NotNode.cc → Src/Game/Event/ConditionNode.cc

@@ -1,12 +1,12 @@
 #include <boost/foreach.hpp>
 #include "Base/Marcos.h"
-#include "LogicTree/NotNode.h"
+#include "Event/ConditionNode.h"
 
 namespace Egametang {
 
-bool NotNode::Run(LogicContex* contex)
+bool BuffType::Check(ContexIf* contex)
 {
-	return !node->Run(contex);
+	return true;
 }
 
 } // namespace Egametang

+ 5 - 5
Src/Game/LogicTree/ConditionNode.h → Src/Game/Event/ConditionNode.h

@@ -1,7 +1,7 @@
-#ifndef LOGICTREE_CONDITIONNODE_H
-#define LOGICTREE_CONDITIONNODE_H
+#ifndef EVENT_CONDITIONNODE_H
+#define EVENT_CONDITIONNODE_H
 
-#include "LogicTree/ConditionNode.h"
+#include "Event/ConditionNode.h"
 
 namespace Egametang {
 
@@ -13,10 +13,10 @@ public:
 	int type;
 
 public:
-	virtual bool Run(LogicContex* contex);
+	virtual bool Check(ContexIf* contex);
 };
 
 } // namespace Egametang
 
 
-#endif // LOGICTREE_CONDITIONNODE_H
+#endif // EVENT_CONDITIONNODE_H

+ 27 - 0
Src/Game/Event/DotFirstDamage.txt

@@ -0,0 +1,27 @@
+EventConf
+{
+	// 事件类型
+	type: 1
+	
+	// 条件节点
+	ConditionConf 
+	{
+		LogicNode 
+		{
+			// 4表示这是一个条件节点
+			type: 4
+			// 1表示这个节点是用来判断buff类型的条件节点
+			condition: 1
+			// 2表示dot
+			args:2
+		}
+	}
+	
+	// 
+	ActionConf
+	{
+		// 扣血
+		action: 2
+		args: 100
+	}
+}

+ 42 - 0
Src/Game/Event/Event.cc

@@ -0,0 +1,42 @@
+#include "Event/Event.h"
+
+namespace Egametang {
+
+Event::Event(EventConf& conf)
+{
+	BuildCondition(conf);
+	BuildAction(conf);
+}
+
+Event::~Event()
+{
+	delete condition;
+	delete action;
+}
+
+void Event::BuildCondition(EventConf& conf)
+{
+
+}
+
+void Event::BuildAction(EventConf& conf)
+{
+
+}
+
+void Event::Excute(ContexIf* contex)
+{
+	if(condition->Check(contex))
+	{
+		// 执行动作
+		action->Excute(contex);
+	}
+}
+
+int Event::Type() const
+{
+	return type;
+}
+
+} // namespace Egametang
+

+ 31 - 0
Src/Game/Event/Event.h

@@ -0,0 +1,31 @@
+#ifndef EVENT_EVENT_H
+#define EVENT_EVENT_H
+
+#include "Event/ActionIf.h"
+#include "Event/LogicNodeIf.h"
+
+namespace Egametang {
+
+class EventConf;
+
+class Event
+{
+private:
+	int type;
+	LogicNodeIf* condition;
+	ActionIf* action;
+
+	void BuildCondition(EventConf& conf);
+	void BuildAction(EventConf& conf);
+
+public:
+	Event(EventConf& conf);
+	~Event();
+	int Type() const;
+	void Excute(ContexIf* contex);
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_EVENT_H

+ 35 - 0
Src/Game/Event/EventConf.proto

@@ -0,0 +1,35 @@
+package Egametang;
+
+message LogicNode
+{
+	// and or not condition 4种节点
+	reqired int32 type = 1;
+	// 哪种条件
+	optional int32 condition = 2;
+	// 条件需要的参数
+	repeated int32 args = 3;
+	// 包含多个子节点
+	repeated LogicNode nodes = 4;
+};
+
+message ConditionConf
+{
+	optional LogicNode node = 1
+};
+
+message ActionConf
+{
+	// 行为编号
+	required int32 id = 1;
+	repeated int32 args = 2;
+};
+
+message EventConf
+{
+	// 哪类事件
+	required int32 type = 1;
+	// 条件
+	ConditionConf condition = 2;
+	// 动作
+	ActionConf action = 3;
+};

+ 35 - 0
Src/Game/Event/GameEvents.cc

@@ -0,0 +1,35 @@
+#include "Event/GameEvents.h"
+
+namespace Egametang {
+
+GameEvents::GameEvents(): events(100)
+{
+}
+
+void GameEvents::AddEvent(Event& event)
+{
+	events[event.Type()].push_back(event);
+}
+
+void GameEvents::Excute(int type, ContexIf* contex)
+{
+	const std::list<Event>& es = events[type];
+
+	for (std::list<Event>::iterator iter = es.begin(); iter != es.end();)
+	{
+		// 暂未考虑event删除情况,每个event都会对应到一个buff
+		// 所以可以在这里遍历的时候查看相应buff是否删除,如果
+		// 删除就删除相应event
+		if (false)
+		{
+			std::list<Event>::iterator current = iter;
+			++iter;
+			es.erase(current);
+			continue;
+		}
+		iter->Excute(contex);
+		++iter;
+	}
+}
+
+} // namespace Egametang

+ 32 - 0
Src/Game/Event/GameEvents.h

@@ -0,0 +1,32 @@
+#ifndef EVENT_GAMEEVENTS_H
+#define EVENT_GAMEEVENTS_H
+
+#include <boost/foreach.hpp>
+#include "Base/Marcos.h"
+
+namespace Egametang {
+
+enum
+{
+	SPELL_START     = 0,
+	SPELL_FINISH    = 1,
+	ADD_BUFF        = 2,
+	REMOVE_BUFF     = 3,
+};
+
+class GameEvents
+{
+private:
+	std::vector<std::list<Event> > events;
+
+public:
+	GameEvents();
+
+	void AddEvent(Event& event);
+
+	void Excute(int type, ContexIf* contex);
+};
+
+} // namespace Egametang
+
+#endif // EVENT_GAMEEVENTS_H

+ 30 - 0
Src/Game/Event/LogicNodeIf.h

@@ -0,0 +1,30 @@
+#ifndef EVENT_LOGICNODEIF_H
+#define EVENT_LOGICNODEIF_H
+
+namespace Egametang {
+
+class Spell
+{
+
+};
+
+class Buff
+{
+public:
+	int type;
+};
+
+class ContexIf
+{
+};
+
+class LogicNodeIf
+{
+public:
+	virtual ~LogicNodeIf();
+	virtual bool Check(ContexIf* contex) = 0;
+};
+
+} // namespace Egametang
+
+#endif // EVENT_LOGICNODEIF_H

+ 17 - 0
Src/Game/Event/NotNode.cc

@@ -0,0 +1,17 @@
+#include <boost/foreach.hpp>
+#include "Base/Marcos.h"
+#include "Event/NotNode.h"
+
+namespace Egametang {
+NotNode::~NotNode()
+{
+	delete node;
+}
+
+bool NotNode::Check(ContexIf* contex)
+{
+	return !node->Check(contex);
+}
+
+} // namespace Egametang
+

+ 21 - 0
Src/Game/Event/NotNode.h

@@ -0,0 +1,21 @@
+#ifndef EVENT_NOTNODE_H
+#define EVENT_NOTNODE_H
+
+#include "Event/LogicNodeIf.h"
+
+namespace Egametang {
+
+class NotNode: public LogicNodeIf
+{
+private:
+	LogicNodeIf* node;
+
+public:
+	virtual ~NotNode();
+	virtual bool Check(ContexIf* contex);
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_NOTNODE_H

+ 11 - 4
Src/Game/LogicTree/OrNode.cc → Src/Game/Event/OrNode.cc

@@ -1,14 +1,21 @@
 #include <boost/foreach.hpp>
 #include "Base/Marcos.h"
-#include "LogicTree/OrNode.h"
+#include "Event/OrNode.h"
 
-namespace Egametang {
+namespace Egametang {
+OrNode::~OrNode()
+{
+	foreach(LogicNodeIf* node, nodes)
+	{
+		delete node;
+	}
+}
 
-bool OrNode::Run(LogicContex* contex)
+bool OrNode::Check(ContexIf* contex)
 {
 	foreach(LogicNodeIf* node, nodes)
 	{
-		if (node->Run(contex))
+		if (node->Check(contex))
 		{
 			return true;
 		}

+ 21 - 0
Src/Game/Event/OrNode.h

@@ -0,0 +1,21 @@
+#ifndef EVENT_ORNODE_H
+#define EVENT_ORNODE_H
+
+#include "Event/LogicNodeIf.h"
+
+namespace Egametang {
+
+class OrNode: public LogicNodeIf
+{
+private:
+	std::list<LogicNodeIf*> nodes;
+
+public:
+	virtual ~OrNode();
+	virtual bool Check(ContexIf* contex);
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_ORNODE_H

+ 0 - 20
Src/Game/LogicTree/AndNode.h

@@ -1,20 +0,0 @@
-#ifndef LOGICTREE_ANDNODE_H
-#define LOGICTREE_ANDNODE_H
-
-#include "LogicTree/LogicNodeIf.h"
-
-namespace Egametang {
-
-class AndNode: public LogicNodeIf
-{
-private:
-	std::list<LogicNodeIf*> nodes;
-
-public:
-	virtual bool Run(LogicContex* contex);
-};
-
-} // namespace Egametang
-
-
-#endif // LOGICTREE_ANDNODE_H

+ 0 - 18
Src/Game/LogicTree/ConditionNode.cc

@@ -1,18 +0,0 @@
-#include <boost/foreach.hpp>
-#include "Base/Marcos.h"
-#include "LogicTree/ConditionNode.h"
-
-namespace Egametang {
-
-bool BuffType::Run(LogicContex* contex)
-{
-	Buff* buff = contex->buff;
-	if (buff->type == type)
-	{
-		return true;
-	}
-	return false;
-}
-
-} // namespace Egametang
-

+ 0 - 35
Src/Game/LogicTree/LogicNodeIf.h

@@ -1,35 +0,0 @@
-#ifndef LOGICTREE_LOGICNODEIF_H
-#define LOGICTREE_LOGICNODEIF_H
-
-namespace Egametang {
-
-class Spell;
-class Buff;
-
-class Spell
-{
-
-};
-
-class Buff
-{
-public:
-	int type;
-};
-
-class LogicContex
-{
-public:
-	Spell* spell;
-	Buff* buff;
-};
-
-class LogicNodeIf
-{
-public:
-	virtual bool Run(LogicContex* contex) = 0;
-};
-
-} // namespace Egametang
-
-#endif // LOGICTREE_LOGICNODEIF_H

+ 0 - 20
Src/Game/LogicTree/NotNode.h

@@ -1,20 +0,0 @@
-#ifndef LOGICTREE_NOTNODE_H
-#define LOGICTREE_NOTNODE_H
-
-#include "LogicTree/LogicNodeIf.h"
-
-namespace Egametang {
-
-class NotNode: public LogicNodeIf
-{
-private:
-	LogicNodeIf* node;
-
-public:
-	virtual bool Run(LogicContex* contex);
-};
-
-} // namespace Egametang
-
-
-#endif // LOGICTREE_NOTNODE_H

+ 0 - 20
Src/Game/LogicTree/OrNode.h

@@ -1,20 +0,0 @@
-#ifndef LOGICTREE_ORNODE_H
-#define LOGICTREE_ORNODE_H
-
-#include "LogicTree/LogicNodeIf.h"
-
-namespace Egametang {
-
-class OrNode: public LogicNodeIf
-{
-private:
-	std::list<LogicNodeIf*> nodes;
-
-public:
-	virtual bool Run(LogicContex* contex);
-};
-
-} // namespace Egametang
-
-
-#endif // LOGICTREE_ORNODE_H