/// <summary> /// 检测是否符合逻辑 /// </summary> /// <param name="sk">技能</param> /// <param name="cfg">条件配置技能</param> /// <param name="caster">施法者忽略</param> /// <param name="targets">目标者们忽略</param> public bool check(RtSkData sk, ConditionConfigure cfg, ServerNPC caster, IEnumerable <ServerNPC> targets) { #if DEBUG Utils.Assert(sk == null, "Skill is null in TimeoutCondition."); Utils.Assert(cfg == null, "ConditionConfigure is null in TimeoutCondition."); #endif bool Condi = false; /// /// 1. 判定是否符合关心的BeHead类型 /// var self = this.GetType(); var classAttribute = (ConditionAttribute)Attribute.GetCustomAttribute(self, typeof(ConditionAttribute)); if (cfg.ConditionType == classAttribute.Con) { RtFakeSkData fakeSk = sk as RtFakeSkData; if (fakeSk != null) { float TimeOut = cfg.Param1 * Consts.OneThousand; /// ///2.判定是否超时 /// Condi = fakeSk.aliveDur >= TimeOut; ///3.判定概率 if (Condi) { Condi = PseudoRandom.getInstance().happen(cfg.Prop); } } } return(Condi); }
public void OnHappen(MsgParam msg, WarServerNpcMgr npcMgr) { //TODO : do something WarAnimParam warParam = msg as WarAnimParam; if (warParam != null && warParam.described != null) { //杀死人,described只有一个元素 SelfDescribed described = warParam.described; if (described.srcEnd != null) { /// /// 杀死别人,自己身上的Buff和Trigger消失 /// int casterId = described.srcEnd.param1; //int sufferId = described.srcEnd.param2; if (casterId == HangUpNpcId) { /// /// 概率上的检测 /// bool happed = PseudoRandom.getInstance().happen(cfg.Prob); if (happed) { OnEnd(); } } } } }
public Dmg toTargetDmg(NPCData self, NPCData target, EffectConfigData cfg) { ///-------- 物理伤害强度------ ///先计算自己的物理伤害, float bphyselfhit = Physical_Hit(self, cfg); ///-------- 魔法伤害强度 ------- /// 先计算自己的魔法伤害, float bMagselfhit = Magical_Hit(self, cfg); ///-------- NPC的总攻击强度,是cfg.EffectClass 类型------- float hit = bphyselfhit + bMagselfhit; //---------- 开始计算伤害 --------- float dmg = 0f; switch (cfg.EffectClass) { case SkillTypeClass.Holly: //神圣伤害不减少伤害 dmg = hit; break; case SkillTypeClass.Magical: float magenemyavoid = Magical_Avoid(target, self); dmg = hit * (1.0f - magenemyavoid); break; case SkillTypeClass.Physical: float avdenemyratio = Physical_Avoid(target, self); dmg = hit * (1.0f - avdenemyratio); break; } /// --------- 暴击伤害 ---------- /// float critialRatio = CriticalRatio(self, target, cfg); bool isCri = PseudoRandom.getInstance().happen(critialRatio); if (isCri) { float addtion = AdditionRatio(self, cfg); dmg = dmg * addtion; } Dmg final = new Dmg() { dmgValue = dmg, dmgType = cfg.EffectClass, isCritical = isCri, hitCls = HurtHitClass.None, }; return(final); }
/// <summary> /// 检测是否符合逻辑 /// </summary> /// <param name="sk">技能忽略</param> /// <param name="cfg">条件配置技能忽略</param> /// <param name="caster">施法者忽略</param> /// <param name="targets">目标者们忽略</param> public bool check(RtSkData sk, ConditionConfigure cfg, ServerNPC caster, IEnumerable <ServerNPC> targets) { #if DEBUG Utils.Assert(cfg == null, "ConditionConfigure is null in PropCondition."); #endif ///1.判定概率 bool Condi = PseudoRandom.getInstance().happen(cfg.Prop); return(Condi); }
// --- create salt ---- private byte[] generateSalt() { PseudoRandom mRandom = PseudoRandom.getInstance(); byte[] content = mRandom.generateRandom(SALT_LENGTH); // Create the file and write to it. // DANGER: System.IO.File.Create will overwrite the file if it already exists. using (FileStream fs = File.Create(saltPath)) { fs.Write(content, 0, content.Length); } return(content); }
/// 治疗值 = (p(1)*物理攻击系数+p(2)*法术攻击系数) /1000 + p(3) +p(4) * TargetAttr(MaxHP) / 1000 /// /// 疗效 = TargetAttr(BeHeal) /// 治疗值 = 治疗值 * (1+疗效) * (1+p(5) / 1000) /// /// 是否可暴击按照p(6)处理 /// 技能暴击率 = 暴击率 + p(7) / 1000 /// 技能治疗暴击提升比=治疗暴击提升比+P(8) / 1000 /// /// if 暴击 then /// 真实治疗值 = 治疗值 * 技能治疗暴击提升比 /// end if public Treat toTargetTreat(NPCData self, NPCData target, EffectConfigData cfg) { ///-------- 物理伤害强度------ ///先计算自己的物理伤害, float bphyselfhit = Physical_Hit(self, cfg); ///-------- 魔法伤害强度 ------- /// 先计算自己的魔法伤害, float bMagselfhit = Magical_Hit(self, cfg); ///-------- NPC的总攻击强度,是cfg.EffectClass 类型------- float hit = bphyselfhit + bMagselfhit + cfg.Param3 + cfg.Param4 * self.rtData.totalHp * Consts.OneThousand; /// /// ------------ 分为不可暴击 和 不计算疗效 ------------ /// TreatClass treatCls = (TreatClass)Enum.ToObject(typeof(TreatClass), cfg.Param6); bool forbid_critical = treatCls == TreatClass.Forbid_Critical; bool forbid_beheal = treatCls == TreatClass.Forbid_BeHeal; /// 治疗值 float treat = hit * (1 + cfg.Param7 * Consts.OneThousand); if (!forbid_beheal) { treat = treat * (1 + self.rtData.BeHeal); } /// --------- 暴击伤害 ---------- /// bool isCri = false; if (!forbid_critical) { float critialRatio = CriticalRatio(self, target, cfg); isCri = PseudoRandom.getInstance().happen(critialRatio); if (isCri) { float addtion = AdditionRatio(self, cfg); treat = treat * addtion; } } Treat val = new Treat() { treatValue = (int)treat, treatType = cfg.EffectClass, isCritical = isCri, }; return(val); }
// 浮动伤害 private int unstableDamage(int damage, int rate) { // 0 减值 , 1 加值 int result = PseudoRandom.getInstance().next(2); int vol = MathHelper.MidpointRounding(damage * PseudoRandom.getInstance().next(rate) * Consts.oneHundred); if (result == 1) { damage += vol; } else { damage -= vol; } return(damage); }
/// <summary> /// 检测是否符合逻辑 /// </summary> /// <param name="sk">技能,忽略</param> /// <param name="caster">施法者,忽略</param> /// <param name="targets">目标者们</param> public bool check(RtSkData sk, ConditionConfigure cfg, ServerNPC caster, IEnumerable <ServerNPC> targets) { #if DEBUG Utils.Assert(cfg == null, "ConditionConfigure is null in BeHeadCondition."); Utils.Assert(targets == null, "Targets are null in BeHeadCondition."); #endif bool Condi = false; /// /// 1. 判定是否符合关心的BeHead类型 /// var self = this.GetType(); var classAttribute = (ConditionAttribute)Attribute.GetCustomAttribute(self, typeof(ConditionAttribute)); if (cfg.ConditionType == classAttribute.Con) { //血线 float hpLineFactor = cfg.Param1 * Consts.OneThousand; //满足的个数 int Count = cfg.Param2; int curCnt = 0; foreach (ServerNPC npc in targets) { float hpLine = (int)hpLineFactor * npc.data.rtData.totalHp; if (npc.data.rtData.curHp <= hpLine) { curCnt++; } } if (curCnt >= Count) { Condi = true; } //判定概率 if (Condi) { Condi = PseudoRandom.getInstance().happen(cfg.Prop); } } return(Condi); }
/// <summary> /// 筛选,将死亡的,概率上不通过的都去除 /// </summary> /// <param name="targets">Targets.</param> /// <param name="triCfg">Tri cfg.</param> IEnumerable <ServerNPC> filtor(IEnumerable <ServerNPC> targets, TriggerConfigData triCfg) { List <ServerNPC> valid = new List <ServerNPC>(); foreach (ServerNPC bnpc in targets) { if (bnpc.data.rtData.curHp > 0) { bool happend = PseudoRandom.getInstance().happen(triCfg.Prob); if (happend) { valid.Add(bnpc); } } } return(valid.AsEnumerable <ServerNPC>()); }
void HandleDistance() { List <ServerNPC> outOfRange = new List <ServerNPC>(); List <int> Rmed = new List <int>(); ServerNPC castor = null; int cnt = checkList.Count; for (int i = 0; i < cnt; ++i) { Pair pair = checkList[i]; float radius = pair.castor.data.configData.radius + pair.target.data.configData.radius + cfg.Param1 * Consts.OneThousand; bool isIn = SelectorTools.IsInRange(pair.castor.transform.position, radius, pair.target.transform.position); if (isIn == false) { castor = pair.castor; outOfRange.Add(pair.target); Rmed.Add(i); } } if (outOfRange.Count > 0) { /// /// 做一个概率上的检测 /// IEnumerable <ServerNPC> itor = outOfRange.Where(n => PseudoRandom.getInstance().happen(cfg.Prob)); warMgr.triMgr.trigCastor.cast(castor, itor, cfg); } if (Rmed.Count > 0) { int count = Rmed.Count; for (int i = 0; i < count; ++i) { checkList.RemoveAt(Rmed[i]); } } }
/// <summary> /// 检测是否符合逻辑 /// </summary> /// <param name="sk">技能</param> /// <param name="cfg">条件配置技能, 忽略</param> /// <param name="caster">施法者, 忽略</param> /// <param name="targets">目标者们, 忽略</param> public bool check(RtSkData sk, ConditionConfigure cfg, ServerNPC caster, IEnumerable <ServerNPC> targets) { #if DEBUG Utils.Assert(sk == null, "Skill is null in CountingCondition."); Utils.Assert(cfg == null, "ConditionConfigure is null in CountingCondition."); #endif bool Condi = false; /// /// 1. 判定是否符合关心的Counting类型 /// var self = this.GetType(); var classAttribute = (ConditionAttribute)Attribute.GetCustomAttribute(self, typeof(ConditionAttribute)); if (cfg.ConditionType == classAttribute.Con) { /// /// 2. 只有RtFakeSkData才有计算功能 /// RtFakeSkData fakeSk = sk as RtFakeSkData; if (fakeSk != null) { /// /// 3. 判定计数 /// if (fakeSk.curCounting >= cfg.Param1) { Condi = true; } ///4.判定概率 if (Condi) { Condi = PseudoRandom.getInstance().happen(cfg.Prop); } } } return(Condi); }
void Start() { PseudoRandom rand = PseudoRandom.getInstance(); ThreadPool.QueueUserWorkItem((obj) => { using (var context = NetMQContext.Create()) using (pubSocket = context.CreatePublisherSocket()) { ConsoleEx.DebugLog("Publisher socket binding...", ConsoleEx.RED); pubSocket.Options.SendHighWatermark = 1000; pubSocket.Bind("tcp://*:52323"); for (var i = 0; i < 50; i++) { if (quite) { break; } var randomizedTopic = rand.next(1000); if (randomizedTopic > 50) { var msg = "TopicA msg-" + i; ConsoleEx.DebugLog("Sending message : " + msg, ConsoleEx.RED); pubSocket.SendMore("TopicA").Send(msg); } else { var msg = "TopicB msg-" + i; ConsoleEx.DebugLog("Sending message : " + msg, ConsoleEx.RED); pubSocket.SendMore("TopicB").Send(msg); } Thread.Sleep(500); } ConsoleEx.DebugLog("Publisher job is down.", ConsoleEx.RED); } }); }
/// <summary> /// specified possibility. /// </summary> /// <param name="possibility">Possibility.0-100</param> public static bool happen(int possibility) { int rnd = PseudoRandom.getInstance().next(100); return(rnd <= possibility); }
/// /// 带AI的伤害技能的实现 /// 但是要不要减伤 /// /// 〖物理伤害〗_敌=〖物理攻击力〗_敌×(1-〖物理免伤〗_自 ) /// 〖法术伤害〗_敌=〖法术攻击力〗_敌×(1-〖法术免伤〗_自 ) /// 〖伤害〗_敌=〖物理伤害〗_敌+〖法术伤害〗_敌 /// /// Self 对 target的技能伤害 /// 只考虑了输出值,并不考虑后续的反弹,护盾等情况 /// public Dmg toTargetDmg(NPCData self, NPCData target, EffectConfigData cfg) { ///-------- 物理伤害强度------ ///先计算自己的物理伤害, float bphyselfhit = Physical_Hit(self, cfg); ///-------- 魔法伤害强度 ------- /// 先计算自己的魔法伤害, float bMagselfhit = Magical_Hit(self, cfg); ///-------- NPC的总攻击强度,是cfg.EffectClass 类型------- float hit = bphyselfhit + bMagselfhit + cfg.Param3; HurtHitClass hitType = (HurtHitClass)Enum.ToObject(typeof(HurtHitClass), cfg.Param7); /// /// --------- 检测 不计算减伤 ----------- /// bool forbidArmer = hitType.check(HurtHitClass.Forbid_Armer); float dmg = 0f; if (forbidArmer) { dmg = hit; } else { switch (cfg.EffectClass) { case SkillTypeClass.Holly: //神圣伤害不减少伤害 dmg = hit; break; case SkillTypeClass.Magical: float magenemyavoid = Magical_Avoid(target, self); dmg = hit * (1.0f - magenemyavoid); break; case SkillTypeClass.Physical: float avdenemyratio = Physical_Avoid(target, self); dmg = hit * (1.0f - avdenemyratio); break; } } dmg = dmg * (1 + cfg.Param4 * Consts.OneThousand); /// --------- 暴击伤害 ---------- /// float critialRatio = CriticalRatio(self, target, cfg); bool isCri = PseudoRandom.getInstance().happen(critialRatio); if (isCri) { float addtion = AdditionRatio(self, cfg); dmg = dmg * addtion; } Dmg final = new Dmg() { dmgValue = dmg, dmgType = cfg.EffectClass, isCritical = isCri, hitCls = hitType, }; return(final); }
public EffectSelector(WarServerNpcMgr NpcMgr) { npcMgr = NpcMgr; areaSelector = new EffectAreaSelector(npcMgr); random = PseudoRandom.getInstance(); }