Esempio n. 1
0
 private void UpdateMigration(DwarfTime gameTime)
 {
     if (Stats.IsMigratory && !AI.IsPositionConstrained())
     {
         if (MigrationTimer == null)
         {
             MigrationTimer = new Timer(3600f + MathFunctions.Rand(-120, 120), false);
         }
         MigrationTimer.Update(gameTime);
         if (MigrationTimer.HasTriggered)
         {
             AI.LeaveWorld();
         }
     }
 }
Esempio n. 2
0
        /// <summary> Updates the creature </summary>
        public virtual void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (FirstUpdate)
            {
                FirstUpdate = false;
                Faction.Minions.Add(AI);
                Physics.AllowPhysicsSleep = false;

                addToSpeciesCount();
            }

            if (!Active)
            {
                return;
            }
            DrawLifeTimer.Update(gameTime);

            if (!DrawLifeTimer.HasTriggered)
            {
                float val   = Hp / MaxHealth;
                Color color = val < 0.75f ? (val < 0.5f ? Color.Red : Color.Orange) : Color.LightGreen;
                Drawer2D.DrawLoadBar(Manager.World.Camera, AI.Position - Vector3.Up * 0.5f, color, Color.Black, 32, 2, Hp / MaxHealth);
            }

            CheckNeighborhood(chunks, (float)gameTime.ElapsedGameTime.TotalSeconds);
            UpdateAnimation(gameTime, chunks, camera);
            Status.Update(this, gameTime, chunks, camera);
            JumpTimer.Update(gameTime);
            HandleBuffs(gameTime);

            if (Stats.IsMigratory && !AI.IsPositionConstrained())
            {
                if (MigrationTimer == null)
                {
                    MigrationTimer = new Timer(3600f + MathFunctions.Rand(-120, 120), false);
                }
                MigrationTimer.Update(gameTime);
                if (MigrationTimer.HasTriggered)
                {
                    AI.LeaveWorld();
                }
            }

            if (Stats.LaysEggs)
            {
                if (EggTimer == null)
                {
                    EggTimer = new Timer(3600f + MathFunctions.Rand(-120, 120), false);
                }
                EggTimer.Update(gameTime);

                if (EggTimer.HasTriggered)
                {
                    if (!_speciesCounts.ContainsKey(Species) || _speciesCounts[Species] < _maxPerSpecies)
                    {
                        LayEgg();
                        EggTimer = new Timer(1200f + MathFunctions.Rand(-30, 30), false);
                    }
                }
            }

            if (IsPregnant && World.Time.CurrentDate > CurrentPregnancy.EndDate)
            {
                if (!_speciesCounts.ContainsKey(Species) || _speciesCounts[Species] < _maxPerSpecies)
                {
                    var baby = EntityFactory.CreateEntity <GameComponent>(BabyType, Physics.Position);
                    baby.GetRoot().GetComponent <CreatureAI>().PositionConstraint = AI.PositionConstraint;
                }
                CurrentPregnancy = null;
            }

            if (MathFunctions.RandEvent(0.0001f))
            {
                NoiseMaker.MakeNoise("Chirp", AI.Position, true, 0.25f);
            }
        }