示例#1
0
文件: Item.cs 项目: sokol815/Exilania
        /// <summary>
        ///
        /// </summary>
        /// <param name="p">item being added</param>
        /// <param name="ppiece_id">position in array of pieces (from the Exilania.ItemManager class)</param>
        /// <param name="parent_piece">id of parent to be added to</param>
        /// <param name="my_rotation">the number of clockwise 90 degree turns to do to attach it</param>
        /// <param name="my_attach">which point to attach to on the new piece</param>
        /// <param name="parent_attach">which point to attach to on the parent piece</param>
        public void add_piece(ItemPiece p, int ppiece_id, int parent_piece, int my_rotation, int my_attach, int parent_attach)
        {
            if (parent_piece == -1)
            {
                pieces.Add(new ItemPieceEnumeration(ppiece_id, 0, 0, my_rotation));
                for (int x = 0; x < p.item_attach_points.Count; x++)
                {
                    pieces[0].children[x] = -1;
                }
                return;
            }
            //calculate the location of this item relative to the parent item, then get the center and that is the position of the item.
            Point parent_at = get_point_offset_position(parent_piece, parent_attach);

            pieces.Add(new ItemPieceEnumeration(ppiece_id, 0, 0, my_rotation));
            for (int x = 0; x < p.item_attach_points.Count; x++)
            {
                pieces[pieces.Count - 1].children[x] = -1;
            }
            Point my_at = get_point_offset_position(pieces.Count - 1, my_attach);

            pieces[pieces.Count - 1].loc.X = pieces[parent_piece].loc.X + parent_at.X - my_at.X;
            pieces[pieces.Count - 1].loc.Y = pieces[parent_piece].loc.Y + parent_at.Y - my_at.Y;
        }
示例#2
0
        public ItemManager()
        {
            item_pieces        = new List <ItemPiece>();
            custom_item_images = new Dictionary <int, Texture2D>();

            if (System.IO.File.Exists(@"item_pieces.txt"))
            {
                System.IO.StreamReader r = new System.IO.StreamReader(@"item_pieces.txt");
                string    line           = "";
                ItemPiece p    = new ItemPiece();
                bool      cont = true;
                while (cont)
                {
                    line = r.ReadLine();
                    if (line[0] == '#')
                    {
                        //skip this line
                    }
                    else
                    {
                        string[] items = line.Split(':');
                        switch (items[0])
                        {
                        case "PIECE":
                            if (p.name == "")
                            {
                                p.name = items[1];
                            }
                            else
                            {
                                item_pieces.Add(p);
                                Exilania.text_stream.WriteLine("Item Piece '" + p.name + "' Loaded.");
                                p      = new ItemPiece();
                                p.name = items[1];
                            }
                            break;

                        case "IMAGE":
                            items   = Acc.get_inner_parenthesis(items[1]).Split(',');
                            p.image = new Rectangle(Int32.Parse(items[0]), Int32.Parse(items[1]), Int32.Parse(items[2]), Int32.Parse(items[3]));
                            break;

                        case "HAND-ATTACH":
                            items = items[1].Split(',');
                            p.hand_attach_point     = new Point(Int32.Parse(items[0]), Int32.Parse(items[1]));
                            p.has_hand_attach_point = true;
                            break;

                        case "ATTACH-POINT":
                            items = Acc.get_inner_parenthesis(items[1]).Split(',');
                            p.item_attach_points.Add(new Point(Int32.Parse(items[0]), Int32.Parse(items[1])));
                            break;

                        case "CLICK":
                            p.click_action += items[1];
                            break;

                        case "DATA":
                            items = items[1].Split('=');
                            p.data.Add(items[0], items[1]);
                            break;

                        case "BREAK-BLOCK":
                            items = items[1].Split(';');
                            for (int x = 0; x < items.Length; x++)
                            {
                                if (items[x] != "")
                                {
                                    string[] mitems = items[x].Split('=');

                                    int key   = BlockData.block_enum[mitems[0]];
                                    int value = Int32.Parse(mitems[1]);
                                    if (p.break_block.ContainsKey(key))
                                    {
                                        p.break_block[key] = Math.Min(p.break_block[key], value);
                                    }
                                    else
                                    {
                                        p.break_block.Add(key, value);
                                    }
                                }
                            }
                            if (items.Length > 0)
                            {
                                p.break_block.Add(BlockData.block_enum["SINGLE"], 0);
                            }
                            break;

                        case "MATERIAL":
                            items = items[1].Split(';');
                            for (int x = 0; x < items.Length; x++)
                            {
                                if (items[x] != "")
                                {
                                    string[] mitems = items[x].Split('=');

                                    string key   = mitems[0];
                                    int    value = Int32.Parse(mitems[1]);
                                    if (p.materials.ContainsKey(key))
                                    {
                                        p.materials[key] = Math.Min(p.materials[key], value);
                                    }
                                    else
                                    {
                                        p.materials.Add(key, value);
                                    }
                                }
                            }
                            break;

                        case "CRAFT-REQUIRE":
                            if (items[1].Trim().ToLower() != "none")
                            {
                                p.craft_require = items[1].Trim().ToLower();
                            }
                            break;

                        case "COMPLEXITY":
                            p.complexity = int.Parse(items[1]);
                            break;

                        case "WORTH":
                            p.worth = int.Parse(items[1]);
                            break;

                        default:
                            Exilania.text_stream.WriteLine("UNHANDLED type " + items[0]);
                            break;
                        }
                    }
                    if (r.EndOfStream)
                    {
                        item_pieces.Add(p);
                        Exilania.text_stream.WriteLine("Item Piece '" + p.name + "' Loaded.");
                        cont = false;
                    }
                }
                r.Close();
            }
            else
            {
                Exilania.text_stream.Write("ERROR! NO ITEM PIECES DEFINING items....");
            }
        }