Example #1
0
        protected override void Init()
        {
            base.Init();

            if (!_slotInited)
            {
                _inventory = new InventoryBase();
                _inventory.Init(1);
            }

            _gameManager = GameObject.FindWithTag("GameManager").GetComponent <GameManager>();
            StartCoroutine(RefreshProgress());
        }
Example #2
0
        protected override void Init()
        {
            base.Init();

            if (!_slotInited)
            {
                _inventory = new InventoryBase();
                _inventory.Init(MaxSlots);
                foreach (var item in StartItems)
                {
                    _inventory.AddItem(HolderObjectFactory.GetItem(item.name, item.amount));
                }
            }
        }
Example #3
0
        protected override void Init()
        {
            base.Init();

            if (!_slotInited)
            {
                _sourceinventory = new InventoryBase();
                _sourceinventory.Init(SourceSlotsAmount);
                _destinationInventory = new InventoryBase();
                _destinationInventory.Init(DestinationSlotsAmount);

                LightGameObject.SetActive(false);

                _slotInited = true;
            }

            if (AutoStart)
            {
                Fire();
            }
        }
Example #4
0
        public void PlaceSavedItems(List <GroundItemSaveModel> items)
        {
            foreach (var item in LootChests)
            {
                item.gameObject.SetActive(false);
            }

            foreach (var groundItemSaveModel in items)
            {
                var item = BaseObjectFactory.GetItem(groundItemSaveModel.ItemName);

                string prefabPath = string.Empty;
                if (!groundItemSaveModel.Dropped && item is IPlacement)
                {
                    prefabPath = (item as IPlacement).PrefabPath;
                }
                else
                {
                    prefabPath = item.OnGroundPrefabPath;
                }

                var itemPrefab = Resources.Load <GameObject>(prefabPath);
                var itemGo     = Instantiate(itemPrefab);
                if (groundItemSaveModel.Dropped)
                {
                    itemGo.GetComponent <WorldItem>().SetItem(item.GetType(), groundItemSaveModel.Amount, groundItemSaveModel.Durability);
                }

                itemGo.transform.position = new Vector3(groundItemSaveModel.PosX, groundItemSaveModel.PosY,
                                                        groundItemSaveModel.PosZ);
                itemGo.transform.rotation =
                    Quaternion.Euler(new Vector3(groundItemSaveModel.Pitch, groundItemSaveModel.Roll,
                                                 groundItemSaveModel.Yaw));

                var destroyable = itemGo.GetComponentInChildren <DestroyableObject>();
                if (destroyable != null)
                {
                    destroyable.CurrentHp   = groundItemSaveModel.CurrentHp;
                    destroyable.ItemModel   = item;
                    destroyable.Initialized = true;
                }

                if (groundItemSaveModel.IsActive)
                {
                    var iconverter = itemGo.GetComponent <IConverter>();
                    if (iconverter != null)
                    {
                        iconverter.AutoStart = true;
                    }
                }

                var filledItem = itemGo.GetComponent <IFilled>();
                if (filledItem != null)
                {
                    filledItem.CurrentFilledAmount = groundItemSaveModel.AmountFilled;
                }

                AddPlacedItem(itemGo, item, groundItemSaveModel.Dropped, groundItemSaveModel.Amount);

                var inventoryItem = itemGo.GetComponent <IInventoryThing>();
                if (groundItemSaveModel.InventoryList != null && inventoryItem != null)
                {
                    var inventoryList = new List <InventoryBase>();
                    foreach (var invListModel in groundItemSaveModel.InventoryList.InventoryList)
                    {
                        var currentInventory = new InventoryBase();
                        currentInventory.Init(invListModel.SlotAmount);
                        foreach (var invItemModel in invListModel.Items)
                        {
                            var amount = invItemModel.Amount;
                            if (currentInventory.Slots.Count <= invItemModel.SlotId)
                            {
                                currentInventory.Slots.Add(null);
                            }
                            currentInventory.Slots[invItemModel.SlotId] =
                                HolderObjectFactory.GetItem(invItemModel.ItemName, amount,
                                                            invItemModel.CurrentDurability);
                        }
                        inventoryList.Add(currentInventory);
                    }
                    inventoryItem.SetInventoryList(inventoryList);
                }
            }

            SetActiveConstructionColliders(false);
        }
Example #5
0
    protected void Init()
    {
        villagerList.AddRange(FindObjectsOfType <BaseVillager>());

        cameraReference = Camera.main;

        controller = cameraReference.GetComponent <PlayerController>();

        mainUI       = Instantiate(Resources.Load("UI/MainUI")) as GameObject;
        woodText     = mainUI.GetComponentsInChildren <Text>()[0];
        stoneText    = mainUI.GetComponentsInChildren <Text>()[1];
        foodText     = mainUI.GetComponentsInChildren <Text>()[2];
        villagerText = mainUI.GetComponentsInChildren <Text>()[3];


        questMenu        = Instantiate(Resources.Load("UI/QuestMenuPanel")) as GameObject;
        characterMenu    = Instantiate(Resources.Load("UI/CharacterMenuPanel")) as GameObject;
        characterScroll  = characterMenu.GetComponentInChildren <CharacterDisplay>().gameObject;
        characterDisplay = characterScroll.GetComponent <CharacterDisplay>();
        characterInfo    = Instantiate(Resources.Load("UI/SelectedCharacterInfo")) as GameObject;

        buildingMenu    = Instantiate(Resources.Load("UI/BuildingMenuPanel")) as GameObject;
        buildingPanel   = buildingMenu.GetComponentInChildren <HorizontalLayoutGroup>().gameObject;
        buildingInfo    = Instantiate(Resources.Load("UI/BuildingInfoPanel")) as GameObject;
        buildingDisplay = buildingInfo.GetComponentInChildren <BuildingDisplay>();

        lossPanel = Instantiate(Resources.Load("UI/GameOverPanel")) as GameObject;

        inventoryPanel = Instantiate(Resources.Load("UI/InventoryPanel")) as GameObject;
        inventoryPanel.GetComponentInChildren <Dropdown>().onValueChanged.AddListener(delegate { inventoryReference.SortItems(inventoryPanel.GetComponentInChildren <Dropdown>().value); });

        pauseMenu = Instantiate(Resources.Load("UI/PauseMenu")) as GameObject;

        if (!GetComponent <InventoryBase>())
        {
            inventoryReference = gameObject.AddComponent <InventoryBase>();
        }
        else
        {
            inventoryReference = GetComponent <InventoryBase>();
        }

        if (!GetComponent <QuestManager>())
        {
            questManager = gameObject.AddComponent <QuestManager>();
        }
        else
        {
            questManager = GetComponent <QuestManager>();
        }

        pauseMenu.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { TogglePauseMenu(true); });
        pauseMenu.GetComponentsInChildren <Button>()[1].onClick.AddListener(RestartGame);
        pauseMenu.GetComponentsInChildren <Button>()[2].onClick.AddListener(SaveQuit);

        questMenu.GetComponentInChildren <Button>().onClick.AddListener(delegate { ToggleQuestMenu(true); });
        characterMenu.GetComponentInChildren <Button>().onClick.AddListener(ToggleCharacterMenu);

        //Incident Panel
        incidentPanel = Instantiate(Resources.Load("UI/AttackArrivalPanel")) as GameObject;

        //Loss Panel
        lossPanel.GetComponentsInChildren <Button>()[0].onClick.AddListener(RestartGame);
        lossPanel.GetComponentsInChildren <Button>()[1].onClick.AddListener(ReturnToMenu);

        //Build Menu
        buildingText = buildingMenu.transform.GetChild(1).gameObject;
        buildingText.GetComponentsInChildren <Button>()[0].onClick.AddListener(CreateBuilding);
        buildingText.GetComponentsInChildren <Button>()[1].onClick.AddListener(CloseBuildingMenu);

        buildingMenu.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingTownHall") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[1].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingWall") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[2].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingHouse") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[3].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingFarm") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[4].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingLumbercamp") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[5].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingMiningcamp") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[6].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingBarracks") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[7].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingOutpost") as GameObject); });
        buildingMenu.GetComponentsInChildren <Button>()[8].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingBlacksmith") as GameObject); });

        //Barracks Buttons
        buildingInfo.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[1].onClick.AddListener(delegate { AddingCharacter(1); });
        buildingInfo.GetComponentsInChildren <Button>()[2].onClick.AddListener(delegate { AddingCharacter(2); });
        buildingInfo.GetComponentsInChildren <Button>()[3].onClick.AddListener(delegate { AddingCharacter(3); });

        //Blacksmith Buttons
        buildingInfo.GetComponentsInChildren <Button>()[4].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[5].onClick.AddListener(delegate { AddingCharacter(1); });

        //Farm Buttons
        buildingInfo.GetComponentsInChildren <Button>()[7].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[8].onClick.AddListener(delegate { AddingCharacter(1); });
        buildingInfo.GetComponentsInChildren <Button>()[9].onClick.AddListener(delegate { AddingCharacter(2); });
        buildingInfo.GetComponentsInChildren <Button>()[10].onClick.AddListener(delegate { AddingCharacter(3); });

        //Lumbermill Buttons
        buildingInfo.GetComponentsInChildren <Button>()[11].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[12].onClick.AddListener(delegate { AddingCharacter(1); });
        buildingInfo.GetComponentsInChildren <Button>()[13].onClick.AddListener(delegate { AddingCharacter(2); });
        buildingInfo.GetComponentsInChildren <Button>()[14].onClick.AddListener(delegate { AddingCharacter(3); });

        //MiningCamp Buttons
        buildingInfo.GetComponentsInChildren <Button>()[15].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[16].onClick.AddListener(delegate { AddingCharacter(1); });
        buildingInfo.GetComponentsInChildren <Button>()[17].onClick.AddListener(delegate { AddingCharacter(2); });
        buildingInfo.GetComponentsInChildren <Button>()[18].onClick.AddListener(delegate { AddingCharacter(3); });

        //Outpost Buttons
        buildingInfo.GetComponentsInChildren <Button>()[19].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[20].onClick.AddListener(delegate { AddingCharacter(1); });

        //Townhall Buttons
        buildingInfo.GetComponentsInChildren <Button>()[21].onClick.AddListener(delegate { AddingCharacter(0); });
        buildingInfo.GetComponentsInChildren <Button>()[22].onClick.AddListener(delegate { AddingCharacter(1); });
        buildingInfo.GetComponentsInChildren <Button>()[23].onClick.AddListener(delegate { AddingCharacter(2); });
        buildingInfo.GetComponentsInChildren <Button>()[24].onClick.AddListener(delegate { AddingCharacter(3); });

        controller.Init(inventoryPanel, characterInfo, buildingInfo, this);
        characterDisplay.Init(this, characterMenu.GetComponentInChildren <Scrollbar>());
        questManager.Init(questMenu, questMenu.GetComponentInChildren <HorizontalLayoutGroup>().gameObject);
        inventoryReference.Init(inventoryPanel, controller);

        buildingPanelPositionStart = buildingPanel.transform.position;
        buildingPanelPositionEnd   = new Vector3(buildingPanel.transform.position.x - 570, buildingPanel.transform.position.y, buildingPanel.transform.position.z);

        buildingMenu.GetComponentInChildren <Scrollbar>().onValueChanged.AddListener(ScrollBuildingMenu);

        buildingDisplay.Init();

        mainUI.GetComponentsInChildren <Button>()[0].onClick.AddListener(controller.OpenInventory);
        mainUI.GetComponentsInChildren <Button>()[1].onClick.AddListener(ToggleBuildingMenu);
        mainUI.GetComponentsInChildren <Button>()[2].onClick.AddListener(OpenQuestMenu);
        mainUI.GetComponentsInChildren <Button>()[3].onClick.AddListener(ToggleCharacterMenu);
        mainUI.GetComponentsInChildren <Button>()[4].onClick.AddListener(RestartGame);
        mainUI.GetComponentsInChildren <Button> () [5].onClick.AddListener(delegate { TogglePauseMenu(false); });

        Debug.Log("Init Successful");
    }