Пример #1
0
        public override void OnFinishTurn(Action action)
        {
            // Make some noise.
            LastNoise = action.Noise;

            HeroClass.FinishedTurn(action);
        }
Пример #2
0
        /// This is called when another monster in sight of this one has damaged the
        /// hero.
        public void _viewHeroDamage(Action action, int damage)
        {
            var fear = 50.0 * damage / Health.Max;

            _modifyFear(action, -fear);
            Debugger.Instance.logMonster(this, "Witness " + damage + $" / {Health.Max} decreases fear by {fear} to {Fear}");
        }
Пример #3
0
        /// Called when this Actor has been killed by [attackNoun].
        public override void OnDied(Noun attackNoun)
        {
            // Try to keep dropped items from overlapping.
            var flow = new Flow(Game.CurrentStage, Position, null, false, true);

            Func <VectorBase, bool> predicateNearestWhere = delegate(VectorBase position)
            {
                if (Rng.Instance.OneIn(5))
                {
                    return(true);
                }
                return(Game.CurrentStage.ItemAt(position) == null);
            };

            // A "Delefate" with no return type
            Action <Item> myBreedDrop = delegate(Item item)
            {
                var itemPos = Position;
                if (Game.CurrentStage.ItemAt(Position) != null)
                {
                    itemPos = flow.NearestWhere(predicateNearestWhere);
                }

                item.Position = itemPos;
                Game.CurrentStage.Items.Add(item);
                Log("{1} drop[s] {2}.", this, item);
            };

            Breed.Drop.SpawnDrop(new AddItem(myBreedDrop));

            Game.CurrentStage.removeActor(this);
            Debugger.Instance.removeMonster(this);
        }
Пример #4
0
        public override void KilledMonster(Action action, Monster monster)
        {
            var         weapon = Hero.Equipment.Weapon;
            TrainedStat stat;
            string      name;

            if (weapon != null)
            {
                stat = Combat;
                name = "combat";

                if (!Masteries.ContainsKey(weapon.type.category))
                {
                    Masteries.Add(weapon.type.category, NewMasteryStat());
                }
                var mastery = Masteries[weapon.type.category];
                if (mastery.Increment(monster.Breed.MaxHealth))
                {
                    action.Game.Log.Gain("{1} [have|has] reached ${weapon.type.category} mastery level ${mastery.level}.", Hero);
                }
            }
            else
            {
                stat = Fighting;
                name = "fighting";
            }

            // Base it on the health of the monster to discourage the player from just
            // killing piles of weak monsters.
            if (stat.Increment(monster.Breed.MaxHealth))
            {
                action.Game.Log.Gain($"{Hero.NounText} [have|has] reached {name} level {stat.Level}.");
            }
        }
Пример #5
0
        //public override void OnKilled(Action.Action action, Monster defender)
        public override void OnKilled(Action action, Actor defender)
        {
            var monster = (Monster)defender;

            ExperienceCents += monster.ExperienceCents / Level;
            RefreshLevel(true);
            HeroClass.KilledMonster(action, monster);
        }
Пример #6
0
 /// Processes one turn of the condition.
 public void Update(Action action)
 {
     if (IsActive)
     {
         turnsRemaining--;
         if (IsActive)
         {
             OnUpdate(action);
         }
         else
         {
             OnDeactivate();
             Intensity = 0;
         }
     }
 }
Пример #7
0
        /// Fear decays over time, more quickly the farther the monster is from the
        /// hero.
        private void DecayFear(Action action)
        {
            // TODO: Poison should slow the decay of fear.
            var fearDecay = 5.0 + (Position - Game.Hero.Position).kingLength();

            // Fear decays more quickly if out of sight.
            if (!IsVisible)
            {
                fearDecay = 5.0 + fearDecay * 2.0;
            }

            // The closer the monster is to death, the less quickly it gets over fear.
            fearDecay = 2.0 + fearDecay * Health.Current / Health.Max;

            _modifyFear(action, -fearDecay);
            Debugger.Instance.logMonster(this, "Decay fear by " + fearDecay + " to " + Fear);
        }
Пример #8
0
        /// Inflicting damage decreases fear.
        public override void OnDamage(Action action, Actor defender, int damage)
        {
            // The greater the power of the hit, the more emboldening it is.
            var fear = 100.0 * damage / Game.Hero.Health.Max;

            _modifyFear(action, -fear);
            Debugger.Instance.logMonster(this, "Hit for " + damage + " / " + Game.Hero.Health.Max + " decreases fear by " + fear + " to " + Fear);

            Func <Monster, bool> myWitness = delegate(Monster witness)
            {
                witness._viewHeroDamage(action, damage);
                return(true);
            };

            // Nearby monsters may witness it.
            _updateWitnesses(myWitness);
        }
Пример #9
0
        public void FinishTurn(Action action)
        {
            Energy.Spend();

            if (Conditions != null)
            {
                foreach (var condition in Conditions)
                {
                    condition.Update(action);
                }
            }

            if (IsAlive)
            {
                OnFinishTurn(action);
            }
        }
Пример #10
0
        /// This is called when another monster in sight of this one has taken
        /// damage.
        private void _viewMonsterDamage(Action action, Monster monster, int damage)
        {
            var fear = 50.0 * damage / Health.Max;

            if (Breed.Flags.Contains("protective") && monster.Breed == Breed)
            {
                // Seeing its own kind get hurt enrages it.
                fear *= -2.0;
            }
            else if (Breed.Flags.Contains("berzerk"))
            {
                // Seeing any monster get hurt enrages it.
                fear *= -1.0;
            }

            _modifyFear(action, fear);
            Debugger.Instance.logMonster(this, "Witness " + damage + " / " + Health.Max + " increases fear by " + fear + " to " + Fear);
        }
Пример #11
0
        /// Modifies fear and then determines if it's has crossed the threshold to
        /// cause a state change.
        private void _modifyFear(Action action, double offset)
        {
            // Don't add effects if the monster already died.
            if (!IsAlive)
            {
                return;
            }

            if (Breed.Flags.Contains("fearless"))
            {
                return;
            }

            // If it can't run, there's no point in being afraid.
            if (Breed.Flags.Contains("immobile"))
            {
                return;
            }

            Fear = Math.Max(0.0, Fear + offset);

            if (State is AwakeState && Fear > _frightenThreshold)
            {
                // Clamp the fear. This is mainly to ensure that a bunch of monsters
                // don't all get over their fear at the exact same time later. Since the
                // threshold is randomized, this will make the delay before growing
                // courageous random too.
                Fear = _frightenThreshold;

                Log("{1} is afraid!", this);
                changeState(new AfraidState());
                action.AddEvent(EventType.Fear, this);
                return;
            }

            if (State is AfraidState && Fear <= 0.0)
            {
                Log("{1} grows courageous!", this);
                changeState(new AwakeState());
                action.AddEvent(EventType.Courage, this);
            }
        }
Пример #12
0
        public override void TookDamage(Action action, Actor attacker, int damage)
        {
            // Getting hit increases fury.
            Hero.Charge.Current = Math.Min(100, Hero.Charge.Current + 200 * damage / Hero.Health.Max);

            // Indirect damage doesn't increase toughness.
            if (attacker == null)
            {
                return;
            }

            // Reduce damage by armor (again). This is so that toughness increases
            // much more slowly as the hero wears more armor.
            damage = (int)Math.Floor(damage * ArmorUtilities.GetArmorMultiplier(Hero.Armor - Toughness.Level) * 10);

            if (Toughness.Increment(damage))
            {
                action.Game.Log.Gain("{1} [have|has] reached toughness level " + Toughness.Level + ".", Hero);
            }
        }
Пример #13
0
        /// Taking damage increases fear.
        public override void OnDamaged(Action action, Actor attacker, int damage)
        {
            // The greater the power of the hit, the more frightening it is.
            var fear = 100.0 * damage / Health.Max;

            // Getting hurt enrages it.
            if (Breed.Flags.Contains("berzerk"))
            {
                fear *= -3.0;
            }

            _modifyFear(action, fear);

            Debugger.Instance.logMonster(this, "Hit for " + damage + $" / {Health.Max} increases fear by {fear} to {Fear}");

            Func <Monster, bool> myWitness = delegate(Monster witness)
            {
                witness._viewMonsterDamage(action, this, damage);
                return(true);
            };

            // Nearby monsters may witness it.
            _updateWitnesses(myWitness);
        }
Пример #14
0
        /// Reduces the actor's health by [damage], and handles its death. Returns
        /// `true` if the actor died.
        public bool TakeDamage(Action action, int damage, Noun attackNoun, Actor attacker = null)
        {
            Health.Current -= damage;
            action.Log("{1} takes {2} damage.", this.NounText, damage.ToString());

            OnDamaged(action, attacker, damage);

            if (Health.Current > 0)
            {
                return(false);
            }

            action.AddEvent(EventType.Die, element: ElementFactory.Instance.None, other: null, pos: null, dir: null, actor: this);

            action.Log("{1} kill[s] {2}.", attackNoun, this);
            if (attacker != null)
            {
                attacker.OnKilled(action, this);
            }

            OnDied(attackNoun);

            return(true);
        }
Пример #15
0
 public void SetNextAction(Action action)
 {
     Behavior = new ActionBehavior(action);
 }
Пример #16
0
 /// Called when the [Hero] has finished taking a turn.
 public abstract void FinishedTurn(Action action);
Пример #17
0
 public override void OnDamaged(Action action, Actor attacker, int damage)
 {
     HeroClass.TookDamage(action, attacker, damage);
 }
Пример #18
0
 public void OnUpdate(Action action)
 {
 }
Пример #19
0
 /// Called when this actor has successfully hit this [defender].
 public virtual void OnDamage(Action action, Actor defender, int damage)
 {
     // Do nothing.
 }
Пример #20
0
 /// Called when the [Hero] has killed [monster].
 public abstract void KilledMonster(Action action, Monster monster);
Пример #21
0
 public override void OnFinishTurn(Action action)
 {
     DecayFear(action);
 }
Пример #22
0
 /// Called when this Actor has completed a turn.
 public virtual void OnFinishTurn(Action action)
 {
     // Do nothing.
 }
Пример #23
0
 public override void FinishedTurn(Action action)
 {
     // Fury decays over time.
     Hero.Charge.Current = Math.Floor(Hero.Charge.Current * 0.9);
 }
Пример #24
0
 /// Called when [attacker] has successfully hit this actor.
 ///
 /// [attacker] may be `null` if the damage is not the direct result of an
 /// attack (for example, poison).
 public virtual void OnDamaged(Action action, Actor attacker, int damage)
 {
     // Do nothing.
 }
Пример #25
0
 /// Called when this Actor has killed [defender].
 public virtual void OnKilled(Action action, Actor defender)
 {
     // Do nothing.
 }
Пример #26
0
 /// Called when the [Hero] has taken [damage] from [attacker].
 public abstract void TookDamage(Action action, Actor attacker, int damage);