Beispiel #1
0
        internal bool ReserveSpace(Actor a)
        {
            if (reserves.Contains(a))
            {
                return(true);
            }

            var w = GetWeight(a);

            if (!HasSpace(w))
            {
                return(false);
            }

            if (reserves.Count == 0)
            {
                foreach (var u in Info.LoadingUpgrades)
                {
                    upgradeManager.GrantUpgrade(self, u, this);
                }
            }

            reserves.Add(a);
            reservedWeight += w;

            return(true);
        }
Beispiel #2
0
        void OnDeployCompleted()
        {
            foreach (var up in info.DeployedUpgrades)
            {
                manager.GrantUpgrade(self, up, this);
            }

            deployState = DeployState.Deployed;
        }
Beispiel #3
0
 void OnAirborneAltitudeReached()
 {
     if (airborne)
     {
         return;
     }
     airborne = true;
     if (um != null)
     {
         foreach (var u in Info.AirborneUpgrades)
         {
             um.GrantUpgrade(self, u, this);
         }
     }
 }
Beispiel #4
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString != "DeployToUpgrade")
            {
                return;
            }

            if (!OnValidTerrain())
            {
                return;
            }

            if (isUpgraded)
            {
                foreach (var up in info.Upgrades)
                {
                    manager.RevokeUpgrade(self, up, this);
                }
            }
            else
            {
                foreach (var up in info.Upgrades)
                {
                    manager.GrantUpgrade(self, up, this);
                }
            }

            isUpgraded = !isUpgraded;
        }
Beispiel #5
0
        public void Tick(Actor self)
        {
            if (IsTraitDisabled)
            {
                return;
            }

            if (remainingTime > 0 && !IsTraitDisabled && !damageDisabled && --remainingTime <= 0)
            {
                Game.Sound.Play(Info.CloakSound, self.CenterPosition);
                if (upgradeManager != null)
                {
                    foreach (var u in Info.WhileCloakedUpgrades)
                    {
                        upgradeManager.GrantUpgrade(self, u, this);
                    }
                }
            }

            if (self.IsDisabled())
            {
                Uncloak();
            }

            if (Info.UncloakOnMove && (lastPos == null || lastPos.Value != self.Location))
            {
                Uncloak();
                lastPos = self.Location;
            }
        }
        void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
        {
            if (um == null)
            {
                return;
            }

            var rand = Game.CosmeticRandom;

            if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
            {
                granted = true;
                var sound = info.EnabledSounds.RandomOrDefault(rand);
                Game.Sound.Play(sound, self.CenterPosition);
                foreach (var u in info.Upgrades)
                {
                    um.GrantUpgrade(self, u, this);
                }
            }
            else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState))
            {
                granted = false;
                var sound = info.DisabledSounds.RandomOrDefault(rand);
                Game.Sound.Play(sound, self.CenterPosition);
                foreach (var u in info.Upgrades)
                {
                    um.RevokeUpgrade(self, u, this);
                }
            }
        }
        public void Tick(Actor self)
        {
            var currentTerrain = self.World.Map.GetTerrainInfo(self.Location).Type;
            var wantsGranted   = info.TerrainTypes.Contains(currentTerrain);

            if (currentTerrain != previousTerrain)
            {
                if (wantsGranted && !granted)
                {
                    foreach (var up in info.Upgrades)
                    {
                        manager.GrantUpgrade(self, up, this);
                    }

                    granted = true;
                }
                else if (!wantsGranted && granted)
                {
                    foreach (var up in info.Upgrades)
                    {
                        manager.RevokeUpgrade(self, up, this);
                    }

                    granted = false;
                }
            }

            previousTerrain = currentTerrain;
        }
Beispiel #8
0
 void GrantUpgrades(Actor self)
 {
     if (upgradeManager != null)
     {
         foreach (var u in Info.WhileCloakedUpgrades)
         {
             upgradeManager.GrantUpgrade(self, u, this);
         }
     }
 }
Beispiel #9
0
        public virtual void Attached(Actor self)
        {
            if (attached)
            {
                return;
            }

            attached = true;
            foreach (var u in info.CarryableUpgrades)
            {
                upgradeManager.GrantUpgrade(self, u, this);
            }
        }
Beispiel #10
0
        void Lock()
        {
            if (locked)
            {
                return;
            }

            locked = true;
            foreach (var u in info.CarryableUpgrades)
            {
                upgradeManager.GrantUpgrade(self, u, this);
            }
        }
Beispiel #11
0
 public void Created(Actor self)
 {
     upgradeManager = self.TraitOrDefault <UpgradeManager>();
     if (remainingTime == 0)
     {
         if (upgradeManager != null)
         {
             foreach (var u in Info.WhileCloakedUpgrades)
             {
                 upgradeManager.GrantUpgrade(self, u, this);
             }
         }
     }
 }
Beispiel #12
0
        public void EnablePlug(Actor self, string type)
        {
            string[] upgrades;
            if (!Info.Upgrades.TryGetValue(type, out upgrades))
            {
                return;
            }

            foreach (var u in upgrades)
            {
                upgradeManager.GrantUpgrade(self, u, this);
            }

            active = type;
        }
        void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
        {
            if (!info.ValidDamageStates.HasFlag(state))
            {
                return;
            }

            granted = true;
            var rand  = Game.CosmeticRandom;
            var sound = info.EnabledSounds.RandomOrDefault(rand);

            Game.Sound.Play(sound, self.CenterPosition);
            foreach (var u in info.Upgrades)
            {
                um.GrantUpgrade(self, u, this);
            }
        }
Beispiel #14
0
        public void GiveExperience(int amount, bool silent = false)
        {
            experience += amount;

            while (Level < MaxLevel && experience >= nextLevel[Level].First)
            {
                var upgrades = nextLevel[Level].Second;

                Level++;

                foreach (var u in upgrades)
                {
                    um.GrantUpgrade(self, u, this);
                }

                if (!silent)
                {
                    Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", "LevelUp", self.Owner.Faction.InternalName);
                    self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", info.LevelUpPalette)));
                }
            }
        }
        public void SetPrimaryProducer(Actor self, bool state)
        {
            if (state == false)
            {
                IsPrimary = false;
                foreach (var up in info.Upgrades)
                {
                    manager.RevokeUpgrade(self, up, this);
                }
                return;
            }

            // TODO: THIS IS SHIT
            // Cancel existing primaries
            foreach (var p in self.Info.TraitInfo <ProductionInfo>().Produces)
            {
                var productionType = p;                         // benign closure hazard
                foreach (var b in self.World
                         .ActorsWithTrait <PrimaryBuilding>()
                         .Where(a =>
                                a.Actor.Owner == self.Owner &&
                                a.Trait.IsPrimary &&
                                a.Actor.Info.TraitInfo <ProductionInfo>().Produces.Contains(productionType)))
                {
                    b.Trait.SetPrimaryProducer(b.Actor, false);
                }
            }

            IsPrimary = true;
            foreach (var up in info.Upgrades)
            {
                manager.GrantUpgrade(self, up, this);
            }

            Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.SelectionNotification, self.Owner.Faction.InternalName);
        }
Beispiel #16
0
        public void PrerequisitesUpdated(Actor self, bool available)
        {
            if (available == wasAvailable)
            {
                return;
            }

            if (available)
            {
                foreach (var u in info.Upgrades)
                {
                    manager.GrantUpgrade(self, u, this);
                }
            }
            else
            {
                foreach (var u in info.Upgrades)
                {
                    manager.RevokeUpgrade(self, u, this);
                }
            }

            wasAvailable = available;
        }