/// <title>Saga.NpcTakeItem</title> /// <code> /// Saga.NpcTakeItem(cid, QuestID, ItemId, Count); /// </code> /// <description> /// Takes a npc item as with a message that the npc took it. /// </description> /// <example> public static int TakeItem(uint cid, uint itemid, byte count) { Character value; if (LifeCycle.TryGetById(cid, out value)) { //HELPER VARIABLES DEFAULT_FACTORY_ITEMS.ItemInfo info; Singleton.Item.TryGetItem(itemid, out info); //int stackcount = 0; Predicate <Rag2Item> callback = delegate(Rag2Item item) { bool result = item.info.item == itemid; //if (result) stackcount += item.info.max_stack - item.count; return(result); }; //CHECK IF RIGHT AMOUNT OF ITEMS WAS FOUND List <int> FoundItems = value.ITEMS.FindAll(callback); //if (count > stackcount) return -1; //DO THE ACTUAL TAKING int acount = count; foreach (int currentInxdex in FoundItems) { Stackable <Rag2Item> item = value.ITEMS[currentInxdex]; int MinCount = Math.Min(acount, Math.Min(item.Count, info.max_stack)); acount -= MinCount; if ((item.Count -= MinCount) == 0) { value.ITEMS.RemoveAt(currentInxdex); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Container = 2; spkt.Index = (byte)currentInxdex; spkt.UpdateReason = (byte)ITEMUPDATEREASON.GIVE_TO_NPC; spkt.SessionId = value.id; value.client.Send((byte[])spkt); } else { SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Amount = (byte)item.Count; spkt.UpdateReason = (byte)ITEMUPDATEREASON.GIVE_TO_NPC; spkt.UpdateType = 4; spkt.Container = 2; spkt.SessionId = value.id; spkt.Index = (byte)currentInxdex; value.client.Send((byte[])spkt); break; } } return(count); } else { return(-1); } }
/// <title>Saga.AddStep</title> /// <code> /// Saga.AddStep(cid, QuestID, StepId, State); /// </code> /// <description> /// Adds a step to the quest. This can only be done during initialisation. /// 0 = Hidden, 1 = Visible, 2 = Completed /// </description> /// <example> ///function QUEST_START(cid) /// -- Initialize all quest steps /// -- Initialize all starting navigation points /// /// Saga.AddStep(cid, QuestID, 101, 1); /// Saga.AddStep(cid, QuestID, 102, 0); /// Saga.AddStep(cid, QuestID, 103, 0); /// Saga.InsertQuest(cid, QuestID, 1); /// /// return 0; ///end /// </example> public static bool NpcTakeItem(uint CID, uint ItemId, int ItemCount) { Character Character; if (LifeCycle.TryGetById(CID, out Character)) { foreach (KeyValuePair <byte, Rag2Item> pair in Character.container.GetAllItems()) { if (pair.Value.info.item != ItemId || pair.Value.count < ItemCount) { continue; } int newCount = pair.Value.count -= ItemCount; if (newCount > 0) { SMSG_ITEMADJUST spkt = new SMSG_ITEMADJUST(); spkt.Container = 2; spkt.Function = 4; spkt.Slot = pair.Key; spkt.UpdateReason = (byte)ItemUpdateReason.GiveToNpc; spkt.Value = (byte)pair.Value.count; spkt.SessionId = Character.id; Character.client.Send((byte[])spkt); } else { Character.container.RemoveAt(pair.Key); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Container = 2; spkt.Index = pair.Key; spkt.UpdateReason = (byte)ItemUpdateReason.GiveToNpc; spkt.SessionId = Character.id; Character.client.Send((byte[])spkt); } return(true); } } return(false); }
private void CM_QUESTITEMSTART(CMSG_QUESTITEMSTART cpkt) { Rag2Item item = this.character.container[cpkt.Index]; if (item == null) { return; } if (item.info.quest == 0) { return; } byte result = 1; if (Singleton.Database.IsQuestComplete(this.character, item.info.quest)) { result = 1; } else if (this.character.QuestObjectives[item.info.quest] != null) { result = 2; } else { try { QuestBase Quest; if (Singleton.Quests.TryFindQuests(item.info.quest, out Quest) == false || Quest.OnStart(this.character.id) < 0) { result = 1; QuestBase.InvalidateQuest(Quest, this.character); } else { result = 0; int newLength = this.character.container[cpkt.Index].count - 1; if (newLength > 0) { this.character.container[cpkt.Index].count = newLength; SMSG_UPDATEITEM spkt2 = new SMSG_UPDATEITEM(); spkt2.Amount = (byte)newLength; spkt2.UpdateReason = 8; spkt2.UpdateType = 4; spkt2.Container = 2; spkt2.SessionId = this.character.id; spkt2.Index = cpkt.Index; this.Send((byte[])spkt2); } else { this.character.container.RemoveAt(cpkt.Index); SMSG_DELETEITEM spkt3 = new SMSG_DELETEITEM(); spkt3.UpdateReason = 8; spkt3.Container = 2; spkt3.Index = cpkt.Index; spkt3.SessionId = this.character.id; this.Send((byte[])spkt3); } Quest.CheckQuest(this.character); } } catch (Exception) { Trace.TraceError("Error starting quest: {0}", item.info.quest); } } SMSG_USEQUESTITEM spkt = new SMSG_USEQUESTITEM(); spkt.Index = cpkt.Index; spkt.Result = result; spkt.SessionId = this.character.id; this.Send((byte[])spkt); }
/// <summary> /// Occurs when your aggreeing with the trade. /// After the trade content has been agreed. /// </summary> private void CM_TRADECONFIRM(CMSG_TRADECONFIRM cpkt) { TradeSession session = this.character.TradeSession; if (session != null) { //OBTAIN THE ORGIN TARGET Character target; TradeSession.TradeItem[] Items; if (this.character.TradeSession.Source == this.character) { target = session.Target; Items = session.TargetItem; } else { target = session.Source; Items = session.SourceItem; } //Calculate required slots int slots = 0; for (int i = 0; i < 16; i++) { if (Items[i] == null) { continue; } slots++; } if (slots > this.character.container.Capacity - this.character.container.Count) { //Not enough space oponent SMSG_TRADERESULT2 spkt = new SMSG_TRADERESULT2(); spkt.Reason = (byte)TradeResult.TargetNotEnoughInventorySpace; spkt.SessionId = target.id; target.client.Send((byte[])spkt); //Not enough space myself SMSG_TRADERESULT2 spkt2 = new SMSG_TRADERESULT2(); spkt2.Reason = (byte)TradeResult.NotEnoughIventorySpace; spkt2.SessionId = this.character.id; this.Send((byte[])spkt2); //Set tradesession to null; this.character.TradeSession = null; target.TradeSession = null; return; } else { if (session.Source == this.character) { session.SourceHasAgreed = true; } else { session.TargetHasAgreed = true; } } if (session.TargetHasAgreed && session.SourceHasAgreed) { target.ZENY += session.ZenySource; this.character.ZENY -= session.ZenySource; target.ZENY -= session.ZenyTarget; this.character.ZENY += session.ZenyTarget; List <Rag2Item> SourceList = new List <Rag2Item>(); List <Rag2Item> TargetList = new List <Rag2Item>(); for (int i = 0; i < 16; i++) { TradeSession.TradeItem item = session.SourceItem[i]; if (item == null) { continue; } Rag2Item ragitem = this.character.container[item.Slot]; if (ragitem.count - item.Count == 0) { SourceList.Add(ragitem); this.character.container.RemoveAt(item.Slot); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Container = 2; spkt.Index = item.Slot; spkt.SessionId = this.character.id; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; this.Send((byte[])spkt); } else { SourceList.Add(ragitem.Clone(item.Count)); ragitem.count -= item.Count; SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Container = 2; spkt.Index = item.Slot; spkt.SessionId = this.character.id; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; spkt.UpdateType = 4; this.Send((byte[])spkt); } } for (int i = 0; i < 16; i++) { TradeSession.TradeItem item = session.TargetItem[i]; if (item == null) { continue; } Rag2Item ragitem = target.container[item.Slot]; if (ragitem.count - item.Count == 0) { TargetList.Add(ragitem); this.character.container.RemoveAt(item.Slot); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Container = 2; spkt.Index = item.Slot; spkt.SessionId = target.id; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; target.client.Send((byte[])spkt); } else { TargetList.Add(ragitem.Clone(item.Count)); ragitem.count -= item.Count; SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Container = 2; spkt.Index = item.Slot; spkt.SessionId = target.id; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; spkt.UpdateType = 4; target.client.Send((byte[])spkt); } } for (int i = 0; i < SourceList.Count; i++) { Rag2Item ragitem = SourceList[i]; int index = target.container.Add(ragitem); SMSG_ADDITEM spkt = new SMSG_ADDITEM(); spkt.Container = 2; spkt.UpdateReason = (byte)ItemUpdateReason.ReceiveFromTrade; spkt.SessionId = target.id; spkt.SetItem(ragitem, index); target.client.Send((byte[])spkt); } for (int i = 0; i < TargetList.Count; i++) { Rag2Item ragitem = TargetList[i]; int index = this.character.container.Add(ragitem); SMSG_ADDITEM spkt = new SMSG_ADDITEM(); spkt.Container = 2; spkt.UpdateReason = (byte)ItemUpdateReason.ReceiveFromTrade; spkt.SessionId = this.character.id; spkt.SetItem(ragitem, index); this.Send((byte[])spkt); } //Update zeny yourself SMSG_SENDZENY spkt4 = new SMSG_SENDZENY(); spkt4.SessionId = this.character.id; spkt4.Zeny = this.character.ZENY; this.Send((byte[])spkt4); //Update zeny opponent SMSG_SENDZENY spkt5 = new SMSG_SENDZENY(); spkt5.SessionId = target.id; spkt5.Zeny = target.ZENY; target.client.Send((byte[])spkt5); //Set traderesult to succesfull SMSG_TRADERESULT2 spkt3 = new SMSG_TRADERESULT2(); spkt3.SessionId = this.character.id; this.Send((byte[])spkt3); //Set traderesult successfull oponent SMSG_TRADERESULT2 spkt2 = new SMSG_TRADERESULT2(); spkt2.SessionId = target.id; target.client.Send((byte[])spkt2); //Set the tradesession to null this.character.TradeSession = null; target.TradeSession = null; } } }
/// <summary> /// Registers a item from your inventory onto the market. /// </summary> /// <param name="cpkt"></param> private void CM_MARKET_REGISTERITEM(CMSG_MARKETREGISTER cpkt) { SMSG_MARKETREGISTER spkt = new SMSG_MARKETREGISTER(); byte result = 0; try { Rag2Item item = this.character.container[cpkt.Index]; if (item == null) { return; } uint requiredZeny = (uint)(50 * cpkt.Days); //NOT ENOUGH MONEY TO REGISTER ITEM if (requiredZeny > this.character.ZENY) { result = 6; } //CHECK REGISTERED ITEM COUNT else if (Singleton.Database.GetOwnerItemCount(this.character) == 20) { result = 8; } //EVERYTHING OKAY else { //Create mail argument Rag2Item bitem = item.Clone(cpkt.Count); MarketItemArgument argument = new MarketItemArgument(); argument.item = bitem; argument.expires = DateTime.Now.AddDays(cpkt.Days); argument.cat = (byte)item.info.categorie; argument.price = cpkt.Price; argument.sender = this.character.Name; argument.itemname = item.info.name; argument.id = Singleton.Database.RegisterNewMarketItem(this.character, argument); spkt.Item = bitem; spkt.AuctionID = argument.id; spkt.Zeny = cpkt.Price; spkt.ExpireDate = argument.expires; this.character.ZENY -= requiredZeny; CommonFunctions.UpdateZeny(this.character); int newCount = item.count - cpkt.Count; if (newCount > 0) { item.count = newCount; SMSG_UPDATEITEM spkt2 = new SMSG_UPDATEITEM(); spkt2.Index = cpkt.Index; spkt2.UpdateReason = (byte)ItemUpdateReason.AuctionRegister; spkt2.UpdateType = 4; spkt2.SessionId = this.character.id; spkt2.Amount = (byte)item.count; spkt2.Container = 2; this.Send((byte[])spkt2); } else { this.character.container.RemoveAt(cpkt.Index); SMSG_DELETEITEM spkt2 = new SMSG_DELETEITEM(); spkt2.Index = cpkt.Index; spkt2.UpdateReason = (byte)ItemUpdateReason.AuctionRegister; spkt2.UpdateReason = 4; spkt2.SessionId = this.character.id; spkt2.Container = 2; this.Send((byte[])spkt2); } } } //DATABASE ERROR catch (Exception e) { result = 1; Console.WriteLine(e); } finally { spkt.SessionId = this.character.id; spkt.Result = result; this.Send((byte[])spkt); } }
/// <summary> /// Learns a new skill from a skillbook /// </summary> /// <param name="cpkt"></param> private void CM_SKILLS_LEARNFROMSKILLBOOK(CMSG_SKILLLEARN cpkt) { byte result = 1; try { Saga.Factory.Spells.Info spellinfo; Rag2Item item = character.container[cpkt.Index]; if (item != null) { //Helpers predicates Predicate <Skill> FindSkill = delegate(Skill skill) { return(skill.Id == item.info.skill); }; Predicate <Skill> FindPreviousSkill = delegate(Skill skill) { return(skill.Id == item.info.skill - 1); }; //HELPER VARIABLES uint baseskill = (item.info.skill / 100) * 100 + 1; int newLength = character.container[cpkt.Index].count - 1; List <Skill> learnedSpells = this.character.learnedskills; Singleton.SpellManager.TryGetSpell(item.info.skill, out spellinfo); Skill CurrentSkill = learnedSpells.FindLast(FindSkill); Skill PreviousSkill = learnedSpells.FindLast(FindPreviousSkill); bool IsBaseSkill = item.info.skill == baseskill; //CHECK IF THE CURRENT JOB CAN LEARN THE SPELL if (item.info.JobRequirement[this.character.job - 1] > this.character.jlvl) { result = (byte)Generalerror.ConditionsNotMet; } //CHECK IF WE ALREADY LEARNED THE SPELL else if (CurrentSkill != null) { result = (byte)Generalerror.AlreadyLearntSkill; } //CHECK IF A PREVIOUS SKILL WAS FOUND else if (!IsBaseSkill && PreviousSkill == null) { result = (byte)Generalerror.PreviousSkillNotFound; } //CHECK SKILL EXP else if (PreviousSkill != null && PreviousSkill.Experience < PreviousSkill.info.maximumexperience) { result = (byte)Generalerror.NotEnoughSkillExperience; } else { //ADD A NEW SKILL if (IsBaseSkill) { //Passive skill bool canUse = Singleton.SpellManager.CanUse(this.character, spellinfo); if (spellinfo.skilltype == 2 && canUse) { Singleton.Additions.ApplyAddition(spellinfo.addition, this.character); int ActiveWeaponIndex = (this.character.weapons.ActiveWeaponIndex == 1) ? this.character.weapons.SeconairyWeaponIndex : this.character.weapons.PrimaryWeaponIndex; if (ActiveWeaponIndex < this.character.weapons.UnlockedWeaponSlots) { Weapon weapon = this.character.weapons[ActiveWeaponIndex]; if ((baseskill - 1) == weapon.Info.weapon_skill) { BattleStatus status = character._status; status.MaxWMAttack += (ushort)weapon.Info.max_magic_attack; status.MinWMAttack += (ushort)weapon.Info.min_magic_attack; status.MaxWPAttack += (ushort)weapon.Info.max_short_attack; status.MinWPAttack += (ushort)weapon.Info.min_short_attack; status.MaxWRAttack += (ushort)weapon.Info.max_range_attack; status.MinWRAttack += (ushort)weapon.Info.min_range_attack; status.Updates |= 2; } } } Singleton.Database.InsertNewSkill(this.character, item.info.skill, spellinfo.maximumexperience); CurrentSkill = new Skill(); CurrentSkill.info = spellinfo; CurrentSkill.Id = item.info.skill; CurrentSkill.Experience = spellinfo.maximumexperience; learnedSpells.Add(CurrentSkill); } //UPDATE A OLD SKILL else { //Passive skill if (spellinfo.skilltype == 2) { Saga.Factory.Spells.Info oldSpellinfo; Singleton.SpellManager.TryGetSpell(PreviousSkill.info.skillid, out oldSpellinfo); bool canUseOld = Singleton.SpellManager.CanUse(this.character, oldSpellinfo); bool canUseNew = Singleton.SpellManager.CanUse(this.character, spellinfo); if (canUseOld) { Singleton.Additions.DeapplyAddition(oldSpellinfo.addition, this.character); } if (canUseNew) { Singleton.Additions.ApplyAddition(spellinfo.addition, this.character); } } Singleton.Database.UpgradeSkill(this.character, PreviousSkill.info.skillid, item.info.skill, spellinfo.maximumexperience); PreviousSkill.info = spellinfo; PreviousSkill.Id = item.info.skill; PreviousSkill.Experience = spellinfo.maximumexperience; } SMSG_SKILLADD spkt2 = new SMSG_SKILLADD(); spkt2.Slot = 0; spkt2.SkillId = item.info.skill; spkt2.SessionId = this.character.id; this.Send((byte[])spkt2); if (newLength > 0) { this.character.container[cpkt.Index].count = newLength; SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Amount = (byte)newLength; spkt.UpdateReason = 8; spkt.UpdateType = 4; spkt.Container = 2; spkt.SessionId = this.character.id; spkt.Index = cpkt.Index; this.Send((byte[])spkt); } else { this.character.container.RemoveAt(cpkt.Index); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.UpdateReason = 8; spkt.Container = 2; spkt.Index = cpkt.Index; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } Common.Internal.CheckWeaponary(this.character); Tasks.LifeCycle.Update(this.character); result = 0; } } } finally { //OUTPUT THE RESULT SMSG_SKILLLEARN spkt = new SMSG_SKILLLEARN(); spkt.Result = result; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } }
/// <summary> /// Occurs when using a item that uses a skill /// </summary> /// <param name="cpkt"></param> private void CM_ITEMTOGGLE(CMSG_ITEMTOGLE cpkt) { lock (this.character.cooldowncollection) { try { Rag2Item item = this.character.container[cpkt.Index]; MapObject target; uint skillid = cpkt.SkillID; byte skilltype = cpkt.SkillType; ItemSkillUsageEventArgs argument = null; bool cancast = Regiontree.TryFind(cpkt.TargetActor, this.character, out target) && ItemSkillUsageEventArgs.Create(item, this.character, target, out argument) && argument.SpellInfo.casttime > -1 && (argument.SpellInfo.casttime == 0 || this.character._lastcastedskill == skillid) && ((long)((uint)Environment.TickCount) - this.character._lastcastedtick) > 0 && (argument.SpellInfo.delay == 0 || !this.character.cooldowncollection.IsCoolDown(skillid)) && (argument.SpellInfo.maximumrange == 0 || argument.SpellInfo.IsInRangeOf((int)(Vector.GetDistance2D(this.character.Position, target.Position)))) && argument.SpellInfo.requiredWeapons[this.character.weapons.GetCurrentWeaponType()] == 1 && this.character.jlvl > argument.SpellInfo.requiredJobs[this.character.job - 1] && argument.SpellInfo.IsTarget(this.character, target) && item.count > 0; if (cancast && argument.Use()) { int delay = (int)(argument.SpellInfo.delay - ((character.stats.Dexterity * 2) + (character.stats.Concentration * 2))); if (delay > 0) { this.character.cooldowncollection.Add(skillid, delay); } this.character.cooldowncollection.Update(); int newLength = this.character.container[cpkt.Index].count - 1; if (newLength > 0) { this.character.container[cpkt.Index].count = newLength; SMSG_UPDATEITEM spkt2 = new SMSG_UPDATEITEM(); spkt2.Amount = (byte)newLength; spkt2.UpdateReason = 8; spkt2.UpdateType = 4; spkt2.Container = 2; spkt2.SessionId = this.character.id; spkt2.Index = cpkt.Index; this.Send((byte[])spkt2); } else { this.character.container.RemoveAt(cpkt.Index); SMSG_DELETEITEM spkt3 = new SMSG_DELETEITEM(); spkt3.UpdateReason = 8; spkt3.Container = 2; spkt3.Index = cpkt.Index; spkt3.SessionId = this.character.id; this.Send((byte[])spkt3); } //Preprocess packet SMSG_ITEMTOGGLE spkt = new SMSG_ITEMTOGGLE(); spkt.Container = cpkt.Container; spkt.SkillMessage = (byte)argument.Result; spkt.Index = cpkt.Index; spkt.SkillID = cpkt.SkillID; spkt.SkillType = cpkt.SkillType; spkt.SourceActor = this.character.id; spkt.TargetActor = cpkt.TargetActor; spkt.Value = argument.Damage; //Send packets in one-mighty blow Regiontree tree = this.character.currentzone.Regiontree; foreach (Character regionObject in tree.SearchActors(this.character, SearchFlags.Characters)) { if (character.client.isloaded == false || !Point.IsInSightRangeByRadius(this.character.Position, regionObject.Position)) { continue; } spkt.SessionId = target.id; regionObject.client.Send((byte[])spkt); } } } catch (Exception) { Trace.TraceError("Error processing item skill"); } } }
/// <summary> /// Occurs when exchanging goods /// </summary> /// <param name="cpkt"></param> private void CM_EXCHANGEGOODS(CMSG_SUPPLYEXCHANGE cpkt) { byte useresult = 1; byte result = 5; try { SingleTradelist stradelist = this.character.Tag as SingleTradelist; GroupedTradelist gtradelist = this.character.Tag as GroupedTradelist; List <Rag2Item> Production = null; List <Rag2Item> Supplyment = null; uint supplymoney = 0; uint productionmoney = 0; //Obtain type of tradelist if (stradelist != null) { useresult = 1; Production = stradelist.list.GetProductionlist; Supplyment = stradelist.list.GetSupplementlist; supplymoney = stradelist.supplementzeny; productionmoney = stradelist.productionzeny; } else if (gtradelist != null) { useresult = 2; Production = gtradelist.list[cpkt.ButtonId].GetProductionlist; Supplyment = gtradelist.list[cpkt.ButtonId].GetSupplementlist; } else { return; } uint reqzeny = productionmoney - supplymoney; if (reqzeny < 0 && this.character.ZENY - reqzeny <= 0) { result = 3; return; } List <byte> ListOfIndexes = new List <byte>(); int numdelitems = 0; for (int i = 0; i < Supplyment.Count; i++) { bool IsFound = false; Rag2Item item2 = Supplyment[i]; foreach (KeyValuePair <byte, Rag2Item> pair in this.character.container.GetAllItems()) { Rag2Item item1 = pair.Value; bool IsSame = item1.clvl == item2.clvl && item1.info == item2.info && item1.dyecolor == item2.dyecolor && item1.count >= item2.count && item1.clvl == item2.clvl; //Set the to true, keep true if already true; if (IsSame == true) { ListOfIndexes.Add(pair.Key); IsFound |= IsSame; int count = item1.count - item2.count; if (count == 0) { numdelitems++; } break; } } if (IsFound == false) { break; } } if (ListOfIndexes.Count != Supplyment.Count) { result = 4; return; } int reqslots = Production.Count - numdelitems; if (reqslots > 0 && this.character.container.Count + reqslots > this.character.container.Capacity) { result = 2; return; } for (int i = 0; i < ListOfIndexes.Count; i++) { int index = ListOfIndexes[i]; int newcount = this.character.container[index].count - Supplyment[i].count; if (newcount == 0) { this.character.container.RemoveAt(index); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Index = (byte)index; spkt.Container = 2; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } else { this.character.container[index].count = newcount; SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Amount = (byte)newcount; spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader; spkt.UpdateType = 4; spkt.Container = 2; spkt.SessionId = this.character.id; spkt.Index = (byte)index; this.Send((byte[])spkt); } } foreach (Rag2Item item in Production) { int index = this.character.container.Add(item); SMSG_ADDITEM spkt = new SMSG_ADDITEM(); spkt.Container = 2; spkt.UpdateReason = (byte)ItemUpdateReason.ReceiveFromTrade; spkt.SetItem(item, index); spkt.SessionId = this.character.id; this.Send((byte[])spkt); } result = 0; } finally { SMSG_SUPPLYLISTRESULT spkt = new SMSG_SUPPLYLISTRESULT(); if (useresult == 2) { spkt.Reason1 = 1; spkt.Reason2 = result; } else if (useresult == 1) { spkt.Reason2 = result; } spkt.SessionId = this.character.id; this.Send((byte[])spkt); } }
/// <summary> /// Sends a new mail message /// </summary> private void CM_NEWMAILITEM(CMSG_SENDMAIL cpkt) { //HELPER VARIABLES byte result = 1; uint req_zeny = 0; Rag2Item item = null; MailItem mailmessage = new MailItem(); mailmessage.Content = cpkt.Content; mailmessage.Recieptent = cpkt.Name; mailmessage.Topic = cpkt.Topic; mailmessage.item = item; if ((cpkt.HasItem & 2) == 2) { item = this.character.container[cpkt.Slot]; if (item != null) { req_zeny = 10; mailmessage.item = item.Clone(cpkt.StackCount); } } if ((cpkt.HasItem & 1) == 1) { req_zeny = 10 + cpkt.Zeny; mailmessage.Zeny = cpkt.Zeny; } try { //RECIEVER DOES NOT EXISTS if (!Singleton.Database.VerifyNameExists(mailmessage.Recieptent)) { result = 2; } //NOT ENOUGH MONEY else if (this.character.ZENY < req_zeny) { result = 3; } //CHECK ITEM INVENTORY else if (item != null && cpkt.StackCount > item.count) { result = 5; } //CHECK IF OWNER OUTBOX IF FULL else if (Singleton.Database.GetInboxMailCount(this.character.Name) == 20) { result = 6; } //CHECK IF SENDER INBOX IS FULL else if (Singleton.Database.GetInboxMailCount(mailmessage.Recieptent) == 20) { result = 7; } //DATABASE ERROR else if (!Singleton.Database.InsertNewMailItem(this.character, mailmessage)) { result = 1; } //EVERYTHING IS OKAY else { if (cpkt.HasItem > 0) { this.character.ZENY -= req_zeny; CommonFunctions.UpdateZeny(this.character); } //UPDATE ITEM COUNT AS FORM OF A ATTACHMENT if ((cpkt.HasItem & 2) == 2) { item.count -= cpkt.StackCount; if (item.count > 0) { SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM(); spkt.Amount = (byte)item.count; spkt.UpdateReason = (byte)ItemUpdateReason.AttachmentReceived; spkt.UpdateType = 4; spkt.Container = 2; spkt.SessionId = this.character.id; spkt.Index = cpkt.Slot; this.Send((byte[])spkt); } else { this.character.container.RemoveAt(cpkt.Slot); SMSG_DELETEITEM spkt = new SMSG_DELETEITEM(); spkt.Container = 2; spkt.Index = cpkt.Slot; spkt.UpdateReason = (byte)ItemUpdateReason.AttachmentReceived; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } } //EVERYTHING OKAY result = 0; } } finally { SMSG_MAILSENDAWNSER spkt = new SMSG_MAILSENDAWNSER(); spkt.Result = result; spkt.SessionId = cpkt.SessionId; this.Send((byte[])spkt); } }