Example #1
0
        private void CacheTextures()
        {
            if (mTexturesFound == false && GameContentManager.Current.TilesetsLoaded)
            {
                for (var i = 0; i < Options.LayerCount; i++)
                {
                    for (var x = 0; x < Options.MapWidth; x++)
                    {
                        for (var y = 0; y < Options.MapHeight; y++)
                        {
                            var tileset = TilesetBase.Get(Layers[i].Tiles[x, y].TilesetId);
                            if (tileset != null)
                            {
                                var tilesetTex = Globals.ContentManager.GetTexture(
                                    GameContentManager.TextureType.Tileset, tileset.Name
                                    );

                                Layers[i].Tiles[x, y].TilesetTex = tilesetTex;
                            }
                        }
                    }
                }

                mTexturesFound = true;
            }
        }
        //GameObjectPacket
        private static void HandlePacket(GameObjectPacket packet)
        {
            var type    = packet.Type;
            var id      = packet.Id;
            var another = packet.AnotherFollowing;
            var deleted = packet.Deleted;
            var json    = "";

            if (!deleted)
            {
                json = packet.Data;
            }

            switch (type)
            {
            case GameObjectType.Map:
                //Handled in a different packet
                break;

            case GameObjectType.Tileset:
                var obj = new TilesetBase(id);
                obj.Load(json);
                TilesetBase.Lookup.Set(id, obj);
                if (Globals.HasGameData && !another)
                {
                    Globals.ContentManager.LoadTilesets(TilesetBase.GetNameList());
                }

                break;

            case GameObjectType.Event:
                //Clients don't store event data, im an idiot.
                break;

            default:
                var lookup = type.GetLookup();
                if (deleted)
                {
                    lookup.Get(id).Delete();
                }
                else
                {
                    lookup.DeleteAt(id);
                    var item = lookup.AddNew(type.GetObjectType(), id);
                    item.Load(json);
                }

                break;
            }
        }
Example #3
0
        private static void ProcessLoading()
        {
            if (Globals.Me == null || Globals.Me.MapInstance == null)
            {
                return;
            }

            if (!_loadedTilesets && Globals.HasGameData)
            {
                Globals.ContentManager.LoadTilesets(TilesetBase.GetNameList());
                _loadedTilesets = true;
            }

            Audio.PlayMusic(MapInstance.Get(Globals.Me.CurrentMap).Music, 3, 3, true);
            Globals.GameState = GameStates.InGame;
            Fade.FadeIn();
        }
Example #4
0
        public void SetTileset(string name)
        {
            TilesetBase tSet     = null;
            var         tilesets = TilesetBase.Lookup;
            var         id       = Guid.Empty;

            foreach (var tileset in tilesets.Pairs)
            {
                if (tileset.Value.Name.ToLower() == name.ToLower())
                {
                    id = tileset.Key;

                    break;
                }
            }

            if (id != Guid.Empty)
            {
                tSet = TilesetBase.Get(id);
            }

            if (tSet != null)
            {
                if (File.Exists("resources/tilesets/" + tSet.Name))
                {
                    picTileset.Show();
                    Globals.CurrentTileset = tSet;
                    Globals.CurSelX        = 0;
                    Globals.CurSelY        = 0;
                    var tilesetTex = GameContentManager.GetTexture(GameContentManager.TextureType.Tileset, tSet.Name);
                    if (tilesetTex != null)
                    {
                        picTileset.Width  = tilesetTex.Width;
                        picTileset.Height = tilesetTex.Height;
                    }

                    cmbTilesets.SelectedItem = name;
                    CreateSwapChain();
                }
            }
        }
        public static void LoadTilesets()
        {
            if (!Directory.Exists("resources/tilesets"))
            {
                Directory.CreateDirectory("resources/tilesets");
            }

            var tilesets               = Directory.GetFiles("resources/tilesets", "*.png");
            var tilesetWarning         = false;
            var suppressTilesetWarning = Preferences.LoadPreference("SuppressTextureWarning");

            if (suppressTilesetWarning != "" && Convert.ToBoolean(suppressTilesetWarning))
            {
                tilesetWarning = true;
            }

            var newTilesets = new List <string>();

            Array.Sort(tilesets, new AlphanumComparatorFast());
            if (tilesets.Length > 0)
            {
                var tilesetBaseList = TilesetBase.Names;
                for (var i = 0; i < tilesets.Length; i++)
                {
                    tilesets[i] = tilesets[i].Replace("resources/tilesets\\", "");
                    if (tilesetBaseList.Length > 0)
                    {
                        for (var x = 0; x < tilesetBaseList.Length; x++)
                        {
                            if (tilesetBaseList[x].ToLower() == tilesets[i].ToLower())
                            {
                                break;
                            }

                            if (x != tilesetBaseList.Length - 1)
                            {
                                continue;
                            }

                            newTilesets.Add(tilesets[i]);
                        }
                    }
                    else
                    {
                        newTilesets.Add(tilesets[i]);
                    }
                }
            }

            sTilesetDict.Clear();
            TilesetTextures.Clear();
            var badTilesets = new List <string>();

            for (var i = 0; i < TilesetBase.Lookup.Count; i++)
            {
                var tileset = TilesetBase.Get(TilesetBase.IdFromList(i));
                if (File.Exists("resources/tilesets/" + tileset.Name))
                {
                    try
                    {
                        sTilesetDict[tileset.Name.ToLower()] = new Texture("resources/tilesets/" + tileset.Name);
                        TilesetTextures.Add(sTilesetDict[tileset.Name.ToLower()]);
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"Fake methods! ({tileset.Name})");
                        if (exception.InnerException != null)
                        {
                            Log.Error(exception.InnerException);
                        }

                        Log.Error(exception);

                        throw;
                    }

                    if (!tilesetWarning)
                    {
                        using (var img = Image.FromFile("resources/tilesets/" + tileset.Name))
                        {
                            if (img.Width > 2048 || img.Height > 2048)
                            {
                                badTilesets.Add(tileset.Name);
                            }
                        }
                    }
                }
            }

            if (badTilesets.Count > 0)
            {
                MessageBox.Show(
                    "One or more tilesets is too large and likely won't load for your players on older machines! We recommmend that no graphic is larger than 2048 pixels in width or height.\n\nFaulting tileset(s): " +
                    string.Join(",", badTilesets.ToArray()), "Large Tileset Warning!", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation
                    );
            }

            if (newTilesets.Count > 0)
            {
                PacketSender.SendNewTilesets(newTilesets.ToArray());
            }
        }
Example #6
0
        //GameObjectPacket
        private static void HandlePacket(GameObjectPacket packet)
        {
            var id      = packet.Id;
            var deleted = packet.Deleted;
            var json    = "";

            if (!packet.Deleted)
            {
                json = packet.Data;
            }

            switch (packet.Type)
            {
            case GameObjectType.Animation:
                if (deleted)
                {
                    var anim = AnimationBase.Get(id);
                    anim.Delete();
                }
                else
                {
                    var anim = new AnimationBase(id);
                    anim.Load(json);
                    try
                    {
                        AnimationBase.Lookup.Set(id, anim);
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"Another mystery NPE. [Lookup={AnimationBase.Lookup}]");
                        if (exception.InnerException != null)
                        {
                            Log.Error(exception.InnerException);
                        }

                        Log.Error(exception);
                        Log.Error($"{nameof(id)}={id},{nameof(anim)}={anim}");

                        throw;
                    }
                }

                break;

            case GameObjectType.Class:
                if (deleted)
                {
                    var cls = ClassBase.Get(id);
                    cls.Delete();
                }
                else
                {
                    var cls = new ClassBase(id);
                    cls.Load(json);
                    ClassBase.Lookup.Set(id, cls);
                }

                break;

            case GameObjectType.Item:
                if (deleted)
                {
                    var itm = ItemBase.Get(id);
                    itm.Delete();
                }
                else
                {
                    var itm = new ItemBase(id);
                    itm.Load(json);
                    ItemBase.Lookup.Set(id, itm);
                }

                break;

            case GameObjectType.Npc:
                if (deleted)
                {
                    var npc = NpcBase.Get(id);
                    npc.Delete();
                }
                else
                {
                    var npc = new NpcBase(id);
                    npc.Load(json);
                    NpcBase.Lookup.Set(id, npc);
                }

                break;

            case GameObjectType.Projectile:
                if (deleted)
                {
                    var proj = ProjectileBase.Get(id);
                    proj.Delete();
                }
                else
                {
                    var proj = new ProjectileBase(id);
                    proj.Load(json);
                    ProjectileBase.Lookup.Set(id, proj);
                }

                break;

            case GameObjectType.Quest:
                if (deleted)
                {
                    var qst = QuestBase.Get(id);
                    qst.Delete();
                }
                else
                {
                    var qst = new QuestBase(id);
                    qst.Load(json);
                    foreach (var tsk in qst.Tasks)
                    {
                        qst.OriginalTaskEventIds.Add(tsk.Id, tsk.CompletionEventId);
                    }

                    QuestBase.Lookup.Set(id, qst);
                }

                break;

            case GameObjectType.Resource:
                if (deleted)
                {
                    var res = ResourceBase.Get(id);
                    res.Delete();
                }
                else
                {
                    var res = new ResourceBase(id);
                    res.Load(json);
                    ResourceBase.Lookup.Set(id, res);
                }

                break;

            case GameObjectType.Shop:
                if (deleted)
                {
                    var shp = ShopBase.Get(id);
                    shp.Delete();
                }
                else
                {
                    var shp = new ShopBase(id);
                    shp.Load(json);
                    ShopBase.Lookup.Set(id, shp);
                }

                break;

            case GameObjectType.Spell:
                if (deleted)
                {
                    var spl = SpellBase.Get(id);
                    spl.Delete();
                }
                else
                {
                    var spl = new SpellBase(id);
                    spl.Load(json);
                    SpellBase.Lookup.Set(id, spl);
                }

                break;

            case GameObjectType.CraftTables:
                if (deleted)
                {
                    var cft = CraftingTableBase.Get(id);
                    cft.Delete();
                }
                else
                {
                    var cft = new CraftingTableBase(id);
                    cft.Load(json);
                    CraftingTableBase.Lookup.Set(id, cft);
                }

                break;

            case GameObjectType.Crafts:
                if (deleted)
                {
                    var cft = CraftBase.Get(id);
                    cft.Delete();
                }
                else
                {
                    var cft = new CraftBase(id);
                    cft.Load(json);
                    CraftBase.Lookup.Set(id, cft);
                }

                break;

            case GameObjectType.Map:
                //Handled in a different packet
                break;

            case GameObjectType.Event:
                var wasCommon = false;
                if (deleted)
                {
                    var evt = EventBase.Get(id);
                    wasCommon = evt.CommonEvent;
                    evt.Delete();
                }
                else
                {
                    var evt = new EventBase(id);
                    evt.Load(json);
                    wasCommon = evt.CommonEvent;
                    EventBase.Lookup.Set(id, evt);
                }

                if (!wasCommon)
                {
                    return;
                }

                break;

            case GameObjectType.PlayerVariable:
                if (deleted)
                {
                    var pvar = PlayerVariableBase.Get(id);
                    pvar.Delete();
                }
                else
                {
                    var pvar = new PlayerVariableBase(id);
                    pvar.Load(json);
                    PlayerVariableBase.Lookup.Set(id, pvar);
                }

                break;

            case GameObjectType.ServerVariable:
                if (deleted)
                {
                    var svar = ServerVariableBase.Get(id);
                    svar.Delete();
                }
                else
                {
                    var svar = new ServerVariableBase(id);
                    svar.Load(json);
                    ServerVariableBase.Lookup.Set(id, svar);
                }

                break;

            case GameObjectType.Tileset:
                var obj = new TilesetBase(id);
                obj.Load(json);
                TilesetBase.Lookup.Set(id, obj);
                if (Globals.HasGameData && !packet.AnotherFollowing)
                {
                    GameContentManager.LoadTilesets();
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GameObjectUpdatedDelegate?.Invoke(packet.Type);
        }