Exemple #1
0
 private void QueueElementInsertedHandler(
     NetworkSyncList <CraftingQueueItem> source,
     int index,
     CraftingQueueItem value)
 {
     this.AddControl(value);
 }
Exemple #2
0
        private void RemoveControl(CraftingQueueItem removedValue)
        {
            var control = this.craftingQueueItemsControls[removedValue];

            this.craftingQueueItemsControls.Remove(removedValue);
            control.Hide();
        }
Exemple #3
0
        private void DeleteCraftingQueueItemHandler(CraftingQueueItem craftingQueueItem)
        {
            if (!craftingQueueItem.Recipe.IsCancellable)
            {
                NotificationSystem.ClientShowNotification(
                    NotificationCannotDegradeableCraftItem_Title,
                    NotificationCannotDegradeableCraftItem_Message,
                    icon: craftingQueueItem.Recipe.Icon);
                return;
            }

            CraftingSystem.Instance.ClientDeleteQueueItem(craftingQueueItem);
        }
Exemple #4
0
        public ViewModelCraftingQueueItem(
            CraftingQueue craftingQueue,
            CraftingQueueItem craftingQueueItem,
            Action countToCraftChangedCallback)
        {
            if (IsDesignTime)
            {
                this.Icon = Brushes.BlueViolet;
                return;
            }

            this.craftingQueue               = craftingQueue;
            this.craftingQueueItem           = craftingQueueItem;
            this.countToCraftChangedCallback = countToCraftChangedCallback;
            var outputProtoItem = this.craftingQueueItem.RecipeEntry.ProtoItemSkinOverride
                                  ?? this.craftingQueueItem.RecipeEntry.Recipe.OutputItems.Items.First().ProtoItem;

            this.RecipeViewModel = new ViewModelCraftingRecipe(this.craftingQueueItem.RecipeEntry.Recipe);

            // TODO: it's not a great idea to always send this info from the server,
            // it could be calculated on Client-side with custom component (updates every frame)
            // and only sometimes sync with the server.
            craftingQueue.ClientSubscribe(
                _ => _.TimeRemainsToComplete,
                _ => this.UpdateProgress(),
                this);

            this.UpdateProgress();

            this.craftingQueueItem.ClientSubscribe(
                _ => _.CountToCraftRemains,
                newCountToCraftRemains =>
            {
                if (this.lastCountToCraft.HasValue &&
                    this.lastCountToCraft.Value > newCountToCraftRemains)
                {
                    // count to craft decreased
                    Client.Audio.PlayOneShot(new SoundResource("UI/Notifications/ItemAdded"));
                }

                this.UpdateCountToCraftRemains();
                countToCraftChangedCallback?.Invoke();
            },
                this);

            this.UpdateCountToCraftRemains();

            this.Icon = Client.UI.GetTextureBrush(outputProtoItem.Icon);
        }
Exemple #5
0
        private void QueueClientElementRemovedHandler(
            NetworkSyncList <CraftingQueueItem> source,
            int index,
            CraftingQueueItem removedValue)
        {
            if (this.craftingQueueItems.Count == 0)
            {
                // queue finished sounds
                ClientComponentTimersManager.AddAction(
                    delaySeconds: 0.3,
                    action: () => Client.Audio.PlayOneShot(new SoundResource("UI/Crafting/Completed")));
            }

            this.RemoveControl(removedValue);
        }
Exemple #6
0
        // Reward player for the crafted item.
        private static void ServerOnRecipeCraftedHandler(CraftingQueueItem craftingQueueItem)
        {
            if (!(craftingQueueItem.GameObject is ICharacter character) ||
                character.ProtoCharacter.GetType() != typeof(PlayerCharacter))
            {
                // not crafted by player or player prototype is not exactly PlayerCharacter
                return;
            }

            // add experience according to the crafted recipe's original duration
            var exp = ExperienceForCraftingPerSecond
                      * craftingQueueItem.Recipe.OriginalDuration;

            character.ServerAddSkillExperience <SkillCrafting>(exp);
        }
Exemple #7
0
        private void AddControl(CraftingQueueItem craftingQueueItem)
        {
            var control = new CraftingQueueItemControl
            {
                DeleteCallback = this.DeleteCraftingQueueItemHandler,
                HiddenCallback = this.ItemControlHiddenHandler,
                CountToCraftChangedCallback = this.ItemControlCountToCraftChangedCallback
            };

            control.Setup(this.craftingQueue, craftingQueueItem);

            this.craftingQueueItemsControls[craftingQueueItem] = control;
            this.itemsChildrenCollection.Add(control);

            this.Refresh();
        }
Exemple #8
0
        private void RecipeCraftedHandler(CraftingQueueItem craftingQueueItem)
        {
            if (!(craftingQueueItem.GameObject is ICharacter character))
            {
                return;
            }

            var context = this.GetActiveContext(character, out var state);

            if (context == null)
            {
                return;
            }

            if (!this.List.Contains(craftingQueueItem.Recipe))
            {
                return;
            }

            state.SetCountCurrent(state.CountCurrent + 1, this.RequiredCount);
            context.Refresh();
        }
Exemple #9
0
 private void ItemControlCountToCraftChangedCallback(CraftingQueueItem _ = null)
 {
     this.Refresh();
 }
 private void MakeFirstInQueueHandler(CraftingQueueItem craftingQueueItem)
 {
     CraftingSystem.ClientMakeItemFirstInQueue(craftingQueueItem);
 }