コード例 #1
0
        /// <summary>
        /// 检查工作可行性
        /// </summary>
        /// <param name="workTiles">工作列表,如果可行将加进列表</param>
        /// <param name="contents">工作目标</param>
        /// <param name="workType">工作类型</param>
        /// <param name="count">统计计数</param>
        public static void TryWork(List <FarmTile> workTiles, FarmTileContents contents, WorkType workType, ref int count)
        {
            FailedActionReason far;

            if (contents.CanWork(StageScript.Instance.LocalPlayer, workType, out far))
            {
                workTiles.Add(contents.Tile);
                count++;
            }
        }
コード例 #2
0
 public static bool Prefix(FarmTile __instance, FarmTileContents content)
 {
     if (mod.Enabled)
     {
         if (startFill)
         {
             SetContent(__instance, content);
             return(false);
         }
     }
     return(true);
 }
コード例 #3
0
        public static void SetContent(FarmTile tile, FarmTileContents content)
        {
            var ct = Traverse.Create(tile).Field("contents");

            ct.SetValue(content);
            if (content != null)
            {
                FarmTileContentsType category = content.Category;
                var tsc = Traverse.Create(tile).Field("tileState");
                switch (category)
                {
                case FarmTileContentsType.Crop:
                    tsc.SetValue(FarmTileState.Plow);
                    break;

                default:
                    if (category != FarmTileContentsType.Flower)
                    {
                        tsc.SetValue(FarmTileState.Building);
                    }
                    else
                    {
                        tsc.SetValue(FarmTileState.Flower);
                    }
                    break;

                case FarmTileContentsType.Animal:
                    tsc.SetValue(FarmTileState.Animal);
                    break;

                case FarmTileContentsType.Pond:
                    tsc.SetValue(FarmTileState.Pond);
                    break;
                }
            }
        }
コード例 #4
0
        public static void Fill(string id, Texture2D pic)
        {
            //判断尺寸
            var farm = StageScript.Instance.FarmData;

            mod.Logger.Log($"像素画尺寸 w:{pic.width} h:{pic.height}");
            if (pic.width != 280 || pic.height != 140)
            {
                mod.Logger.Log("像素画尺寸不等于280x140,停止工作");
                return;
            }
            //判断物品
            FarmItemDefinition fillObj = null;

            foreach (var kv in ShopManager.ItemDictionary)
            {
                if (kv.Value.FullId == id)
                {
                    mod.Logger.Log($"找到了ID为{id}的物品,名字为{Localization.Get(id)}");
                    fillObj = kv.Value;
                    break;
                }
            }
            if (fillObj == null)
            {
                mod.Logger.Log("未找到物品");
                return;
            }
            FailedActionReason far;
            int        workCount   = 0;
            FillAction action      = null;
            Type       contentType = null;

            switch (fillObj.Category)
            {
            case ShopItemType.Crop:
                contentType = Assembly.Load("Assembly-CSharp").GetType("Logic.Farm.Contents.FarmCrop");
                action      = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        FarmTileContents content = Activator.CreateInstance(contentType, fillObj, tile) as FarmTileContents;
                        Traverse.Create(content).Field("state").SetValue(byte.Parse("1"));     //设置作物为成熟状态
                        SetContent(tile, content);
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Tree:
                action = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        SetContent(tile, new FarmTree(fillObj as TreeDefinition, tile));
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Animal:
                action = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        farm.PlaceAnimal(fillObj as AnimalDefinition, tile.TileId, out far);
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Pond:
                action = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        farm.PlacePond(fillObj as PondDefinition, tile.TileId, out far);
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Building:
            case ShopItemType.House:
            case ShopItemType.Decoration:
                action = new FillAction((tile) =>
                {
                    if (farm.CanPlaceBuilding(fillObj as BaseBuildingDefinition, tile.TileId, 0, out far))
                    {
                        farm.PlaceBuilding(fillObj as BaseBuildingDefinition, tile.TileId, 0, farm.GetNextBuildingId(), out far);
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Road:
                contentType = Assembly.Load("Assembly-CSharp").GetType("Logic.Farm.Contents.FarmRoad");
                action      = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        SetContent(tile, Activator.CreateInstance(contentType, fillObj, tile) as FarmTileContents);
                        workCount++;
                    }
                });
                break;

            case ShopItemType.Flower:
                contentType = Assembly.Load("Assembly-CSharp").GetType("Logic.Farm.Contents.FarmFlower");
                action      = new FillAction((tile) =>
                {
                    if (tile.CheckEmpty(out far))
                    {
                        FarmTileContents content = Activator.CreateInstance(contentType, fillObj, tile) as FarmTileContents;
                        Traverse.Create(content).Field("state").SetValue(1);     //设置花为成熟状态
                        SetContent(tile, content);
                        workCount++;
                    }
                });
                break;
            }
            if (action != null)
            {
                startFill = true;
                for (int x = 0; x < 280; x++)
                {
                    for (int y = 0; y < 140; y++)
                    {
                        if (IsNearBlack(pic.GetPixel(x, y)))
                        {
                            var tile = farm.GetTile(GetId(x, y));
                            if (tile != null)
                            {
                                action(tile);
                            }
                        }
                    }
                }
                startFill = false;
                mod.Logger.Log($"导入完毕,共填充{workCount}个地块");
            }
            else
            {
                mod.Logger.Log($"填充失败,未定义此类物品的填充方法");
            }
        }
コード例 #5
0
        /// <summary>
        /// 一键收获
        /// </summary>
        public static void Harvest()
        {
            if (StageScript.Instance.IsOnline)
            {
                if (StageScript.Instance.LocalPlayer.Permissions != PlayerPermissions.Full)
                {
                    SendChat("[一键收获] 没有权限,你必须拥有农场全部权限才能进行此操作");
                    return;
                }
            }
            if (!(setting.animalHarvestToggle || setting.cropHarvestToggle || setting.flowerHarvestToggle || setting.pondHarvestToggle || setting.treeHarvestToggle))
            {
                SendChat("[一键收获] 所有选项都已关闭,无法进行工作");
                return;
            }
            if (startWork)
            {
                SendChat("正在进行工作,请等待工作结束");
                return;
            }
            startWork     = true;
            startWorkType = WorkType.Harvest;
            int animal = 0, crop = 0, flower = 0, tree = 0, pond = 0;

            FarmChunk[,] chunks = StageScript.Instance.FarmData.Chunks;
            List <FarmTile> workTiles = new List <FarmTile>();

            for (int i = 0; i < chunks.GetLength(0); i++)
            {
                for (int j = 0; j < chunks.GetLength(1); j++)
                {
                    if (chunks[i, j] != null)
                    {
                        if (chunks[i, j].IsUnlocked)
                        {
                            for (int x = 0; x < chunks[i, j].Tiles.GetLength(0); x++)
                            {
                                for (int y = 0; y < chunks[i, j].Tiles.GetLength(1); y++)
                                {
                                    if (chunks[i, j].Tiles[x, y] != null)
                                    {
                                        FarmTileContents contents = chunks[i, j].Tiles[x, y].Contents;
                                        if (contents != null)
                                        {
                                            switch (contents.Category)
                                            {
                                            case FarmTileContentsType.Animal: if (setting.animalHarvestToggle)
                                                {
                                                    TryWork(workTiles, contents, WorkType.Harvest, ref animal);
                                                }
                                                break;

                                            case FarmTileContentsType.Crop: if (setting.cropHarvestToggle)
                                                {
                                                    TryWork(workTiles, contents, WorkType.Harvest, ref crop);
                                                }
                                                break;

                                            case FarmTileContentsType.Flower: if (setting.flowerHarvestToggle)
                                                {
                                                    TryWork(workTiles, contents, WorkType.Harvest, ref flower);
                                                }
                                                break;

                                            case FarmTileContentsType.Tree: if (setting.treeHarvestToggle)
                                                {
                                                    TryWork(workTiles, contents, WorkType.Harvest, ref tree);
                                                }
                                                break;

                                            case FarmTileContentsType.Pond: if (setting.pondHarvestToggle)
                                                {
                                                    TryWork(workTiles, contents, WorkType.Harvest, ref pond);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //每一万个格子分成一个工作批次
                    if (workTiles.Count > 10000)
                    {
                        workQueue.Enqueue(workTiles);
                        workTiles = new List <FarmTile>();
                    }
                }
            }
            if (workTiles.Count > 0)
            {
                workQueue.Enqueue(workTiles);
            }
            string logmsg             = "[一键收获] 准备进行收获,目标: ";

            if (setting.animalHarvestToggle)
            {
                logmsg += animal + "动物 ";
            }
            if (setting.cropHarvestToggle)
            {
                logmsg += crop + "作物 ";
            }
            if (setting.flowerHarvestToggle)
            {
                logmsg += flower + "花 ";
            }
            if (setting.pondHarvestToggle)
            {
                logmsg += tree + "树 ";
            }
            if (setting.treeHarvestToggle)
            {
                logmsg += pond + "鱼池 ";
            }
            SendChat(logmsg);
            if (workQueue.Count > 1)
            {
                SendChat("开始工作,目标过多,将分成" + workQueue.Count.ToString() + "个批次工作,期间请勿操作人物");
            }
        }