예제 #1
0
        /// <summary>
        /// Add a new entry to the resource dictionary
        /// </summary>
        /// <param name="resourceName">Name of resource to add</param>
        /// <param name="resourceAmount">Amount of resource to add</param>
        public void AddToSynceDict(string resourceName, int resourceAmount)
        {
            bool canAfford = false;

            Mod_ResourceCache cache = new Mod_ResourceCache();

            // Check if the resource is in the dictionary
            if (!SyncedResources.ContainsKey(resourceName))
            {
                canAfford = cache.IncreaseValue(resourceAmount);
            }
            // Check if the increase/decrease can be afforded
            else
            {
                canAfford = SyncedResources[resourceName].IncreaseValue(resourceAmount);
                cache.CurrentResourceValue = SyncedResources[resourceName].CurrentResourceValue;
            }

            // Tell all clients to update their dictionaries
            if (canAfford)
            {
                SyncedResources[resourceName] = cache;
                RpcSetResource(resourceName, cache.CurrentResourceValue);
            }
        }
예제 #2
0
        public void RpcSetResource(string resourceName, int resourceAmount)
        {
            if (isLocalPlayer)
            {
                // If the resource is in the dictionary then set it to the new value
                if (SyncedResources.ContainsKey(resourceName))
                {
                    SyncedResources[resourceName].CurrentResourceValue = resourceAmount;
                }
                // Else just add a new entry to the dictionary
                else
                {
                    Mod_ResourceCache cache = new Mod_ResourceCache();
                    cache.CurrentResourceValue = resourceAmount;
                }

                // Uodate the UI
                UpdateUI(resourceName, resourceAmount);
            }
        }