Exemple #1
0
        public override void OnActorEnterPortal(Actor aActor)
        {
            if (aActor.ActorType == ActorType.PC)
            {
                bool    warped = false;
                ActorPC pc     = (ActorPC)aActor;
                foreach (PortalTrigger i in portal.PortalTriggers)
                {
                    if (i.Quest > 0)
                    {
                        if (pc.Quests.ContainsKey(i.Quest))
                        {
                            if (i.Step == pc.Quests[i.Quest].NextStep - 1 || i.Step == -1 || (i.Step == 0 && i.Step == pc.Quests[i.Quest].Step))
                            {
                                int abs = Math.Abs(i.Dir - pc.Dir);
                                if (abs <= 90 || abs > 270)
                                {
                                    Map.Map map = Map.MapManager.Instance.GetMap(i.MapTarget, pc.CharID, pc.PartyID);
                                    if (map != null)
                                    {
                                        warped = true;
                                        pc.Client().Map.SendActorToMap(pc, map, pc.X, pc.Y, pc.Z);
                                    }
                                    else
                                    {
                                        Logger.Log.Warn(string.Format("MapID:{0} isn't defined!", i.MapTarget));
                                    }

                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Map.Map map = Map.MapManager.Instance.GetMap(i.MapTarget, pc.CharID, pc.PartyID);
                        if (map != null)
                        {
                            warped = true;
                            pc.Client().Map.SendActorToMap(pc, map, pc.X, pc.Y, pc.Z);
                        }
                    }
                }
                if (!warped)
                {
                    pc.Client().SendPortalNotWarp();
                }
            }
        }
Exemple #2
0
 public void ProcessQuest(ActorPC pc, uint mapID, bool hasCoordinate = false)
 {
     foreach (ushort questID in pc.Quests.Keys)
     {
         Quest quest = pc.Quests[questID];
         if (items.ContainsKey(questID))
         {
             QuestDetail detail = items[questID];
             if (detail.Steps.ContainsKey(quest.NextStep))
             {
                 QuestStep s = detail.Steps[quest.NextStep];
                 foreach (QuestTarget t in s.Targets)
                 {
                     if (t.TargetType == StepTargetType.Map && t.TargetIDs.Contains(mapID) && ((hasCoordinate && t.HasCoordinate) || (!hasCoordinate && !t.HasCoordinate)))
                     {
                         ProcessQuestSub(pc, quest, s, detail);
                         QuestArgument arg = new QuestArgument()
                         {
                             Player = pc,
                             Quest  = quest,
                             Step   = quest.Step
                         };
                         pc.Client().Map.SendEventToAllActorsWhoCanSeeActor(MapEvents.QUEST_UPDATE, arg, pc, false);
                     }
                 }
             }
         }
     }
 }
 private void SendLevelUp(ActorPC pc, uint numLevels)
 {
     for (int i = pc.Level + 1; i <= pc.Level + numLevels; i++)
     {
         foreach (uint j in items[(uint)i].JobStatus[pc.Job].Skills)
         {
             Skills.SkillManager.Instance.PlayerAddSkill(pc, j, true);
         }
     }
     pc.Level += (byte)numLevels;
     PC.Status.CalcStatus(pc);
     Interlocked.Exchange(ref pc.HP, pc.MaxHP);
     pc.Client().SendPlayerStats();
     pc.Client().SendPlayerLevelUp();
     Logger.Log.Info(pc.Name + " gained " + numLevels + "x levels");
 }
Exemple #4
0
        public void PlayerAddSkill(ActorPC pc, uint skillID, bool sendPacket)
        {
            if (SkillFactory.Instance.Items.ContainsKey(skillID))
            {
                Skill skill = new Skill(SkillFactory.Instance[skillID]);
                pc.Skills[skillID] = skill;
                foreach (uint i in skill.BaseData.RelatedSkills)
                {
                    if (i == skillID || pc.Skills.ContainsKey(i))
                    {
                        continue;
                    }

                    if (SkillFactory.Instance.Items.ContainsKey(i))
                    {
                        Skill dummy = new Skill(SkillFactory.Instance[i])
                        {
                            Dummy = true
                        };
                        pc.Skills[i] = dummy;
                    }
                }
                if (sendPacket)
                {
                    pc.Client().SendSkillAdd(skillID);
                }
            }
            else
            {
                Logger.Log.Debug(string.Format("SkillID:{0} not found!", skillID));
            }
        }
        public void OnPartyReplyInvitation(CM_PARTY_REPLY_INVITATION p)
        {
            foreach (KeyValuePair <ActorPC, ulong> i in partyInviteTable)
            {
                if (i.Value == p.PartyID)
                {
                    Common.Party.Party newParty;
                    ActorPC            partyTarget = i.Key;
                    if (chara.Party == null)
                    {
                        if (partyTarget.Party != null)
                        {
                            newParty = partyTarget.Party;
                            if (newParty.Members.Count < 5)
                            {
                                newParty.Members.Add(chara);
                                chara.Party   = newParty;
                                chara.PartyID = i.Value;
                            }
                            else
                            {
                                //TODO: party full
                                partyInviteTable.TryRemove(i.Key, out ulong removed);
                                GameSession target = partyTarget.Client();
                                target.partyInviteTable.TryRemove(chara, out removed);
                            }
                        }
                        else
                        {
                            newParty = PartyManager.Instance.NewParty(i.Value, partyTarget, chara);
                        }

                        foreach (ActorPC pc in newParty.Members)
                        {
                            GameSession client = pc.Client();
                            client?.SendPartyInfo();
                        }
                    }
                    {
                        partyInviteTable.TryRemove(i.Key, out ulong removed);
                        GameSession target = partyTarget.Client();
                        target.partyInviteTable.TryRemove(chara, out removed);
                    }
                }
            }
        }
        public void CheckExp(ActorPC pc)
        {
            uint lvlDelta = 0;

            lvlDelta = GetLevelDelta(pc.Level, pc.Exp, true);
            if (lvlDelta > 0)
            {
                SendLevelUp(pc, lvlDelta);
            }
            else
            {
                Network.Client.GameSession client = pc.Client();
                client?.SendPlayerEXP();
            }
        }
 public void OnPartyReplyInvitationDenied(CM_PARTY_REPLY_INVITATION_DENIED p)
 {
     foreach (KeyValuePair <ActorPC, ulong> i in partyInviteTable)
     {
         if (i.Value == p.PartyID)
         {
             ActorPC partyTarget = i.Key;
             if (partyTarget != null)
             {
                 partyInviteTable.TryRemove(i.Key, out ulong removed);
                 GameSession target = partyTarget.Client();
                 target.partyInviteTable.TryRemove(chara, out removed);
             }
         }
     }
 }
Exemple #8
0
 public void ProcessQuest(ActorPC pc, ushort questID, byte step, Quest quest)
 {
     if (items.ContainsKey(questID))
     {
         QuestDetail detail = items[questID];
         if (detail.Steps.ContainsKey(step))
         {
             QuestStep s = detail.Steps[step];
             foreach (QuestTarget t in s.Targets)
             {
                 if (t.TargetType == StepTargetType.None)
                 {
                     if (quest == null)
                     {
                         quest = new Quest()
                         {
                             QuestID = questID
                         };
                         if (pc.Quests.ContainsKey(questID))
                         {
                             return;
                         }
                         else
                         {
                             pc.Quests[questID] = quest;
                         }
                     }
                     ProcessQuestSub(pc, quest, s, detail);
                     QuestArgument arg = new QuestArgument()
                     {
                         Player = pc,
                         Quest  = quest,
                         Step   = quest.Step
                     };
                     pc.Client().Map.SendEventToAllActorsWhoCanSeeActor(MapEvents.QUEST_UPDATE, arg, pc, false);
                 }
             }
         }
     }
 }
Exemple #9
0
 protected void HoldItemCancel(ActorPC pc, uint item)
 {
     Network.Client.GameSession client = pc.Client();
     client?.SendHoldItemCancel(item);
 }
Exemple #10
0
        public void ProcessQuest(ActorPC pc, ActorMapObj obj)
        {
            ulong objID = obj.ToULong();

            if (mapObjectMapping.ContainsKey(objID))
            {
                foreach (uint questID in mapObjectMapping[objID].Keys)
                {
                    if (items.ContainsKey(questID))
                    {
                        QuestDetail detail = items[questID];
                        byte        step   = mapObjectMapping[objID][questID];
                        Quest       quest;
                        if (detail.Steps.ContainsKey(step))
                        {
                            QuestStep s     = detail.Steps[step];
                            byte      index = 0;
                            foreach (QuestTarget t in s.Targets)
                            {
                                if (t.TargetType == StepTargetType.MapObject && t.TargetIDs.Contains(obj.ObjectID) && t.TargetMapID == obj.MapID)
                                {
                                    if (s.DropItem > 0)
                                    {
                                        if (pc.HoldingItem != null && s.DropItem == pc.HoldingItem.ObjectID)
                                        {
                                            HoldItemCancel(pc, s.DropItem);
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }

                                    if (pc.Quests.ContainsKey((ushort)questID))
                                    {
                                        quest = pc.Quests[(ushort)questID];
                                    }
                                    else
                                    {
                                        continue;
                                    }

                                    bool finished = ProcessTarget(pc, quest, s, t, t.SpecifyIndex >= 0 ? t.SpecifyIndex : index);
                                    if (finished)
                                    {
                                        ProcessQuestSub(pc, quest, s, detail, 0);
                                    }
                                    else
                                    {
                                        UpdateQuest(pc, quest);
                                    }

                                    QuestArgument arg = new QuestArgument()
                                    {
                                        Player = pc,
                                        Quest  = quest,
                                        Step   = quest.Step
                                    };
                                    pc.Client().Map.SendEventToAllActorsWhoCanSeeActor(MapEvents.QUEST_UPDATE, arg, pc, false);
                                }
                                index++;
                            }
                        }
                    }
                }
            }
        }
Exemple #11
0
 protected void FinishQuest(ActorPC pc, Quest quest)
 {
     Network.Client.GameSession client = pc.Client();
     client?.FinishQuest(quest);
 }
Exemple #12
0
 protected void NextQuest(ActorPC pc, ushort next)
 {
     Network.Client.GameSession client = pc.Client();
     client?.SendNextQuest(next);
 }
Exemple #13
0
 protected void UpdateQuest(ActorPC pc, Quest quest)
 {
     Network.Client.GameSession client = pc.Client();
     client?.SendQuestUpdate(quest);
 }
Exemple #14
0
        private void ProcessQuestSub(ActorPC pc, Quest quest, QuestStep s, QuestDetail detail, int selection = 0)
        {
            if (pc.EventHandler == null)
            {
                return;
            }

            if (s.NextStep > 0 || s.Finish)
            {
                quest.Step = s.StepID;
                if (!s.Finish)
                {
                    quest.StepStatus = s.StepStatus;
                    quest.NextStep   = s.NextStep;
                    quest.Flag1      = s.Flag1;
                    quest.Flag2      = s.Flag2;
                    quest.Flag3      = s.Flag3;
                    UpdateQuest(pc, quest);
                }
                else
                {
                    FinishQuest(pc, quest);
                }
            }
            for (int i = 0; i < quest.Count.Length; i++)
            {
                quest.Count[i] = 0;
            }
            if (s.HoldItem != 0)
            {
                HoldItem(pc, s.HoldItem);
            }

            foreach (uint i in s.TakeItems[pc.Job].Keys)
            {
                ushort count = s.TakeItems[pc.Job][i];
                pc.Client().RemoveItem(i, count);
            }
            foreach (uint i in s.TakeItems[Job.None].Keys)
            {
                ushort count = s.TakeItems[Job.None][i];
                pc.Client().RemoveItem(i, count);
            }
            foreach (uint i in s.GiveItems[pc.Job].Keys)
            {
                ((ActorEventHandlers.PCEventHandler)pc.EventHandler).Client.AddItem(i, s.GiveItems[pc.Job][i]);
            }
            foreach (uint i in s.GiveItems[Job.None].Keys)
            {
                ((ActorEventHandlers.PCEventHandler)pc.EventHandler).Client.AddItem(i, s.GiveItems[Job.None][i]);
            }
            foreach (uint i in s.LearnSkills[pc.Job])
            {
                SkillManager.Instance.PlayerAddSkill(pc, i, true);
            }
            foreach (uint i in s.LearnSkills[Job.None])
            {
                ((ActorEventHandlers.PCEventHandler)pc.EventHandler).Client.SendSkillAdd(i);
                pc.Skills[i] = new Skill(SkillFactory.Instance[i]);
            }
            Map.Map map = MapManager.Instance.GetMap(pc.MapInstanceID);
            foreach (NPC.SpawnData i in s.Spawns)
            {
                Scripting.Utils.SpawnNPC(map, i.NpcID, i.AppearEffect, i.X, i.Y, i.Z, i.Dir, i.Motion);
            }
            {
                Dictionary <uint, int> rewardOptions = new Dictionary <uint, int>();

                if (s.RewardOptions[pc.Job].Count > 0)
                {
                    rewardOptions = s.RewardOptions[pc.Job];
                }
                else
                {
                    rewardOptions = s.RewardOptions[Job.None];
                }

                if (rewardOptions.Count > 0)
                {
                    if (selection < rewardOptions.Count)
                    {
                        KeyValuePair <uint, int> pair = rewardOptions.ToList()[selection];
                        pc.Client().AddItem(pair.Key, (ushort)pair.Value);
                    }
                }
            }
            if (s.Exp > 0)
            {
                ExperienceManager.Instance.ApplyExp(pc, s.Exp);
            }
            if (s.Gold > 0)
            {
                Interlocked.Add(ref pc.Gold, s.Gold);
                pc.Client().SendPlayerGold();
            }
            if (s.CutScene > 0)
            {
                pc.Client().SendQuestCutScene(s.CutScene);
            }
            if (s.TeleportMapID > 0)
            {
                map = MapManager.Instance.GetMap(s.TeleportMapID, pc.CharID, pc.PartyID);
                pc.MapChangeCutScene   = s.TeleportCutscene;
                pc.MapChangeCutSceneU1 = s.TeleportU1;
                pc.MapChangeCutSceneU2 = s.TeleportU2;
                if (s.X != 0 && s.Y != 0 && s.Z != 0)
                {
                    pc.Client().Map.SendActorToMap(pc, map, s.X, s.Y, s.Z);
                }
                else
                {
                    pc.Client().Map.SendActorToMap(pc, map, pc.X, pc.Y, pc.Z);
                }
            }
            if (s.Finish)
            {
                if (detail.NextQuest[pc.Job] != 0)
                {
                    NextQuest(pc, (ushort)detail.NextQuest[pc.Job]);
                }
                else if (detail.NextQuest[Job.None] != 0)
                {
                    NextQuest(pc, (ushort)detail.NextQuest[Job.None]);
                }
            }
        }
 public CombatStatusTask(int duration, ActorPC actor)
     : base(duration, duration, "CombatStatusTask")
 {
     client = actor.Client();
 }
 public HPRegenerationTask(ActorPC actor)
     : base(0, 1000, "HPRegeneration")
 {
     client = actor.Client();
 }
Exemple #17
0
        public void ProcessQuest(ActorPC pc, ushort questID, byte step, Quest quest, ActorNPC npc, bool isLoot = false, bool isHunt = false, int selection = 0, bool party = false)
        {
            if (pc.Party != null && (isLoot || isHunt) && !party)
            {
                foreach (ActorPC i in pc.Party.Members)
                {
                    if (i != pc && !i.Offline && pc.MapInstanceID == i.MapInstanceID && pc.DistanceToActor(pc) < 200)
                    {
                        if (i.Quests.TryGetValue(questID, out Quest q))
                        {
                            ProcessQuest(i, questID, step, q, npc, isLoot, isHunt, selection, true);
                        }
                    }
                }
            }
            if (items.ContainsKey(questID))
            {
                QuestDetail detail = items[questID];
                if (pc.Quests.ContainsKey(questID) && detail.Steps.ContainsKey(pc.Quests[questID].NextStep))
                {
                    QuestStep s     = detail.Steps[pc.Quests[questID].NextStep];
                    byte      index = 0;
                    foreach (QuestTarget t in s.Targets)
                    {
                        if (((t.TargetType == StepTargetType.NPC && !isLoot) || (isLoot && t.TargetType == StepTargetType.Loot)) && t.TargetIDs.Contains(npc.NpcID))
                        {
                            if (s.DropItem > 0 && !isHunt && !isLoot)
                            {
                                if (pc.HoldingItem != null && s.DropItem == pc.HoldingItem.ObjectID)
                                {
                                    HoldItemCancel(pc, s.DropItem);
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (quest == null)
                            {
                                quest = new Quest()
                                {
                                    QuestID = questID
                                };
                                if (pc.Quests.ContainsKey(questID))
                                {
                                    return;
                                }
                                else
                                {
                                    pc.Quests[questID] = quest;
                                }
                            }
                            bool finished = ProcessTarget(pc, quest, s, t, t.SpecifyIndex >= 0 ? t.SpecifyIndex : index);

                            if (finished)
                            {
                                ProcessQuestSub(pc, quest, s, detail, selection);
                            }
                            else
                            {
                                UpdateQuest(pc, quest);
                            }

                            QuestArgument arg = new QuestArgument()
                            {
                                Player    = pc,
                                OriginNPC = npc.NpcID,
                                Quest     = quest,
                                Step      = quest.Step
                            };
                            pc.Client().Map.SendEventToAllActorsWhoCanSeeActor(MapEvents.QUEST_UPDATE, arg, pc, false);
                        }
                        index++;
                    }
                }
            }
        }
Exemple #18
0
        public void SkillActivate(SkillArg arg)
        {
            ActorPC pc = arg.Caster as ActorPC;

            arg.Caster.Status.CastingSkill = false;
            if (pc != null && arg.Skill.BaseData.MovementLockOnAction > 0)
            {
                SkillHandlers.Common.Additions.MovementLock mLock = new SkillHandlers.Common.Additions.MovementLock(pc.Client(), arg.Skill.BaseData.MovementLockOnAction);
                mLock.Activate();
            }
            if (arg.Caster.Status.Dead)
            {
                return;
            }

            arg.Caster.Status.LastSkillID = arg.Skill.ID;
            if (!arg.Caster.Status.Dead && !arg.Caster.Status.Down)
            {
                HandleSkillCastFinish(arg);
                BroadcastSkillCast(arg, SkillMode.Activate);
                HandleSkillActivate(arg);
            }

            if (pc != null)
            {
                int duration = arg.AffectedActors.Count > 0 ? 30000 : 5000;
                if (pc.Tasks.TryGetValue("CombatStatusTask", out Task task))
                {
                    if (task.DueTime < duration)
                    {
                        task.DueTime = duration;
                    }
                    task.Activate();
                }
                else
                {
                    Tasks.Player.CombatStatusTask ct = new Tasks.Player.CombatStatusTask(duration, pc);
                    pc.Tasks["CombatStatusTask"] = ct;
                    ct.Activate();
                }
            }
            arg.ActivationIndex++;
            if (arg.Skill.BaseData.Duration <= 0)
            {
                BroadcastSkillCast(arg, SkillMode.End);
            }

            if (arg.ActivationIndex < arg.Skill.BaseData.ActivationTimes.Count)
            {
                arg.Caster.Status.CastingSkill = true;
                SkillCastTask task = new SkillCastTask(arg.Skill.BaseData.ActivationTimes[arg.ActivationIndex - 1], arg.Caster, arg);
                arg.Caster.Tasks["SkillCast"] = task;
                task.Activate();
            }
            else
            {
                if (arg.Skill.BaseData.CoolDown != 0)
                {
                    arg.Skill.CoolDownEndTime = DateTime.Now.AddMilliseconds(arg.Skill.BaseData.CoolDown);
                }

                //if (arg.Skill.BaseData.ActivationTimes.Count < arg.ActivationIndex)
                //{
                //    Logger.Log.Debug($"ActivationTimes for skill:{arg.Skill.ID} is smaller than index:{arg.ActivationIndex}");
                //}
                if (arg.Caster.ActorType == ActorType.NPC)
                {
                    arg.Caster.Status.SkillCooldownEnd = DateTime.Now.AddMilliseconds(arg.Skill.BaseData.ActivationTimes.Count > 0 && arg.Skill.BaseData.ActivationTimes.Count > (arg.ActivationIndex - 1) ? arg.Skill.BaseData.ActivationTimes[arg.ActivationIndex - 1] : 500);
                }
                else
                {
                    arg.Caster.Status.SkillCooldownEnd = DateTime.Now.AddMilliseconds(100);//TODO: Use real data
                }
            }
        }
Exemple #19
0
 public MPRegenerationTask(ActorPC actor)
     : base(0, 3000, "MPRegeneration")
 {
     client = actor.Client();
 }