PostCooking & Campfire

Posts 1–3 of 3 · Page 1 of 1
Cooking & Campfire
Cooking...self explanatory but I cannot say the same for the coding, I am to lazy to make it simpler but at least it is something to work off if anyone is interested.

 
World.cs

This just checks if X and Y is a <Campfire/> don't bother this it isn't really to be changed
Code:
        public bool IsCampFire(int x, int y)
        {
            var tile = Map[x, y];
            ObjectDesc desc;
            if (Manager.GameData.ObjectDescs.TryGetValue(tile.ObjType, out desc))
            {
                if (!desc.Campfire)
                    return false;
            }
            return true;
        }


 
Descriptors.cs

<Cookable/> Add this to your item or it will not "cook"
Code:
    public bool Cookable { get; private set; }
    Cookable = elem.Element("Cookable") != null;
<Campfire/> Add this to the non-static object that will be your campfire, the player must stand on top of the campfire for it to work.
Code:
    public bool Campfire { get; private set; }
    Campfire = elem.Element("Campfire") != null;

 
(Admin/N> Command.cs

You don't have to worry about the command itself, the raw/cooked food item type goes in the cookassociation
Code:
    internal class Cook : Command
    {
        public Cook() : base("cook"){}
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            if (args.Length == 0)
            {
                player.SendHelp("Usage: /cook <Cookable-ItemName>");
                return false;
            }
            string name = string.Join(" ", args.ToArray()).Trim();
            ushort obj_1;
             Dictionary<string, ushort> icdatas = new Dictionary<string,  ushort>(player.Manager.GameData.IdToObjectType,
                StringComparer.OrdinalIgnoreCase);
            if (!icdatas.TryGetValue(name, out obj_1))
            {
                player.SendError("Unknown type!");
                return false;
            }
            if (!CookAssociation.CheckForCampfire(player))
            {
                player.SendError("You must be standing on top of a campfire!");
                return false;
            }
            if (player.Manager.GameData.Items[obj_1].Cookable)
            {
                ushort obj_2 = CookAssociation.ItemConversion(obj_1);
                for (int g = 0; g < player.Inventory.Length; g++)
 
(Admin/N> Command.cs
Code:
               {
                       if (player.Inventory[g] != player.Manager.GameData.Items[obj_1]) { continue;}
                    player.Inventory[g] = player.Manager.GameData.Items[obj_2];
                       player.UpdateCount++;                       player.SaveToCharacter();
                       player.SendInfo("Success!");
                       break;
                }
            }
            else
            {
                player.SendError("The item is not Cookable");
                return false;
            }
            return true;
        }
    }

It is a two set piece to simplify and shorten the command so it doesn't get filled with spam.
the ItemConversion is where you will place the raw food to/=> cooked food.
NOTE : Currently in the case and switch it has case 0x999 and return 0x998 these are not real items it is just there to fill in.
SECONDARY NOTE : CASE is the RAW food and RETURN is the COOKED food

Code:
    internal class CookAssociation
    {
        public static bool CheckForCampfire(Player player)
        {
            int x = (int) player.X;
            int y = (int) player.Y;
            return (player.Owner.IsCampFire(x, y));
        }

        public static ushort ItemConversion(ushort obj_1)
        {
            switch (obj_1)
            {
                case 0x999:
                    return 0x998;
                default:
                    return obj_1;
            }
        }
    }

There is not suppose to be 2 spoilers of Command.cs MPGH is just being annoying and somehow glitching.

If I were to use this I would have to stand on top of the campfire, type /cook "item", and it will automatically give me the corresponding item.


@Riigged Sorry, for taking your idea if you wish I can request the moderators to remove this just pm me.
@Joe @Nyaro's Panda Close it, anyone with any questions or concerns just pm me.
I dont mind, I shared the idea on the thread for the exact reason: so people can use it.
I already finished mine, although its done differently, no command is used, its just automatic when you stand on a tile around the campfire (I just use forbidden jungle fire texture xD)
Requested Close
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us