コード例 #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
ファイル: ResourceCollector.cs プロジェクト: jeepitou/USPS
    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
ファイル: Heatsink.cs プロジェクト: arlyon/darkflight
    // 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
ファイル: Generator.cs プロジェクト: arlyon/darkflight
 public ResourceBank Take(ResourceBank maxAmount)
 {
     return maxAmount;
 }
コード例 #20
0
ファイル: Generator.cs プロジェクト: arlyon/darkflight
 private void Start()
 {
     this._generates = ResourceBank.Empty;
     this._generates.Add(Resources.Power, 1000);
 }
コード例 #21
0
ファイル: Heatsink.cs プロジェクト: arlyon/darkflight
 public ResourceBank Store(ResourceBank maxAmount)
 {
     _stores += maxAmount;
     return(ResourceBank.Empty);
 }
コード例 #22
0
ファイル: Heatsink.cs プロジェクト: arlyon/darkflight
 public ResourceBank Retrieve(ResourceBank maxAmount)
 {
     return(maxAmount);
 }
コード例 #23
0
ファイル: Heatsink.cs プロジェクト: arlyon/darkflight
 public ResourceBank Give(ResourceBank maxAmount)
 {
     return(ResourceBank.Empty);
 }
コード例 #24
0
ファイル: Heatsink.cs プロジェクト: arlyon/darkflight
 /// <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)