Esempio n. 1
0
        public void MapDropItem(int val, Client playerFor)
        {
            if (HeldItem != null)
            {
                IMap currentMap = MapManager.RetrieveActiveMap(MapID);
                int  i          = currentMap.FindOpenItemSlot();

                if (i != -1)
                {
                    if (currentMap != null)
                    {
                        if (val >= HeldItem.Amount)
                        {
                            currentMap.SpawnItemSlot(i, HeldItem.Num, HeldItem.Amount, HeldItem.Sticky, false, HeldItem.Tag, HeldItem.IsSandboxed, X, Y, playerFor);
                            RemoveFromActiveItemList(HeldItem.Num);
                            HeldItem = null;
                        }
                        else
                        {
                            currentMap.SpawnItemSlot(i, HeldItem.Num, val, false, false, HeldItem.Tag, HeldItem.IsSandboxed, X, Y, playerFor);
                            HeldItem.Amount -= val;
                        }
                        Scripting.ScriptManager.InvokeSub("OnDropItem", this, -1, currentMap.ActiveItem[i]);
                    }
                }
            }
        }
Esempio n. 2
0
        public static bool IsMapSeamless(IMap map, Enums.MapID direction)
        {
            // return false;

            if (map.MapType == Enums.MapType.Standard)
            {
                string borderingMapID = MapManager.RetrieveBorderingMapID(map, direction);
                if (!string.IsNullOrEmpty(borderingMapID))
                {
                    IMap borderingMap = MapManager.RetrieveActiveMap(borderingMapID);
                    if (borderingMap != null)
                    {
                        return(IsMapSeamless(map, borderingMap));
                    }
                }
            }

            return(false);
        }
Esempio 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, "", map.IsZoneOrObjectSandboxed(), 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;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
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);
                }
            }
        }