コード例 #1
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);
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
                }
            }
        }