Пример #1
0
        private AttackReport Attack(LivingTarget livingTarget)
        {
            AttackReport report = new AttackReport();

            report.attackPath = new Tuple <Point, Point>(this.Position, livingTarget.Being.Position);
            // calcualte
            Being target = livingTarget.Being;
            // first if it hits...
            // % based on attributes
            // of myself and
            int chanceOfHitting = (base.Attributes.Reactivity.Value - (target.Attributes.Reactivity.Value / 2));

            chanceOfHitting = chanceOfHitting < 25 ? 25 : chanceOfHitting;
            // bonuses and other stuff?!?!?!!???
            //not now it seems.. // TODO weapon bonuses, classees, if implemented, and other stufff

            int attempt = random.Next(99) + 1;

            if (attempt < chanceOfHitting)
            {
                // HIT
                int dmg = (base.Attributes.Strength.Value / 10 + CurrentWeapon.Damage);
                dmg = (int)Math.Round(dmg * ((double)random.Next(1, 10) / (double)10));
                target.Attributes.Durability -= dmg;
                report.Hits = true;
            }
            else
            {
                // MISS
                report.Hits = false;
            }

            return(report);
        }
Пример #2
0
        private ActionReport MoveToward(LivingTarget target)
        {
            // move towards the enemy some how.
            if (base.Attributes.PossibleMovementUnitWithOneUniversalMovement == null)
            {
                throw new InvalidOperationException("This being cannot move, as he has no movement.");
            }
            int movementMade = 0;
            int newX         = 0;
            int newY         = 0;

            while (movementMade < base.Attributes.PossibleMovementUnitWithOneUniversalMovement)
            {
                newX = CalculatePositionX(target);
                newY = CalculatePositionY(target);
                Point wantedPoint = new Point(newX, newY);
                if (target.PhaseOfExistance.CanIMoveInThePointPlace(this, wantedPoint))
                {
                    this.Position = wantedPoint;
                }

                movementMade++;
            }
            return(new ActionReport());
        }
Пример #3
0
 private bool AmIInRange(LivingTarget target)
 {
     if (CurrentWeapon.Range >= target.Distance)
     {
         return(true);
     }
     return(false);
 }
Пример #4
0
        /// <summary>
        /// The phase calls this, after an universal moment of time has passed
        /// </summary>
        /// <param name="phase"></param>
        public ActionReport DecideWhatTodo(Phase phase)
        {
            if (currentActionLimitation == 0)
            {
                currentActionLimitation = random.Next(4, 8);
            }
            // AM I alive?
            if (this.IsAlive)
            {
                // Where am I?
                //Phase phase =  FindOutInWhichPhaseIAm();
                // Is there anything I can attack?

                if (CurrentAttackTarget == null || !CurrentAttackTarget.Being.IsAlive || sameTargetIteration > currentActionLimitation)
                {
                    CurrentAttackTarget     = phase.GetLivingBeingClosestTo(this);
                    sameTargetIteration     = 0;
                    currentActionLimitation = random.Next(4, 8);
                }
                else
                {
                    sameTargetIteration++;
                }

                if (CurrentAttackTarget == null)
                {
                    return(MoveAround(phase));
                }
                else
                {
                    // Am In range?
                    if (AmIInRange(CurrentAttackTarget))
                    {
                        return(Attack(CurrentAttackTarget));
                    }
                    else
                    {
                        return(MoveToward(CurrentAttackTarget));
                    }
                }
            }
            else
            {
                if (this.IsALivingBeing)
                {
                    // if you are dead you keep losing 10 hp
                    // when you have less thatn 200, it will decompose.
                    this.Attributes.Durability -= 10;
                    return(new ActionReport());
                }
                else
                {
                    // do nothing
                    return(new ActionReport());
                }
            }
        }
Пример #5
0
 private int CalculatePositionX(LivingTarget target)
 {
     if (Position.X < target.Being.Position.X)
     {
         return(base.Position.X + 1);
     }
     else if (Position.X == target.Being.Position.X)
     {
         return(base.Position.X);
     }
     else
     {
         return(base.Position.X - 1);
     }
 }
Пример #6
0
 private int CalculatePositionY(LivingTarget target)
 {
     if (Position.Y < target.Being.Position.Y)
     {
         return(base.Position.Y + 1);
     }
     else if (Position.Y == target.Being.Position.Y)
     {
         return(base.Position.Y);
     }
     else
     {
         return(base.Position.Y - 1);
     }
 }