Beispiel #1
0
 public static double GetDefaultEffect(AugmentorType AttachedType)
 {
     if (AttachedType == AugmentorType.Output)
     {
         return(1.0);
     }
     else if (AttachedType == AugmentorType.Speed)
     {
         return(1.0);
     }
     else if (AttachedType == AugmentorType.Efficiency)
     {
         return(1.0);
     }
     else if (AttachedType == AugmentorType.Quality)
     {
         return(0.0);
     }
     else if (AttachedType == AugmentorType.Production)
     {
         return(1.0);
     }
     else if (AttachedType == AugmentorType.Duplication)
     {
         return(0.0);
     }
     else
     {
         throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", AttachedType.ToString()));
     }
 }
Beispiel #2
0
 public static double ComputeEffect(AugmentorType AttachedType, int AttachedQuantity, bool RequiresInput, int ProcessingTime = 60)
 {
     if (AttachedType == AugmentorType.Output)
     {
         return(OutputAugmentor.ComputeEffect(AttachedQuantity, RequiresInput));
     }
     else if (AttachedType == AugmentorType.Speed)
     {
         return(SpeedAugmentor.ComputeEffect(AttachedQuantity, RequiresInput));
     }
     else if (AttachedType == AugmentorType.Efficiency)
     {
         return(EfficiencyAugmentor.ComputeEffect(AttachedQuantity, RequiresInput));
     }
     else if (AttachedType == AugmentorType.Quality)
     {
         return(QualityAugmentor.ComputeEffect(AttachedQuantity, RequiresInput));
     }
     else if (AttachedType == AugmentorType.Production)
     {
         return(ProductionAugmentor.ComputeEffect(AttachedQuantity, RequiresInput));
     }
     else if (AttachedType == AugmentorType.Duplication)
     {
         return(DuplicationAugmentor.ComputeEffect(AttachedQuantity, RequiresInput, ProcessingTime));
     }
     else
     {
         throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", AttachedType.ToString()));
     }
 }
        internal void Update()
        {
            //  Check if the Machine has been removed from this tile
            if (!Location.Location.Objects.TryGetValue(new Vector2(Position.X, Position.Y), out Object CurrentMachine) || CurrentMachine != Machine)
            {
                Location.OnMachineRemoved(this);
                return;
            }

            try
            {
                if (!Context.IsMultiplayer || Context.IsMainPlayer)
                {
                    if (PreviousMachineState != null)
                    {
                        if (PreviousMachineState.PreviousMinutesUntilReady <= 0 && PreviousMachineState.CurrentMinutesUntilReady > 0)
                        {
                            foreach (KeyValuePair <AugmentorType, int> KVP in PlacedAugmentorsManager.GetOrderedEnumerable(Quantities))
                            {
                                AugmentorType Type             = KVP.Key;
                                int           AttachedQuantity = KVP.Value;

                                if (AttachedQuantity > 0)
                                {
                                    if (Type == AugmentorType.Output)
                                    {
                                        OutputAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else if (Type == AugmentorType.Speed)
                                    {
                                        SpeedAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else if (Type == AugmentorType.Efficiency)
                                    {
                                        EfficiencyAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else if (Type == AugmentorType.Quality)
                                    {
                                        QualityAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else if (Type == AugmentorType.Production)
                                    {
                                        ProductionAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else if (Type == AugmentorType.Duplication)
                                    {
                                        DuplicationAugmentor.OnMinutesUntilReadySet(PreviousMachineState, AttachedQuantity);
                                    }
                                    else
                                    {
                                        throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", Type.ToString()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally { PreviousMachineState = new MachineState(this.Machine); }
        }
Beispiel #4
0
        public SerializableAugmentedTile(AugmentedTile CopyFrom)
        {
            InitializeDefaults();

            if (CopyFrom != null)
            {
                this.TileXPosition = CopyFrom.Position.X;
                this.TileYPosition = CopyFrom.Position.Y;

                List <AugmentorType> TempTypes      = new List <AugmentorType>();
                List <int>           TempQuantities = new List <int>();
                foreach (KeyValuePair <AugmentorType, int> KVP in CopyFrom.Quantities)
                {
                    AugmentorType Type     = KVP.Key;
                    int           Quantity = KVP.Value;
                    if (Quantity > 0)
                    {
                        TempTypes.Add(Type);
                        TempQuantities.Add(Quantity);
                    }
                }

                this.AugmentorTypes      = TempTypes.ToArray();
                this.AugmentorQuantities = TempQuantities.ToArray();
            }
        }
Beispiel #5
0
 public static bool TryGetIconDetails(AugmentorType Type, out Texture2D SourceTexture, out Rectangle SourceRect, out float BaseScale, out SpriteEffects Effects)
 {
     if (Type == AugmentorType.Output)
     {
         SourceTexture = TextureHelpers.EmojiSpritesheet;
         SourceRect    = new Rectangle(55, 90, 7, 9); // Lightbulb
         BaseScale     = 3f;
         Effects       = SpriteEffects.None;
         return(true);
     }
     else if (Type == AugmentorType.Speed)
     {
         SourceTexture = Game1.mouseCursors;
         SourceRect    = new Rectangle(410, 501, 9, 9); // Clock
         BaseScale     = 3f;
         Effects       = SpriteEffects.None;
         return(true);
     }
     else if (Type == AugmentorType.Efficiency)
     {
         SourceTexture = Game1.mouseCursors;
         SourceRect    = new Rectangle(80, 428, 10, 10); // E^
         BaseScale     = 3f;
         Effects       = SpriteEffects.None;
         return(true);
     }
     else if (Type == AugmentorType.Quality)
     {
         SourceTexture = TextureHelpers.PlayerStatusList;
         SourceRect    = new Rectangle(16, 48, 16, 16); // Star
         BaseScale     = 2f;
         Effects       = SpriteEffects.None;
         return(true);
     }
     else if (Type == AugmentorType.Production)
     {
         SourceTexture = Game1.mouseCursors;
         SourceRect    = new Rectangle(130, 430, 10, 7); // Weapon speed icon
         BaseScale     = 3f;
         Effects       = SpriteEffects.FlipHorizontally;
         return(true);
     }
     else if (Type == AugmentorType.Duplication)
     {
         SourceTexture = Game1.mouseCursors;
         SourceRect    = new Rectangle(395, 497, 6, 8); // Blue/Yellow exclamation marks
         BaseScale     = 4f;
         Effects       = SpriteEffects.None;
         return(true);
     }
     else
     {
         SourceTexture = null;
         SourceRect    = new Rectangle();
         BaseScale     = 1f;
         Effects       = SpriteEffects.None;
         return(false);
     }
 }
Beispiel #6
0
 public static void DrawIcon(SpriteBatch SB, AugmentorType Type, Vector2 PrimaryIconBottomLeft, float BaseScale, float Transparency, float LayerDepth)
 {
     if (TryGetIconDetails(Type, out Texture2D Texture, out Rectangle SourceRect, out float IconScale, out SpriteEffects Effects))
     {
         Vector2 Destination = PrimaryIconBottomLeft + new Vector2(4f * BaseScale, -4f * BaseScale - SourceRect.Height * IconScale * BaseScale);
         SB.Draw(Texture, Destination, SourceRect, Color.White * Transparency, 0f, new Vector2(0, 0), BaseScale * IconScale, Effects, LayerDepth);
     }
 }
        public PlacedAugmentorsManager()
        {
            this.Locations = new Dictionary <string, AugmentedLocation>();

            try
            {
                if (!Context.IsMultiplayer || Context.IsMainPlayer)
                {
                    //  Load data from save file
                    SerializablePlacedAugmentors SavedData = MachineAugmentorsMod.ModInstance.Helper.Data.ReadSaveData <SerializablePlacedAugmentors>(SavedDataKey);
                    if (SavedData != null)
                    {
                        foreach (SerializableAugmentedLocation SavedLocation in SavedData.Locations)
                        {
                            string       LocationName = SavedLocation.UniqueLocationName;
                            GameLocation GL           = Game1.getLocationFromName(LocationName);
                            if (GL == null)
                            {
                                MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Warning - Could not find a GameLocation named '{0}'. Some of your augmentors may not have been loaded from your save file!", LocationName), LogLevel.Warn);
                            }
                            else
                            {
                                AugmentedLocation AL = new AugmentedLocation(this, LocationName);
                                Locations.Add(LocationName, AL);

                                foreach (SerializableAugmentedTile SavedTile in SavedLocation.Tiles)
                                {
                                    if (!GL.Objects.TryGetValue(new Vector2(SavedTile.TileXPosition, SavedTile.TileYPosition), out Object Item))
                                    {
                                        string Warning = string.Format("Warning - GameLocation '{0}' does not have a machine at ({1},{2}). Some of your augmentors may not have been loaded from your save file!",
                                                                       LocationName, SavedTile.TileXPosition, SavedTile.TileYPosition);
                                        MachineAugmentorsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn);
                                    }
                                    else
                                    {
                                        AugmentedTile AT = new AugmentedTile(AL, SavedTile.TileXPosition, SavedTile.TileYPosition);
                                        AL.Tiles.Add(AugmentedLocation.EncodeTileToString(SavedTile.TileXPosition, SavedTile.TileYPosition), AT);

                                        for (int i = 0; i < SavedTile.AugmentorTypes.Length; i++)
                                        {
                                            AugmentorType Type     = SavedTile.AugmentorTypes[i];
                                            int           Quantity = SavedTile.AugmentorQuantities[i];
                                            AT.Quantities.Add(Type, Quantity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MachineAugmentorsMod.ModInstance.Monitor.Log("Error while loading augmentor data from ReadSaveData: " + ex, LogLevel.Error);
            }
        }
Beispiel #8
0
        //TODO Multiplayer support -
        //1. When a farmhand connects to host, host client has to send them a json string of the augmentor data.
        //(new SerializablePlacedAugmentors(PlacedAugmentorsManager.Instance) ) ----- convert to a Json string
        //when the farmhand receives it, deserialize back to a SerializablePlacedAugmentors, then call PlacedAugmentorsManager.Instance.LoadSettings(...)
        //2. When a client (host or farmhand) places an augmentor, need to send info about what they placed, quantity, gamelocation, tile location to all other clients
        //so the other clients can update their PlacedAugmentorsManager.Instance data.

        internal static void LogTrace(AugmentorType Type, int Quantity, Object Machine, bool RequiresInput, Vector2 Position, string PropertyName, double PreviousValue, double NewValueBeforeRounding, double NewValue, double Modifier)
        {
#if DEBUG
            LogLevel LogLevel = LogLevel.Debug;
#else
            LogLevel LogLevel = LogLevel.Trace;
#endif
            ModInstance.Monitor.Log(string.Format("MachineAugmentors: {0} ({1}) - Modified {2}{3} at ({4},{5}) - Changed {6} from {7} to {8} ({9}% / Desired Value = {10})",
                                                  Type.ToString(), Quantity, Machine.DisplayName, RequiresInput ? "" : " (Inputless)", Position.X, Position.Y, PropertyName, PreviousValue, NewValue, (Modifier * 100.0).ToString("0.##"), NewValueBeforeRounding), LogLevel);
        }
        public void OnAugmentorPlaced(string UniqueLocationName, AugmentorType Type, int Qty, bool RemoveFromInventory, int TileX, int TileY, Augmentor Instance = null)
        {
            if (!Locations.TryGetValue(UniqueLocationName, out AugmentedLocation Location))
            {
                Location = new AugmentedLocation(this, UniqueLocationName);
                Locations.Add(UniqueLocationName, Location);
            }

            Location.OnAugmentorPlaced(Type, Qty, RemoveFromInventory, TileX, TileY, Instance);
        }
Beispiel #10
0
 public static Augmentor CreateInstance(AugmentorType Type, int Quantity = 1)
 {
     if (Type == AugmentorType.Output)
     {
         return new OutputAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else if (Type == AugmentorType.Speed)
     {
         return new SpeedAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else if (Type == AugmentorType.Efficiency)
     {
         return new EfficiencyAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else if (Type == AugmentorType.Quality)
     {
         return new QualityAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else if (Type == AugmentorType.Production)
     {
         return new ProductionAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else if (Type == AugmentorType.Duplication)
     {
         return new DuplicationAugmentor()
                {
                    Stack = Quantity
                }
     }
     ;
     else
     {
         throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", Type.ToString()));
     }
 }
        internal void OnAugmentorPlaced(AugmentorType Type, int Qty, bool RemoveFromInventory, int TileX, int TileY, Augmentor Instance = null)
        {
            string Key = EncodeTileToString(TileX, TileY);

            if (!Tiles.TryGetValue(Key, out AugmentedTile Tile))
            {
                Tile = new AugmentedTile(this, TileX, TileY);
                Tiles.Add(Key, Tile);
            }

            Tile.OnAugmentorPlaced(Type, Qty, RemoveFromInventory, Instance);
        }
        internal void OnProductsCollected(CheckForActionData CFAData)
        {
            if (!CFAData.IsLocalPlayer)
            {
                return;
            }

            if (CFAData.CurrentHeldObject != null)
            {
                //  This point of the code should be reached when collecting from a machine that does not require inputs
                //  such as when collecting from a Bee Hive / Crystalarium / Tapper, a new product is automatically placed back into the machine and the MinutesUntilReady gets reset
                if (TryFindAugmentedTile(CFAData.Machine, CFAData.Machine.TileLocation, out AugmentedTile AT))
                {
                    foreach (KeyValuePair <AugmentorType, int> KVP in GetOrderedEnumerable(AT.Quantities))
                    {
                        AugmentorType Type             = KVP.Key;
                        int           AttachedQuantity = KVP.Value;

                        if (AttachedQuantity > 0)
                        {
                            if (Type == AugmentorType.Output)
                            {
                                OutputAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else if (Type == AugmentorType.Speed)
                            {
                                SpeedAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else if (Type == AugmentorType.Efficiency)
                            {
                                EfficiencyAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else if (Type == AugmentorType.Quality)
                            {
                                QualityAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else if (Type == AugmentorType.Production)
                            {
                                ProductionAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else if (Type == AugmentorType.Duplication)
                            {
                                DuplicationAugmentor.OnProductsCollected(CFAData, AttachedQuantity);
                            }
                            else
                            {
                                throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", Type.ToString()));
                            }
                        }
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>Draws the Augmentor textures on the given tile of the game world</summary>
        public static void DrawOnTile(SpriteBatch b, AugmentorType Type, int TileX, int TileY, float Scale)
        {
            float draw_layer      = GetTileDrawLayerDepth(TileX, TileY);
            float DrawLayerOffset = 1E-05f; // The SpriteBatch LayerDepth needs to be slightly larger than the layer depth used for the bigCraftable texture, because if they're equal, the textures will flicker, changing order every few game ticks at random

            Vector2 Position = Game1.GlobalToLocal(Game1.viewport, new Vector2(TileX * Game1.tileSize, TileY * Game1.tileSize));

            b.Draw(Game1.mouseCursors, Position, GetPrimaryIconSourceRect(2), Color.White, 0f, Vector2.Zero, 4f * Scale, SpriteEffects.None, draw_layer + DrawLayerOffset);

            Vector2 BottomLeftPosition = new Vector2(Position.X, Position.Y + 64f * Scale);

            DrawIcon(b, Type, BottomLeftPosition, Scale, 1f, draw_layer + DrawLayerOffset + 1E-04f);
        }
        internal void OnInputsInserted(PerformObjectDropInData PODIData)
        {
            if (!PODIData.IsLocalPlayer)
            {
                return;
            }

            //  This point of the code should be reached when placing an input item into a machine that requires inputs,
            //  such as when placing Copper Ore into a furnace
            if (TryFindAugmentedTile(PODIData.Machine, PODIData.Machine.TileLocation, out AugmentedTile AT))
            {
                foreach (KeyValuePair <AugmentorType, int> KVP in GetOrderedEnumerable(AT.Quantities))
                {
                    AugmentorType Type             = KVP.Key;
                    int           AttachedQuantity = KVP.Value;

                    if (AttachedQuantity > 0)
                    {
                        if (Type == AugmentorType.Output)
                        {
                            OutputAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else if (Type == AugmentorType.Speed)
                        {
                            SpeedAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else if (Type == AugmentorType.Efficiency)
                        {
                            EfficiencyAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else if (Type == AugmentorType.Quality)
                        {
                            QualityAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else if (Type == AugmentorType.Production)
                        {
                            ProductionAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else if (Type == AugmentorType.Duplication)
                        {
                            DuplicationAugmentor.OnInputsInserted(PODIData, AttachedQuantity);
                        }
                        else
                        {
                            throw new NotImplementedException(string.Format("Unrecognized AugmentorType: {0}", Type.ToString()));
                        }
                    }
                }
            }
        }
Beispiel #15
0
        public static void MonsterDrop_Postfix(GameLocation __instance, Monster monster, int x, int y, Farmer who)
        {
            try
            {
                if (who == Game1.player)
                {
                    //  Make the monster drop an augmentor if you're lucky
                    double Chance = MachineAugmentorsMod.UserConfig.MonsterLootSettings.GetAugmentorDropChance(__instance, monster,
                                                                                                               out double BaseChance, out double LocationMultiplier, out double ExpMultiplier, out double HPMultiplier);
                    bool   Success = Augmentor.Randomizer.NextDouble() <= Chance;
                    string LogMessage;
                    if (Success)
                    {
                        int           SpawnDirection = Augmentor.Randomizer.Next(4);
                        int           NumTypes       = Enum.GetValues(typeof(AugmentorType)).Length;
                        AugmentorType Type           = (AugmentorType)Augmentor.Randomizer.Next(NumTypes);
                        int           Quantity       = Augmentor.RollDice(0.1) ? 2 : 1;
                        Game1.createItemDebris(Augmentor.CreateInstance(Type, Quantity), Game1.player.getStandingPosition(), SpawnDirection, null, -1);

                        LogMessage = string.Format("Succeeded drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n"
                                                   + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)",
                                                   __instance.Name, monster.ExperienceGained, monster.MaxHealth,
                                                   BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"),
                                                   ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###"));
                    }
                    else
                    {
                        LogMessage = string.Format("Failed drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n"
                                                   + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)",
                                                   __instance.Name, monster.ExperienceGained, monster.MaxHealth,
                                                   BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"),
                                                   ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###"));
                    }
#if DEBUG
                    MachineAugmentorsMod.ModInstance.Monitor.Log(LogMessage, LogLevel.Debug);
#else
                    MachineAugmentorsMod.ModInstance.Monitor.Log(LogMessage, LogLevel.Trace);
#endif
                }
            }
            catch (Exception ex)
            {
                MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Unhandled Error in {0}:\n{1}", nameof(MonsterDrop_Postfix), ex), LogLevel.Error);
            }
        }
        internal void LoadSettings(SerializablePlacedAugmentors Data)
        {
            if (Data != null)
            {
                foreach (SerializableAugmentedLocation SavedLocation in Data.Locations)
                {
                    string       LocationName = SavedLocation.UniqueLocationName;
                    GameLocation GL           = Game1.getLocationFromName(LocationName);
                    if (GL == null)
                    {
                        MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Warning - Could not find a GameLocation named '{0}'. Some of your augmentors may not have been loaded from your save file!", LocationName), LogLevel.Warn);
                    }
                    else
                    {
                        AugmentedLocation AL = new AugmentedLocation(this, LocationName);
                        Locations.Add(LocationName, AL);

                        foreach (SerializableAugmentedTile SavedTile in SavedLocation.Tiles)
                        {
                            if (!GL.Objects.TryGetValue(new Vector2(SavedTile.TileXPosition, SavedTile.TileYPosition), out Object Item))
                            {
                                string Warning = string.Format("Warning - GameLocation '{0}' does not have a machine at ({1},{2}). Some of your augmentors may not have been loaded from your save file!",
                                                               LocationName, SavedTile.TileXPosition, SavedTile.TileYPosition);
                                MachineAugmentorsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn);
                            }
                            else
                            {
                                AugmentedTile AT = new AugmentedTile(AL, SavedTile.TileXPosition, SavedTile.TileYPosition);
                                AL.Tiles.Add(AugmentedLocation.EncodeTileToString(SavedTile.TileXPosition, SavedTile.TileYPosition), AT);

                                for (int i = 0; i < SavedTile.AugmentorTypes.Length; i++)
                                {
                                    AugmentorType Type     = SavedTile.AugmentorTypes[i];
                                    int           Quantity = SavedTile.AugmentorQuantities[i];
                                    AT.Quantities.Add(Type, Quantity);
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <param name="RemoveFromInventory">True if the given <paramref name="Qty"/> should be removed from the player's inventory.</param>
        /// <param name="Instance">If <paramref name="RemoveFromInventory"/>=true, this Instance's Stack will be reduced. If not specified, the first instance found in the player's inventory will be reduced.</param>
        internal void OnAugmentorPlaced(AugmentorType Type, int Qty, bool RemoveFromInventory, Augmentor Instance = null)
        {
            int MaxQuantity = MachineAugmentorsMod.UserConfig.GetConfig(Type).MaxAttachmentsPerMachine;
            int CurrentQty  = 0;

            Quantities.TryGetValue(Type, out CurrentQty);
            int ActualQtyPlaced = Math.Max(0, Math.Min(MaxQuantity - CurrentQty, Qty));

            if (ActualQtyPlaced <= 0)
            {
                return;
            }

            if (Quantities.ContainsKey(Type))
            {
                Quantities[Type] += ActualQtyPlaced;
            }
            else
            {
                Quantities.Add(Type, ActualQtyPlaced);
            }

            if (RemoveFromInventory)
            {
                int PendingRemoval = ActualQtyPlaced;
                if (Instance != null && Game1.player.Items.Contains(Instance))
                {
                    int Amt = Math.Min(Instance.Stack, PendingRemoval);
                    if (Amt == Instance.Stack)
                    {
                        Game1.player.Items[Game1.player.Items.IndexOf(Instance)] = null;
                    }
                    else
                    {
                        Instance.Stack -= Amt;
                    }
                }
                else
                {
                    for (int i = 0; i < Game1.player.Items.Count; i++)
                    {
                        Item Item = Game1.player.Items[i];
                        if (Item != null && Item is Augmentor Augmentor && Augmentor.AugmentorType == Type)
                        {
                            int Amt = Math.Min(Augmentor.Stack, PendingRemoval);
                            if (Amt == Augmentor.Stack)
                            {
                                Game1.player.Items[i] = null;
                            }
                            else
                            {
                                Item.Stack -= Amt;
                            }

                            PendingRemoval -= Amt;
                            if (PendingRemoval <= 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
 internal void OnAugmentorPlaced(AugmentorType Type, int Qty, bool RemoveFromInventory, Vector2 Tile, Augmentor Instance = null)
 {
     OnAugmentorPlaced(Type, Qty, RemoveFromInventory, (int)Tile.X, (int)Tile.Y, Instance);
 }
 public void OnAugmentorPlaced(string UniqueLocationName, AugmentorType Type, int Qty, bool RemoveFromInventory, Vector2 Tile, Augmentor Instance = null)
 {
     OnAugmentorPlaced(UniqueLocationName, Type, Qty, RemoveFromInventory, (int)Tile.X, (int)Tile.Y, Instance);
 }
Beispiel #20
0
 public AugmentorConfig GetConfig(AugmentorType Type)
 {
     return(IndexedConfigs[Type]);
 }
Beispiel #21
0
 protected Augmentor(AugmentorType Type)
     : base(22763 + (int)Type, 1, false, -1, 0)
 {
     this.AugmentorType = Type;
 }