Beispiel #1
0
        public override void Execute(GameCommandTrigger trigger)
        {
            int mobId = trigger.Get <int>("id");

            if (NpcMetadataStorage.GetNpc(mobId) == null)
            {
                trigger.Session.Send(NoticePacket.Notice($"No MOB was found with the id: {mobId.ToString().Color(Color.DarkOliveGreen)}", NoticeType.Chat));
                return;
            }
            Mob mob = new Mob(mobId)
            {
                Animation = trigger.Get <short>("ani"),
                ZRotation = trigger.Get <short>("dir")
            };

            IFieldObject <Mob> fieldMob = trigger.Session.FieldManager.RequestFieldObject(mob);
            CoordF             coord    = trigger.Get <CoordF>("coord");

            if (coord == default)
            {
                fieldMob.Coord = trigger.Session.FieldPlayer.Coord;
            }
            else
            {
                fieldMob.Coord = coord;
            }
            trigger.Session.FieldManager.AddMob(fieldMob);
        }
Beispiel #2
0
        public short ZRotation; // In degrees * 10

        public Npc(int id)
        {
            NpcMetadata npc = NpcMetadataStorage.GetNpcMetadata(id);

            Id        = npc.Id;
            Animation = 255;
            Friendly  = npc.Friendly;
        }
Beispiel #3
0
        public short ZRotation; // In degrees * 10

        public Mob(int id)
        {
            NpcMetadata mob = NpcMetadataStorage.GetNpcMetadata(id);

            Id        = mob.Id;
            Animation = 255;
            Stats     = mob.Stats;
            Friendly  = mob.Friendly;
        }
    private static void HandleBeauty(GameSession session)
    {
        MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined

        if (portal is null)
        {
            return;
        }

        session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
        NpcMetadata npcTarget = NpcMetadataStorage.GetNpcMetadata(session.Player.NpcTalk.Npc.Id);

        session.Player.ShopId = npcTarget.ShopId;

        switch (npcTarget.ShopId)
        {
        case 500:                                                                                  // Dr Dixon
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
            break;

        case 501:     // Dr Zenko
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
            break;

        case 504:     // Rosetta
        case 509:     //Lolly
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
            break;

        case 505:     // Ren
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
            break;

        case 506:     // Douglas
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
            break;

        case 507:     // Mirror
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
            break;

        case 508:     // Paulie
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
            break;

        case 510:     // Mino
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
            break;
        }

        session.Send(UserMoveByPortalPacket.Move(session.Player.FieldPlayer, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
    }
Beispiel #5
0
    private static void HandleLoadShop(GameSession session, PacketReader packet)
    {
        int            npcId    = packet.ReadInt();
        BeautyCategory category = (BeautyCategory)packet.ReadByte();

        NpcMetadata beautyNpc = NpcMetadataStorage.GetNpcMetadata(npcId);

        if (beautyNpc == null)
        {
            return;
        }

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(beautyNpc.ShopId);

        if (beautyShop == null)
        {
            return;
        }

        session.Player.ShopId = beautyNpc.ShopId;

        if (beautyShop.BeautyCategory == BeautyCategory.Dye)
        {
            if (beautyShop.BeautyType == BeautyShopType.Dye)
            {
                session.Send(BeautyPacket.LoadDyeShop(beautyShop));
                return;
            }

            session.Send(BeautyPacket.LoadBeautyShop(beautyShop));
            return;
        }

        if (beautyShop.BeautyCategory == BeautyCategory.Save)
        {
            session.Send(BeautyPacket.LoadSaveShop(beautyShop));
            session.Send(BeautyPacket.InitializeSaves());
            session.Send(BeautyPacket.LoadSaveWindow());
            session.Send(BeautyPacket.LoadSavedHairCount((short)session.Player.HairInventory.SavedHair.Count));
            if (session.Player.HairInventory.SavedHair.Count != 0)
            {
                session.Player.HairInventory.SavedHair = session.Player.HairInventory.SavedHair.OrderBy(o => o.CreationTime).ToList();
                session.Send(BeautyPacket.LoadSavedHairs(session.Player.HairInventory.SavedHair));
            }

            return;
        }

        List <BeautyShopItem> beautyItems = DatabaseManager.BeautyShopItems.FindAllByShopIdAndGender(beautyShop.Id, session.Player.Gender);

        session.Send(BeautyPacket.LoadBeautyShop(beautyShop, beautyItems));
    }
Beispiel #6
0
        public short ZRotation; // In degrees * 10

        public Npc(int id)
        {
            NpcMetadata npc = NpcMetadataStorage.GetNpcMetadata(id);

            if (npc != null)
            {
                Id        = npc.Id;
                Animation = 255;
                Friendly  = npc.Friendly;
                Kind      = npc.Kind;
                ShopId    = npc.ShopId;
            }
        }
Beispiel #7
0
        public Mob(int id)
        {
            NpcMetadata mob = NpcMetadataStorage.GetNpcMetadata(id);

            if (mob != null)
            {
                Id         = mob.Id;
                Animation  = AnimationStorage.GetSequenceIdBySequenceName(mob.Model, "Walk_A"); //Walking animation as default
                Stats      = mob.Stats;
                Experience = mob.Experience;
                Friendly   = mob.Friendly;
            }
        }
Beispiel #8
0
        public static void HandleOpen(GameSession session, IFieldObject <Npc> npcFieldObject)
        {
            NpcMetadata metadata = NpcMetadataStorage.GetNpc(npcFieldObject.Value.Id);

            ShopMetadata shop = ShopMetadataStorage.GetShop(metadata.ShopId);

            if (shop == null)
            {
                Console.WriteLine($"Unknown shop ID: {metadata.ShopId}");
                return;
            }

            session.Send(ShopPacket.Open(shop));
            session.Send(ShopPacket.LoadProducts(shop.Items));
            session.Send(ShopPacket.Reload());
            session.Send(NpcTalkPacket.Respond(npcFieldObject, NpcType.Default, DialogType.None, 0));
        }
Beispiel #9
0
        public Mob(int id)
        {
            NpcMetadata mob = NpcMetadataStorage.GetNpcMetadata(id);

            if (mob != null)
            {
                Id           = mob.Id;
                Model        = mob.Model;
                Animation    = AnimationStorage.GetSequenceIdBySequenceName(Model, "Idle_A");
                StateActions = mob.StateActions;
                MoveRange    = mob.MoveRange;
                Stats        = mob.Stats;
                Experience   = mob.Experience;
                Friendly     = mob.Friendly;
                AI           = MobAIManager.GetAI(mob.AiInfo);
                State        = NpcState.Normal;
            }
        }
Beispiel #10
0
    public override void Execute(GameCommandTrigger trigger)
    {
        int mobId = trigger.Get <int>("id");

        if (NpcMetadataStorage.GetNpcMetadata(mobId) is null)
        {
            trigger.Session.Send(NoticePacket.Notice($"No MOB was found with the id: {mobId.ToString().Color(Color.DarkOliveGreen)}", NoticeType.Chat));
            return;
        }

        CoordF coord = trigger.Get <CoordF>("coord");

        if (coord == default)
        {
            coord = trigger.Session.Player.FieldPlayer.Coord;
        }

        trigger.Session.FieldManager.RequestMob(mobId, coord, CoordF.From(0.0f, 0.0f, trigger.Get <short>("dir")), trigger.Get <short>("ani"));
    }
Beispiel #11
0
    public void CreateMonster(int[] spawnPointIds, bool spawnAnimation, int arg3)
    {
        foreach (int spawnPointId in spawnPointIds)
        {
            MapEventNpcSpawnPoint spawnPoint = MapEntityMetadataStorage.GetMapEventNpcSpawnPoint(Field.MapId, spawnPointId);
            if (spawnPoint is null)
            {
                continue;
            }

            for (int i = 0; i < spawnPoint.Count; i++)
            {
                foreach (string npcId in spawnPoint.NpcIds)
                {
                    if (!int.TryParse(npcId, out int id))
                    {
                        continue;
                    }

                    short animation = -1;
                    if (spawnAnimation)
                    {
                        NpcMetadata npcMetadata = NpcMetadataStorage.GetNpcMetadata(id);
                        if (npcMetadata is null || !npcMetadata.StateActions.TryGetValue(NpcState.Normal, out (string, NpcAction, short)[] stateAction))
                        {
                            continue;
                        }

                        if (stateAction.Length == 0)
                        {
                            continue;
                        }

                        animation = AnimationStorage.GetSequenceIdBySequenceName(npcMetadata.NpcMetadataModel.Model, stateAction[0].Item1);
                    }

                    Npc npc = Field.RequestNpc(id, spawnPoint.Position, spawnPoint.Rotation, animation);
                    npc.SpawnPointId = spawnPointId;
                }
            }
        }
    }
Beispiel #12
0
        public static void HandleOpen(GameSession session, IFieldObject <Npc> npcFieldObject)
        {
            NpcMetadata metadata = NpcMetadataStorage.GetNpc(npcFieldObject.Value.Id);

            Shop shop = DatabaseManager.Shops.FindById(metadata.ShopId);

            if (shop == null)
            {
                Logger.Warn($"Unknown shop ID: {metadata.ShopId}");
                return;
            }

            session.Send(ShopPacket.Open(shop));
            foreach (ShopItem shopItem in shop.Items)
            {
                session.Send(ShopPacket.LoadProducts(shopItem));
            }
            session.Send(ShopPacket.Reload());
            session.Send(NpcTalkPacket.Respond(npcFieldObject, NpcType.Default, DialogType.None, 0));
            session.Player.ShopId = shop.Id;
        }
Beispiel #13
0
        public static List <NpcMetadata> SelectMobs(int difficulty, int minDifficulty, string[] tags)
        {
            // Look into optimizing this.
            HashSet <NpcMetadata> matchedNpcs = new HashSet <NpcMetadata>();

            foreach (string tag in tags)
            {
                foreach (NpcMetadata mob in NpcMetadataStorage.GetNpcsByMainTag(tag))
                {
                    if (mob.NpcMetadataBasic.Difficulty >= minDifficulty && mob.NpcMetadataBasic.Difficulty <= difficulty)
                    {
                        matchedNpcs.Add(mob);
                    }
                }
            }
            if (matchedNpcs.Count == 0)
            {
                matchedNpcs.Add(NpcMetadataStorage.GetNpc(21000001));
            }
            return(matchedNpcs.ToList());
        }
Beispiel #14
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            switch (function)
            {
            case 0:     // Cancel
                return;

            case 1:
                int objectId = packet.ReadInt();
                if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
                {
                    return;     // Invalid NPC
                }
                session.Player.NpcTalk = npc;
                // If NPC is a shop, load and open the shop
                if (npc.Value.IsShop())
                {
                    ShopHandler.HandleOpen(session, npc);
                    return;
                }
                else if (npc.Value.IsBank())
                {
                    session.Send(HomeBank.OpenBank());
                    return;
                }
                else if (npc.Value.IsBeauty())
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                    return;
                }
                // Stellar Chest: 11004215
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, 0));
                break;

            case 2:                                                                                                                 // Continue chat?
                int index = packet.ReadInt();                                                                                       // selection index

                if (session.Player.NpcTalk.Value.IsBeauty())                                                                        // This may need a cleaner method
                {
                    MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined
                    session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
                    NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Value.Id);

                    switch (npcTarget.ShopId)
                    {
                    case 500:                                                                                  // Dr Dixon
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
                        break;

                    case 501:         // Dr Zenko
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
                        break;

                    case 504:         // Rosetta
                    case 509:         //Lolly
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
                        break;

                    case 505:         // Ren
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
                        break;

                    case 506:         // Douglas
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
                        break;

                    case 507:         // Mirror
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
                        break;

                    case 508:         // Paulie
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
                        break;

                    case 510:         // Mino
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
                        break;
                    }
                    session.Send(UserMoveByPortalPacket.Move(session, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
                }
                session.Send(NpcTalkPacket.Close());
                session.Player.NpcTalk = null;
                break;
            }
        }
Beispiel #15
0
        private static void HandleRespond(GameSession session, PacketReader packet)
        {
            List <QuestStatus> npcQuests = new List <QuestStatus>();
            int objectId = packet.ReadInt();

            // Find if npc object id exists in field manager
            if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
            {
                return;
            }

            // Get all quests for this npc
            foreach (QuestStatus item in session.Player.QuestList.Where(x => !x.Completed))
            {
                if (npc.Value.Id == item.StartNpcId)
                {
                    npcQuests.Add(item);
                }
                if (item.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item))
                {
                    npcQuests.Add(item);
                }
            }
            session.Player.NpcTalk = new NpcTalk(npc.Value, npcQuests);
            ScriptLoader scriptLoader = new ScriptLoader($"Npcs/{npc.Value.Id}", session);

            // If NPC is a shop, load and open the shop
            if (npc.Value.IsShop())
            {
                ShopHandler.HandleOpen(session, npc);
                return;
            }
            else if (npc.Value.IsBank())
            {
                session.Send(HomeBank.OpenBank());
                return;
            }
            else if (npc.Value.IsBeauty())
            {
                NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Npc.Id);
                if (npcTarget.ShopId == 507) // mirror
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 0));
                    HandleBeauty(session);
                    return;
                }

                session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                return;
            }

            // Check if npc has an exploration quest
            QuestHelper.UpdateExplorationQuest(session, npc.Value.Id.ToString(), "talk_in");

            // If npc has quests, send quests and talk option
            if (npcQuests.Count != 0)
            {
                session.Player.NpcTalk.ScriptId = 0;
                session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, session.Player.NpcTalk.ScriptId));
                return;
            }

            ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id);

            if (!scriptMetadata.Options.Exists(x => x.Type == ScriptType.Script))
            {
                return;
            }

            int firstScriptId = GetFirstScriptId(scriptLoader, scriptMetadata);

            session.Player.NpcTalk.ScriptId = firstScriptId;

            Option option = scriptMetadata.Options.First(x => x.Id == firstScriptId);

            DialogType dialogType = DialogType.None;

            if (option.Contents[0].Goto.Count == 0)
            {
                dialogType = DialogType.Close1;
            }
            else
            {
                dialogType = DialogType.CloseNextWithDistractor;
            }

            session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk3, dialogType, firstScriptId));

            // If npc has buttonset roulette, send roulette id 13.
            // TODO: Send the correct roulette id
            if (scriptMetadata.Options.Any(x => x.ButtonSet == "roulette"))
            {
                session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "RouletteDialog", "13"));
            }
        }
Beispiel #16
0
 public Mob(int objectId, int mobId) : this(objectId, NpcMetadataStorage.GetNpcMetadata(mobId))
 {
 }
Beispiel #17
0
 public Npc(int objectId, int npcId) : this(objectId, NpcMetadataStorage.GetNpcMetadata(npcId))
 {
 }