/// <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; } } }
/// <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 }); } }
public ActionResult DeleteConfirmed(Guid id) { OilType oilType = db.OilTypes.Find(id); db.OilTypes.Remove(oilType); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <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 }); } }
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)); }
public ActionResult Create([Bind(Include = "OilTypeID,OilTypeName")] OilType oilType) { if (ModelState.IsValid) { db.OilTypes.Add(oilType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(oilType)); }
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"); } }
/// <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(); } }
/// <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 }); } }
/// <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); }
// 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)); }
/// <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 }); } }
public JointKey(string category, string type, OilType oilType) { Category = category; Type = type; PaintType = PaintTypeFormat(oilType); }
/// <summary> /// Set oil type for the order /// </summary> /// <param name="oil"></param> public void SetOrder(OilType type) { oil = type; }
public void OnNavigatedTo(NavigationContext navigationContext) { equipments = new ObservableCollection <Oil>(Oil.getEquipment());; oilTypes = OilType.getOilTypes(); }
/// <summary> /// Set cargo type /// </summary> /// <param name="oilType"></param> public void SetCargoType(OilType oilType) { type = oilType; }
/// <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; }
/// <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); }
/// <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); }