コード例 #1
0
 public override StardewValley.Object attach(StardewValley.Object o)
 {
     if (o != null)
     {
         StardewValley.Object @object = this.attachments[0];
         if (@object != null && @object.canStackWith((Item)o))
         {
             @object.Stack = o.addToStack(@object);
             if (@object.Stack <= 0)
             {
                 @object = (StardewValley.Object)null;
             }
         }
         this.attachments[0] = o;
         Game1.playSound("button1");
         return(@object);
     }
     else
     {
         if (this.attachments[0] != null)
         {
             StardewValley.Object attachment = this.attachments[0];
             this.attachments[0] = (StardewValley.Object)null;
             Game1.playSound("dwop");
             return(attachment);
         }
     }
     return((StardewValley.Object)null);
 }
コード例 #2
0
        public static SimilarItem GetSimilarity(StardewValley.Object obj, Item otherItem)
        {
            var otherObj = otherItem as StardewValley.Object;

            if (otherObj == null)
            {
                return(GetSimilarity((Item)obj, otherItem));
            }

            float similarity = 0;

            if (obj.canStackWith(otherItem))
            {
                similarity += 100;
            }

            similarity += (obj.Name == otherObj.Name) ? 100 : 0;
            similarity += (obj.Category == otherObj.Category) ? 2 : 0;
            similarity += (obj.Type == otherObj.Type) ? 5 : 0;
            similarity += -Math.Abs(obj.Quality - otherObj.Quality);

            //float qualityScore = a.SpecialVariable;
            return(new SimilarItem()
            {
                Similarity = similarity,
                Item = otherItem
            });
        }
コード例 #3
0
        // This method is used by the game to attach the given object to the tool.
        // To actually attach an object, you use attachments[<index>] = <object to attach>;
        // The returned object is what is placed in the player's cursor.
        public override StardewValley.Object attach(StardewValley.Object o)
        {
            /* Seeds: attachment slot 0 */
            if (o != null && o.category == StardewValley.Object.SeedsCategory)
            {
                StardewValley.Object obj = attachments[0];
                if (obj != null && obj.canStackWith(o))
                {
                    obj.Stack = o.addToStack(obj.Stack);
                    if (obj.Stack <= 0)
                    {
                        obj = null;
                    }
                }
                attachments[0] = o;
                Game1.playSound("button1");
                return(obj);
            }

            /* Fertilizer: attachment slot 1 */
            if (o != null && o.category == StardewValley.Object.fertilizerCategory)
            {
                StardewValley.Object obj = attachments[1];
                if (obj != null && obj.canStackWith(o))
                {
                    obj.Stack = o.addToStack(obj.Stack);
                    if (obj.Stack <= 0)
                    {
                        obj = null;
                    }
                }
                attachments[1] = o;
                Game1.playSound("button1");
                return(obj);
            }

            // Remove attachments.
            if (o == null)
            {
                // Remove seeds first.
                if (attachments[0] != null)
                {
                    StardewValley.Object attachment = attachments[0];
                    attachments[0] = null;
                    Game1.playSound("dwop");
                    return(attachment);
                }

                // Remove fertilizer second.
                if (attachments[1] != null)
                {
                    StardewValley.Object attachment = attachments[1];
                    attachments[1] = null;
                    Game1.playSound("dwop");
                    return(attachment);
                }
            }

            return(null); // unreachable?
        }
コード例 #4
0
 internal static bool CanCombine(SObject Machine1, SObject Machine2)
 {
     return(Machine1 != null && Machine2 != null &&
            Machine1.bigCraftable.Value && Machine2.bigCraftable.Value &&
            Machine1.Stack >= 1 && Machine2.Stack >= 1 &&
            Machine1.ParentSheetIndex == Machine2.ParentSheetIndex &&
            (Machine1.IsCombinedMachine() || Machine2.IsCombinedMachine() || Machine1.canStackWith(Machine2)));
 }
コード例 #5
0
        public static bool attach(MilkPail __instance, StardewValley.Object o, ref StardewValley.Object __result)
        {
            if (!IsInseminationSyringe(__instance))
            {
                return(true);
            }

            if (o != null)
            {
                StardewValley.Object @object = __instance.attachments[0];
                if (@object != null && @object.canStackWith((Item)o))
                {
                    @object.Stack = o.addToStack(@object);
                    if (@object.Stack <= 0)
                    {
                        @object = (StardewValley.Object)null;
                    }
                }
                __instance.attachments[0] = o;
                Game1.playSound("button1");
                __result = @object;
                return(false);
            }
            else
            {
                if (__instance.attachments[0] != null)
                {
                    StardewValley.Object attachment = __instance.attachments[0];
                    __instance.attachments[0] = (StardewValley.Object)null;
                    Game1.playSound("dwop");
                    __result = attachment;
                    return(false);
                }
            }
            __result = (StardewValley.Object)null;
            return(false);
        }
コード例 #6
0
 /// <summary>The method to call before <see cref="FishingRod.attach"/>.</summary>
 private static bool Before_Attach(FishingRod __instance, SObject o, ref SObject __result)
 {
     if (o?.Category == -21 && __instance.UpgradeLevel > 1)
     {
         SObject tmp = __instance.attachments[0];
         if (tmp != null && tmp.canStackWith(o))
         {
             tmp.Stack = o.addToStack(tmp);
             if (tmp.Stack <= 0)
             {
                 tmp = null;
             }
         }
         __instance.attachments[0] = o;
         Game1.playSound("button1");
         __result = tmp;
         return(false);
     }
     if (o?.Category == -22 && __instance.UpgradeLevel > 2)
     {
         // Rewrote this portion
         bool hasEnchant = __instance.hasEnchantmentOfType <MoreLuresEnchantment>();
         if (__instance.attachments[1] == null)
         {
             __instance.attachments[1] = o;
         }
         else if (__instance.attachments[2] == null && hasEnchant)
         {
             __instance.attachments[2] = o;
         }
         else if (__instance.attachments[2] != null && hasEnchant)
         {
             __result = __instance.attachments[2];
             __instance.attachments[2] = o;
         }
         else if (__instance.attachments[1] != null)
         {
             __result = __instance.attachments[1];
             __instance.attachments[1] = o;
         }
         Game1.playSound("button1");
         return(false);
     }
     if (o == null)
     {
         if (__instance.attachments[0] != null)
         {
             SObject result2 = __instance.attachments[0];
             __instance.attachments[0] = null;
             Game1.playSound("dwop");
             __result = result2;
             return(false);
         }
         if (__instance.attachments[2] != null)
         {
             SObject result3 = __instance.attachments[2];
             __instance.attachments[2] = null;
             Game1.playSound("dwop");
             __result = result3;
             return(false);
         }
         if (__instance.attachments[1] != null)
         {
             SObject result3 = __instance.attachments[1];
             __instance.attachments[1] = null;
             Game1.playSound("dwop");
             __result = result3;
             return(false);
         }
     }
     __result = null;
     return(false);
 }