diff --git a/CSharp/Game/Model/Buff.cs b/CSharp/Game/Model/Buff.cs index 3602925ad94bcd7487f44b3c16672b934858f28b..5d4c197ecf9ccb5c4537ff5fb4bf4e95661d33a0 100644 --- a/CSharp/Game/Model/Buff.cs +++ b/CSharp/Game/Model/Buff.cs @@ -4,18 +4,6 @@ namespace Model { public class Buff: Object { - private BuffType type; - - public BuffType Type - { - get - { - return this.type; - } - set - { - this.type = value; - } - } + public BuffType Type { get; set; } } } \ No newline at end of file diff --git a/CSharp/Game/Model/BuffComponent.cs b/CSharp/Game/Model/BuffComponent.cs index 5d6bc691c3c5f1a00db284c0cf93c8d48658555c..ffcaf203e12969c28c7b6363f880d40169df7db9 100644 --- a/CSharp/Game/Model/BuffComponent.cs +++ b/CSharp/Game/Model/BuffComponent.cs @@ -1,14 +1,15 @@ using System.Collections.Generic; -using System.ComponentModel; using Common.Base; using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using Component = Common.Base.Component; namespace Model { - public class BuffComponent: Component, ISupportInitialize + public class BuffComponent: Component { - public HashSet Buffs { get; set; } + [BsonElement] + private HashSet Buffs { get; set; } private Dictionary buffGuidDict { get; set; } @@ -21,11 +22,7 @@ namespace Model this.buffTypeMMap = new MultiMap(); } - void ISupportInitialize.BeginInit() - { - } - - void ISupportInitialize.EndInit() + public override void EndInit() { foreach (var buff in this.Buffs) { diff --git a/CSharp/Game/Model/GameObject.cs b/CSharp/Game/Model/GameObject.cs index cc81e5375ad6e961381dee55a7c37805bc795567..4ac0aa2bcd903bcd5b7a7738e92da2008f2329e7 100644 --- a/CSharp/Game/Model/GameObject.cs +++ b/CSharp/Game/Model/GameObject.cs @@ -9,18 +9,6 @@ namespace Model public class GameObject: Entity { - private GameObjectType type; - - public GameObjectType Type - { - get - { - return this.type; - } - set - { - this.type = value; - } - } + public GameObjectType Type { get; set; } } } \ No newline at end of file diff --git a/CSharp/Platform/Common/Base/Component.cs b/CSharp/Platform/Common/Base/Component.cs index b3a1873f0b62f0deddd689919c7a3cf24c730df2..afa3e07425467a1aa285d4cc8dbecc5146a1420f 100644 --- a/CSharp/Platform/Common/Base/Component.cs +++ b/CSharp/Platform/Common/Base/Component.cs @@ -1,13 +1,15 @@ -using MongoDB.Bson.Serialization.Attributes; +using System.ComponentModel; +using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { - public class Component: Object + public abstract class Component : Object, ISupportInitialize { private Entity owner; [BsonIgnore] - public Entity Owner { + public Entity Owner + { get { return owner; @@ -19,7 +21,11 @@ namespace Common.Base } } - protected Component() + public virtual void BeginInit() + { + } + + public virtual void EndInit() { } } diff --git a/CSharp/Platform/Common/Base/Entity.cs b/CSharp/Platform/Common/Base/Entity.cs index f9fa0c3e8eb533721edfeee20206b677589a443b..4783f99f7cd496aa37db1c3e1570dff3f774fc9c 100644 --- a/CSharp/Platform/Common/Base/Entity.cs +++ b/CSharp/Platform/Common/Base/Entity.cs @@ -1,32 +1,43 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { - public class Entity: Object + public abstract class Entity : Object, ISupportInitialize { - public Dictionary Components { get; private set; } + [BsonElement] + private HashSet Components { get; set; } + + private Dictionary ComponentDict { get; set; } protected Entity() { - this.Components = new Dictionary(); + this.Components = new HashSet(); + this.ComponentDict = new Dictionary(); } public void AddComponent() where T : Component, new() { T t = new T { Owner = this }; - this.Components.Add(typeof(T).Name, t); + this.Components.Add(t); + this.ComponentDict.Add(typeof (T), t); } public void RemoveComponent() where T : Component { - this.Components.Remove(typeof(T).Name); + Component t; + this.ComponentDict.TryGetValue(typeof(T), out t); + this.Components.Remove(t); + this.ComponentDict.Remove(typeof(T)); } public T GetComponent() where T : Component { Component t; - if (!this.Components.TryGetValue(typeof(T).Name, out t)) + if (!this.ComponentDict.TryGetValue(typeof (T), out t)) { return null; } @@ -35,7 +46,20 @@ namespace Common.Base public Component[] GetComponents() { - return this.Components.Values.ToArray(); + return this.Components.ToArray(); + } + + public virtual void BeginInit() + { + } + + public virtual void EndInit() + { + foreach (Component component in this.Components) + { + this.ComponentDict.Add(component.GetType(), component); + component.Owner = this; + } } } } \ No newline at end of file diff --git a/CSharp/Platform/Common/Base/Object.cs b/CSharp/Platform/Common/Base/Object.cs index 2a1103ed18bb0cea1d667164824261cb06804330..92c2760c7c97c515829222ebb9fc17259e63c8ad 100644 --- a/CSharp/Platform/Common/Base/Object.cs +++ b/CSharp/Platform/Common/Base/Object.cs @@ -4,14 +4,14 @@ using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { - public class Object + public abstract class Object { [BsonId] public ObjectId Guid { get; protected set; } [BsonElement] [BsonIgnoreIfNull] - public Dictionary Values; + private Dictionary Values; protected Object() {