Exemplo n.º 1
0
        public ObjectLandClaimCanUpgradeCheckResult ServerRemote_UpgradeStructure(
            IStaticWorldObject oldWorldObjectLandClaim,
            IProtoObjectLandClaim upgradeStructure)
        {
            this.VerifyGameObject(oldWorldObjectLandClaim);
            var character = ServerRemoteContext.Character;
            var result    = this.SharedCanUpgrade(oldWorldObjectLandClaim,
                                                  upgradeStructure,
                                                  character,
                                                  out var upgradeEntry);

            if (result != ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                return(result);
            }

            // consume items
            upgradeEntry.ServerDestroyRequiredItems(character);

            // upgrade (it will destroy an existing structure and place new in its place)
            var upgradedWorldObjectLandClaim = LandClaimSystem.ServerUpgrade(oldWorldObjectLandClaim,
                                                                             upgradeStructure,
                                                                             character);

            // notify client (to play a sound)
            ConstructionPlacementSystem.Instance.ServerNotifyOnStructurePlacedOrRelocated(
                upgradedWorldObjectLandClaim,
                character);
            return(result);
        }
Exemplo n.º 2
0
        public ObjectLandClaimCanUpgradeCheckResult ServerRemote_UpgradeStructure(
            IStaticWorldObject oldWorldObjectLandClaim,
            IProtoObjectLandClaim upgradeStructure)
        {
            this.VerifyGameObject(oldWorldObjectLandClaim);
            var character = ServerRemoteContext.Character;
            var result    = this.SharedCanUpgrade(oldWorldObjectLandClaim,
                                                  upgradeStructure,
                                                  character,
                                                  out var upgradeEntry);

            if (result != ObjectLandClaimCanUpgradeCheckResult.Success)
            {
                return(result);
            }

            // consume items
            upgradeEntry.ServerDestroyRequiredItems(character);

            // copy all items to temp container
            var oldStorage = GetPrivateState(oldWorldObjectLandClaim).ItemsContainer;

            var tempStorageOwner = Server.World.CreateLogicObject <LogicObjectTempItemsContainerHolder>();
            var tempStorage      = Server.Items.CreateContainer(
                owner: tempStorageOwner, // we must set an owner, unfortunately
                slotsCount: (byte)oldStorage.OccupiedSlotsCount);

            Server.Items.TryMoveAllItems(oldStorage, tempStorage);

            // upgrade (it will destroy an existing structure and place new in its place)
            var upgradedWorldObjectLandClaim = LandClaimSystem.ServerUpgrade(oldWorldObjectLandClaim,
                                                                             upgradeStructure,
                                                                             character);

            // move all items from temp container to the upgraded land claim
            var newStorage = GetPrivateState(upgradedWorldObjectLandClaim).ItemsContainer;

            Server.Items.TryMoveAllItems(tempStorage, newStorage);
            Server.Items.DestroyContainer(tempStorage);
            Server.World.DestroyObject(tempStorageOwner);

            // notify client (to play sound)
            ConstructionPlacementSystem.Instance.ServerOnStructurePlaced(upgradedWorldObjectLandClaim, character);

            return(result);
        }