/** 权重随机一个(intArr)(重置随机) */ public int[] randomForIntArr(ILogicEntity entity, int seedType) { int[][] intArr; if ((intArr = _intArr).Length == 0) { return(null); } int rd = 0; if (seedType == ClientRandomSeedType.Client) { rd = MathUtils.randomInt(_weight); } else { rd = entity.randomInt(_weight); } int index = 0; while (rd >= intArr[index][0]) { rd -= intArr[index++][0]; } return(intArr[index]); }
protected override void Touched(UUID entity, TouchEventArgs args) { if (!Authorize(args.AvatarName, args.AvatarID)) { return; } switch (Control.State.GetState(args.AvatarName, args.AvatarID)) { case Impl.Module.Control.NothingSelected: OnSelected(args.AvatarName, args.AvatarID); break; case SandboxControl.RouterSelected: ILogicEntity selectedRouter = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID); selectedRouter.Selected = 0d; OnSelected(args.AvatarName, args.AvatarID); break; case SandboxControl.EPSelected: ILogicEntity selectedEP = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID); selectedEP.Selected = 0d; OnSelected(args.AvatarName, args.AvatarID); break; case SandboxControl.LinkSelected: ILogicEntity selectedLink = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID); if (selectedLink.ID.Equals(entity)) { Control.State.ResetState(args.AvatarName, args.AvatarID); } else { selectedLink.Selected = 0d; Control.State.SetSelectedPrim(ID, args.AvatarName, args.AvatarID); } break; case SandboxControl.VisualiseAlgorithmSelected: Control.State.ResetState(args.AvatarName, args.AvatarID); Control.State.SetState(SandboxControl.LinkSelected, args.AvatarName, args.AvatarID); Control.State.SetSelectedPrim(ID, args.AvatarName, args.AvatarID); break; case SandboxControl.DeleteSelected: Control.Record.RemoveLink(ID, GetParameters(args.AvatarID)); break; case SandboxControl.DisplayTableSelected: //Do Nothing break; } }
public RoutingTable(IButton button, Module.Control control, IPrimFactory primFactory) { _selectedButtons = new HashSet <UUID>(); _factory = primFactory; _control = control; _button = button; foreach (var prim in button.Prims) { control.Record.MakeMapped <IEntity>(new MappableEntity(prim)); } button.OnTouched += (source, args) => { if (_selectedButtons.Contains(source)) { primFactory[source].Glow = 0d; _selectedButtons.Remove(source); if (_selectedButtons.Count == 0) { control.State.ResetState(args.AvatarName, args.AvatarID); } } else { string state = control.State.GetState(args.AvatarName, args.AvatarID); if (state.Equals(SandboxControl.EPSelected) || state.Equals(SandboxControl.RouterSelected)) { ILogicEntity selectedNode = control.State.GetSelectedEntity(args.AvatarName, args.AvatarID); _control.HostPrim.Say("Displaying forwarding table for " + selectedNode.Name); control.Model.DisplayForwardingTable(selectedNode.ID, new Parameters(), source); control.State.ResetState(args.AvatarName, args.AvatarID); } else { _selectedButtons.Add(source); if (!_prims.Contains(source)) { control.Record.MakeMapped <IEntity>(new MappableEntity(primFactory[source])); _prims.Add(source); } primFactory[source].Glow = control.ToggleGlow; control.State.SetState(SandboxControl.DisplayTableSelected, args.AvatarName, args.AvatarID); } } }; control.State.OnStateChange += (source, args) => { if (!args.NewState.Equals(SandboxControl.DisplayTableSelected)) { ResetSelected(); } }; }
// 发布消息 public virtual void PublishMessageEvent(ILogicWork logic, ILogicEntity entity) { if (!LogicFactory.ParseToCommunication.ContainsKey(entity.FindKey)) { WriteError(string.Format("逻辑:{0} 消息队列发布失败,未找到实体需要发布的解析实体:{1}", logic != null ? logic.GetType().Name : "null", entity.FindKey)); return; } // 取池 var communicationEntity = CommunicateFactory.GetOrCreateEntity(entity.FindKey); try { // 反解析 LogicFactory.ParseToCommunication[entity.FindKey].Convert(communicationEntity, entity); } catch (Exception ex) { WriteError(string.Format("逻辑:{0} 逻辑数据[{1}] 反解失败,异常:{2}", logic != null ? logic.GetType().Name : "null", entity.FindKey, ex)); // 还池,使用者还池 //CommunicateFactory.GivebackEntity(communicationEntity); return; } if (!PushQueueDic.ContainsKey(entity.FindKey)) { WriteError(string.Format("逻辑:{0} 消息队列发布失败,未找到实体需要发布的消息队列:{1}", logic != null ? logic.GetType().Name : "null", entity.FindKey)); return; } try { // 推送数据 PushQueueDic[entity.FindKey].Push(communicationEntity); } catch (Exception ex)// 传入参数由调用使用者归还 { WriteError(ex, string.Format("逻辑:{0} 消息{1}发布失败", logic != null ? logic.GetType().Name : "null", entity.FindKey)); } if (PublishMessageCount == long.MaxValue) { WriteInfo(string.Format("数据发送计数器达到最大值,计数器清空")); PublishMessageCount = 0; } // 计数器计数 System.Threading.Interlocked.Increment(ref PublishMessageCount); }
/// <summary> /// 处理下行数据逻辑 /// </summary> public void Dowork(ICommunicationEntity messge, ILogicEntity entity) { if (entity == null) { return; } var logicEntity = (FromIncomBufferEntity)entity; if (logicEntity.Buffer == null) { return; } PubulisMesssage(logicEntity.Buffer); }
/// <summary> /// 处理上行数据逻辑 /// </summary> /// <param name="messge">原消息</param> /// <param name="obj">通信实体对象</param> public void Dowork(ICommunicationEntity messge, ILogicEntity obj) { if (obj == null) { return; } var logicEntity = (FromInComEntity)obj; if (logicEntity.RealEntity == null) { return; } PubulisMesssage(logicEntity.RealEntity); }
public void Convert(ICommunicationEntity communicationEntity, ILogicEntity entity) { try { var cEntity = communicationEntity as TCEntity; OnConvert(cEntity, entity as TLEntity); SetRouteing(cEntity, entity as TLEntity); } finally { if (Service != null && Service.CommunicateFactory != null) { Service.CommunicateFactory.GivebackEntity(communicationEntity); } } }
public virtual void ResetState(string name, UUID id) { SetState(Module.Control.NothingSelected, name, id); ILogicEntity selectedPrim = GetSelectedEntity(name, id); if (selectedPrim != null) { selectedPrim.Selected = 0d; } if (_stateButtons.ContainsKey(id)) { foreach (IButton b in _stateButtons[id]) { b.SetVisualState(_control.Fade, 0d); } } }
public void SetSelectedPrim(UUID prim, string name, UUID id) { IControlEntity entity; if (_control.IsNode(prim)) { entity = _control.GetNode(prim); } else { entity = _control.GetLink(prim); } if (!entity.Authorize(name, id)) { return; } entity.Selected = _control.ToggleGlow; _selectedPrim = entity; }
/// <summary> /// 随机一个物品(可能为空) /// </summary> public ItemData randomOne(ILogicEntity entity, int seedType) { switch (type) { case RandomItemType.Single: { int[] arr = args[0]; if (arr[0] <= 0) { return(null); } return(BaseC.logic.createItem(arr[0], arr.Length > 1 ? arr[1] : 1)); } case RandomItemType.AverageItem: { int[] arr = null; if (seedType == ClientRandomSeedType.Client) { arr = args[MathUtils.randomInt(args.Length)]; } else { arr = args[entity.randomInt(args.Length)]; } if (arr[0] <= 0) { return(null); } return(BaseC.logic.createItem(arr[0], arr.Length > 1 ? arr[1] : 1)); } case RandomItemType.WeightItem: { int[] arr = _weightTool.randomForIntArr(entity, seedType); if (arr[1] <= 0) { return(null); } return(BaseC.logic.createItem(arr[1], arr.Length > 2 ? arr[2] : 1)); } case RandomItemType.WeightCreateItem: { int[] arr = _weightTool.randomForIntArr(entity, seedType); if (arr[1] <= 0) { return(null); } ItemData data = BaseC.logic.createItemByCreateID(arr[1]); data.num = arr.Length > 2 ? arr[2] : 1; return(data); } case RandomItemType.WeightRandomItem: { int[] arr = _weightTool.randomForIntArr(entity, seedType); if (arr[1] <= 0) { return(null); } return(get(arr[1]).randomOne(entity, seedType)); } } return(null); }
/// <summary> /// Store the entity that this wrapper wraps /// </summary> /// <param name = "_entity"></param> protected LogicEntityWrapper(ILogicEntity e) { this._entity = e; _log = LogManager.GetLogger(GetType()); }
/** 随机一组物品 */ public void randomItemList(SList <ItemData> list, int randItemListConfigID, ILogicEntity entity) { RandomItemListConfig.get(randItemListConfigID).randomList(list, entity); }
/** 随机一个物品(可能为空) */ public ItemData randomItem(int randomItemConfigID, ILogicEntity entity, int seedType) { return(RandomItemConfig.get(randomItemConfigID).randomOne(entity, seedType)); }
public void SetSelectedPrim(UUID prim, string name, UUID id) { IControlEntity entity; if (_control.IsNode(prim)) entity = _control.GetNode(prim); else entity = _control.GetLink(prim); if (!entity.Authorize(name, id)) return; entity.Selected = _control.ToggleGlow; _selectedPrim = entity; }
/// <summary> /// 执行对应逻辑指令 /// </summary> /// <param name="logic">逻辑操作</param> /// <param name="entity">通信实体</param> /// <param name="logicEntity">逻辑实体</param> protected virtual void Dowork(ILogicWork logic, ICommunicationEntity entity, ILogicEntity logicEntity) { logic.Dowork(entity, logicEntity); }
protected override void Touched(UUID entity, TouchEventArgs args) { if (!Authorize(args.AvatarName, args.AvatarID)) { return; } Logger.Debug(Name + " touched. Initial state " + Control.State.GetState(args.AvatarName, args.AvatarID) + "."); switch (Control.State.GetState(args.AvatarName, args.AvatarID)) { case Impl.Module.Control.NothingSelected: Control.State.SetState(SandboxControl.EPSelected, args.AvatarName, args.AvatarID); Control.State.SetSelectedPrim(ID, args.AvatarName, args.AvatarID); break; case SandboxControl.RouterSelected: UUID selectedRouter = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID).ID; Control.State.ResetState(args.AvatarName, args.AvatarID); if (!Control.AreLinked(selectedRouter, ID)) { foreach (ILogicEntity otherEnd in Control.GetNeighbours(ID)) { RemoveLink(otherEnd.ID, args.AvatarName, args.AvatarID); } AddLink(selectedRouter, args.AvatarName, args.AvatarID); } else { RemoveLink(selectedRouter, args.AvatarName, args.AvatarID); } break; case SandboxControl.EPSelected: UUID selectedEP = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID).ID; if (!selectedEP.Equals(ID)) { Send(selectedEP, args.AvatarID); } Control.State.ResetState(args.AvatarName, args.AvatarID); break; case SandboxControl.LinkSelected: ILogicEntity selectedLink = Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID); selectedLink.Selected = 0d; Control.State.SetState(SandboxControl.EPSelected, args.AvatarName, args.AvatarID); Control.State.SetSelectedPrim(ID, args.AvatarName, args.AvatarID); break; case SandboxControl.VisualiseAlgorithmSelected: VisualiseRouting(Control.State.GetSelectedEntity(args.AvatarName, args.AvatarID).ID, args.AvatarName, args.AvatarID); break; case SandboxControl.DeleteSelected: RemoveThis(args.AvatarName, args.AvatarID); break; case SandboxControl.DisplayTableSelected: DisplayForwardingTable(args.AvatarName, args.AvatarID); break; } Logger.Debug(Name + " touched. New state " + Control.State.GetState(args.AvatarName, args.AvatarID) + "."); }
/// <summary> /// 随机一组物品 /// </summary> public void randomList(SList <ItemData> list, ILogicEntity entity) { //list 不需要在这里clear ,最外层调用者负责维护 if (seedType == ClientRandomSeedType.Server) { Ctrl.throwError("此随机组不支持客户端随机"); return; } if (seedType == ClientRandomSeedType.Seed && !CommonSetting.needClientRandomSeeds) { Ctrl.throwError("此随机组模式需要开启客户端随机种子模式"); return; } switch (type) { case RandomItemListType.SingleItem: { int[] arr = args[0]; if (arr[0] > 0) { list.add(BaseC.logic.createItem(arr[0], arr.Length > 1 ? arr[1] : 1)); } } break; case RandomItemListType.SingleRandomItem: { int[] arr = args[0]; if (arr[0] > 0) { ItemData data = RandomItemConfig.get(arr[0]).randomOne(entity, seedType); if (data != null) { data.num *= (arr.Length > 1 ? arr[1] : 1); list.add(data); } } } break; case RandomItemListType.SumProbRandomItem: { foreach (int[] arr in args) { bool randomProb = false; //万分位 if (seedType == ClientRandomSeedType.Client) { randomProb = MathUtils.randomProb(arr[0], 10000); } else { randomProb = entity.randomProb(arr[0], 10000); } if (randomProb) { ItemData data = RandomItemConfig.get(arr[1]).randomOne(entity, seedType); if (data != null) { int min = arr.Length > 2 ? arr[2] : 1; int max = arr.Length > 3 ? arr[3] : min; if (min == max) { data.num *= min; } else { if (seedType == ClientRandomSeedType.Client) { data.num *= MathUtils.randomRange2(min, max); } else { data.num *= entity.randomRange2(min, max); } } list.add(data); } } } } break; case RandomItemListType.WeightRandomList: { int[] arr = _weightTool.randomForIntArr(entity, seedType); if (arr[1] > 0) { get(arr[1]).randomList(list, entity); } } break; } }
public static EntityInfo GetEntityInfo(ILogicEntity entity) { Type type = entity.GetType(); return(GetEntityInfo(type)); }
public static void InsertEntityInfo(ILogicEntity entity, EntityInfo entityInfo) { Type type = entity.GetType(); InsertEntityInfo(type, entityInfo); }