Exemple #1
0
        public int AdminKill(Player from, RealmTime time)
        {
            if (nonDamage || isDead)
            {
                return(0);
            }

            if (from.IsValid())
            {
                counter.HitBy(from, time, null, MaxHP + 1);
            }
            Death(time);
            UpdateCount++;
            return(MaxHP + 1);
        }
Exemple #2
0
        public int Damage(Player from, RealmTime time, int dmg, bool noDef, bool fromProjectile, Projectile proj, params ConditionEffect[] effs)
        {
            if (nonDamage || isDead)
            {
                return(0);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(0);
            }
            if (!HasConditionEffect(ConditionEffects.Paused) && !HasConditionEffect(ConditionEffects.Stasis))
            {
                var effDmg = (int)StatsManager.GetEnemyDamage(this, dmg, 0);
                if (!noDef)
                {
                    effDmg = (int)StatsManager.GetEnemyDamage(this, dmg, Defense);
                }

                HP -= effDmg;
                ApplyConditionEffect(effs);
                Owner.BroadcastPacket(new DamagePacket
                {
                    TargetId = Id,
                    Effects  = 0,
                    Damage   = (ushort)effDmg,
                    Killed   = HP <= 0,
                    BulletId = 0,
                    ObjectId = from.Id
                }, fromProjectile ? from : null);

                if (from.IsValid())
                {
                    counter.HitBy(from, time, proj, effDmg);
                }

                if (HP <= 0 && Owner != null)
                {
                    Death(time);
                }

                UpdateCount++;
                return(effDmg);
            }
            return(0);
        }
Exemple #3
0
        public void RequestTrade(RealmTime time, RequestTradePacket pkt)
        {
            if (!NameChosen)
            {
                SendInfo("Unique name is required to trade with others!");
                return;
            }
            Player target = Owner.GetUniqueNamedPlayer(pkt.Name);

            if (tradeTarget != null)
            {
                SendError("You're already trading!");
                tradeTarget = null;
                return;
            }

            if (target.Ignored.Contains(client.Account.AccountId))
            {
                SendError("This person has ignored you!");
                tradeTarget = null;
                return;
            }

            if (client.Player == target)
            {
                SendError("Trading with yourself would be pointless.");
                tradeTarget = null;
                return;
            }
            if (!target.IsValid())
            {
                SendError("Player not found!");
                return;
            }
            if (target.tradeTarget != null && target.tradeTarget != this)
            {
                SendError(target.Name + " is already trading!");
                return;
            }

            if (potentialTrader.ContainsKey(target))
            {
                tradeTarget          = target;
                trade                = new bool[12];
                tradeAccepted        = false;
                target.tradeTarget   = this;
                target.trade         = new bool[12];
                target.tradeAccepted = false;
                potentialTrader.Clear();
                target.potentialTrader.Clear();
                taking = false;

                TradeItem[] my = new TradeItem[Inventory.Length];
                for (int i = 0; i < Inventory.Length; i++)
                {
                    my[i] = new TradeItem
                    {
                        Item      = Inventory[i] == null ? -1 : Inventory[i].ObjectType,
                        Data      = Inventory.Data[i] ?? new ItemData(),
                        SlotType  = SlotTypes[i],
                        Included  = false,
                        Tradeable = (Inventory[i] != null && i >= 4) && (!Inventory[i].Soulbound) && (!Inventory[i].AdminOnly) && (Inventory.Data[i] == null || !Inventory.Data[i].Soulbound)
                    }
                }
                ;
                TradeItem[] your = new TradeItem[target.Inventory.Length];
                for (int i = 0; i < target.Inventory.Length; i++)
                {
                    your[i] = new TradeItem
                    {
                        Item      = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType,
                        Data      = target.Inventory.Data[i] ?? new ItemData(),
                        SlotType  = target.SlotTypes[i],
                        Included  = false,
                        Tradeable = (target.Inventory[i] != null && i >= 4) && (!target.Inventory[i].Soulbound) && (!target.Inventory[i].AdminOnly) && (target.Inventory.Data[i] == null || !target.Inventory.Data[i].Soulbound)
                    }
                }
                ;

                client.SendPacket(new TradeStartPacket
                {
                    MyItems   = my,
                    YourName  = target.Name,
                    YourItems = your
                });
                target.client.SendPacket(new TradeStartPacket
                {
                    MyItems   = your,
                    YourName  = Name,
                    YourItems = my
                });
            }
            else
            {
                target.potentialTrader[this] = 1000 * 20;
                target.client.SendPacket(new TradeRequestedPacket
                {
                    Name = Name
                });
                SendInfo("Sent trade request to " + target.Name);
            }
        }
Exemple #4
0
        private void DoTrade()
        {
            if (this.IsValid() && tradeTarget.IsValid() && this.Owner == tradeTarget.Owner)
            {
                int thisemptyslots   = 0;
                int targetemptyslots = 0;
                var thisItems        = new List <Item>();
                var thisDatas        = new List <ItemData>();
                for (int i = 0; i < trade.Length; i++)
                {
                    if (trade[i])
                    {
                        thisItems.Add(Inventory[i]);
                        thisDatas.Add(Inventory.Data[i]);
                        Inventory[i]      = null;
                        Inventory.Data[i] = null;
                        UpdateCount++;
                        if (itemnumber1 == 0)
                        {
                            try
                            {
                                items1 = items1 + " " + thisItems[itemnumber1].ObjectId;
                            }
                            catch (Exception e)
                            {
                                client.SendPacket(new TradeDonePacket
                                {
                                    Result  = 1,
                                    Message = "Error."
                                });
                                log.Error(e);
                            }
                        }
                        else if (itemnumber1 > 0)
                        {
                            items1 = items1 + ", " + thisItems[itemnumber1].ObjectId;
                        }
                        itemnumber1++;
                    }
                }

                var targetItems = new List <Item>();
                var targetDatas = new List <ItemData>();
                for (int i = 0; i < tradeTarget.trade.Length; i++)
                {
                    if (tradeTarget.trade[i])
                    {
                        targetItems.Add(tradeTarget.Inventory[i]);
                        targetDatas.Add(tradeTarget.Inventory.Data[i]);
                        tradeTarget.Inventory[i]      = null;
                        tradeTarget.Inventory.Data[i] = null;
                        tradeTarget.UpdateCount++;

                        if (itemnumber2 == 0)
                        {
                            try
                            {
                                items2 = items2 + " " + targetItems[itemnumber2].ObjectId;
                            }
                            catch (Exception e)
                            {
                                client.SendPacket(new TradeDonePacket
                                {
                                    Result  = 1,
                                    Message = "Error."
                                });
                                log.Error(e);
                            }
                        }
                        else if (itemnumber2 > 0)
                        {
                            items2 = items2 + ", " + targetItems[itemnumber2].ObjectId;
                        }
                        itemnumber2++;
                    }
                }

                for (int i = 0; i != Inventory.Length; i++)
                {
                    if (Inventory[i] == null)
                    {
                        if (SlotTypes[i] == 10)
                        {
                            thisemptyslots++;
                        }
                        else
                        {
                            for (int j = 0; j < targetItems.Count; j++)
                            {
                                if (targetItems[j].SlotType == SlotTypes[i])
                                {
                                    thisemptyslots++;
                                    break;
                                }
                            }
                        }
                    }
                }
                for (int i = 0; i != tradeTarget.Inventory.Length; i++)
                {
                    if (SlotTypes[i] == 10)
                    {
                        targetemptyslots++;
                    }
                    else
                    {
                        for (int j = 0; j < thisItems.Count; j++)
                        {
                            try
                            {
                                if (thisItems[j].SlotType == SlotTypes[i])
                                {
                                    targetemptyslots++;
                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                client.SendPacket(new TradeDonePacket
                                {
                                    Result  = 1,
                                    Message = "Error."
                                });
                                log.Error(e);
                            }
                        }
                    }
                }
                if (targetemptyslots >= thisItems.Count && thisemptyslots >= targetItems.Count)
                {
                    if (tradeTarget.Owner.Id != Owner.Id)
                    {
                        return;
                    }

                    if (targetItems.Count == 0)
                    {
                        targetItems.Add(null);
                        targetDatas.Add(null);
                    }
                    if (thisItems.Count == 0)
                    {
                        thisItems.Add(null);
                        thisDatas.Add(null);
                    }
                    for (int i = 0; i < Inventory.Length; i++) //put items by slotType
                    {
                        if (Inventory[i] == null)
                        {
                            if (SlotTypes[i] == 10)
                            {
                                Inventory[i]      = targetItems[0];
                                Inventory.Data[i] = targetDatas[0];
                                targetItems.RemoveAt(0);
                                targetDatas.RemoveAt(0);
                                client.Save();
                            }
                            else
                            {
                                int itmIdx = -1;
                                for (int j = 0; j < targetItems.Count; j++)
                                {
                                    try
                                    {
                                        if (targetItems[j].SlotType == SlotTypes[i] && targetItems[j].LevelRequirement <= Level)
                                        {
                                            itmIdx = j;
                                            break;
                                        }
                                    }
                                    catch
                                    {
                                        itmIdx = -1;
                                    }
                                }
                                if (itmIdx != -1)
                                {
                                    Inventory[i]      = targetItems[itmIdx];
                                    Inventory.Data[i] = targetDatas[itmIdx];
                                    targetItems.RemoveAt(itmIdx);
                                    targetDatas.RemoveAt(itmIdx);
                                    client.Save();
                                }
                            }
                            if (targetItems.Count == 0)
                            {
                                break;
                            }
                        }
                    }

                    for (int i = 0; i < tradeTarget.Inventory.Length; i++) //put items by slotType
                    {
                        if (tradeTarget.Inventory[i] == null)
                        {
                            if (tradeTarget.SlotTypes[i] == 10)
                            {
                                tradeTarget.Inventory[i]      = thisItems[0];
                                tradeTarget.Inventory.Data[i] = thisDatas[0];
                                thisItems.RemoveAt(0);
                                thisDatas.RemoveAt(0);
                                tradeTarget.client.Save();
                            }
                            else
                            {
                                int itmIdx = -1;
                                for (int j = 0; j < thisItems.Count; j++)
                                {
                                    try
                                    {
                                        if (thisItems[j].SlotType == tradeTarget.SlotTypes[i] && thisItems[i].LevelRequirement <= tradeTarget.Level)
                                        {
                                            itmIdx = j;
                                            break;
                                        }
                                    }
                                    catch
                                    {
                                        itmIdx = -1;
                                    }
                                }
                                if (itmIdx != -1)
                                {
                                    tradeTarget.Inventory[i]      = thisItems[itmIdx];
                                    tradeTarget.Inventory.Data[i] = thisDatas[itmIdx];
                                    thisItems.RemoveAt(itmIdx);
                                    thisDatas.RemoveAt(itmIdx);
                                    tradeTarget.client.Save();
                                }
                            }
                            if (thisItems.Count == 0)
                            {
                                break;
                            }
                        }
                    }

                    client.Player.SendError("Saving Trade.. Please wait");
                    tradeTarget.client.Player.SendError("Saving Trade.. Please wait");

                    client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Trade successful!"
                    });
                    client.Save();

                    tradeTarget.client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Trade successful!"
                    });
                    tradeTarget.client.Save();

                    items1      = "";
                    items2      = "";
                    itemnumber1 = 0;
                    itemnumber2 = 0;

                    tradeTarget.tradeTarget   = null;
                    tradeTarget.trade         = null;
                    tradeTarget.tradeAccepted = false;
                    tradeTarget   = null;
                    trade         = null;
                    tradeAccepted = false;
                }
                else
                {
                    client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                    tradeTarget.client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                    items1      = "";
                    items2      = "";
                    itemnumber1 = 0;
                    itemnumber2 = 0;
                    UpdateCount++;
                    tradeTarget.UpdateCount++;
                    tradeTarget.tradeTarget   = null;
                    tradeTarget.trade         = null;
                    tradeTarget.tradeAccepted = false;
                    tradeTarget   = null;
                    trade         = null;
                    tradeAccepted = false;
                }
            }
            else
            {
                if (this != null)
                {
                    client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                }
                if (tradeTarget != null)
                {
                    tradeTarget.client.SendPacket(new TradeDonePacket
                    {
                        Result  = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                }
                items1      = "";
                items2      = "";
                itemnumber1 = 0;
                itemnumber2 = 0;
                UpdateCount++;
                tradeTarget.UpdateCount++;
                tradeTarget.tradeTarget   = null;
                tradeTarget.trade         = null;
                tradeTarget.tradeAccepted = false;
                tradeTarget   = null;
                trade         = null;
                tradeAccepted = false;
            }
        }