提交 d5973987 编写于 作者: T tanghai

事件分发增加了servertype配置,事件分发可以配置在不同的server中是否生效

上级 87bb8e01
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -37,8 +37,8 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Action\BuffTimeoutAction.cs" />
<Compile Include="Action\MessageAction.cs" />
<Compile Include="Event\BuffTimeoutAction.cs" />
<Compile Include="Event\MessageAction.cs" />
<Compile Include="BehaviorTreeNode\Not.cs" />
<Compile Include="BehaviorTreeNode\Selector.cs" />
<Compile Include="BehaviorTreeNode\Sequence.cs" />
......@@ -64,6 +64,7 @@
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
using Common.Event;
using Model;
using Model;
namespace Controller
{
......
using Common.Event;
using Model;
using Model;
using MongoDB.Bson;
namespace Controller
{
[Action(ActionType.BuffTimeoutAction)]
[Event(EventType.BuffTimeoutAction)]
public class BuffTimeoutAction: IEventSync
{
public void Run(Env env)
......
using System;
using System.Threading.Tasks;
using Common.Event;
using Common.Network;
using Model;
namespace Controller
{
[Action(ActionType.MessageAction)]
[Event(EventType.MessageAction)]
public class MessageAction : IEventAsync
{
public async Task RunAsync(Env env)
......
using Common.Event;
using Common.Helper;
using Common.Helper;
using Model;
using Common.Network;
......
using System;
namespace Common.Event
namespace Model
{
[AttributeUsage(AttributeTargets.Class)]
public abstract class AEventAttribute: Attribute
{
public int Type { get; private set; }
protected AEventAttribute(int type)
private int ServerType { get; set; }
protected AEventAttribute(int type, params ServerType[] serverTypes)
{
this.Type = type;
foreach (ServerType serverType in serverTypes)
{
this.ServerType |= (int) serverType;
}
}
public bool Contains(ServerType serverType)
{
if ((this.ServerType & (int)serverType) == 0)
{
return false;
}
return true;
}
}
}
\ No newline at end of file
using System;
using Common.Base;
using Common.Event;
using Common.Helper;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
......@@ -63,7 +62,7 @@ namespace Model
env[EnvKey.OwnerId] = this.OwnerId;
env[EnvKey.BuffId] = this.Id;
this.TimerId = World.Instance.GetComponent<TimerComponent>()
.Add(this.Expiration, ActionType.BuffTimeoutAction, env);
.Add(this.Expiration, EventType.BuffTimeoutAction, env);
}
}
......@@ -101,7 +100,7 @@ namespace Model
env[EnvKey.OwnerId] = this.OwnerId;
env[EnvKey.BuffId] = this.Id;
this.TimerId = World.Instance.GetComponent<TimerComponent>()
.Add(this.Expiration, ActionType.BuffTimeoutAction, env);
.Add(this.Expiration, EventType.BuffTimeoutAction, env);
}
}
......
......@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Common.Base;
using Common.Event;
using Common.Logger;
namespace Model
......
using System;
using System.Collections.Generic;
using Common.Base;
using Common.Event;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
......
......@@ -24,7 +24,7 @@ namespace Model
continue;
}
ConfigAttribute configAttribute = (ConfigAttribute) attrs[0];
if (!configAttribute.Contain(serverType))
if (!configAttribute.Contains(serverType))
{
continue;
}
......
......@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Common.Base;
using Common.Event;
namespace Model
{
......@@ -11,7 +10,6 @@ namespace Model
where AttributeType : AEventAttribute
{
private Dictionary<int, List<IEventSync>> eventSyncs;
private Dictionary<int, List<IEventAsync>> eventAsyncs;
public void Load(Assembly assembly)
......@@ -19,6 +17,8 @@ namespace Model
this.eventSyncs = new Dictionary<int, List<IEventSync>>();
this.eventAsyncs = new Dictionary<int, List<IEventAsync>>();
ServerType serverType = World.Instance.Options.ServerType;
Type[] types = assembly.GetTypes();
foreach (Type t in types)
{
......@@ -27,17 +27,22 @@ namespace Model
{
continue;
}
AEventAttribute aEventAttribute = (AEventAttribute)attrs[0];
if (!aEventAttribute.Contains(serverType))
{
continue;
}
object obj = Activator.CreateInstance(t);
IEventSync iEventSync = obj as IEventSync;
if (iEventSync != null)
{
AEventAttribute iEventAttribute = (AEventAttribute)attrs[0];
if (!this.eventSyncs.ContainsKey(iEventAttribute.Type))
if (!this.eventSyncs.ContainsKey(aEventAttribute.Type))
{
this.eventSyncs.Add(iEventAttribute.Type, new List<IEventSync>());
this.eventSyncs.Add(aEventAttribute.Type, new List<IEventSync>());
}
this.eventSyncs[iEventAttribute.Type].Add(iEventSync);
this.eventSyncs[aEventAttribute.Type].Add(iEventSync);
continue;
}
......@@ -45,13 +50,11 @@ namespace Model
// ReSharper disable once InvertIf
if (iEventAsync != null)
{
AEventAttribute iEventAttribute = (AEventAttribute)attrs[0];
if (!this.eventAsyncs.ContainsKey(iEventAttribute.Type))
if (!this.eventAsyncs.ContainsKey(aEventAttribute.Type))
{
this.eventAsyncs.Add(iEventAttribute.Type, new List<IEventAsync>());
this.eventAsyncs.Add(aEventAttribute.Type, new List<IEventAsync>());
}
this.eventAsyncs[iEventAttribute.Type].Add(iEventAsync);
this.eventAsyncs[aEventAttribute.Type].Add(iEventAsync);
continue;
}
......
using System;
using System.Reflection;
using Common.Base;
using Common.Event;
using Common.Network;
using TNet;
using UNet;
......@@ -64,8 +62,8 @@ namespace Model
env[EnvKey.Channel] = channel;
env[EnvKey.Message] = message;
#pragma warning disable 4014
World.Instance.GetComponent<EventComponent<ActionAttribute>>()
.RunAsync(ActionType.MessageAction, env);
World.Instance.GetComponent<EventComponent<EventAttribute>>()
.RunAsync(EventType.MessageAction, env);
#pragma warning restore 4014
}
}
......
using System.Collections.Generic;
using Common.Base;
using Common.Event;
using Common.Helper;
using MongoDB.Bson;
......@@ -58,12 +57,12 @@ namespace Model
{
break;
}
timeoutTimer.Enqueue(time);
this.timeoutTimer.Enqueue(time);
}
while (timeoutTimer.Count > 0)
while (this.timeoutTimer.Count > 0)
{
long key = timeoutTimer.Dequeue();
long key = this.timeoutTimer.Dequeue();
List<ObjectId> timeOutId = this.timeId[key];
foreach (ObjectId id in timeOutId)
{
......@@ -73,7 +72,7 @@ namespace Model
continue;
}
this.Remove(id);
World.Instance.GetComponent<EventComponent<ActionAttribute>>()
World.Instance.GetComponent<EventComponent<EventAttribute>>()
.Run(timer.CallbackId, timer.Env);
}
}
......
......@@ -15,7 +15,7 @@ namespace Model
}
}
public bool Contain(ServerType serverType)
public bool Contains(ServerType serverType)
{
if ((this.ServerType & (int)serverType) == 0)
{
......
using Common.Base;
namespace Common.Event
namespace Model
{
public class Env: Object
{
......
using Common.Event;
namespace Model
namespace Model
{
public class EventAttribute: AEventAttribute
{
......@@ -8,11 +6,4 @@ namespace Model
{
}
}
public class ActionAttribute: AEventAttribute
{
public ActionAttribute(int type): base(type)
{
}
}
}
\ No newline at end of file
......@@ -6,11 +6,7 @@
public const int AfterAddBuff = 1;
public const int BeforeRemoveBuff = 2;
public const int AfterRemoveBuff = 3;
}
public static class ActionType
{
public const int BuffTimeoutAction = 0;
public const int MessageAction = 1;
public const int BuffTimeoutAction = 4;
public const int MessageAction = 5;
}
}
\ No newline at end of file
using System.Threading.Tasks;
namespace Common.Event
namespace Model
{
public interface IEventAsync
{
......
namespace Common.Event
namespace Model
{
public interface IEventSync
{
......
using Common.Event;
namespace Model
namespace Model
{
/// <summary>
/// 搭配EventComponent用来分发消息
/// </summary>
public class MessageAttribute: AEventAttribute
{
public MessageAttribute(int type): base(type)
public MessageAttribute(int type, params ServerType[] serverTypes)
: base(type, serverTypes)
{
}
}
......
......@@ -45,6 +45,7 @@
<ItemGroup>
<Compile Include="ACategory.cs" />
<Compile Include="AConfig.cs" />
<Compile Include="AEventAttribute.cs" />
<Compile Include="BehaviorTree\BehaviorTree.cs" />
<Compile Include="BehaviorTree\BehaviorTreeFactory.cs" />
<Compile Include="BehaviorTree\BlackBoard.cs" />
......@@ -68,6 +69,7 @@
<Compile Include="Config\NodeConfig.cs" />
<Compile Include="Config\ServerInfoConfig.cs" />
<Compile Include="Config\UnitConfig.cs" />
<Compile Include="Env.cs" />
<Compile Include="EnvKey.cs" />
<Compile Include="EventAttribute.cs" />
<Compile Include="EventType.cs" />
......@@ -75,6 +77,8 @@
<Compile Include="IAssemblyLoader.cs" />
<Compile Include="ICategory.cs" />
<Compile Include="IConfigLoader.cs" />
<Compile Include="IEventAsync.cs" />
<Compile Include="IEventSync.cs" />
<Compile Include="IFactory.cs" />
<Compile Include="IStart.cs" />
<Compile Include="IUpdate.cs" />
......
......@@ -54,10 +54,6 @@
<Compile Include="Base\Object.cs" />
<Compile Include="Base\QueueDictionary.cs" />
<Compile Include="Base\TimerManager.cs" />
<Compile Include="Event\AEventAttribute.cs" />
<Compile Include="Event\Env.cs" />
<Compile Include="Event\IEventAsync.cs" />
<Compile Include="Event\IEventSync.cs" />
<Compile Include="Helper\BigIntegerHelper.cs" />
<Compile Include="Helper\ByteHelper.cs" />
<Compile Include="Helper\EnumHelper.cs" />
......
......@@ -23,7 +23,6 @@ namespace MongoDBTest
// 加载配置
world.AddComponent<ConfigComponent>();
world.AddComponent<EventComponent<ActionAttribute>>();
world.AddComponent<EventComponent<EventAttribute>>();
world.AddComponent<TimerComponent>();
world.AddComponent<UnitComponent>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册