//  Write this object into message-out
        internal override void Write(BinaryWriter binaryWriter)
        {
            base.Write(binaryWriter);

            //  Is building
            MyMwcLog.IfNetVerbose_AddToLog("IsBuilding: " + IsBuilding);
            MyMwcMessageOut.WriteBool(IsBuilding, binaryWriter);

            //  Building time from start
            MyMwcLog.IfNetVerbose_AddToLog("BuildingTimeFromStart: " + BuildingTimeFromStart);
            MyMwcMessageOut.WriteInt32(BuildingTimeFromStart, binaryWriter);

            //  Building queue
            int countBuildingQueueObjects = BuildingQueue == null ? 0 : BuildingQueue.Count;

            MyMwcLog.IfNetVerbose_AddToLog("CountBuildingQueueObjects: " + countBuildingQueueObjects);
            MyMwcMessageOut.WriteInt32(countBuildingQueueObjects, binaryWriter);
            for (int i = 0; i < countBuildingQueueObjects; i++)
            {
                BuildingQueue[i].Write(binaryWriter);
            }

            //  Building object
            bool isBuildingObjectObjectBuilder = BuildingObject != null;

            MyMwcMessageOut.WriteBool(isBuildingObjectObjectBuilder, binaryWriter);
            if (isBuildingObjectObjectBuilder)
            {
                BuildingObject.Write(binaryWriter);
            }
        }
Example #2
0
    private void ProcessInput()
    {
        if (!preview)
        {
            return;
        }

        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("Both")))
        {
            Vector3 mousePos = hit.point;
            preview.transform.position = mousePos + building.Offset;
        }

        if (Input.GetMouseButton(0))
        {
            BuildingBehaviour buildingBehaviour = preview.GetComponent <BuildingBehaviour>();
            if (buildingBehaviour.validPosition)
            {
                buildingBehaviour.Place();
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    preview = CreatePreview(building);
                }
                else
                {
                    preview    = null;
                    building   = null;
                    isBuilding = false;
                }
            }
        }
    }
Example #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Address,Responsible,Amount,PriceOfContract,Executor,PublishDate,EndDate,BidsDate,AuctionDate,Bids,Partner,AmountOfContract,DateOfContract,Stage,StageOfContract,SourceOfFinancing,TypeOfTable")] BuildingObject buildingObject)
        {
            if (id != buildingObject.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    buildingObject.LastUpDateTime = DateTime.Now;
                    _context.Update(buildingObject);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BuildingObjectExists(buildingObject.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                return(RedirectToAction("Index"));
            }
            return(View(buildingObject));
        }
        public int CreateOrFindBuildingFloorId(int buildingId, int floorNr, string description, int?objectNr = null)
        {
            int result = 0;

            using (IUnitOfWork work = UnitOfWork.Begin())
            {
                var floor = _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.BuildingId == buildingId && x.TypeId == (int)BuildingObjectTypes.Floor && x.FloorNr == floorNr);

                if (floor.Count() == 0)
                {
                    BuildingObject bObject = DomainObjectFactory.CreateBuildingObject();

                    bObject.TypeId      = (int)BuildingObjectTypes.Floor;
                    bObject.BuildingId  = buildingId;
                    bObject.FloorNr     = floorNr;
                    bObject.Description = description;
                    bObject.IsDeleted   = false;
                    bObject.ObjectNr    = objectNr;

                    _buildingObjectRepository.Add(bObject);
                    work.Commit();

                    result = bObject.Id;
                }
                else
                {
                    result = floor.FirstOrDefault().Id;
                }
            }

            return(result);
        }
    private void RemoveBuildingFromBottom()
    {
        BuildingObject buildingToRemove = _occupyingBuilding;

        SetUnoccupied(_occupyingBuilding.BuildingData.Size.x, _occupyingBuilding.BuildingData.Size.y);
        buildingToRemove.Remove();
    }
 private void OnDestroy()
 {
     _trackable      = null;
     _buildingObject = null;
     _floorContainer = null;
     //GC.Collect();
 }
 public void ConstructionClick(BuildingObject b)
 {
     if (GameController.instance.gameManager.resourceManager.EnoughResources(b.resourceCost) && playerState == PlayerState.normal)
     {
         GameController.instance.gameManager.resourceManager.DeductResources(b.resourceCost);
         currentConstructionO = b;
         currentConstruction  = Instantiate(b.Hologram, Vector3.zero, Quaternion.identity);
         Vector3    gravityUp      = (Vector3.zero - currentConstruction.transform.position).normalized;                         //up vector from centre of earth
         Vector3    bodyUp         = currentConstruction.transform.up;
         Quaternion targetRotation = Quaternion.FromToRotation(bodyUp, gravityUp * -1) * currentConstruction.transform.rotation; //corrects up vector for location on planet
         currentConstruction.transform.rotation = targetRotation;
         foreach (Human h in GameController.instance.gameManager.humanManager.humans)
         {
             h._age._go.GetComponent <HumanController>().SetLastPositionForTombstone(false);
         }
         playerState      = PlayerState.building;
         placingConstruct = true;
         if (UIScript.instance.GetComponentInChildren <BuildingMenu>().GetComponent <RectTransform>().position.x < -20)
         {
             clickCheck = false;
         }
         else
         {
             clickCheck = true;
         }
         clickCheck2 = false;
     }
 }
    public void useResourcesToBuyBuilding(BuildingObject building)
    {
        if (canBuy(building))
        {
            if (mResources.ContainsKey("Lumber"))
            {
                mResources["Lumber"].modifyCountCond(-building.LumberCost, building.LumberCost);
            }
            if (mResources.ContainsKey("Stone"))
            {
                mResources["Stone"].modifyCountCond(-building.StoneCost, building.StoneCost);
            }
            if (mResources.ContainsKey("Stone Slab"))
            {
                mResources["Stone Slab"].modifyCountCond(-building.BrickCost, building.BrickCost);
            }

            if (mGoldAmount >= building.GoldCost)
            {
                mGoldAmount -= building.GoldCost;
            }
            if (building.PopulationIncrease != 0)
            {
                hpei.populationIncrease = building.PopulationIncrease;
                EventController.getInstance().FireEvent(hpei);
                //Fire event for workercontroller
                //OR
                //just call workercontroller function?
                //this event system is a pain
            }
        }
    }
Example #9
0
    public void DoSomething(BaseObject baseObject)
    {
        targetBaseObject = baseObject;

        // hit an object
        BuildingObject buildingObject = baseObject.GetComponent <BuildingObject>();
        ResourceObject resourceObject = baseObject.GetComponent <ResourceObject>();
        UnitObject     unitObject     = baseObject.GetComponent <UnitObject>();

        List <Cell> cells   = GridManager.instance.FindCellsAroundRegion(new Vector2(baseObject.transform.position.x, baseObject.transform.position.z), new Vector2(baseObject.transform.localScale.x, baseObject.transform.localScale.z));
        float       minDist = cells.Min(x => (transform.position - new Vector3(x.x, transform.position.y, x.y)).magnitude);

        navAgent.targetCell = cells.FirstOrDefault(x => (transform.position - new Vector3(x.x, transform.position.y, x.y)).magnitude <= minDist);

        if (buildingObject != null)
        {
            if (!buildingObject.built)
            {
                activity = Activity.Building;
            }
        }
        else if (unitObject != null)
        {
        }
        else if (resourceObject != null)
        {
        }
        return;
    }
    public void SetSelected(BuildingObject buildingObject)
    {
        building = buildingObject;
        if (buildingObject == null)
        {
            Name.text        = "";
            Description.text = "";
            Icon.sprite      = null;
            Icon.enabled     = false;
            GoldCost.text    = "0";
            StoneCost.text   = "0";
            BrickCost.text   = "0";
            LumberCost.text  = "0";
            return;
        }
        Name.text        = buildingObject.name;
        Description.text = buildingObject.Description;
        Icon.sprite      = buildingObject.Icon;
        Icon.enabled     = true;

        GoldCost.text   = buildingObject.GoldCost.ToString();
        StoneCost.text  = buildingObject.StoneCost.ToString();
        BrickCost.text  = buildingObject.BrickCost.ToString();
        LumberCost.text = buildingObject.LumberCost.ToString();
    }
Example #11
0
    private void CreateGameObject()
    {
        BuildingObject bo = new BuildingObject();

        bo.SetActive(false);
        pool.Push(bo);
    }
Example #12
0
        public async Task <ActionResult> Edit(BuildingObjectModel model)
        {
            BuildingObject objectByName = await _mediator.Send(new GetBuildingObjectByNameQuery(model.Name));

            if (objectByName != null && objectByName.Id != model.Id)
            {
                ModelState.AddModelError("", "Объект с таким именем уже существует");
            }

            if (ModelState.IsValid)
            {
                await _mediator.Send(new SaveBuildingObjectCommand()
                {
                    Id                    = model.Id,
                    Name                  = model.Name,
                    Status                = model.Status,
                    Price                 = model.Price.Value,
                    ContractDateStart     = model.ContractDateStart.Value,
                    ContractDateEnd       = model.ContractDateEnd.Value,
                    ResponsibleEmployeeId = model.ResponsibleEmployeeId,
                    IsInactive            = model.IsInactive
                });

                return(RedirectToAction(nameof(Index)));
            }

            await FillRelatedObjects(model);

            return(View(model));
        }
Example #13
0
        private BuildingObject makeBuildingObject()
        {
            BuildingObject bo = new BuildingObject();

            bo.buildingName               = "";
            bo.description                = "";
            bo.color                      = Color.Blue;
            bo.sprite                     = null;
            bo.prefab                     = new GameObject();
            bo.populationRequirement      = 1;
            bo.populationName             = "";
            bo.resourceType               = 2;
            bo.projects                   = null;
            bo.production                 = null;
            bo.constructionMonthlyCost    = null;
            bo.storageIncreaseMonthlyCost = null;
            bo.constructionTime           = 0;
            bo.control                    = false;
            bo.culture                    = 1;
            bo.baseStorage                = 2.3;
            bo.decay                      = 0.2;
            bo.decayEffect                = "stop";
            bo.maintainenceEffect         = "stop";
            bo.costInfo                   = "";
            bo.shortageEffect             = "";
            bo.constructionSound          = null;

            return(bo);
        }
Example #14
0
    private GameObject CreatePreview(BuildingObject building)
    {
        GameObject go = Instantiate(building.Prefab);

        go.transform.SetParent(transform);
        return(go);
    }
Example #15
0
 public void BuildObject()
 {
     //instantiate building object prefab here
     building = Instantiate(buildingPrefab.GetComponent <BuildingObject>());
     building.transform.SetParent(transform);
     building.transform.localPosition = Vector3.zero;
     building.name = string.Format("Building {0}x{1}", x, y);
 }
Example #16
0
    // Add a new building if enough room
    //TODO ADD
    public void Add(BuildingObject building)
    {
        buildings.Add(building);

        if (onBuildingChangedCallback != null)
        {
            onBuildingChangedCallback.Invoke();
        }
    }
Example #17
0
    // Remove an building
    public void Remove(BuildingObject item)
    {
        buildings.Remove(item);

        if (onBuildingChangedCallback != null)
        {
            onBuildingChangedCallback.Invoke();
        }
    }
Example #18
0
 public void assignBuildingNPC(BuildingObject building, GameObject npcObject)
 {
     building.assignedNPC         = npcObject.GetComponent <basicNPC>().npc;
     npcObject.transform.position = new Vector3(building.tilePositions[0].x + 1, building.tilePositions[0].y + 1, 0);
     npcObject.GetComponent <basicNPC>().status = "working";
     building.setSpawnChance();
     npcObject.GetComponent <basicNPC>().npc.employment = building.building.name;
     gameObject.transform.GetChild(1).gameObject.SetActive(false);
 }
Example #19
0
            public static BuildInfo Create(BuildingObject buildingObj, long ownerId)
            {
                BuildInfo result = ReferencePool.Acquire <BuildInfo>();

                // set properties
                result.buildingObj = buildingObj;
                result.ownerId     = ownerId;
                return(result);
            }
    public void SpawnHouse(Building building)
    {
        GameObject     buildingGameObj = Instantiate <GameObject>(_buildingObjectPrefab.gameObject, new Vector3(transform.position.x, transform.position.y, 0f), Quaternion.identity);
        BuildingObject buildingObj     = buildingGameObj.GetComponent <BuildingObject>();

        buildingObj.Setup(building, this);

        SetOccupied(building.Size.x, building.Size.y, buildingObj);
    }
Example #21
0
 public override void RemapEntityIds(IMyEntityIdRemapContext remapContext)
 {
     base.RemapEntityIds(remapContext);
     PrefabContainer.RemapEntityIds(remapContext);
     BuildingObject.RemapEntityIds(remapContext);
     foreach (var obj in BuildingQueue)
     {
         obj.RemapEntityIds(remapContext);
     }
 }
Example #22
0
    public void Show(BaseObject baseObject)
    {
        if (baseObject == null)
        {
            UIManager.instance.ClearAll();
            UIManager.instance.infoText.text = "";
            showBaseObject = null;
            return;
        }

        showBaseObject = baseObject;

        UIManager.instance.ClearAll();
        UIManager.instance.infoText.text = "";
        if (baseObject.objectType == BaseObject.ObjectType.Building)
        {
            BuildingObject buildingObject = baseObject.GetComponent <BuildingObject>();
            // Actions
            if (buildingObject.built)
            {
                // Units to create
                if (buildingObject.creatableUnits.Length > 0)
                {
                    for (int i = 0; i < buildingObject.creatableUnits.Length; i++)
                    {
                        if (GameManager.instance.RequirementsReached(buildingObject.creatableUnits[i].unit.cost.requirements))
                        {
                            CreateAction(buildingObject.ActionPressed, GameManager.instance.GenerateDescription(buildingObject.creatableUnits[i].unit.description, buildingObject.creatableUnits[i].unit.cost), i, buildingObject.creatableUnits[i].unit.icon);
                        }
                    }
                }
            }
            CreateAction(buildingObject.ActionPressed, "Destroy - Removes building", -1, destroySprite);
        }
        else if (baseObject.objectType == BaseObject.ObjectType.Resource)
        {
            ResourceObject resourceObject = baseObject.GetComponent <ResourceObject>();
        }
        else if (baseObject.objectType == BaseObject.ObjectType.Unit)
        {
            UnitObject unitObject = baseObject.GetComponent <UnitObject>();
            // Actions
            if (unitObject.canBuild)
            {
                for (int i = 0; i < ObjectManager.instance.buildingObjects.Length; i++)
                {
                    if (GameManager.instance.RequirementsReached(ObjectManager.instance.buildingObjects[i].cost.requirements))
                    {
                        CreateAction(unitObject.ActionPressed, GameManager.instance.GenerateDescription(ObjectManager.instance.buildingObjects[i].description, ObjectManager.instance.buildingObjects[i].cost), i, ObjectManager.instance.buildingObjects[i].sprite);
                    }
                }
            }
            CreateAction(unitObject.ActionPressed, "Destroy - Removes Unit", -1, destroySprite);
        }
    }
Example #23
0
            public void Clear()
            {
                buildingObj = null;
                parent      = null;
                ownerId     = 0;
                slave.Release();
                master.Release();
                scaffold.Release();

                constructFxID = 0;
            }
Example #24
0
    public static void Spawn(Building building)
    {
        Object         BuildingPrefab = Resources.Load(Constants.BUILDINGS_PREFAB_PATH + building.Card.Name);
        GameObject     BuildingGO     = GameObject.Instantiate(BuildingPrefab, new Vector3(building.Position.x, 0f, building.Position.y), Quaternion.identity) as GameObject;
        BuildingObject BuildingObject = BuildingGO.AddComponent <BuildingObject>();

        building.OnAttack          += BuildingObject.Attack;
        building.OnBuildingDestroy += BuildingObject.Die;
        building.OnDamage          += BuildingObject.OnDamage;
        BuildingObject.Initialize();
    }
Example #25
0
 /// <summary>
 /// Destroys a specific building
 /// </summary>
 public void Destroy() {
     currentBuilding = null;
     currentProject = null;
     Destroy(buildingModel);
     constructionModel.SetActive(false);
     progressBar.fillAmount = 0f;
     storage = 0;
     status = BuildingStatus.Construction;
     selected = false;
     GM.I.city.UpdateCityVisuals();
 }
Example #26
0
    public override void ActionPressedMethod(int response)
    {
        Debug.Log("Pressed: " + response);
        BuildingObject newBuilding = BuildManager.instance.Build(ObjectManager.instance.buildingObjects[response]);

        if (newBuilding == null)
        {
            return;
        }
        newBuilding.placedCallback += PlaceResponse;
    }
Example #27
0
 //以下デバッグ用
 void FillIdInMap(BuildingObject obj)
 {
     //_mapの指定座標から指定サイズをidで埋める
     for (var z = obj.Position.z; z < obj.Position.z + obj.Scale.z; z++)
     {
         for (var x = obj.Position.x; x < obj.Position.x + obj.Scale.x; x++)
         {
             _mapList[z][x] = obj.Id;
         }
     }
 }
Example #28
0
 public void SelectBuilding(int id)
 {
     for (int i = 0; i < BuildingsDatabase.Instance.buildingsDatabase.Count; i++)
     {
         if (BuildingsDatabase.Instance.buildingsDatabase[i].buildingID == id)
         {
             isBuildingChosen = true;
             buildingToPlace  = BuildingsDatabase.Instance.buildingsDatabase[i].refOfBuilding;
         }
     }
 }
Example #29
0
    public BuildingObject Build(BuildingObject buildingObject)
    {
        Debug.Log("Building: " + buildingObject.buildingType);

        if (GameManager.instance.Purchase(buildingObject.cost, false))
        {
            GameObject newBuidling = Instantiate(buildingObject.gameObject) as GameObject;
            return(newBuidling.GetComponent <BuildingObject>());
        }
        return(null);
    }
Example #30
0
 /// <summary>
 /// Builds the building on a specific location
 /// </summary>
 public void Build() {
     currentBuilding = GM.I.ui.buildingMenu.selectedBuilding;
     integrity = 1f;
     constructionAmount = 0;
     buildingModel = Instantiate(currentBuilding.prefab, transform);
     buildingModel.SetActive(false);
     constructionModel.SetActive(true);
     progressBar.color = currentBuilding.color;
     GM.I.city.SetBuildingSpotMode(BuildingSpotMode.Building);
     status = BuildingStatus.Construction;
     GM.I.sfx.Play(SFX.Build, Random.Range(0.8f, 1.2f));
 }