コード例 #1
0
    public static void UpdateZeny(Character target)
    {
        SMSG_SENDZENY spkt = new SMSG_SENDZENY();

        spkt.Zeny      = target.ZENY;
        spkt.SessionId = target.id;
        target.client.Send((byte[])spkt);
    }
コード例 #2
0
        /// <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;
                }
            }
        }