Esempio n. 1
0
    public void ChooseBuilding()
    {
        StopSound();
        _buildingDecision.Reset();
        foreach (System.Reflection.MethodInfo method in this.GetType().GetMethods())
        {
            if (((BuildingChoiceMethod[])method.GetCustomAttributes(typeof(BuildingChoiceMethod), true)).Length > 0)
            {
                DecisionTree <GameObject> .Percept p = _buildingDecision.GetPercept(method.Name);
                if (p != null && ((Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), this, method))())
                {
                    p.Activate();
                }
            }
        }
        GameObject nextBuild = _buildingDecision.Decide();
        bool       water     = (nextBuild.name == "FishermanHut");

        _target          = _village.AddBuilding(_construction, ChooseEmplacement(water)).GetComponent <ConstructionSite>();
        _target.Building = nextBuild;
        string[] props = Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name).GetElements();
        for (int i = 1; i < props.Length; i++)
        {
            props[i] = props[i].Remove(0, _target.Building.name.Length + 1);
        }
        for (int i = 1; i < props.Length - 1; i++)
        {
            _target.Needed[props[i]] = (int)(float)Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name + "." + props[i]).Value;
        }
        _target.Duration = (float)Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name + ".Duration").Value;
    }
Esempio n. 2
0
 public bool AlreadyConstruction()
 {
     if (_target == null)
     {
         foreach (object[] tuple in _memory.DB.Tables["Patch"].Entries)
         {
             if ((string)tuple[1] == "Construction Site")
             {
                 Patch p = Patch.GetPatch((int)tuple[2], (int)tuple[3]).GetComponent <Patch>();
                 if (p.InnerObjects.Length > 0 && p.InnerObjects[0] != null)
                 {
                     _target = p.InnerObjects[0].GetComponent <ConstructionSite>();
                     if (_target != null)
                     {
                         break;
                     }
                     tuple[1] = p.InnerObjects[0].GetComponent <Entity>().Name;
                     tuple[4] = Time.time;
                 }
                 else
                 {
                     tuple[1] = "None";
                     tuple[4] = Time.time;
                 }
             }
         }
     }
     return(_target != null);
 }
Esempio n. 3
0
    public void AssignConstructionSite(ConstructionSite constructionSite, bool builtOnSecondLevel)
    {
        ConstructionSite = constructionSite;
        ModelObject      = constructionSite.Building;

        Scaffolding.SetActive(false);
        Building.SetActive(false);
        ClippableBuilding.SetActive(false);
        ClippableScaffolding.SetActive(false);

        if (builtOnSecondLevel)
        {
            currentBuilding    = ClippableBuilding;
            currentScaffolding = ClippableScaffolding;
        }
        else
        {
            currentBuilding    = Building;
            currentScaffolding = Scaffolding;
        }

        currentBuilding.SetActive(true);
        currentScaffolding.SetActive(true);

        constructionWithoutScaffolding = ConstructionSite.Building.Prototype.ConstructionWithoutScaffolding;

        levelOffset = builtOnSecondLevel ? 1f : 0f;

        colliderBottomPlane = levelOffset + 0.005f;

        startingScaffoldingUpperPlanePosition = levelOffset - 0.1f;
        finalScaffoldingUpperPlanePosition    = levelOffset + scaffoldingHeight;

        startingBuildingYPosition = levelOffset - HeightOffset - 1.2f;
        finalBuildingYPosition    = levelOffset;

        if (TwoLevelBuilding)
        {
            startingBuildingYPosition             -= 1.3f;
            startingScaffoldingUpperPlanePosition -= 1.3f;
            finalScaffoldingUpperPlanePosition    += scaffoldingHeight;
        }

        if (OverrideUpperPlanePosition > 0.05f)
        {
            finalScaffoldingUpperPlanePosition = OverrideUpperPlanePosition;
        }

        SetScaffoldingUpperPlanePosition(startingScaffoldingUpperPlanePosition);
        SetBuilidingYPosition(startingBuildingYPosition);

        Collider.transform.SetPositionAndRotation(
            new Vector3(Collider.transform.position.x,
                        levelOffset,
                        Collider.transform.position.z),
            Collider.transform.rotation);

        SetColliderUpperPlanePosition(levelOffset);
    }
Esempio n. 4
0
        public ConstructionSite Create(ConstructionSite constructionSite)
        {
            if (context.ConstructionSites.Where(x => x.Identifier != null && x.Identifier == constructionSite.Identifier).Count() == 0)
            {
                //if (context.ConstructionSites.Where(x => x.InternalCode == constructionSite.InternalCode).Count() > 0)
                //throw new Exception("Gradilište sa datom šifrom već postoji u bazi! / Eine Baustelle mit diesem Code existiert bereits in der Datenbank!");

                constructionSite.Id = 0;

                constructionSite.Code   = GetNewCodeValue(constructionSite.CompanyId ?? 0);
                constructionSite.Active = true;

                constructionSite.UpdatedAt = DateTime.Now;
                constructionSite.CreatedAt = DateTime.Now;

                context.ConstructionSites.Add(constructionSite);
                return(constructionSite);
            }
            else
            {
                // Load constructionSite that will be updated
                ConstructionSite dbEntry = context.ConstructionSites
                                           .FirstOrDefault(x => x.Identifier == constructionSite.Identifier && x.Active == true);

                if (dbEntry != null)
                {
                    dbEntry.CityId            = constructionSite.CityId ?? null;
                    dbEntry.CityPartnerId     = constructionSite.CityPartnerId ?? null;
                    dbEntry.CountryId         = constructionSite.CountryId ?? null;
                    dbEntry.BusinessPartnerId = constructionSite.BusinessPartnerId ?? null;
                    dbEntry.StatusId          = constructionSite.StatusId ?? null;
                    dbEntry.ShipmentId        = constructionSite.ShipmentId ?? null;
                    dbEntry.CompanyId         = constructionSite.CompanyId ?? null;
                    dbEntry.CreatedById       = constructionSite.CreatedById ?? null;

                    // Set properties
                    dbEntry.Code               = constructionSite.Code;
                    dbEntry.InternalCode       = constructionSite.InternalCode;
                    dbEntry.Name               = constructionSite.Name;
                    dbEntry.NamePartner        = constructionSite.NamePartner;
                    dbEntry.AddressPartner     = constructionSite.AddressPartner;
                    dbEntry.StatusDate         = constructionSite.StatusDate;
                    dbEntry.Address            = constructionSite.Address;
                    dbEntry.MaxWorkers         = constructionSite.MaxWorkers;
                    dbEntry.ProContractDate    = constructionSite.ProContractDate;
                    dbEntry.ContractStart      = constructionSite.ContractStart;
                    dbEntry.ContractExpiration = constructionSite.ContractExpiration;

                    dbEntry.PaymentDate  = constructionSite.PaymentDate;
                    dbEntry.Path         = constructionSite.Path;
                    dbEntry.PaymentValue = constructionSite.PaymentValue;

                    // Set timestamp
                    dbEntry.UpdatedAt = DateTime.Now;
                }

                return(dbEntry);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ConstructionSite constructionSite = db.ConstructionSites.Find(id);

            db.ConstructionSites.Remove(constructionSite);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
    private void Awake()
    {
        controls = new BaseControls();
        controls.Planning.Position.performed += ctx => mousePos = ctx.ReadValue <Vector2>();
        controls.Planning.Place.performed    += ctx => PlaceCurrent();

        construction = terrain.GetComponent <ConstructionSite>();
    }
 public void SetConstructionSite(ConstructionSite cs)
 {
     ConstructionSite = cs;
     if (cs != null)
     {
         lastTransitionState = cs.TransitionToDeconstructionStage;
         firstShow           = true;
         Update();
     }
 }
Esempio n. 8
0
        public ConstructionSite GetConstructionSite(int constructionSiteId)
        {
            ConstructionSite constructionSite = context.ConstructionSites
                                                .Include(x => x.City)
                                                .Include(x => x.Company)
                                                .Include(x => x.CreatedBy)
                                                .FirstOrDefault(x => x.Id == constructionSiteId);

            return(constructionSite);
        }
Esempio n. 9
0
    public void Construct()
    {
        PlaySound();
        if (_target == null)
        {
            return;
        }
        bool near = false;

        foreach (Entity entity in _agent.Percepts)
        {
            if (entity == null)
            {
                continue;
            }
            ConstructionSite cs = entity.GetComponent <ConstructionSite>();
            if (cs == _target)
            {
                near = true;
            }
        }
        if (!near)
        {
            if (_moving.Direction == Vector3.zero)
            {
                _moving.SetDestination(_target.transform.position);
            }
            return;
        }
        Dictionary <string, int> need = new Dictionary <string, int>();
        Inventory inv = _target.GetComponent <Inventory>();

        foreach (string key in _target.Needed.Keys)
        {
            if (inv.GetElement(key) < _target.Needed[key])
            {
                need.Add(key, _target.Needed[key] - inv.GetElement(key));
            }
        }
        if (need.Keys.Count > 0)
        {
            foreach (string key in need.Keys)
            {
                if (_inventory.GetElement(key) > 0)
                {
                    inv.AddElement(key, _inventory.RemoveElement(key, need[key]));
                }
            }
        }
        else
        {
            _target.Construct();
        }
    }
Esempio n. 10
0
        public void EndConstruction()
        {
            // Turn into the project set when construction began
            // Mark this container as developed so that nothing else can be built here

            site.Inventory["Labor"].onEmpty -= EndConstruction;
            project.gameObject.SetActive(true);
            SetObject(project);
            Element.State = DevelopmentState.Developed;
            OnEndConstruction(project);
            site = null;
        }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        if (_camera.Target == null)
        {
            gameObject.SetActive(false);
            return;
        }
        Entity entity = _camera.Target.GetComponent <Entity>();

        if (entity.Type != Entity.EntityType.BUILDING || entity.Name != "Construction Site")
        {
            gameObject.SetActive(false);
            return;
        }
        ConstructionSite construction = entity.GetComponent <ConstructionSite>();

        _textBuilding.text = construction.Building.GetComponent <Entity>().Name;
        Inventory     inventory = entity.GetComponent <Inventory>();
        List <string> keys      = new List <string>(construction.Needed.Keys);

        for (int i = 0; i < keys.Count; i++)
        {
            if (i >= _additionalName.Count)
            {
                GameObject aName     = Instantiate(_textName, transform);
                GameObject aQuantity = Instantiate(_textQuantity, transform);
                aName.SetActive(true);
                aQuantity.SetActive(true);
                RectTransform tr = aName.GetComponent <RectTransform>();
                tr.position = new Vector3(tr.position.x, tr.position.y - i * 20.0f);
                tr          = aQuantity.GetComponent <RectTransform>();
                tr.position = new Vector3(tr.position.x, tr.position.y - i * 20.0f);
                _additionalName.Add(aName.GetComponent <Text>());
                _additionalQuantity.Add(aQuantity.GetComponent <Text>());
            }
            _additionalName[i].text     = keys[i] + " :";
            _additionalQuantity[i].text =
                inventory.GetElement(keys[i]).ToString() + "/" + construction.Needed[keys[i]].ToString();
        }
        if (keys.Count < _additionalName.Count)
        {
            for (int i = keys.Count; i < _additionalName.Count; i++)
            {
                Destroy(_additionalName[i].gameObject);
                Destroy(_additionalQuantity[i].gameObject);
            }
            _additionalName.RemoveRange(keys.Count, _additionalName.Count - keys.Count);
            _additionalQuantity.RemoveRange(keys.Count, _additionalQuantity.Count - keys.Count);
        }
        _slider.maxValue = construction.Duration;
        _slider.value    = construction.Duration - construction.Release;
        _panel.sizeDelta = new Vector2(_panel.sizeDelta.x, _defaultHeight + (keys.Count - 1) * 20.0f);
    }
 public ActionResult Edit(ConstructionSite constructionSite)
 {
     if (ModelState.IsValid)
     {
         db.Entry(constructionSite).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.company  = new SelectList(db.Companies, "companyId", "companyName", constructionSite.company);
     ViewBag.country  = new SelectList(db.Countries, "countryId", "countryName", constructionSite.country);
     ViewBag.province = new SelectList(db.Provinces, "provinceId", "provinceName", constructionSite.province);
     return(View(constructionSite));
 }
Esempio n. 13
0
        public ConstructionSite Delete(Guid identifier)
        {
            // Load ConstructionSite that will be deleted
            ConstructionSite dbEntry = context.ConstructionSites
                                       .FirstOrDefault(x => x.Identifier == identifier);

            if (dbEntry != null)
            {
                // Set activity
                dbEntry.Active = false;
                // Set timestamp
                dbEntry.UpdatedAt = DateTime.Now;
            }

            return(dbEntry);
        }
        public static ConstructionSiteViewModel ConvertToConstructionSiteViewModel(this ConstructionSite constructionSite)
        {
            ConstructionSiteViewModel constructionSiteViewModel = new ConstructionSiteViewModel()
            {
                Id         = constructionSite.Id,
                Identifier = constructionSite.Identifier,

                Code         = constructionSite.Code,
                InternalCode = constructionSite.InternalCode,

                Name = constructionSite.Name,

                NamePartner    = constructionSite.NamePartner,
                AddressPartner = constructionSite.AddressPartner,

                Address    = constructionSite.Address,
                MaxWorkers = constructionSite.MaxWorkers,

                ProContractDate    = constructionSite.ProContractDate,
                ContractStart      = constructionSite.ContractStart,
                ContractExpiration = constructionSite.ContractExpiration,

                PaymentDate  = constructionSite.PaymentDate,
                Path         = constructionSite.Path,
                PaymentValue = constructionSite.PaymentValue,

                CityPartner     = constructionSite.CityPartner?.ConvertToCityViewModelLite(),
                City            = constructionSite.City?.ConvertToCityViewModelLite(),
                Country         = constructionSite.Country?.ConvertToCountryViewModelLite(),
                BusinessPartner = constructionSite.BusinessPartner?.ConvertToBusinessPartnerViewModelLite(),
                Status          = constructionSite.Status?.ConvertToStatusViewModelLite(),
                Shipment        = constructionSite.Shipment?.ConvertToShipmentViewModelLite(),
                StatusDate      = constructionSite.StatusDate,
                IsActive        = constructionSite.Active,

                CreatedBy = constructionSite.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = constructionSite.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = constructionSite.UpdatedAt,
                CreatedAt = constructionSite.CreatedAt
            };

            return(constructionSiteViewModel);
        }
        public EmployeeByConstructionSiteResponse Create(EmployeeByConstructionSiteViewModel re)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                ConstructionSite constructionSite = unitOfWork.GetConstructionSiteRepository().GetConstructionSite(re.ConstructionSite.Id);

                Employee employee = unitOfWork.GetEmployeeRepository().GetEmployeeEntity(re.Employee.Id);
                employee.ConstructionSiteCode = constructionSite.InternalCode;
                employee.ConstructionSiteName = constructionSite.Name;
                employee.UpdatedAt            = DateTime.Now;

                EmployeeByConstructionSite addedEmployeeByConstructionSite = unitOfWork.GetEmployeeByConstructionSiteRepository().Create(re.ConvertToEmployeeByConstructionSite());

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = re.Employee.Id,
                    CardDate    = addedEmployeeByConstructionSite.StartDate,
                    Description = "Radnik " + employee?.Name + " " + employee?.SurName + " je krenuo da radi na gradilištu " + constructionSite?.Name + ". Radnik je na gradilištu od: " + re.StartDate.ToString("dd.MM.yyyy") + " do " + re.EndDate.ToString("dd.MM.yyyy"),
                    PlusMinus   = "+",
                    CreatedById = re.CreatedBy?.Id,
                    CompanyId   = re.Company?.Id,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByConstructionSite = addedEmployeeByConstructionSite.ConvertToEmployeeByConstructionSiteViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByConstructionSite = new EmployeeByConstructionSiteViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
    public void SetModule(IBuildingModule module)
    {
        Module = module;

        canBeHalted        = false;
        canBeDeconstructed = false;

        if (Module != null)
        {
            if (Module is ConstructionSite)
            {
                ConstructionSite site = (ConstructionSite)Module;

                canBeHalted = true;
                if (site.ConstructionMode && site.TransitionToDeconstructionStage == false)
                {
                    canBeDeconstructed = true;
                }
            }
            else if (Module is Storage)
            {
                canBeDeconstructed = true;
            }
            else if (Module is Factory)
            {
                canBeHalted        = true;
                canBeDeconstructed = true;
            }
            else if (Module is Service)
            {
                canBeDeconstructed = true;
            }

            if (module.Building.Prototype.CanBeDeconstructed == false)
            {
                canBeDeconstructed = false;
            }
        }

        changed = true;
        Update();
    }
        public EmployeeByConstructionSiteResponse Delete(EmployeeByConstructionSiteViewModel re)
        {
            EmployeeByConstructionSiteResponse response = new EmployeeByConstructionSiteResponse();

            try
            {
                EmployeeByConstructionSite deletedEmployeeByConstructionSite = unitOfWork.GetEmployeeByConstructionSiteRepository().Delete(re.ConvertToEmployeeByConstructionSite());

                Employee         employee         = unitOfWork.GetEmployeeRepository().GetEmployeeEntity((int)deletedEmployeeByConstructionSite.EmployeeId);
                ConstructionSite constructionSite = unitOfWork.GetConstructionSiteRepository().GetConstructionSite((int)deletedEmployeeByConstructionSite.ConstructionSiteId);
                employee.ConstructionSiteCode = "";
                employee.ConstructionSiteName = "";
                employee.UpdatedAt            = DateTime.Now;

                EmployeeCard ec = new EmployeeCard()
                {
                    Identifier  = Guid.NewGuid(),
                    EmployeeId  = deletedEmployeeByConstructionSite.Employee.Id,
                    CardDate    = (DateTime)deletedEmployeeByConstructionSite.RealEndDate,
                    Description = "Radnik " + employee?.Name + " " + employee.SurName + " je prestao da radi na gradilištu " + constructionSite?.Name + ". Prestanak je od: " + ((DateTime)deletedEmployeeByConstructionSite.RealEndDate).ToString("dd.MM.yyyy"),
                    CreatedById = deletedEmployeeByConstructionSite.CreatedById,
                    PlusMinus   = "-",
                    CompanyId   = deletedEmployeeByConstructionSite.CompanyId,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                unitOfWork.GetEmployeeCardRepository().Create(ec);

                unitOfWork.Save();

                response.EmployeeByConstructionSite = deletedEmployeeByConstructionSite.ConvertToEmployeeByConstructionSiteViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeByConstructionSite = new EmployeeByConstructionSiteViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public void TestMessagesFromComponent()
        {
            var scene = new Scene();
            ConstructionSystem system = SetupMock(scene);
            var building = new Systems.Construction.Building()
            {
                Name   = "Test",
                Stages =
                {
                    new Systems.Construction.Building.Stage()
                    {
                        NeededResources = new Dictionary <string, int>
                        {
                            { "Wood", 2 }
                        },
                        Steps = 2,
                    },
                }
            };

            system.AddBuilding(building);
            var component = new ConstructionSite()
            {
                Building = "Test",
            };
            var entity = new Entity
            {
                component,
            };

            scene.Entities.Add(entity);

            Assert.NotNull(entity.Get <ConstructionSite>());
            Assert.Null(entity.Get <Components.Building>());
            system.Actor.Tell(new Systems.Construction.Messages.ConstructionFinished(entity.Id, component.Building));
            ExpectNoMsg(500);
            Assert.Null(entity.Get <ConstructionSite>());
            Components.Building entBuilding = entity.Get <Components.Building>();
            Assert.NotNull(building);
            Assert.Equal(component.Building, entBuilding.Name);
        }
Esempio n. 19
0
 public ConstructionSite BeginConstruction <T> (int laborCost = 0, bool autoConstruct = false) where T : StaticUnit
 {
     // Create a construction site and listen for labor to be completed
     // Set the project to turn into once labor completes
     if (Element.State == DevelopmentState.Undeveloped)
     {
         project = (StaticUnit)ObjectPool.Instantiate <T> ();
         project.gameObject.SetActive(false);
         site = (ConstructionSite)SetObject <ConstructionSite> ();
         site.Inventory["Labor"].onEmpty += EndConstruction;
         site.Inventory["Labor"].Capacity = laborCost;
         site.Inventory["Labor"].Fill();
         site.PerformableTasks.Get <CancelConstruction> ().Init(this, project.Settings.Symbol);
         if (autoConstruct)
         {
             site.AutoConstruct();
         }
         Element.State = DevelopmentState.UnderConstruction;
     }
     return(site);
 }
Esempio n. 20
0
    /// <summary>
    /// Spawn a construction site on the map and all assigned citizen begin to work.
    /// </summary>
    /// <param name="building">The building to be build.</param>
    /// <param name="position">The world position of the build spot.</param>
    /// <param name="player">The player that owns the building</param>
    /// <param name="citizens">The assigned citizen.</param>
    /// <returns>true if the player has enough resources and the construction has started.</returns>
    public bool Build(Building building, Vector3 position, Player player, Citizen[] citizens)
    {
        // Check if the player has enough resources.
        if (EnoughResources(player, building))
        {
            // Remove the resource cost from the player resources.
            player.resources.RemoveResources(building.buildCost);

            GameObject construction;

            // Spawen a construction site according to the building size.
            if (building.constructionSiteSize == ConstructionSiteSize.Size4x4)
            {
                construction = (GameObject)Instantiate(Resources.Load("ConstructionSite4x4"), position, Quaternion.identity);
            }
            else
            {
                construction = (GameObject)Instantiate(Resources.Load("ConstructionSite8x8"), position, Quaternion.identity);
            }

            // Set the stats of the construction site.
            ConstructionSite constructionSite = construction.GetComponent <ConstructionSite>();

            constructionSite.buildTimeLeft = building.buildTime;
            constructionSite.combatDefense = building.combatDefense;
            constructionSite.name          = building.name + " Construction";
            constructionSite.building      = building.name;
            constructionSite.player        = player;
            constructionSite.SetPlayerStats();

            // Delegate all responsible citizen to the construction site.
            foreach (Citizen citizen in citizens)
            {
                citizen.Build(construction);
            }

            return(true);
        }
        return(false);
    }
Esempio n. 21
0
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     _agent             = GetComponent <AgentController> ();
     _agent.CurrentTask = this;
     _memory            = GetComponent <Memory> ();
     _moving            = GetComponent <Moving> ();
     _inventory         = GetComponent <Inventory>();
     _village           = GameObject.Find("Village").GetComponent <Village>();
     _construction      = _village.GetPrefab("ConstructionSite");
     _target            = null;
     _stockpile         = null;
     _buildingDecision  = new DecisionTree <GameObject>();
     System.Reflection.MethodInfo[] methods = this.GetType().GetMethods();
     foreach (YamlLoader.PropertyElement element in (List <YamlLoader.PropertyElement>)Manager.Instance.Properties.GetElement("BuildingCost").Value)
     {
         _buildingDecision.AddAction(new DecisionTree <GameObject> .Action(element.Name, _village.GetPrefab(element.Name)));
     }
     foreach (System.Reflection.MethodInfo method in methods)
     {
         if (((BuildingChoiceMethod[])method.GetCustomAttributes(typeof(BuildingChoiceMethod), true)).Length > 0)
         {
             List <DecisionTree <GameObject> .Action> actions = new List <DecisionTree <GameObject> .Action>();
             List <float> weights = new List <float>();
             foreach (BuildingChoiceLink link in (BuildingChoiceLink[])method.GetCustomAttributes(typeof(BuildingChoiceLink), true))
             {
                 DecisionTree <GameObject> .Action a = _buildingDecision.GetAction(link.Name);
                 if (a != null)
                 {
                     actions.Add(a);
                     weights.Add(link.Weight);
                 }
             }
             if (actions.Count > 0)
             {
                 _buildingDecision.AddPercept(new DecisionTree <GameObject> .Percept(method.Name, actions.ToArray(), weights.ToArray()));
             }
         }
     }
 }
        public static ConstructionSite ConvertToConstructionSite(this ConstructionSiteViewModel constructionSiteViewModel)
        {
            ConstructionSite constructionSite = new ConstructionSite()
            {
                Id         = constructionSiteViewModel.Id,
                Identifier = constructionSiteViewModel.Identifier,

                Code         = constructionSiteViewModel.Code,
                InternalCode = constructionSiteViewModel.InternalCode,

                Address        = constructionSiteViewModel.Address,
                Name           = constructionSiteViewModel.Name,
                NamePartner    = constructionSiteViewModel.NamePartner,
                AddressPartner = constructionSiteViewModel.AddressPartner,
                MaxWorkers     = constructionSiteViewModel.MaxWorkers,

                ProContractDate    = constructionSiteViewModel.ProContractDate,
                ContractStart      = constructionSiteViewModel.ContractStart,
                ContractExpiration = constructionSiteViewModel.ContractExpiration,

                PaymentDate       = constructionSiteViewModel.PaymentDate,
                Path              = constructionSiteViewModel.Path,
                PaymentValue      = constructionSiteViewModel.PaymentValue,
                CityPartnerId     = constructionSiteViewModel.CityPartner?.Id ?? null,
                CityId            = constructionSiteViewModel.City?.Id ?? null,
                CountryId         = constructionSiteViewModel.Country?.Id ?? null,
                BusinessPartnerId = constructionSiteViewModel.BusinessPartner?.Id ?? null,
                StatusId          = constructionSiteViewModel.Status?.Id ?? null,
                ShipmentId        = constructionSiteViewModel.Shipment?.Id ?? null,
                StatusDate        = constructionSiteViewModel.StatusDate,
                CreatedById       = constructionSiteViewModel.CreatedBy?.Id ?? null,
                CompanyId         = constructionSiteViewModel.Company?.Id ?? null,

                CreatedAt = constructionSiteViewModel.CreatedAt,
                UpdatedAt = constructionSiteViewModel.UpdatedAt
            };

            return(constructionSite);
        }
        public ConstructionSiteResponse Delete(Guid identifier)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                ConstructionSite deletedConstructionSite = unitOfWork.GetConstructionSiteRepository().Delete(identifier);

                unitOfWork.Save();

                response.ConstructionSite = deletedConstructionSite.ConvertToConstructionSiteViewModel();
                response.Success          = true;
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }
Esempio n. 24
0
    public ConstructionSiteDisplayObject ShowConstructionSite(ConstructionSite newSite)
    {
        Building building = newSite.Building;

        GameObject siteObjectPrefab = null;
        for (int i = 0; i < buildingDisplay.Length; i++)
        {
            if (buildingDisplay[i] != null && buildingDisplay[i].Type == building.Type)
            {
                siteObjectPrefab = buildingDisplay[i].ConstructionSiteObject;
                break;
            }
        }

        if (siteObjectPrefab == null)
        {
            return null;
        }

        GameObject gameObject = GameObject.Instantiate(
            siteObjectPrefab,
            new Vector3(building.Tiles[0].Position.X,
                        building.Tiles[0].Position.Height * LevelHeightOffset,
                        building.Tiles[0].Position.Y),
            Quaternion.identity,
            ConstructionSitesParent.transform
            );

        RotateGameObject(gameObject, building.Rotation);

        bool builtOnSecondLevel = (building.Tiles[0].Position.Height > 0);

        ConstructionSiteDisplayObject selectableObject = gameObject.GetComponentInChildren<ConstructionSiteDisplayObject>();

        building.AssignDisplayObject(selectableObject);
        selectableObject.AssignConstructionSite(newSite, builtOnSecondLevel);

        return selectableObject;
    }
Esempio n. 25
0
        public IRoomObject[] Find(Find type)
        {
            var ids    = Game.js.Invoke <string[]>($"{_ref}.findIds", (int)type);
            var output = new IRoomObject[ids.Length];

            for (int i = 0; i < ids.Length; i++)
            {
                switch (type)
                {
                case ScreepsSharp.Core.Find.constructionSites:
                    output[i] = new ConstructionSite(ids[i], _js);
                    continue;

                case ScreepsSharp.Core.Find.structures:
                case ScreepsSharp.Core.Find.myStructures:
                    output[i] = FromId(ids[i]);
                    continue;

                case ScreepsSharp.Core.Find.mySpawns:
                    output[i] = new Spawn(ids[i], _js);
                    continue;

                case ScreepsSharp.Core.Find.sources:
                    output[i] = new Source(ids[i], _js);
                    continue;

                case ScreepsSharp.Core.Find.creeps:
                case ScreepsSharp.Core.Find.myCreeps:
                case ScreepsSharp.Core.Find.hostileCreeps:
                    output[i] = new Creep(ids[i], _js);
                    continue;

                default: throw new NotImplementedException(type.ToString());
                }
            }

            return(output);
        }
        public void TestGetActor()
        {
            var building = new Building()
            {
                Name = "Test",
            };
            var buildings = new Dictionary <string, Building>()
            {
                { "Test", building },
            };

            var buildingManagerMock = new Mock <IBuildingManager>();

            buildingManagerMock.Setup(bm => bm.GetBuilding(It.IsAny <string>())).Returns((string name) => buildings[name]);

            var factory = new ConstructionSiteActorFactory(buildingManagerMock.Object, Sys);

            var testSite = new ConstructionSite
            {
                Building = building.Name,
            };

            Assert.NotNull(factory.GetOrCreateActorForComponent(testSite));
        }
Esempio n. 27
0
 public Build(ConstructionSite target, ComponentActorFactory <ConstructionSite> componentActorFactory)
 {
     this.target = target;
     this.componentActorFactory = componentActorFactory;
 }
        public ConstructionSiteResponse Create(ConstructionSiteViewModel constructionSite)
        {
            ConstructionSiteResponse response = new ConstructionSiteResponse();

            try
            {
                // Backup items
                List <ConstructionSiteDocumentViewModel> constructionSiteDocuments = constructionSite.ConstructionSiteDocuments?.ToList() ?? new List <ConstructionSiteDocumentViewModel>();
                constructionSite.ConstructionSiteDocuments = null;
                List <ConstructionSiteNoteViewModel> constructionSiteNotes = constructionSite.ConstructionSiteNotes?.ToList() ?? new List <ConstructionSiteNoteViewModel>();
                constructionSite.ConstructionSiteNotes = null;
                List <ConstructionSiteCalculationViewModel> constructionSiteCalculations = constructionSite.ConstructionSiteCalculations?.ToList() ?? new List <ConstructionSiteCalculationViewModel>();
                constructionSite.ConstructionSiteCalculations = null;

                ConstructionSite createdConstructionSite = unitOfWork.GetConstructionSiteRepository()
                                                           .Create(constructionSite.ConvertToConstructionSite());

                // Update notes
                if (constructionSiteNotes != null && constructionSiteNotes.Count > 0)
                {
                    foreach (ConstructionSiteNoteViewModel item in constructionSiteNotes
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteNoteViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());
                    }

                    foreach (ConstructionSiteNoteViewModel item in constructionSiteNotes
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteNoteViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());

                        unitOfWork.GetConstructionSiteNoteRepository().Delete(item.Identifier);
                    }
                }

                // Update documents
                if (constructionSiteDocuments != null && constructionSiteDocuments.Count > 0)
                {
                    foreach (ConstructionSiteDocumentViewModel item in constructionSiteDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteDocumentViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());
                    }

                    foreach (ConstructionSiteDocumentViewModel item in constructionSiteDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteDocumentViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());

                        unitOfWork.GetConstructionSiteDocumentRepository().Delete(item.Identifier);
                    }
                }

                // Update calculations
                if (constructionSiteCalculations != null && constructionSiteCalculations.Count > 0)
                {
                    foreach (ConstructionSiteCalculationViewModel item in constructionSiteCalculations
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ConstructionSiteCalculationViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        item.ItemStatus = ItemStatus.Submited;
                        var createdItem = unitOfWork.GetConstructionSiteCalculationRepository().Create(item.ConvertToConstructionSiteCalculation());
                    }

                    foreach (ConstructionSiteCalculationViewModel item in constructionSiteCalculations
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ConstructionSiteCalculationViewModel>())
                    {
                        item.ConstructionSite = new ConstructionSiteViewModel()
                        {
                            Id = createdConstructionSite.Id
                        };
                        unitOfWork.GetConstructionSiteCalculationRepository().Create(item.ConvertToConstructionSiteCalculation());

                        unitOfWork.GetConstructionSiteCalculationRepository().Delete(item.Identifier);
                    }
                }
                //// Update items
                //var ConstructionSiteDocumentsFromDB = unitOfWork.GetConstructionSiteDocumentRepository().GetConstructionSiteDocumentsByConstructionSite(createdConstructionSite.Id);
                //foreach (var item in ConstructionSiteDocumentsFromDB)
                //    if (!constructionSiteDocuments.Select(x => x.Identifier).Contains(item.Identifier))
                //        unitOfWork.GetConstructionSiteDocumentRepository().Delete(item.Identifier);
                //foreach (var item in constructionSiteDocuments)
                //{
                //    item.ConstructionSite = new ConstructionSiteViewModel() { Id = createdConstructionSite.Id };
                //    unitOfWork.GetConstructionSiteDocumentRepository().Create(item.ConvertToConstructionSiteDocument());
                //}

                //var ConstructionSiteNotesFromDB = unitOfWork.GetConstructionSiteNoteRepository().GetConstructionSiteNotesByConstructionSite(createdConstructionSite.Id);
                //foreach (var item in ConstructionSiteNotesFromDB)
                //    if (!constructionSiteNotes.Select(x => x.Identifier).Contains(item.Identifier))
                //        unitOfWork.GetConstructionSiteNoteRepository().Delete(item.Identifier);
                //foreach (var item in constructionSiteNotes)
                //{
                //    item.ConstructionSite = new ConstructionSiteViewModel() { Id = createdConstructionSite.Id };
                //    unitOfWork.GetConstructionSiteNoteRepository().Create(item.ConvertToConstructionSiteNote());
                //}

                unitOfWork.Save();

                response.ConstructionSite = createdConstructionSite.ConvertToConstructionSiteViewModel();
                response.Success          = true;
            }
            catch (Exception ex)
            {
                response.ConstructionSite = new ConstructionSiteViewModel();
                response.Success          = false;
                response.Message          = ex.Message;
            }

            return(response);
        }
    void Update()
    {
        if (changed == false)
        {
            return;
        }

        if (Module is ConstructionSite)
        {
            ConstructionSite site = (ConstructionSite)Module;
            canBeDeconstructed = (site.ConstructionMode &&
                                  site.TransitionToDeconstructionStage == false);
        }

        if (canBeHalted && canBeDeconstructed)
        {
            deconstructButtonOffset = FirstButtonOffset;
            haltButtonOffset        = SecondButtonOffset;
        }
        else if (canBeHalted)
        {
            haltButtonOffset = FirstButtonOffset;
        }
        else if (canBeDeconstructed)
        {
            deconstructButtonOffset = FirstButtonOffset;
        }

        HaltButton.anchoredPosition                 = new Vector2(ButtonXPosition, haltButtonOffset);
        StartButton.anchoredPosition                = new Vector2(ButtonXPosition, haltButtonOffset);
        DeconstructButton.anchoredPosition          = new Vector2(ButtonXPosition, deconstructButtonOffset);
        CancelDeconstructionButton.anchoredPosition = new Vector2(ButtonXPosition, deconstructButtonOffset);

        if (canBeHalted)
        {
            if (Module.Halted)
            {
                HaltButton.gameObject.SetActive(false);
                StartButton.gameObject.SetActive(true);
            }
            else
            {
                HaltButton.gameObject.SetActive(true);
                StartButton.gameObject.SetActive(false);
            }
        }
        else
        {
            HaltButton.gameObject.SetActive(false);
            StartButton.gameObject.SetActive(false);
        }

        if (canBeDeconstructed)
        {
            if (Module.IsPreparingForDeconstruction())
            {
                DeconstructButton.gameObject.SetActive(false);
                CancelDeconstructionButton.gameObject.SetActive(true);

                HaltButton.gameObject.SetActive(false);
                StartButton.gameObject.SetActive(false);
            }
            else
            {
                DeconstructButton.gameObject.SetActive(true);
                CancelDeconstructionButton.gameObject.SetActive(false);
            }
        }
        else
        {
            DeconstructButton.gameObject.SetActive(false);
            CancelDeconstructionButton.gameObject.SetActive(false);
        }
    }
    public void CreateBuilding(Vector3 position, Buildings type)
    {
        switch (type)
        {
        case Buildings.CommandCenter:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(commandCenterPrefab, position, commandCenterPrefab.rotation);
            //newBuilding.GetComponent<MeshRenderer>().enabled = false;
            //newBuilding.GetComponent<ConstructionSite>().constructionSite = constructionSite;
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = commandCenterPrefab;
            cs.hitpointsMax    = CommandCenter.hitpointsMax;
            foreach (var item in CommandCenter.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.Refinery:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(refineryPrefab, position, refineryPrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = refineryPrefab;
            cs.hitpointsMax    = Refinery.hitpointsMax;
            foreach (var item in Refinery.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.Mine:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(minePrefab, position, minePrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = minePrefab;
            cs.hitpointsMax    = Mine.hitpointsMax;
            foreach (var item in Mine.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.Hangar:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(hangarPrefab, position, hangarPrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = hangarPrefab;
            cs.hitpointsMax    = Hangar.hitpointsMax;
            foreach (var item in Hangar.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.UnitsFactory:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(unitsFactoryPrefab, position, unitsFactoryPrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = unitsFactoryPrefab;
            cs.hitpointsMax    = UnitsFactory.hitpointsMax;
            foreach (var item in UnitsFactory.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.PowerPlant:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(powerPlantPrefab, position, powerPlantPrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = powerPlantPrefab;
            cs.hitpointsMax    = PowerPlant.hitpointsMax;
            foreach (var item in PowerPlant.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }

        case Buildings.Silo:
        {
            //Transform newBuilding = (Transform)GameObject.Instantiate(siloPrefab, position, siloPrefab.rotation);
            //AstarPath.active.UpdateGraphs(newBuilding.collider.bounds);
            Transform        newContruction = (Transform)GameObject.Instantiate(constructionSite, position, Quaternion.identity);
            ConstructionSite cs             = newContruction.GetComponent <ConstructionSite>();
            cs.createdBuilding = siloPrefab;
            cs.hitpointsMax    = Silo.hitpointsMax;
            foreach (var item in Silo.cost)
            {
                Colony.colonyResources[item.Key] -= item.Value;
            }
            break;
        }
        }
    }