/// <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)*/ }
/// <summary> /// 根据公式, 计算并返回实际伤害(正值). /// </summary> /// <param name="critical">是否为暴击伤害</param> /// <returns></returns> private int computeDamageByFormula(out bool critical) { critical = false; LevelCommonPropertiesItem levelProperties = DataManager.LevelCommonPropertiesTable[mAttackerAttr.AttackerLevel] as LevelCommonPropertiesItem; if (levelProperties == null) { SkillUtilities.ResourceNotFound("levelcommonproperties", mAttackerAttr.AttackerLevel); return(0); } // 等级暴击系数. float levelCriticalRate = (float)levelProperties.levelCriticalRate; float levelDefanceRate = (float)levelProperties.levelDefanceRate; if (Utility.isZero(levelCriticalRate)) { ErrorHandler.Parse(ErrorCode.ConfigError, "等级暴击系数不可为0!"); levelCriticalRate = 1; } // 暴击几率 = 暴击等级 / (等级暴击系数 + 暴击等级). float criticalProp = 100f * mAttackerAttr.CriticalLevel / (mAttackerAttr.CriticalLevel + levelCriticalRate); // 是否暴击. critical = SkillUtilities.Random100((uint)criticalProp); // 免伤百分比 = 防守方真实防护 / (防守方真实防护 + 等级防护系数). float defance = (float)mOwner.GetPropertyValue((int)PropertyTypeEnum.PropertyTypeDefance); float defancePercent = defance / (defance + levelDefanceRate); // 攻击者的实际伤害, 如果暴击, 为基本伤害的CriticalDamageScale倍. float criticalDamageScale = (critical ? GameConfig.CriticalDamageScale : 1f); float realDamage = criticalDamageScale * mAttackerAttr.AttackerDamage * mImpactRes.damageAttrPercent / 100f; // 最少造成1点血量伤害. return((int)Mathf.Max(realDamage * (1f - defancePercent), 1f)); }