Ejemplo n.º 1
0
        private void Start()
        {
            _items = new Dictionary <ItemID, InventoryItemStats>();

            // TODO: Remove After Testing
            _items.Add(testItem.itemId, new InventoryItemStats
            {
                inventoryItem = testItem,
                itemCount     = 20
            });

            // TODO: Read initial resources from file
            resourcesChanged?.Invoke();
        }
Ejemplo n.º 2
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        Resources = new Dictionary <ResourceType, int>()
        {
            { ResourceType.Bones, 0 },
            { ResourceType.Food, 0 },
            { ResourceType.Meat, 0 }
        };
        OnResourcesChanged?.Invoke();
    }
Ejemplo n.º 3
0
        public Styles()
        {
            ResetBehavior = ResetBehavior.Remove;
            this.ForEachItem(
                x =>
            {
                if (x.ResourceParent == null && x is ISetStyleParent setParent)
                {
                    setParent.SetParent(this);
                    setParent.NotifyResourcesChanged(new ResourcesChangedEventArgs());
                }

                if (x.HasResources)
                {
                    ResourcesChanged?.Invoke(this, new ResourcesChangedEventArgs());
                }

                x.ResourcesChanged += SubResourceChanged;
                _cache              = null;
            },
                x =>
            {
                if (x.ResourceParent == this && x is ISetStyleParent setParent)
                {
                    setParent.SetParent(null);
                    setParent.NotifyResourcesChanged(new ResourcesChangedEventArgs());
                }

                if (x.HasResources)
                {
                    ResourcesChanged?.Invoke(this, new ResourcesChangedEventArgs());
                }

                x.ResourcesChanged -= SubResourceChanged;
                _cache              = null;
            },
                () => { });
        }
Ejemplo n.º 4
0
 protected virtual void OnResourcesChanged()
 {
     ResourcesChanged?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Raises <see cref="ResourcesChanged"/> event.
 /// </summary>
 private void OnWorkerResourcesChanged(WorkerResource kind, bool increased)
 {
     ResourcesChanged?.Invoke(this, kind, increased);
 }
Ejemplo n.º 6
0
        public void SetSystem()
        {
            Owner.EnemyControlSystem.EnemyDied    += OnEnemyDied;
            Owner.SpiritPlaceSystem.SpiritPlaced  += OnSpiritCreated;
            Owner.PlayerInputSystem.SpiritSold    += OnSpiritSold;
            Owner.WaveSystem.AllWaveEnemiesKilled += OnAllEnemiesKilled;
            Owner.ElementSystem.LearnedElement    += OnElementLearned;
            Owner.ItemDropSystem.ItemUICreated    += OnItemUICreated;

            void OnElementLearned(int learnCost) => AddResource(ResourceType.MagicCrystal, -learnCost);

            void OnItemUICreated(ItemUISystem e)
            {
                e.System.ConsumedMagicCrystals += OnMagicCrystalsConsumed;
                e.System.ConsumedSpiritVessels += OnSpiritVesselsConsumed;

                void OnMagicCrystalsConsumed(double value) => AddResource(ResourceType.MagicCrystal, value);
                void OnSpiritVesselsConsumed(double value) => AddResource(ResourceType.MaxSpiritLimit, value);
            }

            void OnSpiritSold(SpiritSystem spirit)
            {
                AddResource(ResourceType.Resource, spirit.Data.Get(Numeral.ResourceCost).Value);
                AddResource(ResourceType.SpiritLimit, -spirit.Data.Get(Enums.Spirit.SpiritLimit).Value);
            }

            void OnSpiritCreated(SpiritSystem spirit)
            {
                AddResource(ResourceType.Resource, -spirit.Data.Get(Numeral.ResourceCost).Value);
                AddResource(ResourceType.SpiritLimit, spirit.Data.Get(Enums.Spirit.SpiritLimit).Value);
            }

            void OnEnemyDied(EnemySystem enemy)
            {
                if (enemy.LastDamageDealer != null)
                {
                    AddResource(ResourceType.Resource, enemy.Data.Get(Numeral.ResourceCost).Sum);
                }
            }

            void OnAllEnemiesKilled()
            {
                AddResource(ResourceType.MagicCrystal, 5f);
                AddResource(ResourceType.Resource, Owner.WaveSystem.WaveNumber * 10 + Owner.Data.Resources.Resource.GetPercent(10));
            }

            void AddResource(ResourceType type, double amount)
            {
                if (type == ResourceType.Resource)
                {
                    Owner.Data.Resources.Resource += amount;
                }

                else if (type == ResourceType.MagicCrystal)
                {
                    Owner.Data.Resources.MagicCrystals += amount;
                }

                else if (type == ResourceType.SpiritLimit)
                {
                    Owner.Data.Resources.CurrentSpiritLimit += amount;
                }

                else if (type == ResourceType.MaxSpiritLimit)
                {
                    Owner.Data.Resources.MaxSpiritLimit += amount;
                }

                //DataLoadingSystem.Save(GM.I.Players[0]);
                ResourcesChanged?.Invoke();
            }
        }