예제 #1
0
            public int DamageReceivedOnAttack(Group attackingGroup)
            {
                if (ImmuneTo.Contains(attackingGroup.Attack.Type))
                {
                    return(0);
                }

                var damage = attackingGroup.EffectivePower;

                if (Weaknesses.Contains(attackingGroup.Attack.Type))
                {
                    damage = damage * 2;
                }

                return(damage);
            }
예제 #2
0
            public UnitGroup(int id, string type, string line, int attackPowerboost)
            {
                ID = id;
                var digitRegex = new Regex(@"-?\d+");

                if (line.Contains("("))
                {
                    var character = new string(line.Skip(line.IndexOf('(') + 1).TakeWhile(c => c != ')').ToArray());

                    var immuneIndexString = "immune to ";
                    var weakIndexString   = "weak to ";

                    var characterSubstring = character.Split(';');
                    foreach (var sub in characterSubstring)
                    {
                        switch (sub.Trim().First())
                        {
                        case 'i':
                            var mysub = sub.Trim().Replace(immuneIndexString, "").Split(',');
                            foreach (var s in mysub)
                            {
                                ImmuneTo.Add(GetAttackType(s.Trim()));
                            }
                            break;

                        case 'w':
                            var myweakSyb = sub.Trim().Replace(weakIndexString, "").Split(',');
                            foreach (var s in myweakSyb)
                            {
                                WeakTo.Add(GetAttackType(s.Trim()));
                            }
                            break;

                        default:
                            throw new Exception("Not allright!");
                        }
                    }
                }
                var damageIndexTo = new string(" damage at initiative".Reverse().ToArray());

                var reverseString = new string(line.Reverse().ToArray());
                var attackType    = new string(reverseString.Skip(reverseString.IndexOf(damageIndexTo) + damageIndexTo.Length).TakeWhile(c => c != ' ').Reverse().ToArray());
                var group         = digitRegex.Matches(line);

                switch (type)
                {
                case "Immune System:":
                    UnitType      = UnitType.Immune_System;
                    EnemyUnitType = UnitType.Infection;
                    break;

                case "Infection:":
                    UnitType      = UnitType.Infection;
                    EnemyUnitType = UnitType.Immune_System;
                    break;

                default:
                    break;
                }

                AttackType  = GetAttackType(attackType);
                Attackpower = Convert.ToInt32(group[2].Value) + (UnitType == UnitType.Immune_System ? attackPowerboost : 0);
                Initiative  = Convert.ToInt32(group[3].Value);

                for (int i = 0; i < Convert.ToInt32(group[0].Value); i++)
                {
                    Units.Add(new Unit(Convert.ToInt32(group[1].Value), AttackType, Convert.ToInt32(group[3].Value)));
                }
            }