Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        _job  = null;
        _jobm = null;

        GameObject canvas = GameObject.Find("Canvas");

        _objUi = Instantiate(_grocuiPrefab, canvas.GetComponent <Transform>());
        _objUi.GetComponent <GroceryUi>().SetGrocery(this);

        _mpReskCRes = new Dictionary <RESOURCEK, int>();
        _mpReskCRes[RESOURCEK.Food]    = 0;
        _mpReskCRes[RESOURCEK.WarmBed] = 0;
        _mpReskCRes[RESOURCEK.Work]    = 0;

        switch (_grock)
        {
        case GROCERYK.Apples:
        case GROCERYK.Broccoli:
            _mpReskCRes[RESOURCEK.Food] = _width * _height * CFoodPerSlotFromGrock(_grock);;
            break;

        case GROCERYK.Milk:
        case GROCERYK.Jar:
        case GROCERYK.Eggs:
            break;
        }
    }
Esempio n. 2
0
        public DeliveryDto New(int jobID, int empid)
        {
            string  name    = ctx.Employee.Find(empid).firstname + ' ' + ctx.Employee.Find(empid).lastname;
            JobSite jobsite = ctx.JobSite.Where(p => p.JobID == jobID).FirstOrDefault();

            Delivery newEntity = new Delivery
            {
                JobID        = jobID,
                JobSiteID    = jobsite.JobSiteID,
                DeliveryDate = DateTime.Now,
                EmployeeID   = empid
            };

            ctx.Delivery.Add(newEntity);
            ctx.SaveChanges();

            DeliveryDto dto = new DeliveryDto
            {
                JobID        = newEntity.JobID,
                DeliveryDate = newEntity.DeliveryDate,
                EmployeeID   = newEntity.EmployeeID,
                DriverName   = name,
                JobSiteID    = newEntity.JobSiteID
            };

            return(dto);
        }
Esempio n. 3
0
        public ActionResult Edit([Bind(Include = "SiteName,JobSiteID,Address,Town,State,Zip,Lat,Long")] JobSite jobSite)
        {
            if (ModelState.IsValid)
            {
                db.Entry(jobSite).State = EntityState.Modified;

                //Query the API for new coordinates upon changes to any properties that actually change the address.
                var entry   = db.Entry(jobSite);
                var changed = entry.CurrentValues.PropertyNames.Where(x => entry.Property(x).IsModified);
                if (changed.Contains("Address") || changed.Contains("Town") || changed.Contains("State") || changed.Contains("Zip"))
                {
                    var validateZipCode = FormAPIZipCodeService.ValidateZipCode(jobSite.Zip, jobSite.State.GetDisplayName(), jobSite.Town);

                    if (validateZipCode.Successful)
                    {
                        var geoCode = OpenGeocodingService.GetGeocode(jobSite.Address, jobSite.Town, jobSite.State.GetDisplayName(), jobSite.Zip);

                        jobSite.Lat  = geoCode.Return.Geocode.DecimalLatitude;
                        jobSite.Long = geoCode.Return.Geocode.DecimalLongitude;

                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Zip", validateZipCode.Return.ErrorMessage);
                    }
                }
            }
            return(View(jobSite));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "SiteName,JobSiteID,Address,Town,State,Zip,Lat,Long")] JobSite jobSite)
        {
            if (ModelState.IsValid)
            {
                var validateZipCode = FormAPIZipCodeService.ValidateZipCode(jobSite.Zip, jobSite.State.GetDisplayName(), jobSite.Town);

                if (validateZipCode.Successful)
                {
                    var geoCode = OpenGeocodingService.GetGeocode(jobSite.Address, jobSite.Town, jobSite.State.GetDisplayName(), jobSite.Zip);

                    jobSite.Lat  = geoCode.Return.Geocode.DecimalLatitude;
                    jobSite.Long = geoCode.Return.Geocode.DecimalLongitude;

                    db.JobSites.Add(jobSite);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Zip", validateZipCode.Return.ErrorMessage);
                }
            }

            return(View(jobSite));
        }
Esempio n. 5
0
    public Task(JobSite job, TASKK taskk)
    {
        _taskk = taskk;
        _job   = job;

        // Claim the resources now so that I'm guaranteed to get it
        switch (_taskk)
        {
        case TASKK.EatFood:
        case TASKK.CollectFood:
        {
            bool fClaimed = _job.FTryClaimResource(RESOURCEK.Food);
            Debug.Assert(fClaimed);
            break;
        }

        case TASKK.GetWarm:
        {
            bool fClaimed = _job.FTryClaimResource(RESOURCEK.WarmBed);
            Debug.Assert(fClaimed);
            break;
        }

        case TASKK.StoreFood:
        case TASKK.Work:
            break;
        }
    }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] JobSite jobSite)
        {
            if (id != jobSite.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(jobSite);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!JobSiteExists(jobSite.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(jobSite));
        }
Esempio n. 7
0
        public ActionResult CreateAjax([Bind(Include = "SiteName,JobSiteID,Address,Town,State,Zip,Lat,Long")] JobSite jobSite)
        {
            if (ModelState.IsValid)
            {
                var validateZipCode = FormAPIZipCodeService.ValidateZipCode(jobSite.Zip, jobSite.State.GetDisplayName(), jobSite.Town);

                // the following logic is setup to bypass the 509 error code from the FormAPIZipCodeService.
                // It may seem counter intutative, but it first checks if it was unsucessful, and if so, if it was a 509
                // error. if it's a 509, then it adds to the database anyway, if not, it reports the error to the form,
                // and it if it was successful, then it jumps to the add database label using the goto/label.

                if (!validateZipCode.Successful)
                {
                    if (validateZipCode.Return.ErrorMessage.Contains("509"))
                    {
                        //509 error is bandwidth limit exceeded or rather, that the api server itself is busy.
                        var geoCode = OpenGeocodingService.GetGeocode(jobSite.Address, jobSite.Town, jobSite.State.GetDisplayName(), jobSite.Zip);

                        jobSite.Lat  = geoCode.Return.Geocode.DecimalLatitude;
                        jobSite.Long = geoCode.Return.Geocode.DecimalLongitude;

                        db.JobSites.Add(jobSite);
                        db.SaveChanges();
                        return(Json(new { success = "true", jobSite_Text = jobSite.SiteName, jobSite_Value = jobSite.JobSiteID }));
                    }
                    else
                    {
                        // invalid zip code
                        // add error to zip field
                        ModelState.AddModelError("Zip", validateZipCode.Return.ErrorMessage);

                        // return json with false success, and pass in the field name and errors
                        return(Json(new { success = "false", errors = ExtractErrors(ViewData.ModelState) }));
                    }
                }
                else
                {
                    var geoCode = OpenGeocodingService.GetGeocode(jobSite.Address, jobSite.Town, jobSite.State.GetDisplayName(), jobSite.Zip);

                    jobSite.Lat  = geoCode.Return.Geocode.DecimalLatitude;
                    jobSite.Long = geoCode.Return.Geocode.DecimalLongitude;

                    db.JobSites.Add(jobSite);
                    db.SaveChanges();
                    return(Json(new { success = "true", jobSite_Text = jobSite.SiteName, jobSite_Value = jobSite.JobSiteID }));
                }
            }
            else
            {
                // invalid form
                // return json with false success, and pass in the field name and errors
                return(Json(new { success = "false", errors = ExtractErrors(ViewData.ModelState) }));
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] JobSite jobSite)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jobSite);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(jobSite));
        }
Esempio n. 9
0
        public IHttpActionResult Post([FromBody] JobSite entity)
        {
            try
            {
                _JobSiteSvc.Create(entity);
                _data.SaveChanges();
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            return(Created(entity));
        }
Esempio n. 10
0
        public IHttpActionResult Patch([FromBody] JobSite entity)
        {
            try
            {
                if (!_JobSiteSvc.Update(entity))
                {
                    return(NotFound());
                }
                _data.SaveChanges();
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            return(Updated(entity));
        }
Esempio n. 11
0
    public void SetDesignation(DESIGNATIONK desk)
    {
        if (desk != DESIGNATIONK.None)
        {
            _desk = desk;
        }

        if (_job != null)
        {
            switch (_job._jobk)
            {
            case JOBK.Build:
                break;

            case JOBK.StoreFood:
                _mpReskCRes[RESOURCEK.Food] = _job._mpReskCRes[RESOURCEK.Food];
                break;

            case JOBK.CollectFood:
                _mpReskCRes[RESOURCEK.Food] = _job._mpReskCRes[RESOURCEK.Food];
                break;

            case JOBK.WarmHome:
                break;
            }

            _jobm.RemoveJob(_job);
            _job = null;
        }

        // if (_objBuilding != null)
        // {
        //     Destroy(_objBuilding);
        //     _objBuilding = null;
        // }
    }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        if (_jobm == null)
        {
            _jobm = GameObject.Find("Game Manager").GetComponent <Game>()._jobManager;
        }

        if (_tDying != -1.0f && Time.time - _tDying > 10.0f)
        {
            GroceryManager grocm = GameObject.Find("Game Manager").GetComponent <Game>()._grocm;
            grocm.DestroyGrocery(gameObject);
        }

        if (_job == null && _desk != DESIGNATIONK.None)
        {
            Vector3 vecDoorOffset = new Vector3((int)(((_width * 0.5f) - 1)) + 0.5f, 0.0f, 0.0f);
            switch (_desk)
            {
            case DESIGNATIONK.StoreFood:
                _job = new JobSite(JOBK.StoreFood, transform, vecDoorOffset);
                _job._mpReskCResLimit[RESOURCEK.Food] = _width * _height * CFoodPerSlotFromGrock(_grock);
                break;

            case DESIGNATIONK.CollectFood:
                _job = new JobSite(JOBK.CollectFood, transform, vecDoorOffset);
                _job._mpReskCRes[RESOURCEK.Food]      = _mpReskCRes[RESOURCEK.Food];
                _job._mpReskCResLimit[RESOURCEK.Food] = _width * _height * CFoodPerSlotFromGrock(_grock);
                break;

            case DESIGNATIONK.BuildHomes:
                _job = new JobSite(JOBK.Build, transform, vecDoorOffset);
                _job._mpReskCResLimit[RESOURCEK.Work] = _width * _height * CWorkRequiredPerSlotFromGrock(_grock);
                break;
            }

            _jobm.AddJob(_job);
            Debug.Log("Job Manager adding Job: ");
        }

        if (_desk == DESIGNATIONK.None)
        {
            return;
        }

        switch (_desk)
        {
        case DESIGNATIONK.StoreFood:
        {
            Debug.Assert(_job._jobk == JOBK.StoreFood);

            GroceryManager grocm = GameObject.Find("Game Manager").GetComponent <Game>()._grocm;

            if (_objBuilding == null)
            {
                GameObject prefabBuildingType = grocm._lPrefabBuildingType[UnityEngine.Random.Range(0, grocm._lPrefabBuildingType.Count)];
                _objBuilding = Instantiate(prefabBuildingType, transform.position, transform.rotation, transform);
                _objBuilding.GetComponent <Building>().mBuildingWidth  = _width;
                _objBuilding.GetComponent <Building>().mBuildingHeight = _height;
                _objBuilding.GetComponent <Building>().ClearAndRefresh();
            }

            int cSlot        = _objBuilding.GetComponent <Building>().NumSlots();
            int cSlotMax     = _objBuilding.GetComponent <Building>().NumSlotsMax();
            int cFoodPerSlot = CFoodPerSlotFromGrock(_grock);

            if (_job._mpReskCRes[RESOURCEK.Food] >= (cSlot + 1) * cFoodPerSlot)
            {
                _objBuilding.GetComponent <Building>().BuildNewModule();
            }
        }
        break;

        case DESIGNATIONK.CollectFood:
            break;

        case DESIGNATIONK.BuildHomes:
            if (_job._jobk == JOBK.Build)
            {
                GroceryManager grocm = GameObject.Find("Game Manager").GetComponent <Game>()._grocm;

                if (_objBuilding == null)
                {
                    GameObject prefabBuildingType = grocm._lPrefabBuildingType[UnityEngine.Random.Range(0, grocm._lPrefabBuildingType.Count)];
                    _objBuilding = Instantiate(prefabBuildingType, transform.position, transform.rotation, transform);
                    _objBuilding.GetComponent <Building>().mBuildingWidth  = _width;
                    _objBuilding.GetComponent <Building>().mBuildingHeight = _height;
                    _objBuilding.GetComponent <Building>().ClearAndRefresh();
                }

                Building building             = _objBuilding.GetComponent <Building>();
                int      cSlot                = building.NumSlots();
                int      cSlotMax             = building.NumSlotsMax();
                int      cWorkRequiredPerSlot = CWorkRequiredPerSlotFromGrock(_grock);

                if (_job._mpReskCRes[RESOURCEK.Work] > (cSlot + 1) * cWorkRequiredPerSlot)
                {
                    building.BuildNewModule();
                }

                if (_job._mpReskCRes[RESOURCEK.Work] >= cSlotMax * cWorkRequiredPerSlot)
                {
                    while (building.NumSlots() != building.NumSlotsMax())
                    {
                        building.BuildNewModule();
                    }

                    // done building!
                    _jobm.RemoveJob(_job);

                    // we can have beds now!
                    Vector3 vecDoorOffset = new Vector3((int)(((_width * 0.5f) - 1)) + 0.5f, 0.0f, 0.0f);
                    _job = new JobSite(JOBK.WarmHome, transform, vecDoorOffset);
                    _job._mpReskCRes[RESOURCEK.WarmBed]      = CWarmBedsPerSlotFromGrock(_grock) * cSlot;
                    _job._mpReskCResLimit[RESOURCEK.WarmBed] = CWarmBedsPerSlotFromGrock(_grock) * cSlot;

                    Debug.Log("Job Manager adding Job: ");
                    _jobm.AddJob(_job);
                }
            }
            break;
        }
    }
Esempio n. 13
0
        // GET: Jobsites/Create
        public ActionResult Create()
        {
            var newJobSite = new JobSite();

            return(View(newJobSite));
        }
Esempio n. 14
0
    // If this returns true, the list of tasks is filled with instructions on work to do for the player
    public bool FTryGetWork(ref List <Task> pLTask, float posY)
    {
        pLTask.Clear();

        JobSite jobPerformed = null;

        foreach (JobSite job in _lJob)
        {
            switch (job._jobk)
            {
            case JOBK.CollectFood:
                break;

            case JOBK.WarmHome:
                break;

            case JOBK.StoreFood:
                if (job._mpReskCRes[RESOURCEK.Food] + job._mpReskCResPending[RESOURCEK.Food] < job._mpReskCResLimit[RESOURCEK.Food])
                {
                    for (int j = 0; j < 2; ++j)
                    {
                        foreach (JobSite jobOther in _lJob)
                        {
                            if (j == 0 && jobOther._location.position.y != posY)
                            {
                                continue;
                            }

                            if (jobOther._jobk == JOBK.CollectFood && jobOther.FHasResource(RESOURCEK.Food))
                            {
                                pLTask.Add(new Task(jobOther, TASKK.CollectFood));
                                break;
                            }
                        }

                        if (pLTask.Count > 0)
                        {
                            break;
                        }
                    }

                    if (pLTask.Count > 0)
                    {
                        pLTask.Add(new Task(job, TASKK.StoreFood));
                        job._mpReskCResPending[RESOURCEK.Food]++;
                    }
                }

                break;

            case JOBK.Build:
                if (job._mpReskCRes[RESOURCEK.Work] + job._mpReskCResPending[RESOURCEK.Work] < job._mpReskCResLimit[RESOURCEK.Work])
                {
                    pLTask.Add(new Task(job, TASKK.Work));
                    job._mpReskCResPending[RESOURCEK.Work]++;
                }
                break;
            }

            if (pLTask.Count > 0)
            {
                jobPerformed = job;
                break;
            }
        }

        if (jobPerformed != null)
        {
            // move the performed job to the back of the list to do shitty load balancing

            _lJob.Remove(jobPerformed);
            _lJob.Add(jobPerformed);
            return(true);
        }

        return(false);
    }
Esempio n. 15
0
 public void RemoveJob(JobSite job)
 {
     _lJob.Remove(job);
 }
Esempio n. 16
0
 public void AddJob(JobSite job)
 {
     _lJob.Add(job);
 }