Exemple #1
0
    public bool OnCommodityPlaced(Commodity _commodity, bool force = false)
    {
        if (owner != null && (/*(!force && !owner.available) || */ !owner.CheckCanLoad(_commodity)))
        {
            return(false);
        }

        UITarget otherTarget = _commodity.target;

        if (otherTarget != null)
        {
            otherTarget.UnloadCommodity();
        }
        if (loadedCommodity != null)
        {
            Commodity lastLoadedCommodity = loadedCommodity;
            UnloadCommodity();
            if (!force && otherTarget != null)
            {
                otherTarget.OnCommodityPlaced(lastLoadedCommodity);
            }
        }
        if (_commodity.lastTarget == null || stockID != _commodity.target.stockID)
        {
            _commodity.lastTarget = otherTarget;
        }
        _commodity.target = this;
        loadedCommodity   = _commodity;
        onCommodityPlaced?.Invoke(loadedCommodity);
        CommoditiesService.instance.RegisterCommodityPlacement();
        return(true);
    }
Exemple #2
0
    public void PopWorkForce()
    {
        Commodity spawnedWorkforce = workforces.Dequeue();

        spawnedWorkforce.gameObject.SetActive(true);
        if (workforces.Count < 5)
        {
            ReplenishPool();
        }

        spawnedWorkforce.rect.position = rect.position;
        spawnedWorkforce.StartLerp(workforcePopSpeed);
        workforceSlot.OnCommodityPlaced(spawnedWorkforce);
    }
    public void ProduceCommodity()
    {
        Recipe recipe = CommoditiesService.instance.GetCommodityByComponents(loadedCommodities);

        if (recipe != null && productionTarget.loadedCommodity == null)
        {
            CommoditySO             producedCommoditySO = recipe.result;
            Commodity               produceInstance     = CommoditiesService.instance.SpawnCommodity(producedCommoditySO);
            List <CommodityProfile> profiles            = (from commodity in loadedCommodities
                                                           select commodity.profile).ToList();
            produceInstance.TransferComponentsValue(profiles);
            productionTarget.OnCommodityPlaced(produceInstance);
            List <Commodity> toRemove = new List <Commodity>();
            foreach (Commodity component in loadedCommodities)
            {
                if (!component.OnUsed())
                {
                    toRemove.Add(component);
                }
            }
            loadedCommodities = (loadedCommodities.Where(x => !toRemove.Contains(x))).ToList();
            onCommodityProduced?.Invoke(producedCommoditySO);
            CommoditiesService.instance.CheckRecipes(recipe);
        }
        else if (recipe == null)
        {
            print("No produce from: ");
            for (var i = 0; i < loadedCommodities.Count; i++)
            {
                print(loadedCommodities[i].type);
            }
            List <Commodity> workforces = (from commodity in loadedCommodities
                                           where commodity.type.index == 1
                                           select commodity).ToList();
            if (ScenarioService.instance.workforceIntroduced && workforces.Count == 0)
            {
                errorMessage.LaunchError("Nécessite une force de travail !");
            }
            else
            {
                errorMessage.LaunchError("Ingrédients incorrects !");
            }
        }
        else
        {
            errorMessage.LaunchError("Retirez le produit précédent !");
            print("Clear the production space");
        }
    }
Exemple #4
0
    public void OnEndDrag(PointerEventData pointerEventData)
    {
        if (!draggable)
        {
            return;
        }
        List <RaycastResult> results = new List <RaycastResult>();

        UIService.instance.graphicRaycatser.Raycast(pointerEventData, results);

        foreach (RaycastResult result in results)
        {
            if (result.gameObject.CompareTag("Target"))
            {
                UITarget targetScript     = result.gameObject.GetComponent <UITarget>();
                Stock    stockCast        = targetScript.owner as Stock;
                Stock    currentStockCast = target.owner as Stock;
                if ((!ScenarioService.instance.inProductionPhase &&
                     //No direct movement from one base stock to another base stock
                     ((targetScript.stockID != target.stockID && stockCast != null && currentStockCast != null) ||
                      //No direct movement from left to right or from right to left
                      Mathf.Sign(target.stockID) != Mathf.Sign(targetScript.stockID) ||
                      //No direct movement from trade stock to a base stock from which the commodity doesn't orginate
                      (currentStockCast == null && stockCast != null && targetScript.stockID != lastTarget.stockID) ||
                      //No direct movement from base stock to trade stock if another base stock
                      //already has at least one commodity of its own inside
                      (currentStockCast != null && stockCast == null && target.stockID >= 0 &&
                       target.stockID != ExchangeService.instance.otherStockIndex && ExchangeService.instance.otherStockIndex != -1))))
                {
                    break;
                }
                if (targetScript.OnCommodityPlaced(this))
                {
                    break;
                }
            }
        }
        StartLerp();
    }
Exemple #5
0
 public void AutomaticMove()
 {
     if (ScenarioService.instance.inProductionPhase)
     {
         if ((target.owner == null && target.stockID == 1) || target.owner as Stock != null)
         {
             //Is in workslot or in stock
             CommoditiesService.instance.meanOfProduction.GetCommodities(this);
             print("Go to mean of production");
         }
         else
         {
             //Is in MoP
             if (lastTarget == null)
             {
                 //New produced commodity
                 CommoditiesService.instance.homeStock.GetCommodities(this);
                 print("Go to stock");
             }
             else if (lastTarget.owner != null)
             {
                 //Was in stock, then go to stock
                 Stock stock = lastTarget.owner as Stock;
                 stock.GetCommodities(this);
                 print("Go to stock");
             }
             else
             {
                 //Was in worlslot, then go to worlslot
                 StartLerp();
                 lastTarget.OnCommodityPlaced(this);
                 print("Go to workslot");
             }
         }
     }
     else
     {
         if (target.owner as TradingStock != null)
         {
             //Is in trading stock
             Stock stock = lastTarget.owner as Stock;
             stock.GetCommodities(this);
             print("Go to stock");
         }
         else
         {
             //Is in stock
             if (target.stockID == -1)
             {
                 //Move to home trading stock
                 ExchangeService.instance.GetCommodities(this, true);
                 print("Go to home trading stock");
             }
             else if (target.stockID == ExchangeService.instance.otherStockIndex || ExchangeService.instance.otherStockIndex == -1)
             {
                 //Move to other trading stock
                 ExchangeService.instance.GetCommodities(this, false);
                 print("Go to other trading stock");
             }
         }
     }
 }