コード例 #1
0
 public Color GetRemappedColor(Color original, int index)
 {
     return(Color.FromArgb(original.A,
                           (int)Exts.Clamp((int)(scale * original.R + offset), 0, 255),
                           (int)Exts.Clamp((int)(scale * original.G + offset), 0, 255),
                           (int)Exts.Clamp((int)(scale * original.B + offset), 0, 255)));
 }
コード例 #2
0
        // Support power beacons are expected to clean themselves up
        public Beacon(Player owner, WPos position, string palettePrefix, string posterType, string posterPalette, Func <float> clockFraction)
            : this(owner, position, -1, palettePrefix)
        {
            this.posterPalette = posterPalette;

            if (posterType != null)
            {
                poster = new Animation(owner.World, "beacon");
                poster.Play(posterType);

                if (clockFraction != null)
                {
                    clock = new Animation(owner.World, "beacon");
                    clock.PlayFetchIndex("clock", () => Exts.Clamp((int)(clockFraction() * (clock.CurrentSequence.Length - 1)), 0, clock.CurrentSequence.Length - 1));
                }
            }
        }
コード例 #3
0
ファイル: Beacon.cs プロジェクト: JustSomeDev1/OpenRA
        // By default, support power beacons are expected to clean themselves up
        public Beacon(Player owner, WPos position, bool isPlayerPalette, string palette, string posterCollection, string posterType, string posterPalette,
                      string beaconSequence, string arrowSequence, string circleSequence, string clockSequence, Func <float> clockFraction, int delay = 0, int duration = -1)
            : this(owner, position, duration, palette, isPlayerPalette, posterCollection, beaconSequence, arrowSequence, circleSequence, delay)
        {
            this.posterPalette = posterPalette;

            if (posterType != null)
            {
                poster = new Animation(owner.World, posterCollection);
                poster.Play(posterType);

                if (clockFraction != null)
                {
                    clock = new Animation(owner.World, posterCollection);
                    clock.PlayFetchIndex(clockSequence, () => Exts.Clamp((int)(clockFraction() * (clock.CurrentSequence.Length - 1)), 0, clock.CurrentSequence.Length - 1));
                }
            }
        }
コード例 #4
0
        public void InflictDamage(Actor self, Actor attacker, int damage, WarheadInfo warhead, bool ignoreModifiers)
        {
            if (IsDead)
            {
                return;                                 /* overkill! don't count extra hits as more kills! */
            }
            var oldState = this.DamageState;
            /* apply the damage modifiers, if we have any. */
            var modifier = (float)self.TraitsImplementing <IDamageModifier>()
                           .Concat(self.Owner.PlayerActor.TraitsImplementing <IDamageModifier>())
                           .Select(t => t.GetDamageModifier(attacker, warhead)).Product();

            if (!ignoreModifiers)
            {
                damage = damage > 0 ? (int)(damage * modifier) : damage;
            }

            hp = Exts.Clamp(hp - damage, 0, MaxHP);

            var ai = new AttackInfo
            {
                Attacker            = attacker,
                Damage              = damage,
                DamageState         = this.DamageState,
                PreviousDamageState = oldState,
                Warhead             = warhead,
            };

            foreach (var nd in self.TraitsImplementing <INotifyDamage>()
                     .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyDamage>()))
            {
                nd.Damaged(self, ai);
            }

            if (DamageState != oldState)
            {
                foreach (var nd in self.TraitsImplementing <INotifyDamageStateChanged>())
                {
                    nd.DamageStateChanged(self, ai);
                }
            }

            if (attacker != null && attacker.IsInWorld && !attacker.IsDead())
            {
                foreach (var nd in attacker.TraitsImplementing <INotifyAppliedDamage>()
                         .Concat(attacker.Owner.PlayerActor.TraitsImplementing <INotifyAppliedDamage>()))
                {
                    nd.AppliedDamage(attacker, self, ai);
                }
            }

            if (hp == 0)
            {
                attacker.Owner.Kills++;
                self.Owner.Deaths++;

                foreach (var nd in self.TraitsImplementing <INotifyKilled>()
                         .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyKilled>()))
                {
                    nd.Killed(self, ai);
                }

                if (RemoveOnDeath)
                {
                    self.Destroy();
                }

                Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
            }
        }
コード例 #5
0
        public void InflictDamage(Actor self, Actor attacker, int damage, DamageWarhead warhead, bool ignoreModifiers)
        {
            // Overkill! don't count extra hits as more kills!
            if (IsDead)
            {
                return;
            }

            var oldState = this.DamageState;

            // Apply any damage modifiers
            if (!ignoreModifiers && damage > 0)
            {
                var modifiers = self.TraitsImplementing <IDamageModifier>()
                                .Concat(self.Owner.PlayerActor.TraitsImplementing <IDamageModifier>())
                                .Select(t => t.GetDamageModifier(attacker, warhead));

                damage = Util.ApplyPercentageModifiers(damage, modifiers);
            }

            hp = Exts.Clamp(hp - damage, 0, MaxHP);

            var ai = new AttackInfo
            {
                Attacker            = attacker,
                Damage              = damage,
                DamageState         = this.DamageState,
                PreviousDamageState = oldState,
                Warhead             = warhead,
            };

            foreach (var nd in self.TraitsImplementing <INotifyDamage>()
                     .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyDamage>()))
            {
                nd.Damaged(self, ai);
            }

            if (DamageState != oldState)
            {
                foreach (var nd in self.TraitsImplementing <INotifyDamageStateChanged>())
                {
                    nd.DamageStateChanged(self, ai);
                }
            }

            if (Info.NotifyAppliedDamage && attacker != null && attacker.IsInWorld && !attacker.IsDead())
            {
                foreach (var nd in attacker.TraitsImplementing <INotifyAppliedDamage>()
                         .Concat(attacker.Owner.PlayerActor.TraitsImplementing <INotifyAppliedDamage>()))
                {
                    nd.AppliedDamage(attacker, self, ai);
                }
            }

            if (hp == 0)
            {
                foreach (var nd in self.TraitsImplementing <INotifyKilled>()
                         .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyKilled>()))
                {
                    nd.Killed(self, ai);
                }

                if (RemoveOnDeath)
                {
                    self.Destroy();
                }

                Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
            }
        }