public void UpdateRTB()
 {
     rtbAttackingChars.Text    = "";
     rtbSpellcastingChars.Text = "";
     rtbCharsWithNotes.Text    = "";
     foreach (Character example in CombatHolder._makingAttackChars)
     {
         rtbAttackingChars.Text += example.CombatStuff.CombatName + "\n";
         rtbAttackingChars.Text += " Weapon =" + Convert.ToString(example.CombatStuff.CombatWeapon.ItemName) + "\n";
         rtbAttackingChars.Text += " Shield =" + Convert.ToString(example.CombatStuff.CombatShield.ItemName) + "\n";
         rtbAttackingChars.Text += " OB =" + Convert.ToString(example.CombatStuff.CombatOB) + "\n";
         rtbAttackingChars.Text += " DB =" + Convert.ToString(example.CombatStuff.CombatDB) + "\n";
         rtbAttackingChars.Text += " Roll =" + Convert.ToString(example.CombatStuff.CombatRoll) + "\n";
         double staminaReqirement = example.CombatStuff.CombatWeapon.StaminaRequirement;
         foreach (Armor arm in example.Armor)
         {
             staminaReqirement += arm.StaminaRequirement;
         }
         rtbAttackingChars.Text += " Energy Used = " + staminaReqirement + "\n";
         if (EffectHolder.GetValidEffectsByEffect(example, EffectHolder.EffectType.Focus) < 0)
         {
             rtbAttackingChars.Text += "STUNNED STUNNED STUNNED STUNNED" + "\n";
         }
         if (!(EffectHolder.GetValidEffectsByEffect(example, EffectHolder.EffectType.KO) < 1))
         {
             rtbAttackingChars.Text += "KO KO KO KO KO KO KO KO KO KO KO" + "\n";
         }
         rtbAttackingChars.Text += "\n";
     }
     foreach (Character example in CombatHolder._inCombatChars)
     {
         if (example.GoogleNinjaNotesInbound != null && example.GoogleNinjaNotesInbound != "")
         {
             rtbCharsWithNotes.Text += example.Name + "\n";
             if (example.GoogleNinjaNotesInbound.Length < 20)
             {
                 rtbCharsWithNotes.Text += "\"" + example.GoogleNinjaNotesInbound + "\"\n";
             }
             else
             {
                 rtbCharsWithNotes.Text += "\"" + example.GoogleNinjaNotesInbound.Substring(0, 18) + "...\"\n";
             }
         }
         foreach (SpellToCast stc in example.CombatStuff.SpellsToCast)
         {
             if (stc != null && stc.IsCorrectlyFormattedAndReadyToCast())
             {
                 rtbSpellcastingChars.Text += "Caster: " + stc.caster.CombatStuff.CombatName + "\n";
                 rtbSpellcastingChars.Text += "Instigator: " + example.CombatStuff.CombatName + "\n";
                 rtbSpellcastingChars.Text += "Spell: " + stc.spell.SpellName + "\n";
                 rtbSpellcastingChars.Text += "Power: " + stc.spellPower + "\n";
                 foreach (Character tar in stc.targets)
                 {
                     rtbSpellcastingChars.Text += "Target: " + tar.CombatStuff.CombatName + "\n";
                 }
                 rtbSpellcastingChars.Text += "\n";
             }
         }
     }
 }
        public static double GetWeightFactor(Character c)
        {
            double weightFactor = 0.0;

            foreach (Armor arm in c.Armor)
            {
                weightFactor += arm.Weight;
            }
            foreach (Weapon w in c.Weapons)
            {
                weightFactor += w.Weight;
            }
            foreach (Shield s in c.Shields)
            {
                weightFactor += s.Weight;
            }
            weightFactor += EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Weight);
            weightFactor  = weightFactor * -1;
            weightFactor += Convert.ToDouble(c.Statistics.Strength + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Strength));
            weightFactor += c.Skills.ArmorSkill * 0.5;
            if (weightFactor > 0)
            {
                weightFactor = weightFactor * c.CombatStuff.CombatWeapon.ExcessStrengthMultiplier;
            }
            return(weightFactor);
        }
Esempio n. 3
0
        private Boolean SaveChar()
        {
            if (!Utilities.ValidateComboBox(cboBoxWeapon.Text))
            {
                return(false);
            }
            if (!Utilities.ValidateDoubleOrNegativeTextBox(txtBoxOB.Text))
            {
                return(false);
            }
            if (!Utilities.ValidateDoubleOrNegativeTextBox(txtBoxDB.Text))
            {
                return(false);
            }
            if (!Utilities.ValidateDoubleOrNegativeTextBox(txtBoxHP.Text))
            {
                return(false);
            }
            if (!Utilities.ValidateDoubleOrNegativeTextBox(txtBoxStamina.Text))
            {
                return(false);
            }

            ThisChar.CombatStuff.CombatDB     = Convert.ToDouble(txtBoxDB.Text);
            ThisChar.CombatStuff.CombatOB     = Convert.ToDouble(txtBoxOB.Text);
            ThisChar.CombatStuff.CombatWeapon = ThisChar.Weapons.Find(A => A.ItemName == cboBoxWeapon.Text);
            ThisChar.CombatStuff.CombatShield = ThisChar.Shields.Find(A => A.ItemName == cboBoxShield.Text);
            //ThisChar.Armor = Utilities.GetArmorByName(ThisChar.Armor.ArmorName);
            ThisChar.HitPoints = Convert.ToDouble(txtBoxHP.Text) - EffectHolder.GetValidEffectsByEffect(ThisChar, EffectHolder.EffectType.Health);
            ThisChar.Stamina   = Convert.ToDouble(txtBoxStamina.Text);
            ThisChar.GoogleNinjaNotesOutbound = rtbOutbound.Text;

            CombatHolder._masterOfDeclarations.UpdateRTB();
            return(true);
        }
        public static Tuple <List <AttackOutcome>, List <Effect> > castSpell(Character caster, Character target, Spell s, double spellPower, double defensePower)
        {
            Tuple <List <AttackOutcome>, List <Effect> > ret = new Tuple <List <AttackOutcome>, List <Effect> >(new List <AttackOutcome>(), new List <Effect>());

            spellPower += EffectHolder.GetValidEffectsByEffect(caster, EffectHolder.EffectType.SpellBonus);
            foreach (Effect eff in s.SpellEffects.Keys)
            {
                Effect effMultiplied = new Effect(eff.effectTypes,
                                                  eff.effectStrength + s.SpellEffects[eff].Item1 * spellPower,
                                                  eff.effectLength + (int)Math.Round(s.SpellEffects[eff].Item2 * spellPower),
                                                  eff.deterioration + s.SpellEffects[eff].Item3 * spellPower);
                effMultiplied.effectTag = eff.effectTag;
                ret.Item2.Add(effMultiplied);
            }

            foreach (Weapon weap in s.SpellWeapons.Keys)
            {
                Weapon save = caster.CombatStuff.CombatWeapon;
                caster.CombatStuff.CombatWeapon = Utilities.GetWeaponByName(weap.ItemName);

                AttackOutcome outcome = CombatScripts.RunCombat(caster.MakeDeepCopy(), target, s.SpellWeapons[weap] + spellPower, defensePower, null);
                outcome.Attacker.CombatStuff.attackResultsForDisplay = new List <List <string> >();
                outcome.Defender.CombatStuff.defendResultsForDisplay = new List <List <string> >();
                ret.Item1.Add(outcome);

                caster.CombatStuff.CombatWeapon = save;
            }


            return(ret);
        }
 public static void removeOverhealFromCharacters()
 {
     foreach (Character c in CombatHolder._inCombatChars)
     {
         c.HitPoints = System.Math.Min(c.HitPoints, GetBaseHealth(c) + (int)EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Health));
         c.Stamina   = System.Math.Min(c.Stamina, GetBaseStamina(c));
     }
 }
        // when the save effect button is pressed
        //reads the form, and adds the effect
        private void button1_Click(object sender, EventArgs e)
        {
            if (!ValidateAll())
            {
                return;
            }
            Effect NewEffect = readForm();

            if (Utilities.EffectableTypes.Character == (Utilities.EffectableTypes)comboBoxEffectableTypes.SelectedItem)
            {
                EffectHolder.CreateEffect(NewEffect, Utilities.getCharacterFromXmlOrCombatHolderByString(cboBoxName.Text), ckBoxPermanent.Checked);
            }
            else
            {
                Item toAffect = new Item();

                if (comboBoxEffectableTypes.Text == "Item")
                {
                    toAffect = Utilities.GetItemByName(cboBoxName.Text);
                }
                if (comboBoxEffectableTypes.Text == "Shield")
                {
                    toAffect = Utilities.GetShieldByName(cboBoxName.Text);
                }
                if (comboBoxEffectableTypes.Text == "Weapon")
                {
                    toAffect = Utilities.GetWeaponByName(cboBoxName.Text);
                }
                if (comboBoxEffectableTypes.Text == "Armor")
                {
                    toAffect = Utilities.GetArmorByName(cboBoxName.Text);
                }

                toAffect.ItemEffects.Add(NewEffect);

                if (comboBoxEffectableTypes.Text == "Item")
                {
                    Utilities.SaveItem(toAffect);
                }
                if (comboBoxEffectableTypes.Text == "Shield")
                {
                    Utilities.SaveShield((Shield)toAffect);
                }
                if (comboBoxEffectableTypes.Text == "Weapon")
                {
                    Utilities.SaveWeapon((Weapon)toAffect);
                }
                if (comboBoxEffectableTypes.Text == "Armor")
                {
                    Utilities.SaveArmor((Armor)toAffect);
                }

                Utilities.SaveItem(toAffect);
            }


            UpdateRtb();
        }
        public static double GetBaseReflex(Character c)// + 0.2 * defensiveCalculator for actual Reflex
        {
            double dxMod2 = (Convert.ToDouble(c.Statistics.Dexterity + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Dexterity)) - 10) / 2;
            //BASE REFLEX
            //reflex = (dex/2)-3 + reflexskill OR dexmod + 2 (they're the same. the algebra here is correct I promise) plus a little extra based on your general fighting skill
            double d_defenderReflex = dxMod2 + 2 + c.Skills.ReflexSkill + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Reflex);

            //reduce reflex if overburdened
            if (GetWeightFactor(c) < 0)
            {
                //+ because weight factor is a negative number
                d_defenderReflex += GetWeightFactor(c);
            }
            return(d_defenderReflex);
        }
        public void clearDedPeople()
        {
            if (leftSide.Count == 0 || rightSide.Count == 0)
            {
                return;
            }
            if (leftSide.Keys.Last().HitPoints + EffectHolder.GetValidEffectsByEffect(leftSide.Keys.Last(), EffectHolder.EffectType.Health) <= 0)
            {
                leftSide.Remove(leftSide.Keys.Last());
            }

            if (rightSide.Keys.Last().HitPoints + EffectHolder.GetValidEffectsByEffect(rightSide.Keys.Last(), EffectHolder.EffectType.Health) <= 0)
            {
                rightSide.Remove(rightSide.Keys.Last());
            }
        }
        //next round
        private void button3_Click(object sender, EventArgs e)
        {
            CombatHolder._alreadyAttackedThisRound.Clear();

            int rounds = 1;

            Int32.TryParse(textBoxRoundsToJump.Text, out rounds);
            if (rounds < 1)
            {
                rounds = 1;
            }
            textBoxRoundsToJump.Text = "";
            for (int i = 0; i < rounds; i++)
            {
                EffectHolder.ProcAndDecayEffects();
                foreach (Character c in CombatHolder._inCombatChars)
                {
                    EnchantmentUtilities.triggerAllEnchantmentsForChar(c, new EnchantmentParameters()
                    {
                        triggerSource = EnchantmentUtilities.SourceTypes.Round
                    });
                    foreach (SpellToCast stc in c.CombatStuff.SpellsToCast)
                    {
                        if (stc != null)
                        {
                            stc.hasBeenCast = false;
                            if (!stc.castAtBeginningOfNextRound)
                            {
                                stc.spellPower = -1;
                            }
                        }
                    }
                }
                if (rounds < 10)
                {
                    SpellResults frmCreator = new SpellResults(false);
                }
                CombatScripts.slowlyRegenerateCharacters();
                CombatScripts.removeOverhealFromCharacters();
            }



            UpdateRTB();
            CombatHolder.updateCombatDeclarations();
        }
        public static double CalculateReflex(Character c, Double defensiveCalculator)
        {
            double d_defenderReflex = GetBaseReflex(c) + 0.2 * defensiveCalculator;
            //divide reflex if stunned (negative focus)
            double focus = EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Focus);

            if (focus < 0)
            {
                d_defenderReflex = d_defenderReflex / (1 - focus);
            }
            d_defenderReflex = d_defenderReflex * GetStaminaFactor(c);
            //no reflex if KO
            if (!(EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.KO) < 1))
            {
                d_defenderReflex = 0.0;
            }
            return(d_defenderReflex);
        }
Esempio n. 11
0
        public void ChangeStatLabels()
        {
            //Now, fill out some labels about the attacker's stats

            Character statCharacter = Utilities.getCharacterFromXmlOrCombatHolderByString(cboBoxChar1.Text);

            lblHealth.Text  = "Health: " + Convert.ToString(CombatScripts.GetBaseHealth(statCharacter));
            lblStamina.Text = "Stamina: " + Convert.ToString(CombatScripts.GetBaseStamina(statCharacter));

            statCharacter.CombatStuff.CombatWeapon = statCharacter.Weapons.Find(A => A.ItemName == cboBoxWeapon1.Text) ?? new Weapon();
            statCharacter.CombatStuff.CombatShield = statCharacter.Shields.Find(A => A.ItemName == cboBoxShield1.Text) ?? new Shield();


            double attackerWeightFactor = CombatScripts.GetWeightFactor(statCharacter);

            lblWeightFactor.Text = "WeightFactor: " + Convert.ToString(CombatScripts.GetWeightFactor(statCharacter));

            double dxMod1 = (Convert.ToDouble(statCharacter.Statistics.Dexterity + EffectHolder.GetValidEffectsByEffect(statCharacter, EffectHolder.EffectType.Dexterity)) - 10) / 2;

            double attackerReflex = CombatScripts.GetBaseReflex(statCharacter);

            lblReflex.Text = "Reflex: " + attackerReflex.ToString();
        }
        private void FOLLOWTHETACO_Click(object sender, EventArgs e)
        {
            List <AttackOutcome> followedTacos = new List <AttackOutcome>();

            foreach (AttackOutcome tacoToFollow in allAttacks)
            {
                AttackOutcome followedTaco = CombatScripts.RunCombat(tacoToFollow.Attacker, tacoToFollow.Defender, tacoToFollow.attackRoll, tacoToFollow.defendRoll, null);


                followedTaco.Attacker.CombatStuff.AttackNotes = followedTaco.Notes;
                followedTaco.Defender.CombatStuff.DefendNotes = followedTaco.Notes;

                followedTacos.Add(followedTaco);
            }

            CombatScripts.fatigueCharactersAndRecordCombat(followedTacos);

            foreach (AttackOutcome Whack in followedTacos)
            {
                CombatScripts.applyAttackOutcome(Whack);
            }

            EffectHolder.ClearUselessEffects();
            CombatHolder.MoveAttackingCharsToHasAttackedChars();
            if (CombatHolder._masterOfDeclarations != null)
            {
                CombatHolder._masterOfDeclarations.UpdateRTB();
            }
            CombatHolder.updateCombatDeclarations();
            AfterCrits frmCreator = new AfterCrits();

            frmCreator.Show();

            Master_Attacker frmCloser = this;

            frmCloser.Hide();
        }
        public static void applyAttackOutcome(AttackOutcome Whack)
        {
            Whack.Attacker.CombatStuff.attackResultsForDisplay.Insert(0, Utilities.translateAttackOutcomeToDisplayStrings(Whack, Whack.attackUUID));
            Whack.Defender.CombatStuff.defendResultsForDisplay.Insert(0, Utilities.translateAttackOutcomeToDisplayStrings(Whack, Whack.defenceUUID));
            Character Whackee = CombatHolder._inCombatChars.Find(Ch => Ch.CombatStuff.CombatName == Whack.Defender.CombatStuff.CombatName);

            //this can happen in some enchantment cases
            if (Whackee == null)
            {
                return;
            }

            Whackee.HitPoints = Whackee.HitPoints - Whack.harm;
            Effect bleed = new Effect(EffectHolder.EffectType.Regeneration, Whack.bleed * -1, Whack.bleed, -1);

            bleed.effectTag = EffectHolder.EffectTag.Bleed;
            Effect trauma = new Effect(EffectHolder.EffectType.Focus, Whack.trauma * -1, Whack.trauma, -1);

            trauma.effectTag = EffectHolder.EffectTag.Trauma;
            bool   doPermanantImpairment = Whackee.CharTypeTag != "" && Whackee.CharTypeTag != null;
            Effect impairment            = new Effect(EffectHolder.EffectType.OB, Whack.impairment * -1, -1, 0);

            impairment.effectTypes.Add(EffectHolder.EffectType.DB);
            impairment.effectTag = EffectHolder.EffectTag.NerveImpairment;
            Effect disorientation = new Effect(EffectHolder.EffectType.OB, Whack.disorientation * -1, Whack.disorientation, 1);

            disorientation.effectTypes.Add(EffectHolder.EffectType.DB);
            disorientation.effectTag = EffectHolder.EffectTag.Disorientation;
            Effect KO = new Effect(EffectHolder.EffectType.KO, Whack.ko, Whack.ko, 0.02);

            EffectHolder.CreateEffect(disorientation, Whackee, false);
            EffectHolder.CreateEffect(bleed, Whackee, false);
            EffectHolder.CreateEffect(trauma, Whackee, false);
            EffectHolder.CreateEffect(impairment, Whackee, false);
            EffectHolder.CreateEffect(KO, Whackee, false);
        }
        private void resolveSpells(bool updateboxes)
        {
            foreach (SpellToCast stc in spells)
            {
                foreach (Effect eff in stc.effectResult.Keys)
                {
                    EffectHolder.CreateEffect(eff, stc.effectResult[eff], false);
                }
                foreach (AttackOutcome ao in stc.weaponResult)
                {
                    CombatScripts.applyAttackOutcome(ao);
                }
                stc.caster.Stamina -= stc.spell.SpellCost;
                attemptToAddResult(stc.caster, stc);
                foreach (Character c in stc.targets)
                {
                    attemptToAddResult(c, stc);
                }
                stc.targets.Clear();
                stc.spellPower = 0;
            }
            EffectHolder.ClearUselessEffects();

            if (updateboxes)
            {
                if (CombatHolder._masterOfDeclarations != null)
                {
                    CombatHolder._masterOfDeclarations.UpdateRTB();
                }
                CombatHolder.updateCombatDeclarations();
            }

            SpellResults frmCloser = this;

            frmCloser.Hide();
        }
Esempio n. 15
0
        private string Inventory(Character selectedByUser, Dictionary <String, String> args)
        {
            selectedByUser.Inventory = Utilities.GetCharByName(selectedByUser.Name).Inventory;
            Item toDropOnGround = new Item();
            Item toConsume      = new Item();
            int  count          = 1;

            if (args.ContainsKey("itemamount"))
            {
                Int32.TryParse(args["itemamount"], out count);
            }
            count = Math.Max(count, 1);
            foreach (Item i in selectedByUser.Inventory)
            {
                if (!args.ContainsKey(i.ItemName))
                {
                    continue;
                }
                if (args[i.ItemName] == "drop")
                {
                    toDropOnGround = i;
                }
                if (args[i.ItemName] == "unequip")
                {
                    i.IsEquipped = false;
                    Utilities.SaveCharacter(selectedByUser);
                    break;
                }
                if (args[i.ItemName] == "equip")
                {
                    i.IsEquipped = true;
                    Utilities.SaveCharacter(selectedByUser);
                    break;
                }
                if (args[i.ItemName] == "consume")
                {
                    toConsume = i;
                }
                if (args[i.ItemName] == "inspect")
                {
                    return(HTMLWriter.ItemDisplay(i));
                }
            }
            if (toDropOnGround.ItemName != "")
            {
                toDropOnGround            = Item.Deserialize(toDropOnGround.Serialize(), toDropOnGround.GetType());
                toDropOnGround.Count      = Math.Min(count, toDropOnGround.Count);
                toDropOnGround.IsEquipped = false;
                Utilities.RemoveItemFromInventory(toDropOnGround, selectedByUser.Inventory);
                Utilities.AddItemToInventory(toDropOnGround, CombatHolder._theGround);
                Utilities.SaveCharacter(selectedByUser);
            }
            if (toConsume.ItemName != "")
            {
                toConsume            = Item.Deserialize(toConsume.Serialize(), toConsume.GetType());
                toConsume.Count      = 1;
                toConsume.IsEquipped = false;
                Utilities.RemoveItemFromInventory(toConsume, selectedByUser.Inventory);
                foreach (Effect ef in toConsume.ItemEffects)
                {
                    EffectHolder.CreateEffect(ef, selectedByUser, false);
                }
                Utilities.SaveCharacter(selectedByUser);
            }
            Item toMoveFromGround = new Item();

            foreach (Item i in CombatHolder._theGround)
            {
                if (!args.ContainsKey(i.ItemName))
                {
                    continue;
                }
                if (args[i.ItemName] == "pick up")
                {
                    toMoveFromGround = i;
                    break;
                }
                if (args[i.ItemName] == "inspect")
                {
                    return(HTMLWriter.ItemDisplay(i));
                }
            }
            if (toMoveFromGround.ItemName != "")
            {
                toMoveFromGround       = Item.Deserialize(toMoveFromGround.Serialize(), toMoveFromGround.GetType());
                toMoveFromGround.Count = Math.Min(count, toMoveFromGround.Count);
                Utilities.AddItemToInventory(toMoveFromGround, selectedByUser.Inventory);
                Utilities.RemoveItemFromInventory(toMoveFromGround, CombatHolder._theGround);
                Utilities.SaveCharacter(selectedByUser);
            }

            return(HTMLWriter.InventoryTerminal(selectedByUser));
        }
        private void runSingleAttack()
        {
            clearDedPeople();
            if (leftSide.Count == 0 || rightSide.Count == 0)
            {
                return;
            }
            Character attackingChar = new Character();
            Character toAttackChar  = new Character();
            bool      thereIsACharThatHasNotAttacked = false;
            bool      thereIsAnAttackingChar         = false;

            ifThisThenLeftAttacksNext = !ifThisThenLeftAttacksNext;
            foreach (Character c in leftSide.Keys)
            {
                if (!leftSide[c])
                {
                    thereIsACharThatHasNotAttacked = true;
                    break;
                }
            }
            foreach (Character c in rightSide.Keys)
            {
                if (!rightSide[c])
                {
                    thereIsACharThatHasNotAttacked = true;
                    break;
                }
            }
            if (!thereIsACharThatHasNotAttacked)
            {
                EffectHolder.ProcAndDecayEffectsForSingleChar(rightSide.Keys.Last());
                EffectHolder.ProcAndDecayEffectsForSingleChar(leftSide.Keys.Last());
                clearDedPeople();
                //c# really does make you do it this way. Iteration through a dictionary is hard for some reason
                List <Character> temp = new List <Character>();
                foreach (Character c in leftSide.Keys)
                {
                    temp.Add(c);
                }
                foreach (Character c in temp)
                {
                    leftSide[c] = false;
                }
                temp.Clear();
                foreach (Character c in rightSide.Keys)
                {
                    temp.Add(c);
                }
                foreach (Character c in temp)
                {
                    rightSide[c] = false;
                }
                if (leftSide.Count == 0 || rightSide.Count == 0)
                {
                    return;
                }
            }
            if (ifThisThenLeftAttacksNext)
            {
                foreach (Character c in leftSide.Keys)
                {
                    if (!leftSide[c])
                    {
                        attackingChar          = c;
                        thereIsAnAttackingChar = true;
                        leftSide[c]            = true;
                        break;
                    }
                }
                toAttackChar = rightSide.Keys.Last();
            }
            else
            {
                foreach (Character c in rightSide.Keys)
                {
                    if (!rightSide[c])
                    {
                        attackingChar          = c;
                        thereIsAnAttackingChar = true;
                        rightSide[c]           = true;
                        break;
                    }
                }
                toAttackChar = leftSide.Keys.Last();
            }
            if (!thereIsAnAttackingChar)
            {
                return;
            }
            AttackOutcome ao = CombatScripts.RunCombat(attackingChar, toAttackChar, Math.Round(r.NextDouble() * 20), Math.Round(r.NextDouble() * 20), null);


            if (ao.Othertext.ToString() == "Hit")
            {
                toAttackChar.HitPoints = toAttackChar.HitPoints - ao.harm;
                Effect bleed        = new Effect(EffectHolder.EffectType.Regeneration, ao.bleed * -1, -1, 0);
                Effect focus        = new Effect(EffectHolder.EffectType.Focus, ao.trauma * -1, -1, 0);
                Effect impairmentOB = new Effect(EffectHolder.EffectType.OB, ao.impairment * -1, -1, 0);
                Effect impairmentDB = new Effect(EffectHolder.EffectType.DB, ao.impairment * -1, -1, 0);
                Effect OB           = new Effect(EffectHolder.EffectType.OB, ao.disorientation * -1, ao.disorientation, 1);
                Effect DB           = new Effect(EffectHolder.EffectType.DB, ao.disorientation * -1, ao.disorientation, 1);
                EffectHolder.CreateEffect(OB, toAttackChar, false);
                EffectHolder.CreateEffect(DB, toAttackChar, false);
                EffectHolder.CreateEffect(bleed, toAttackChar, false);
                EffectHolder.CreateEffect(focus, toAttackChar, false);
                EffectHolder.CreateEffect(impairmentOB, toAttackChar, false);
                EffectHolder.CreateEffect(impairmentDB, toAttackChar, false);
                EffectHolder.ClearUselessEffects();
            }

            if (doPrinting)
            {
                richTextBoxBig.Text += attackingChar.CombatStuff.CombatName + " -> " + toAttackChar.CombatStuff.CombatName + " " + " " + ao.Othertext.ToString() + "\n";
            }

            clearDedPeople();
        }
 private void UpdateRTBs()
 {
     richTextBoxLeft.Text  = "";
     richTextBoxRight.Text = "";
     foreach (Character c in leftSide.Keys)
     {
         richTextBoxLeft.Text += c.CombatStuff.CombatName + " " + (c.HitPoints + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Health)) + "\n";
     }
     foreach (Character c in rightSide.Keys)
     {
         richTextBoxRight.Text += c.CombatStuff.CombatName + " " + (c.HitPoints + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Health)) + "\n";
     }
 }
        public static void CalculateCrit(AttackOutcome CritSource)
        {
            double harm;
            double bleed;
            double heavybleed;
            double disorientation;
            double impairment;
            double trauma;
            double ko;

            double harmCumulative           = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictHarm);
            double bleedCumulative          = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictBleed);
            double heavybleedCumulative     = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictBleed);
            double disorientationCumulative = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictDisorientation);
            double impairmentCumulative     = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictImpairment);
            double traumaCumulative         = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictTrauma);
            double koCumulative             = CritSource.TotalStrikeAmountFromAllTypes() * EffectHolder.GetValidEffectsByEffect(CritSource.Attacker, EffectHolder.EffectType.InflictKO);
            bool   locationMatters;

            foreach (Utilities.DamageType critType in CritSource.DamageTypes.Keys)
            {
                switch (critType)
                {
                case Utilities.DamageType.Slash:
                    harm            = 0.3;
                    bleed           = 0.6;
                    heavybleed      = 0.3;
                    disorientation  = 0.3;
                    impairment      = 0.3;
                    trauma          = 0.2;
                    ko              = 0.2;
                    locationMatters = true;
                    break;

                case Utilities.DamageType.Pierce:
                    harm            = 0.3;
                    bleed           = 0.3;
                    heavybleed      = 0.6;
                    disorientation  = 0.1;
                    impairment      = 0.2;
                    trauma          = 0.2;
                    ko              = 0.1;
                    locationMatters = true;
                    break;

                case Utilities.DamageType.Crush:
                    harm            = 0.2;
                    bleed           = 0.0;
                    heavybleed      = 0.1;
                    disorientation  = 0.4;
                    impairment      = 0.4;
                    trauma          = 0.4;
                    ko              = 0.4;
                    locationMatters = true;
                    break;

                case Utilities.DamageType.Heat:
                    harm            = 0.7;
                    bleed           = -0.1;
                    heavybleed      = 0.0;
                    disorientation  = 0.5;
                    impairment      = 0.3;
                    trauma          = 0.3;
                    ko              = 0.0;
                    locationMatters = true;
                    break;

                case Utilities.DamageType.Cold:
                    harm            = 0.2;
                    bleed           = -0.3;
                    heavybleed      = -0.3;
                    disorientation  = 0.5;
                    impairment      = 0.8;
                    trauma          = 0.3;
                    ko              = 0.3;
                    locationMatters = true;
                    break;

                case Utilities.DamageType.Shock:
                    harm            = 0.6;
                    bleed           = 0.0;
                    heavybleed      = 0.0;
                    disorientation  = 0.4;
                    impairment      = 0.5;
                    trauma          = 0.6;
                    ko              = 0.4;
                    locationMatters = false;
                    break;

                case Utilities.DamageType.Mental:
                    harm            = 0;
                    bleed           = 0;
                    heavybleed      = 0.1;
                    disorientation  = 1.0;
                    impairment      = 0.0;
                    trauma          = 1.0;
                    ko              = 0.3;
                    locationMatters = false;
                    break;

                case Utilities.DamageType.Impact:
                    harm            = 0.8;
                    bleed           = 0;
                    heavybleed      = 0.1;
                    disorientation  = 0.5;
                    impairment      = 0.3;
                    trauma          = 0.6;
                    ko              = 0.6;
                    locationMatters = false;
                    break;

                case Utilities.DamageType.Soul:
                    harm            = 1.0;
                    bleed           = 0;
                    heavybleed      = 0.0;
                    disorientation  = 0.0;
                    impairment      = 0.7;
                    trauma          = 0.2;
                    ko              = 0.4;
                    locationMatters = false;
                    break;

                default:
                    throw new Exception("No valid Critical Type found.");
                }
                if (locationMatters)
                {
                    switch (CritSource.HitLocation)
                    {
                    case Utilities.BodyParts.Head:
                        harm           += 0.2;
                        bleed          += 0.0;
                        heavybleed     += 0.0;
                        disorientation += 0.2;
                        impairment     += 0.1;
                        trauma         += 0.2;
                        ko             += 0.2;
                        break;

                    case Utilities.BodyParts.Gut:
                        harm           += 0.4;
                        bleed          += 0.1;
                        heavybleed     += 0.2;
                        disorientation += 0.0;
                        impairment     += 0.0;
                        trauma         += 0.1;
                        ko             += 0.1;
                        break;

                    case Utilities.BodyParts.Groin:
                        harm           += 0.0;
                        bleed          += 0.0;
                        heavybleed     += 0.0;
                        disorientation += 0.5;
                        impairment     += 0.1;
                        trauma         += 0.5;
                        ko             += 0.0;
                        break;

                    case Utilities.BodyParts.Chest:
                        harm           += 0.3;
                        bleed          += 0.1;
                        heavybleed     += 0.2;
                        disorientation += 0.0;
                        impairment     += 0.0;
                        trauma         += 0.0;
                        ko             += 0.2;
                        break;

                    case Utilities.BodyParts.Neck:
                        harm           += 0.2;
                        bleed          += 0.2;
                        heavybleed     += 0.4;
                        disorientation += 0.0;
                        impairment     += 0.0;
                        trauma         += 0.0;
                        ko             += 0.3;
                        break;

                    default:
                        harm           += 0.0;
                        bleed          += 0.1;
                        heavybleed     += 0.1;
                        disorientation += 0.0;
                        impairment     += 0.2;
                        trauma         += 0.0;
                        ko             += 0.0;
                        break;
                    }
                }
                harmCumulative           += harm * CritSource.DamageTypes[critType];
                bleedCumulative          += bleed * CritSource.DamageTypes[critType];
                heavybleedCumulative     += heavybleed * CritSource.DamageTypes[critType];
                disorientationCumulative += disorientation * CritSource.DamageTypes[critType];
                impairmentCumulative     += impairment * CritSource.DamageTypes[critType];
                traumaCumulative         += trauma * CritSource.DamageTypes[critType];
                koCumulative             += ko * CritSource.DamageTypes[critType];
            }
            //ADD THIS FOR SOME  RANDOMNESS

            /*
             * harmCumulative = harmCumulative * (_generator.NextDouble() + 0.5);
             * bleedCumulative = bleedCumulative * (_generator.NextDouble() + 0.5);
             * heavybleedCumulative = heavybleedCumulative * (_generator.NextDouble() + 0.5);
             * disorientationCumulative = disorientationCumulative * (_generator.NextDouble() + 0.5);
             * impairmentCumulative = impairmentCumulative * (_generator.NextDouble() + 0.5);
             * traumaCumulative = traumaCumulative * (_generator.NextDouble() + 0.5);
             * koCumulative = koCumulative * (_generator.NextDouble() + 0.5);*/

            //adjust the values. changing these lines vastly changes the harm dealt by all attacks, futz with caution

            //harm is easy to come by, as it has the smallest impact on its own and needs to accumulate to perform its function
            harmCumulative = harmCumulative * 2;
            //bleed is easy to get in smallish doses, and scales at a moderate rate
            bleedCumulative = bleedCumulative / 2;
            //....until a certain point, when you start hitting arteries and stuff, and it scales rapidly
            heavybleedCumulative = heavybleedCumulative - 7;
            //the plus on the right is necessary, because 1 point of disorientation matters very little, since it dissapates at the end of the round
            disorientationCumulative = (disorientationCumulative / 2) + 0.4;
            //impairment has to scale slowly and be difficult to achieve, since it will accumulate over combat and seriously hamstrings a fighter
            impairmentCumulative = (impairmentCumulative / 4) - 0.5;
            //like disorientation, 1 point of trauma matters very little, unless you held off on your attack for the round
            traumaCumulative = (traumaCumulative / 4);
            //even one point of ko is usually fatal, since you are likely to be bleeding, so this needs to be difficult to achieve
            koCumulative = (koCumulative / 2) - 7.5;

            Character Whackee              = CritSource.Defender;
            double    resistHarm           = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistHarm);
            double    resistBleed          = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistBleed);
            double    resistDisorientation = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistDisorientation);
            double    resistImpairment     = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistImpairment);
            double    resistTrauma         = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistTrauma);
            double    resistKo             = EffectHolder.GetValidEffectsByEffect(Whackee, EffectHolder.EffectType.ResistKO);

            harmCumulative = (harmCumulative - resistHarm) * 5 / (5 + resistHarm);
            // NOTE bleed and heavybleed both accounted for here
            bleedCumulative          = (Math.Max(0, bleedCumulative) + Math.Max(0, heavybleedCumulative) - resistBleed) * 5 / (5 + resistBleed);
            disorientationCumulative = (disorientationCumulative - resistDisorientation) * 5 / (5 + resistDisorientation);
            impairmentCumulative     = (impairmentCumulative - resistImpairment) * 5 / (5 + resistImpairment);
            traumaCumulative         = (traumaCumulative - resistTrauma) * 5 / (5 + resistTrauma);
            koCumulative             = (koCumulative - resistKo) * 5 / (5 + resistKo);

            //round the values properly and send them back, no negative values accepted
            CritSource.harm           = (int)Math.Round(Math.Max(0, harmCumulative));
            CritSource.bleed          = (int)Math.Round(Math.Max(0, bleedCumulative));
            CritSource.disorientation = (int)Math.Round(Math.Max(0, disorientationCumulative));
            CritSource.impairment     = (int)Math.Round(Math.Max(0, impairmentCumulative));
            CritSource.trauma         = (int)Math.Round(Math.Max(0, traumaCumulative));
            CritSource.ko             = (int)Math.Round(Math.Max(0, koCumulative));
        }
Esempio n. 19
0
        public static string CombatTerminal(Character c)
        {
            var doc = new HtmlDocument();

            doc.Load("HTMLPages\\CombatTerminal.html");

            doc.GetElementbyId("menuform").Attributes["action"].Value      = BaseURL();
            doc.GetElementbyId("inventoryform").Attributes["action"].Value = BaseURL() + "/Combat/" + c.CombatStuff.CombatName + "/Inventory";
            doc.GetElementbyId("combatform").Attributes["action"].Value    = CombatTerminalPage(c);
            doc.GetElementbyId("CharacterName").InnerHtml              = c.Name;
            doc.GetElementbyId("str").InnerHtml                        = c.Statistics.Strength.ToString();
            doc.GetElementbyId("dex").InnerHtml                        = c.Statistics.Dexterity.ToString();
            doc.GetElementbyId("con").InnerHtml                        = c.Statistics.Constitution.ToString();
            doc.GetElementbyId("int").InnerHtml                        = c.Statistics.Intelligence.ToString();
            doc.GetElementbyId("wis").InnerHtml                        = c.Statistics.Wisdom.ToString();
            doc.GetElementbyId("cha").InnerHtml                        = c.Statistics.Charisma.ToString();
            doc.GetElementbyId("hp").InnerHtml                         = ((int)(c.HitPoints + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Health))).ToString();
            doc.GetElementbyId("stamina").InnerHtml                    = ((int)c.Stamina).ToString();
            doc.GetElementbyId("regen").InnerHtml                      = EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Regeneration).ToString();
            doc.GetElementbyId("exhaustion").InnerHtml                 = (Math.Round(1.0 / CombatScripts.GetStaminaFactor(c), 2)).ToString();
            doc.GetElementbyId("obmod").InnerHtml                      = (EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.OB)).ToString();
            doc.GetElementbyId("dbmod").InnerHtml                      = (EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.DB)).ToString();
            doc.GetElementbyId("focus").InnerHtml                      = (EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Focus)).ToString();
            doc.GetElementbyId("weightfactor").InnerHtml               = (Math.Round(CombatScripts.GetWeightFactor(c), 2)).ToString();
            doc.GetElementbyId("reflex").InnerHtml                     = (Math.Round(CombatScripts.CalculateReflex(c, 0), 2)).ToString();
            doc.GetElementbyId("offbonus").Attributes["value"].Value   = c.CombatStuff.CombatOB.ToString();
            doc.GetElementbyId("defbonus").Attributes["value"].Value   = c.CombatStuff.CombatDB.ToString();
            doc.GetElementbyId("roll").Attributes["value"].Value       = c.CombatStuff.CombatRoll.ToString();
            doc.GetElementbyId("spellpower").Attributes["value"].Value = c.CombatStuff.SpellsToCast[0].spellPower.ToString();
            foreach (Character target in CombatHolder._inCombatChars)
            {
                if (target.CombatStuff.CombatName == c.LastAttackTargetSelected)
                {
                    doc.GetElementbyId("targets").InnerHtml += "\r\n<option selected>" + target.CombatStuff.CombatName;
                }
                else
                {
                    doc.GetElementbyId("targets").InnerHtml += "\r\n<option>" + target.CombatStuff.CombatName;
                }

                if (target.CombatStuff.CombatName == c.LastSpellTargetSelected)
                {
                    doc.GetElementbyId("spelltargets").InnerHtml += "\r\n<option selected>" + target.CombatStuff.CombatName;
                }
                else
                {
                    doc.GetElementbyId("spelltargets").InnerHtml += "\r\n<option>" + target.CombatStuff.CombatName;
                }
            }
            foreach (Weapon weap in c.Weapons)
            {
                if (weap == c.CombatStuff.CombatWeapon)
                {
                    doc.GetElementbyId("weapons").InnerHtml += "\r\n<option selected>" + weap.ItemName;
                }
                else
                {
                    doc.GetElementbyId("weapons").InnerHtml += "\r\n<option>" + weap.ItemName;
                }
            }

            foreach (Shield sh in c.Shields)
            {
                if (sh == c.CombatStuff.CombatShield)
                {
                    doc.GetElementbyId("shields").InnerHtml += "\r\n<option selected>" + sh.ItemName;
                }
                else
                {
                    doc.GetElementbyId("shields").InnerHtml += "\r\n<option>" + sh.ItemName;
                }
            }

            foreach (Spell sp in c.Spells)
            {
                if (sp == c.CombatStuff.SpellsToCast[0].spell)
                {
                    doc.GetElementbyId("spells").InnerHtml += "\r\n<option selected>" + sp.SpellName;
                }
                else
                {
                    doc.GetElementbyId("spells").InnerHtml += "\r\n<option>" + sp.SpellName;
                }
            }

            if (c.CombatStuff.SpellsToCast[0].targets.Any())
            {
                doc.GetElementbyId("attacks").InnerHtml += "\r\n<p>Casting " + c.CombatStuff.SpellsToCast[0].spell.SpellName + " at:";
                foreach (Character target in c.CombatStuff.SpellsToCast[0].targets)
                {
                    doc.GetElementbyId("attacks").InnerHtml += target.CombatStuff.CombatName + "<br>";
                }
                doc.GetElementbyId("attacks").InnerHtml += " </ p > ";
            }
            foreach (Character attacking in CombatHolder._makingAttackChars)
            {
                doc.GetElementbyId("attacks").InnerHtml += "\r\n<p>" + attacking.CombatStuff.CombatName + " is attacking:";
                foreach (Character beingattacked in attacking.CombatStuff.targets)
                {
                    doc.GetElementbyId("attacks").InnerHtml += beingattacked.CombatStuff.CombatName + "<br>";
                }
                doc.GetElementbyId("attacks").InnerHtml += "with " + attacking.CombatStuff.CombatWeapon.ItemName + " </ p > ";
            }
            doc.GetElementbyId("attackresults").InnerHtml += " </ p > ";
            foreach (List <String> attack in c.CombatStuff.attackResultsForDisplay)
            {
                doc.GetElementbyId("attackresults").InnerHtml += "\r\n<p>ATTACK<br>";
                foreach (string str in attack)
                {
                    if (str.Length > 7 && str.Substring(0, 7) == "http://")
                    {
                        doc.GetElementbyId("attackresults").InnerHtml += "<a href=\"" + str + "\">Display Attack</a>";
                    }
                    else
                    {
                        doc.GetElementbyId("attackresults").InnerHtml += str + "<br>";
                    }
                }
                doc.GetElementbyId("attackresults").InnerHtml += " </ p > ";
            }
            foreach (List <String> defence in c.CombatStuff.defendResultsForDisplay)
            {
                doc.GetElementbyId("attackresults").InnerHtml += "\r\n<p>DEFENCE<br>";
                foreach (string str in defence)
                {
                    if (str.Length > 7 && str.Substring(0, 7) == "http://")
                    {
                        doc.GetElementbyId("attackresults").InnerHtml += "<a href=\"" + str + "\">Display Defense</a>";
                    }
                    else
                    {
                        doc.GetElementbyId("attackresults").InnerHtml += str + "<br>";
                    }
                }
                doc.GetElementbyId("attackresults").InnerHtml += " </ p > ";
            }
            foreach (SpellToCast castSpell in c.CombatStuff.spellResultsForDisplay)
            {
                doc.GetElementbyId("attackresults").InnerHtml += "\r\n<p>SPELL<br>";
                foreach (Effect eff in castSpell.effectResult.Keys)
                {
                    doc.GetElementbyId("attackresults").InnerHtml += eff.getDisplayString() + "<br>";
                }
                doc.GetElementbyId("attackresults").InnerHtml += " </ p > ";
            }
            String lastAttackExp = "\r\n<p style =\"white-space: pre-line;\">\nLast Attack Explanation\n";

            lastAttackExp += c.CombatStuff.AttackNotes.DisplayResults() + "<br></p>";
            doc.GetElementbyId("attackresults").InnerHtml += lastAttackExp;

            String lastDefenceExp = "\r\n<p style =\"white-space: pre-line;\">\nLast Defence Explanation\n";

            lastDefenceExp += c.CombatStuff.DefendNotes.DisplayResults() + "<br></p>";
            doc.GetElementbyId("attackresults").InnerHtml += lastDefenceExp;

            //nodename.Attributes["value"].Value = c.Name;
            // < option > thief
            var bleh = doc.DocumentNode.OuterHtml;

            return(bleh);

            /*
             * ret += wItemName + "<br>\n";
             * ret += w.Description + "<br>\n";
             * foreach (Utilities.DamageType dt in w.DamageTypes.Keys)
             * {
             *  ret += dt.ToString() + " " + w.DamageTypes[dt] + "<br>\n";
             * }
             * ret += EndBit();*/
        }
Esempio n. 20
0
        public void RefreshThisCharacter()
        {
            this.Text            = ThisChar.CombatStuff.CombatName;
            lblOB.Text           = "+( " + Convert.ToString(EffectHolder.GetValidEffectsByEffect(ThisChar, EffectHolder.EffectType.OB)) + " )";
            lblDB.Text           = "+( " + Convert.ToString(EffectHolder.GetValidEffectsByEffect(ThisChar, EffectHolder.EffectType.DB)) + " )";
            lblFB.Text           = "+( " + Convert.ToString(Convert.ToDouble(EffectHolder.GetValidEffectsByEffect(ThisChar, EffectHolder.EffectType.Dexterity)) / 2) + " )";
            txtBoxHP.Text        = Convert.ToString(ThisChar.HitPoints + EffectHolder.GetValidEffectsByEffect(ThisChar, EffectHolder.EffectType.Health));
            txtBoxStamina.Text   = Convert.ToString(ThisChar.Stamina);
            richTextBox1.Text    = Utilities.translateCharacterStatusToDisplayString(ThisChar) + "\n\n";
            rtbLastDefenses.Text = "";
            foreach (Effect ef in ThisChar.TemporaryEffects)
            {
                richTextBox1.Text += ef.getDisplayString();
            }
            if (ThisChar.CombatStuff.defendResultsForDisplay != null &&
                ThisChar.CombatStuff.defendResultsForDisplay.Any())
            {
                foreach (List <String> lststr in ThisChar.CombatStuff.defendResultsForDisplay)
                {
                    rtbLastDefenses.Text += lststr[1] + "\n";
                    rtbLastDefenses.Text += lststr[2] + "\n";
                    if (lststr.Count > 10)
                    {
                        rtbLastDefenses.Text += lststr[10] + "\n";
                    }
                    rtbLastDefenses.Text += "\n";
                }
            }
            rtbInbound.Text  = "This Character's Message: \n";
            rtbInbound.Text += ThisChar.GoogleNinjaNotesInbound;
            rtbInbound.Text += "\n\nOther Messages To This Character:\n" + ThisChar.GoogleNinjaNotesRebound;
            rtbOutbound.Text = ThisChar.GoogleNinjaNotesOutbound;

            List <Weapon> WeaponList = ThisChar.Weapons;
            List <Shield> ShieldList = ThisChar.Shields;

            cboBoxWeapon.SelectedIndex = -1;
            cboBoxShield.SelectedIndex = -1;
            cboBoxWeapon.Items.Clear();
            cboBoxShield.Items.Clear();
            foreach (Weapon NowWep in WeaponList)
            {
                cboBoxWeapon.Items.Add(NowWep.ItemName);
            }
            foreach (Shield NowShield in ShieldList)
            {
                cboBoxShield.Items.Add(NowShield.ItemName);
            }
            if (cboBoxWeapon.Items.Count != 0)
            {
                cboBoxWeapon.SelectedIndex = 0;
            }
            if (cboBoxShield.Items.Count != 0)
            {
                cboBoxShield.SelectedIndex = 0;
            }
            if (!(ThisChar.CombatStuff.CombatWeapon == null))
            {
                cboBoxShield.Text = ThisChar.CombatStuff.CombatShield.ItemName;
                cboBoxWeapon.Text = ThisChar.CombatStuff.CombatWeapon.ItemName;
                txtBoxDB.Text     = Convert.ToString(ThisChar.CombatStuff.CombatDB);
                txtBoxOB.Text     = Convert.ToString(ThisChar.CombatStuff.CombatOB);
            }


            SetColorCorrectly();
        }
        public static AttackOutcome RunCombat(Character _attacker, Character _defender, double AttackRoll, double DefendRoll, Utilities.BodyParts?location)
        {
            AttackOutcome outcome = new AttackOutcome();

            _attacker.CombatStuff.aoForEnchantments = outcome;
            _defender.CombatStuff.aoForEnchantments = outcome;
            outcome.attackRoll = AttackRoll;
            outcome.defendRoll = DefendRoll;
            //this is to give the option of one-roll combat on the specific input of DefensiveRoll == -999.0

            /*
             * if (DefendRoll == -999.0)
             * {
             *  DefendRoll = 20 - AttackRoll;
             * }*/

            outcome.Attacker = _attacker;
            outcome.Defender = _defender;

            Weapon _attackerSelectedWeapon = _attacker.CombatStuff.CombatWeapon;
            Weapon _defenderSelectedWeapon = _defender.CombatStuff.CombatWeapon;
            Shield _attackerSelectedShield = _attacker.CombatStuff.CombatShield;
            Shield _defenderSelectedShield = _defender.CombatStuff.CombatShield;

            outcome.Notes.attackerWeaponName = _attackerSelectedWeapon.ItemName;
            outcome.Notes.defenderWeaponName = _defenderSelectedWeapon.ItemName;
            outcome.Notes.stun = -1 * EffectHolder.GetValidEffectsByEffect(_defender, EffectHolder.EffectType.Focus);

            double _attackerWeightFactor = GetWeightFactor(_attacker);
            double _defenderWeightFactor = GetWeightFactor(_defender);

            double _attackerStaminaFactor = GetStaminaFactor(_attacker);
            double _defenderStaminaFactor = GetStaminaFactor(_defender);
            //primary calculators
            double offensiveCalculator = (AttackRoll + _attacker.CombatStuff.CombatOB + _attackerSelectedWeapon.OffensiveBonus + _attackerSelectedShield.OffensiveBonus + EffectHolder.GetValidEffectsByEffect(_attacker, EffectHolder.EffectType.OB) + _attackerWeightFactor) * _attackerStaminaFactor;
            double defensiveCalculator = (DefendRoll + _defender.CombatStuff.CombatDB + _defenderSelectedWeapon.DefensiveBonus + _defenderSelectedShield.DefensiveBonus + EffectHolder.GetValidEffectsByEffect(_defender, EffectHolder.EffectType.DB) + _defenderWeightFactor) * _defenderStaminaFactor;

            foreach (Armor a in _attacker.Armor)
            {
                offensiveCalculator += a.OffensiveBonus;
            }
            foreach (Armor a in _defender.Armor)
            {
                defensiveCalculator += a.DefensiveBonus;
            }

            outcome.Notes.attackroll  = AttackRoll;
            outcome.Notes.attackValue = offensiveCalculator;
            outcome.Notes.defendRoll  = DefendRoll;
            outcome.Notes.defendValue = defensiveCalculator;

            EnchantmentUtilities.triggerAllEnchantmentsForChar(_attacker, new EnchantmentParameters()
            {
                triggerSource = EnchantmentUtilities.SourceTypes.Attack
            });
            EnchantmentUtilities.triggerAllEnchantmentsForChar(_defender, new EnchantmentParameters()
            {
                triggerSource = EnchantmentUtilities.SourceTypes.WasAttacked
            });

            //generate reflex
            double defenderReflex = CalculateReflex(_defender, defensiveCalculator);

            //adjust by a percentage if stamina is low
            defenderReflex = defenderReflex * _defenderStaminaFactor;

            outcome.Notes.reflex = defenderReflex;

            //generate blocking difficulty
            double attackerBlockingDifficulty = _attackerSelectedWeapon.BlockingDifficulty + EffectHolder.GetValidEffectsByEffect(_attacker, EffectHolder.EffectType.BlockingDifficulty) + 0.2 * offensiveCalculator;

            outcome.Notes.blockingDifficulty = attackerBlockingDifficulty;

            //apply 25% of blocking difficulty
            defensiveCalculator -= attackerBlockingDifficulty * 0.25;

            //generate block
            double defenderBlock = defensiveCalculator * (_defenderSelectedShield.Coverage + EffectHolder.GetValidEffectsByEffect(_defender, EffectHolder.EffectType.ShieldCoverage));

            outcome.Notes.block = defenderBlock;

            //apply rest of blocking difficulty
            defensiveCalculator -= attackerBlockingDifficulty * 0.75;

            //generate parry
            double defenderParry = defensiveCalculator * _defenderSelectedWeapon.ParryStrength / System.Math.Max(_attackerSelectedWeapon.ParryBreak, 0.01);

            outcome.Notes.parryBreak    = _attackerSelectedWeapon.ParryBreak;
            outcome.Notes.parryStrength = _defenderSelectedWeapon.ParryStrength;
            outcome.Notes.parry         = defenderParry;
            outcome.Notes.defendValueAfterBlockingDifficulty = defensiveCalculator;


            //perform dodge
            if (defenderReflex > 0)
            {
                offensiveCalculator -= defenderReflex;
            }

            //if the attack has been reduced to 0, it was dodged
            if (offensiveCalculator <= 0)
            {
                outcome.Othertext  = Utilities.AttackResultType.Miss;
                outcome.HitCaliber = offensiveCalculator;
                return(outcome);
            }

            outcome.Notes.attackAfterReflex = offensiveCalculator;

            //perform block
            if (defenderBlock > 0)
            {
                offensiveCalculator -= defenderBlock;
            }

            //if the attack has been reduced to 0, it was blocked
            if (offensiveCalculator <= 0)
            {
                outcome.Othertext  = Utilities.AttackResultType.Block;
                outcome.HitCaliber = offensiveCalculator;
                return(outcome);
            }

            outcome.Notes.attackAfterBlock = offensiveCalculator;

            //perform parry
            if (defenderParry > 0)
            {
                offensiveCalculator -= defenderParry;
            }

            //if the attack has been reduced to 0, it was parried
            if (offensiveCalculator <= 0)
            {
                outcome.Othertext  = Utilities.AttackResultType.Parry;
                outcome.HitCaliber = offensiveCalculator;
                return(outcome);
            }

            outcome.Notes.attackAfterParry = offensiveCalculator;
            if (location == null)
            {
                Utilities.FindCritLocation(outcome);
            }
            else
            {
                outcome.HitLocation = (Utilities.BodyParts)location;
            }

            //otherwise, attacker hit! do damage/armor calculation
            Dictionary <Utilities.DamageType, Double> tempDamageValues = new Dictionary <Utilities.DamageType, double>();

            foreach (Utilities.DamageType dt in _attackerSelectedWeapon.DamageTypes.Keys)
            {
                tempDamageValues.Add(dt, _attackerSelectedWeapon.DamageTypes[dt]);
            }
            foreach (Utilities.DamageType dt in Enum.GetValues(typeof(Utilities.DamageType)))
            {
                double addedDamage = EffectHolder.GetValidEffectsByEffectAndDamageType(_attacker, EffectHolder.EffectType.WeaponDamage, dt);
                if (addedDamage != 0)
                {
                    if (tempDamageValues.ContainsKey(dt))
                    {
                        tempDamageValues[dt] += addedDamage;
                    }
                    else
                    {
                        tempDamageValues.Add(dt, addedDamage);
                    }
                }
            }
            foreach (Utilities.DamageType dt in tempDamageValues.Keys)
            {
                Double strikeAmountForDamageType = offensiveCalculator * tempDamageValues[dt];
                outcome.HitStrength             = outcome.HitStrength + strikeAmountForDamageType;
                outcome.Notes.damageBeforeArmor = outcome.HitStrength;
                //actually percentage of damage that will go through
                double damageResistance = 1.0 - EffectHolder.GetValidEffectsByEffectAndDamageType(_defender, EffectHolder.EffectType.DamageResistance, null);
                damageResistance -= EffectHolder.GetValidEffectsByEffectAndDamageType(_defender, EffectHolder.EffectType.DamageResistance, dt);
                foreach (Armor arm in _defender.Armor)
                {
                    if (arm.CoveredAreas.Contains(outcome.HitLocation) && arm.DamageResistanceTypes.ContainsKey(dt))
                    {
                        //subtraction because a lower percentage of the damage will get through
                        damageResistance -= (arm.DamageResistanceTypes[dt]);
                    }
                }
                outcome.DamageTypes.Add(dt, Math.Max(0, (strikeAmountForDamageType * damageResistance)));
            }

            double generalDamageReduction     = EffectHolder.GetValidEffectsByEffectAndDamageType(_defender, EffectHolder.EffectType.DamageReduction, null);
            double totalDamageBeforeReduction = outcome.TotalStrikeAmountFromAllTypes();

            //weird things happen if this is less than or equal to zero
            if (totalDamageBeforeReduction > 0)
            {
                foreach (Utilities.DamageType dt in tempDamageValues.Keys)
                {
                    //the amount of damage that will be prevented
                    outcome.DamageTypes[dt] -= generalDamageReduction * (outcome.DamageTypes[dt] / totalDamageBeforeReduction);
                    outcome.DamageTypes[dt] -= EffectHolder.GetValidEffectsByEffectAndDamageType(_defender, EffectHolder.EffectType.DamageReduction, dt);
                    foreach (Armor arm in _defender.Armor)
                    {
                        if (arm.CoveredAreas.Contains(outcome.HitLocation) && arm.DamageReductionTypes.ContainsKey(dt))
                        {
                            outcome.DamageTypes[dt] -= (arm.DamageReductionTypes[dt]);
                        }
                    }
                    if (outcome.DamageTypes[dt] < 0)
                    {
                        outcome.DamageTypes[dt] = 0;
                    }
                }
            }



            outcome.Notes.damageAfterArmor = outcome.TotalStrikeAmountFromAllTypes();

            outcome.Othertext  = Utilities.AttackResultType.Hit;
            outcome.HitCaliber = offensiveCalculator;


            CritCalculator.CalculateCrit(outcome);

            EnchantmentUtilities.triggerAllEnchantmentsForChar(_attacker, new EnchantmentParameters()
            {
                triggerSource = EnchantmentUtilities.SourceTypes.PostAttack
            });
            EnchantmentUtilities.triggerAllEnchantmentsForChar(_defender, new EnchantmentParameters()
            {
                triggerSource = EnchantmentUtilities.SourceTypes.PostWasAttacked
            });

            return(outcome);
        }
 public static double GetBaseHealth(Character c)
 {
     return(Convert.ToDouble(Convert.ToDouble((c.Statistics.Constitution) + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Constitution)) * (2 + c.Skills.HPSkill * 0.25)));
 }
 public static double GetBaseStamina(Character c)
 {
     return(Convert.ToDouble((c.Statistics.Constitution + EffectHolder.GetValidEffectsByEffect(c, EffectHolder.EffectType.Constitution) + c.Skills.EnduranceSkill - 10) * 25 + 300));
 }
        private void btnCastSpell_Click(object sender, EventArgs e)
        {
            if (!Utilities.ValidateComboBox(cboBoxChars.Text) || !Utilities.ValidateComboBox(cboBoxSpells.Text))
            {
                return;
            }
            if (chkBoxSecurity.Checked)
            {
                chkBoxSecurity.Checked = false;
            }
            else
            {
                return;
            }
            richTextBox1.Text = "";
            double spellPower = 0.0;

            Double.TryParse(txtBoxSpellPower.Text, out spellPower);
            double defensePower = 0.0;

            Double.TryParse(txtBoxDefenseRoll.Text, out defensePower);

            // Character c = Utilities.GetCharByName(cboBoxChars.Text); something like this needs to work eventually
            Character target = CombatHolder._inCombatChars.Find(A => A.CombatStuff.CombatName == cboBoxChars.Text);

            Character caster = new Character();

            if (cboBoxCaster.Text.Equals("Nobody"))
            {
                caster = Utilities.GetCharByName("Nobody");
                caster.CombatStuff.CombatShield = caster.Shields.First();
                caster.Stamina = CombatScripts.GetBaseStamina(caster);
                caster.CombatStuff.CombatName = "Nobody";
            }
            else
            {
                caster = CombatHolder._inCombatChars.Find(A => A.CombatStuff.CombatName == cboBoxCaster.Text);
            }


            if (target == null)  //fail
            {
                Utilities.ValidateComboBox("");
            }
            Spell s = Utilities.GetSpellByName(cboBoxSpells.Text);


            caster.Stamina -= s.SpellCost;

            Tuple <List <AttackOutcome>, List <Effect> > results = SpellScripts.castSpell(caster, target, s, spellPower, defensePower);

            foreach (Effect effMultiplied in results.Item2)
            {
                richTextBox1.Text += effMultiplied.getDisplayString();

                EffectHolder.CreateEffect(effMultiplied, target, false);
            }

            foreach (AttackOutcome outcome in results.Item1)
            {
                richTextBox1.Text += outcome.Attacker.CombatStuff.CombatName + " against " + outcome.Defender.CombatStuff.CombatName + " with " + outcome.Attacker.CombatStuff.CombatWeapon.ItemName + "\n";
                richTextBox1.Text += "Attackroll: " + outcome.attackRoll.ToString() + "\n";
                richTextBox1.Text += "Defendroll: " + outcome.defendRoll.ToString() + "\n";
                richTextBox1.Text += "Result: " + outcome.Othertext.ToString() + "\n";
                if (outcome.Othertext == Utilities.AttackResultType.Hit)
                {
                    richTextBox1.Text += "Location: " + outcome.HitLocation + "\n";
                    richTextBox1.Text += "Hit Caliber: " + Convert.ToString(outcome.HitCaliber) + "\n";
                    richTextBox1.Text += "Hit Strength: " + Convert.ToString(outcome.HitStrength) + "\n";
                    richTextBox1.Text += "Strike Power: " + Convert.ToString(outcome.TotalStrikeAmountFromAllTypes()) + "\n\n";
                    richTextBox1.Text += "Harm: " + Convert.ToString(outcome.harm) + "\n" + "Bleed: " + Convert.ToString(outcome.bleed) + "\n" + "Disorientation: " + Convert.ToString(outcome.disorientation) + "\n" + "Impairment: " + Convert.ToString(outcome.impairment) + "\n" + "Trauma: " + Convert.ToString(outcome.trauma) + "\n" + "KO: " + Convert.ToString(outcome.ko) + "\n";
                }
                richTextBox1.Text += outcome.HitLocation.ToString() + "\n\n";
                CombatScripts.applyAttackOutcome(outcome);
                EffectHolder.ClearUselessEffects();
            }
        }