Ejemplo n.º 1
0
        public void unserializeBorder(XElement border_node)
        {
            uint id = border_node.Attribute("id").GetUInt32();

            if (borders[id] != null)
            {
                return;
            }

            AutoBorder border = new AutoBorder();

            border.Id = id;
            border.Load(border_node);
            borders[id] = border;
            if (id > maxBorderId)
            {
                maxBorderId = id;
            }
        }
Ejemplo n.º 2
0
        public override void load(XElement node)
        {
            UInt16 intVal = 0;
            String strVal = "";

            look_id = node.Attribute("lookid").GetUInt16();
            if (node.Attribute("server_lookid").GetUInt16() != 0)
            {
                look_id = node.Attribute("server_lookid").GetUInt16();
            }
            z_order           = node.Attribute("z-order").GetUInt16();
            use_only_optional = Generic.isTrueString(node.Attribute("solo_optional").GetString());
            randomize         = Generic.isTrueString(node.Attribute("randomize").GetString());
            foreach (var item_node in node.Elements("item"))
            {
                UInt16   itemid = item_node.Attribute("id").GetUInt16();
                int      chance = item_node.Attribute("chance").GetInt32();
                ItemType it     = Global.items.items[itemid];
                if (it == null)
                {
                    throw new Exception("Invalid item id brushId: " + this.id);
                }
                if (!it.isGroundTile())
                {
                    throw new Exception("is not ground item: " + itemid + " this is a " + it.Group.ToString());
                }

                if (it.brush != null && !it.brush.Equals(this))
                {
                    throw new Exception("can not be member of two brushes id:" + itemid);
                }
                it.brush = this;
                ItemChanceBlock ci;
                ci.id     = itemid;
                ci.chance = total_chance + chance;
                border_items.Add(ci);
                total_chance += chance;
            }
            foreach (var optional_node in node.Elements("optional"))
            {
                if (optional_border != null)
                {
                    throw new Exception("Duplicate optional borders");
                    // continue;
                }
                intVal = optional_node.Attribute("ground_equivalent").GetUInt16();
                if (intVal != 0)
                {
                    ItemType it = Global.items.items[intVal];
                    if (it == null)
                    {
                        throw new Exception("Invalid id of ground dependency equivalent item");
                    }
                    if (!it.isGroundTile())
                    {
                        throw new Exception("Ground dependency equivalent is not a ground item");
                    }

                    if (!this.Equals(it.brush))
                    {
                        throw new Exception("Ground dependency equivalent does not use the same brush as ground border");
                    }

                    AutoBorder ab = new AutoBorder();
                    ab.Load(optional_node, this, intVal);
                    optional_border = ab;
                }
                else
                {
                    Int32 id = optional_node.Attribute("id").GetInt32();
                    if (id == 0)
                    {
                        throw new Exception("Missing tag id for border node");
                        //continue;
                    }
                    AutoBorder border_secound = null;

                    for (int x = 0; x <= Brushes.getInstance().maxBorderId; x++)
                    {
                        AutoBorder border = Brushes.getInstance().borders[x];
                        if ((border != null) &&
                            (border.Id == id))
                        {
                            border_secound = border;
                        }
                    }
                    if (border_secound == null)
                    {
                        throw new Exception("Could not find border id. Brush: " + name);
                    }
                    optional_border = border_secound;
                }
            }
            foreach (var border_node in node.Elements("border"))
            {
                AutoBorder ab;
                int        id = border_node.Attribute("id").GetInt32();
                if (id == 0)
                {
                    intVal = border_node.Attribute("ground_equivalent").GetUInt16();
                    ItemType it = Global.items.items[intVal];
                    if (it == null)
                    {
                        throw new Exception("Invalid id of ground dependency equivalent item");
                    }

                    if (!it.isGroundTile())
                    {
                        throw new Exception("Ground dependency equivalent is not a ground item");
                    }

                    if (!this.Equals(it.brush))
                    {
                        throw new Exception("Ground dependency equivalent does not use the same brush as ground border");
                    }
                    ab = new AutoBorder();
                    ab.Load(border_node, this, intVal);
                }
                else
                {
                    AutoBorder border_secound = null;

                    for (int x = 0; x <= Brushes.getInstance().maxBorderId; x++)
                    {
                        AutoBorder border = Brushes.getInstance().borders[x];
                        if ((border != null) &&
                            (border.Id == id))
                        {
                            border_secound = border;
                        }
                    }
                    if (border_secound == null)
                    {
                        throw new Exception("Could not find border id. Brush:" + name);
                    }
                    ab = border_secound;
                }
                BorderBlock bb = new BorderBlock();
                bb.super      = false;
                bb.autoborder = ab;

                strVal = border_node.Attribute("to").GetString();
                if (!"".Equals(strVal))
                {
                    if ("all".Equals(strVal))
                    {
                        bb.to = 0xFFFFFFFF;
                    }
                    else if ("none".Equals(strVal))
                    {
                        bb.to = 0;
                    }
                    else
                    {
                        Brush toBrush = Brushes.getInstance().getBrush(strVal);
                        if (toBrush != null)
                        {
                            bb.to = toBrush.getID();
                        }
                        else
                        {
                            throw new Exception("To brush " + strVal + " doesn't exist.");
                        }
                    }
                }
                else
                {
                    bb.to = 0xFFFFFFFF;
                }
                strVal = border_node.Attribute("super").GetString();
                if (!"".Equals(strVal))
                {
                    if (Generic.isTrueString(strVal))
                    {
                        bb.super = true;
                    }
                }
                strVal = border_node.Attribute("align").GetString();
                if (!"".Equals(strVal))
                {
                    if ("outer".Equals(strVal))
                    {
                        bb.outer = true;
                    }
                    else if ("inner".Equals(strVal))
                    {
                        bb.outer = false;
                    }
                    else
                    {
                        bb.outer = true;
                    }
                }

                if (bb.outer)
                {
                    if (bb.to == 0)
                    {
                        has_zilch_outer_border = true;
                    }
                    else
                    {
                        has_outer_border = true;
                    }
                }
                else
                {
                    if (bb.to == 0)
                    {
                        has_zilch_inner_border = true;
                    }
                    else
                    {
                        has_inner_border = true;
                    }
                }
                if (border_node.HasElements)
                {
                    foreach (var specific_border_node in border_node.Elements("specific"))
                    {
                        SpecificCaseBlock scb = null;

                        foreach (var conditions_specific in specific_border_node.Elements("conditions"))
                        {
                            foreach (var match_border_conditions in conditions_specific.Elements("match_border"))
                            {
                                int    border_id = 0;
                                string edge      = "";
                                border_id = match_border_conditions.Attribute("id").GetInt32();
                                edge      = match_border_conditions.Attribute("edge").GetString();
                                if ((border_id == 0) || "".Equals(edge))
                                {
                                    continue;
                                }
                                int        edge_id    = AutoBorder.EdgeNameToEdge(edge);
                                AutoBorder bit_border = Brushes.getInstance().findBorder(edge_id);
                                if (bit_border == null)
                                {
                                    throw new Exception("Unknown border id in specific case match block");
                                }

                                AutoBorder ab2 = bit_border;
                                if (ab2 == null)
                                {
                                    throw new Exception("error ab2 ==null");
                                }
                                UInt16 match_itemid = ab.tiles[edge_id];
                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.items_to_match.Add(match_itemid);
                            }

                            foreach (var match_group_conditions in conditions_specific.Elements("match_group"))
                            {
                                uint   group = 0;
                                String edge  = "";
                                group = match_group_conditions.Attribute("group").GetUInt32();
                                edge  = match_group_conditions.Attribute("edge").GetString();
                                if ((group == 0) || "".Equals(edge))
                                {
                                    continue;
                                }

                                int edge_id = AutoBorder.EdgeNameToEdge(edge);
                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.match_group           = group;
                                scb.group_match_alignment = edge_id;
                                scb.items_to_match.Add((UInt16)group);
                            }
                            foreach (var match_item_conditions in conditions_specific.Elements("match_item"))
                            {
                                ushort match_itemid = 0;
                                match_itemid = match_item_conditions.Attribute("id").GetUInt16();
                                if (match_itemid == 0)
                                {
                                    continue;
                                }
                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.match_group = 0;
                                scb.items_to_match.Add(match_itemid);
                            }
                        }

                        // aqui conditions_specific
                        foreach (var actions_specific in specific_border_node.Elements("actions"))
                        {
                            foreach (var actions_replace_border in actions_specific.Elements("replace_border"))
                            {
                                int    border_id = 0;
                                String edge      = "";
                                ushort with_id   = 0;

                                border_id = actions_replace_border.Attribute("id").GetInt32();
                                edge      = actions_replace_border.Attribute("edge").GetString();
                                with_id   = actions_replace_border.Attribute("with").GetUInt16();

                                if ((border_id == 0) || ("".Equals(edge)) || (with_id == 0))
                                {
                                    continue;
                                }
                                int        edge_id    = AutoBorder.EdgeNameToEdge(edge);
                                AutoBorder bit_border = Brushes.getInstance().findBorder(border_id);
                                if (bit_border == null)
                                {
                                    throw new Exception("Unknown border id in specific case match block");
                                }

                                AutoBorder ab2 = bit_border;
                                if (ab2 == null)
                                {
                                    throw new Exception("error ab2 ==null");
                                }
                                ItemType it = Global.items.items[with_id];
                                if (it == null)
                                {
                                    throw new Exception("Unknown with_id in replace border");
                                }
                                it.IsBorder = true;

                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.to_replace_id = ab2.tiles[edge_id];
                                scb.with_id       = with_id;
                            }

                            foreach (var actions_replace_item in actions_specific.Elements("replace_item"))
                            {
                                ushort to_replace_id = actions_replace_item.Attribute("to_replace_id").GetUInt16();
                                ushort with_id       = actions_replace_item.Attribute("with").GetUInt16();;
                                if ((to_replace_id == 0) || (with_id == 0))
                                {
                                    continue;
                                }
                                ItemType it = Global.items.items[with_id];
                                if (it == null)
                                {
                                    throw new Exception("Unknown with_id in replace item");
                                }
                                it.IsBorder = true;

                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.to_replace_id = to_replace_id;
                                scb.with_id       = with_id;
                            }

                            foreach (var actions_delete_borders in actions_specific.Elements("delete_borders"))
                            {
                                if (scb == null)
                                {
                                    scb = new SpecificCaseBlock();
                                }
                                scb.delete_all = true;
                            }
                        }
                        if (scb != null)
                        {
                            bb.specific_cases.Add(scb);
                        }
                    }
                }
                borders.Add(bb);
            }
            foreach (var friend_node in node.Elements("friend"))
            {
                String friendName = friend_node.Attribute("name").GetString();
                if ("all".Equals(friendName))
                {
                    friends.Add(0xFFFFFFFF);
                }
                else
                {
                    Brush brush = Brushes.getInstance().getBrush(friendName);
                    if (brush != null)
                    {
                        friends.Add(brush.getID());
                    }
                    else
                    {
                        throw new Exception("Brush" + friendName + " is not defined.");
                    }
                }
                hateFriends = false;
            }
            foreach (var friend_node in node.Elements("enemy"))
            {
                String enemyName = friend_node.Attribute("name").GetString();
                if ("all".Equals(enemyName))
                {
                    friends.Add(0xFFFFFFFF);
                }
                else
                {
                    Brush brush = Brushes.getInstance().getBrush(enemyName);
                    if (brush != null)
                    {
                        friends.Add(brush.getID());
                    }
                    else
                    {
                        throw new Exception("Brush" + enemyName + " is not defined.");
                    }
                }
                hateFriends = true;
            }

            foreach (var friend_node in node.Elements("clear_borders"))
            {
                borders.Clear();
            }

            foreach (var friend_node in node.Elements("clear_friends"))
            {
                friends.Clear();
                hateFriends = false;
            }

            if (total_chance == 0)
            {
                randomize = false;
            }
        }
Ejemplo n.º 3
0
        public override void load(XElement node)
        {
            string strVal = "";

            look_id = node.Attribute("lookid").GetUInt16();
            if (node.Attribute("server_lookid").GetUInt16() != 0)
            {
                look_id = node.Attribute("server_lookid").GetUInt16();
            }

            foreach (XElement child_node in node.Elements())
            {
                if ("carpet".Equals(child_node.Name.LocalName))
                {
                    int alignment;
                    strVal = child_node.Attribute("align").GetString();
                    if (!"".Equals(strVal))
                    {
                        alignment = AutoBorder.EdgeNameToEdge(strVal);
                        if (alignment == BorderType.BORDER_NONE)
                        {
                            if ("center".Equals(strVal))
                            {
                                alignment = BorderType.CARPET_CENTER;
                            }
                            else
                            {
                                Messages.AddWarning("Invalid alignment of carpet node");
                                continue;
                            }
                        }
                    }
                    else
                    {
                        Messages.AddWarning("Could not read alignment tag of carpet node");
                        continue;
                    }
                    bool use_local_id = true;

                    foreach (XElement subchild_node in child_node.Elements())
                    {
                        if ("item".Equals(subchild_node.Name.LocalName))
                        {
                            use_local_id = false;

                            int id     = subchild_node.Attribute("id").GetInt32();
                            int chance = subchild_node.Attribute("chance").GetInt32();

                            if (id == 0)
                            {
                                Messages.AddWarning("Could not read id tag of item node");
                                continue;
                            }

                            if (chance == 0)
                            {
                                Messages.AddWarning("Could not read chance tag of item node");
                                continue;
                            }
                            ItemType it = Global.items.items[id];
                            if (it == null)
                            {
                                Messages.AddWarning("There is no itemtype with id " + id);
                                continue;
                            }

                            if ((it.brush != null) && (it.brush != this))
                            {
                                Messages.AddWarning("itemId " + id + "already has a brush");
                                continue;
                            }
                            it.IsCarpet = true;
                            it.brush    = this;

                            carpet_items[alignment].total_chance += chance;
                            CarpetType t = new CarpetType();
                            t.chance = chance;
                            t.id     = (ushort)id;
                            carpet_items[alignment].items.Add(t);
                        }
                    }

                    if (use_local_id)
                    {
                        int id = child_node.Attribute("id").GetInt32();
                        if (id == 0)
                        {
                            Messages.AddWarning("Could not read id tag of item node");
                            continue;
                        }
                        ItemType it = Global.items.items[id];
                        if (it == null)
                        {
                            Messages.AddWarning("There is no itemtype with id " + id);
                            continue;
                        }
                        if ((it.brush != null) && (it.brush != this))
                        {
                            Messages.AddWarning("itemId " + id + "already has a brush");
                            continue;
                        }
                        it.IsCarpet = true;
                        it.brush    = this;

                        carpet_items[alignment].total_chance += 1;
                        CarpetType t = new CarpetType();
                        t.chance = 1;
                        t.id     = (ushort)id;
                        carpet_items[alignment].items.Add(t);
                    }
                }
            }
        }