Пример #1
0
        public void createOtherTileset()
        {
            TileSet others      = null;
            TileSet npc_tileset = null;

            if (tilesets.ContainsKey("Others"))
            {
                others = tilesets["Others"];
            }
            else
            {
                others             = new TileSet(Brushes.getInstance(), "Others");
                tilesets["Others"] = others;
            }

            if (tilesets.ContainsKey("NPCs"))
            {
                npc_tileset = tilesets["NPCs"];
                npc_tileset.clear();
            }
            else
            {
                npc_tileset      = new TileSet(Brushes.getInstance(), "NPCs");
                tilesets["NPCs"] = npc_tileset;
            }

            foreach (CreatureType type in CreatureDatabase.creatureDatabase)
            {
                if (type.in_other_tileset)
                {
                    if (type.isNpc)
                    {
                        npc_tileset.getCategory(TilesetCategoryType.TILESET_CREATURE).brushlist.Add(type.brush);
                    }
                    else
                    {
                        others.getCategory(TilesetCategoryType.TILESET_CREATURE).brushlist.Add(type.brush);
                    }
                }
                else if (type.brush == null)
                {
                    type.brush = new CreatureBrush(type);
                    Brushes.getInstance().addBrush(type.brush);
                    type.brush.flagAsVisible();
                    type.in_other_tileset = true;
                    if (type.isNpc)
                    {
                        npc_tileset.getCategory(TilesetCategoryType.TILESET_CREATURE).brushlist.Add(type.brush);
                    }
                    else
                    {
                        others.getCategory(TilesetCategoryType.TILESET_CREATURE).brushlist.Add(type.brush);
                    }
                }
            }
        }
Пример #2
0
        private void unserializeTileset(XElement tileset_node)
        {
            String tileSetName = tileset_node.Attribute("name").GetString();

            if (!"".Equals(tileSetName))
            {
                TileSet ts = getTileSet(tileSetName);
                if (ts == null)
                {
                    ts = new TileSet(Brushes.getInstance(), tileSetName);
                    tilesets.Add(tileSetName, ts);
                }

                foreach (XElement element_tileset_node in tileset_node.Elements())
                {
                    ts.LoadCategory(element_tileset_node);
                }
            }
            //
        }
Пример #3
0
        public override void load(XElement brush)
        {
            look_id = brush.Attribute("lookid").GetUInt16();
            if (brush.Attribute("server_lookid").GetUInt16() != 0)
            {
                look_id = brush.Attribute("server_lookid").GetUInt16();
            }

            foreach (XElement wall_brush in brush.Elements("wall"))
            {
                int    alignment = 0;
                String type      = wall_brush.Attribute("type").GetString();
                if (!"".Equals(type))
                {
                    if (type == "vertical")
                    {
                        alignment = BorderType.WALL_VERTICAL;
                    }
                    else if (type == "horizontal")
                    {
                        alignment = BorderType.WALL_HORIZONTAL;
                    }
                    else if (type == "corner")
                    {
                        alignment = BorderType.WALL_NORTHWEST_DIAGONAL;
                    }
                    else if (type == "pole")
                    {
                        alignment = BorderType.WALL_POLE;
                    }
                    else if (type == "south end")
                    {
                        alignment = BorderType.WALL_SOUTH_END;
                    }
                    else if (type == "east end")
                    {
                        alignment = BorderType.WALL_EAST_END;
                    }
                    else if (type == "north end")
                    {
                        alignment = BorderType.WALL_NORTH_END;
                    }
                    else if (type == "west end")
                    {
                        alignment = BorderType.WALL_WEST_END;
                    }
                    else if (type == "south T")
                    {
                        alignment = BorderType.WALL_SOUTH_T;
                    }
                    else if (type == "east T")
                    {
                        alignment = BorderType.WALL_EAST_T;
                    }
                    else if (type == "west T")
                    {
                        alignment = BorderType.WALL_WEST_T;
                    }
                    else if (type == "north T")
                    {
                        alignment = BorderType.WALL_NORTH_T;
                    }
                    else if (type == "northwest diagonal")
                    {
                        alignment = BorderType.WALL_NORTHWEST_DIAGONAL;
                    }
                    else if (type == "northeast diagonal")
                    {
                        alignment = BorderType.WALL_NORTHEAST_DIAGONAL;
                    }
                    else if (type == "southwest diagonal")
                    {
                        alignment = BorderType.WALL_SOUTHWEST_DIAGONAL;
                    }
                    else if (type == "southeast diagonal")
                    {
                        alignment = BorderType.WALL_SOUTHEAST_DIAGONAL;
                    }
                    else if (type == "intersection")
                    {
                        alignment = BorderType.WALL_INTERSECTION;
                    }
                    else if (type == "untouchable")
                    {
                        alignment = BorderType.WALL_UNTOUCHABLE;
                    }
                    else
                    {
                        Messages.AddWarning("Unknown wall alignment '" + type + "'");
                        continue;
                    }
                }
                else
                {
                    Messages.AddWarning("Could not read type tag of wall node");
                    continue;
                }
                foreach (XElement item_wall_brush in wall_brush.Elements("item"))
                {
                    int id     = 0;
                    int chance = 0;

                    id = item_wall_brush.Attribute("id").GetInt32();

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

                    chance = item_wall_brush.Attribute("chance").GetInt32();
                    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("Itemtype id " + id + " already has a brush");
                        continue;
                    }
                    it.IsWall          = true;
                    it.brush           = this;
                    it.BorderAlignment = alignment;

                    WallType wt = new WallType();
                    //issi é la do tipo
                    wall_items[alignment].total_chance += chance;
                    wt.chance = wall_items[alignment].total_chance;
                    wt.id     = (UInt16)id;
                    wall_items[alignment].items.Add(wt);
                }
                foreach (XElement door_wall_brush in wall_brush.Elements("door"))
                {
                    String type_door = "";
                    int    chance    = 0;
                    bool   isOpen;
                    bool   hate = false;
                    int    id   = door_wall_brush.Attribute("id").GetInt32();
                    if (id == 0)
                    {
                        Messages.AddWarning("Could not read id tag of item node");
                        break;
                    }
                    chance    = door_wall_brush.Attribute("chance").GetInt32();
                    type_door = door_wall_brush.Attribute("type").GetString();
                    if (!"".Equals(type_door))
                    {
                        String strVal = door_wall_brush.Attribute("open").GetString();
                        if (!"".Equals(strVal))
                        {
                            isOpen = Generic.isTrueString(strVal);
                        }
                        else
                        {
                            isOpen = true;
                            if ((!type_door.Equals("window")) && (!type_door.Equals("any window")) && (!type_door.Equals("hatch window")))
                            {
                                Messages.AddWarning("Could not read open tag of item node");
                                break;
                            }
                        }
                    }
                    else
                    {
                        Messages.AddWarning("Could not read type tag of item node");
                        break;
                    }

                    if (!"".Equals(door_wall_brush.Attribute("type").GetString()))
                    {
                        hate = Generic.isTrueString(door_wall_brush.Attribute("type").GetString());
                    }

                    ItemType it = Global.items.items[id];
                    if (it == null)
                    {
                        Messages.AddWarning("There is no itemtype with id " + id);
                        continue;
                    }
                    it.IsWall          = true;
                    it.brush           = this;
                    it.IsBrushDoor     = true;
                    it.WallHateMe      = hate;
                    it.IsOpen          = isOpen;
                    it.BorderAlignment = alignment;

                    DoorType dt          = new DoorType();
                    bool     all_windows = false;
                    bool     all_doors   = false;
                    if (type_door == "normal")
                    {
                        dt.type = EDoorType.WALL_DOOR_NORMAL;
                    }
                    else if (type_door == "locked")
                    {
                        dt.type = EDoorType.WALL_DOOR_LOCKED;
                    }
                    else if (type_door == "quest")
                    {
                        dt.type = EDoorType.WALL_DOOR_QUEST;
                    }
                    else if (type_door == "magic")
                    {
                        dt.type = EDoorType.WALL_DOOR_MAGIC;
                    }
                    else if (type_door == "archway")
                    {
                        dt.type = EDoorType.WALL_ARCHWAY;
                    }
                    else if (type_door == "window")
                    {
                        dt.type = EDoorType.WALL_WINDOW;
                    }
                    else if (type_door == "hatch_window" || type_door == "hatch window")
                    {
                        dt.type = EDoorType.WALL_HATCH_WINDOW;
                    }
                    else if (type_door == "any door")
                    {
                        all_doors = true;
                    }
                    else if (type_door == "any window")
                    {
                        all_windows = true;
                    }
                    else if (type_door == "any")
                    {
                        all_windows = true;
                        all_doors   = true;
                    }
                    else
                    {
                        Messages.AddWarning("Unknown door type '" + type_door + "'");
                        break;
                    }
                    dt.id = (UInt16)id;
                    if (all_windows)
                    {
                        dt.type = EDoorType.WALL_WINDOW; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_HATCH_WINDOW; door_items[alignment].Add(dt);
                    }

                    if (all_doors)
                    {
                        dt.type = EDoorType.WALL_ARCHWAY; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_NORMAL; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_LOCKED; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_QUEST; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_MAGIC; door_items[alignment].Add(dt);
                    }
                    if (!all_doors && !all_windows)
                    {
                        door_items[alignment].Add(dt);
                    }
                }
            }
            foreach (XElement efriend_brush in brush.Elements("friend"))
            {
                String friendName = efriend_brush.Attribute("name").GetString();
                if (friendName != "")
                {
                    if ("all".Equals(friendName))
                    {
                        //nada
                    }
                    else
                    {
                        Brush friend_brush = Brushes.getInstance().getBrush(friendName);
                        if (friend_brush != null)
                        {
                            friends.Add(friend_brush.getID());
                        }
                        else
                        {
                            Messages.AddWarning("Brush '" + friendName + "' is not defined.");
                        }
                        String redirect = efriend_brush.Attribute("redirect").GetString();
                        if ((!"".Equals(redirect)) && Generic.isTrueString(redirect))
                        {
                            WallBrush rd = null;
                            try
                            {
                                rd = (WallBrush)friend_brush;
                            }
                            catch// (Exception ex)
                            {
                                Messages.AddWarning("Wall brush redirect link: '" + redirect + "' is not a wall brush.");
                            }
                            if (redirect_to == null)
                            {
                                redirect_to = rd;
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
 public TileSet(Brushes brushes, String name)
 {
     this.name       = name;
     this.brushes    = brushes;
     this.categories = new List <TilesetCategory>();
 }
Пример #5
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;
            }
        }