コード例 #1
0
        public override void SharedUpdate(double deltaTime)
        {
            if ((this.ItemCrowbarTool is not null &&
                 this.ItemCrowbarTool != this.CharacterPublicState.SelectedItem) ||
                !this.CheckIsAllowed())
            {
                // selected hotbar item changed or the action is not allowed anymore
                this.AbortAction();
                return;
            }

            if (!DeconstructionSystem.SharedCheckCanInteract(
                    this.Character,
                    this.WorldObject,
                    writeToLog: true))
            {
                this.AbortAction();
                return;
            }

            this.currentStageTimeRemainsSeconds -= deltaTime;
            if (this.currentStageTimeRemainsSeconds <= 0)
            {
                this.SharedOnStageCompleted();
            }

            this.UpdateProgress();
        }
コード例 #2
0
        private void SharedOnStageCompleted()
        {
            if (Api.IsServer &&
                this.ItemCrowbarTool is not null)
            {
                // notify tool was used
                ServerItemUseObserver.NotifyItemUsed(this.Character, this.ItemCrowbarTool);

                // reduce tool durability
                ItemDurabilitySystem.ServerModifyDurability(this.ItemCrowbarTool, delta: -1);
            }

            this.currentStageDurationSeconds     = this.CalculateStageDurationSeconds(this.Character, isFirstStage: false);
            this.currentStageTimeRemainsSeconds += this.currentStageDurationSeconds;

            var oldStructurePoints = this.ObjectPublicState.StructurePointsCurrent;
            var newStructurePoints = Math.Max(
                0,
                oldStructurePoints - this.stageStructureRemoveValue);

            this.protoStructure.SharedOnDeconstructionStage(
                this.WorldObject,
                this.Character,
                oldStructurePoints,
                newStructurePoints);

            if (Api.IsClient || // client will simply always deconstruct until finished
                newStructurePoints > 0)
            {
                // deconstruction progressed
                if (Api.IsServer)
                {
                    Logger.Important(
                        $"Deconstruction progressed: {this.WorldObject} structure points: {newStructurePoints}/{this.structurePointsMax}; by {this.Character}");
                }

                this.UpdateProgress();

                if (Api.IsServer &&
                    this.ItemCrowbarTool is not null &&
                    this.ItemCrowbarTool.IsDestroyed)
                {
                    // tool was destroyed (durability 0)
                    this.AbortAction();
                    return;
                }

                return;
            }

            // deconstruction is completed
            if (Api.IsServer)
            {
                if (!(this.protoStructure is ProtoObjectConstructionSite))
                {
                    this.CharacterPrivateState.Skills.ServerAddSkillExperience <SkillBuilding>(
                        SkillBuilding.ExperienceAddWhenDeconstructionFinished);
                }

                Logger.Important(
                    $"Deconstruction completed: {this.WorldObject} structure points: {newStructurePoints}/{this.structurePointsMax}; by {this.Character}");
                this.ObjectPublicState.StructurePointsCurrent = newStructurePoints;
            }

            this.SetCompleted(isCancelled: false);
            DeconstructionSystem.SharedActionCompleted(this.Character, this);
        }
コード例 #3
0
 protected override void AbortAction()
 {
     DeconstructionSystem.SharedAbortAction(
         this.Character,
         this.WorldObject);
 }