コード例 #1
0
ファイル: Server.cs プロジェクト: Logof/UnityAllods
    public static void NotifySack(int x, int y, long price)
    {
        MapSack sack = MapLogic.Instance.GetSackAt(x, y);

        if (sack == null)
        {
            NotifyNoSack(x, y);
            return;
        }

        foreach (ServerClient client in ServerManager.Clients)
        {
            if (client.State != ClientState.Playing)
            {
                continue;
            }

            Player p = MapLogic.Instance.GetNetPlayer(client);
            if (sack.IsVisibleForNetPlayer(p))
            {
                ClientCommands.SackAt sckCmd;
                sckCmd.X     = x;
                sckCmd.Y     = y;
                sckCmd.Price = price;
                client.SendCommand(sckCmd);
            }
        }
    }
コード例 #2
0
ファイル: UnitStates.cs プロジェクト: Logof/UnityAllods
    public bool Process()
    {
        if (Unit.Stats.Health <= 0)
        {
            return(false);
        }

        // check if sack still exists
        MapSack targetsack = MapLogic.Instance.GetSackAt(TargetX, TargetY);

        if (targetsack == null)
        {
            return(false);
        }

        // if unit is on target cell, just pick up
        if (Unit.X <= TargetX && Unit.Y <= TargetY &&
            Unit.X + Unit.Width > TargetX && Unit.Y + Unit.Height > TargetY)
        {
            // pick the target sack up.
            // add money
            for (int i = 0; i < targetsack.Pack.Count; i++)
            {
                Item newItem = Unit.ItemsPack.PutItem(Unit.ItemsPack.Count, new Item(targetsack.Pack[i], targetsack.Pack[i].Count));
                // display "you have picked up ..."
                Server.NotifyItemPickup(Unit, targetsack.Pack[i].Class.ItemID, newItem.Count);
            }

            if (targetsack.Pack.Money > 0)
            {
                Unit.ItemsPack.Money += targetsack.Pack.Money;
                Server.NotifyItemPickup(Unit, -1, targetsack.Pack.Money);
            }

            MapLogic.Instance.RemoveSackAt(TargetX, TargetY);

            if (NetworkManager.IsServer)
            {
                Server.NotifyUnitPack(Unit);
            }

            return(false); // done
        }
        else
        {
            MoveState.TryWalkTo(Unit, TargetX, TargetY);
            return(true);
        }
    }
コード例 #3
0
    // sack related
    public MapSack GetSackByTag(int tag)
    {
        foreach (MapObject mobj in Objects)
        {
            if (mobj.GetObjectType() != MapObjectType.Sack)
            {
                continue;
            }
            MapSack sack = (MapSack)mobj;
            if (sack.Tag == tag)
            {
                return(sack);
            }
        }

        return(null);
    }
コード例 #4
0
    public MapSack PutSackAt(int x, int y, ItemPack pack, bool alwayscreate)
    {
        if (x < 0 || y < 0 || x >= Width || y >= Height)
        {
            return(null);
        }

        MapSack existingsack = null;

        if (alwayscreate)
        {
            RemoveSackAt(x, y);
        }
        else
        {
            existingsack = GetSackAt(x, y);
        }

        if (existingsack == null)
        {
            existingsack     = new MapSack(pack);
            existingsack.X   = x;
            existingsack.Y   = y;
            existingsack.Tag = TopSackTag++;
            existingsack.LinkToWorld();
            Objects.Add(existingsack);
            existingsack.UpdateNetVisibility();
        }
        else
        {
            for (int i = 0; i < pack.Count; i++)
            {
                existingsack.Pack.PutItem(existingsack.Pack.Count, new Item(pack[i], pack[i].Count));
            }
            existingsack.Pack.Money  += pack.Money;
            existingsack.DoUpdateView = true;

            if (NetworkManager.IsServer)
            {
                Server.NotifySack(x, y, existingsack.Pack.Price);
            }
        }

        return(existingsack);
    }
コード例 #5
0
    // get sack at x,y
    public MapSack GetSackAt(int x, int y)
    {
        if (x < 0 || y < 0 || x >= Width || y >= Height)
        {
            return(null);
        }

        foreach (MapObject mobj in Nodes[x, y].Objects)
        {
            if (mobj.GetObjectType() != MapObjectType.Sack)
            {
                continue;
            }
            MapSack sack = (MapSack)mobj;
            return(sack);
        }

        return(null);
    }
コード例 #6
0
    public void Update()
    {
        CurrentCommandActual &= EnabledCommands;
        CurrentCommand        = CurrentCommandActual;

        Spell.Spells viewCast = MapView.Instance.GetCastSpell();
        if (viewCast != Spell.Spells.NoneSpell)
        {
            CurrentCommand = Commands.Cast;
        }
        else if (CurrentCommandActual == Commands.Move)
        {
            // check if ctrl is pressed.
            // if alt is pressed, it's always Move overriding any other command.
            bool bAlt = (Input.GetKey(KeyCode.RightAlt) ||
                         Input.GetKey(KeyCode.LeftAlt));
            bool bCtrl = (Input.GetKey(KeyCode.RightControl) ||
                          Input.GetKey(KeyCode.LeftControl));

            if (bAlt && !bCtrl)
            {
                CurrentCommand = Commands.Move;
            }
            else if (bCtrl && !bAlt)
            {
                CurrentCommand = (MapView.Instance.HoveredObject != null &&
                                  (MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Monster ||
                                   MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Human)) ? Commands.Attack : Commands.MoveAttack;
            }
            else
            {
                // get own player
                Player ownPlayer = MapLogic.Instance.ConsolePlayer;
                Player hisPlayer = (MapView.Instance.HoveredObject != null &&
                                    (MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Monster ||
                                     MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Human)) ? ((IPlayerPawn)MapView.Instance.HoveredObject).GetPlayer() : null;
                if (ownPlayer != null && hisPlayer != null)
                {
                    if ((ownPlayer.Diplomacy[hisPlayer.ID] & DiplomacyFlags.Enemy) != 0)
                    {
                        CurrentCommand = Commands.Attack;
                    }
                }

                // check pickup
                // if selected unit == hovered unit
                // AND selected unit belongs to us
                // AND we are hovering a pack
                if (CurrentCommand == Commands.Move)
                {
                    MapSack sack = MapLogic.Instance.GetSackAt(MapView.Instance.MouseCellX, MapView.Instance.MouseCellY);
                    if (sack != null &&
                        (MapView.Instance.HoveredObject == MapView.Instance.SelectedObject || MapView.Instance.HoveredObject == null) &&
                        MapView.Instance.SelectedObject != null &&
                        MapView.Instance.SelectedObject is IPlayerPawn &&
                        ((IPlayerPawn)MapView.Instance.SelectedObject).GetPlayer() == ownPlayer)
                    {
                        CurrentCommand = Commands.Pickup;
                    }
                }
            }
        }

        // update visual button states
        for (int i = 0; i < 8; i++)
        {
            Commands icmd = (Commands)(1 << i);
            if ((EnabledCommands & icmd) != 0)
            {
                CommandBarDnObjects[i].SetActive(CurrentCommand == icmd);
                CommandBarUpObjects[i].SetActive(CurrentCommand != icmd);
            }
            else
            {
                CommandBarDnObjects[i].SetActive(false);
                CommandBarUpObjects[i].SetActive(false);
            }
        }
    }
コード例 #7
0
ファイル: Server.cs プロジェクト: Logof/UnityAllods
    public static void ObjectBecameVisible(Player player, MapObject mobj)
    {
        if (player.NetClient == null)
        {
            return;
        }

        //Debug.LogFormat("visible = {0}->{1}", player.Name, mobj.GetObjectType().ToString());
        if (mobj.GetObjectType() == MapObjectType.Monster ||
            mobj.GetObjectType() == MapObjectType.Human)
        {
            MapUnit unit = (MapUnit)mobj;
            ClientCommands.AddUnit unitCmd;
            unitCmd.Tag          = unit.Tag;
            unitCmd.X            = unit.X;
            unitCmd.Y            = unit.Y;
            unitCmd.Angle        = unit.Angle;
            unitCmd.Player       = unit.Player.ID;
            unitCmd.ServerID     = unit.ServerID;
            unitCmd.CurrentStats = unit.Stats;
            unitCmd.IsAvatar     = (unit == unit.Player.Avatar);
            unitCmd.VState       = unit.VState;
            unitCmd.IdleFrame    = unit.IdleFrame;
            unitCmd.IdleTime     = unit.IdleTime;
            unitCmd.MoveFrame    = unit.MoveFrame;
            unitCmd.MoveTime     = unit.MoveTime;
            unitCmd.FracX        = unit.FracX;
            unitCmd.FracY        = unit.FracY;
            unitCmd.AttackFrame  = unit.AttackFrame;
            unitCmd.AttackTime   = unit.AttackTime;
            unitCmd.DeathFrame   = unit.DeathFrame;
            unitCmd.DeathTime    = unit.DeathTime;
            unitCmd.IsAlive      = unit.IsAlive;
            unitCmd.IsDying      = unit.IsDying;
            unitCmd.IsHuman      = (unit.GetObjectType() == MapObjectType.Human);

            if (unitCmd.IsHuman)
            {
                MapHuman human = (MapHuman)unit;
                unitCmd.IsHero = human.IsHero;
            }
            else
            {
                unitCmd.IsHero = false;
            }

            unitCmd.ItemsBody = new List <NetItem>();
            for (int i = 0; i < unit.ItemsBody.Count; i++)
            {
                unitCmd.ItemsBody.Add(new NetItem(unit.ItemsBody[i]));
            }

            unitCmd.ItemsPack = new List <NetItem>();
            if (unit.Player == player)
            {
                for (int i = 0; i < unit.ItemsPack.Count; i++)
                {
                    unitCmd.ItemsPack.Add(new NetItem(unit.ItemsPack[i]));
                }
            }

            uint sps = 0;
            foreach (Spell cspell in unit.SpellBook)
            {
                sps |= 1u << (int)cspell.SpellID;
            }
            unitCmd.SpellBook = sps;

            player.NetClient.SendCommand(unitCmd);
            // also notify of current unit state
            NotifyAddUnitActionsSingle(player.NetClient, unit, unit.Actions.Skip(1).ToArray());
            //Debug.LogFormat("sending player {0} unit {1}", player.Name, unitCmd.Tag);
        }
        else if (mobj.GetObjectType() == MapObjectType.Sack)
        {
            MapSack sack = (MapSack)mobj;
            NotifySack(sack.X, sack.Y, sack.Pack.Price);
        }
        else if (mobj.GetObjectType() == MapObjectType.Obstacle)
        {
            MapObstacle obstacle = (MapObstacle)mobj;
            if (obstacle.IsDead)
            {
                Server.NotifyStaticObjectDead(obstacle.X, obstacle.Y);
            }
        }
    }
コード例 #8
0
    private void InitFromFileWorker(string filename)
    {
        try
        {
            PathfindingType = (PathfindingType)Config.sv_pathfinding;

            AllodsMap mapStructure = AllodsMap.LoadFrom(filename);
            if (mapStructure == null)
            {
                //Core.Abort("Couldn't load \"{0}\"", filename);
                GameConsole.Instance.WriteLine("Couldn't load \"{0}\"", filename);
                Unload();
                return;
            }

            Width  = (int)mapStructure.Data.Width;
            Height = (int)mapStructure.Data.Height;

            // load in map.reg
            // for base terrain costs here
            Registry reg = null;
            try
            {
                reg = new Registry("world/data/map.reg");
            }
            catch (Exception)
            {
                reg = new Registry();
            }

            int[] NodeCosts = new int[]
            {
                reg.GetInt("Terrain", "CostLand", 8),
                reg.GetInt("Terrain", "CostGrass", 8),
                reg.GetInt("Terrain", "CostFlowers", 9),
                reg.GetInt("Terrain", "CostSand", 14),
                reg.GetInt("Terrain", "CostCracked", 6),
                reg.GetInt("Terrain", "CostStones", 12),
                reg.GetInt("Terrain", "CostSavanna", 11),
                reg.GetInt("Terrain", "CostMountain", 16),
                reg.GetInt("Terrain", "CostWater", 8),
                reg.GetInt("Terrain", "CostRoad", 6)
            };

            int[] NodeTileTypesInCell = new int[]
            {
                2, 3, 2, 4, 3, 4, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0,
                3, 5, 3, 3, 1, 3, 2, 4, 2, 2, 4, 2, 4, 4, 0, 0,
                2, 3, 2, 4, 3, 4, 2, 4, 2, 2, 4, 2, 4, 4, 0, 0,
                5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0
            };

            int[,] NodeTileTypes = new int[16, 2]
            {
                { 2, 1 }, { 5, 1 }, { 4, 1 }, { 7, 1 }, { 6, 1 }, { 5, 6 }, { 3, 7 }, { 8, 6 },
                { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 10, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 }
            };
            // end loading terrain costs

            Nodes = new MapNode[Width, Height];
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    MapNode node = Nodes[x, y] = new MapNode();
                    node.Tile   = (ushort)(mapStructure.Tiles[y * Width + x] & 0x3FF);
                    node.Height = mapStructure.Heights[y * Width + x];
                    node.Flags  = 0;
                    node.Light  = 255;

                    int   costTileType     = (node.Tile & 0x3C0) >> 6;
                    int   costTileBorder   = (node.Tile & 0x3F);
                    float costTileFactor   = (NodeTileTypesInCell[costTileBorder] - 1) / 4f; // 1..5 -> 0..4 -> 0..1
                    int   costSubTileType1 = NodeTileTypes[costTileType, 1] - 1;
                    int   costSubTileType2 = NodeTileTypes[costTileType, 0] - 1;
                    int   costSubTile1     = (costSubTileType1 >= 0) ? NodeCosts[costSubTileType1] : 0;
                    int   costSubTile2     = (costSubTileType2 >= 0) ? NodeCosts[costSubTileType2] : 0;
                    node.BaseWalkCost = (byte)((costSubTile1 * (1f - costTileFactor)) + (costSubTile2 * costTileFactor));

                    // 7 = rock
                    // 8 = water
                    int   walkType   = costSubTileType1;
                    float walkFactor = 1f - costTileFactor;
                    if (costSubTileType2 == 7 || costSubTileType2 == 8 || costSubTileType1 == -1)
                    {
                        walkType   = costSubTileType2;
                        walkFactor = costTileFactor;
                    }

                    if (walkType < 0 || walkType == 8 || (walkType == 7 && walkFactor > 0.25f))
                    {
                        node.Flags |= MapNodeFlags.BlockedTerrain;
                    }
                }
            }

            // load players
            foreach (AllodsMap.AlmPlayer almplayer in mapStructure.Players)
            {
                Player player = new Player(almplayer);
                Players.Add(player);
                //Debug.Log(string.Format("player ID={2} {0} (flags {1})", player.Name, player.Flags, player.ID));
            }

            GameManager.Instance.CallDelegateOnNextFrame(() =>
            {
                Speed = 5;
                return(false);
            });

            _TopObjectID = 0;

            // load obstacles
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    int typeId = mapStructure.Objects[y * Width + x];
                    if (typeId <= 0)
                    {
                        continue;
                    }
                    typeId -= 1;
                    MapObstacle mob = new MapObstacle(typeId);
                    mob.X = x;
                    mob.Y = y;
                    mob.LinkToWorld();
                    AddObject(mob, false);
                }
            }

            // load structures
            if (mapStructure.Structures != null)
            {
                foreach (AllodsMap.AlmStructure almstruc in mapStructure.Structures)
                {
                    MapStructure struc;
                    struc = new MapStructure(almstruc.TypeID);
                    if (struc.Class == null)
                    {
                        Debug.LogFormat("Tried to load invalid structure {0}", almstruc.TypeID);
                        continue;
                    }

                    struc.X      = (int)almstruc.X;
                    struc.Y      = (int)almstruc.Y;
                    struc.Health = almstruc.Health;
                    struc.Tag    = almstruc.ID;
                    struc.Player = GetPlayerByID(almstruc.Player - 1);
                    if (almstruc.IsBridge)
                    {
                        struc.Width  = almstruc.Width;
                        struc.Height = almstruc.Height;
                        // also this crutch is apparently done by ROM2
                        if (struc.Width < 2)
                        {
                            struc.Width = 2;
                        }
                        if (struc.Height < 2)
                        {
                            struc.Height = 2;
                        }
                        struc.IsBridge = true;
                    }

                    // find inn/shop data if needed
                    if (struc.Class != null && struc.Class.Usable)
                    {
                        if ((struc.Class.ID >= 105 && struc.Class.ID <= 107) || // druid shop
                            (struc.Class.ID >= 34 && struc.Class.ID <= 35) ||   // plagat shop
                            (struc.Class.ID >= 93 && struc.Class.ID <= 95))     // kaarg shop
                        {
                            foreach (AllodsMap.AlmShop shop in mapStructure.Shops)
                            {
                                if (shop.ID == struc.Tag)
                                {
                                    struc.Logic = new ShopStructure(struc, shop);
                                    break;
                                }
                            }
                            if (struc.Logic == null)
                            {
                                Debug.LogFormat("Warning: Loaded multiplayer shop without data (ID={0})", struc.ID);
                            }
                        }
                        else if ((struc.Class.ID >= 99 && struc.Class.ID <= 101) ||  // kaarg inn
                                 (struc.Class.ID >= 111 && struc.Class.ID <= 113) || // druid inn
                                 (struc.Class.ID >= 67 && struc.Class.ID <= 69))     // plagat inn
                        {
                            foreach (AllodsMap.AlmInnInfo info in mapStructure.Inns)
                            {
                                if (info.ID == struc.Tag)
                                {
                                    struc.Logic = new InnStructure(struc, info);
                                    break;
                                }
                            }
                            if (struc.Logic == null)
                            {
                                Debug.LogFormat("Warning: Loaded multiplayer inn without data (ID={0})", struc.ID);
                            }
                        }
                    }

                    struc.LinkToWorld();
                    AddObject(struc, (struc.Logic != null));
                }
            }

            // load groups
            if (!NetworkManager.IsClient && mapStructure.Groups != null)
            {
                foreach (AllodsMap.AlmGroup almgroup in mapStructure.Groups)
                {
                    Group grp = FindNewGroup((int)almgroup.GroupID);
                    grp.RepopDelay = (int)almgroup.RepopTime * TICRATE;
                    grp.Flags      = 0;
                    if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.RandomPositions))
                    {
                        grp.Flags |= GroupFlags.RandomPositions;
                    }
                    if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestKill))
                    {
                        grp.Flags |= GroupFlags.QuestKill;
                    }
                    if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestIntercept))
                    {
                        grp.Flags |= GroupFlags.QuestIntercept;
                    }
                }
            }

            // load units
            if (!NetworkManager.IsClient && mapStructure.Units != null)
            {
                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
                foreach (AllodsMap.AlmUnit almunit in mapStructure.Units)
                {
                    if ((almunit.Flags & 0x10) != 0)
                    {
                        MapHuman human = new MapHuman(almunit.ServerID);
                        if (human.Class == null)
                        {
                            Debug.LogFormat("Tried to load invalid unit {0}", almunit.ServerID);
                            continue;
                        }

                        human.X      = human.TargetX = human.SpawnX = human.LastSpawnX = (int)almunit.X;
                        human.Y      = human.TargetY = human.SpawnY = human.LastSpawnY = (int)almunit.Y;
                        human.Tag    = almunit.ID;
                        human.Player = GetPlayerByID(almunit.Player - 1);
                        if (almunit.HealthMax >= 0)
                        {
                            human.CoreStats.HealthMax = almunit.HealthMax;
                            human.UpdateItems();
                        }
                        if (almunit.Health >= 0)
                        {
                            human.Stats.TrySetHealth(almunit.Health);
                        }
                        human.CalculateVision();
                        human.Group = FindNewGroup(almunit.Group);

                        human.LinkToWorld();
                        AddObject(human, true);
                    }
                    else
                    {
                        MapUnit unit = new MapUnit(almunit.ServerID);
                        if (unit.Class == null)
                        {
                            Debug.LogFormat("Tried to load invalid unit {0}", almunit.ServerID);
                            continue;
                        }

                        unit.X      = unit.TargetX = unit.SpawnX = unit.LastSpawnX = (int)almunit.X;
                        unit.Y      = unit.TargetY = unit.SpawnY = unit.LastSpawnY = (int)almunit.Y;
                        unit.Tag    = almunit.ID;
                        unit.Player = GetPlayerByID(almunit.Player - 1);
                        if (almunit.HealthMax >= 0)
                        {
                            unit.CoreStats.HealthMax = almunit.HealthMax;
                            unit.UpdateItems();
                        }
                        if (almunit.Health >= 0)
                        {
                            unit.Stats.TrySetHealth(almunit.Health);
                        }
                        unit.CalculateVision();
                        unit.Group = FindNewGroup(almunit.Group);

                        unit.LinkToWorld();
                        AddObject(unit, true);
                    }
                }
            }

            // load items into units
            if (!NetworkManager.IsClient && mapStructure.Sacks != null)
            {
                foreach (AllodsMap.AlmSack almsack in mapStructure.Sacks)
                {
                    if (almsack.Items.Length <= 0)
                    {
                        continue;
                    }

                    MapUnit unit = null;
                    MapSack sack = null;
                    if (almsack.UnitID != 0)
                    {
                        unit = GetUnitByTag((int)almsack.UnitID);
                        if (unit == null)
                        {
                            Debug.LogFormat("Error: Can't resolve unit ID {0} for sack", almsack.UnitID);
                            continue;
                        }
                    }
                    else
                    {
                        sack             = PutSackAt((int)almsack.X, (int)almsack.Y, new ItemPack(), false);
                        sack.Pack.Money += almsack.Gold;
                    }

                    List <Item> items = new List <Item>();
                    foreach (AllodsMap.AlmSackItem almitem in almsack.Items)
                    {
                        List <ItemEffect>   effects       = new List <ItemEffect>();
                        AllodsMap.AlmEffect almBaseEffect = null;
                        int almBaseEffectId = (int)(almitem.EffectNumber - 1);
                        if (mapStructure.Effects != null && almBaseEffectId >= 0 && almBaseEffectId < mapStructure.Effects.Length)
                        {
                            almBaseEffect = mapStructure.Effects[almBaseEffectId];
                            foreach (AllodsMap.AlmEffectModifier mod in almBaseEffect.EffectModifiers)
                            {
                                ItemEffect effect = new ItemEffect((ItemEffect.Effects)mod.TypeOfMod, (int)mod.Value);
                                effects.Add(effect);
                            }
                        }
                        else if (almBaseEffectId >= 0)
                        {
                            Debug.LogFormat("Warning: Can't resolve effect #{0} for sack item", almBaseEffectId);
                        }

                        Item item = new Item((ushort)almitem.ItemID, effects);
                        if (unit != null)
                        {
                            if (almitem.Wielded > 0)
                            {
                                unit.PutItemToBody((MapUnit.BodySlot)item.Class.Option.Slot, item);
                            }
                            else
                            {
                                unit.ItemsPack.PutItem(unit.ItemsPack.Count, item);
                            }
                        }
                        else if (sack != null)
                        {
                            sack.Pack.PutItem(sack.Pack.Count, item);
                        }
                    }
                }
            }

            //* WB_pathfind
            if (PathfindingType == PathfindingType.Flood)
            {
                Wizard.LoadMap(this);
            }
            //* end

            // only if loaded
            MapStructure = mapStructure;
            FileName     = filename;
            FileMD5      = ResourceManager.CalcMD5(FileName);
            MapLighting  = new TerrainLighting(Width, Height);
            CalculateLighting(180);

            // postprocessing
            // if we are playing in singleplayer, then console player is Self.
            if (!NetworkManager.IsClient && !NetworkManager.IsServer)
            {
                Player Self = GetPlayerByName("Self");
                if (Self == null)
                {
                    GameConsole.Instance.WriteLine("Error: couldn't set ConsolePlayer: Self not found!");
                }
                else
                {
                    ConsolePlayer = Self;
                }
                if (ConsolePlayer != null)
                {
                    ConsolePlayer.Name  = Config.cl_nickname.Length == 0 ? "Self" : Config.cl_nickname;
                    ConsolePlayer.Flags = 0;
                    ConsolePlayer.Diplomacy[ConsolePlayer.ID] = DiplomacyFlags.Ally | DiplomacyFlags.Vision;
                    GameManager.Instance.CallDelegateOnNextFrame(() =>
                    {
                        ConsolePlayer.Avatar = CreateAvatar(ConsolePlayer);
                        // center view on avatar.
                        MapView.Instance.CenterOnObject(ConsolePlayer.Avatar);
                        return(false);
                    });
                }
            }

            if (!NetworkManager.IsClient)
            {
                // testing

                /*
                 * ItemPack testpack = new ItemPack();
                 * testpack.PutItem(0, new Item("Very Rare Crystal Ring"));
                 * PutSackAt(16, 16, testpack, false);
                 */

                /*
                 * MapProjectile proj = new MapProjectile(15);
                 * proj.SetPosition(16, 16, 0);
                 * Objects.Add(proj);
                 */
            }

            GameManager.Instance.CallDelegateOnNextFrame(() =>
            {
                MapView.Instance.OnMapLoaded();
                return(false);
            });
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            GameConsole.Instance.WriteLine("Failed to load {0}: {1}: {2}", filename, e.GetType().Name, e.Message);
            MapStructure = null;
        }
        finally
        {
            IsLoading = false;
        }
    }