Exemple #1
0
        private static List <string> DumpGenericStats(FarmItemDefinition def)
        {
            var list = new List <string>();

            list.AddRange(new[]
            {
                def.name,
                Localization.Get(def.FullId, true),
                def.Category.ToString(),
                def.MinLevel.ToString(),
                GetRequirements(def),
                def.RequiredDLC.ToString(),
                def.IsEventItem ? "Y" : "N",
                def.IsEventReward ? "Y" : "N",
                def.SeasonalEvent.ToString(),
                def.VariablePrice ? "Y" : "N",
                def.VariablePriceItemCountFactor.ToString(),
                def.BuyXp.ToString()
            });
            list.AddRange(ConvertMoney(def.Price));
            if (def is HarvestItemDefinition)
            {
                var harvestItemDefinition = (HarvestItemDefinition)def;
                list.Add(harvestItemDefinition.Resource.Type.ToString());
                list.Add(harvestItemDefinition.Resource.Amount.ToString());
            }
            else
            {
                list.AddRange(new string[2]);
            }

            return(list);
        }
 public static bool CanBuy(
     PlayerScript player,
     FarmItemDefinition definition,
     FarmData __instance,
     bool __result
     )
 {
     if (!isEnable)
     {
         return(true);
     }
     #region
     //logger.Log(definition.);
     //for (int i = 0; i < building.buildings.Count; i++)
     //{
     //    if (building.buildings[i].isEnable)
     //    {
     //        if(definition.FullId== building.buildings[i].ID)
     //        {
     //            definition.ItemCountLimit = building.buildings[i].limit;
     //        }
     //    }
     //}
     #endregion
     {
         //完全版
         definition.ItemCountLimit = 99999;
     }
     return(true);
 }
Exemple #3
0
        private static string GetRequirements(FarmItemDefinition f)
        {
            var list = new List <string>();

            foreach (var itemLevelRequirement in f.ItemLevelRequirements)
            {
                list.Add(itemLevelRequirement.Item.name + "@" + itemLevelRequirement.Level);
            }

            return(string.Join(",", list.ToArray()));
        }
 public static bool CanBuy(
     PlayerScript player,
     FarmItemDefinition definition,
     FarmData __instance,
     bool __result
     )
 {
     if (!isEnable)
     {
         return(true);
     }
     {
         //完全版
         definition.ItemCountLimit = 99999;
     }
     return(true);
 }
        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($"填充失败,未定义此类物品的填充方法");
            }
        }