Example #1
0
        // fight procedure
        public void Fight(Unit Attacker, Unit Defender)
        {
            int Distance = Coord.DistanceBetweenCoord(Attacker.Position, Defender.Position);

            Attacker.AttackedThisRound = true;
            Attacker.Range = 0; // attacker can't move after attacking

            int AttackerHealthBeforeFight = Attacker.Health;
            int AttackerPower = Attacker.GetCombatSkills()[0][(int)Defender.GetClass()], DefenderPower = Defender.GetCombatSkills()[1][(int)Attacker.GetClass()];
            int AttackerBuildingBasedBonus = (Map.GetBuildingByCoord(Attacker.Position) != null) ? Map.GetBuildingByCoord(Attacker.Position).GetAttackBonus() : 0;
            int DefenderGroundBasedBonus = Map.GetSurfaceByCoord(Defender.Position).DefenseBonus;

            Attacker.DecrementAmmunition();
            Defender.DecrementAmmunition();

            if (!(Defender.GetFiringRange() < Distance))
                if (!Attacker.DecreaseHealth((int)Math.Round(2 * ((Defender.Health / (double)Defender.GetMaxHealth()) * (DefenderPower / ((AttackerPower == 0) ? 1 : AttackerPower))) + DefenderGroundBasedBonus + 0.5, 0)))
                    RemoveUnit(Attacker, true);

            if (!(Attacker.GetFiringRange() < Distance))
                if (!Defender.DecreaseHealth((int)Math.Round(2 * ((AttackerHealthBeforeFight / (double)Attacker.GetMaxHealth()) * (AttackerPower / ((DefenderPower == 0) ? 1 : DefenderPower))) + AttackerBuildingBasedBonus + 0.5, 0)))
                    RemoveUnit(Defender, true);
        }
Example #2
0
        // returns a list of attackable fields for a unit
        public List<Coord> GetPossibleFieldsToAttack(Unit Unit)
        {
            if (Unit.AttackedThisRound || (!Unit.GetMoveAndFightInOneRound() && Unit.Range < Unit.GetDefaultRange()) || Unit.Ammunition == 0)
                return new List<Coord>();

            return Move.ConvertToCoordList(GetPossibleFieldsForUnit(Unit, Unit.Position, Unit.GetFiringRange(), true));
        }
Example #3
0
        // display info of a unit
        public void DisplayClickedFieldInfo(Unit Unit)
        {
            HideClickedFieldInfo();

            if (Unit == null) return;
            this.ShownUnit = Unit;

            Label_Info_Name.Content = R.String(Unit.GetName());
            Label_Info_Type.Visibility = Visibility.Visible;
            Label_Info_Type.Content = Unit.UnitClassToString(Unit.GetClass());

            Image_Info_Unit.Source = new BitmapImage(new Uri("Resources/Units/" + ((Unit.Fraction == Fraction.Saracens) ? "S" : "C") + "_" + Unit.GetName() + ".png", UriKind.Relative)); ;

            ListBox_Info_GeneralInformation_Description.Visibility = Visibility.Visible;
            StackPanel_UnitInfoIcons.Visibility = Visibility.Visible;

            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.Health.ToString() + " / " + Unit.GetMaxHealth().ToString());
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.Ammunition.ToString().Replace("-1", "++") + " / " + Unit.GetMaxAmmunition().ToString().Replace("-1", "++"));
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.Food.ToString().Replace("-1", "++") + " / " + Unit.GetMaxFood().ToString().Replace("-1", "++"));
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.Range.ToString() + " / " + Unit.GetDefaultRange().ToString());
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.GetInitiative().ToString());
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.GetFiringRange().ToString());
            ListBox_Info_GeneralInformation_Value.Items.Add(Unit.GetPrice().ToString());

            ShowUnitTypeInformationPopup(Unit);
        }