public override void StartUsing()
 {
     base.StartUsing();
     ParentThing.IsStealthy = true;
     blinking = new BlinkBehavior(1.4582f, 0.05f); // add a blinking which signals stealth
     ParentThing.AddNextUpdate(blinking);
     Level.Current.Subtitles.Show(2, "Wonders! My body faded away...", 3f);
 }
Exemple #2
0
        protected override void OnNextMove()
        {
            base.OnNextMove();

            // only attack if not blocked there.
            if (IsAttacking && !ParentThing.CollidesWithBackground(Leader.FacingDirection))
            {
                TargetMove          = Leader.FacingDirection;
                IsTargetMoveDefined = true;
            }
        }
 protected override void OnUpdate(ref TTengine.Core.UpdateParams p)
 {
     base.OnUpdate(ref p);
     IsTargetMoveDefined = true;
     AllowNextMove();
     if (SimTime >= PixelStormLevel.SCROLLING_START_TIME)
     {
         ParentThing.AddNextUpdate(new MoveUpBehavior());
         Delete = true;
     }
 }
Exemple #4
0
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            // check for dead chase targets
            if (ChaseTarget != null && ChaseTarget.Delete)
            {
                ChaseTarget = null;
            }

            // check the idle when far mode: if active, check distance to hero
            // and when far away from it don't bother to reget a new chase target.
            // since 'FindNearest' is CPU intensive.
            if (IsIdleWhenFarAway && ChaseTarget == null)
            {
                Vector2 dif  = Level.Current.hero.Position - ParentThing.Target;
                float   dist = dif.Length();
                if (dist >= FAR_AWAY_DISTANCE)
                {
                    return;
                }
            }

            // recheck for nearest chase target
            if (ChaseTarget == null && ChaseTargetType != null)
            {
                ChaseTarget = ParentThing.FindNearest(ChaseTargetType);
            }

            if (ChaseTarget != null && !ChaseTarget.IsStealthy && ChaseTarget.Health > 0f)
            {
                Vector2 dif  = ChaseTarget.Position - ParentThing.Target;
                float   dist = dif.Length();
                if (dist <= ChaseRange)
                {
                    if (dist > SatisfiedRange)
                    {
                        // indicate we're chasing
                        IsTargetMoveDefined = !isPauseChase;
                        AllowNextMove();
                    }
                }
                else
                {
                    if (ChaseTargetType != null)
                    {
                        // too far away - loose target; find a new one on next update.
                        ChaseTarget = null;
                    }
                }
            }
        }
Exemple #5
0
        public override void StartUsing()
        {
            base.StartUsing();

            // check what I'm facing
            List <Thing> facing = ParentThing.DetectCollisions(ParentThing.FacingDirection);

            foreach (Thing t in facing)
            {
                if (t is RedGuard || t is Servant)
                {
                    SerumTarget = t;
                    break; // only attack one thing at a time
                }
            }

            if (SerumTarget == null)
            {
                Level.Current.Subtitles.Show(2, "I can't use the serum here.", 3f);
                IsUsed = false;
                UsesLeft++;
            }
            else
            {
                String t = "";
                PathFindToTargetBehavior pathFindBehavior = new PathFindToTargetBehavior()
                {
                    ChaseTarget    = Level.Current.king,
                    ChaseRange     = 1970f,
                    SatisfiedRange = 3f,
                    Duration       = UseTimeMax
                };

                if (SerumTarget is RedGuard)
                {
                    t += "Red Guard";
                    var rg = SerumTarget as RedGuard;
                    rg.ComplexBehavior.Active = false;
                    rg.AddNextUpdate(pathFindBehavior);
                }
                if (SerumTarget is Servant)
                {
                    t += "Servant";
                    var sv = SerumTarget as Servant;
                    sv.ComplexBehavior.Active = false;
                    sv.AddNextUpdate(pathFindBehavior);
                }
                t += ", show me - WHERE is Arthur?!";
                Level.Current.Subtitles.Show(7, t, 4f);
            }
        }
Exemple #6
0
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            Vector2 rightHandDirection = RotateVector2(CurrentDirection, MathHelper.PiOver2);
            Vector2 leftHandDirection  = RotateVector2(CurrentDirection, -MathHelper.PiOver2);
            bool    isRightHandFree    = !ParentThing.CollidesWithBackground(rightHandDirection);
            bool    isLeftHandFree     = !ParentThing.CollidesWithBackground(leftHandDirection);
            bool    isFrontFree        = !ParentThing.CollidesWithBackground(CurrentDirection);

            // keep this control active if near walls
            if (didSeeWall || !isRightHandFree || !isLeftHandFree || !isFrontFree)
            {
                IsTargetMoveDefined = true;
                AllowNextMove();
            }
        }
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            // check if there is push from others. This push can build up over time, only
            // released upon a next move
            float dist = pushFromOthers.Length();

            if (dist > 0f)
            {
                // yes - check if push direction square occupied
                Vector2 dif = pushFromOthers;

                // choose dominant direction, if diagonals would be required
                if (Math.Abs(dif.X) > Math.Abs(dif.Y))
                {
                    dif.Y = 0f;
                }
                else
                {
                    dif.X = 0f;
                }
                dist = dif.Length(); // keep track of push force in that direction.
                dif.Normalize();

                // if that square is taken, transfer my push to the Thing there with my own Force added
                List <Thing> lt = ParentThing.DetectCollisions(dif);
                foreach (Thing t in lt)
                {
                    t.Pushing.BePushed(dif * dist);
                }

                // if the square being pushed to is free, allow the move to go there
                if (lt.Count == 0)
                {
                    TargetMove          = dif;
                    IsTargetMoveDefined = true;
                    wTime = 0f; // FIXME hack to trigger instant-move
                    AllowNextMove();
                }
            }

            // reset the push buildup
            pushFromOthers = Vector2.Zero;
        }
Exemple #8
0
    public ParentThing GenerateEntity()
    {
        var thing = new ParentThing();

        thing.TheFirstThing = new ChildThing
        {
            Code = FirstThingCode,
            Name = FirstThingName
        };
        if (!string.IsNullOrWhiteSpace(SecondThingCode))
        {
            thing.TheSecondThing = new ChildThing
            {
                Code = SecondThingCode,
                Name = SecondThingName
            };
        }
        return(thing);
    }
        protected override void OnNextMove()
        {
            base.OnNextMove();

            // check for enemy facing
            List <Thing> facing = ParentThing.DetectCollisions(ParentThing.FacingDirection);

            WasCombat = IsCombat;
            IsCombat  = false;
            float randomVal = RandomMath.RandomUnit();

            foreach (Thing t in facing)
            {
                if (t.GetType() == EnemyType && t.Health > 0 && !t.IsStealthy)
                {
                    IsCombat            = true;
                    IsTargetMoveDefined = true;
                    TargetMove          = Vector2.Zero;
                    if (!WasCombat || randomVal < 0.08f)
                    {
                        var damage = RandomMath.RandomBetween(MinDamage, MaxDamage);
                        HurtBehavior.Apply(t, damage, MaxDamage);
                        t.Health -= damage;
                    }
                    break; // only attack one thing at a time
                }
            }

            if (IsCombat)
            {
                if (!WasCombat || randomVal < 0.08f)
                {
                    var dist = (ParentThing.Position - Level.Current.hero.Position).Length();
                    Level.Current.Sound.PlayRandomCombatSound(0.2f, 0.3f, dist);
                }
            }
        }
Exemple #10
0
        protected override void OnNextMove()
        {
            base.OnNextMove();

            Vector2 rightHandDirection = RotateVector2(CurrentDirection, MathHelper.PiOver2);
            Vector2 leftHandDirection  = RotateVector2(CurrentDirection, -MathHelper.PiOver2);
            bool    isRightHandFree    = !ParentThing.CollidesWithSomething(rightHandDirection);
            bool    isLeftHandFree     = !ParentThing.CollidesWithSomething(leftHandDirection);
            bool    isFrontFree        = !ParentThing.CollidesWithSomething(CurrentDirection);

            // change direction to righthand if that's free
            if (didSeeWall && isRightHandFree)
            {
                CurrentDirection    = rightHandDirection;
                didSeeWall          = false;
                TargetMove          = CurrentDirection;
                IsTargetMoveDefined = true;
            }

            else if (!isFrontFree)
            {
                // turn left if the way is blocked
                CurrentDirection = leftHandDirection;
                didSeeWall       = true;
            }
            else if (didSeeWall || !isRightHandFree || !isLeftHandFree || !isFrontFree)
            {
                TargetMove          = CurrentDirection;
                IsTargetMoveDefined = true;
            }

            if (!isRightHandFree)
            {
                didSeeWall = true;
            }
        }
Exemple #11
0
 public GivenAnInstanceOfParent()
 {
     _parent = new ParentThing();
 }
Exemple #12
0
 public GivenANullParent()
 {
     _parent = default(ParentThing);
 }
Exemple #13
0
        protected override void OnNextMove()
        {
            base.OnNextMove();

            // compute direction towards chase-target
            Vector2 dif = ChaseTarget.Position - ParentThing.Target;

            if (Avoidance)
            {
                dif = -dif;
            }
            if (dif.Length() == 0f)
            {
                return;
            }

            Vector2 difX = new Vector2(dif.X, 0f);
            Vector2 difY = new Vector2(0f, dif.Y);

            if (difX.Length() > 0f)
            {
                difX.Normalize();
            }
            if (difY.Length() > 0f)
            {
                difY.Normalize();
            }

            // whats-free
            bool isBlockedX     = (difX.X != 0f) && ParentThing.ChecksCollisions && ParentThing.CollidesWithBackground(difX);
            bool isBlockedY     = (difY.Y != 0f) && ParentThing.ChecksCollisions && ParentThing.CollidesWithBackground(difY);
            bool isFullyBlocked = (isBlockedX && (dif.Y == 0f)) ||
                                  (isBlockedY && (dif.X == 0f)) ||
                                  (isBlockedX && isBlockedY);
            bool isDiagonal = (dif.X != 0f) && (dif.Y != 0f);

            // choose one direction 1) based on whats free, then 2) semi-randomly, if diagonals would be required
            isPauseChase = false;
            if (isFullyBlocked)
            {
                dif = new Vector2(difY.Y, difX.X); // try a swap to get around obstacle
            }
            else if (isBlockedX)                   // choose Y move if x is blocked
            {
                dif = difY;
            }
            else if (isBlockedY)    // choose X move if y is blocked
            {
                dif = difX;
            }
            else if (isDiagonal)   // choose random x/y if a diagonal move would be required
            {
                float r     = RandomMath.RandomUnit();
                float thres = 0.5f;
                if (r > thres)
                {
                    dif = difX;
                }
                else
                {
                    dif = difY;
                }
            }
            else
            {
                dif.Normalize();
            }

            TargetMove = dif;
        }