// 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 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();
        }
Пример #4
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 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();
            }
        }