Beispiel #1
0
        private void DrawIcon()
        {
            Debug.Assert(bmpIconOriginal != null);
            Debug.Assert(IsLive);

            bmpIcon?.Dispose();
            bmpIcon = new Bitmap(bmpIconOriginal);
            Graphics g = Graphics.FromImage(bmpIcon);

            // Рисуем иконку героя
            g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            Program.formMain.imListObjectsCell.DrawImage(g, Program.formMain.TreatImageIndex(PlayerHero.TypeCreature.ImageIndex, PlayerHero.BattleParticipant), State != StateHeroInBattle.Tumbstone, false, FormMain.Config.ShiftForBorder.X, FormMain.Config.ShiftForBorder.Y);

            // Если юнит в могиле и исчезает, применяем исчезновение
            if (countAction <= FormMain.Config.UnitStepsTimeToDisappearance)
            {
            }

            // Если это противник, то обращаем его в противоположную сторону
            if (PlayerHero.BattleParticipant != Battle.Player1)
            {
                bmpIcon.RotateFlip(RotateFlipType.RotateNoneFlipX);
            }

            // Рисуем бордюр
            g.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImageUnscaled(PlayerHero.BattleParticipant == Battle.Player1 ? Program.formMain.bmpBorderForIconAlly : Program.formMain.bmpBorderForIconEnemy, 0, 0);

            // Рисуем состояние
            if ((State != StateHeroInBattle.None) || (priorState != StateHeroInBattle.None))
            {
                StateHeroInBattle s = State != StateHeroInBattle.None ? State : priorState;

                //Program.formMain.ilStateHero.DrawImage(g, (int)s, ImageState.Normal, FormMain.Config.ShiftForBorder.X + 1, FormMain.Config.ShiftForBorder.Y + 1);
            }

            // Рисуем полоску жизни
            GuiUtils.DrawBand(g, new Rectangle(FormMain.Config.ShiftForBorder.X + 2, FormMain.Config.ShiftForBorder.Y + Program.formMain.imListObjectsCell.Size - 6, Program.formMain.imListObjectsCell.Size - 4, 4), brushBandHealth, brushBandHealthNone, CurrentHealth, Parameters.Health);

            // Применяем исчезновение
            if (inDisappearance)
            {
                bmpIcon = GuiUtils.ApplyDisappearance(bmpIcon, countAction, FormMain.Config.UnitStepsTimeToDisappearance);
            }

            needRedraw = false;
            g.Dispose();
        }
Beispiel #2
0
        //internal int MoveStepPaa

        // Делает шаг битвы
        internal void DoStepBattle(Battle b)
        {
            Debug.Assert(IsLive == true);
            Debug.Assert(CurrentTile != null);

            priorState = State;

            if (inRollbackAfterAction == false)
            {
                switch (State)
                {
                case StateHeroInBattle.None:
                    Debug.Assert(Target == null);
                    Debug.Assert(countAction == 0);
                    Debug.Assert(CurrentHealth > 0);
                    Debug.Assert(IsLive == true);

                    // Если сейчас ничего не выполняем, ищем, что можно сделать
                    // Сначала пробуем атаковать стрелковым оружием

                    if (((PlayerHero.RangeWeapon != null) && (QuantityArrows > 0)) || (PlayerHero.TypeCreature.ID == "Cleric") || (PlayerHero.TypeCreature.ID == "Mage"))
                    {
                        bool underMeleeAttack = false;
                        // Если юнит не атакован врукопашную, можно атаковать стрелковой атакой
                        foreach (HeroInBattle h in b.ActiveHeroes)
                        {
                            if ((h != this) && (h.Target == this) && (h.State == StateHeroInBattle.MeleeAttack))
                            {
                                underMeleeAttack = true;
                                break;
                            }
                        }

                        if (!underMeleeAttack)
                        {
                            SearchTargetForShoot();
                        }
                    }

                    if (Target == null)
                    {
                        if (!SearchTargetForMelee())
                        {
                            // Если целей нет, идем к ней
                            if (Target == null)
                            {
                                if (SearchTargetForMove() == true)
                                {
                                    State                 = StateHeroInBattle.Move;
                                    countAction           = (int)(TimeMove() * 1.00 * ((TileForMove.X != 0) && (TileForMove.Y != 0) ? 1.4 : 1));
                                    timeAction            = countAction;
                                    inRollbackAfterAction = false;
                                    //State = StateHeroInBattle.PrepareMove;
                                }
                            }
                        }
                    }

                    break;

                case StateHeroInBattle.MeleeAttack:
                    countAction--;

                    if (Target.State != StateHeroInBattle.Tumbstone)
                    {
                        if (countAction == 0)
                        {
                            // Делаем удар по противнику
                            Target.GetDamage(CalcDamageMelee(Target), CalcDamageShoot(Target), CalcDamageMagic(Target));
                            LastTarget = Target.Coord;
                            Target     = null;

                            // После удара делаем паузу длиной во время атаки
                            countAction           = TimeAttack();
                            inRollbackAfterAction = true;
                        }
                    }
                    else
                    {
                        // Противника уже убили, пропускаем ход
                        LastTarget            = Target.Coord;
                        Target                = null;
                        State                 = StateHeroInBattle.None;
                        countAction           = timeAction - countAction;
                        timeAction            = countAction;
                        inRollbackAfterAction = true;
                    }

                    break;

                case StateHeroInBattle.RangeAttack:
                case StateHeroInBattle.Cast:
                    countAction--;

                    if (Target.State != StateHeroInBattle.Tumbstone)
                    {
                        if (countAction == 0)
                        {
                            // Делаем удар по противнику
                            LastTarget = Target.Coord;
                            Target     = null;

                            // После удара делаем паузу длиной во время атаки
                            countAction           = TimeAttack();
                            inRollbackAfterAction = true;
                        }
                    }
                    else
                    {
                        // Противника уже убили, пропускаем ход
                        LastTarget            = Target.Coord;
                        Target                = null;
                        State                 = StateHeroInBattle.None;
                        countAction           = timeAction - countAction;
                        timeAction            = countAction;
                        inRollbackAfterAction = true;
                    }

                    break;

                case StateHeroInBattle.Tumbstone:
                    Debug.Assert(Target == null);

                    countAction--;
                    if (countAction == 0)
                    {
                        IsLive           = false;
                        State            = StateHeroInBattle.Dead;
                        currentTile.Unit = null;
                        currentTile      = null;
                    }
                    else
                    {
                        // Если осталось шагов меньше, чем шагов на исчезновение, то надо перерисовать иконку
                        if (countAction <= FormMain.Config.UnitStepsTimeToDisappearance)
                        {
                            inDisappearance = true;
                            needRedraw      = true;
                        }
                    }

                    break;

                case StateHeroInBattle.Move:
                    Debug.Assert(TileForMove != null);
                    Debug.Assert(TileForMove.Unit == null);

                    countAction--;
                    if (countAction == 0)
                    {
                        Debug.Assert(TileForMove.ReservedForMove == this);

                        // Пришли на тайл
                        Target      = null;
                        CurrentTile = TileForMove;
                        TileForMove.ReservedForMove = null;
                        TileForMove = null;

                        if (PathToDestination.Count() > 1)
                        {
                            // Заново осматриваемся
                            State = StateHeroInBattle.None;

                            /*TileForMove = PathToDestination.First();
                             * PathToDestination.RemoveAt(0);
                             * countAction = TimeMove();
                             * timeAction = countAction;*/
                        }
                        else
                        {
                            // Пришли на конечный тайл
                            State = StateHeroInBattle.None;
                        }
                        PathToDestination  = null;
                        DestinationForMove = null;
                    }

                    break;

                default:
                    break;
                }
            }
            else
            {
                countAction--;
                if (countAction == 0)
                {
                    LastTarget            = default;
                    State                 = StateHeroInBattle.None;
                    inRollbackAfterAction = false;
                }
            }

            if (priorState != State)
            {
                needRedraw = true;
            }

            bool SearchTargetForMelee()
            {
                // Ищем, кого атаковать
                List <HeroInBattle> targets = new List <HeroInBattle>();

                foreach (HeroInBattle h in b.ActiveHeroes)
                {
                    // Собираем список вражеских героев вокруг себя
                    if (h.IsLive == true)
                    {
                        if (h.Player != Player)
                        {
                            if (h.CurrentHealth > 0)
                            {
                                if (IsNeighbour(h) == true)
                                {
                                    targets.Add(h);
                                }
                            }
                        }
                    }
                }

                if (targets.Count > 0)
                {
                    Debug.Assert(this != targets[0]);

                    State       = StateHeroInBattle.MeleeAttack;
                    Target      = targets[0];
                    countAction = TimeAttack();
                    timeAction  = countAction;

                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            bool SearchTargetForShoot()
            {
                //Debug.Assert(PlayerHero.RangeWeapon != null);

                // Если герой, по которому стреляли, жив, атакуем его снова
                if ((lastAttackedHero != null) && (lastAttackedHero.CurrentHealth > 0))
                {
                    Target = lastAttackedHero;
                }
                else
                {
                    // Ищем, кого атаковать
                    List <HeroInBattle> targets = new List <HeroInBattle>();

                    foreach (HeroInBattle h in b.ActiveHeroes)
                    {
                        // Собираем список вражеских героев
                        if (h.Player != Player)
                        {
                            if (h.CurrentHealth > 0)
                            {
                                targets.Add(h);
                            }
                        }
                    }

                    if (targets.Count > 0)
                    {
                        Debug.Assert(this != targets[0]);
                        Target = targets[0];// targets[Battle.Rnd.Next(0, targets.Count - 1)];
                    }
                }

                if (Target != null)
                {
                    State            = StateHeroInBattle.RangeAttack;
                    countAction      = TimeAttack();
                    timeAction       = countAction;
                    lastAttackedHero = Target;

                    // Создаем выстрел
                    if (PlayerHero.RangeWeapon != null)
                    {
                        Debug.Assert(QuantityArrows > 0);
                        Battle.Missiles.Add(new Arrow(this, Target.CurrentTile));
                        QuantityArrows--;
                    }
                    else
                    {
                        Battle.Missiles.Add(new MagicStrike(this, Target.CurrentTile));
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            bool IsNeighbour(HeroInBattle hb)
            {
                Debug.Assert(this != hb);

                return(currentTile.IsNeighbourTile(hb.currentTile));
            }
        }