Esempio n. 1
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);
        }
        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); }
        }
        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()));
                        }
                    }
                }
            }
        }
        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()));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
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()));
     }
 }
Esempio n. 6
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()));
     }
 }
Esempio n. 7
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()));
     }
 }