Example #1
0
        public IEnumerable <LogMessage> GetErrors(IMobileSpaceObject executor, IRecyclable target)
        {
            if (target == null)
            {
                yield return(new GenericLogMessage("A scrap order was issued for a nonexistent target."));

                yield break;
            }
            if (target.IsDisposed)
            {
                yield return(target.CreateLogMessage($"{target} cannot be scrapped because it is already destroyed."));
            }
            if (target.RecycleContainer != executor)
            {
                yield return(target.CreateLogMessage(target + " cannot be scrapped by " + executor + " because " + target + " does not belong to " + executor + "."));
            }
            if ((target is Ship || target is Base) && !executor.Sector.SpaceObjects.Any(sobj => sobj.Owner == executor.Owner && sobj.HasAbility("Space Yard")))
            {
                yield return(target.CreateLogMessage(target + " cannot be scrapped at " + executor.Sector + " because there is no space yard present in that sector."));
            }
            if ((target is IUnit) && !executor.Sector.SpaceObjects.Any(sobj => sobj.Owner == executor.Owner && (sobj is Planet || sobj.HasAbility("Space Yard"))))
            {
                yield return(target.CreateLogMessage(target + " cannot be scrapped at " + executor.Sector + " because there is no space yard or colony present in that sector."));
            }
        }
Example #2
0
        public void Execute(IRecyclable target, bool didRecycle = false)
        {
            // don't scrap stuff that's already been scrapped due to it being in cargo of something else being scrapped!
            if (!target.IsDisposed)
            {
                var val = target.ScrapValue;
                if (target.Owner != null)                 // if not, it's already scrapped?
                {
                    target.Owner.StoredResources += val;
                    target.Owner.Log.Add(target.CreateLogMessage("We have scrapped " + target + " and reclaimed " + val + "."));
                }
                target.Dispose();

                if (!didRecycle)
                {
                    target.Recycle(this, true);
                }
            }
        }