コード例 #1
0
 public MapleQuestStatus(MapleQuest quest, MapleQuestStatusType status)
 {
     Quest          = quest;
     Status         = status;
     CompletionTime = DateTime.Now.GetTimeMilliseconds();
     if (status == MapleQuestStatusType.Started)
     {
         RegisterMobs();
     }
 }
コード例 #2
0
ファイル: MapleQuest.cs プロジェクト: uvbs/NeoMapleStory
        public static MapleQuest GetInstance(int id)
        {
            MapleQuest ret;

            if (!Quests.TryGetValue(id, out ret))
            {
                ret = new MapleQuest(id);
                Quests.Add(id, ret);
            }
            return(ret);
        }
コード例 #3
0
        public bool Check(MapleCharacter c, int?npcid)
        {
            if (RequirData == null)
            {
                return(true);
            }
            switch (Type)
            {
            case MapleQuestRequirementType.Job:
                foreach (var jobEntry in RequirData.Children)
                {
                    var jobid = MapleDataTool.GetShort(jobEntry, -1);
                    if (jobid == -1)
                    {
                        return(true);
                    }
                    if (c.Job == MapleJob.GetByJobId(jobid) || c.GmLevel > 0)
                    {
                        return(true);
                    }
                }
                return(false);

            case MapleQuestRequirementType.Quest:
                foreach (var questEntry in RequirData.Children)
                {
                    var qid = MapleDataTool.GetInt(questEntry.GetChildByPath("id"), -1);
                    if (qid == -1)
                    {
                        return(true);
                    }
                    var q = c.GetQuest(MapleQuest.GetInstance(qid));
                    if (q == null &&
                        MapleDataTool.GetInt(questEntry.GetChildByPath("state"), 0) ==
                        (int)MapleQuestStatusType.NotStarted)
                    {
                        continue;
                    }
                    if (q == null || (int)q.Status != MapleDataTool.GetInt(questEntry.GetChildByPath("state"), 0))
                    {
                        return(false);
                    }
                }
                return(true);

            case MapleQuestRequirementType.Item:
                var ii = MapleItemInformationProvider.Instance;
                foreach (var itemEntry in RequirData.Children)
                {
                    var itemId = MapleDataTool.GetInt(itemEntry.GetChildByPath("id"), -1);
                    if (itemId == -1)
                    {
                        return(true);
                    }
                    short quantity = 0;
                    var   iType    = ii.GetInventoryType(itemId);
                    foreach (var item in c.Inventorys[iType.Value].ListById(itemId))
                    {
                        quantity += item.Quantity;
                    }
                    if (quantity < MapleDataTool.GetInt(itemEntry.GetChildByPath("count"), 0) ||
                        MapleDataTool.GetInt(itemEntry.GetChildByPath("count"), 0) <= 0 && quantity > 0)
                    {
                        return(false);
                    }
                }
                return(true);

            case MapleQuestRequirementType.MinLevel:
                return(c.Level >= MapleDataTool.GetInt(RequirData, 1));

            case MapleQuestRequirementType.MaxLevel:
                return(c.Level <= MapleDataTool.GetInt(RequirData, 200));

            case MapleQuestRequirementType.EndDate:
                var timeStr = MapleDataTool.GetString(RequirData, null);
                if (timeStr == null)
                {
                    return(true);
                }
                var cal = new DateTime(int.Parse(timeStr.Substring(0, 4)), int.Parse(timeStr.Substring(4, 6)),
                                       int.Parse(timeStr.Substring(6, 8)), int.Parse(timeStr.Substring(8, 10)), 0, 0);
                return(cal.GetTimeMilliseconds() > DateTime.Now.GetTimeMilliseconds());

            case MapleQuestRequirementType.Mob:
                foreach (var mobEntry in RequirData.Children)
                {
                    var mobId   = MapleDataTool.GetInt(mobEntry.GetChildByPath("id"), -1);
                    var killReq = MapleDataTool.GetInt(mobEntry.GetChildByPath("count"), 1);
                    if (mobId == -1)
                    {
                        return(true);    // let the thing slide I guess
                    }
                    if (c.GetQuest(m_mQuest).GetMobKills(mobId) < killReq)
                    {
                        return(false);
                    }
                }
                return(true);

            case MapleQuestRequirementType.MonsterBook:
                //return c.getMonsterBook().getTotalCards() >= MapleDataTool.GetInt(getData());
                return(false);

            case MapleQuestRequirementType.Npc:
                return(npcid == null || npcid == MapleDataTool.GetInt(RequirData));

            case MapleQuestRequirementType.FieldEnter:
                if (RequirData == null)
                {
                    return(true);
                }
                var zeroField = RequirData.GetChildByPath("0");
                if (zeroField != null)
                {
                    return(MapleDataTool.GetInt(zeroField) == c.Map.MapId);
                }
                return(false);

            case MapleQuestRequirementType.Interval:
                return(c.GetQuest(m_mQuest).Status != MapleQuestStatusType.Completed ||
                       c.GetQuest(m_mQuest).CompletionTime <=
                       DateTime.Now.GetTimeMilliseconds() - MapleDataTool.GetInt(RequirData) * 60 * 1000);

            //case  MapleQuestRequirementType.PET:
            //case  MapleQuestRequirementType.MIN_PET_TAMENESS:
            case MapleQuestRequirementType.CompleteQuest:
                if (c.GetNumQuest() >= MapleDataTool.GetInt(RequirData))
                {
                    return(true);
                }
                return(false);

            default:
                return(true);
            }
        }
コード例 #4
0
 public MapleQuestRequirement(MapleQuest quest, MapleQuestRequirementType type, IMapleData data)
 {
     Type       = type;
     RequirData = data;
     m_mQuest   = quest;
 }
コード例 #5
0
        /** Creates a new instance of MapleQuestAction */

        public MapleQuestAction(MapleQuestActionType type, IMapleData data, MapleQuest quest)
        {
            Type    = type;
            Data    = data;
            m_quest = quest;
        }
コード例 #6
0
        public void Run(MapleCharacter c, int?extSelection)
        {
            MapleQuestStatus status;

            switch (Type)
            {
            case MapleQuestActionType.Exp:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.GainExp(MapleDataTool.GetInt(Data) * c.Client.ChannelServer.ExpRate, true, true);
                break;

            case MapleQuestActionType.Item:
                var ii    = MapleItemInformationProvider.Instance;
                var props = new Dictionary <int, int>();
                foreach (var iEntry in Data.Children)
                {
                    if (iEntry.GetChildByPath("prop") != null &&
                        MapleDataTool.GetInt(iEntry.GetChildByPath("prop")) != -1 && CanGetItem(iEntry, c))
                    {
                        for (var i = 0; i < MapleDataTool.GetInt(iEntry.GetChildByPath("prop")); i++)
                        {
                            props.Add(props.Count, MapleDataTool.GetInt(iEntry.GetChildByPath("id")));
                        }
                    }
                }
                var selection = 0;
                var extNum    = 0;
                if (props.Any())
                {
                    props.TryGetValue((int)(Randomizer.NextDouble() * props.Count), out selection);
                }
                foreach (var iEntry in Data.Children)
                {
                    if (!CanGetItem(iEntry, c))
                    {
                        continue;
                    }
                    if (iEntry.GetChildByPath("prop") != null)
                    {
                        if (MapleDataTool.GetInt(iEntry.GetChildByPath("prop")) == -1)
                        {
                            if (extSelection.HasValue && extSelection.Value != extNum++)
                            {
                                continue;
                            }
                        }
                        else if (MapleDataTool.GetInt(iEntry.GetChildByPath("id")) != selection)
                        {
                            continue;
                        }
                    }
                    if (MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0) < 0)
                    {
                        // remove items

                        var itemId   = MapleDataTool.GetInt(iEntry.GetChildByPath("id"));
                        var iType    = ii.GetInventoryType(itemId);
                        var quantity = (short)(MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0) * -1);
                        try
                        {
                            //MapleInventoryManipulator.removeById(c.Client, iType, itemId, quantity, true, false);
                        }
                        catch
                        {
                            Console.WriteLine("Completing a quest without meeting the requirements");
                        }
                        c.Client.Send(PacketCreator.GetShowItemGain(itemId,
                                                                    (short)MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0), true));
                    }
                    else
                    {
                        // add items

                        var itemId   = MapleDataTool.GetInt(iEntry.GetChildByPath("id"));
                        var quantity = (short)MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0);
                        var logInfo  = new StringBuilder(c.Name);
                        logInfo.Append(" received ");
                        logInfo.Append(quantity);
                        logInfo.Append(" as reward from a quest");
                        // MapleInventoryManipulator.addById(c.Client, itemId, quantity, logInfo.ToString(), null, -1);
                        c.Client.Send(PacketCreator.GetShowItemGain(itemId, quantity, true));
                    }
                }
                break;

            case MapleQuestActionType.Nextquest:
                status = c.GetQuest(m_quest);
                var nextQuest = MapleDataTool.GetInt(Data);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.Client.Send(PacketCreator.UpdateQuestFinish((short)m_quest.GetQuestId(), status.Npcid,
                                                              (short)nextQuest));
                MapleQuest.GetInstance(nextQuest).Start(c, status.Npcid);
                break;

            case MapleQuestActionType.Meso:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.GainMeso(MapleDataTool.GetInt(Data), true, false, true);
                break;

            case MapleQuestActionType.Quest:
                foreach (var qEntry in Data)
                {
                    var questid = MapleDataTool.GetInt(qEntry.GetChildByPath("id"));
                    var stat    = MapleDataTool.GetInt(qEntry.GetChildByPath("state"), 0);
                    c.UpdateQuest(new MapleQuestStatus(MapleQuest.GetInstance(questid), (MapleQuestStatusType)stat));
                }
                break;

            case MapleQuestActionType.Skill:
                foreach (var sEntry in Data)
                {
                    var skillid        = MapleDataTool.GetInt(sEntry.GetChildByPath("id"));
                    var skillLevel     = (byte)MapleDataTool.GetInt(sEntry.GetChildByPath("skillLevel"));
                    var masterLevel    = (byte)MapleDataTool.GetInt(sEntry.GetChildByPath("masterLevel"));
                    var skillObject    = SkillFactory.GetSkill(skillid);
                    var shouldLearn    = false;
                    var applicableJobs = sEntry.GetChildByPath("job");
                    foreach (var applicableJob in applicableJobs)
                    {
                        var job = MapleJob.GetByJobId(MapleDataTool.GetShort(applicableJob));
                        if (c.Job == job)
                        {
                            shouldLearn = true;
                            break;
                        }
                    }
                    if (skillObject.IsBeginnerSkill)
                    {
                        shouldLearn = true;
                    }
                    skillLevel  = Math.Max(skillLevel, c.GetSkillLevel(skillObject));
                    masterLevel = Math.Max(masterLevel, skillObject.MaxLevel);
                    if (shouldLearn)
                    {
                        c.ChangeSkillLevel(skillObject, skillLevel, masterLevel);
                        c.DropMessage(
                            $"你已获得 {SkillFactory.GetSkillName(skillid)} 当前等级 {skillLevel} 最高等级 {masterLevel}");
                    }
                }
                break;

            case MapleQuestActionType.Fame:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.Fame += MapleDataTool.GetShort(Data);
                c.UpdateSingleStat(MapleStat.Fame, c.Fame);
                var fameGain = MapleDataTool.GetInt(Data);
                c.Client.Send(PacketCreator.GetShowFameGain(fameGain));
                break;

            case MapleQuestActionType.Buff:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                var mii = MapleItemInformationProvider.Instance;
                //mii.GetItemEffect(MapleDataTool.GetInt(data)).applyTo(c);
                break;

            case MapleQuestActionType.Petskill:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                var flag = MapleDataTool.GetInt("petskill", Data);
                //c.getPet(0).setFlag((byte)(c.getPet(0).getFlag() | InventoryConstants.Items.Flags.getFlagByInt(flag)));
                break;

            default:
                break;
            }
        }