コード例 #1
0
        public bool WithdrawCard(ICard card, int currentDay)
        {
            DepartmentResources dr = GetResourcesForType(card.type);

            if (!dr.Cards.Remove(card))
            {
                return(false);
            }
            int sum = 0;

            if (card is ICardWithParameters cardP)
            {
                sum = cardP.GetSumByParam(DepartmentParameter);
                RemoveResourceFromDetecting(card, currentDay);
            }
            else if (card is IExpendable cardE)
            {
                sum = cardE.Amount;
            }
            if (sum != 0)
            {
                dr.General   -= sum;
                dr.Available -= sum;
                ResourcesChanged(dr);
            }
            return(true);
        }
コード例 #2
0
        public DepartmentResources GetResourcesForType(CardType type, bool create = false)
        {
            DepartmentResources dr = _resourcesCards.SingleOrDefault(c => c.Type == type);

            if (dr == null && create)
            {
                dr = new DepartmentResources();
                _resourcesCards.Add(dr);
                dr.Type = type;
            }
            return(dr);
        }
コード例 #3
0
        public void ReleaseResource(ICard card)
        {
            IHoldable           cardH = card as IHoldable;
            ICardWithParameters cardP = card as ICardWithParameters;
            DepartmentResources dr    = GetResourcesForType(card.type);

            if (dr != null && cardH != null && cardP != null && dr.Cards.SingleOrDefault(c => c == card) != null)
            {
                int sum = cardP.GetSumByParam(DepartmentParameter);
                dr.Available += sum;
                ResourcesChanged(dr);
                cardH.Release();
            }
        }
コード例 #4
0
        public void OccupyResource(ICard card)
        {
            IHoldable           cardH = card as IHoldable;
            ICardWithParameters cardP = card as ICardWithParameters;
            DepartmentResources rc    = GetResourcesForType(card.type);

            if (rc != null && cardH != null && cardP != null && rc.Cards.SingleOrDefault(c => c == card) != null)
            {
                int sum = cardP.GetSumByParam(DepartmentParameter);
                rc.Available -= sum;
                ResourcesChanged(rc);
                cardH.Hold();
            }
        }
コード例 #5
0
        public List <ICard> GetAvailableResources(CardType type)
        {
            DepartmentResources dr     = GetResourcesForType(type);
            List <ICard>        result = new List <ICard>();

            if (dr == null)
            {
                return(result);
            }
            foreach (ICard c in dr.Cards)
            {
                if (c is IHoldable cardH)
                {
                    if (cardH.Available)
                    {
                        result.Add(c);
                    }
                }
            }
            return(result);
        }
コード例 #6
0
        public void OccupyAmountedResources()
        {
            if (_consumablesCards.Count == 0)
            {
                return;
            }
            DepartmentResources   dr            = GetResourcesForType(_consumablesCards[0].type);
            List <ConsumableCard> cardsToDelete = new List <ConsumableCard>();

            foreach (ConsumableToExpend cons in CurrentConsExpending.ExpendList)
            {
                int rest = cons.Spended;
                foreach (ConsumableCard card in _consumablesCards)
                {
                    if (rest <= 0)
                    {
                        break;
                    }
                    if (card.ConsumableData == cons.Resource)
                    {
                        int minAmount = Math.Min(card.Amount, rest);
                        card.Expend(minAmount);
                        rest -= minAmount;
                        //need to call remove card in display?
                        if (card.Amount == 0)
                        {
                            cardsToDelete.Add(card);
                        }
                    }
                }
                foreach (ConsumableCard card in cardsToDelete)
                {
                    dr.Cards.Remove(card);
                }
            }
            ResourcesChanged(dr);
            CurrentConsExpending = null;
        }
コード例 #7
0
        public void AddCard(ICard card, int currentDay)
        {
            DepartmentResources dr = GetResourcesForType(card.type, true);

            dr.Cards.Add(card);

            int sum = 0;

            if (card is ICardWithParameters cardP)
            {
                sum = cardP.GetSumByParam(DepartmentParameter);
                AddResourceToDetect(card, currentDay);
            }
            else if (card is IExpendable cardE)
            {
                sum = cardE.Amount;
            }
            if (sum != 0)
            {
                dr.General   += sum;
                dr.Available += sum;
                ResourcesChanged(dr);
            }
        }
コード例 #8
0
        //***RESOURCES***//
        public bool HasCard(ICard card)
        {
            DepartmentResources dr = GetResourcesForType(card.type);

            return(dr == null ? false : dr.Cards.Contains(card));
        }