Beispiel #1
0
        public static bool VerifyKeyTile(Client client, IMap map, int x, int y, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);
            bool unlocked = false;

            Tile mapTile = map.Tile[x, y];

            if (mapTile.Type == Server.Enums.TileType.Scripted)
            {
                if (mapTile.Data1 == 58)
                {
                    int      chargeLevel = mapTile.String1.ToInt();
                    exPlayer exPlayer    = exPlayer.Get(client);

                    if ((exPlayer.ElectrolockLevel == chargeLevel && exPlayer.ElectrolockCharge >= ChargesNeededForLevel(chargeLevel) && exPlayer.ElectrolockSublevel.Count >= SublevelsNeededForLevel(chargeLevel)) ||
                        exPlayer.ElectrolockLevel > chargeLevel)
                    {
                        unlocked = true;
                        DisplayInvisibleKeyTile(client, map, x, y, packetList);
                    }
                    else
                    {
                        DisplayVisibleKeyTile(client, map, x, y, packetList);
                    }
                }
            }
            PacketHitList.MethodEnded(ref packetList);
            return(unlocked);
        }
Beispiel #2
0
        public static void OnStep(Client client, PacketHitList hitlist)
        {
            // NOTE: Remove the mapper+ check for release
            if (exPlayer.Get(client).AnniversaryEnabled&& client.Player.CurrentChapter == null && Ranks.IsAllowed(client, Enums.Rank.Mapper))
            {
                int currentAnniversarySection = client.Player.StoryHelper.ReadSetting("[Anniversary12]-CurrentSection").ToInt();
                //Messenger.PlayerMsg(client, "Section: " + currentAnniversarySection, Text.BrightRed);
                // NOTE: Do /not/ remove the mapper+ check here, this resets the story when you reach the end
                if (currentAnniversarySection == annivRiddles.Length && Ranks.IsAllowed(client, Enums.Rank.Mapper))
                {
                    currentAnniversarySection = 0;
                    client.Player.StoryHelper.SaveSetting("[Anniversary12]-CurrentSection", currentAnniversarySection.ToString());
                    Messenger.PlayerMsg(client, "Section reset!", Text.BrightRed);
                }
                if (currentAnniversarySection >= 0 && currentAnniversarySection < annivRiddles.Length)
                {
                    AnniversaryRiddle currentRiddle = annivRiddles[currentAnniversarySection];
                    if (client.Player.MapID == currentRiddle.MapId &&
                        client.Player.X == currentRiddle.X && client.Player.Y == currentRiddle.Y)
                    {
                        client.Player.SetStoryState(currentRiddle.Story - 1, false);
                        StoryManager.PlayStory(client, currentRiddle.Story - 1);

                        currentAnniversarySection++;
                        client.Player.StoryHelper.SaveSetting("[Anniversary12]-CurrentSection", currentAnniversarySection.ToString());
                    }
                }
            }
            if (exPlayer.Get(client).StoryEnabled&& client.Player.CurrentChapter == null)
            {
                int currentStorySection = client.Player.StoryHelper.ReadSetting("[MainStory]-CurrentSection").ToInt();
                switch (client.Player.MapID)
                {
                case "s737": {
                    if (currentStorySection == 3)                                       // Tiny Grotto complete, first time [Bulbasaur mission]
                    {
                        if (client.Player.X > 20 && client.Player.X < 35 && client.Player.Y > 43)
                        {
                            if (client.Player.GetDungeonCompletionCount(1 - 1) >= 1)
                            {
                                StoryManager.PlayStory(client, 614 - 1);
                            }
                        }
                    }
                }
                break;

                case "s1934": {
                    if (currentStorySection == 6)
                    {
                        if (client.Player.X == 10 && client.Player.Y == 9)
                        {
                            StoryManager.PlayStory(client, 616 - 1);
                        }
                    }
                }
                break;
                }
            }
        }
Beispiel #3
0
        public static void RunTest(Client client)
        {
            Messenger.PlayerMsg(client, client.IP.ToString(), Text.BrightRed);


            return;

            int           playerCount = 0;
            PacketHitList hitlist     = null;

            PacketHitList.MethodStart(ref hitlist);
            IMap map = client.Player.Map;

            Stopwatch watch = new Stopwatch();

            watch.Start();
            using (DatabaseConnection db = new DatabaseConnection(DatabaseID.Players)) {
                PlayerManager.RetrieveCharacterID(db, "luigiDUDE");
            }
            //Messenger.PlayerWarp(client, map.MapID, 0, 25);
            watch.Stop();
            PacketHitList.MethodEnded(ref hitlist);
            Messenger.PlayerMsg(client, "Time: " + watch.ElapsedMilliseconds + "\nPlayer Count: " + playerCount, Text.BrightGreen);
            Messenger.PlayerMsg(client, "RNG: " + Server.Math.Rand(0, 1000), Text.BrightGreen);
            Messenger.PlayerMsg(client, "Tick Count: " + Server.Core.GetTickCount().Tick, Text.BrightGreen);
            //exPlayer.Get(client).EvolutionActive = !exPlayer.Get(client).EvolutionActive;
            //Messenger.PlayerMsg(client, "Evolution active: " + exPlayer.Get(client).EvolutionActive, Text.Yellow);
            //BossBattles.StartBossBattle(client, "CliffsideRelic");


            //map.SetTile(9, 3, 3, 0, 4, 3);
            //map.SetAttribute(9, 3, Server.Enums.TileType.Scripted, 46, 0, 0, "2", "1015", "25:25");
            //Messenger.SendTile(9, 3, map);
        }
Beispiel #4
0
        public override void OnNpcDeath(PacketHitList hitlist, ICharacter attacker, MapNpc npc)
        {
            var map = MapManager.RetrieveActiveMap(npc.MapID);

            if (!map.ActiveNpc.Enumerate().Where(x => x.Num > 0).Where(x => x != npc).Any())
            {
                SetCompletionTile(MapManager.RetrieveActiveMap(npc.MapID));
            }
        }
Beispiel #5
0
 public static bool MoveNpcRight(IMap map, Client target, PacketHitList packetList, int mapNpcSlot)
 {
     // Right
     if (map.ActiveNpc[mapNpcSlot].X < target.Player.X)
     {
         if (MovementProcessor.CanNpcMove(map, mapNpcSlot, Enums.Direction.Right))
         {
             MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking);
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
        public static void VerifyMapSublevelTriggerTiles(Client client, IMap map, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);
            bool unlocked = false;

            for (int x = 0; x <= map.MaxX; x++)
            {
                for (int y = 0; y <= map.MaxY; y++)
                {
                    VerifySublevelTriggerTile(client, map, x, y, packetList);
                }
            }
            PacketHitList.MethodEnded(ref packetList);
        }
Beispiel #7
0
        public static void OnMapLoaded(Client client, IMap map, PacketHitList packetList)
        {
            if (exPlayer.Get(client).StoryEnabled)
            {
                int currentStorySection = client.Player.StoryHelper.ReadSetting("[MainStory]-CurrentSection").ToInt();
                switch (map.MapID)
                {
                case "s50": {
                    if (currentStorySection == 4)                                       // Retreive 500 Poke for Team Jaw
                    {
                        if (client.Player.HasItem(1) >= 500)
                        {
                            // We have the 500 Poke
                            client.Player.TakeItem(1, 500);
                            // Move forward one section so we don't have to take the money again
                            currentStorySection++;
                            client.Player.StoryHelper.SaveSetting("[MainStory]-CurrentSection", currentStorySection.ToString());
                        }
                        else
                        {
                            // We don't have the 500 Poke
                            StoryManager.PlayStory(client, 619 - 1);
                        }
                    }
                    if (currentStorySection == 5)                                       // We already delivered the 500 Poke to Team Jaw
                    {
                        StoryManager.PlayStory(client, 615 - 1);
                    }
                }
                break;

                case "s737": {
                    if (currentStorySection == 1)
                    {
                        StoryManager.PlayStory(client, 612 - 1);
                    }
                }
                break;

                case "s1286": {
                    if (client.Player.Y > 8 && client.Player.Y < 40 &&
                        currentStorySection == 2)
                    {
                        StoryManager.PlayStory(client, 613 - 1);
                    }
                }
                break;
                }
            }
        }
Beispiel #8
0
        public override void DeconfigurePlayer(Client client)
        {
            base.DeconfigurePlayer(client);

            client.Player.KillableAnywhere = false;
            client.Player.EndTempStatMode();

            PacketHitList packetHitList = null;

            PacketHitList.MethodStart(ref packetHitList);

            Main.RefreshCharacterSpeedLimit(client.Player.GetActiveRecruit(), client.Player.Map, packetHitList);

            PacketHitList.MethodEnded(ref packetHitList);
        }
Beispiel #9
0
        public static void CheckForSublevelGoal(Client client, PacketHitList packetList)
        {
            for (int i = 0; i < client.Player.TriggerEvents.Count; i++)
            {
                if (client.Player.TriggerEvents[i].Trigger == TriggerEventTrigger.SteppedOnTile &&
                    client.Player.TriggerEvents[i].ID.StartsWith("ESTSublevelGoal"))
                {
                    SteppedOnTileTriggerEvent tEvent = client.Player.TriggerEvents[i] as SteppedOnTileTriggerEvent;

                    if (client.Player.MapID == tEvent.MapID)
                    {
                        DisplayVisibleSublevelGoalTile(client, client.Player.Map, tEvent.X, tEvent.Y, packetList);
                    }
                }
            }
        }
Beispiel #10
0
        public static void CreateNewParty(Client leader)
        {
            PacketHitList hitlist = null;

            PacketHitList.MethodStart(ref hitlist);
            List <string> partyIDs = new List <string>();

            using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players))
            {
                partyIDs = LoadPartyIDList(dbConnection.Database);
            }

            if (leader.Player.PartyID == null)
            {
                string partyID = null;
                rwLock.EnterWriteLock();
                try
                {
                    while (true)
                    {
                        string tempID = Security.PasswordGen.Generate(10, 15);
                        if (partyIDs.Contains(tempID) == false)
                        {
                            partyID = tempID;
                            break;
                        }
                    }
                    Party party = new Party(partyID, leader);
                    leader.Player.PartyID = partyID;
                    parties.Add(partyID, party);
                }
                finally
                {
                    rwLock.ExitWriteLock();
                }
                leader.Player.AddExpKitModule(new AvailableExpKitModule(Enums.ExpKitModules.Party, true));
                PacketBuilder.AppendPartyMemberDataFor(leader, hitlist, 0);
                hitlist.AddPacket(leader, PacketBuilder.CreateChatMsg("You have created a new party!", Text.BrightGreen));
            }
            else
            {
                hitlist.AddPacket(leader, PacketBuilder.CreateChatMsg("You are already in a party!", Text.BrightRed));
            }

            PacketHitList.MethodEnded(ref hitlist);
        }
Beispiel #11
0
        public static void JoinParty(Party party, Client client)
        {
            PacketHitList hitlist = null;

            PacketHitList.MethodStart(ref hitlist);

            if (party != null)
            {
                Client leader = party.GetLeader();
                if (Combat.MoveProcessor.IsInAreaRange(1, client.Player.X, client.Player.Y, leader.Player.X, leader.Player.Y))
                {
                    if (party.AddToParty(client))
                    {
                        client.Player.PartyID = party.PartyID;
                        client.Player.AddExpKitModule(new AvailableExpKitModule(Enums.ExpKitModules.Party, true));
                        hitlist.AddPacket(client, PacketBuilder.CreateChatMsg("You have joined the party!", Text.BrightGreen));
                        //PartyMember member = party.FindMember(client.Player.CharID);
                        int slot = party.GetMemberSlot(client.Player.CharID);
                        //Messenger.SendPartyMemberData(client, member, slot);
                        foreach (Client i in party.GetOnlineMemberClients())
                        {
                            if (i.IsPlaying() && i != client)
                            {
                                //PartyMember teamMember = party.Members.FindMember(i.Player.CharID);
                                //int teamMemberSlot = party.Members.GetMemberSlot(i.Player.CharID);
                                //Messenger.SendPartyMemberData(client, teamMember, teamMemberSlot);
                                //Messenger.SendPartyMemberData(i, member, slot);
                                hitlist.AddPacket(i, PacketBuilder.CreateChatMsg(client.Player.Name + " has joined the party!", Text.BrightGreen));
                            }
                            PacketBuilder.AppendPartyMemberData(i, hitlist, slot);
                        }
                    }
                    else
                    {
                        hitlist.AddPacket(client, PacketBuilder.CreateChatMsg("You couldn't join the party!", Text.BrightRed));
                    }
                }
                else
                {
                    Messenger.PlayerMsg(client, "You need to stand next to the leader to join the party!", Text.BrightRed);
                }
            }

            PacketHitList.MethodEnded(ref hitlist);
        }
Beispiel #12
0
        public void CompleteRoom(Client client)
        {
            var playerData = Data.ExtendPlayer(client);

            if (playerData.CurrentRoom % CheckpointInterval == 0)
            {
                PacketHitList hitlist = null;

                PacketHitList.MethodStart(ref hitlist);
                Main.HealParty(hitlist, client);
                PacketHitList.MethodEnded(ref hitlist);
            }

            playerData.CurrentRoom++;
            playerData.RoomsCleared++;

            WarpToCurrentRoom(client);
        }
Beispiel #13
0
        public static void DisplayInvisibleSublevelGoalTile(Client client, IMap map, int x, int y, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);
            Tile tile = new Tile(new DataManager.Maps.Tile());

            MapCloner.CloneTile(map, x, y, tile);
            tile.Mask    = 0;
            tile.MaskSet = 7;
            tile.Type    = Enums.TileType.Walkable;
            Messenger.SendTemporaryTileTo(packetList, client, x, y, tile);

            MapCloner.CloneTile(map, x, y - 1, tile);
            tile.Fringe    = 0;
            tile.FringeSet = 7;
            tile.Type      = Enums.TileType.Walkable;
            Messenger.SendTemporaryTileTo(packetList, client, x, y - 1, tile);

            PacketHitList.MethodEnded(ref packetList);
        }
Beispiel #14
0
        public static bool VerifyMapKeyTiles(Client client, IMap map, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);
            bool unlocked = false;

            for (int x = 0; x <= map.MaxX; x++)
            {
                for (int y = 0; y <= map.MaxY; y++)
                {
                    bool state = VerifyKeyTile(client, map, x, y, packetList);
                    if (state)
                    {
                        unlocked = true;
                    }
                }
            }
            PacketHitList.MethodEnded(ref packetList);

            return(unlocked);
        }
Beispiel #15
0
        public override void OnNpcDeath(PacketHitList hitlist, ICharacter attacker, MapNpc npc)
        {
            base.OnNpcDeath(hitlist, attacker, npc);

            if (Data.Started)
            {
                var map = MapManager.RetrieveMap(attacker.MapID);
                if (!map.IsZoneOrObjectSandboxed())
                {
                    if (attacker.CharacterType == Enums.CharacterType.Recruit)
                    {
                        var npcDefinition = NpcManager.Npcs[npc.Species];
                        var owner         = ((Recruit)attacker).Owner;

                        if (npc.Shiny == Enums.Coloration.Shiny &&
                            (npcDefinition.Behavior == Enums.NpcBehavior.AttackOnSight || npcDefinition.Behavior == Enums.NpcBehavior.AttackWhenAttacked || npcDefinition.Behavior == Enums.NpcBehavior.FleeOnsight))
                        {
                            if (Data.Scores.TryGetValue(owner.Player.CharID, out var userScore))
                            {
                                userScore.Score += 1;
                            }
                            else
                            {
                                userScore = new UserScore()
                                {
                                    Score = 1
                                };
                                Data.Scores.Add(owner.Player.CharID, userScore);
                            }

                            if (!userScore.FoundSpecies.Contains(npc.Species))
                            {
                                userScore.FoundSpecies.Add(npc.Species);
                            }

                            Messenger.PlayerMsg(owner, "You got a point!", Text.BrightGreen);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        public static void HandleOutlawGameOver(Client client, ref PacketHitList hitList)
        {
            PacketHitList.MethodStart(ref hitList);

            if (client.Player.OutlawRole == Enums.OutlawRole.Outlaw)
            {
                var lostPoints   = client.Player.PlayerData.PendingOutlawPoints % OutlawPointInterval;
                var gainedPoints = client.Player.PlayerData.PendingOutlawPoints - lostPoints;

                client.Player.PlayerData.LockedOutlawPoints += gainedPoints;

                Messenger.PlayerMsg(client, $"You have been defeated! You gained {gainedPoints} points from this round!", Text.BrightGreen);

                Messaging.SendGlobalMessage($"{client.Player.DisplayName} has been captured!", Settings.DiscordOutlawChannel, Text.BrightGreen);
            }

            client.Player.OutlawRole = Enums.OutlawRole.None;
            client.Player.PlayerData.PendingOutlawPoints = 0;

            PacketBuilder.AppendPlayerData(client, hitList);

            PacketHitList.MethodEnded(ref hitList);
        }
Beispiel #17
0
        public static void OnMapLoaded(Client client, IMap map, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);
            if (IsInTower(map))
            {
                // Prevent others from entering until finished. Spoiler prevention!

                if (Ranks.IsDisallowed(client, Enums.Rank.Scripter))
                {
                    packetList.HitList.Clear(); // Remove the warp packets to cancel the map load
                    Messenger.PlayerWarp(client, 1015, 25, 25);
                    if (Ranks.IsAllowed(client, Enums.Rank.Moniter))
                    {
                        Messenger.PlayerMsg(client, "Sorry, you can't go here! ~Pikachu", Text.BrightRed);
                    }
                    else
                    {
                        Messenger.PlayerMsg(client, "Sorry, you can't go here!", Text.BrightRed);
                    }
                }
                else
                {
                    if (VerifyMapKeyTiles(client, map, packetList))
                    {
                        packetList.AddPacket(client, PacketBuilder.CreateBattleMsg("An electrolock has been opened nearby!", Text.BrightGreen));
                    }
                    CheckForSublevelGoal(client, packetList);
                    VerifyMapSublevelTriggerTiles(client, map, packetList);
                }
            }
            else
            {
                ResetPlayer(client);
            }
            PacketHitList.MethodEnded(ref packetList);
        }
Beispiel #18
0
        public static void VerifySublevelTriggerTile(Client client, IMap map, int x, int y, PacketHitList packetList)
        {
            PacketHitList.MethodStart(ref packetList);

            Tile mapTile = map.Tile[x, y];

            if (mapTile.Type == Server.Enums.TileType.Scripted)
            {
                if (mapTile.Data1 == 59)
                {
                    string   triggerID = mapTile.String1;
                    exPlayer exPlayer  = exPlayer.Get(client);
                    if (exPlayer.ElectrolockSublevelTriggersActive.Contains(triggerID) == false)
                    {
                        DisplayVisibleSublevelTriggerTile(client, map, x, y, packetList);
                    }
                    else
                    {
                        DisplayInvisibleSublevelTriggerTile(client, map, x, y, packetList);
                    }
                }
            }
            PacketHitList.MethodEnded(ref packetList);
        }
Beispiel #19
0
        public static void DisplayInvisibleSublevelTriggerTile(Client client, IMap map, int x, int y, PacketHitList packetList)
        {
            Tile tile = new Tile(new DataManager.Maps.Tile());

            MapCloner.CloneTile(map, x, y, tile);
            tile.Mask    = 0;
            tile.MaskSet = 10;
            tile.Anim    = 0;
            tile.AnimSet = 10;
            tile.Type    = Enums.TileType.Walkable;

            Messenger.SendTemporaryTileTo(packetList, client, x, y, tile);
        }
Beispiel #20
0
        public override void OnNpcSpawn(IMap map, MapNpcPreset npc, MapNpc spawnedNpc, PacketHitList hitlist)
        {
            spawnedNpc.MaxHPBonus = 300;
            spawnedNpc.SpAtkBuff  = 1;
            spawnedNpc.SpDefBuff  = 1;
            spawnedNpc.HP         = spawnedNpc.MaxHP;

            Main.RefreshCharacterTraits(spawnedNpc, map, hitlist);
        }
Beispiel #21
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);
                }
            }
        }
Beispiel #22
0
        public static bool MoveNpcInDirection(Enums.Direction direction, IMap map, Client target, PacketHitList packetList, int mapNpcSlot)
        {
            switch (direction)
            {
            case Enums.Direction.Up: {
                return(MoveNpcUp(map, target, packetList, mapNpcSlot));
            }

            case Enums.Direction.Down: {
                return(MoveNpcDown(map, target, packetList, mapNpcSlot));
            }

            case Enums.Direction.Left: {
                return(MoveNpcLeft(map, target, packetList, mapNpcSlot));
            }

            case Enums.Direction.Right: {
                return(MoveNpcRight(map, target, packetList, mapNpcSlot));
            }
            }
            return(false);
        }
Beispiel #23
0
 public void SendHPToMap(PacketHitList packetList, IMap map, int mapNpcNum)
 {
     PacketBuilder.AppendNpcHP(map, packetList, mapNpcNum);
     hpChanged = false;
 }
Beispiel #24
0
        public void HandoutExp(Client giver, ulong exp, PacketHitList hitlist)
        {
            PacketHitList.MethodStart(ref hitlist);
            bool  totalForAll = true;
            ulong newExp;

            if (totalForAll)
            {
                newExp = exp;
            }
            else
            {
                newExp = exp * (ulong)(Members.Count + 3) / 4 / (ulong)Members.Count;
            }


            if (!(giver.Player.GetActiveRecruit().Level == Exp.ExpManager.Exp.MaxLevels) && giver.Player.Hunted && !giver.Player.Dead)
            {
                Scripting.ScriptManager.InvokeSub("PlayerEXP", hitlist, giver, newExp);

                Combat.BattleProcessor.CheckPlayerLevelUp(hitlist, giver);
            }

            foreach (Client i in GetOnlineMemberClients())
            {
                if (i.IsPlaying() && i != giver)
                {
                    //PartyMember member = members.FindMember(i.Player.CharID);
                    //if (member != null) {
                    if (giver.Player.Map == i.Player.Map)
                    {
                        if (!(i.Player.GetActiveRecruit().Level == Exp.ExpManager.Exp.MaxLevels) && i.Player.Hunted && !i.Player.Dead)
                        {
                            int lowestBound  = 8000;
                            int chosenMiddle = 8000;
                            if (i.Player.GetActiveRecruit().Level < giver.Player.GetActiveRecruit().Level)
                            {
                                int diff = giver.Player.GetActiveRecruit().Level - i.Player.GetActiveRecruit().Level;
                                lowestBound -= diff * diff * 100 / 5;
                                int distance = Math.Max(Math.Abs(giver.Player.X - i.Player.X), Math.Abs(giver.Player.Y - i.Player.Y));

                                if (distance > 40)
                                {
                                    distance = 40;
                                }

                                if (distance < 8)
                                {
                                    distance = 8;
                                }

                                chosenMiddle = lowestBound * (distance - 8) / 40 + chosenMiddle * (40 - (distance - 8)) / 40;

                                if (chosenMiddle < 0)
                                {
                                    chosenMiddle = 0;
                                }
                            }

                            ulong moddedExp = newExp * (ulong)chosenMiddle / 8000;

                            if (moddedExp < 1)
                            {
                                moddedExp = 1;
                            }

                            Scripting.ScriptManager.InvokeSub("PlayerEXP", hitlist, i, moddedExp);

                            Combat.BattleProcessor.CheckPlayerLevelUp(hitlist, i);
                        }
                        else
                        {
                            // The party member is at the max level, so do nothing
                        }
                    }
                    //}
                }
            }

            PacketHitList.MethodEnded(ref hitlist);
        }
Beispiel #25
0
        public static void DisplayVisibleKeyTile(Client client, IMap map, int x, int y, PacketHitList packetList)
        {
            Tile tile = new Tile(new DataManager.Maps.Tile());

            MapCloner.CloneTile(map, x, y, tile);
            tile.Mask    = 6;
            tile.MaskSet = 4;
            tile.Type    = Enums.TileType.Blocked;

            Messenger.SendTemporaryTileTo(packetList, client, x, y, tile);
        }
Beispiel #26
0
        public override void OnNpcSpawn(IMap map, MapNpcPreset npc, MapNpc spawnedNpc, PacketHitList hitlist)
        {
            base.OnNpcSpawn(map, npc, spawnedNpc, hitlist);

            if (Data.Started)
            {
                if (!map.IsZoneOrObjectSandboxed())
                {
                    spawnedNpc.Unrecruitable = true;
                    spawnedNpc.Shiny         = Server.Enums.Coloration.Shiny;

                    PacketBuilder.AppendNpcSprite(map, hitlist, spawnedNpc.MapSlot);
                }
            }
        }
Beispiel #27
0
        public void ProcessAI()
        {
            try {
                TickCount tickCount = Core.GetTickCount();

                PacketHitList packetList = null;
                PacketHitList.MethodStart(ref packetList);
                if (map.IsSaving == false)
                {
                    // Keys/Other timed tile stuff
                    for (int x = 0; x <= map.MaxX; x++)
                    {
                        for (int y = 0; y <= map.MaxY; y++)
                        {
                            if (map.Tile[x, y] != null)
                            {
                                if (tickCount.Elapsed(map.Tile[x, y].DoorTimer, 5000))
                                {
                                    if ((map.Tile[x, y].Type == Enums.TileType.Key || map.Tile[x, y].Type == Enums.TileType.Door) && map.Tile[x, y].DoorOpen == true)
                                    {
                                        map.Tile[x, y].DoorOpen = false;
                                        packetList.AddPacketToMap(map, TcpPacket.CreatePacket("mapkey", x.ToString(), y.ToString(), "0"));
                                    }
                                }
                            }
                        }
                    }

                    Scripting.ScriptManager.InvokeSub("OnMapTick", map);

                    if (map.ProcessingPaused == false)
                    {
                        int livingNpcs = 0;

                        for (int mapNpcSlot = 0; mapNpcSlot < Constants.MAX_MAP_NPCS; mapNpcSlot++)
                        {
                            int    npcNum = map.ActiveNpc[mapNpcSlot].Num;
                            MapNpc mapNpc = map.ActiveNpc[mapNpcSlot];

                            if (npcNum > 0)
                            {
                                livingNpcs++;

                                Npc npc = NpcManager.Npcs[npcNum];

                                if (npc.Behavior != Enums.NpcBehavior.FullyScriptedAI || npc.AIScript == "" || npc.AIScript.ToLower() == "none")
                                {
                                    #region Used for attacking on sight
                                    if (npc.Behavior == Enums.NpcBehavior.AttackOnSight || npc.Behavior == Enums.NpcBehavior.Guard)
                                    {
                                        foreach (Client i in map.GetClients())
                                        {
                                            if (i.Player.MapID == map.MapID && map.ActiveNpc[mapNpcSlot].Target == null && !i.Player.Dead &&
                                                i.Player.Hunted && map.Tile[i.Player.X, i.Player.Y].Type != Enums.TileType.NPCAvoid && i.Player.Hunted)
                                            {
                                                if (MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], i.Player.GetActiveRecruit()))
                                                {
                                                    if (npc.Behavior == Enums.NpcBehavior.AttackOnSight /* || i.Player.PK == true*/)
                                                    {
                                                        //if (!string.IsNullOrEmpty(npc.AttackSay)) {
                                                        //    packetList.AddPacket(i, PacketBuilder.CreateChatMsg("A " + npc.Name + " : " + npc.AttackSay, Text.Grey));
                                                        //}

                                                        map.ActiveNpc[mapNpcSlot].Target = i;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion

                                    #region Used for walking/targetting/picking up items
                                    if (npcNum > 0)
                                    {
                                        bool hasNpcWalked;

                                        if (map.ActiveNpc[mapNpcSlot].Target != null && map.ActiveNpc[mapNpcSlot].Target.IsPlaying() &&
                                            map.ActiveNpc[mapNpcSlot].Target.Player.MapID == map.MapID &&
                                            (map.Tile[map.ActiveNpc[mapNpcSlot].Target.Player.X, map.ActiveNpc[mapNpcSlot].Target.Player.Y].Type == Enums.TileType.NPCAvoid ||
                                             !map.ActiveNpc[mapNpcSlot].Target.Player.Hunted || map.ActiveNpc[mapNpcSlot].Target.Player.Dead ||
                                             !MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], map.ActiveNpc[mapNpcSlot].Target.Player.GetActiveRecruit())))
                                        {
                                            map.ActiveNpc[mapNpcSlot].Target = null;
                                        }

                                        Client target = map.ActiveNpc[mapNpcSlot].Target;


                                        if (npc.Behavior != Enums.NpcBehavior.Shopkeeper)
                                        {
                                            if (target != null)
                                            {
                                                if (target.IsPlaying() && target.Player.MapID == map.MapID)
                                                {
                                                    hasNpcWalked = false;
                                                    int dir = Math.Rand(0, 5);

                                                    hasNpcWalked = AIProcessor.MoveNpcInDirection((Enums.Direction)dir, map, target, packetList, mapNpcSlot);
                                                    if (!hasNpcWalked)
                                                    {
                                                        foreach (Enums.Direction direction in Enum.GetValues(typeof(Enums.Direction)))
                                                        {
                                                            if (direction != (Enums.Direction)dir)
                                                            {
                                                                if (AIProcessor.MoveNpcInDirection(direction, map, target, packetList, mapNpcSlot))
                                                                {
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }

                                                    if (hasNpcWalked == false)
                                                    {
                                                        if (map.ActiveNpc[mapNpcSlot].X - 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y)
                                                        {
                                                            if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Left)
                                                            {
                                                                MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Left);
                                                            }
                                                            hasNpcWalked = true;
                                                        }
                                                        if (map.ActiveNpc[mapNpcSlot].X + 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y)
                                                        {
                                                            if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Right)
                                                            {
                                                                MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Right);
                                                            }
                                                            hasNpcWalked = true;
                                                        }
                                                        if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y - 1 == target.Player.Y)
                                                        {
                                                            if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Up)
                                                            {
                                                                MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Up);
                                                            }
                                                            hasNpcWalked = true;
                                                        }
                                                        if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y + 1 == target.Player.Y)
                                                        {
                                                            if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Down)
                                                            {
                                                                MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Down);
                                                            }
                                                            hasNpcWalked = true;
                                                        }
                                                    }

                                                    if (hasNpcWalked == false)
                                                    {
                                                        int val = Math.Rand(0, 2);
                                                        if (val == 1)
                                                        {
                                                            val = Math.Rand(0, 4);
                                                            if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)val))
                                                            {
                                                                MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking);
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    map.ActiveNpc[mapNpcSlot].Target = null;
                                                }
                                            }
                                            else
                                            {
                                                int shouldWalk = Math.Rand(0, 2);
                                                if (npc.Behavior != Enums.NpcBehavior.Friendly)
                                                {
                                                    for (int i = 0; i < Constants.MAX_MAP_ITEMS; i++)
                                                    {
                                                        if (map.ActiveItem[i].X == map.ActiveNpc[mapNpcSlot].X && map.ActiveItem[i].Y == map.ActiveNpc[mapNpcSlot].Y &&
                                                            map.ActiveItem[i].Num > -1 && map.ActiveNpc[mapNpcSlot].HeldItem == null)
                                                        {
                                                            map.ActiveNpc[mapNpcSlot].MapGetItem();
                                                            shouldWalk = 1;
                                                        }
                                                    }
                                                }
                                                else if (npc.Behavior == Enums.NpcBehavior.Friendly)
                                                {
                                                    foreach (Client i in map.GetClients())
                                                    {
                                                        if (i.Player.X >= map.ActiveNpc[mapNpcSlot].X - 1 && i.Player.X <= map.ActiveNpc[mapNpcSlot].X + 1 &&
                                                            i.Player.Y >= map.ActiveNpc[mapNpcSlot].Y - 1 && i.Player.Y <= map.ActiveNpc[mapNpcSlot].Y + 1)
                                                        {
                                                            shouldWalk = Math.Rand(0, 10);
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (shouldWalk == 0)
                                                {
                                                    shouldWalk = Math.Rand(0, 5);
                                                    if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)shouldWalk))
                                                    {
                                                        MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    #endregion

                                    #region Used for attacking players

                                    if (npcNum > 0)
                                    {
                                        Client target = map.ActiveNpc[mapNpcSlot].Target;
                                        if (target != null)
                                        {
                                            if (target.IsPlaying() && target.Player.MapID == map.MapID)
                                            {
                                                // Make sure npcs dont attack more then once a second
                                                if (Core.GetTickCount().Elapsed(map.ActiveNpc[mapNpcSlot].AttackTimer, 1000))
                                                {
                                                    int usableMoveCount = 0;
                                                    for (int i = 0; i < mapNpc.Moves.Length; i++)
                                                    {
                                                        if (mapNpc.Moves[i].MoveNum > -1 && mapNpc.Moves[i].CurrentPP > 0)
                                                        {
                                                            usableMoveCount++;
                                                        }
                                                    }
                                                    if (usableMoveCount == 0)
                                                    {
                                                        if (BattleProcessor.ShouldUseMove(map, mapNpc, -1))
                                                        {
                                                            mapNpc.UseMove(-1);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        // Try to use a move, up to 50 times
                                                        for (int i = 0; i < 50; i++)
                                                        {
                                                            int moveSlotToUse = Server.Math.Rand(0, 5) - 1;
                                                            if (moveSlotToUse == -1)
                                                            {
                                                                // A standard attack
                                                                if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse))
                                                                {
                                                                    mapNpc.UseMove(moveSlotToUse);
                                                                    break;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (mapNpc.Moves[moveSlotToUse].MoveNum > -1 && mapNpc.Moves[moveSlotToUse].CurrentPP > 0)
                                                                {
                                                                    // Use a move
                                                                    if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse))
                                                                    {
                                                                        mapNpc.UseMove(moveSlotToUse);
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                map.ActiveNpc[mapNpcSlot].Target = null;
                                            }
                                        }
                                    }

                                    #endregion

                                    if (npcNum > 0 && map.ActiveNpc[mapNpcSlot].HPChanged)
                                    {
                                        map.ActiveNpc[mapNpcSlot].SendHPToMap(packetList, map, mapNpcSlot);
                                    }
                                }
                                else
                                {
                                    // Scripted AI: Reimplement?
                                    //Globals.AIScriptManager.CallAIProcessSub(NpcManager.Npcs[map.Npc[x].NpcNum].AIScript, tickCount, map.MapNum, x);
                                }
                            }
                        }
                        //try and spawn something
                        if (map.NpcSpawnWait == null)
                        {
                            map.NpcSpawnWait = Core.GetTickCount();
                        }
                        if (Core.GetTickCount().Tick > map.NpcSpawnWait.Tick)
                        {
                            if (livingNpcs < map.MaxNpcs)
                            {
                                map.SpawnNpc(true);
                            }
                            map.NpcSpawnWait = new TickCount(map.NpcSpawnWait.Tick + map.NpcSpawnTime * 1000);
                        }
                    }
                }
                //lock (MapManager.ActiveMapLockObject) {
                bool shouldRemove = false;
                if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL))
                {
                    if (map.IsProcessingComplete())
                    {
                        shouldRemove = true;

                        for (int i = 1; i < 9; i++)
                        {
                            IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i);
                            if (borderingMap != null)
                            {
                                if (borderingMap.PlayersOnMap.Count > 0)
                                {
                                    shouldRemove = false;
                                }
                            }
                        }

                        if (shouldRemove)
                        {
                            MapManager.rwLock.EnterWriteLock();
                            try {
                                if (map.MapType == Enums.MapType.House)
                                {
                                    // Only save the map here when logging out - otherwise, the map is saved when the player is saved
                                    map.Save();
                                }
                                if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced))
                                {
                                    using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) {
                                        if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0)
                                        {
                                            DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID);
                                        }
                                        else
                                        {
                                            map.Save();
                                        }
                                    }
                                }

                                MapManager.UnsafeRemoveActiveMap(map.MapID);
                            } finally {
                                MapManager.rwLock.ExitWriteLock();
                            }
                        }
                    }
                }
                //}

                PacketHitList.MethodEnded(ref packetList);
            } catch (Exception ex) {
                Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "MapAIProcessor");
            }
        }