Esempio n. 1
0
        public ViewModelStructureUpgrade(IConstructionUpgradeEntryReadOnly upgradeEntry)
        {
            this.UpgradeEntry = upgradeEntry;
            this.ViewModelUpgradedStructure = new ViewModelStructure(upgradeEntry.ProtoStructure);

            this.Refresh();
            this.SubscribeToEvents();
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor for upgrade recipe for IProtoStructure.
        /// Must be used only in InitEntityRelationships phase.
        /// </summary>
        /// <param name="structureViewModel">View Model of IProtoStructure.</param>
        /// <param name="upgradeEntry">Entry of upgrade config.</param>
        public RecipeViewModel([NotNull] ProtoObjectStructureViewModel structureViewModel,
                               [NotNull] IConstructionUpgradeEntryReadOnly upgradeEntry)
            : base(upgradeEntry.ProtoStructure)
        {
            if (!EntityViewModelsManager.EntityDictonaryCreated)
            {
                throw new Exception("CNEI: Upgrade constructor used before all entity VMs sets.");
            }

            var inputTempList = new List <BaseViewModel>()
            {
                new ViewModelEntityWithCount(structureViewModel)
            };

            inputTempList.AddRange(upgradeEntry.RequiredItems
                                   .Select(item => new ViewModelEntityWithCount(EntityViewModelsManager.GetEntityViewModel(item.ProtoItem),
                                                                                item.Count)));
            InputItemsVMList = inputTempList.AsReadOnly();

            if (!(EntityViewModelsManager.GetEntityViewModel(upgradeEntry.ProtoStructure)
                  is ProtoObjectStructureViewModel newStructureViewModel))
            {
                throw new Exception("CNEI: Can not find ProtoObjectStructureViewModel for " +
                                    upgradeEntry.ProtoStructure);
            }
            OutputItemsVMList = new List <BaseViewModel>()
            {
                new ViewModelEntityWithCount(newStructureViewModel)
            }.AsReadOnly();

            OriginText     = "Upgrade from:";
            IsStationCraft = Visibility.Visible;
            StationsList   = new List <ProtoEntityViewModel>()
            {
                structureViewModel
            }.AsReadOnly();
            // Can not simply get it from result entityVM because it can has not initilized Tech.
            //ListedInTechNodes = newStructureViewModel.ListedInTechNodes;
            ListedInTechNodes = upgradeEntry.ProtoStructure.ListedInTechNodes
                                .Select(EntityViewModelsManager.GetEntityViewModel)
                                .ToList().AsReadOnly();
            IsAutoUnlocked = structureViewModel.IsAutoUnlocked;
        }
        /// <summary>
        /// Constructor for upgrade recipe for IProtoStructure.
        /// Must be used only in InitEntityRelationships phase.
        /// </summary>
        /// <param name="structureViewModel">View Model of IProtoStructure.</param>
        /// <param name="upgradeEntry">Entry of upgrade config.</param>
        public StructureUpgradeRecipeViewModel([NotNull] ProtoObjectStructureViewModel structureViewModel,
                                               [NotNull] IConstructionUpgradeEntryReadOnly upgradeEntry)
            : base(upgradeEntry.ProtoStructure)
        {
            if (!EntityViewModelsManager.EntityDictionaryCreated)
            {
                throw new Exception("CNEI: Upgrade constructor used before all entity VMs sets.");
            }

            StructureVM = structureViewModel;

            InputItemsList = upgradeEntry.RequiredItems
                             .Select(item => EntityViewModelsManager.GetEntityViewModel(item.ProtoItem))
                             .ToList();
            InputItemsList.Add(structureViewModel);

            InputItemsVMList = upgradeEntry.RequiredItems
                               .Select(item => new ViewModelEntityWithCount(EntityViewModelsManager.GetEntityViewModel(item.ProtoItem),
                                                                            item.Count))
                               .ToList().AsReadOnly();

            if (!(EntityViewModelsManager.GetEntityViewModel(upgradeEntry.ProtoStructure)
                  is ProtoObjectStructureViewModel newStructureViewModel))
            {
                throw new Exception("CNEI: Can not find ProtoObjectStructureViewModel for " +
                                    upgradeEntry.ProtoStructure);
            }

            OutputItemsList.Add(newStructureViewModel);

            UpgradedStructureVM = newStructureViewModel;

            // Can not simply get it from result entityVM because it can has not Initialized Tech.
            //ListedInTechNodes = newStructureViewModel.ListedInTechNodes;
            ListedInTechNodes = upgradeEntry.ProtoStructure.ListedInTechNodes
                                .Select(EntityViewModelsManager.GetEntityViewModel)
                                .ToList().AsReadOnly();
            IsAutoUnlocked = structureViewModel.IsAutoUnlocked;
        }
Esempio n. 4
0
        public ObjectLandClaimCanUpgradeCheckResult SharedCanUpgrade(
            IStaticWorldObject worldObjectLandClaim,
            IProtoObjectLandClaim protoUpgradedLandClaim,
            ICharacter character,
            out IConstructionUpgradeEntryReadOnly upgradeEntry,
            bool writeErrors = true)
        {
            if (!this.SharedCanInteract(character,
                                        worldObjectLandClaim,
                                        writeToLog: writeErrors))
            {
                upgradeEntry = null;
                return(ObjectLandClaimCanUpgradeCheckResult.ErrorUnknown);
            }

            upgradeEntry = null;
            foreach (var entry in this.ConfigUpgrade.Entries)
            {
                if (entry.ProtoStructure == protoUpgradedLandClaim)
                {
                    upgradeEntry = entry;
                    break;
                }
            }

            var currentLandClaimArea = GetPublicState(worldObjectLandClaim).LandClaimAreaObject;
            var founderName          = LandClaimArea.GetPrivateState(currentLandClaimArea).LandClaimFounder;

            var result = ObjectLandClaimCanUpgradeCheckResult.Success;

            if (upgradeEntry == null)
            {
                result = ObjectLandClaimCanUpgradeCheckResult.ErrorUnknown;
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                if (character.Name != founderName &&
                    !CreativeModeSystem.SharedIsInCreativeMode(character))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorNotFounder;
                }
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                // validate player know the tech, have enough items, etc
                if (!upgradeEntry.CheckRequirementsSatisfied(character))
                {
                    upgradeEntry = null;
                    result       = ObjectLandClaimCanUpgradeCheckResult.ErrorRequirementsNotSatisfied;
                }
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                // check there will be no intersection with other areas
                var landClaimCenterTilePosition =
                    LandClaimSystem.SharedCalculateLandClaimObjectCenterTilePosition(worldObjectLandClaim);
                if (!LandClaimSystem.SharedCheckCanPlaceOrUpgradeLandClaimThere(
                        protoUpgradedLandClaim,
                        landClaimCenterTilePosition,
                        character))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorAreaIntersection;
                }
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                if (!InteractionCheckerSystem.SharedHasInteraction(character,
                                                                   worldObjectLandClaim,
                                                                   requirePrivateScope: true))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorNoActiveInteraction;
                }
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                if (LandClaimSystem.SharedIsUnderRaidBlock(character, worldObjectLandClaim))
                {
                    // the building is in an area under the raid
                    LandClaimSystem.SharedSendNotificationActionForbiddenUnderRaidblock(character);
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorUnderRaid;
                }
            }

            if (writeErrors &&
                result != ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                Logger.Warning(
                    $"Can\'t upgrade: {worldObjectLandClaim} to {protoUpgradedLandClaim}: error code - {result}",
                    character);
            }

            return(result);
        }