예제 #1
0
        private static bool Prefix(UIDate __instance)
        {
            if (!Main.enabled)
            {
                return(true);
            }

            AutoHarvest.GetAllBooties();

            ResourceMaintainer.TryBuyingResources();

            ResourceMaintainer.UpdateResourceWarning();

            TurnEvent.AddEvent(__instance);

            if (Main.settings.autoAssignBuildingWorkers)
            {
                HumanResource hr          = new HumanResource();
                int           mainPartId  = int.Parse(DateFile.instance.GetGangDate(16, 3));
                int           mainPlaceId = int.Parse(DateFile.instance.GetGangDate(16, 4));
                hr.AssignBuildingWorkers(mainPartId, mainPlaceId);
            }

            return(true);
        }
예제 #2
0
        public static bool ChangeResourceIdealHolding(int resourceId, bool add, int nMultiple)
        {
            int amount = (add ? 100 : -100) * nMultiple;

            int ideal = Main.settings.resIdealHolding[resourceId] + amount;

            var resourcesInfo = ResourceMaintainer.GetResourcesInfo();
            int max           = resourcesInfo[resourceId].max;

            if (ideal > max)
            {
                ideal = max;
            }
            if (ideal < 0)
            {
                ideal = 0;
            }

            if (Main.settings.resIdealHolding[resourceId] == ideal)
            {
                return(false);
            }

            Main.settings.resIdealHolding[resourceId] = ideal;
            ResourceMaintainer.resIdealHoldingText[resourceId].text = ideal.ToString();
            return(true);
        }
예제 #3
0
        public static void TryBuyingResources()
        {
            ResourceMaintainer.shoppingRecord = "";

            // 过季的时候才能采购
            int solarTerms = DateFile.instance.GetDayTrun();

            if (!(solarTerms == 4 || solarTerms == 10 || solarTerms == 16 || solarTerms == 22))
            {
                return;
            }

            var resourcesInfo = ResourceMaintainer.GetResourcesInfo();

            var resPacksNeedToBuy = ResourceMaintainer.GetResPacksNeedToBuy(resourcesInfo);

            if (resPacksNeedToBuy.Count == 0)
            {
                return;
            }

            var moneyInfo   = resourcesInfo[RES_ID_MONEY];
            int usableMoney = Math.Min(
                moneyInfo.current - Main.settings.moneyMinHolding,
                moneyInfo.current - Math.Max(-moneyInfo.consumed * Main.settings.resMinHolding, 0));

            if (usableMoney <= 0)
            {
                return;
            }

            ResourceMaintainer.BuyResources(usableMoney, resPacksNeedToBuy);
        }
예제 #4
0
        public static void TryBuyingResources()
        {
            ResourceMaintainer.shoppingRecord = "";

            var resourcesInfo = ResourceMaintainer.GetResourcesInfo();

            var resPacksNeedToBuy = ResourceMaintainer.GetResPacksNeedToBuy(resourcesInfo);

            if (resPacksNeedToBuy.Count == 0)
            {
                return;
            }

            var moneyInfo   = resourcesInfo[RES_ID_MONEY];
            int usableMoney = Math.Min(
                moneyInfo.current - Main.settings.moneyMinHolding,
                moneyInfo.current - Math.Max(-moneyInfo.consumed * Main.settings.resMinHolding, 0));

            if (usableMoney <= 0)
            {
                return;
            }

            ResourceMaintainer.BuyResources(usableMoney, resPacksNeedToBuy);
        }
예제 #5
0
        // 因为每时每刻的资源数量都可能变化,因此要显示月初的资源警示,就必须缓存住
        public static void UpdateResourceWarning()
        {
            string text = "";

            foreach (var entry in ResourceMaintainer.GetResourcesInfo())
            {
                var resourceId   = entry.Key;
                var resourceInfo = entry.Value;
                if (resourceInfo.current < -resourceInfo.consumed * Main.settings.resMinHolding)
                {
                    string name = DateFile.instance.resourceDate[(int)resourceId][1];
                    text += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "、";
                }
            }

            if (text.Length > 0)
            {
                text = "以下资源库存不足:" + text.Substring(0, text.Length - 1) + "。\n需要尽快补充,否则将导致建筑损坏。\n";
                text = TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, text);
            }

            ResourceMaintainer.resourceWarning = text;

            if (!string.IsNullOrEmpty(text))
            {
                string recordingMessage = text.Replace("\n", "");
                MajordomoWindow.instance.AppendMessage(new TaiwuDate(), Message.IMPORTANCE_HIGHEST, recordingMessage);
            }
        }
예제 #6
0
 private static void BuyResources(int usableMoney, Dictionary<int, int> resPacksNeedToBuy)
 {
     TemporaryResourceShop shop = new TemporaryResourceShop();
     ResourceMaintainer.boughtResources = new SortedList<int, int>();
     ResourceMaintainer.spentMoney = shop.Buy(usableMoney, resPacksNeedToBuy, ResourceMaintainer.boughtResources);
     ResourceMaintainer.UpdateShoppingRecord();
 }
예제 #7
0
        public static void InitialzeResourcesIdealHolding()
        {
            // 初始化资源保有目标
            if (Main.settings.resIdealHolding == null)
            {
                Main.settings.resIdealHolding = new int[5];

                var resourcesInfo = ResourceMaintainer.GetResourcesInfo();

                for (int i = 0; i < Main.settings.resIdealHolding.Length; ++i)
                {
                    int ideal = (int)(resourcesInfo[i].max * Main.settings.resInitIdealHoldingRatio);
                    ideal = (ideal / 100) * 100;
                    Main.settings.resIdealHolding[i] = ideal;
                }
            }

            // 向资源图标注册鼠标事件
            GameObject[] resourceIcons = GameObject.FindGameObjectsWithTag("ResourceIcon");
            foreach (GameObject resourceIcon in resourceIcons)
            {
                int resourceId = int.Parse(resourceIcon.name.Split(',')[1]);
                switch (resourceId)
                {
                    case RES_ID_FOOD:
                    case RES_ID_WOOD:
                    case RES_ID_STONE:
                    case RES_ID_SILK:
                    case RES_ID_HERBAL:
                        var handler = resourceIcon.AddComponent<ResourceIconPointerHandler>();
                        handler.resourceId = resourceId;
                        break;
                }
            }

            // 增加资源保有目标文本控件
            foreach (var text in GameObject.FindObjectsOfType(typeof(Text)) as Text[])
            {
                switch (text.name)
                {
                    case "FoodUPText":
                        ResourceMaintainer.RegisterResourceIdealHoldingText(RES_ID_FOOD, text.transform.parent);
                        break;
                    case "WoodUPText":
                        ResourceMaintainer.RegisterResourceIdealHoldingText(RES_ID_WOOD, text.transform.parent);
                        break;
                    case "StoneUPText":
                        ResourceMaintainer.RegisterResourceIdealHoldingText(RES_ID_STONE, text.transform.parent);
                        break;
                    case "SilkUPText":
                        ResourceMaintainer.RegisterResourceIdealHoldingText(RES_ID_SILK, text.transform.parent);
                        break;
                    case "HerbalUPText":
                        ResourceMaintainer.RegisterResourceIdealHoldingText(RES_ID_HERBAL, text.transform.parent);
                        break;
                }
            }
        }
예제 #8
0
        static void Postfix()
        {
            if (!Main.enabled)
            {
                return;
            }

            ResourceMaintainer.ShowResourceIdealHoldingText();
        }
예제 #9
0
        static void Postfix()
        {
            if (!Main.enabled)
            {
                return;
            }

            ResourceMaintainer.InitialzeResourcesIdealHolding();
        }
예제 #10
0
        private void OnClick(int nMultiple = 1)
        {
            bool add     = this.pressedButton == PointerEventData.InputButton.Left;
            bool changed = ResourceMaintainer.ChangeResourceIdealHolding(this.resourceId, add, nMultiple);

            if (changed)
            {
                DateFile.instance.PlayeSE(2);
            }
        }
예제 #11
0
        static bool Prefix(WindowManage __instance)
        {
            if (!Main.enabled)
            {
                return(true);
            }

            ResourceMaintainer.InterfereFloatWindow(__instance);

            return(true);
        }
예제 #12
0
        private static bool Prefix(UIDate __instance)
        {
            if (!Main.enabled)
            {
                return(true);
            }

            AutoHarvest.GetAllBooties();

            ResourceMaintainer.TryBuyingResources();

            ResourceMaintainer.UpdateResourceWarning();

            TurnEvent.RegisterEvent(__instance);

            return(true);
        }
예제 #13
0
        private static bool Prefix(UIDate __instance)
        {
            if (!Main.enabled)
            {
                return(true);
            }

            AutoHarvest.GetAllBooties();

            ResourceMaintainer.TryBuyingResources();

            ResourceMaintainer.UpdateResourceWarning();

            TurnEvent.AddEvent(__instance);

            if (Main.settings.autoAssignBuildingWorkers)
            {
                HumanResource.AssignBuildingWorkersForTaiwuVillage();
            }

            return(true);
        }
예제 #14
0
        // 因为每时每刻的资源数量都可能变化,因此要显示月初的资源警示,就必须缓存住
        public static void UpdateResourceWarning()
        {
            string text = "";

            foreach (var entry in ResourceMaintainer.GetResourcesInfo())
            {
                var resourceId   = entry.Key;
                var resourceInfo = entry.Value;
                if (resourceInfo.current < -resourceInfo.consumed * Main.settings.resMinHolding)
                {
                    string name = DateFile.instance.resourceDate[(int)resourceId][1];
                    text += name + "、";
                }
            }
            if (text.Length > 0)
            {
                text = "以下资源库存不足,需要尽快补充,否则将导致建筑损坏:" +
                       text.Substring(0, text.Length - 1) + "。\n";
                text = DateFile.instance.SetColoer(20009, text);  // 橙色文字
            }

            ResourceMaintainer.resourceWarning = text;
        }