Explorar o código

增加action节点,增加GameEventsTest,test暂未通过

tanghai %!s(int64=14) %!d(string=hai) anos
pai
achega
86664002fd

+ 2 - 0
Cpp/CMakeLists.txt

@@ -15,6 +15,8 @@ ENDIF()
 
 INCLUDE_DIRECTORIES(Platform)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/Platform)
+INCLUDE_DIRECTORIES(Game)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/Game)
 
 FIND_PACKAGE(GFlags REQUIRED)
 INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR})

+ 0 - 14
Cpp/Game/Event/ActionIf.h

@@ -1,14 +0,0 @@
-#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

+ 19 - 18
Cpp/Game/Event/AndNode.cc

@@ -1,36 +1,37 @@
+#include <boost/foreach.hpp>
+#include "Base/Marcos.h"
 #include "Event/AndNode.h"
 
 namespace Egametang {
 
 AndNode::~AndNode()
 {
-	delete left;
-	delete right;
+	foreach(NodeIf* node, nodes)
+	{
+		delete node;
+	}
 }
 
-bool AndNode::Check(ContexIf* contex)
+bool AndNode::Run(ContexIf* contex)
 {
-	if (!left->Check(contex))
-	{
-		return false;
-	}
-	if (!right->Check(contex))
+	foreach(NodeIf* node, nodes)
 	{
-		return false;
+		if (!node->Run(contex))
+		{
+			return false;
+		}
 	}
 	return true;
 }
 
-void AndNode::AddChildNode(NodeIf *node, int type)
+void AndNode::AddChildNode(NodeIf *node)
 {
-	if (type == 0)
-	{
-		left = node;
-	}
-	else
-	{
-		right = node;
-	}
+	nodes.push_back(node);
+}
+
+NodeIf* AndNodeFactory::GetInstance(const EventNode& conf)
+{
+	return new AndNode();
 }
 
 } // namespace Egametang

+ 12 - 4
Cpp/Game/Event/AndNode.h

@@ -1,6 +1,7 @@
 #ifndef EVENT_ANDNODE_H
 #define EVENT_ANDNODE_H
 
+#include <list>
 #include "Event/NodeIf.h"
 
 namespace Egametang {
@@ -8,13 +9,20 @@ namespace Egametang {
 class AndNode: public NodeIf
 {
 private:
-	NodeIf* left;
-	NodeIf* right;
+	std::list<NodeIf*> nodes;
 
 public:
 	virtual ~AndNode();
-	virtual bool Check(ContexIf* contex);
-	virtual void AddChildNode(NodeIf *node, int type);
+
+	virtual bool Run(ContexIf* contex);
+
+	virtual void AddChildNode(NodeIf *node);
+};
+
+class AndNodeFactory: public NodeFactoryIf
+{
+public:
+	virtual NodeIf* GetInstance(const EventNode& conf);
 };
 
 } // namespace Egametang

+ 28 - 0
Cpp/Game/Event/BuffType.cc

@@ -0,0 +1,28 @@
+#include "Event/BuffType.h"
+#include "Event/ContexIf.h"
+#include "Event/SpellBuff.h"
+#include "Event/EventConf.pb.h"
+
+namespace Egametang {
+
+BuffType::BuffType(int buff_type): buff_type(buff_type)
+{
+}
+
+bool BuffType::Run(ContexIf* contex)
+{
+	Buff* buff = contex->GetBuff();
+	return buff->buff_type == buff_type;
+}
+
+BuffTypeFactory::~BuffTypeFactory()
+{
+}
+
+NodeIf* BuffTypeFactory::GetInstance(const EventNode& conf)
+{
+	return new BuffType(conf.args(0));
+}
+
+} // namespace Egametang
+

+ 6 - 6
Cpp/Game/Event/BuffTypeCondition.h → Cpp/Game/Event/BuffType.h

@@ -1,5 +1,5 @@
-#ifndef EVENT_BUFFTYPECONDITION_H
-#define EVENT_BUFFTYPECONDITION_H
+#ifndef EVENT_BUFFTYPE_H
+#define EVENT_BUFFTYPE_H
 
 #include "Event/NodeIf.h"
 
@@ -18,18 +18,18 @@ private:
 public:
 	BuffType(int buff_type);
 
-	virtual bool Check(ContexIf* contex);
+	virtual bool Run(ContexIf* contex);
 };
 
-class BuffTypeFactory: NodeFactoryIf
+class BuffTypeFactory: public NodeFactoryIf
 {
 public:
 	virtual ~BuffTypeFactory();
 
-	virtual NodeIf* GetInstance(const LogicNode& conf);
+	virtual NodeIf* GetInstance(const EventNode& conf);
 };
 
 } // namespace Egametang
 
 
-#endif // EVENT_BUFFTYPECONDITION_H
+#endif // EVENT_BUFFTYPE_H

+ 0 - 24
Cpp/Game/Event/BuffTypeCondition.cc

@@ -1,24 +0,0 @@
-#include "Event/BuffTypeCondition.h"
-
-namespace Egametang {
-
-BuffType::BuffType(int buff_type): buff_type(buff_type)
-{
-}
-
-bool BuffType::Check(ContexIf* contex)
-{
-	return true;
-}
-
-BuffTypeFactory::~BuffTypeFactory()
-{
-}
-
-NodeIf* BuffTypeFactory::GetInstance(const LogicNode& conf)
-{
-	return new BuffType(conf.args(0));
-}
-
-} // namespace Egametang
-

+ 24 - 1
Cpp/Game/Event/CMakeLists.txt

@@ -2,8 +2,31 @@ PROTOBUF_GENERATE_CPP(proto_srcs proto_hdrs
 	EventConf.proto
 )
 
-SET(EventSrc 
+SET(EventSrc
+	AndNode.cc
+	BuffType.cc
+	ChangeHealth.cc
+	CombatContex.cc
+	Event.cc
+	GameEvents.cc
+	NodeFactories.cc
+	NotNode.cc
+	OrNode.cc
 	${proto_srcs}
 )
 
 ADD_LIBRARY(Event ${EventSrc})
+
+ADD_EXECUTABLE(GameEventsTest GameEventsTest.cc)
+
+SET(Excutes 
+	GameEventsTest
+)
+
+FOREACH(Excute ${Excutes})
+	TARGET_LINK_LIBRARIES(${Excute}
+		Event
+		${ThirdPartyLibs}
+	)
+	ADD_TEST(${Excute} ${Excute})
+ENDFOREACH()

+ 42 - 0
Cpp/Game/Event/ChangeHealth.cc

@@ -0,0 +1,42 @@
+#include "Event/ChangeHealth.h"
+#include "Event/CombatContex.h"
+#include "Event/EventConf.pb.h"
+#include "Event/SpellBuff.h"
+
+namespace Egametang {
+
+ChangeHealth::ChangeHealth(int32 unit, int32 value):
+		unit(unit), value(value)
+{
+}
+
+ChangeHealth::~ChangeHealth()
+{
+}
+
+bool ChangeHealth::Run(ContexIf *contex)
+{
+	Spell* spell = contex->GetSpell();
+
+	Unit* target = NULL;
+	if (unit == 0)
+	{
+		target = spell->caster;
+	}
+	else
+	{
+		target = spell->victim;
+	}
+
+	target->health -= value;
+
+	return true;
+}
+
+NodeIf *ChangeHealthFactory::GetInstance(const EventNode& conf)
+{
+	return new ChangeHealth(conf.args(0), conf.args(1));
+}
+
+} // namespace Egametang
+

+ 31 - 0
Cpp/Game/Event/ChangeHealth.h

@@ -0,0 +1,31 @@
+#ifndef EVENT_CHANGEHEALTH_H
+#define EVENT_CHANGEHEALTH_H
+
+#include "Base/Typedef.h"
+#include "Event/NodeIf.h"
+
+namespace Egametang {
+
+class ChangeHealth: public NodeIf
+{
+private:
+	int32 unit;
+	int32 value;
+
+public:
+	ChangeHealth(int32 unit, int32 value);
+
+	virtual ~ChangeHealth();
+
+	virtual bool Run(ContexIf* contex);
+};
+
+class ChangeHealthFactory: public NodeFactoryIf
+{
+public:
+	virtual NodeIf* GetInstance(const EventNode& conf);
+};
+
+} // namespace Egametang
+
+#endif // EVENT_CHANGEHEALTH_H

+ 20 - 0
Cpp/Game/Event/CombatContex.cc

@@ -0,0 +1,20 @@
+#include "Event/CombatContex.h"
+
+namespace Egametang {
+
+CombatContex::CombatContex(Spell* spell, Buff* buff):
+	spell(spell), buff(buff)
+{
+}
+
+Spell* CombatContex::GetSpell()
+{
+	return spell;
+}
+
+Buff* CombatContex::GetBuff()
+{
+	return buff;
+}
+
+} // namespace Egametang

+ 25 - 0
Cpp/Game/Event/CombatContex.h

@@ -0,0 +1,25 @@
+#ifndef EVENT_COMBATCONTEX_H
+#define EVENT_COMBATCONTEX_H
+
+#include "Event/ContexIf.h"
+
+namespace Egametang {
+
+class CombatContex: public ContexIf
+{
+private:
+	Spell* spell;
+	Buff* buff;
+
+public:
+	CombatContex(Spell* spell, Buff* buff);
+
+	virtual Spell* GetSpell();
+
+	virtual Buff* GetBuff();
+};
+
+} // namespace Egametang
+
+#endif // EVENT_COMBATCONTEX_H
+

+ 0 - 28
Cpp/Game/Event/ConditionFactory.cc

@@ -1,28 +0,0 @@
-#include "Event/ConditionFactory.h"
-
-namespace Egametang {
-
-ConditionFactory::ConditionFactory(): factories(100)
-{
-}
-
-ConditionFactory::~ConditionFactory()
-{
-	for (std::size_t i = 0; i < factories.size(); ++i)
-	{
-		delete factories[i];
-	}
-}
-
-void ConditionFactory::Register(int type, NodeFactoryIf* factory)
-{
-	factories[type] = factory;
-}
-
-NodeIf* ConditionFactory::GetInstance(const LogicNode& conf)
-{
-	int32 type = conf.type();
-	return factories[type]->GetInstance(conf);
-}
-
-} // namespace Egametang

+ 0 - 26
Cpp/Game/Event/ConditionFactory.h

@@ -1,26 +0,0 @@
-#ifndef EVENT_CONDITIONFACTORY_H
-#define EVENT_CONDITIONFACTORY_H
-
-#include <vector>
-#include "Event/NodeIf.h"
-
-namespace Egametang {
-
-class ConditionFactory
-{
-private:
-	std::vector<NodeFactoryIf*> factories;
-
-public:
-	ConditionFactory();
-
-	~ConditionFactory();
-
-	void Register(int type, NodeFactoryIf* factory);
-
-	NodeIf* GetInstance(const LogicNode& conf);
-};
-
-} // namespace Egametang
-
-#endif // EVENT_CONDITIONFACTORY_H

+ 28 - 0
Cpp/Game/Event/ContexIf.h

@@ -0,0 +1,28 @@
+#ifndef EVENT_CONTEXIF_H
+#define EVENT_CONTEXIF_H
+
+#include <stddef.h>
+#include "Event/SpellBuff.h"
+
+namespace Egametang {
+
+class ContexIf
+{
+public:
+	virtual ~ContexIf();
+
+	virtual Spell* GetSpell()
+	{
+		return NULL;
+	}
+
+	virtual Buff* GetBuff()
+	{
+		return NULL;
+	}
+};
+
+} // namespace Egametang
+
+#endif // EVENT_CONTEXIF_H
+

+ 30 - 0
Cpp/Game/Event/Defines.proto

@@ -0,0 +1,30 @@
+package Egametang
+
+enum EventType
+{
+	ON_SPELL_START     = 0,
+	ON_SPELL_FINISH    = 1,
+	ON_ADD_BUFF        = 2,
+	ON_REMOVE_BUFF     = 3,
+	ON_HIT             = 4,
+	ON_HITTED          = 5,
+};
+
+enum NodeType
+{
+	AND = 0;
+	OR = 1;
+	NOT = 2;
+
+	// 条件子节点100 - 1001
+	BUFF_TYPE = 100;
+
+	// 行为节点
+	CHANGE_HEALTH = 1001
+};
+
+enum SpellUnit
+{
+	CASTER = 0;
+	VICTIM = 1;
+};

+ 14 - 27
Cpp/Game/Event/DotFirstDamage.txt

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

+ 9 - 7
Cpp/Game/Event/Event.cc

@@ -1,4 +1,6 @@
+#include "Base/Typedef.h"
 #include "Event/Event.h"
+#include "Event/NodeFactories.h"
 #include "Event/EventConf.pb.h"
 
 namespace Egametang {
@@ -9,23 +11,23 @@ Event::Event(NodeFactories& factories, EventConf& conf):
 	const ConditionConf& condition_conf = conf.condition();
 	if (condition_conf.has_node())
 	{
-		const LogicNode& node_conf = condition_conf.node();
+		const EventNode& node_conf = condition_conf.node();
 		BuildCondition(factories, node_conf, condition);
 	}
 }
 
 void Event::BuildCondition(
-		NodeFactories& factories, const LogicNode& conf,
+		NodeFactories& factories, const EventNode& conf,
 		NodeIf*& node)
 {
 	int32 type = conf.type();
 	node = factories.GetInstance(conf);
 	for (int i = 0; i < conf.nodes_size(); ++i)
 	{
-		const LogicNode& logic_node_conf = conf.nodes(i);
+		const EventNode& logic_node_conf = conf.nodes(i);
 		NodeIf* logic_node = NULL;
 		BuildCondition(factories, logic_node_conf, logic_node);
-		node->AddChildNode(logic_node, i);
+		node->AddChildNode(logic_node);
 	}
 }
 
@@ -35,12 +37,12 @@ Event::~Event()
 	delete action;
 }
 
-void Event::Excute(ContexIf* contex)
+void Event::Run(ContexIf* contex)
 {
-	if(condition->Check(contex))
+	if(condition->Run(contex))
 	{
 		// 执行动作
-		action->Excute(contex);
+		action->Run(contex);
 	}
 }
 

+ 10 - 5
Cpp/Game/Event/Event.h

@@ -1,24 +1,29 @@
 #ifndef EVENT_EVENT_H
 #define EVENT_EVENT_H
 
-#include "Event/ActionIf.h"
 #include "Event/NodeIf.h"
 
 namespace Egametang {
 
+class EventNode;
+class NodeFactories;
+class ConditionConf;
+class EventConf;
+
 class Event
 {
 private:
 	int type;
-	ActionIf* action;
 	NodeIf* condition;
+	NodeIf* action;
 
 	void BuildCondition(
-			NodeFactories& factories, const LogicNode& conf,
+			NodeFactories& factories, const EventNode& conf,
 			NodeIf*& condition);
 
 	void BuildAction(
-			NodeFactories& factories, const ConditionConf& conf);
+			NodeFactories& factories, const ConditionConf& conf,
+			NodeIf*& action);
 
 public:
 	Event(NodeFactories& factories, EventConf& conf);
@@ -27,7 +32,7 @@ public:
 
 	int Type() const;
 
-	void Excute(ContexIf* contex);
+	void Run(ContexIf* contex);
 };
 
 } // namespace Egametang

+ 13 - 18
Cpp/Game/Event/EventConf.proto

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

+ 7 - 12
Cpp/Game/Event/GameEvents.cc

@@ -1,33 +1,28 @@
+#include "Base/Typedef.h"
 #include "Event/GameEvents.h"
+#include "Event/EventConf.pb.h"
 
 namespace Egametang {
 
-GameEvents::GameEvents(): events(100)
+GameEvents::GameEvents(NodeFactories& factories):
+		factories(factories), events(100)
 {
 }
 
 GameEvents::~GameEvents()
 {
-	for (std::size_t i = 0; i < events.size(); ++i)
-	{
-		for (std::list<Event>::iterator iter = events[i].begin();
-			iter != events[i].end(); ++iter)
-		{
-			delete *iter;
-		}
-	}
 }
 
 void GameEvents::AddEvent(EventConf& conf)
 {
 	int32 type = conf.type();
-	Event* event = NULL;
+	Event event(factories, conf);
 	events[type].push_back(event);
 }
 
 void GameEvents::Excute(int type, ContexIf* contex)
 {
-	const std::list<Event>& es = events[type];
+	std::list<Event>& es = events[type];
 
 	for (std::list<Event>::iterator iter = es.begin(); iter != es.end();)
 	{
@@ -41,7 +36,7 @@ void GameEvents::Excute(int type, ContexIf* contex)
 			es.erase(current);
 			continue;
 		}
-		iter->Excute(contex);
+		iter->Run(contex);
 		++iter;
 	}
 }

+ 6 - 11
Cpp/Game/Event/GameEvents.h

@@ -1,27 +1,22 @@
 #ifndef EVENT_GAMEEVENTS_H
 #define EVENT_GAMEEVENTS_H
 
-#include <boost/foreach.hpp>
-#include "Base/Marcos.h"
+#include <list>
+#include <vector>
+#include "Event/Event.h"
 
 namespace Egametang {
 
-enum
-{
-	SPELL_START     = 0,
-	SPELL_FINISH    = 1,
-	ADD_BUFF        = 2,
-	REMOVE_BUFF     = 3,
-};
+class NodeFactories;
 
 class GameEvents
 {
 private:
-	ConditionFactory factories;
+	NodeFactories& factories;
 	std::vector<std::list<Event> > events;
 
 public:
-	GameEvents();
+	GameEvents(NodeFactories& factories);
 
 	~GameEvents();
 

+ 48 - 0
Cpp/Game/Event/GameEventsTest.cc

@@ -0,0 +1,48 @@
+#include <fcntl.h>
+#include <gtest/gtest.h>
+#include <gflags/gflags.h>
+#include <glog/logging.h>
+#include <iosfwd>
+#include "Event/GameEvents.h"
+#include "Event/NodeFactories.h"
+#include "Event/EventConf.pb.h"
+
+namespace Egametang {
+
+class GameEventsTest: public testing::Test
+{
+protected:
+	NodeFactories factories;
+	GameEvents game_events;
+
+public:
+	GameEventsTest():factories(), game_events(factories)
+	{
+	}
+
+	virtual ~GameEventsTest()
+	{
+	}
+};
+
+TEST_F(GameEventsTest, DotChangeHealth)
+{
+	std::string conf_file = "../../../Cpp/Game/Event/DotFirstDamage.txt";
+	EventConf conf;
+	int fd = -1;
+	fd = open(conf_file.c_str(), O_RDONLY);
+	conf.ParseFromFileDescriptor(fd);
+	VLOG(2) << "conf: " << conf.DebugString();
+	close(fd);
+}
+
+} // namespace Egametang
+
+
+int main(int argc, char* argv[])
+{
+	testing::InitGoogleTest(&argc, argv);
+	google::ParseCommandLineFlags(&argc, &argv, true);
+	google::InitGoogleLogging(argv[0]);
+	return RUN_ALL_TESTS();
+}

+ 22 - 22
Cpp/Game/Event/NodeFactories.cc

@@ -1,39 +1,39 @@
+#include "Base/Typedef.h"
+#include "Event/AndNode.h"
+#include "Event/OrNode.h"
+#include "Event/NotNode.h"
+#include "Event/BuffType.h"
+#include "Event/ChangeHealth.h"
 #include "Event/NodeFactories.h"
+#include "Event/EventConf.pb.h"
 
 namespace Egametang {
 
-NodeIf* AndNodeFactory::GetInstance(const LogicNode& conf)
+NodeFactories::NodeFactories(): factories(2000)
 {
-	return new AndNode();
-}
-
-NodeIf* AndNodeFactory::GetInstance(const LogicNode& conf)
-{
-	return new OrNode();
-}
+	factories[0] = new AndNodeFactory();
+	factories[1] = new OrNodeFactory();
+	factories[2] = new NotNodeFactory();
 
-NodeIf* AndNodeFactory::GetInstance(const LogicNode& conf)
-{
-	return new NotNode();
-}
+	// 条件节点
+	factories[101] = new BuffTypeFactory();
 
-NodeFactories::NodeFactories(ConditionFactory* condition_factory):
-		node_factories(4)
-{
-	node_factories[0] = new AndNodeFactory();
-	node_factories[1] = new OrNodeFactory();
-	node_factories[2] = new NotNodeFactory();
-	node_factories[3] = condition_factory;
+	// 行为节点
+	factories[1001] = new ChangeHealthFactory();
 }
 
 NodeFactories::~NodeFactories()
-{
+{
+	for (std::size_t i = 0; i < factories.size(); ++i)
+	{
+		delete factories[i];
+	}
 }
 
-NodeIf* NodeFactories::GetInstance(const LogicNode& conf)
+NodeIf* NodeFactories::GetInstance(const EventNode& conf)
 {
 	int32 type = conf.type();
-	return node_factories[type]->GetInstance(conf);
+	return factories[type]->GetInstance(conf);
 }
 
 }

+ 3 - 24
Cpp/Game/Event/NodeFactories.h

@@ -6,38 +6,17 @@
 
 namespace Egametang {
 
-class AndNodeFactory: public NodeFactoryIf
-{
-public:
-	virtual NodeIf* GetInstance(const LogicNode& conf);
-};
-
-
-class OrNodeFactory: public NodeFactoryIf
-{
-public:
-	virtual NodeIf* GetInstance(const LogicNode& conf);
-};
-
-
-class NotNodeFactory: public NodeFactoryIf
-{
-public:
-	virtual NodeIf* GetInstance(const LogicNode& conf);
-};
-
-
 class NodeFactories
 {
 private:
-	std::vector<NodeFactoryIf*> node_factories;
+	std::vector<NodeFactoryIf*> factories;
 
 public:
-	NodeFactories(ConditionFactory* condition_factory);
+	NodeFactories();
 
 	virtual ~NodeFactories();
 
-	virtual NodeIf* GetInstance(const LogicNode& conf);
+	virtual NodeIf* GetInstance(const EventNode& conf);
 };
 
 } // namespace Egametang

+ 8 - 12
Cpp/Game/Event/NodeIf.h

@@ -3,27 +3,23 @@
 
 namespace Egametang {
 
-class ContexIf
-{
-};
-
-enum ChildNodeType
-{
-	LEFT  = 0,
-	RIGHT = 1,
-};
+class ContexIf;
+class EventNode;
 
 class NodeIf
 {
 public:
-	virtual bool Check(ContexIf* contex) = 0;
-	virtual void AddChildNode(NodeIf *node, int type);
+	virtual bool Run(ContexIf* contex) = 0;
+
+	virtual void AddChildNode(NodeIf *node)
+	{
+	}
 };
 
 class NodeFactoryIf
 {
 public:
-	virtual NodeIf* GetInstance(const LogicNode& conf) = 0;
+	virtual NodeIf* GetInstance(const EventNode& conf) = 0;
 };
 
 } // namespace Egametang

+ 15 - 6
Cpp/Game/Event/NotNode.cc

@@ -1,22 +1,31 @@
-#include <glog/logging.h>
+#include <stddef.h>
 #include "Event/NotNode.h"
 
-namespace Egametang {
+namespace Egametang {
+
+NotNode::NotNode(): node(NULL)
+{
+}
+
 NotNode::~NotNode()
 {
 	delete node;
 }
 
-bool NotNode::Check(ContexIf* contex)
+bool NotNode::Run(ContexIf* contex)
 {
-	return !node->Check(contex);
+	return !node->Run(contex);
 }
 
-void NotNode::AddChildNode(NodeIf *node, int type)
+void NotNode::AddChildNode(NodeIf *node)
 {
-	CHECK_EQ(1, type);
 	this->node = node;
 }
 
+NodeIf* NotNodeFactory::GetInstance(const EventNode& conf)
+{
+	return new NotNode();
+}
+
 } // namespace Egametang
 

+ 12 - 2
Cpp/Game/Event/NotNode.h

@@ -11,9 +11,19 @@ private:
 	NodeIf* node;
 
 public:
+	NotNode();
+
 	virtual ~NotNode();
-	virtual bool Check(ContexIf* contex);
-	virtual void AddChildNode(NodeIf *node, int type);
+
+	virtual bool Run(ContexIf* contex);
+
+	virtual void AddChildNode(NodeIf *node);
+};
+
+class NotNodeFactory: public NodeFactoryIf
+{
+public:
+	virtual NodeIf* GetInstance(const EventNode& conf);
 };
 
 } // namespace Egametang

+ 21 - 19
Cpp/Game/Event/OrNode.cc

@@ -1,35 +1,37 @@
+#include <boost/foreach.hpp>
+#include "Base/Marcos.h"
 #include "Event/OrNode.h"
 
-namespace Egametang {
+namespace Egametang {
+
 OrNode::~OrNode()
 {
-	delete left;
-	delete right;
+	foreach(NodeIf* node, nodes)
+	{
+		delete node;
+	}
 }
 
-bool OrNode::Check(ContexIf* contex)
+bool OrNode::Run(ContexIf* contex)
 {
-	if (left->Check(contex))
-	{
-		return true;
-	}
-	if (right->Check(contex))
+	foreach(NodeIf* node, nodes)
 	{
-		return true;
+		if (!node->Run(contex))
+		{
+			return true;
+		}
 	}
 	return false;
 }
 
-void OrNode::AddChildNode(NodeIf *node, int type)
+void OrNode::AddChildNode(NodeIf *node)
 {
-	if (type == 0)
-	{
-		left = node;
-	}
-	else
-	{
-		right = node;
-	}
+	nodes.push_back(node);
+}
+
+NodeIf* OrNodeFactory::GetInstance(const EventNode& conf)
+{
+	return new OrNode();
 }
 
 } // namespace Egametang

+ 12 - 4
Cpp/Game/Event/OrNode.h

@@ -1,6 +1,7 @@
 #ifndef EVENT_ORNODE_H
 #define EVENT_ORNODE_H
 
+#include <list>
 #include "Event/NodeIf.h"
 
 namespace Egametang {
@@ -8,13 +9,20 @@ namespace Egametang {
 class OrNode: public NodeIf
 {
 private:
-	NodeIf* left;
-	NodeIf* right;
+	std::list<NodeIf*> nodes;
 
 public:
 	virtual ~OrNode();
-	virtual bool Check(ContexIf* contex);
-	virtual void AddChildNode(NodeIf *node, int type);
+
+	virtual bool Run(ContexIf* contex);
+
+	virtual void AddChildNode(NodeIf *node);
+};
+
+class OrNodeFactory: public NodeFactoryIf
+{
+public:
+	virtual NodeIf* GetInstance(const EventNode& conf);
 };
 
 } // namespace Egametang

+ 28 - 0
Cpp/Game/Event/SpellBuff.h

@@ -0,0 +1,28 @@
+#ifndef EVENT_SPELLBUFF_H
+#define EVENT_SPELLBUFF_H
+
+namespace Egametang {
+
+class Unit
+{
+public:
+	int health;
+};
+
+class Spell
+{
+public:
+	Unit* caster;
+	Unit* victim;
+};
+
+class Buff
+{
+public:
+	int buff_type;
+};
+
+} // namespace Egametang
+
+
+#endif // EVENT_SPELLBUFF_H