public static bool SharedValidateCanUnstuck(ICharacter character)
        {
            using var tempAreas = Api.Shared.GetTempList <ILogicObject>();
            var bounds = new RectangleInt(
                offset: character.TilePosition - (1, 1),
                size: (2, 2));

            LandClaimSystem.SharedGetAreasInBounds(bounds, tempAreas, addGracePadding: false);
            foreach (var area in tempAreas.AsList())
            {
                if (LandClaimSystem.SharedIsAreaUnderRaid(area))
                {
                    Logger.Info("Cannot unstuck when located in an area under raid", character);
                    LandClaimSystem.SharedSendNotificationActionForbiddenUnderRaidblock(character);
                    return(false);
                }

                if (LandClaimShieldProtectionSystem.SharedIsAreaUnderShieldProtection(area))
                {
                    Logger.Info("Cannot unstuck when located in an area under shield protection", character);
                    LandClaimShieldProtectionSystem.SharedSendNotificationActionForbiddenUnderShieldProtection(character);
                    return(false);
                }
            }

            return(true);
        }
Пример #2
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 &&
                LandClaimShieldProtectionSystem.SharedIsAreaUnderShieldProtection(currentLandClaimArea))
            {
                // the building is in an area under shield protection
                result = ObjectLandClaimCanUpgradeCheckResult.ErrorUnderShieldProtection;
            }

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                // check there will be no intersection with other areas
                var landClaimCenterTilePosition =
                    LandClaimSystem.SharedCalculateLandClaimObjectCenterTilePosition(worldObjectLandClaim);

                if (!LandClaimSystem.SharedCheckCanPlaceOrUpgradeLandClaimThereConsideringShieldProtection(
                        protoUpgradedLandClaim,
                        landClaimCenterTilePosition,
                        character))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorAreaIntersectionWithShieldProtectedArea;
                }

                if (!LandClaimSystem.SharedCheckCanPlaceOrUpgradeLandClaimThere(
                        protoUpgradedLandClaim,
                        landClaimCenterTilePosition,
                        character))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorAreaIntersection;
                }

                if (!LandClaimSystem.SharedCheckNoLandClaimByDemoPlayers(
                        protoUpgradedLandClaim,
                        landClaimCenterTilePosition,
                        character,
                        exceptAreasGroup: LandClaimSystem.SharedGetLandClaimAreasGroup(currentLandClaimArea)))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorAreaIntersectionDemoPlayer;
                }

                if (IsServer &&
                    !LandClaimSystem.ServerCheckFutureBaseWillExceedSafeStorageCapacity(
                        protoUpgradedLandClaim,
                        landClaimCenterTilePosition,
                        character))
                {
                    result = ObjectLandClaimCanUpgradeCheckResult.ErrorExceededSafeStorageCapacity;
                }
            }

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

            if (result == ObjectLandClaimCanUpgradeCheckResult.Success &&
                LandClaimSystem.SharedIsUnderRaidBlock(character, worldObjectLandClaim))
            {
                // the building is in an area under 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);
        }