示例#1
0
        public void ResourceBank_Bank_IndexerWorks()
        {
            ResourceBank bank = new ResourceBank(20);

            bank.Add(TestResource, 5);
            Assert.IsNotNull(bank[TestResource]);
        }
示例#2
0
    /// <summary>
    /// Add resources of a given type to the players inventory.
    /// </summary>
    /// <param name="type">ResourceType to add.</param>
    /// <param name="amount">Amount of resources to add.</param>
    /// <returns>True if the full amount was added</returns>
    public bool AddResources(ResourceType type, int amount)
    {
        if (_resources.ContainsKey(type))
        {
            ResourceBank bank = _resources[type];
            if (bank != null)
            {
                if (bank.Balance == bank.UpperLimit)
                {
                    return(false);
                }

                if (bank.Balance + amount > bank.UpperLimit)
                {
                    bank.Add(bank.UpperLimit - bank.Balance);
                }
                else
                {
                    bank.Add(amount);
                }
                ResourceUpdated(type, bank.Balance, bank.UpperLimit);

                return(true);
            }
        }
        else
        {
            CreateResource(type, amount, amount);
            return(true);
        }

        return(false);
    }
示例#3
0
    void SetpreviewObjectObject(int id)
    {
        BuildIdentifier bid = objects[id].GetComponent <BuildIdentifier>();
        ResourceBank    rba = team.baseObject.GetComponent <ResourceBank>();

        if (bid.woodCost <= rba.wood && bid.stoneCost <= rba.stone && bid.metalCost <= rba.metal)
        {
            if (previewObject != null)
            {
                Destroy(previewObject);
            }
            currentObject = id;
            previewObject = Instantiate(objects[currentObject], baseParent);

            if (previewObject.transform.childCount > 0)
            {
                for (int counter = 0; counter < previewObject.transform.childCount; counter++)
                {
                    previewObject.transform.GetChild(counter).gameObject.GetComponent <BoxCollider>().enabled = false;
                }
            }
            else
            {
                previewObject.GetComponent <BoxCollider>().enabled = false;
            }
            meshRend = previewObject.GetComponent <MeshRenderer>();
            SaveMaterials();
            SetMaterial(invalidMaterial);
            previewObject.layer = 2;
            previewBuildPoints  = previewObject.GetComponent <BuildPoints>();
            previewObject.transform.localEulerAngles = new Vector3(0, 0, 0);
        }
    }
示例#4
0
        public void ResourceBank_Add_ModifiesVolumeCorrectly()
        {
            ResourceBank cargo = new ResourceBank(20);

            cargo.Add(TestResource, 8);
            Assert.IsTrue(cargo.Quantity == 8);
        }
示例#5
0
    void ReceiveResource()
    {
        if (ResourceBank.GetResourceValue(requiredResourceType) == 0)
        {
            return;
        }

        if (_currentResourceToConsume == 0)
        {
            _stateTracker.PlanetSaved();
        }


        int resourceToReceive = (int)(refreshTime * resourceDepositRate);

        if (ResourceBank.GetResourceValue(requiredResourceType) > resourceToReceive)
        {
            _currentResourceToConsume += resourceToReceive;
            ResourceBank.RemoveResource(requiredResourceType, resourceToReceive);
            _gameController.score += resourceToReceive * 5;
            _gameController.UpdateScore();
        }
        else if (ResourceBank.GetResourceValue(requiredResourceType) != 0)
        {
            _currentResourceToConsume += ResourceBank.GetResourceValue(requiredResourceType);
            _gameController.score     += ResourceBank.GetResourceValue(requiredResourceType) * 5;
            ResourceBank.holdedResource[requiredResourceType] = 0;
            _gameController.UpdateScore();
        }
    }
示例#6
0
    void GatherResource()
    {
        if (_currentResource != null)
        {
            Resource type = _currentResource.resourceType;

            if (_timerSpentGathering >= _currentResource.gatherTime)
            {
                if (ResourceBank.GetResourceValue(type) > 45)
                {
                    _animText.text = "+" + (50 - ResourceBank.GetResourceValue(type)).ToString();
                }
                else
                {
                    _animText.text = "+5";
                }

                _animText.enabled = true;
                _animTextAnimator.SetBool("text", true);
                _animTextAnimator.Play("text", 0, 0);
                _currentResource.GatherResource(resourceGatheredPerShot);
                ResourceBank.AddResource(type, resourceGatheredPerShot);


                _timerSpentGathering = 0;
            }
            _timerSpentGathering += Time.deltaTime;
        }
    }
示例#7
0
        public void ResourceBank_Remove_RemovesProperQuantity()
        {
            ResourceBank cargo = new ResourceBank(20);

            cargo.Add(TestResource, 10);
            cargo.Remove(TestResource, 2);
            Assert.IsTrue(cargo[TestResource].Quantity == 8, "Does not remove proper quantity");
        }
示例#8
0
        public void ResourceBank_Add_ModifiesVolume()
        {
            ResourceBank cargo  = new ResourceBank(20);
            uint         curVol = cargo.Quantity;

            cargo.Add(TestResource);
            Assert.IsTrue(curVol != cargo.Quantity, "Does not modify volume");
        }
示例#9
0
    // Use this for initialization
    private void Start()
    {
        this._consumes = ResourceBank.Empty;
        this._consumes.Add(Resources.Power, 100);

        this._canStore = ResourceBank.Empty;
        this._canStore.Add(Resources.Heat, 2000);
        this._stores = this._canStore.GetEmptyCopy();
    }
示例#10
0
        public void ResourceBank_RemoveWorks()
        {
            ResourceBank bank = new ResourceBank(20);

            bank.Add(TestResource, 5);

            bank.Remove(TestResource, 2);
            Assert.IsTrue(bank[TestResource].Quantity != 5, "Does not reduce quantity");
        }
示例#11
0
 public ProductionBaySlot(RegeneratingBank pool, RegeneratingBank reserve, ResourceBank resources, uint seats)
 {
     Pool         = pool;
     Reserve      = reserve;
     Resources    = resources;
     Workers      = new CappedList <Citizen>(seats);
     WorkPairings = new Dictionary <Citizen, Ingredient <Resource> >( );
     Lineup       = new List <Recipe <Resource, Resource> >( );
 }
示例#12
0
 public ResearchBay(Location loc, uint occLimit, uint researcherLim, List <Knowledge> Supported, uint cargoSize, List <IPowerSource> energySources, uint maxEnergyDraw) : base(loc, occLimit)
 {
     SupportedResearches = new List <Knowledge>(Supported);
     Resources           = new ResourceBank(cargoSize);
     Recovering          = new List <Citizen>( );
     Researchers         = new CappedList <Citizen>(researcherLim);
     KnowledgeRepo       = new List <Knowledge>();
     EnergySources       = energySources;
     EnergyMaxDraw       = maxEnergyDraw;
 }
示例#13
0
        public void ResourceBank_Add_RespectsVolumeCapacity()
        {
            ResourceBank cargo = new ResourceBank(2);

            cargo.Add(TestResource);
            cargo.Add(TestResource);
            bool works = false;

            cargo.Add(TestResource, onFailure: () => works = true);
            Assert.IsTrue(works, "Does not respect volume capacity limits");
        }
示例#14
0
        // Use this for initialization
        private void Start()
        {
            _consumes = ResourceBank.Empty;
            _consumes.Add(Resources.Power, 100);
            _consumes.Add(Resources.Fuel, 1);

            _generates = ResourceBank.Empty;
            _generates.Add(Resources.Heat, 20);

            Color = new Color(1, 1, 1);
            GenerateStats();
        }
示例#15
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Enemy"))
     {
         Enemy enemy = collision.GetComponent <Enemy>();
         enemy.TakeDamage(10);
     }
     else
     {
         ResourceBank resourceBank = collision.GetComponent <ResourceBank>();
         if (resourceBank)
         {
             resourceBank.Damage(25);
         }
     }
 }
示例#16
0
        public void ResourceBank_AddWorks()
        {
            ResourceBank cargo = new ResourceBank(20);

            cargo.Add(TestResource);
            bool found = false;

            foreach (Resource res in cargo.Contents)
            {
                if (res.Identifier == TestResource.Identifier)
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "Resource was not added");
        }
示例#17
0
    public void SetResource(ResourceType type, int balance)
    {
        if (_resources.ContainsKey(type))
        {
            ResourceBank bank = _resources[type];
            if (bank != null)
            {
                if (bank.Balance > balance)
                {
                    bank.Subtract(Mathf.Clamp((bank.Balance - balance), 0, bank.UpperLimit));
                }
                else
                {
                    bank.Add(Mathf.Clamp((balance - bank.Balance), 0, bank.UpperLimit));
                }

                ResourceUpdated(type, bank.Balance, bank.UpperLimit);
            }
        }
    }
示例#18
0
    public bool SpendResources(ResourceType type, int amount)
    {
        if (_resources.ContainsKey(type))
        {
            ResourceBank bank = _resources[type];
            if (bank != null)
            {
                if (bank.Balance >= amount)
                {
                    bank.Subtract(amount);

                    ResourceUpdated(type, bank.Balance, bank.UpperLimit);

                    return(true);
                }
            }
        }

        return(false);
    }
示例#19
0
 public ResourceBank Take(ResourceBank maxAmount)
 {
     return maxAmount;
 }
示例#20
0
 private void Start()
 {
     this._generates = ResourceBank.Empty;
     this._generates.Add(Resources.Power, 1000);
 }
示例#21
0
 public ResourceBank Store(ResourceBank maxAmount)
 {
     _stores += maxAmount;
     return(ResourceBank.Empty);
 }
示例#22
0
 public ResourceBank Retrieve(ResourceBank maxAmount)
 {
     return(maxAmount);
 }
示例#23
0
 public ResourceBank Give(ResourceBank maxAmount)
 {
     return(ResourceBank.Empty);
 }
示例#24
0
 /// <summary>
 /// Called once per frame. It will empty out 10 percent of the heat per frame.
 /// </summary>
 private void Update()
 {
     _stores *= 0.9f;
 }
示例#25
0
 // Update is called once per frame
 void Update()
 {
     text.text = ResourceBank.GetResourceValue(resource).ToString();
 }
示例#26
0
 // Use this for initialization
 private void Start()
 {
     _canStore = ResourceBank.Empty;
     _canStore.Add(Resources.Fuel, 500);
     _stores = _canStore.GetCopy();
 }
示例#27
0
 /// <summary>
 /// Create a new ProductionBaySlot limiting the quantity of seats.
 /// </summary>
 /// <param name="pool">The pool of the ProductionBay</param>
 /// <param name="reserve">The reserve of the ProductionBay</param>
 /// <param name="resources"The ResourceBank of the ProductionBay></param>
 /// <param name="seats">The maximum amount of workers in the station</param>
 /// <param name="workers">The list of workers to grab from</param>
 /// <remarks>Note: If the list of workers is larger than the seat count, it'll just grab the first 'seats' quantity of workers</remarks>
 public ProductionBaySlot(RegeneratingBank pool, RegeneratingBank reserve, ResourceBank resources, uint seats, List <Citizen> workers)