/// <summary>
        /// Is called when amount of cargo received
        /// </summary>
        /// <param name="cargo"></param>
        private void OnCargoReceived(CargoController cargo)
        {
            OilType type = cargo.GetCargoType();

            if (type == OilType.CrudeOil)
            {
                //2 things happen, store and extract
                if (storing)
                {
                    int value = cargo.GetAmount();
                    //fill
                    if (value != 0)
                    {
                        FillOil(value);
                    }

                    storing = false;
                }
                else if (!storing)
                {
                    int value = cargo.CheckEmpty();
                    //extract

                    if (value != 0)
                    {
                        ExtractOil(value);
                    }

                    storing = true;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This function is called when the object becomes enabled and active.
        /// </summary>
        private void OnEnable()
        {
            oilModel          = new CargoModel();
            processedModel    = new CargoModel();
            oilCapacity       = oilView.GetAmount();
            processedCapacity = processedView.GetAmount();
            //default type
            oilModel.Initialize(oilCapacity, OilType.CrudeOil, true);
            processedModel.Initialize(processedCapacity, OilType.ProcessedOil, false);
            TurnOff();
            Reset();
            typeMessage = MessageBroker.Default.Receive <CargoTypeMessage>().Subscribe(message =>
            {
                OilType cargoType = message.Type;
                SetCargoType(cargoType);
            }).AddTo(this);
            this.UpdateAsObservable().Subscribe(_ =>
            {
                oilView.SetPosition(truckTransform);
                processedView.SetPosition(truckTransform);
            })
            .AddTo(this);


            cargoRequestMessage = MessageBroker.Default.Receive <CargoRequestMessage>().Subscribe(message =>
            {
                message.Cargo.Invoke(GetComponent <CargoController>());
            })
                                  .AddTo(this);
        }
        /// <summary>
        /// Is called when amount of cargo received
        /// </summary>
        /// <param name="cargo"></param>
        private void OnCargoReceived(CargoController cargo)
        {
            int     value     = cargo.GetAmount();
            int     emptySlot = CheckEmpty();
            OilType type      = cargo.GetCargoType();

            if (value != 0 && emptySlot > 0 && type == OilType.CrudeOil)
            {
                FillOil(value);
            }
            else if (type != OilType.CrudeOil)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.WrongType
                });
            }
            else if (value == 0 && type == OilType.CrudeOil)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.CargoEmpty
                });
            }
            else if (value != 0 && emptySlot == 0 && type == OilType.CrudeOil)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.RefineryFull
                });
            }
        }
예제 #4
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            OilType oilType = db.OilTypes.Find(id);

            db.OilTypes.Remove(oilType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #5
0
        /// <summary>
        /// Is called to check if the received cargo match the order
        /// </summary>
        /// <param name="cargoDestination"></param>
        /// <param name="cargoOilType"></param>
        /// <param name="cargoAmount"></param>
        private void CheckOrder(ResidenceType cargoDestination, OilType cargoOilType, int cargoAmount)
        {
            int index = 0;
            bool isWrongDestination = true;
            foreach (var order in orders)
            {
                if (cargoDestination == order.GetDestination() && cargoOilType == order.GetOrder())
                {
                    int orderAmount = order.GetAmount();
                    int deliveredAmount = 0;
                    while (orderAmount != 0)
                    {
                        deliveredAmount++;
                        cargoAmount--;
                        orderAmount--;

                        if (cargoAmount == 0)
                        {
                            break;
                        }
                    }

                    if (orderAmount != 0)
                    {
                        order.SetOrder(order.GetOrder(), orderAmount);
                    }
                    else if (orderAmount == 0)
                    {
                        //order done, publish reward, remove this order
                        order.StopTimer();
                        orders.RemoveAt(index);
                        StartDespawnAnimation(order);
                        IncreaseScore(3);
                    }

                    //decrease cargo with delivered amount
                    MessageBroker.Default.Publish(new TakeCargoMessage()
                    {
                        Amount = deliveredAmount,
                        Type = cargoOilType
                    });
                    isWrongDestination = false;
                    break;
                }

                index++;
            }

            if (isWrongDestination)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.WrongDestination
                });
            }
        }
예제 #6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] OilType oilType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(oilType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(oilType));
 }
예제 #7
0
        public ActionResult Create([Bind(Include = "OilTypeID,OilTypeName")] OilType oilType)
        {
            if (ModelState.IsValid)
            {
                db.OilTypes.Add(oilType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(oilType));
        }
예제 #8
0
        public static string PaintTypeFormat(OilType oilType)
        {
            switch (oilType)
            {
            case OilType.Clear: return(ConstString.PAINTTYPE_DOOR_Clear);

            case OilType.Mixed: return(ConstString.PAINTTYPE_DOOR_Mix);

            default: throw new Exception("PaintTypeFormat error");
            }
        }
예제 #9
0
 /// <summary>
 /// Set cargo type
 /// </summary>
 /// <param name="type"></param>
 private void SetCargoType(OilType type)
 {
     if (type == OilType.CrudeOil)
     {
         TurnOnOil();
     }
     else if (type == OilType.ProcessedOil)
     {
         TurnOnProcessed();
     }
 }
예제 #10
0
 /// <summary>
 /// Check if the delivered same as the requested order
 /// </summary>
 /// <param name="oil"></param>
 /// <param name="amount"></param>
 private void CheckOrder(OilType oil, int amount)
 {
     if (amount > 0)
     {
         MessageBroker.Default.Publish(new CheckOrderMessage()
         {
             Amount    = amount,
             Residence = GetBuildingType(),
             Oil       = oil
         });
     }
 }
예제 #11
0
        /// <summary>
        /// Set oil type for the order
        /// </summary>
        /// <param name="oil"></param>
        public void SetOrder(OilType oil, int value)
        {
            string oiltype = "";

            if (oil == OilType.CrudeOil)
            {
                oiltype = "Crude oil";
            }

            orderView.SetOrder(oiltype, value);
            orderModel.SetOrder(oil);
            orderModel.SetAmount(value);
        }
예제 #12
0
        // GET: OilTypes/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OilType oilType = db.OilTypes.Find(id);

            if (oilType == null)
            {
                return(HttpNotFound());
            }
            return(View(oilType));
        }
예제 #13
0
        /// <summary>
        /// get current type of cargo
        /// </summary>
        /// <returns></returns>
        public OilType GetCargoType()
        {
            OilType result = OilType.CrudeOil;

            if (oilModel.IsActive())
            {
                result = OilType.CrudeOil;
            }
            else if (processedModel.IsActive())
            {
                result = OilType.ProcessedOil;
            }

            return(result);
        }
        /// <summary>
        /// Is called when amount of cargo received
        /// </summary>
        /// <param name="cargo"></param>
        private void OnCargoReceived(CargoController cargo)
        {
            int     value = cargo.CheckEmpty();
            OilType type  = cargo.GetCargoType();

            if (value != 0 && type == OilType.ProcessedOil)
            {
                ExtractOil(value);
            }
            else if (type != OilType.ProcessedOil)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.WrongType
                });
            }
            else if (value == 0 && type == OilType.ProcessedOil)
            {
                MessageBroker.Default.Publish(new NotificationMessage()
                {
                    Warning = NotificationType.CargoFull
                });
            }
        }
예제 #15
0
 public JointKey(string category, string type, OilType oilType)
 {
     Category  = category;
     Type      = type;
     PaintType = PaintTypeFormat(oilType);
 }
예제 #16
0
 /// <summary>
 /// Set oil type for the order
 /// </summary>
 /// <param name="oil"></param>
 public void SetOrder(OilType type)
 {
     oil = type;
 }
예제 #17
0
 public void OnNavigatedTo(NavigationContext navigationContext)
 {
     equipments = new ObservableCollection <Oil>(Oil.getEquipment());;
     oilTypes   = OilType.getOilTypes();
 }
예제 #18
0
 /// <summary>
 /// Set cargo type
 /// </summary>
 /// <param name="oilType"></param>
 public void SetCargoType(OilType oilType)
 {
     type = oilType;
 }
예제 #19
0
 /// <summary>
 /// Is used to initialize the data model
 /// </summary>
 /// <param name="amount"></param>
 public void Initialize(int amount, OilType oilType, bool active)
 {
     oils      = new bool[amount];
     type      = oilType;
     activated = active;
 }
예제 #20
0
        /// <summary>
        /// Start is called on the frame when a script is enabled just before
        /// any of the Update methods is called the first time.
        /// </summary>
        private void Start()
        {
            orders = new List<OrderController>();
            speed = 1;
            panelWidth = orderPanel.rectTransform().sizeDelta.x;
            panelHeight = orderPanel.rectTransform().sizeDelta.y;
            panelXpos = orderPanel.rectTransform().anchoredPosition.x;
            panelYpos = orderPanel.rectTransform().anchoredPosition.y;
            int randomValue = Random.Range(minTime, maxTime);

            MessageBroker.Default.Receive<AppStateMessage>().Subscribe(message =>
            {
                if (message.AppState == AppState.PlayGame)
                {
                    //use order spawn service to spawn new
                    timerMessage = MessageBroker.Default.Receive<TimerMessage>().Subscribe(tick =>
                    {
                        //first spawn
                        if (orders.Count <= 0)
                        {
                            SpawnOrder(OrderType.normal, orderPanel.transform);
                            randomValue = Random.Range(minTime, maxTime);
                        }

                        if (orders.Count < 3)
                        {
                            if (randomValue <= 0)
                            {
                                SpawnOrder(OrderType.normal, orderPanel.transform);
                                randomValue = Random.Range(minTime, maxTime);
                            }

                            randomValue--;
                        }
                    }).AddTo(this);
                }
                else
                {
                    timerMessage?.Dispose();
                    DespawnOrder(null);
                    orders.Clear();
                }
            }).AddTo(this);

            MessageBroker.Default.Receive<OrderTimesUpMessage>().Subscribe(message =>
            {
                if (message.TimesUp)
                {
                    int index = 0;
                    foreach (var order in orders)
                    {
                        if (order.GetTime() <= 0)
                        {
                            orders.RemoveAt(index);
                            StartDespawnAnimation(order);
                            DecreaseScore(1);
                            break;
                        }

                        index++;
                    }
                }
            }).AddTo(this);

            MessageBroker.Default.Receive<CheckOrderMessage>().Subscribe(message =>
            {
                int cargoAmount = message.Amount;
                OilType cargoOilType = message.Oil;
                ResidenceType cargoDestination = message.Residence;

                Debug.Log(cargoDestination);

                CheckOrder(cargoDestination, cargoOilType, cargoAmount);
            }).AddTo(this);
        }
예제 #21
0
 /// <summary>
 /// Is used to set type of oil for an order
 /// </summary>
 /// <param name="order"></param>
 /// <param name="oil"></param>
 private void SetOrder(OrderController order, OilType oil, int amount)
 {
     order.SetOrder(oil, amount);
 }