Ejemplo n.º 1
0
        public static InstancedMap CreateInstancedMap(IMap sourceMap)
        {
            DataManager.Maps.InstancedMap dmInstancedMap = new DataManager.Maps.InstancedMap(MapManager.GenerateMapID("i"));
            InstancedMap iMap = new InstancedMap(dmInstancedMap);

            CloneMapTileProperties(sourceMap, iMap);
            CloneMapTiles(sourceMap, iMap);
            CloneMapGeneralProperties(sourceMap, iMap);
            CloneMapNpcs(sourceMap, iMap);
            return(iMap);
        }
Ejemplo n.º 2
0
        public void SpawnNpc(MapNpcPreset npc, bool checkSight)
        {
            int  NPCNum  = 0;
            int  X       = 0;
            int  Y       = 0;
            bool Spawned = false;

            // Check for empty NPC slot
            int npcSlot = FindOpenNpcSlot();

            if (npcSlot < 0 || npcSlot >= Constants.MAX_MAP_NPCS)
            {
                return;
            }

            NPCNum = npc.NpcNum;
            if (NPCNum > 0)
            {
                ActiveNpc[npcSlot].Num    = NPCNum;
                ActiveNpc[npcSlot].Target = null;

                ActiveNpc[npcSlot].Name = NpcManager.Npcs[NPCNum].Name;
                ActiveNpc[npcSlot].Form = NpcManager.Npcs[NPCNum].Form;

                //if (NpcManager.Npcs[NPCNum].ShinyChance != 0 && Server.Math.Rand(0, NpcManager.Npcs[NPCNum].ShinyChance) == 0) ActiveNpc[npcSlot].Shiny = true;
                ActiveNpc[npcSlot].Sex = Pokedex.Pokedex.GetPokemonForm(NpcManager.Npcs[NPCNum].Species, ActiveNpc[npcSlot].Form).GenerateLegalSex();

                ActiveNpc[npcSlot].AttackTimer = new TickCount(Core.GetTickCount().Tick);
                ActiveNpc[npcSlot].PauseTimer  = new TickCount(Core.GetTickCount().Tick);

                //if (Npc[npcSlot].MinLevel == -1) {
                //Npc[npcSlot].MinLevel = NpcManager.Npcs[Npc[npcSlot].NpcNum].RecruitLevel;
                if (npc.MinLevel <= 0)
                {
                    npc.MinLevel = 1;
                    npc.MaxLevel = 1;
                }// else {
                //        Console.WriteLine("Npc found!");
                //    }
                //}
                ActiveNpc[npcSlot].Level = Server.Math.Rand(npc.MinLevel, npc.MaxLevel + 1);
                //set initial stats
                ActiveNpc[npcSlot].CalculateOriginalSprite();
                ActiveNpc[npcSlot].CalculateOriginalStats();
                ActiveNpc[npcSlot].CalculateOriginalType();
                ActiveNpc[npcSlot].CalculateOriginalAbility();
                //ActiveNpc[npcSlot].CalculateOriginalMobility();


                ActiveNpc[npcSlot].HP = ActiveNpc[npcSlot].MaxHP;

                ActiveNpc[npcSlot].Direction = (Enums.Direction)Server.Math.Rand(0, 4);

                ActiveNpc[npcSlot].GenerateMoveset();

                if (Moral == Enums.MapMoral.None)
                {
                    ActiveNpc[npcSlot].GenerateHeldItem();
                }

                if (Server.Math.Rand(0, 100) < npc.StartStatusChance)
                {
                    ActiveNpc[npcSlot].StatusAilment        = npc.StartStatus;
                    ActiveNpc[npcSlot].StatusAilmentCounter = npc.StartStatusCounter;
                }

                if (npc.SpawnX < 0 | npc.SpawnY < 0)
                {
                    // We'll try 100 times to randomly place the sprite
                    for (int i = 1; i <= 50; i++)
                    {
                        if (Tile[X, Y].Type == Enums.TileType.Walkable || Tile[X, Y].Type == Enums.TileType.Slow)
                        {
                            if (checkSight)
                            {
                                bool seen = false;
                                foreach (Client client in GetClients())
                                {
                                    if (CanCharacterSeeDestination(client.Player.GetActiveRecruit(), X, Y))
                                    {
                                        seen = true;
                                        break;
                                    }
                                }
                                if (!seen)
                                {
                                    ActiveNpc[npcSlot].X = X;
                                    ActiveNpc[npcSlot].Y = Y;
                                    Spawned = true;
                                    break;
                                }
                            }
                            else
                            {
                                ActiveNpc[npcSlot].X = X;
                                ActiveNpc[npcSlot].Y = Y;
                                Spawned = true;
                                break;
                            }
                        }
                    }

                    for (int i = 1; i <= 50; i++)
                    {
                        X = Server.Math.Rand(0, MaxX + 1);
                        Y = Server.Math.Rand(0, MaxY + 1);

                        // Check if the tile is walkable
                        if (Tile[X, Y].Type == Enums.TileType.Walkable)
                        {
                            ActiveNpc[npcSlot].X = X;
                            ActiveNpc[npcSlot].Y = Y;
                            Spawned = true;
                            break;
                        }
                    }
                }
                else
                {
                    // We no longer subtract one because Rand is ListIndex -1.
                    ActiveNpc[npcSlot].X = npc.SpawnX;
                    ActiveNpc[npcSlot].Y = npc.SpawnY;
                    Spawned = true;
                }

                // Didn't spawn, so now we'll just try to find a free tile
                if (!Spawned)
                {
                    for (Y = 0; Y <= MaxY; Y++)
                    {
                        for (X = 0; X <= MaxX; X++)
                        {
                            if (Tile[X, Y].Type == Enums.TileType.Walkable)
                            {
                                ActiveNpc[npcSlot].X = X;
                                ActiveNpc[npcSlot].Y = Y;
                                Spawned = true;
                            }
                        }
                    }
                }

                // If we suceeded in spawning then send it to everyone
                if (Spawned)
                {
                    PacketHitList hitlist = null;
                    PacketHitList.MethodStart(ref hitlist);
                    PacketBuilder.AppendNpcSpawn(MapManager.RetrieveActiveMap(MapID), hitlist, npcSlot);

                    Scripting.ScriptManager.InvokeFunction("OnNpcSpawn", MapManager.RetrieveActiveMap(MapID), npc, ActiveNpc[npcSlot], hitlist);

                    PacketHitList.MethodEnded(ref hitlist);
                }
            }
        }
Ejemplo n.º 3
0
        public void MapGetItem()
        {
            int i = 0;

            IMap map = MapManager.RetrieveActiveMap(MapID);

            for (i = 0; i < Constants.MAX_MAP_ITEMS; i++)
            {
                // See if theres even an item here
                if ((map.ActiveItem[i].Num >= 0) & (map.ActiveItem[i].Num < Items.ItemManager.Items.MaxItems))
                {
                    // Check if item is at the same location as the player
                    if ((map.ActiveItem[i].X == X) & (map.ActiveItem[i].Y == Y))
                    {
                        // Open slot available?
                        if (HeldItem == null)
                        {
                            // Set item in players inventory
                            InventoryItem newItem = new InventoryItem();
                            newItem.Num    = map.ActiveItem[i].Num;
                            newItem.Sticky = map.ActiveItem[i].Sticky;
                            newItem.Tag    = map.ActiveItem[i].Tag;

                            if (ItemManager.Items[map.ActiveItem[i].Num].Type == Enums.ItemType.Currency || ItemManager.Items[map.ActiveItem[i].Num].StackCap > 0)
                            {
                                newItem.Amount = map.ActiveItem[i].Value;
                                if (newItem.Amount > ItemManager.Items[map.ActiveItem[i].Num].StackCap)
                                {
                                    newItem.Amount = ItemManager.Items[map.ActiveItem[i].Num].StackCap;
                                }
                            }
                            else
                            {
                                newItem.Amount = 0;
                            }

                            GiveItem(newItem);

                            // Erase item from the map ~ done in spawnitemslot

                            map.SpawnItemSlot(i, -1, 0, false, false, "", X, Y, null);

                            Scripting.ScriptManager.InvokeSub("OnPickupItem", this, -1, HeldItem);
                            return;
                        }
                        else
                        {
                            if (map.ActiveItem[i].Num == HeldItem.Num && (ItemManager.Items[map.ActiveItem[i].Num].Type == Enums.ItemType.Currency || ItemManager.Items[map.ActiveItem[i].Num].StackCap > 0))
                            {
                                HeldItem.Amount += map.ActiveItem[i].Value;
                                if (HeldItem.Amount > ItemManager.Items[map.ActiveItem[i].Num].StackCap)
                                {
                                    HeldItem.Amount = ItemManager.Items[map.ActiveItem[i].Num].StackCap;
                                }
                                HeldItem.Sticky = map.ActiveItem[i].Sticky;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static IMap RetrieveMap(string mapID, bool autoActivate)
        {
            if (mapID.StartsWith("s"))
            {
                IMap map;

                bool mapLoaded = false;
                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = MapManager.LoadStandardMap(dbConnection, mapID);
                        }
                        mapLoaded = true;
                        if (autoActivate)
                        {
                            rwLock.EnterWriteLock();
                            try {
                                MapManager.UnsafeAddActiveMap(map);
                            } finally {
                                rwLock.ExitWriteLock();
                            }
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (mapLoaded && autoActivate)
                {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return(map);
            }
            else if (mapID.StartsWith("i"))
            {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadInstancedMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null)
                {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return(map);
            }
            else if (mapID.StartsWith("rd"))
            {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadRDungeonMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null)
                {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return(map);
            }
            else if (mapID.StartsWith("h"))
            {
                // Check if the requested map is already active and loaded
                IMap map       = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadHouseMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        mapLoaded = true;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                //if (map == null) {
                //    // Uh oh! We couldn't load the map! Default to the start map
                //    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                //}

                return(map);
            }
            else if (mapID.StartsWith("void"))
            {
                IMap map       = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null)
                    {
                        string         charID = mapID.Replace("void-", "");
                        Network.Client client = Network.ClientManager.FindClientFromCharID(charID);
                        if (client != null)
                        {
                            map       = new Void(client.Player);
                            mapLoaded = true;
                            if (autoActivate)
                            {
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map != null && mapLoaded && autoActivate)
                {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return(map);
            }
            else
            {
                return(RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads)));
            }
        }
Ejemplo n.º 5
0
 public static IMap RetrieveMap(int mapNum, bool autoActivate)
 {
     return(RetrieveMap(MapManager.GenerateMapID(mapNum), autoActivate));
 }
Ejemplo n.º 6
0
 public static void SwitchSeamlessMaps(Client client, int mapNum, int x, int y)
 {
     SwitchSeamlessMaps(client, MapManager.RetrieveMap(mapNum), x, y);
 }