public static void UpdateEnemyInfo(ActorPC pc, uint MobID, bool maploded) { SagaDB.Quest.Quest quest = GetActiveQuest(pc); UpdateEnemyInfoSub(pc, MobID, quest, maploded); quest = GetActivePersonalQuest(pc); UpdateEnemyInfoSub(pc, MobID, quest, maploded); }
public void ProcessQuest(ActorPC pc, Npc npc, SagaDB.Quest.Quest quest) { this.Functable = npc.Functable; this.I = npc.Actor; this.ID = npc.ID; this.map = npc.Map; this.MapName = npc.MapName; this.Name = npc.Name; this.PersonalQuests = npc.PersonalQuests; this.PersonalQuesttable = npc.PersonalQuesttable; this.Questtable = npc.Questtable; this.SavePoint = npc.SavePoint; this.SupplyMatrials = npc.SupplyMatrials; this.SupplyMenuID = npc.SupplyMenuID; this.SupplyProducts = npc.SupplyProducts; this.Type = npc.Type; foreach (SagaDB.Quest.Step i in quest.Steps.Values) { if (i.Status == 1) { if (handlers.ContainsKey(i.ID)) { handlers[i.ID].Invoke(pc); } } } }
public static byte GetQuestStepStatus(ActorPC pc, uint id, uint step) { if (id == 0 || step == 0) { return(0); } if (pc.QuestTable.ContainsKey(id) == false) { if (!pc.PersonalQuestTable.ContainsKey(id)) { return(0); } else { SagaDB.Quest.Quest quest2 = pc.PersonalQuestTable[id]; if (quest2.Steps.ContainsKey(step) == false) { return(0); } SagaDB.Quest.Step step3 = quest2.Steps[step]; return(step3.Status); } } SagaDB.Quest.Quest quest = pc.QuestTable[id]; if (quest.Steps.ContainsKey(step) == false) { return(0); } SagaDB.Quest.Step step2 = quest.Steps[step]; return(step2.Status); }
public static void UpdateQuestItem(ActorPC pc, bool maploaded) { SagaDB.Quest.Quest quest = GetActiveQuest(pc); UpdateQuestItemSub(pc, quest, maploaded); quest = GetActivePersonalQuest(pc); UpdateQuestItemSub(pc, quest, maploaded); }
public void OnQuestConfirmCancel(Packets.Client.QuestConfirmCancel p) { this.QuestConfirm = false; uint QID = p.GetQuestID(); SagaDB.Quest.Quest quest = Quest.QuestsManager.GetActiveQuest(this.Char); if (QID != 0 && quest != null) { if (QID == quest.ID) { MapServer.charDB.DeleteQuest(this.Char, this.Char.QuestTable[QID]); this.Char.QuestTable.Remove(QID); this.SendQuestInfo(); } } quest = Quest.QuestsManager.GetActivePersonalQuest(this.Char); if (QID != 0 && quest != null) { if (QID == quest.ID) { MapServer.charDB.DeleteQuest(this.Char, this.Char.PersonalQuestTable[QID]); this.Char.PersonalQuestTable.Remove(QID); this.SendQuestInfo(); } } }
public override void OnDie() { base.OnDie(); if (delay != -1) { respawnTask.Activate(); } corpsetask.Activate(); ai.Pause(); if (this.map.GetActor(this.timeSignature.actorID) != null) { ActorPC pc = (ActorPC)this.map.GetActor(this.timeSignature.actorID); ActorEventHandlers.PC_EventHandler eh = (SagaMap.ActorEventHandlers.PC_EventHandler)pc.e; Packet p = new Packet();//don't know its name,maybe for some animation. p.data = new byte[9]; p.ID = 0x060E; p.PutUInt(this.Actor.id, 4); p.PutByte(4, 8); eh.C.netIO.SendPacket(p, eh.C.SessionID); SagaDB.Quest.Quest quest = Quest.QuestsManager.GetActiveQuest(pc); if (quest != null) //Add a temporary loot for a specificial quest { if (Quest.QuestsManager.MobQuestItem.ContainsKey(this.Actor.npcType)) { foreach (Quest.QuestsManager.LootInfo i in Quest.QuestsManager.MobQuestItem[this.Actor.npcType]) { if (i.QID == quest.ID) { if (quest.Steps.ContainsKey(i.SID)) { if (quest.Steps[i.SID].Status == 1) { if (this.Actor.NPCinv == null) { Actor.NPCinv = new List <Item>(); } int j = Global.Random.Next(0, 9999); if (j < i.rate) { this.Actor.NPCinv.Add(new Item(i.itemID)); } return; } } } } } } /*if (eh.C.QuestMobItem != null) * { * if (eh.C.QuestMobItem.ContainsKey(this.Actor.npcType)) * { * if (this.Actor.NPCinv == null) Actor.NPCinv = new List<Item>(); * this.Actor.NPCinv.Add(ItemFactory.GetItem((int)eh.C.QuestMobItem[this.Actor.npcType])); * } * }*/ } }
public static void SendNavPoint(ActorPC pc) { ActorEventHandlers.PC_EventHandler eh = (SagaMap.ActorEventHandlers.PC_EventHandler)pc.e; Packets.Server.SendNavPoint p = new SagaMap.Packets.Server.SendNavPoint(); SagaDB.Quest.Quest quest = GetActiveQuest(pc); if (quest == null) { return; } if (!WayPoints.ContainsKey(quest.ID)) { return; } Dictionary <uint, List <WayPointInfo> > list1 = WayPoints[quest.ID]; uint sid = 0; foreach (uint i in quest.Steps.Keys) { if (quest.Steps[i].Status == 1) { sid = i; } if (sid != 0) { break; } } if (sid == 0) { return; } if (!list1.ContainsKey(sid)) { return; } List <WayPointInfo> list2 = list1[sid]; List <WayPointInfo> list3 = new List <WayPointInfo>(); foreach (WayPointInfo j in list2) { if (j.mapID == pc.mapID) { list3.Add(j); } } if (list3.Count == 0) { return; } p.SetQuestID(quest.ID); p.SetPosition(list3); eh.C.netIO.SendPacket(p, eh.C.SessionID); }
private void LoadQuest(ref ActorPC aChar) { string sqlstr; int i; DataRowCollection result = null; sqlstr = "SELECT * FROM quest WHERE charID=" + aChar.charID + ""; try { result = db.GetDataTable(sqlstr).Rows; } catch (Exception ex) { Logger.ShowError(" can't get quests from database" + ex.Message, null); Logger.ShowError(ex, null); } aChar.QuestTable = new Dictionary <uint, SagaDB.Quest.Quest>(); aChar.PersonalQuestTable = new Dictionary <uint, SagaDB.Quest.Quest>(); for (i = 0; i < result.Count; i++) { try { Quest.Quest sc = new SagaDB.Quest.Quest(); string[] tmp; tmp = result[i]["step"].ToString().Split(','); for (int j = 0; j < (tmp.Length / 4); j++) { Quest.Step step = new SagaDB.Quest.Step(); step.step = Convert.ToByte(tmp[j * 4]); step.ID = Convert.ToUInt32(tmp[j * 4 + 1]); step.Status = Convert.ToByte(tmp[j * 4 + 2]); step.nextStep = Convert.ToUInt32(tmp[j * 4 + 3]); sc.Steps.Add(step.ID, step); } sc.ID = (uint)(int)result[i]["questID"]; switch ((byte)result[i]["type"]) { case 0: aChar.QuestTable.Add(sc.ID, sc); break; case 1: aChar.PersonalQuestTable.Add(sc.ID, sc); break; } } catch (Exception) { } } }
public static byte GetNPCIcon(ActorPC pc, Npc npc) { byte icon = 0; SagaDB.Quest.Quest q = Quest.QuestsManager.GetActiveQuest(pc); if (q != null) { if (npc.Questtable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.Questtable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(pc, q.ID, s.ID)) { icon += 2; } if (icon >= 2) { break; } } } } Npc.QuestReqirement pq = npc.GetAvaluablePersonalQuest(pc); if (pq != null) { icon += 1; } q = QuestsManager.GetActivePersonalQuest(pc); if (icon != 3 && icon != 2) { if (q != null) { if (npc.PersonalQuesttable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.PersonalQuesttable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(pc, q.ID, s.ID)) { icon += 2; } if (icon >= 2) { break; } } } } } return(icon); }
public static bool ifCompletedQuest(ActorPC pc, uint id) { if (id == 0) { return(false); } SagaDB.Quest.Quest quest = GetActiveQuest(pc); if (quest != null) { if (quest.ID == id) { return(false); } } return(pc.QuestTable.ContainsKey(id)); }
/// <summary> /// Send the Quest information of a client /// </summary> public void SendQuestInfo() { List <SagaDB.Quest.Quest> quests = new List <SagaDB.Quest.Quest>(); SagaDB.Quest.Quest q = Quest.QuestsManager.GetActiveQuest(this.Char); if (q != null) { quests.Add(q); } q = Quest.QuestsManager.GetActivePersonalQuest(this.Char); if (q != null) { quests.Add(q); } Packets.Server.QuestInfo p1 = new SagaMap.Packets.Server.QuestInfo(); p1.SetQuestInfo(quests); this.netIO.SendPacket(p1, this.SessionID);; }
private void ProcessTest(MapClient client, string args) { string[] arg = args.Split(' '); Packets.Server.QuestInfo p = new SagaMap.Packets.Server.QuestInfo(); SagaDB.Quest.Quest quest = new SagaDB.Quest.Quest(); quest.ID = uint.Parse(arg[0]); Dictionary<uint, SagaDB.Quest.Step> steps = new Dictionary<uint, SagaDB.Quest.Step>(); for (int i = 1; i < arg.Length; i++) { SagaDB.Quest.Step step = new SagaDB.Quest.Step(); step.ID = uint.Parse(arg[i]); step.step = (byte)i; step.Status = 1; steps.Add(uint.Parse(arg[i]), step); } quest.Steps = steps; List<SagaDB.Quest.Quest> lists = new List<SagaDB.Quest.Quest>(); lists.Add(quest); p.SetQuestInfo(lists); client.netIO.SendPacket(p, client.SessionID); }
private void LoadQuest( ref ActorPC aChar ) { string sqlstr; int i; DataRowCollection result = null; sqlstr = "SELECT * FROM quest WHERE charID=" + aChar.charID + ""; try { result = db.GetDataTable(sqlstr).Rows; } catch (Exception ex) { Logger.ShowError( " can't get quests from database" + ex.Message, null ); Logger.ShowError( ex, null ); } aChar.QuestTable = new Dictionary<uint, SagaDB.Quest.Quest>(); aChar.PersonalQuestTable = new Dictionary<uint, SagaDB.Quest.Quest>(); for( i = 0; i < result.Count; i++ ) { try { Quest.Quest sc = new SagaDB.Quest.Quest(); string[] tmp; tmp = result[i]["step"].ToString().Split(','); for (int j = 0; j < (tmp.Length / 4); j++) { Quest.Step step = new SagaDB.Quest.Step(); step.step = Convert.ToByte(tmp[j * 4]); step.ID = Convert.ToUInt32(tmp[j * 4 + 1]); step.Status = Convert.ToByte(tmp[j * 4 + 2]); step.nextStep = Convert.ToUInt32(tmp[j * 4 + 3]); sc.Steps.Add(step.ID, step); } sc.ID = (uint)(int)result[i]["questID"]; switch ((byte)result[i]["type"]) { case 0: aChar.QuestTable.Add(sc.ID, sc); break; case 1: aChar.PersonalQuestTable.Add(sc.ID, sc); break; } } catch (Exception) { } } }
public void OnNPCChat(Packets.Client.NPCChat p) { Actor aActor = map.GetActor(p.GetActorID()); if (aActor == null || aActor.type == ActorType.PC) { return; } this.Char.CurTarget = aActor; ActorNPC CurNpc = (ActorNPC)aActor; Npc npc = (Npc)CurNpc.e; byte[] tmp = null; SagaDB.Quest.Quest q = Quest.QuestsManager.GetActiveQuest(this.Char); if (q != null) { if (npc.Questtable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.Questtable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(this.Char, q.ID, s.ID)) { tmp = new byte[CurNpc.Attribute.icons.Length + 1]; CurNpc.Attribute.icons.CopyTo(tmp, 0); tmp[CurNpc.Attribute.icons.Length] = (byte)Npc.Functions.OfficialQuest; } } } } q = Quest.QuestsManager.GetActivePersonalQuest(this.Char); if (q != null) { if (npc.PersonalQuesttable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.PersonalQuesttable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(this.Char, q.ID, s.ID)) { tmp = new byte[CurNpc.Attribute.icons.Length + 1]; CurNpc.Attribute.icons.CopyTo(tmp, 0); tmp[CurNpc.Attribute.icons.Length] = (byte)Npc.Functions.PersonalQuest; } } } } Npc.QuestReqirement pq = npc.GetAvaluablePersonalQuest(this.Char); if (pq != null) { if (tmp != null) { byte[] tmp2 = new byte[tmp.Length + 1]; tmp.CopyTo(tmp2, 0); tmp2[tmp.Length] = (byte)Npc.Functions.AcceptPersonalRequest; tmp = tmp2; } else { tmp = new byte[CurNpc.Attribute.icons.Length + 1]; CurNpc.Attribute.icons.CopyTo(tmp, 0); tmp[CurNpc.Attribute.icons.Length] = (byte)Npc.Functions.AcceptPersonalRequest; } } if (tmp == null) { tmp = CurNpc.Attribute.icons; } Packets.Server.NPCChat sendPacket = new SagaMap.Packets.Server.NPCChat(); sendPacket.SetActor(p.GetActorID()); sendPacket.SetScript(CurNpc.Attribute.script); sendPacket.SetIcons((byte)tmp.Length, tmp); sendPacket.SetUnknown(1); this.netIO.SendPacket(sendPacket, this.SessionID); }
public void OnNPCChat(Npc npc) { byte[] tmp = null; SagaDB.Quest.Quest q = Quest.QuestsManager.GetActiveQuest(this.Char); if (q != null) { if (npc.Questtable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.Questtable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(this.Char, q.ID, s.ID)) { tmp = new byte[npc.Actor.Attribute.icons.Length + 1]; npc.Actor.Attribute.icons.CopyTo(tmp, 0); tmp[npc.Actor.Attribute.icons.Length] = (byte)Npc.Functions.OfficialQuest; } } } } q = Quest.QuestsManager.GetActivePersonalQuest(this.Char); if (q != null) { if (npc.PersonalQuesttable.ContainsKey(q.ID)) { foreach (SagaDB.Quest.Step s in npc.PersonalQuesttable[q.ID].Steps.Values) { if (s.Status == Quest.QuestsManager.GetQuestStepStatus(this.Char, q.ID, s.ID)) { tmp = new byte[npc.Actor.Attribute.icons.Length + 1]; npc.Actor.Attribute.icons.CopyTo(tmp, 0); tmp[npc.Actor.Attribute.icons.Length] = (byte)Npc.Functions.PersonalQuest; } } } } Npc.QuestReqirement pq = npc.GetAvaluablePersonalQuest(this.Char); if (pq != null) { if (tmp != null) { byte[] tmp2 = new byte[tmp.Length + 1]; tmp.CopyTo(tmp2, 0); tmp2[tmp.Length] = (byte)Npc.Functions.AcceptPersonalRequest; tmp = tmp2; } else { tmp = new byte[npc.Actor.Attribute.icons.Length + 1]; npc.Actor.Attribute.icons.CopyTo(tmp, 0); tmp[npc.Actor.Attribute.icons.Length] = (byte)Npc.Functions.AcceptPersonalRequest; } } if (tmp == null) { tmp = npc.Actor.Attribute.icons; } Packets.Server.NPCChat sendPacket = new SagaMap.Packets.Server.NPCChat(); sendPacket.SetActor(npc.Actor.id); sendPacket.SetScript(0); sendPacket.SetIcons((byte)tmp.Length, tmp); sendPacket.SetUnknown(1); this.netIO.SendPacket(sendPacket, this.SessionID);; }
private static void UpdateEnemyInfoSub(ActorPC pc, uint MobID, SagaDB.Quest.Quest quest, bool maploded) { ActorEventHandlers.PC_EventHandler eh = (SagaMap.ActorEventHandlers.PC_EventHandler)pc.e; if (quest == null) { return; } if (!Enemys.ContainsKey(quest.ID)) { return; } foreach (uint i in quest.Steps.Keys) { if (GetQuestStepStatus(pc, quest.ID, i) == 1) { if (!Enemys[quest.ID].ContainsKey(i)) { return; } bool completed = true; SagaDB.Quest.Step step = quest.Steps[i]; foreach (EnemyInfo q in Enemys[quest.ID][i]) { if (step.SubSteps == null) { step.SubSteps = new Dictionary <byte, byte>(); } if (!step.SubSteps.ContainsKey(q.SubSID)) { step.SubSteps.Add(q.SubSID, 0); } if (q.id.Contains(MobID)) { if (step.SubSteps[q.SubSID] >= q.ammount) { if (maploded) { Packets.Server.UpdateQuestSubStep p2 = new SagaMap.Packets.Server.UpdateQuestSubStep(); p2.SetQuestID(quest.ID); p2.SetStep(i); if (q.SubSID != 0) { p2.SetSubStep((byte)(q.SubSID - 1)); } p2.SetAmmount(step.SubSteps[q.SubSID]); eh.C.netIO.SendPacket(p2, eh.C.SessionID); } continue; } step.SubSteps[q.SubSID]++; Packets.Server.UpdateQuestSubStep p1 = new SagaMap.Packets.Server.UpdateQuestSubStep(); p1.SetQuestID(quest.ID); p1.SetStep(i); if (q.SubSID != 0) { p1.SetSubStep((byte)(q.SubSID - 1)); } p1.SetAmmount(step.SubSteps[q.SubSID]); eh.C.netIO.SendPacket(p1, eh.C.SessionID); } } foreach (EnemyInfo j in Enemys[quest.ID][i]) { if (step.SubSteps[j.SubSID] < j.ammount) { completed = false; } } if (completed) { SetQuestStepStatus(pc, quest.ID, i, 2); } } } }
private static void UpdateQuestItemSub(ActorPC pc, SagaDB.Quest.Quest quest, bool maploaded) { ActorEventHandlers.PC_EventHandler eh = (SagaMap.ActorEventHandlers.PC_EventHandler)pc.e; if (quest == null) { return; } if (!QuestItem.ContainsKey(quest.ID)) { return; } foreach (uint i in quest.Steps.Keys) { if (GetQuestStepStatus(pc, quest.ID, i) == 1) { if (!QuestItem[quest.ID].ContainsKey(i)) { return; } bool completed = true; SagaDB.Quest.Step step = quest.Steps[i]; foreach (questI q in QuestItem[quest.ID][i]) { List <SagaDB.Items.Item> l = pc.inv.GetInventoryList(); if (step.SubSteps == null) { step.SubSteps = new Dictionary <byte, byte>(); } if (!step.SubSteps.ContainsKey(q.SubSID)) { step.SubSteps.Add(q.SubSID, 0); } foreach (SagaDB.Items.Item j in l) { if (j.id == q.id) { if (step.SubSteps[q.SubSID] >= q.ammount) { if (maploaded) { Packets.Server.UpdateQuestSubStep p2 = new SagaMap.Packets.Server.UpdateQuestSubStep(); p2.SetQuestID(quest.ID); p2.SetStep(i); if (q.SubSID != 0) { p2.SetSubStep((byte)(q.SubSID - 1)); } p2.SetAmmount(j.stack); eh.C.netIO.SendPacket(p2, eh.C.SessionID); } continue; } Packets.Server.UpdateQuestSubStep p1 = new SagaMap.Packets.Server.UpdateQuestSubStep(); p1.SetQuestID(quest.ID); p1.SetStep(i); if (q.SubSID != 0) { p1.SetSubStep((byte)(q.SubSID - 1)); } p1.SetAmmount(j.stack); eh.C.netIO.SendPacket(p1, eh.C.SessionID); step.SubSteps[q.SubSID] = j.stack; } } } foreach (questI j in QuestItem[quest.ID][i]) { if (step.SubSteps[j.SubSID] < j.ammount) { completed = false; } } if (completed) { SetQuestStepStatus(pc, quest.ID, i, 2); } } } }