Ejemplo n.º 1
0
 public ServerPlayerActiveTask(
     IPlayerTask playerTask,
     PlayerTaskState playerTaskState,
     IPlayerActiveTasksHolder playerTaskTarget,
     ICharacter character)
 {
     this.PlayerTask       = playerTask;
     this.PlayerTaskState  = playerTaskState;
     this.PlayerTaskTarget = playerTaskTarget;
     this.Character        = character;
 }
        public ViewModelQuestRequirement(
            IPlayerTask requirement,
            // can be null when the quest is completed
            [CanBeNull] PlayerTaskState taskState,
            bool showIcon)
        {
            this.requirement = requirement;
            this.taskState   = taskState;
            this.showIcon    = showIcon;

            this.taskState?.ClientSubscribe(
                _ => _.IsCompleted,
                isCompletedNow =>
            {
                this.NotifyPropertyChanged(nameof(this.IsCompleted));
                if (!isCompletedNow)
                {
                    return;
                }

                // play requirement satisfied sound (not more often than once per frame)
                if (lastTaskFinishedFrameNumber != Client.CurrentGame.ServerFrameNumber)
                {
                    lastTaskFinishedFrameNumber = Client.CurrentGame.ServerFrameNumber;
                    Api.Client.Audio.PlayOneShot(SoundResourceQuestRequirementSatisfied, volume: 0.5f);
                }
            },
                this);

            if (requirement is IPlayerTaskWithCount questRequirementWithCount)
            {
                this.CountRequired = questRequirementWithCount.RequiredCount;

                if (taskState != null)
                {
                    // requirement state can be null if the quest is already completed
                    this.taskStateWithCount = (PlayerTaskStateWithCount)taskState;
                    this.taskStateWithCount.ClientSubscribe(
                        _ => _.CountCurrent,
                        _ => this.NotifyPropertyChanged(nameof(this.CountCurrent)),
                        this);
                }
            }
        }