Пример #1
0
        public CombatShip(StrategyGame game, string imageFilename, int width, int height, Color teamColor, int team, int alliance, float health, int numPilots, EShipType type, int sectorId)
            : base(game, imageFilename, width, height, teamColor, team, alliance, health, numPilots, sectorId)
        {
            Type    = type;
            Weapons = new List <Weapon>();

            TeamPen = new Pen(Colour.AdjustAlpha(StrategyGame.AbilityPenAlpha), StrategyGame.AbilityPenWidth);

            // Prepare the abilities this ship can use, adjusted with the current upgrades
            Abilities = new Dictionary <EAbilityType, Ability>();

            var t        = team - 1;
            var cooldown = game.TechTree[t].ResearchedUpgrades[EGlobalUpgrade.AbilityCooldown];
            var duration = game.TechTree[t].ResearchedUpgrades[EGlobalUpgrade.AbilityDuration];
            var effect   = game.TechTree[t].ResearchedUpgrades[EGlobalUpgrade.AbilityEffect];

            foreach (var at in game.GetEnabledAbilities(team, type))
            {
                var ad = game.AbilityData[at];
                var ab = new Ability(at, cooldown * ad.CooldownDuration, effect * ad.AbilityEffectMultiplier, duration * ad.AbilityDuration);
                Abilities.Add(at, ab);

                if (at == EAbilityType.WeaponBoost)
                {
                    _boostWeaponsAmount = ab.AbilityEffectMultiplier;
                }

                // Setup what happens to this ship when the ability is triggered & completes
                // (Rapid Fire, Weapon Boost, Engine Boost are handled while active, not toggled on/off)

                if (at == EAbilityType.EngineBoost)
                {
                    ab.AbilityStarted += (Ability a) =>
                    {
                        Speed *= a.AbilityEffectMultiplier;
                    };
                    ab.AbilityFinished += (Ability a) =>
                    {
                        Speed /= a.AbilityEffectMultiplier;
                    };
                }
                else if (at == EAbilityType.ShieldBoost)
                {
                    ab.AbilityStarted += (Ability a) =>
                    {
                        Shield += MaxShield * (a.AbilityEffectMultiplier - 1);
                        if (Shield > MaxShield)
                        {
                            Shield = MaxShield;
                        }
                    };
                }
                else if (at == EAbilityType.ScanBoost)
                {
                    ab.AbilityStarted += (Ability a) =>
                    {
                        ScanRange *= a.AbilityEffectMultiplier;
                    };
                    ab.AbilityFinished += (Ability a) =>
                    {
                        ScanRange /= a.AbilityEffectMultiplier;
                    };
                }
                else if (at == EAbilityType.StealthBoost)
                {
                    ab.AbilityStarted += (Ability a) =>
                    {
                        Signature /= a.AbilityEffectMultiplier;
                    };
                    ab.AbilityFinished += (Ability a) =>
                    {
                        Signature *= a.AbilityEffectMultiplier;
                    };
                }
            }
        }