Beispiel #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);
        }
Beispiel #2
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);
        }