Exemplo n.º 1
0
    private Dictionary <ConsumableData, int> GetConsumablesInStockCountByNeed() ///
    {
        Dictionary <ConsumableData, int> counts = new Dictionary <ConsumableData, int>();

        foreach (ConsumableRate conNeed in consumablesNeed)
        {
            counts.Add(conNeed.Resource, 0);
        }
        RoomResources rc = GetRoomResourcesForType(consumablesType);

        if (rc != null)
        {
            foreach (ICard card in rc.cards)
            {
                if (card is ConsumableCard cardC)
                {
                    if (counts.ContainsKey(cardC.ConsumableData))
                    {
                        counts[cardC.ConsumableData] += cardC.Amount;
                    }
                }
            }
            foreach (ConsumableRate conNeed in consumablesNeed)
            {
                counts[conNeed.Resource] = Mathf.Min(counts[conNeed.Resource], conNeed.amountRate);
            }
        }
        return(counts);
    }
Exemplo n.º 2
0
    public bool WithdrawCard(ICard card) ///
    {
        if (card.type != resourceType && card.type.Parent != resourceType)
        {
            return(false);
        }
        RoomResources rc = GetRoomResourcesForType(card.type);

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

        if (card is ICardWithParameters cardP)
        {
            sum = cardP.GetSumByParam(Designation.value);
            RemoveResourceFromDetecting(card);
        }
        else if (card is IExpendable cardE)
        {
            sum = cardE.Amount;
        }
        if (sum != 0)
        {
            rc.general   -= sum;
            rc.available -= sum;
            resourcesChanged.Invoke(rc.general, rc.available, card.type);
        }
        window.RemoveResourceCard(card);
        return(true);
    }
Exemplo n.º 3
0
    public bool HasCard(ICard card) ///
    {
        if (card.type != resourceType && card.type.Parent != resourceType)
        {
            return(false);
        }
        RoomResources rc = GetRoomResourcesForType(card.type);

        return(rc == null ? false : rc.cards.Contains(card));
    }
Exemplo n.º 4
0
    public int GetCardsCount(CardType type) ///
    {
        int           count = 0;
        RoomResources rc    = GetRoomResourcesForType(type);

        if (rc != null)
        {
            count = rc.cards.Count;
        }
        return(count);
    }
Exemplo n.º 5
0
    public void ReleaseResource(ICard card) ///
    {
        IHoldable           cardH = card as IHoldable;
        ICardWithParameters cardP = card as ICardWithParameters;
        RoomResources       rc    = GetRoomResourcesForType(card.type);

        if (rc != null && cardH != null && cardP != null && rc.cards.SingleOrDefault(c => c == card) != null)
        {
            int sum = cardP.GetSumByParam(Designation.value);
            rc.available += sum;
            resourcesChanged.Invoke(rc.general, rc.available, card.type);
            cardH.Release();
        }
    }
Exemplo n.º 6
0
    public void OccupyResource(ICard card) ///
    {
        Debug.Log("occupy resource1");
        IHoldable           cardH = card as IHoldable;
        ICardWithParameters cardP = card as ICardWithParameters;
        RoomResources       rc    = GetRoomResourcesForType(card.type);

        if (rc != null && cardH != null && cardP != null && rc.cards.SingleOrDefault(c => c == card) != null)
        {
            Debug.Log("occupy resource2");
            int sum = cardP.GetSumByParam(Designation.value);
            rc.available -= sum;
            resourcesChanged.Invoke(rc.general, rc.available, card.type);
            cardH.Hold();
        }
    }
Exemplo n.º 7
0
    public void OccupyAmountedResources() ///
    {
        List <ICard> cardsToDelete;

        foreach (MagicClass m in magicResources)
        {
            int           rest = m.spended;
            RoomResources rc   = GetRoomResourcesForType(consumablesType);
            if (rc != null)
            {
                cardsToDelete = new List <ICard>();
                foreach (ICard card in rc.cards)
                {
                    if (rest == 0)
                    {
                        break;
                    }
                    if (card is ConsumableCard cardC)
                    {
                        if (cardC.ConsumableData == m.Resource)
                        {
                            int minAmount = cardC.Amount > rest ? rest : cardC.Amount;
                            cardC.Expend(minAmount);
                            rc.available -= minAmount;
                            rc.general   -= minAmount;
                            rest         -= minAmount;
                            if (cardC.Amount == 0)
                            {
                                window.RemoveResourceCard(card);
                                cardsToDelete.Add(card);
                            }
                        }
                    }
                }
                foreach (ICard card in cardsToDelete)
                {
                    rc.cards.Remove(card);
                }
                resourcesChanged.Invoke(rc.general, rc.available, consumablesType);
            }
        }
        magicResources = new List <MagicClass>();
    }
Exemplo n.º 8
0
    public void AddCard(ICard card) ///
    {
        if (card.type != resourceType && card.type.Parent != resourceType)
        {
            return;
        }
        RoomResources rc = GetRoomResourcesForType(card.type);

        if (rc == null)
        {
            rc = new RoomResources();
            resourcesCards.Add(rc);
            rc.type = card.type;
        }
        rc.cards.Add(card);

        int sum = 0;

        if (card is ICardWithParameters cardP)
        {
            sum = cardP.GetSumByParam(Designation.value);
            AddResourceToDetect(card);
        }
        else if (card is IExpendable cardE)
        {
            sum = cardE.Amount;
        }
        if (sum != 0)
        {
            rc.general   += sum;
            rc.available += sum;
            Debug.Log("card sum = " + sum);
            resourcesChanged.Invoke(rc.general, rc.available, card.type);
        }
        GameObject cardObject = window.AddResourceCard(card);

        cardObject.GetComponent <ResourceCardFormatter>()?.UpdateParamsDisplayed(Designation.value);
        // else if (card.type == taskType || card.type.Parent == taskType)
        // {
        //     TaskCard cardData = (TaskCard)card;
        //     taskCards.Add(card);
        // }
    }
Exemplo n.º 9
0
    public List <ICard> GetAvailableResourcesCardsByType(CardType type) ///
    {
        RoomResources rc     = GetRoomResourcesForType(type);
        List <ICard>  result = new List <ICard>();

        if (rc != null)
        {
            foreach (ICard c in rc.cards)
            {
                if (c is IHoldable cardH)
                {
                    if (cardH.Available)
                    {
                        result.Add(c);
                    }
                }
            }
        }

        return(result);
    }
        public async Task <int> SyncRoomWithFapAsync(FptFapClient fapClient)
        {
            var rooms = await fapClient.GetAllRooms();

            var area3Rooms = rooms.Where(o => o.AreaId == 3).ToList();

            foreach (var r in area3Rooms)
            {
                var  existed = Rooms.Code(r.RoomNo).Any();
                Room entity  = r.ToRoom();
                if (existed)
                {
                    var oldRes = RoomResources.OfRoom(entity.Code).ToList();
                    DeleteRoomServices(oldRes);
                    context.Room.Update(entity);
                }
                else
                {
                    context.Room.Add(entity);
                }
            }
            return(area3Rooms.Count);
        }