Beispiel #1
0
        public bool FillLiquidContainer(IWIBase liquidContainer, IWIBase foodStuff, WIStack foodStuffStack)
        {
            if (!foodStuff.Is <FoodStuff>())
            {
                //nope! can't do it
                return(false);
            }

            System.Object fssObject = null;
            //check the foodstuff first since it has to be liquid
            if (foodStuff.GetStateOf <FoodStuff>(out fssObject))
            {
                FoodStuffState fss = (FoodStuffState)fssObject;
                if (fss.IsLiquid(foodStuff.State))
                {
                    //okay we've confirmed it's a liquid
                    //now see if the liquid container can hold it
                    if (!liquidContainer.Is <LiquidContainer>())
                    {
                        //we're returning true because it'll make the correct noise and the item will disappear
                        GUIManager.PostWarning("The liquid cannot be held by this container. It seeps away.");
                        foodStuff.RemoveFromGame();
                        return(true);
                    }

                    System.Object lcObject = null;
                    if (liquidContainer.GetStateOf <LiquidContainer>(out lcObject))
                    {
                        LiquidContainerState lcs         = (LiquidContainerState)lcObject;
                        string           liquidFillError = string.Empty;
                        int              numFilled       = 0;
                        GenericWorldItem genericLiquid   = new GenericWorldItem(foodStuff);
                        if (lcs.TryToFillWith(genericLiquid, foodStuffStack.NumItems, out numFilled, out liquidFillError))
                        {
                            //hooray, it worked
                            //how we have to pop items off the top of the food stuff stack
                            for (int i = 0; i < numFilled; i++)
                            {
                                Stacks.Pop.AndToss(foodStuffStack);
                            }
                            GUIManager.PostInfo("Filled " + numFilled.ToString());
                            return(true);
                        }
                        else
                        {
                            GUIManager.PostWarning(liquidFillError);
                        }
                    }
                }
            }
            return(false);
        }
        public ViewModelWindowOilRefinery(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingState manufacturingStateProcessedMineralOil,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            ManufacturingConfig manufacturingConfigProcessedMineralOil,
            LiquidContainerState liquidStateRawPetroleum,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerState liquidStateProcessedMineralOil,
            LiquidContainerConfig liquidConfigRawPetroleum,
            LiquidContainerConfig liquidConfigProcessedGasoline,
            LiquidContainerConfig liquidConfigProcessedMineralOil)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateRawPetroleum = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelManufacturingStateProcessedMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedMineralOil,
                manufacturingConfigProcessedMineralOil);

            this.ViewModelLiquidStateRawPetroleum = new ViewModelLiquidContainerState(
                liquidStateRawPetroleum,
                liquidConfigRawPetroleum);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);

            this.ViewModelLiquidStateProcessedMineralOil = new ViewModelLiquidContainerState(
                liquidStateProcessedMineralOil,
                liquidConfigProcessedMineralOil);

            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => this.NotifyPropertyChanged(
                                                             nameof(this.IsManufacturingActive)),
                                                         this);
        }
        public ViewModelLiquidContainerState(
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
        {
            this.LiquidContainerState = liquidContainerState;
            this.Capacity             = liquidContainerConfig.Capacity;

            liquidContainerState.ClientSubscribe(
                _ => _.Amount,
                _ => this.RefreshAmount(),
                this);

            this.RefreshAmount();
        }
Beispiel #4
0
 public ViewModelWindowGeneratorSteam(
     IStaticWorldObject worldObjectGenerator,
     ObjectGeneratorSteam.PrivateState privateState,
     ManufacturingConfig manufacturingConfig,
     LiquidContainerState liquidContainerState,
     LiquidContainerConfig liquidContainerConfig)
     : base(worldObjectGenerator,
            privateState,
            manufacturingConfig,
            liquidContainerState,
            liquidContainerConfig)
 {
     this.privateState   = privateState;
     this.protoGenerator = (IProtoObjectGeneratorWithFuel)worldObjectGenerator.ProtoStaticWorldObject;
 }
        public ViewModelWindowLithiumOreExtractor(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(worldObjectManufacturer,
                   privateState,
                   manufacturingConfig)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(liquidContainerState,
                                                                                   liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl = new ViewModelDepositCapacityStatsControl(worldObjectDeposit);
        }
 public ViewModelWindowWell(
     IStaticWorldObject worldObjectManufacturer,
     ObjectManufacturerPrivateState privateState,
     ManufacturingConfig manufacturingConfig,
     LiquidContainerState liquidContainerState,
     LiquidContainerConfig liquidContainerConfig)
     : base(
         worldObjectManufacturer,
         privateState,
         manufacturingConfig: manufacturingConfig)
 {
     this.CommandDrink = new ActionCommand(this.ExecuteCommandDrink);
     this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
         liquidContainerState,
         liquidContainerConfig);
 }
        public ViewModelWindowOilCrackingPlant(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            LiquidContainerState liquidStateMineralOil,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerConfig liquidConfigMineralOil,
            LiquidContainerConfig liquidConfigProcessedGasoline)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelLiquidStateMineralOil = new ViewModelLiquidContainerState(
                liquidStateMineralOil,
                liquidConfigMineralOil);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);
            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => NotifyPropertyChanged(nameof(IsManufacturingActive)), this);
            viewModelManufacturerExchange = new ViewModelManufacturerExchange(
                new List <IItemsContainer>
            {
                manufacturingState.ContainerOutput,
                manufacturingStateProcessedGasoline.ContainerOutput
            },
                new List <IItemsContainer>
            {
                manufacturingState.ContainerInput,
                manufacturingStateProcessedGasoline.ContainerInput
            },
                true);
        }
Beispiel #8
0
        public ViewModelWindowGeneratorWithFuel(
            IStaticWorldObject worldObjectGenerator,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectGenerator,
                privateState,
                manufacturingConfig)
        {
            this.protoGenerator = (IProtoObjectGeneratorWithFuel)worldObjectGenerator.ProtoStaticWorldObject;
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig,
                liquidType: this.protoGenerator.LiquidType);

            this.Refresh();
        }
        public ViewModelWindowOilPump(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig,
            FuelBurningState fuelBurningState,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig,
                fuelBurningState)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl = new ViewModelDepositCapacityStatsControl(worldObjectDeposit);
        }
Beispiel #10
0
        public ViewModelWindowOilPump(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectManufacturer,
                privateState,
                manufacturingConfig)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl
                = new ViewModelDepositCapacityStatsControl(worldObjectDeposit,
                                                           worldObjectManufacturer.TilePosition);
        }
Beispiel #11
0
        public static bool ConsumeRequirement(WIStack itemStack, IWIBase item, GenericWorldItem template, bool requirementsMet)
        {
            if (!requirementsMet)
            {
                return(false);
            }

            bool result = false;

            if (item.Is <LiquidContainer> ())
            {
                //see if the thing inside the liquid container has what we need
                bool foundState                  = false;
                LiquidContainerState state       = null;
                System.Object        stateObject = null;
                if (item.GetStateOf <LiquidContainer> (out stateObject))
                {
                    state      = (LiquidContainerState)stateObject;
                    foundState = state != null;
                }

                if (foundState)
                {
                    //hooray it is a liquid
                    if (!state.IsEmpty)
                    {
                        //and it's not empty so steal one
                        state.Contents.InstanceWeight--;
                        result = true;
                        item.SetStateOf <LiquidContainer> (state);
                    }
                }
            }
            else
            {
                Stacks.Pop.AndToss(itemStack);
                result = true;
            }
            return(result);
        }
Beispiel #12
0
        public ViewModelWindowOilRefinery(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingState manufacturingStateProcessedMineralOil,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            ManufacturingConfig manufacturingConfigProcessedMineralOil,
            FuelBurningState fuelBurningState,
            LiquidContainerState liquidStateRawPetroleum,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerState liquidStateProcessedMineralOil,
            LiquidContainerConfig liquidConfigRawPetroleum,
            LiquidContainerConfig liquidConfigProcessedGasoline,
            LiquidContainerConfig liquidConfigProcessedMineralOil)
        {
            this.WorldObjectManufacturer = worldObject;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = new ViewModelFuelBurningState(fuelBurningState);
            this.ViewModelBurningFuel      = ViewModelBurningFuel.Create(this.WorldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingStateRawPetroleum = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelManufacturingStateProcessedMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedMineralOil,
                manufacturingConfigProcessedMineralOil);

            this.ViewModelLiquidStateRawPetroleum = new ViewModelLiquidContainerState(
                liquidStateRawPetroleum,
                liquidConfigRawPetroleum);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);

            this.ViewModelLiquidStateProcessedMineralOil = new ViewModelLiquidContainerState(
                liquidStateProcessedMineralOil,
                liquidConfigProcessedMineralOil);

            // prepare active state property
            var manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();

            manufacturerPublicState.ClientSubscribe(_ => _.IsManufacturingActive,
                                                    _ => RefreshIsManufacturerActive(),
                                                    this);
            RefreshIsManufacturerActive();

            void RefreshIsManufacturerActive()
            {
                this.IsManufacturerActive = manufacturerPublicState.IsManufacturingActive;
            }
        }
Beispiel #13
0
        //this is used in a lot of places
        //eg in player inventory squares for crafting to check if the thing you've put in the square meets requirements
        public static bool AreRequirementsMet(IWIBase item, GenericWorldItem template, BlueprintStrictness strictness, int numItemsInStack, out int maxItemsToCraft)
        {
            maxItemsToCraft = 1;

            if (item != null && item.IsQuestItem)
            {
                return(false);
            }

            bool prefabReqsMet = true;
            bool stackReqsMet  = true;
            bool stateReqsMet  = true;
            bool subCatReqsMet = true;

            //first we need to get the thing we're crafting from
            //if it's a liquid container we need to get the state data
            if (item.Is <LiquidContainer> ())
            {
                LiquidContainerState stateData = null;
                bool foundState = false;
                if (item.IsWorldItem)
                {
                    stateData  = item.worlditem.Get <LiquidContainer> ().State;
                    foundState = true;
                }
                else
                {
                    if (item.GetStackItem(WIMode.None).GetStateData <LiquidContainerState> (out stateData))
                    {
                        foundState = true;
                    }
                }

                if (foundState)
                {
                    //see if the liquid container contains what's needed
                    mCheckRequirements.CopyFrom(stateData.Contents);
                    mCheckRequirements.InstanceWeight = stateData.Contents.InstanceWeight;
                }
            }
            else
            {
                //if it's not a liquid container just get it from the item
                mCheckRequirements.CopyFrom(item);
                mCheckRequirements.InstanceWeight = numItemsInStack;
            }

            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.PrefabName, Flags.CheckType.MatchAny))
            {
                prefabReqsMet = string.Equals(mCheckRequirements.PrefabName, template.PrefabName, StringComparison.InvariantCultureIgnoreCase);
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny))
            {
                stackReqsMet = string.Equals(mCheckRequirements.StackName, template.StackName, StringComparison.InvariantCultureIgnoreCase);
                if (!stackReqsMet)
                {
                    try {
                        //check for the rare case where a non-numbered item is compared against a numbered item
                        //'x #' vs 'x'
                        //'x' vs 'x #'
                        bool isReqDigit  = char.IsDigit(mCheckRequirements.StackName, mCheckRequirements.StackName.Length - 1);
                        bool isItemDigit = char.IsDigit(template.StackName, template.StackName.Length - 1);
                        if (isReqDigit != isItemDigit)
                        {
                            string nonNumbered = isItemDigit ? mCheckRequirements.StackName : template.StackName;
                            string numbered    = isReqDigit ? mCheckRequirements.StackName.Substring(0, mCheckRequirements.StackName.Length - 2) : template.StackName.Substring(0, template.StackName.Length - 2);
                            stackReqsMet = nonNumbered.Equals(numbered);
                                                        #if UNITY_EDITOR
                            Debug.Log("Checking numbered against non-numbered in crafting: " + mCheckRequirements.StackName + " vs " + template.StackName + " - check " + nonNumbered + ", " + numbered + " - " + stackReqsMet.ToString());
                                                        #endif
                        }
                    } catch (Exception e) {
                        Debug.LogError("Error when checking for item digits in crafting skill: " + e.ToString());
                    }
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny))
            {
                if ((string.IsNullOrEmpty(mCheckRequirements.State) || string.IsNullOrEmpty(template.State)) || (mCheckRequirements.State.Equals("Default") || template.State.Equals("Default")))
                {
                    stateReqsMet = true;
                }
                else
                {
                    stateReqsMet = string.Equals(mCheckRequirements.State, template.State, StringComparison.InvariantCultureIgnoreCase);
                }
            }
            if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny))
            {
                if (string.IsNullOrEmpty(mCheckRequirements.Subcategory) || string.IsNullOrEmpty(template.Subcategory))
                {
                    subCatReqsMet = true;
                }
                else
                {
                    subCatReqsMet = string.Equals(mCheckRequirements.Subcategory, template.Subcategory, StringComparison.InvariantCultureIgnoreCase);
                }
            }
                        #if UNITY_EDITOR
            Debug.Log(template.PrefabName + " prefab reqs met: " + prefabReqsMet.ToString() + "\nstackReqsMet: " + stackReqsMet.ToString() + "\nstateReqsMet: " + stateReqsMet.ToString() + "\nsubCatReqsMet: " + subCatReqsMet.ToString());
                        #endif
            //max items to craft is the instance weight divided by instance weight of the template
            //instance weight of template tells us how many we need in that stack to craft
            maxItemsToCraft = mCheckRequirements.InstanceWeight / template.InstanceWeight;
            //if we have enough items to craft, we can proceed
            return(prefabReqsMet && stackReqsMet && stateReqsMet && subCatReqsMet && maxItemsToCraft >= template.InstanceWeight);
        }