public void LoadFromFile(string path, string key = "", bool dencrypt = false)
 {
     try
     {
         string[]        infos  = System.IO.File.ReadAllLines(path + DataName, System.Text.Encoding.UTF8);
         List <ShopInfo> sinfos = new List <ShopInfo>();
         foreach (string info in infos)
         {
             if (dencrypt && key.Length == 32)
             {
                 sinfos.Add(Newtonsoft.Json.JsonConvert.DeserializeObject <ShopInfo>(Encryption.Dencrypt(info, key)));
             }
             else
             {
                 sinfos.Add(Newtonsoft.Json.JsonConvert.DeserializeObject <ShopInfo>(info));
             }
         }
         foreach (ShopInfo si in sinfos)
         {
             //Debug.Log(si.ID + si.Goods);
             ShopAgent sa = ShopAgents.Find(s => s.ID == si.ID);
             sa.LoadFromInfo(si);
         }
     }
     catch { }
 }
Exemplo n.º 2
0
        public void SetVisible(UsableItemDetails details, ShopAgent seller)
        {
            _shopDetails = details;
            gameObject.SetActive(true);

            _seller            = seller;
            newPriceField.text = details.ToString();
        }
        public AgentData GetShop(ShopAgent shopAgent)
        {
            if (!_shopSystems.ContainsKey(shopAgent))
            {
                _shopSystems.Add(shopAgent, new AgentData(basePrices));
            }

            return(_shopSystems[shopAgent]);
        }
 public void CloseUI()
 {
     shopAgent = null;
     buyPage.group.SetAllTogglesOff();
     buyPage.isOn = true;
     buyPage.onValueChanged.Invoke(true);
     MyTools.SetActive(UI.gameObject, false);
     MyTools.SetActive(shopButton.gameObject, false);
 }
 private void Start()
 {
     shopAgent       = null;
     GoodsGridCells  = new List <GameObject>();
     BuyerGridCells  = new List <GameObject>();
     MakingGridCells = new List <GameObject>();
     shopButton.onClick.AddListener(OnShopButtonClick);
     CloseUI();
 }
        private List <UsableItem> GetItems(ShopAgent shopAgent)
        {
            var itemList = new List <UsableItem>();

            foreach (var item in shopAgent.agentInventory.Items)
            {
                itemList.Add(item.Value[0]);
            }
            return(itemList);
        }
        public void SetCurrentPrice(ShopAgent shopAgent, int item, int increment)
        {
            var items = GetShopItems(shopAgent);

            if (item < items.Count)
            {
                SetCurrentPrice(shopAgent, items[item].itemDetails, increment);
            }
            Refresh();
        }
Exemplo n.º 8
0
        public void Init()
        {
            adventurerSystemBehaviour = GameObject.FindObjectOfType <AdventurerSystemBehaviour>();
            adventurerSystem          = adventurerSystemBehaviour.system;

            SpawnAgents();

            //Get Adventurer Agent
            getAdventurerAgent = GameObject.FindObjectOfType <GetCurrentAdventurerAgent>();
            adventurerAgent    = getAdventurerAgent.CurrentAgent;

            //Generate travelSubsystem of the adventurerSystem
            travelSubsystem = adventurerSystem.travelSubsystem;
            travelSubsystem.Start();
            adventurerSystem.travelSubsystem = travelSubsystem;

            //Request System
            requestShopSystemBehaviour = GameObject.FindObjectOfType <RequestShopSystemBehaviour>();
            requestShopSystem          = requestShopSystemBehaviour.system;
            requestSystem = requestShopSystem.requestSystem;
            requestSystem.Start();

            //Generate PlayerFighterData of the adventurerAgent
            adventurerAgent.gameObject.GetComponent <AdventurerFighterData>().Start();
            //Generate adventurerInventory of the adventurerAgent
            adventurerInventory = adventurerAgent.adventurerInventory;
            //Generate agentInventory of the adventurerAgent
            adventurerAgentInventory = adventurerAgent.inventory;
            adventurerAgent.ResetEconomyAgent();
            //Generate AdventurerRequestTaker
            adventurerAgent.requestTaker.Start();


            //Get ShopAgent
            getShopAgent = GameObject.FindObjectOfType <GetCurrentShopAgent>();
            shopAgent    = getShopAgent.CurrentAgent;
            shopAgent.shopInput.Awake();
            shopAgent.agentInventory.ResetInventory();
            shopAgent.craftingInventory.ResetInventory();
            shopAgent.wallet.Reset();

            //ShopSystem
            shopCraftingSystemBehaviour = GameObject.FindObjectOfType <ShopCraftingSystemBehaviour>();
            shopCraftingSystemBehaviour.Start();
            agentShopSubSystem = shopCraftingSystemBehaviour.system.shopSubSubSystem;
            craftingSubSystem  = shopCraftingSystemBehaviour.system.craftingSubSubSystem;

            //ResetSystem
            environmentReset = GameObject.FindObjectOfType <EnvironmentReset>();
            environmentReset.Start();

            //Config
            configSystem = GameObject.FindObjectOfType <EconomyProject.Scripts.ConfigSystem>();
            configSystem.Start();
        }
 public void SetShop(ShopAgent shopAgent, List <BaseItemPrices> basePrices)
 {
     if (!_shopSystems.ContainsKey(shopAgent))
     {
         _shopSystems.Add(shopAgent, new AgentData(basePrices));
     }
     else
     {
         _shopSystems[shopAgent] = new AgentData(basePrices);
     }
 }
Exemplo n.º 10
0
        public float[] GetSenses(ShopAgent agent)
        {
            var output = new float [CraftingRequest.SenseCount];

            if (_shopRequests.ContainsKey(agent))
            {
                var senseA = _shopRequests[agent].GetSenses();
                senseA.CopyTo(output, 0);
            }
            return(output);
        }
 public void CantShop()
 {
     MyTools.SetActive(shopButton.gameObject, false);
     shopAgent     = null;
     shopName.text = string.Empty;
     if (ItemTipsManager.Instance.UI.activeSelf && (ItemTipsManager.Instance.goodsAgent || ItemTipsManager.Instance.makingAgent || ItemTipsManager.Instance.buyerItemAgent))
     {
         ItemTipsManager.Instance.CloseUI();
     }
     ItemConfirmManager.Instance.CloseUI();
     CloseUI();
 }
Exemplo n.º 12
0
        public void SetShopAgent(AdventurerAgent adventurerAgent, ShopAgent shopAgent)
        {
            var found = false;

            for (var i = 0; i < GetAgents.Length && !found; i++)
            {
                if (GetAgents[i] == shopAgent)
                {
                    found = true;
                    _currentShop[adventurerAgent] = i;
                }
            }
        }
Exemplo n.º 13
0
        public void SubmitToShop(ShopAgent agent, int item)
        {
            var items = GetItems(agent);

            if (item < items.Count)
            {
                var shopItem = items[item];
                SubmitToShop(agent, shopItem);
            }
            else
            {
                Debug.Log("Out of range submit");
            }
        }
Exemplo n.º 14
0
        public void SubmitToShop(ShopAgent agent, UsableItem item)
        {
            if (agent.agentInventory.ContainsItem(item) == false)
            {
                Debug.Log("Out of range submit. Item : " + item.ToString());
                return;
            }

            var shop = GetShop(agent);

            shop.SubmitToShop(item);
            agent.agentInventory.RemoveItem(item);

            Refresh();
        }
Exemplo n.º 15
0
        public void PurchaseItem(ShopAgent shopAgent, UsableItemDetails item, EconomyWallet wallet, AgentInventory inventory)
        {
            var shop    = GetShop(shopAgent);
            var success = shop.PurchaseItems(shopAgent.wallet, item, wallet, inventory);

            if (success)
            {
                OverviewVariables.SoldItem();

                if (item.itemName == endItem.itemDetails.itemName)
                {
                    //resetScript.ResetScript();
                }
            }
            Refresh();
        }
Exemplo n.º 16
0
        public void MakeRequest(ShopAgent shopAgent, int input)
        {
            var foundChoice = craftingRequirement.Single(c => c.choice == (CraftingChoice)input);

            if (foundChoice.resource && !HasRequest(shopAgent))
            {
                var craftingInventory = shopAgent.GetComponent <CraftingInventory>();
                var hasResources      = craftingInventory.HasResources(foundChoice.resource);
                if (hasResources)
                {
                    _shopRequests.Add(shopAgent, new CraftingRequest {
                        CraftingRequirements = foundChoice.resource
                    });
                    _shopAgents.Add(shopAgent);
                    Debug.Log("Add request");
                }
            }
        }
Exemplo n.º 17
0
 private void SetCurrentPrice(ShopAgent shopAgent, UsableItemDetails item, int increment)
 {
     GetShop(shopAgent).SetCurrentPrice(item, increment);
     Refresh();
 }
Exemplo n.º 18
0
 public int GetNumber(ShopAgent shopAgent, UsableItemDetails item)
 {
     return(GetShop(shopAgent).GetNumber(item));
 }
Exemplo n.º 19
0
        public float[] GetSenses(ShopAgent agent)
        {
            var items = basePrices.Select(b => b.item).ToList();

            return(GetShop(agent).GetSenses(items));
        }
 public void CanShop(ShopAgent shopAgent)
 {
     this.shopAgent = shopAgent;
     shopName.text  = shopAgent.shopName;
     MyTools.SetActive(shopButton.gameObject, true);
 }
Exemplo n.º 21
0
 public float Progress(ShopAgent agent)
 {
     return(_shopRequests.ContainsKey(agent) ? _shopRequests[agent].Progress : 0.0f);
 }
Exemplo n.º 22
0
 public bool HasRequest(ShopAgent agent)
 {
     return(_shopRequests.ContainsKey(agent));
 }
Exemplo n.º 23
0
 public int GetPrice(ShopAgent shopAgent, UsableItemDetails item)
 {
     return(GetShop(shopAgent).GetPrice(item));
 }
Exemplo n.º 24
0
        public float[] GetSenses(ShopAgent agent)
        {
            var craftingRequests = GetAllCraftingRequests(agent.craftingInventory);

            return(CraftingResourceRequest.GetSenses(craftingRequests, 5));
        }
Exemplo n.º 25
0
 public List <UsableItem> GetShopItems(ShopAgent shopAgent)
 {
     return(GetShop(shopAgent).GetShopItems());
 }