Exemple #1
0
 public DelayedImpact(int delay, IWarhead wh, Target target, WarheadArgs args)
 {
     this.wh     = wh;
     this.delay  = delay;
     this.target = target;
     this.args   = args;
 }
        /// <summary>
        /// Generate the logic for a rocket
        /// </summary>
        /// <param name="is_friendly">States if the rocket was fired by the player</param>
        /// <param name="clickX">The X coordinate of the mouse click</param>
        /// <param name="clickY">The Y coordinate of the mouse click</param>
        /// <returns>Returns a rocket instance</returns>
        public Rocket GenerateRocket(bool is_friendly, double clickX = 0, double clickY = 0)
        {
            IEngine  e = GenerateEngine(is_friendly);
            IWarhead w = GenerateWarhead(is_friendly);
            Rocket   rocket;

            if (is_friendly)
            {
                Point start = new Point(Cw / 2, Ch - (Rocket.H / 2));
                rocket = new Rocket(e, w, start, clickX, clickY, is_friendly);
            }
            else
            {
                Point start;
                if (clickX == 0 && clickY == 0)
                {
                    start = new Point(MainWindow.R.Next(1, (int)Math.Round(Cw - 1)), Rocket.H / 2);
                }
                else
                {
                    start = new Point(clickX, clickY);
                }

                int targetX = MainWindow.R.Next(1, (int)Math.Round(Cw - Rocket.W));
                int targetY = (int)Math.Round(Ch - Rocket.H);
                rocket = new Rocket(e, w, start, targetX, targetY, is_friendly);

                if (clickX != 0 || clickY != 0)
                {
                    rocketsToInsert.Enqueue(rocket);
                }
            }

            return(rocket);
        }
Exemple #3
0
        public DelayedImpact(int delay, IWarhead wh, Target target, Actor firedBy, IEnumerable <int> damageModifiers)
        {
            this.wh    = wh;
            this.delay = delay;

            this.target          = target;
            this.firedBy         = firedBy;
            this.damageModifiers = damageModifiers;
        }
Exemple #4
0
        public void InflictDamage(Actor attacker, int damage, IWarhead warhead)
        {
            if (Disposed || health == null)
            {
                return;
            }

            health.InflictDamage(this, attacker, damage, warhead, false);
        }
Exemple #5
0
        public int GetDamageModifier(Actor attacker, IWarhead warhead)
        {
            if (!IsProne)
                return 100;

            var damageWh = warhead as DamageWarhead;
            if (damageWh == null)
                return 100;

            var modifierPercentages = info.DamageModifiers.Where(x => damageWh.DamageTypes.Contains(x.Key)).Select(x => x.Value);
            return Util.ApplyPercentageModifiers(100, modifierPercentages);
        }
        public int GetDamageModifier(Actor attacker, IWarhead warhead)
        {
            var damageWh = warhead as DamageWarhead;
            if (attacker.Owner.IsAlliedWith(self.Owner) && (damageWh != null && damageWh.Damage < 0) && !Info.ModifyHealing)
                return FullDamage;

            var world = self.World;
            var map = world.Map;

            var pos = map.CellContaining(self.CenterPosition);
            var terrainType = map.GetTerrainInfo(pos).Type;

            if (!Info.TerrainModifier.ContainsKey(terrainType))
                return FullDamage;

            return Info.TerrainModifier[terrainType];
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Airspace_Commander.Rocket" /> class.
        /// </summary>
        /// <param name="newEngine">The engine this rocket will use</param>
        /// <param name="newWarhead">The warhead this rocket will use</param>
        /// <param name="coords">The coordinates this rocket is at</param>
        /// <param name="newTargetX">Target coordinate on the X axis</param>
        /// <param name="newTargetY">Target coordinate on the Y axis</param>
        /// <param name="newIsFriendly">The "friendlyness" of the rocket</param>
        public Rocket(IEngine newEngine, IWarhead newWarhead, Point coords, double newTargetX, double newTargetY, bool newIsFriendly)
        {
            engine     = newEngine;
            warhead    = newWarhead;
            position   = coords;
            startX     = position.X;
            startY     = position.Y;
            targetX    = newTargetX;
            targetY    = newTargetY;
            isFriendly = newIsFriendly;

            double distanceX  = (startX - targetX) * -1;
            double distanceY  = (startY - targetY) * -1;
            double multiplier = 1 / (Math.Abs(distanceX) + Math.Abs(distanceY));

            dx = Engine.Speed * multiplier * distanceX;
            dy = Engine.Speed * multiplier * distanceY;
        }
Exemple #8
0
        public int GetDamageModifier(Actor attacker, IWarhead warhead)
        {
            if (!IsProne)
            {
                return(100);
            }

            var damageWh = warhead as DamageWarhead;

            if (damageWh == null)
            {
                return(100);
            }

            var modifierPercentages = info.DamageModifiers.Where(x => damageWh.DamageTypes.Contains(x.Key)).Select(x => x.Value);

            return(Util.ApplyPercentageModifiers(100, modifierPercentages));
        }
Exemple #9
0
        public int GetDamageModifier(Actor attacker, IWarhead warhead)
        {
            var damageWh = warhead as DamageWarhead;

            if (attacker.Owner.IsAlliedWith(self.Owner) && (damageWh != null && damageWh.Damage < 0) && !Info.ModifyHealing)
            {
                return(FullDamage);
            }

            var world = self.World;
            var map   = world.Map;

            var pos         = map.CellContaining(self.CenterPosition);
            var terrainType = map.GetTerrainInfo(pos).Type;

            if (!Info.TerrainModifier.ContainsKey(terrainType))
            {
                return(FullDamage);
            }

            return(Info.TerrainModifier[terrainType]);
        }
Exemple #10
0
        public int GetDamageModifier(Actor attacker, IWarhead warhead)
        {
            int modifier;

            // Not entirely accurate as it uses positions of actors and not warhead.
            // TODO: Use warhead angle if possible?
            int facing = getFacingAngle(self);
            int angleOfAttack = angleBetweenActors(self, attacker);
            if (isFrontalAttack(facing, angleOfAttack))
            {
                modifier = info.FrontalDamageModifier;
            }
            else if (isSideAttack(facing, angleOfAttack))
            {
                modifier = info.SideDamageModifier;
            }
            else
            {
                modifier = info.BackDamageModifier;
            }

            return modifier;
        }
Exemple #11
0
        public void InflictDamage(Actor self, Actor attacker, int damage, IWarhead warhead, bool ignoreModifiers)
        {
            // Overkill! Don't count extra hits as more kills!
            if (IsDead)
            {
                return;
            }

            var oldState = 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 = (hp - damage).Clamp(0, MaxHP);

            var ai = new AttackInfo
            {
                Attacker            = attacker,
                Damage              = damage,
                DamageState         = 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.Dispose();
                }

                if (attacker == null)
                {
                    Log.Write("debug", "{0} #{1} was killed.", self.Info.Name, self.ActorID);
                }
                else
                {
                    Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
                }
            }
        }
Exemple #12
0
 public int GetDamageModifier(Actor attacker, IWarhead warhead)
 {
     return GetModifier();
 }
 public int GetDamageModifier(Actor attacker, IWarhead warhead)
 {
     return(state == PopupState.Closed ? info.ClosedDamageMultiplier : 100);
 }
        public static object Convert(string file, TextNode node, Type t)
        {
            var value = node.Value;

            if (t.IsEnum)
            {
                object @enum;
                try
                {
                    @enum = Enum.Parse(t, value.Trim(), true);
                }
                catch (Exception e)
                {
                    throw new InvalidEnumConversionException(file, node, t, e);
                }
                return(@enum);
            }
            else if (t == typeof(int))
            {
                if (int.TryParse(value, out var i))
                {
                    return(i);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            if (t == typeof(uint))
            {
                if (uint.TryParse(value, out var i))
                {
                    return(i);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            else if (t == typeof(byte))
            {
                if (byte.TryParse(value, out var i))
                {
                    return(i);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            else if (t == typeof(short))
            {
                if (short.TryParse(value, out var i))
                {
                    return(i);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            else if (t == typeof(float))
            {
                if (float.TryParse(value, out var i))
                {
                    return(i);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            else if (t == typeof(bool))
            {
                var v = value.ToLower().Trim();

                if (trueBooleans.Contains(v))
                {
                    return(true);
                }
                else if (falseBooleans.Contains(v))
                {
                    return(false);
                }
                else
                {
                    throw new InvalidConversionException(file, node, t);
                }
            }
            else if (t == typeof(string))
            {
                return(value.Trim());
            }
            else if (t.IsArray && t.GetElementType().IsEnum)
            {
                var parts = value.Split(',');

                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = parts[i].Trim();
                }

                var elementType = t.GetElementType();
                var enums       = Array.CreateInstance(elementType, parts.Length);
                try
                {
                    for (int i = 0; i < parts.Length; i++)
                    {
                        enums.SetValue(Enum.Parse(elementType, parts[i], true), i);
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidEnumConversionException(file, node, t, e);
                }
                return(enums);
            }
            else if (t == typeof(int[]))
            {
                var parts = value.Split(',');
                var res   = new int[parts.Length];

                for (int i = 0; i < parts.Length; i++)
                {
                    var part = parts[i].Trim();

                    if (int.TryParse(part, out int convert))
                    {
                        res[i] = convert;
                    }
                    else
                    {
                        throw new InvalidConversionException(file, node, t);
                    }
                }

                return(res);
            }
            else if (t == typeof(float[]))
            {
                var parts = value.Split(',');
                var res   = new float[parts.Length];

                for (int i = 0; i < parts.Length; i++)
                {
                    var part = parts[i].Trim();

                    if (float.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out float convert))
                    {
                        res[i] = convert;
                    }
                    else
                    {
                        throw new InvalidConversionException(file, node, t);
                    }
                }

                return(res);
            }
            else if (t == typeof(string[]))
            {
                var parts = value.Split(',');

                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = parts[i].Trim();
                }

                return(parts);
            }
            else if (t == typeof(bool[]))
            {
                var parts = value.Split(',');
                var res   = new bool[parts.Length];

                for (int i = 0; i < parts.Length; i++)
                {
                    var part = parts[i].Trim();

                    if (trueBooleans.Contains(part))
                    {
                        res[i] = true;
                    }
                    else if (falseBooleans.Contains(part))
                    {
                        res[i] = false;
                    }
                    else
                    {
                        throw new InvalidConversionException(file, node, t);
                    }
                }

                return(res);
            }
            else if (t == typeof(ushort[]))
            {
                var parts = value.Split(',');
                var res   = new ushort[parts.Length];

                for (int i = 0; i < parts.Length; i++)
                {
                    var part = parts[i].Trim();

                    if (ushort.TryParse(part, out ushort convert))
                    {
                        res[i] = convert;
                    }
                    else
                    {
                        throw new InvalidConversionException(file, node, t);
                    }
                }

                return(res);
            }
            else if (t == typeof(short[]))
            {
                var parts = value.Split(',');
                var res   = new short[parts.Length];

                for (int i = 0; i < parts.Length; i++)
                {
                    var part = parts[i].Trim();

                    if (short.TryParse(part, out short convert))
                    {
                        res[i] = convert;
                    }
                    else
                    {
                        throw new InvalidConversionException(file, node, t);
                    }
                }

                return(res);
            }
            else if (t == typeof(MPos))
            {
                var parts = value.Split(',');

                if (parts.Length == 2)
                {
                    if (int.TryParse(parts[0], out int x) && int.TryParse(parts[1], out int y))
                    {
                        return(new MPos(x, y));
                    }
                }
            }
            else if (t == typeof(CPos))
            {
                var parts = value.Split(',');

                if (parts.Length == 3)
                {
                    if (int.TryParse(parts[0], out int x) && int.TryParse(parts[1], out int y) && int.TryParse(parts[2], out int z))
                    {
                        return(new CPos(x, y, z));
                    }
                }
            }
            else if (t == typeof(Color))
            {
                var parts = value.Split(',');

                if (parts.Length >= 3 && parts.Length <= 4)
                {
                    if (int.TryParse(parts[0], out int r) && int.TryParse(parts[1], out int g) && int.TryParse(parts[2], out int b))
                    {
                        var a = 255;
                        if (parts.Length == 4 && int.TryParse(parts[3], out a) || parts.Length == 3)
                        {
                            return(new Color(r, g, b, a));
                        }
                    }
                }
            }
            else if (t == typeof(Vector))
            {
                var parts = value.Split(',');

                if (parts.Length == 3)
                {
                    if (float.TryParse(parts[0], out float x) && float.TryParse(parts[1], out float y) && float.TryParse(parts[2], out float z))
                    {
                        return(new Vector(x, y, z));
                    }
                }
            }
            else if (t == typeof(VAngle))
            {
                var parts = value.Split(',');

                if (parts.Length == 3)
                {
                    if (float.TryParse(parts[0], out float x) && float.TryParse(parts[1], out float y) && float.TryParse(parts[2], out float z))
                    {
                        return(new VAngle(x, y, z));
                    }
                }
            }
            else if (t == typeof(SoundType))
            {
                return(new SoundType(node.Children));
            }
            else if (t == typeof(Condition))
            {
                return(new Condition(node.Value));
            }
            else if (t == typeof(ParticleSpawner))
            {
                var type = Type.GetType("WarriorsSnuggery.Objects.Particles." + value.Trim() + "ParticleSpawner", false, true);

                if (type == null || type.IsInterface)
                {
                    throw new InvalidConversionException(file, node, t);
                }

                return(Activator.CreateInstance(type, new[] { node.Children }));
            }
            else if (t == typeof(TextureInfo))
            {
                var  size          = MPos.Zero;
                var  name          = value.Trim();
                var  randomTexture = false;
                var  tick          = 20;
                bool searchFile    = true;

                var children = node.Children;
                foreach (var child in children)
                {
                    switch (child.Key)
                    {
                    case "AddDirectory":
                        searchFile = child.Convert <bool>();
                        break;

                    case "Random":
                        randomTexture = child.Convert <bool>();
                        break;

                    case "Tick":
                        tick = child.Convert <int>();
                        break;

                    case "Size":
                        size = child.Convert <MPos>();
                        break;

                    default:
                        throw new UnexpectedConversionChild(file, node, t, child.Key);
                    }
                }

                if (size != MPos.Zero)
                {
                    return(new TextureInfo(name, randomTexture ? TextureType.RANDOM : TextureType.ANIMATION, size, tick, searchFile));
                }
            }
            else if (t == typeof(WeaponType))
            {
                return(WeaponCache.Types[value.Trim()]);
            }
            else if (t == typeof(ParticleType))
            {
                return(ParticleCache.Types[value.Trim()]);
            }
            else if (t == typeof(ActorType))
            {
                return(ActorCache.Types[value.Trim()]);
            }
            else if (t == typeof(SimplePhysicsType))
            {
                return(new SimplePhysicsType(node.Children));
            }
            else if (t == typeof(Spell))
            {
                if (!SpellCache.Types.ContainsKey(value))
                {
                    throw new MissingInfoException(value);
                }

                return(SpellCache.Types[value.Trim()]);
            }
            else if (t == typeof(Effect))
            {
                return(new Effect(node.Children));
            }
            else if (t == typeof(BotBehaviorType))
            {
                var type = Type.GetType("WarriorsSnuggery.Objects.Actors.Bot." + value.Trim() + "BotBehaviorType", false, true);

                if (type == null || type.IsInterface)
                {
                    throw new InvalidConversionException(file, node, t);
                }

                return(Activator.CreateInstance(type, new[] { node.Children }));
            }
            else if (t == typeof(IProjectile))
            {
                var type = Type.GetType("WarriorsSnuggery.Objects.Weapons.Projectiles." + value.Trim() + "Projectile", false, true);

                if (type == null || type.IsInterface)
                {
                    throw new InvalidConversionException(file, node, t);
                }

                return(Activator.CreateInstance(type, new[] { node.Children }));
            }
            else if (t == typeof(IWarhead[]))
            {
                var array = new IWarhead[node.Children.Count];
                var i     = 0;
                foreach (var child in node.Children)
                {
                    var type = Type.GetType("WarriorsSnuggery.Objects.Weapons.Warheads." + child.Key + "Warhead", false, true);

                    if (type == null || type.IsInterface)
                    {
                        throw new InvalidConversionException(file, child, t);
                    }

                    array[i++] = (IWarhead)Activator.CreateInstance(type, new[] { child.Children });
                }
                return(array);
            }
            else if (t == typeof(IMapGeneratorInfo[]))
            {
                var array = new IMapGeneratorInfo[node.Children.Count];
                var i     = 0;
                foreach (var child in node.Children)
                {
                    var type = Type.GetType("WarriorsSnuggery.Maps.Generators." + child.Key + "Info", true, true);

                    array[i++] = (IMapGeneratorInfo)Activator.CreateInstance(type, new object[] { child.Convert <int>(), child.Children });
                }
                return(array);
            }
            else if (t == typeof(ActorProbabilityInfo[]))
            {
                var convert = new ActorProbabilityInfo[node.Children.Count];

                for (int i = 0; i < node.Children.Count; i++)
                {
                    convert[i] = new ActorProbabilityInfo(node.Children[i].Children);
                }

                return(convert);
            }
            else if (t == typeof(PatrolProbabilityInfo[]))
            {
                var convert = new PatrolProbabilityInfo[node.Children.Count];

                for (int i = 0; i < node.Children.Count; i++)
                {
                    convert[i] = new PatrolProbabilityInfo(node.Children[i].Children);
                }

                return(convert);
            }
            else if (t == typeof(ParticleType[]))
            {
                var convert = new ParticleType[node.Children.Count];

                for (int i = 0; i < node.Children.Count; i++)
                {
                    if (!ParticleCache.Types.ContainsKey(value))
                    {
                        throw new MissingInfoException(value);
                    }

                    convert[i] = ParticleCache.Types[value.Trim()];
                }

                return(convert);
            }
            else if (t == typeof(ParticleSpawner[]))
            {
                var convert = new ParticleSpawner[node.Children.Count];

                for (int i = 0; i < node.Children.Count; i++)
                {
                    convert[i] = Convert <ParticleSpawner>(file, node.Children[i]);
                }

                return(convert);
            }

            throw new InvalidConversionException(file, node, t);
        }
Exemple #15
0
 public int GetDamageModifier(Actor attacker, IWarhead warhead)
 {
     return(GetModifier());
 }
Exemple #16
0
        public static void InflictDamage(this Actor self, Actor attacker, int damage, IWarhead warhead)
        {
            if (self.Disposed)
            {
                return;
            }
            var health = self.TraitOrDefault <Health>();

            if (health == null)
            {
                return;
            }
            health.InflictDamage(self, attacker, damage, warhead, false);
        }