private async void MyCmdOpen_Click() { DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(MyDispatcherProgressBar); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); MaximumProgressBar = 5; ValueProgressBar = 0; LblTotal = "0"; LogBox.Clear(); Task <bool> resu1 = this.run(); LogBox.Add(cbLots_Item); LogBox.Add("Plase Wait..."); await resu1; LogBox.Add("Done.."); dispatcherTimer.Stop(); _Progress = 0; ValueProgressBar = 0; LblTotal = "0"; LogBox.Clear(); _run = false; }
public static (bool, LogBox) AddTFEnergyToPlayer(Player victim, Player attacker, SkillViewModel skill, decimal modifier, decimal victimHealthBefore) { var output = new LogBox { AttackerLog = " ", VictimLog = " " }; var victimMaxHealth = victim.MaxHealth; // Remember this before any form change can affect it // Move old energy to pool, add pool energy to the current attack (var energyBefore, var energyAfter) = AccumulateTFEnergy(victim, attacker, skill, modifier); var eventualForm = FormStatics.GetForm(skill.StaticSkill.FormSourceId.Value); var energyAmount = $" [{energyAfter:0.00} / {eventualForm.TFEnergyRequired:0.00} TF energy]<br />"; output.AttackerLog += energyAmount; output.VictimLog += energyAmount; // Return early if victim is already in the target form if (victim.FormSourceId == eventualForm.Id && victim.Mobility == eventualForm.MobilityType) { var noTransformMessage = $"Since {victim.GetFullName()} is already in this form, the spell has no transforming effect."; output.AttackerLog += noTransformMessage; output.VictimLog += noTransformMessage; return(false, output); } // Perform any form change logic (inc extra health damage) var formChangeLog = new LogBox(); var(complete, victimHealthAfter) = TFEnergyProcedures.RunFormChangeLogic(victim, attacker.Id, skill, energyAfter, formChangeLog); // Add the spell text to the player logs (now that we know the full damage of this hit) var percentTransformedBefore = CalculateTransformationProgress(victimHealthBefore, victimMaxHealth, energyBefore, eventualForm); var percentTransformedAfter = CalculateTransformationProgress(victimHealthAfter, victimMaxHealth, energyAfter, eventualForm); LogTransformationMessages(victim, attacker, eventualForm, percentTransformedBefore, percentTransformedAfter, output); // Append energy overflow damage and form change output from earlier output.Add(formChangeLog); // Only give XP if attacker and victim are not part of the same covenant if (attacker.Covenant == null || attacker.Covenant != victim.Covenant) { AwardXP(victim, attacker, eventualForm.MobilityType, output); } return(complete, output); }
public static (bool, string) Attack(Player attackingPlayer, Player attackedPlayer, SkillViewModel skillBeingUsed, bool timestamp = true) { var result = ""; var attacker = PlayerProcedures.GetPlayer(attackingPlayer.Id); var victim = PlayerProcedures.GetPlayer(attackedPlayer.Id); if (victim.Mobility != PvPStatics.MobilityFull || attacker.Mobility != PvPStatics.MobilityFull || victim.GameMode == (int)GameModeStatics.GameModes.Invisible || attacker.GameMode == (int)GameModeStatics.GameModes.Invisible) { return(false, ""); } var complete = false; var logs = new LogBox(); // all of our checks seem to be okay. So let's lower the player's mana and action points PlayerProcedures.ChangePlayerActionMana(-PvPStatics.AttackCost, 0, -PvPStatics.AttackManaCost, attacker.Id, timestamp); PlayerProcedures.LogCombatTimestampsAndAddAttackCount(victim, attacker); var attackerFullName = attacker.GetFullName(); var victimFullName = victim.GetFullName(); // if the spell is a curse, give the effect and that's all if (skillBeingUsed.StaticSkill.GivesEffectSourceId != null) { var effectBeingGiven = EffectStatics.GetDbStaticEffect(skillBeingUsed.StaticSkill.GivesEffectSourceId.Value); EffectProcedures.GivePerkToPlayer(skillBeingUsed.StaticSkill.GivesEffectSourceId.Value, victim); if (attacker.Gender == PvPStatics.GenderMale && !effectBeingGiven.AttackerWhenHit_M.IsNullOrEmpty()) { logs.AttackerLog += effectBeingGiven.AttackerWhenHit_M; } else if (attacker.Gender == PvPStatics.GenderFemale && !effectBeingGiven.AttackerWhenHit_F.IsNullOrEmpty()) { logs.AttackerLog += effectBeingGiven.AttackerWhenHit_F; } else { logs.AttackerLog += effectBeingGiven.AttackerWhenHit; } if (!String.IsNullOrEmpty(logs.AttackerLog)) { logs.AttackerLog += "<br><br>"; } logs.LocationLog = "<span class='playerAttackNotification'>" + attackerFullName + " cursed " + victimFullName + " with " + skillBeingUsed.StaticSkill.FriendlyName + ".</span>"; logs.AttackerLog += "You cursed " + victimFullName + " with " + skillBeingUsed.StaticSkill.FriendlyName + "."; logs.AttackerLog += " (+1 XP) "; logs.AttackerLog += PlayerProcedures.GiveXP(attacker, 1); logs.VictimLog = effectBeingGiven.MessageWhenHit; logs.VictimLog += " <span class='playerAttackNotification'>" + attackerFullName + " cursed you with <b>" + skillBeingUsed.StaticSkill.FriendlyName + "</b>.</b></span> "; result = logs.AttackerLog; } // the spell is a regular attack else { logs.LocationLog = "<span class='playerAttackNotification'>" + attackerFullName + " cast " + skillBeingUsed.StaticSkill.FriendlyName + " against " + victimFullName + ".</span>"; logs.AttackerLog = "You cast " + skillBeingUsed.StaticSkill.FriendlyName + " against " + victimFullName + ". "; logs.VictimLog = "<span class='playerAttackNotification'>" + attackerFullName + " cast " + skillBeingUsed.StaticSkill.FriendlyName + " against you.</span> "; var meBuffs = ItemProcedures.GetPlayerBuffs(attacker); var targetedBuffs = ItemProcedures.GetPlayerBuffs(victim); var rand = new Random(Guid.NewGuid().GetHashCode()); var basehitChance = rand.NextDouble() * 100; var meDmgExtra = meBuffs.SpellExtraHealthDamagePercent(); var criticalMissPercentChance = PvPStatics.CriticalMissPercentChance - meBuffs.SpellMisfireChanceReduction(); var criticalPercentChance = meBuffs.ExtraSkillCriticalPercent() + PvPStatics.CriticalHitPercentChance; var evasionPercentChance = targetedBuffs.EvasionPercent() - meBuffs.EvasionNegationPercent(); var evasionUpgrade = false; var failedAttack = false; // clamp modifiedEvasion at 50% max if (evasionPercentChance > 50) { evasionPercentChance = 50; } // critical miss! damage caster instead if (basehitChance < (double)criticalMissPercentChance) { // check if there is a health damage aspect to this spell if (skillBeingUsed.StaticSkill.HealthDamageAmount > 0) { var amountToDamage = skillBeingUsed.StaticSkill.HealthDamageAmount * (1 + meDmgExtra / 100); PlayerProcedures.DamagePlayerHealth(attacker.Id, amountToDamage); logs.AttackerLog += $"Misfire! Your spell accidentally lowered your own willpower by {amountToDamage:N2}. "; logs.VictimLog += $"Misfire! {GetPronoun_HisHer(attacker.Gender)} spell accidentally lowered {GetPronoun_hisher(attacker.Gender)} own willpower by {amountToDamage:N2}."; result += logs.AttackerLog; } failedAttack = true; } // spell is evaded else if (basehitChance < (double)criticalMissPercentChance + (double)evasionPercentChance) { // Check for a crit to upgrade the miss to a hit var criticalHitChance = rand.NextDouble() * 100; if (criticalHitChance < (double)criticalPercentChance) { evasionUpgrade = true; } else { logs.AttackerLog += victimFullName + " managed to leap out of the way of your spell."; logs.VictimLog += "You managed to leap out of the way " + attackerFullName + "'s spell."; result = logs.AttackerLog; failedAttack = true; } } // not a miss, so let's deal some damage, possibly if (!failedAttack) { decimal criticalModifier = 1; if (evasionUpgrade) { logs.AttackerLog += "<b>Piercing hit!</b> "; logs.VictimLog += "<b>Piercing hit!</b> "; } else if (rand.NextDouble() * 100 < (double)criticalPercentChance) { criticalModifier = 2; logs.AttackerLog += "<b>Critical hit!</b> "; logs.VictimLog += "<b>Critical hit!</b> "; } var initialVictimHealth = victim.Health; // check if there is a health damage aspect to this spell if (skillBeingUsed.StaticSkill.HealthDamageAmount > 0) { var targetProt = targetedBuffs.SpellHealthDamageResistance(); // calculator the modifier as extra attack - defense. 15 - 20 = -5 modifier var willpowerDamageModifierFromBonuses = 1 + ((meDmgExtra - targetProt) / 100.0M); // cap the modifier at at 50 % IF the target is a human if (willpowerDamageModifierFromBonuses < .5M) { willpowerDamageModifierFromBonuses = .5M; } // cap the modifier at 200 % IF the target is a human if (willpowerDamageModifierFromBonuses > 2 && victim.BotId == AIStatics.ActivePlayerBotId) { willpowerDamageModifierFromBonuses = 2; } var totalHealthDamage = skillBeingUsed.StaticSkill.HealthDamageAmount * willpowerDamageModifierFromBonuses * criticalModifier; // make sure damage is never in the negatives (which would heal instead) if (totalHealthDamage < 0) { totalHealthDamage = 0; } PlayerProcedures.DamagePlayerHealth(victim.Id, totalHealthDamage); // even though it's been done in the db, change the player health here as well victim.Health -= totalHealthDamage; logs.AttackerLog += $"Your spell lowered {GetPronoun_hisher(victim.Gender)} willpower by {Math.Round(totalHealthDamage, 2)}. "; logs.VictimLog += $"{GetPronoun_HisHer(attacker.Gender)} spell lowered your willpower by {Math.Round(totalHealthDamage, 2)}. "; result += logs.AttackerLog; } // if this skill has any TF power, add energy and check for form change if (skillBeingUsed.StaticSkill.TFPointsAmount > 0) { var TFEnergyDmg = meBuffs.SpellExtraTFEnergyPercent(); var TFEnergyArmor = targetedBuffs.SpellTFEnergyDamageResistance(); // calculator the modifier as extra attack - defense. var tfEnergyDamageModifierFromBonuses = 1 + ((TFEnergyDmg - TFEnergyArmor) / 100.0M); // cap the modifier at at 50 % IF the target is a human if (tfEnergyDamageModifierFromBonuses < .5M) { tfEnergyDamageModifierFromBonuses = .5M; } // cap the modifier at at 200 % IF the target is a human if (tfEnergyDamageModifierFromBonuses > 2 && victim.BotId == AIStatics.ActivePlayerBotId) { tfEnergyDamageModifierFromBonuses = 2; } var totalTFEnergyModifier = criticalModifier * tfEnergyDamageModifierFromBonuses; LogBox tfEnergyResult; (complete, tfEnergyResult) = TFEnergyProcedures.AddTFEnergyToPlayer(victim, attacker, skillBeingUsed, totalTFEnergyModifier, initialVictimHealth); logs.Add(tfEnergyResult); result = logs.AttackerLog; } } } LocationLogProcedures.AddLocationLog(attacker.dbLocationName, logs.LocationLog); PlayerLogProcedures.AddPlayerLog(attacker.Id, logs.AttackerLog, false); PlayerLogProcedures.AddPlayerLog(victim.Id, logs.VictimLog, true); DomainRegistry.AttackNotificationBroker.Notify(victim.Id, logs.VictimLog); // if this is a psycho-on-psycho battle, have a chance for the victim bot to switch targets to the attacker bot if (attacker.BotId == AIStatics.PsychopathBotId && victim.BotId == AIStatics.PsychopathBotId) { var rand = new Random(Guid.NewGuid().GetHashCode()); var botAggroRoll = rand.NextDouble(); if (botAggroRoll < .08) { AIDirectiveProcedures.SetAIDirective_Attack(victim.Id, attacker.Id); } } return(complete, result); }