public void Update(uint elapsed) { for (int i = 0; i < mContainer.Length; ++i) { List <BattleUnitRandEvent> list = mContainer[i]; for (int j = 0; j < list.Count; ++j) { BattleUnitRandEvent element = list[j]; if (element.cdMilliseconds > elapsed) { element.cdMilliseconds -= elapsed; } else { element.cdMilliseconds = 0; } } // foreach (BattleUnitRandEvent element in list) // { // // } } // foreach (LinkedList<BattleUnitRandEvent> list in mContainer) // { // foreach (BattleUnitRandEvent element in list) // { // if (element.cdMilliseconds > elapsed) // element.cdMilliseconds -= elapsed; // else // element.cdMilliseconds = 0; // } // } }
public void Add(BattleUnit owner, SkillBuffTableItem buffRes, SkillRandEventTableItem randEventResource, /*const*/ ref AttackerAttr buffCreaterAttr) { BattleUnitRandEvent item = new BattleUnitRandEvent(buffRes, randEventResource); item.LoadScript(owner, ref buffCreaterAttr); mContainer[(int)randEventResource.triggerType].Add(item); }
/// <summary> /// 当triggerType指定的事件发生时, 检查randEventContainer列表, 触发随机事件. /// </summary> /// <param name="theOther">触发事件的单位.</param> /// <param name="eventOwner">为随机事件的拥有者.</param> /// <remarks>randevent的技能效果不由任何技能发起(只可以得知该随机事件是如何被注册的)</remarks> public static void ApplyRandEvent( BattleUnit theOther, BattleUnit eventOwner, BattleUnitRandEventContainer randEventContainer, RandEventTriggerType triggerType, RandEventArg triggerArg ) { List <uint> buffNeed2Remove = new List <uint>(); List <BattleUnitRandEvent> typedContainer = randEventContainer[triggerType]; //LinkedListNode<BattleUnitRandEvent> currentNode = typedContainer.First; // SkillScript可能产生新的randevent加入容器中, 导致容器改变, 因此不能通过foreach遍历. // 获取当前指定类型的容器中的元素个数, 只遍历当前的元素(新的randevent通过AddLast加入到容器中, 因此不会被遍历到). for (int i = typedContainer.Count - 1; i >= 0; --i) { BattleUnitRandEvent randEvent = typedContainer[i]; SkillRandEventTableItem randEventRes = randEvent.randEventResource; // 检查CD. if (randEvent.cdMilliseconds != 0) { continue; } // 检查概率. if (!SkillUtilities.Random100(randEventRes.probability)) { continue; } SkillClientBehaviour.AddEffect2Object(eventOwner, randEventRes._3DEffectID, randEventRes._3DEffectBindpoint); if (randEvent.mScript != null && !randEvent.mScript.RunScript(triggerArg)) { buffNeed2Remove.Add((uint)randEvent.fromBuffRes.resID); } randEvent.cdMilliseconds = randEventRes.cdMilliseconds; } // for (int count = typedContainer.Count; count != 0; --count, currentNode = currentNode.Next) // { // // } for (int i = 0; i < buffNeed2Remove.Count; ++i) { eventOwner.RemoveSkillBuffByResID(buffNeed2Remove[i]); } /* foreach (uint id in buffNeed2Remove)*/ }
public void Remove(SkillBuffTableItem buffRes, SkillEffectStopReason stopReason) { SkillRandEventTableItem randEventRes = DataManager.RandEventTable[buffRes.randEvent] as SkillRandEventTableItem; if (randEventRes == null) { return; } List <BattleUnitRandEvent> typedContainer = mContainer[(int)randEventRes.triggerType]; BattleUnitRandEvent node = typedContainer.Find(x => (x.fromBuffRes.resID == buffRes.resID && x.randEventResource.resID == randEventRes.resID)); if (node != null) { node.StopScript(stopReason); typedContainer.Remove(node); } }
public bool Equals(BattleUnitRandEvent other) { return(other != null && other.fromBuffRes.resID == fromBuffRes.resID); }