protected override void BehaveCore(BehaviorCondition cond, RealmTime? time, object state, string msg,
     Player player)
 {
     if (!adminOnly || player.Client.Account.Rank >= 2)
     {
         foreach (var s in chat)
         {
             if (msg.ToLower() == s.ToLower())
             {
                 foreach (var i in behaves)
                 {
                     i.Tick(Host, (RealmTime)time);
                 }
                 return;
             }
         }
         if (falseBehaves != null)
         {
             foreach (var f in falseBehaves)
             {
                 f.Tick(Host, (RealmTime)time);
             }
         }
     }
 }
        public bool Execute(Player player, RealmTime time, string args)
        {
            if (!HasPermission(player))
            {
                player.SendInfo("You are not an Admin");
                return false;
            }

            try
            {
                string[] a = args.Split(' ');
                bool success = Process(player, time, a);
                if (success)
                player.Manager.Database.DoActionAsync(db =>
                {
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "insert into commandlog (command, args, player) values (@command, @args, @player);";
                    cmd.Parameters.AddWithValue("@command", CommandName);
                    cmd.Parameters.AddWithValue("@args", args);
                    cmd.Parameters.AddWithValue("@player", $"{player.AccountId}:{player.Name}");
                    cmd.ExecuteNonQuery();
                });
                return success;
            }
            catch (Exception ex)
            {
                logger.Error("Error when executing the command.", ex);
                player.SendError("Error when executing the command.");
                return false;
            }
        }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            if (!player.Guild.IsDefault)
            {
                try
                {
                    var saytext = string.Join(" ", args);

                    if (String.IsNullOrWhiteSpace(saytext))
                    {
                        player.SendHelp("Usage: /guild <text>");
                        return false;
                    }
                    else
                    {
                        player.Guild.Chat(player, saytext.ToSafeText());
                        return true;
                    }
                }
                catch
                {
                    player.SendInfo("Cannot guild chat!");
                    return false;
                }
            }
            else
                player.SendInfo("You need to be in a guild to use guild chat!");
            return false;
        }
 public void Execute(Player player, string[] args)
 {
     if (player.GuildRank == 40)
     {
         foreach (var e in from i in RealmManager.Worlds
             where i.Key != 0
             from e in i.Value.Players
             where string.Equals(e.Value.Client.Account.Name, args[0], StringComparison.CurrentCultureIgnoreCase)
             select e)
         {
             if (e.Value.Client.Account.Guild.Rank == 40)
             {
                 player.SendInfo(e.Value.Client.Account.Name + " has been invited to ally with your guild!");
                 e.Value.Client.SendPacket(new GuildAllyRequestPacket
                 {
                     Name = player.Client.Account.Name,
                     Guild = player.Client.Account.Guild.Name
                 });
             }
             else
                 player.SendError(e.Value.Client.Account.Guild.Name + " is already one of your allys!");
         }
     }
     else
         player.SendInfo("Only founders can ally with other guilds!");
 }
Exemple #5
0
 public int GetPrices(Player p)
 {
     int price = 0;
     foreach (var i in SellSlots)
         if (p.Inventory[i] != null && prices.ContainsKey(p.Inventory[i].ObjectType))
             price += prices[p.Inventory[i].ObjectType];
     return price;
 }
Exemple #6
0
 public bool HasPrices(Player p)
 {
     bool ret = false;
     List<int> removeSlots = new List<int>();
     foreach (var i in SellSlots)
         if (p.Inventory[i] != null && prices.ContainsKey(p.Inventory[i].ObjectType))
             ret = true;
         else
             removeSlots.Add(i);
     foreach (var i in removeSlots)
         SellSlots.Remove(i);
     return ret;
 }
 public TradeManager(Player player1, Player player2)
 {
     this.player1Trades = new bool[12];
     this.player2Trades = new bool[12];
     this.player1 = player1;
     this.player2 = player2;
     TradingPlayers.Add(player1);
     TradingPlayers.Add(player2);
     if (CurrentRequests.Contains(new KeyValuePair<Player, Player>(player1, player2)))
         CurrentRequests.Remove(new KeyValuePair<Player, Player>(player1, player2));
     if (CurrentRequests.Contains(new KeyValuePair<Player, Player>(player2, player1)))
         CurrentRequests.Remove(new KeyValuePair<Player, Player>(player2, player1));
 }
 public void Say(Player src, string text)
 {
     src.Owner.BroadcastPacket(new TextPacket
     {
         Name = (src.Client.Account.Admin ? "@" : "") + src.Name,
         ObjectId = src.Id,
         Stars = src.Stars,
         BubbleTime = 5,
         Recipient = "",
         Text = text,
         CleanText = text
     }, null);
 }
 public void Say(Player src, string text)
 {
     src.Owner.BroadcastPacketSync(new TextPacket()
     {
         Name = (src.Client.Account.Rank >= 2 ? "@" : src.Client.Account.Rank >= 1 ? "#" : "") + src.Name,
         ObjectId = src.Id,
         Stars = src.Stars,
         BubbleTime = 10,
         Recipient = "",
         Text = text.ToSafeText(),
         CleanText = text.ToSafeText()
     }, p => !p.Ignored.Contains(src.AccountId));
     logger.InfoFormat("[{0}({1})] <{2}> {3}", src.Owner.Name, src.Owner.Id, src.Name, text);
     src.Owner.ChatReceived(text);
 }
        public void TradeChanged(Player sender, bool[] changes)
        {
            if (sender == player1)
            {
                if (changes != player1Trades)
                {
                    ResetAccept();

                    for (int i = 0; i < changes.Length; i++)
                    {
                        if (sender.Inventory[i] != null)
                        {
                            if (sender.Inventory[i].Soulbound || i < 4)
                                player1Trades[i] = false;
                            else
                                player1Trades[i] = changes[i];
                        }
                        else
                            player1Trades[i] = false;
                    }
                    player2.Client.SendPacket(new TradeChangedPacket { Offers = player1Trades });
                }
            }
            else
            {
                if (changes != player2Trades)
                {
                    ResetAccept();

                    for (int i = 0; i < changes.Length; i++)
                    {
                        if (sender.Inventory[i] != null)
                        {
                            if (sender.Inventory[i].Soulbound || i < 4)
                                player2Trades[i] = false;
                            else
                                player2Trades[i] = changes[i];
                        }
                        else
                            player2Trades[i] = false;
                    }
                    player1.Client.SendPacket(new TradeChangedPacket { Offers = player2Trades });
                }
            }
        }
 public void SayGuild(Player src, string text)
 {
     foreach (Client i in src.Manager.Clients.Values)
     {
         if (String.Equals(src.Guild, i.Player.Guild))
         {
             i.SendPacket(new TextPacket()
             {
                 Name = src.ResolveGuildChatName(),
                 ObjectId = src.Id,
                 Stars = src.Stars,
                 BubbleTime = 10,
                 Recipient = "*Guild*",
                 Text = text.ToSafeText(),
                 CleanText = text.ToSafeText()
             });
         }
     }
 }
        public bool Execute(Player player, RealmTime time, string args)
        {
            if (!HasPermission(player))
            {
                player.SendError("No permission!");
                return false;
            }

            try
            {
                string[] a = args.Split(' ');
                return Process(player, time, a);
            }
            catch (Exception ex)
            {
                log.Error("Error when executing the command.", ex);
                player.SendError("Error when executing the command.");
                return false;
            }
        }
        public void CancelTrade(RealmTime time, CancelTradePacket pkt)
        {
            psr.SendPacket(new TradeDonePacket
            {
                Result = 1,
                Message = "Trade cancelled."
            });
            tradeTarget.psr.SendPacket(new TradeDonePacket
            {
                Result = 1,
                Message = "Trade cancelled."
            });

            tradeTarget.tradeTarget = null;
            tradeTarget.trade = null;
            tradeTarget.tradeAccepted = false;
            tradeTarget = null;
            trade = null;
            tradeAccepted = false;
        }
        public void Execute(Player player, string[] args)
        {
            if (player.Guild != "")
            {
                try
                {
                    var saytext = string.Join(" ", args);

                    foreach (var w in RealmManager.Worlds)
                    {
                        var world = w.Value;
                        if (w.Key == 0)
                            continue;
                        foreach (var i in world.Players.Where(i => i.Value.Guild == player.Guild))
                        {
                            if (string.IsNullOrEmpty(saytext))
                                player.SendHelp("Usage: /g <text>");
                            else
                            {
                                var tp = new TextPacket
                                {
                                    BubbleTime = 10,
                                    Stars = player.Stars,
                                    Name = player.ResolveGuildChatName(),
                                    Recipient = "*Guild*",
                                    Text = saytext
                                };
                                if (world.Id == player.Owner.Id) tp.ObjectId = player.Id;
                                i.Value.Client.SendPacket(tp);
                            }
                        }
                    }
                }
                catch
                {
                    player.SendInfo("Cannot guild chat!");
                }
            }
            else
                player.SendInfo("You need to be in a guild to use guild chat!");
        }
        private void ProcessLoadPacket(LoadPacket pkt)
        {
            Character = Database.LoadCharacter(Account, pkt.CharacterId);
            if (Character != null)
            {
                if (Character.Dead)
                    SendPacket(new FailurePacket
                    {
                        Message = "Character is dead."
                    });
                else if (CheckAccountInUse(Account.AccountId))
                {
                    Logger.Warn($"Account in use {Account.Name} ({Account.AccountId})");
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                }
                else
                {
                    if (Account.Bonuses != null)
                        if (Account.Bonuses.Count > 0)
                        {
                            var chrEquip = Character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] != -1)
                                    continue;
                                chrEquip[i] = Account.Bonuses.First();
                                Account.Bonuses.Remove(Account.Bonuses.First());
                                SendPacket(new TextPacket
                                {
                                    Name = "",
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Text = "You received " + XmlData.ObjectTypeToId[chrEquip[i]] + "."
                                });
                                if (Account.Bonuses.Count == 0)
                                    break;
                            }
                            Database.SetBonuses(Account.AccountId, Account.Bonuses);
                            Character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    else
                    {
                        Account.Bonuses = new List<short>();
                    }
                    if (IP.Gifts != null)
                        if (IP.Gifts.Count > 0)
                        {
                            var chrEquip = Character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] != -1)
                                    continue;
                                chrEquip[i] = IP.Gifts.First();
                                IP.Gifts.Remove(IP.Gifts.First());
                                SendPacket(new TextPacket
                                {
                                    Name = "",
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Text = "You received " + XmlData.ObjectTypeToId[chrEquip[i]] + "."
                                });
                                if (IP.Gifts.Count == 0)
                                    break;
                            }
                            Database.SetBonuses(IP.Address, IP.Gifts);
                            Character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    else
                    {
                        IP.Gifts = new List<short>();
                    }

                    var target = RealmManager.Worlds[targetWorld];
                    //Delay to let client load remote texture
                    target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                    {
                        CharacterID = Character.CharacterId,
                        ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(Player = new Player(this))
                    })));
                    Stage = ProtocalStage.Ready;
                }
            }
            else
            {
                Player.SendInfo("Failed to Load character.");
                Disconnect();
            }
        }
 private static void ActivateHealMp(Player player, int amount, List<Packet> pkts)
 {
     int maxMp = player.Stats[1] + player.Boost[1];
     int newMp = Math.Min(maxMp, player.Mp + amount);
     if (newMp != player.Mp)
     {
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.Potion,
             TargetId = player.Id,
             Color = new ARGB(0x6084e0)
         });
         pkts.Add(new NotificationPacket
         {
             Color = new ARGB(0x6084e0),
             ObjectId = player.Id,
             Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + (newMp - player.Mp) + "\"}}"
         });
         player.Mp = newMp;
         player.UpdateCount++;
     }
 }
 public static void ActivateHealHp(Player player, int amount, List<Packet> pkts)
 {
     int maxHp = player.Stats[0] + player.Boost[0];
     int newHp = Math.Min(maxHp, player.HP + amount);
     if (newHp != player.HP)
     {
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.Potion,
             TargetId = player.Id,
             Color = new ARGB(0xffffffff)
         });
         pkts.Add(new NotificationPacket
         {
             Color = new ARGB(0xff00ff00),
             ObjectId = player.Id,
             Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + (newHp - player.HP) + "\"}}"
             //"+" + (newHp - player.HP)
         });
         player.HP = newHp;
         player.UpdateCount++;
     }
 }
 public StatsManager(Player player)
 {
     this.player = player;
 }
 protected override bool Process(Player player, RealmTime time, string[] args)
 {
     if (String.IsNullOrWhiteSpace(args[0]))
     {
         player.SendInfo("Usage: /join <guild name>");
         return false;
     }
     if (!player.Invited)
     {
         player.SendInfoWithTokens("server.guild_not_invited", new KeyValuePair<string, object>[1]
         {
             new KeyValuePair<string, object>("guild", args[0])
         });
         return false;
     }
     player.Manager.Database.DoActionAsync(db =>
     {
         var gStruct = db.GetGuild(args[0]);
         if (player.Invited == false)
         {
             player.SendInfo("You need to be invited to join a guild!");
         }
         if (gStruct != null)
         {
             var g = db.ChangeGuild(player.Client.Account, gStruct.Id, 0, 0, false);
             if (g != null)
             {
                 player.Client.Account.Guild = g;
                 GuildManager.CurrentManagers[args[0]].JoinGuild(player);
             }
         }
         else
         {
             player.SendInfoWithTokens("server.guild_join_fail", new KeyValuePair<string, object>[1]
             {
                 new KeyValuePair<string, object>("error", "Guild does not exist")
             });
         }
     });
     return true;
 }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            if (String.IsNullOrWhiteSpace(args[0]))
            {
                player.SendInfo("Usage: /invite <player name>");
                return false;
            }

            if (player.Guild[player.AccountId].Rank >= 20)
            {
                foreach (var i in player.Owner.Players.Values)
                {
                    Player target = player.Owner.GetPlayerByName(args[0]);

                    if (target == null)
                    {
                        player.SendInfoWithTokens("server.invite_notfound", new KeyValuePair<string, object>[1]
                        {
                            new KeyValuePair<string, object>("player", args[0])
                        });
                        return false;
                    }
                    if (!target.NameChosen || player.Dist(target) > 20)
                    {
                        player.SendInfoWithTokens("server.invite_notfound", new KeyValuePair<string, object>[1]
                        {
                            new KeyValuePair<string, object>("player", args[0])
                        });
                        return false;
                    }

                    if (target.Guild.IsDefault)
                    {
                        target.Client.SendPacket(new InvitedToGuildPacket()
                        {
                            Name = player.Name,
                            GuildName = player.Guild[player.AccountId].Name
                        });
                        target.Invited = true;
                        player.SendInfoWithTokens("server.invite_succeed", new KeyValuePair<string, object>[2]
                        {
                            new KeyValuePair<string, object>("player", args[0]),
                            new KeyValuePair<string, object>("guild", player.Guild[player.AccountId].Name)
                        });
                        return true;
                    }
                    else
                    {
                        player.SendError("Player is already in a guild!");
                        return false;
                    }
                }
            }
            else
            {
                player.Client.SendPacket(new TextPacket()
                {
                    BubbleTime = 0,
                    Stars = -1,
                    Name = "",
                    Text = "Members and initiates cannot invite!"
                });
            }
            return false;
        }
        private void DoTrade()
        {
            if (tradeTarget != null && Owner != null && tradeTarget.Owner != null && Owner == tradeTarget.Owner)
            {
                int thisemptyslots = 0;
                int targetemptyslots = 0;
                var thisItems = new List<Item>();
                for (var i = 0; i < trade.Length; i++)
                    if (trade[i])
                    {
                        thisItems.Add(Inventory[i]);
                        Inventory[i] = null;
                        UpdateCount++;
                        if (itemnumber1 == 0)
                        {
                            items1 = items1 + " " + thisItems[itemnumber1].ObjectId;
                        }
                        else if (itemnumber1 > 0)
                        {
                            items1 = items1 + ", " + thisItems[itemnumber1].ObjectId;
                        }
                        itemnumber1++;
                    }

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

                        if (itemnumber2 == 0)
                        {
                            items2 = items2 + " " + targetItems[itemnumber2].ObjectId;
                        }
                        else if (itemnumber2 > 0)
                        {
                            items2 = items2 + ", " + targetItems[itemnumber2].ObjectId;
                        }
                        itemnumber2++;
                    }

                for (var i = 0; i != Inventory.Length; i++)
                {
                    if (Inventory[i] == null)
                    {
                        if (SlotTypes[i] == 0)
                        {
                            thisemptyslots++;
                        }
                        else
                        {
                            for (var j = 0; j < targetItems.Count; j++)
                            {
                                if (targetItems[j].SlotType == SlotTypes[i])
                                {
                                    thisemptyslots++;
                                    break;
                                }
                            }
                        }
                    }

                }
                for (var i = 0; i != tradeTarget.Inventory.Length; i++)
                {
                    if (SlotTypes[i] == 0)
                    {
                        targetemptyslots++;
                    }
                    else
                    {
                        for (var j = 0; j < thisItems.Count; j++)
                        {
                            if (thisItems[j].SlotType == SlotTypes[i])
                            {
                                targetemptyslots++;
                                break;
                            }
                        }
                    }
                }
                if (targetemptyslots >= thisItems.Count && thisemptyslots >= targetItems.Count)
                    {
                        if (targetItems.Count == 0)
                            targetItems.Add(null);
                        if (thisItems.Count == 0)
                            thisItems.Add(null);
                        for (var i = 0; i < Inventory.Length; i++) //put items by slotType
                            if (Inventory[i] == null)
                            {
                                if (SlotTypes[i] == 0)
                                {
                                    Inventory[i] = targetItems[0];
                                    targetItems.RemoveAt(0);
                                }
                                else
                                {
                                    var itmIdx = -1;
                                    for (var j = 0; j < targetItems.Count; j++)
                                    {
                                        try
                                        {
                                            if (targetItems[j].SlotType == SlotTypes[i])
                                            {
                                                itmIdx = j;
                                                break;
                                            }
                                        }
                                        catch
                                        {
                                            itmIdx = -1;
                                        }
                                    }
                                    if (itmIdx != -1)
                                    {
                                        Inventory[i] = targetItems[itmIdx];
                                        targetItems.RemoveAt(itmIdx);
                                    }
                                }
                                if (targetItems.Count == 0) break;
                            }
                        if (targetItems.Count > 0)
                            for (var i = 0; i < Inventory.Length; i++) //force put item
                                if (Inventory[i] == null)
                                {
                                    Inventory[i] = targetItems[0];
                                    targetItems.RemoveAt(0);
                                    if (targetItems.Count == 0) break;
                                }

                        for (var i = 0; i < tradeTarget.Inventory.Length; i++) //put items by slotType
                            if (tradeTarget.Inventory[i] == null)
                            {
                                if (tradeTarget.SlotTypes[i] == 0)
                                {
                                    tradeTarget.Inventory[i] = thisItems[0];
                                    thisItems.RemoveAt(0);
                                }
                                else
                                {
                                    var itmIdx = -1;
                                    for (var j = 0; j < thisItems.Count; j++)
                                    {
                                        try
                                        {
                                            if (thisItems[j].SlotType == tradeTarget.SlotTypes[i])
                                            {
                                                itmIdx = j;
                                                break;
                                            }
                                        }
                                        catch
                                        {
                                            itmIdx = -1;
                                        }
                                    }
                                    if (itmIdx != -1)
                                    {
                                        tradeTarget.Inventory[i] = thisItems[itmIdx];
                                        thisItems.RemoveAt(itmIdx);
                                    }
                                }
                                if (thisItems.Count == 0) break;
                            }
                        if (thisItems.Count > 0)
                            for (var i = 0; i < tradeTarget.Inventory.Length; i++) //force put item
                                if (tradeTarget.Inventory[i] == null)
                                {
                                    tradeTarget.Inventory[i] = thisItems[0];
                                    thisItems.RemoveAt(0);
                                    if (thisItems.Count == 0) break;
                                }

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

                        const string dir = @"logs";
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        using (var writer = new StreamWriter(@"logs\TradeLog.log", true))
                        {
                            writer.WriteLine(Name + " traded " + "{" + items1 + "}" + " with " + tradeTarget.Name + " for " +
                                             "{" + items2 + "}");
                        }
                        Console.Out.WriteLine(Name + " traded " + "{" + items1 + "}" + " with " + tradeTarget.Name + " for " +
                                              "{" + items2 + "}");
                        items1 = "";
                        items2 = "";
                        itemnumber1 = 0;
                        itemnumber2 = 0;
                        UpdateCount++;
                        tradeTarget.UpdateCount++;
                        name1 = "";
                        name2 = "";
                        tradeTarget.tradeTarget = null;
                        tradeTarget.trade = null;
                        tradeTarget.tradeAccepted = false;
                        tradeTarget = null;
                        trade = null;
                        tradeAccepted = false;
                    }
                    else
                    {
                        psr.SendPacket(new TradeDonePacket
                        {
                            Result = 1,
                            Message = "Exploit Halted! You have been logged."
                        });
                        tradeTarget.psr.SendPacket(new TradeDonePacket
                        {
                            Result = 1,
                            Message = "Exploit Halted! You have been logged."
                        });
                        const string dir = @"logs";
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        using (var writer = new StreamWriter(@"logs\ExploitLog.log", true))
                        {
                            writer.WriteLine(Name + " tried to trade an ability into a weapon slot with " + tradeTarget.Name + " (Error: More items than free inventory slots)");
                        }
                        Console.Out.WriteLine(Name + " tried to trade an ability into a weapon slot with " + tradeTarget.Name + " (Error: More items than free inventory slots)");
                        items1 = "";
                        items2 = "";
                        itemnumber1 = 0;
                        itemnumber2 = 0;
                        UpdateCount++;
                        tradeTarget.UpdateCount++;
                        name1 = "";
                        name2 = "";
                        tradeTarget.tradeTarget = null;
                        tradeTarget.trade = null;
                        tradeTarget.tradeAccepted = false;
                        tradeTarget = null;
                        trade = null;
                        tradeAccepted = false;
                        return;
                    }
            }
            else
            {
                if (this != null)
                {
                    psr.SendPacket(new TradeDonePacket
                    {
                        Result = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                }
                if (tradeTarget != null)
                {
                    tradeTarget.psr.SendPacket(new TradeDonePacket
                    {
                        Result = 1,
                        Message = "Exploit Halted! You have been logged."
                    });
                }
                const string dir = @"logs";
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                using (var writer = new StreamWriter(@"logs\ExploitLog.log", true))
                {
                    writer.WriteLine(name1 + " tried to trade an ability into a weapon slot with " + name2 + " (Error: More items than free inventory slots)");
                }
                Console.Out.WriteLine(name1 + " tried to trade an ability into a weapon slot with " + name2 + " (Error: More items than free inventory slots)");
                items1 = "";
                items2 = "";
                name1 = "";
                name2 = "";
                itemnumber1 = 0;
                itemnumber2 = 0;
                UpdateCount++;
                tradeTarget.UpdateCount++;
                tradeTarget.tradeTarget = null;
                tradeTarget.trade = null;
                tradeTarget.tradeAccepted = false;
                tradeTarget = null;
                trade = null;
                tradeAccepted = false;
                return;
            }
        }
 private void TradeTick(RealmTime time)
 {
     if (trade != null)
         if (tradeTarget != null)
             if (tradeAccepted && tradeTarget.tradeAccepted)
                 if (tradeTarget != null && Owner != null && tradeTarget.Owner != null &&
                     Owner == tradeTarget.Owner)
                 {
                     DoTrade();
                 }
                 else
                 {
                     tradeTarget.tradeTarget = null;
                     tradeTarget.trade = null;
                     tradeTarget.tradeAccepted = false;
                     tradeTarget = null;
                     trade = null;
                     tradeAccepted = false;
                     return;
                 }
     CheckTradeTimeout(time);
 }
        private void Activate(RealmTime time, Item item, Position target)
        {
            MP -= item.MpCost;
            foreach (var eff in item.ActivateEffects)
            {
                switch (eff.Effect)
                {
                    case ActivateEffects.BulletNova:
                        {
                            var prjDesc = item.Projectiles[0]; //Assume only one
                            var batch = new Packet[21];
                            var s = Random.CurrentSeed;
                            Random.CurrentSeed = (uint)(s * time.tickTimes);
                            for (var i = 0; i < 20; i++)
                            {
                                var random = new Random();

                                var SpellTarget = new Position
                                {
                                    X = (float)(random.NextDouble() * (target.X + 2 - (target.X - 2)) + (target.X - 2)),
                                    Y = (float)(random.NextDouble() * (target.Y + 2 - (target.Y - 2)) + (target.Y - 2))
                                };
                                var proj = CreateProjectile(prjDesc, item.ObjectType,
                                    (int)statsMgr.GetAttackDamage(prjDesc.MinDamage, prjDesc.MaxDamage),
                                    time.tickTimes, SpellTarget, (float)(i * (Math.PI * 2) / 20));
                                Owner.EnterWorld(proj);
                                FameCounter.Shoot(proj);
                                batch[i] = new ShootPacket
                                {
                                    BulletId = proj.ProjectileId,
                                    OwnerId = Id,
                                    ContainerType = item.ObjectType,
                                    Position = target,
                                    Angle = proj.Angle,
                                    Damage = (short)proj.Damage
                                };
                            }
                            Random.CurrentSeed = s;
                            batch[20] = new ShowEffectPacket
                            {
                                EffectType = EffectType.Trail,
                                PosA = target,
                                TargetId = Id,
                                Color = new ARGB(0xFFFF00AA)
                            };
                            Owner.BroadcastPackets(batch, null);
                        }
                        break;
                    case ActivateEffects.Shoot:
                        {
                            ActivateShoot(time, item, target);
                        }
                        break;
                    case ActivateEffects.DualShoot:
                        {
                            ActivateDualShoot(time, item, target);
                        }
                        break;
                    case ActivateEffects.StatBoostSelf:
                        {
                            var idx = -1;

                            switch ((StatsType)eff.Stats)
                            {
                                case StatsType.MaximumHP:
                                    idx = 0;
                                    break;
                                case StatsType.MaximumMP:
                                    idx = 1;
                                    break;
                                case StatsType.Attack:
                                    idx = 2;
                                    break;
                                case StatsType.Defense:
                                    idx = 3;
                                    break;
                                case StatsType.Speed:
                                    idx = 4;
                                    break;
                                case StatsType.Vitality:
                                    idx = 5;
                                    break;
                                case StatsType.Wisdom:
                                    idx = 6;
                                    break;
                                case StatsType.Dexterity:
                                    idx = 7;
                                    break;
                            }
                            var pkts = new List<Packet>();

                            ActivateBoostStat(this, idx, pkts);
                            var OGstat = oldstat;

                            var s = eff.Amount;
                            Boost[idx] += s;
                            UpdateCount++;
                            Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                            {
                                Boost[idx] = OGstat;
                                UpdateCount++;
                            }));
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.Potion,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff)
                            }, null);
                        }
                        break;
                    case ActivateEffects.StatBoostAura:
                        {
                            var idx = -1;
                            switch ((StatsType)eff.Stats)
                            {
                                case StatsType.MaximumHP:
                                    idx = 0;
                                    break;
                                case StatsType.MaximumMP:
                                    idx = 1;
                                    break;
                                case StatsType.Attack:
                                    idx = 2;
                                    break;
                                case StatsType.Defense:
                                    idx = 3;
                                    break;
                                case StatsType.Speed:
                                    idx = 4;
                                    break;
                                case StatsType.Vitality:
                                    idx = 5;
                                    break;
                                case StatsType.Wisdom:
                                    idx = 6;
                                    break;
                                case StatsType.Dexterity:
                                    idx = 7;
                                    break;
                            }

                            var s = eff.Amount;
                            BehaviorBase.AOE(Owner, this, eff.Range, true, player =>
                            {
                                (player as Player).Boost[idx] += s;
                                player.UpdateCount++;
                                Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                                {
                                    (player as Player).Boost[idx] -= s;
                                    player.UpdateCount++;
                                }));
                            });
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = eff.Range }
                            }, null);
                        }
                        break;
                    case ActivateEffects.ConditionEffectSelf:
                        {
                            ApplyConditionEffect(new ConditionEffect
                            {
                                Effect = eff.ConditionEffect.Value,
                                DurationMS = eff.DurationMS
                            });
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = 1 }
                            }, null);
                        }
                        break;
                    case ActivateEffects.ConditionEffectAura:
                        {
                            BehaviorBase.AOE(Owner, this, eff.Range, true, player =>
                            {
                                player.ApplyConditionEffect(new ConditionEffect
                                {
                                    Effect = eff.ConditionEffect.Value,
                                    DurationMS = eff.DurationMS
                                });
                            });
                            var color = 0xffffffff;
                            if (eff.ConditionEffect.Value == ConditionEffectIndex.Damaging)
                                color = 0xffff0000;
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(color),
                                PosA = new Position { X = eff.Range }
                            }, null);
                        }
                        break;
                    case ActivateEffects.Heal:
                        {
                            var pkts = new List<Packet>();
                            ActivateHealHp(this, eff.Amount, pkts);
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.HealNova:
                        {
                            var pkts = new List<Packet>();
                            BehaviorBase.AOE(Owner, this, eff.Range, true,
                                player => { ActivateHealHp(player as Player, eff.Amount, pkts); });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = eff.Range }
                            });
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Magic:
                        {
                            var pkts = new List<Packet>();
                            ActivateHealMp(this, eff.Amount, pkts);
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.MagicNova:
                        {
                            var pkts = new List<Packet>();
                            BehaviorBase.AOE(Owner, this, eff.Range, true,
                                player => { ActivateHealMp(player as Player, eff.Amount, pkts); });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = eff.Range }
                            });
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Teleport:
                        {
                            Move(target.X, target.Y);
                            UpdateCount++;
                            Owner.BroadcastPackets(new Packet[]
                            {
                            new GotoPacket
                            {
                                ObjectId = Id,
                                Position = new Position
                                {
                                    X = X,
                                    Y = Y
                                }
                            },
                            new ShowEffectPacket
                            {
                                EffectType = EffectType.Teleport,
                                TargetId = Id,
                                PosA = new Position
                                {
                                    X = X,
                                    Y = Y
                                },
                                Color = new ARGB(0xFFFFFFFF)
                            }
                            }, null);
                        }
                        break;
                    case ActivateEffects.VampireBlast:
                        {
                            var pkts = new List<Packet>();
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Trail,
                                TargetId = Id,
                                PosA = target,
                                Color = new ARGB(0xFFFF0000)
                            });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Diffuse,
                                Color = new ARGB(0xFFFF0000),
                                TargetId = Id,
                                PosA = target,
                                PosB = new Position { X = target.X + eff.Radius, Y = target.Y }
                            });

                            var totalDmg = 0;
                            var enemies = new List<Enemy>();
                            BehaviorBase.AOE(Owner, target, eff.Radius, false, enemy =>
                            {
                                enemies.Add(enemy as Enemy);
                                totalDmg += (enemy as Enemy).Damage(this, time, eff.TotalDamage, false);
                            });
                            var players = new List<Player>();
                            BehaviorBase.AOE(Owner, this, eff.Radius, true, player =>
                            {
                                players.Add(player as Player);
                                ActivateHealHp(player as Player, totalDmg, pkts);
                            });

                            var rand = new Random();
                            for (var i = 0; i < 5; i++)
                            {
                                var a = enemies[rand.Next(0, enemies.Count)];
                                var b = players[rand.Next(0, players.Count)];
                                pkts.Add(new ShowEffectPacket
                                {
                                    EffectType = EffectType.Flow,
                                    TargetId = b.Id,
                                    PosA = new Position { X = a.X, Y = a.Y },
                                    Color = new ARGB(0xffffffff)
                                });
                            }

                            if (enemies.Count > 0)
                            {
                                var a = enemies[rand.Next(0, enemies.Count)];
                                var b = players[rand.Next(0, players.Count)];
                                pkts.Add(new ShowEffectPacket
                                {
                                    EffectType = EffectType.Flow,
                                    TargetId = b.Id,
                                    PosA = new Position { X = a.X, Y = a.Y },
                                    Color = new ARGB(0Xffffffff)
                                });
                            }

                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Trap:
                        {
                            var effColor = new ARGB(0xff9000ff);
                            if (eff.Color != null)
                                effColor = new ARGB((uint)eff.Color);
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.Throw,
                                Color = effColor,
                                TargetId = Id,
                                PosA = target
                            }, null);
                            Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                            {
                                var trap = new Trap(
                                    this,
                                    eff.Radius,
                                    eff.TotalDamage,
                                    eff.ConditionEffect ?? ConditionEffectIndex.Slowed,
                                    eff.EffectDuration);
                                trap.Move(target.X, target.Y);
                                world.EnterWorld(trap);
                            }));
                        }
                        break;
                    case ActivateEffects.StasisBlast:
                        {
                            var pkts = new List<Packet>();

                            var effColor = new ARGB(0xffffffff);
                            if (eff.Color != null)
                                effColor = new ARGB((uint)eff.Color);
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Concentrate,
                                TargetId = Id,
                                PosA = target,
                                PosB = new Position { X = target.X + 3, Y = target.Y },
                                Color = effColor
                            });
                            BehaviorBase.AOE(Owner, target, 3, false, enemy =>
                            {
                                if (enemy.HasConditionEffect(ConditionEffects.StasisImmune))
                                {
                                    pkts.Add(new NotificationPacket
                                    {
                                        ObjectId = enemy.Id,
                                        Color = new ARGB(0xff00ff00),
                                        Text = "Immune"
                                    });
                                }
                                else if (enemy.isPet)
                                {
                                }
                                else if (!enemy.HasConditionEffect(ConditionEffects.Stasis))
                                {
                                    enemy.ApplyConditionEffect(
                                        new ConditionEffect
                                        {
                                            Effect = ConditionEffectIndex.Stasis,
                                            DurationMS = eff.DurationMS
                                        },
                                        new ConditionEffect
                                        {
                                            Effect = ConditionEffectIndex.Confused,
                                            DurationMS = eff.DurationMS
                                        }
                                        );
                                    Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                                    {
                                        enemy.ApplyConditionEffect(new ConditionEffect
                                        {
                                            Effect = ConditionEffectIndex.StasisImmune,
                                            DurationMS = 3000
                                        }
                                            );
                                    }
                                        ));
                                    pkts.Add(new NotificationPacket
                                    {
                                        ObjectId = enemy.Id,
                                        Color = new ARGB(0xffff0000),
                                        Text = "Stasis"
                                    });
                                }
                            });
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Decoy:
                        {
                            var decoy = new Decoy(this, eff.DurationMS, statsMgr.GetSpeed());
                            decoy.Move(X, Y);
                            Owner.EnterWorld(decoy);
                        }
                        break;
                    case ActivateEffects.MultiDecoy:
                        {
                            for (var i = 0; i < eff.Amount; i++)
                            {
                                var decoy = Decoy.DecoyRandom(this, eff.DurationMS, statsMgr.GetSpeed());
                                decoy.Move(X, Y);
                                Owner.EnterWorld(decoy);
                            }
                        }
                        break;
                    case ActivateEffects.Lightning:
                        {
                            Enemy start = null;
                            var angle = Math.Atan2(target.Y - Y, target.X - X);
                            var diff = Math.PI / 3;
                            BehaviorBase.AOE(Owner, target, 6, false, enemy =>
                            {
                                if (!(enemy is Enemy)) return;
                                var x = Math.Atan2(enemy.Y - Y, enemy.X - X);
                                if (Math.Abs(angle - x) < diff)
                                {
                                    start = enemy as Enemy;
                                    diff = Math.Abs(angle - x);
                                }
                            });
                            if (start == null)
                                break;

                            var current = start;
                            var targets = new Enemy[eff.MaxTargets];
                            for (var i = 0; i < targets.Length; i++)
                            {
                                targets[i] = current;
                                float dist = 8;
                                var next = BehaviorBase.GetNearestEntity(current, ref dist, false,
                                    enemy =>
                                        enemy is Enemy &&
                                        Array.IndexOf(targets, enemy) == -1 &&
                                        BehaviorBase.Dist(this, enemy) <= 6) as Enemy;

                                if (next == null) break;
                                current = next;
                            }

                            var pkts = new List<Packet>();
                            for (var i = 0; i < targets.Length; i++)
                            {
                                if (targets[i] == null) break;
                                var prev = i == 0 ? (Entity)this : targets[i - 1];
                                targets[i].Damage(this, time, eff.TotalDamage, false);
                                if (eff.ConditionEffect != null)
                                    targets[i].ApplyConditionEffect(new ConditionEffect
                                    {
                                        Effect = eff.ConditionEffect.Value,
                                        DurationMS = (int)(eff.EffectDuration * 1000)
                                    });
                                var shotColor = new ARGB(0xffff0088);
                                if (eff.Color != null)
                                    shotColor = new ARGB((uint)eff.Color);
                                pkts.Add(new ShowEffectPacket
                                {
                                    EffectType = EffectType.Lightning,
                                    TargetId = prev.Id,
                                    Color = shotColor,
                                    PosA = new Position
                                    {
                                        X = targets[i].X,
                                        Y = targets[i].Y
                                    },
                                    PosB = new Position { X = 350 }
                                });
                            }
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.PoisonGrenade:
                        {
                            try
                            {
                                Owner.BroadcastPacket(new ShowEffectPacket
                                {
                                    EffectType = EffectType.Throw,
                                    Color = new ARGB(0xffddff00),
                                    TargetId = Id,
                                    PosA = target
                                }, null);
                                var x = new Placeholder(1500);
                                x.Move(target.X, target.Y);
                                Owner.EnterWorld(x);
                                Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                                {
                                    try
                                    {
                                        Owner.BroadcastPacket(new ShowEffectPacket
                                        {
                                            EffectType = EffectType.AreaBlast,
                                            Color = new ARGB(0xffddff00),
                                            TargetId = x.Id,
                                            PosA = new Position { X = eff.Radius }
                                        }, null);
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.Error(ex);
                                    }
                                    var enemies = new List<Enemy>();
                                    BehaviorBase.AOE(world, target, eff.Radius, false,
                                        enemy => PoisonEnemy(enemy as Enemy, eff));
                                }));
                            }
                            catch (Exception ex)
                            {
                                Logger.Error(ex);
                            }
                        }
                        break;
                    case ActivateEffects.RemoveNegativeConditions:
                        {
                            BehaviorBase.AOE(Owner, this, eff.Range, true, player => { ApplyConditionEffect(NegativeEffs); });
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = eff.Range }
                            }, null);
                        }
                        break;
                    case ActivateEffects.RemoveNegativeConditionsSelf:
                        {
                            ApplyConditionEffect(NegativeEffs);
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xffffffff),
                                PosA = new Position { X = 1 }
                            }, null);
                        }
                        break;
                    case ActivateEffects.IncrementStat:
                        {
                            var idx = -1;
                            switch ((StatsType)eff.Stats)
                            {
                                case StatsType.MaximumHP:
                                    idx = 0;
                                    break;
                                case StatsType.MaximumMP:
                                    idx = 1;
                                    break;
                                case StatsType.Attack:
                                    idx = 2;
                                    break;
                                case StatsType.Defense:
                                    idx = 3;
                                    break;
                                case StatsType.Speed:
                                    idx = 4;
                                    break;
                                case StatsType.Vitality:
                                    idx = 5;
                                    break;
                                case StatsType.Wisdom:
                                    idx = 6;
                                    break;
                                case StatsType.Dexterity:
                                    idx = 7;
                                    break;
                            }
                            Stats[idx] += eff.Amount;
                            var limit =
                                int.Parse(
                                    XmlData.TypeToElement[ObjectType].Element(StatsManager.StatsIndexToName(idx))
                                        .Attribute("max")
                                        .Value);
                            if (Stats[idx] > limit)
                                Stats[idx] = limit;
                            UpdateCount++;
                        }
                        break;
                    case ActivateEffects.Create: //this is a portal
                        {
                            short objType;
                            if (!XmlData.IdToObjectType.TryGetValue(eff.Id, out objType) ||
                                !XmlData.Portals.ContainsKey(objType))
                                break; // object not found, ignore
                            var entity = Resolve(objType);
                            var w = RealmManager.GetWorld(Owner.Id); //can't use Owner here, as it goes out of scope
                            var TimeoutTime = XmlData.Portals[objType].TimeoutTime;
                            var DungName = XmlData.Portals[objType].DungeonName;

                            ARGB c;
                            c.A = 0;
                            c.B = 91;
                            c.R = 233;
                            c.G = 176;

                            if (eff.Id == "Wine Cellar Portal") //wine cellar incantation
                            {
                                var opened = false;
                                foreach (var i in w.StaticObjects)
                                {
                                    if (i.Value.ObjectType == 0x0721) //locked wine cellar portal
                                    {
                                        opened = true;
                                        entity.Move(i.Value.X, i.Value.Y);
                                        w.EnterWorld(entity);
                                        w.LeaveWorld(i.Value);
                                        UpdateCount++;
                                    }
                                }
                                if (opened)
                                {
                                    Client.SendPacket(new NotificationPacket
                                    {
                                        Color = c,
                                        Text = DungName + " opened by " + Client.Account.Name,
                                        ObjectId = Client.Player.Id
                                    });

                                    w.BroadcastPacket(new TextPacket
                                    {
                                        BubbleTime = 0,
                                        Stars = -1,
                                        Name = "",
                                        Text = DungName + " opened by " + Client.Account.Name
                                    }, null);
                                    w.Timers.Add(new WorldTimer(TimeoutTime * 1000,
                                        (world, t) => //default portal close time * 1000
                                        {
                                            try
                                            {
                                                w.LeaveWorld(entity);
                                            }
                                            catch
                                            {
                                                Logger.Error("Portal couldnt despawn");
                                            }
                                        }));
                                }
                            }
                            else
                            {
                                entity.Move(X, Y);
                                w.EnterWorld(entity);

                                Client.SendPacket(new NotificationPacket
                                {
                                    Color = c,
                                    Text = DungName + " opened by " + Client.Account.Name,
                                    ObjectId = Client.Player.Id
                                });

                                w.BroadcastPacket(new TextPacket
                                {
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Name = "",
                                    Text = DungName + " opened by " + Client.Account.Name
                                }, null);
                                w.Timers.Add(new WorldTimer(TimeoutTime * 1000,
                                    (world, t) => //default portal close time * 1000
                                    {
                                        try
                                        {
                                            w.LeaveWorld(entity);
                                        }
                                        catch
                                        {
                                            Logger.Error("Portal couldnt despawn");
                                        }
                                    }));
                            }
                        }
                        break;
                    case ActivateEffects.Dye:
                        {
                            if (item.Texture1 != 0)
                            {
                                Texture1 = item.Texture1;
                            }
                            if (item.Texture2 != 0)
                            {
                                Texture2 = item.Texture2;
                            }
                            SaveToCharacter();
                        }
                        break;
                    case ActivateEffects.PartyAOE:
                        {
                            var randomnumber = Random.Next(1, 5);
                            ConditionEffectIndex partyeffect = 0;
                            var color = 0xffffffff;
                            if (randomnumber == 1)
                            {
                                partyeffect = ConditionEffectIndex.Damaging;
                                color = 0xffff0000;
                            }
                            if (randomnumber == 2)
                            {
                                color = 0xff00ff00;
                                partyeffect = ConditionEffectIndex.Speedy;
                            }
                            if (randomnumber == 3)
                            {
                                color = 0xffffd800;
                                partyeffect = ConditionEffectIndex.Berserk;
                            }

                            if (randomnumber == 4)
                            {
                                color = 0xff00ffff;
                                partyeffect = ConditionEffectIndex.Healing;
                            }
                            BehaviorBase.AOE(Owner, this, eff.Range, true, player =>
                            {
                                player.ApplyConditionEffect(new ConditionEffect
                                {
                                    Effect = partyeffect,
                                    DurationMS = eff.DurationMS
                                });
                            });

                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(color),
                                PosA = new Position { X = eff.Range }
                            }, null);
                        }
                        break;
                    case ActivateEffects.ShurikenAbility:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            ApplyConditionEffect(new ConditionEffect
                            {
                                Effect = ConditionEffectIndex.Speedy,
                                DurationMS = eff.DurationMS
                            });

                            var pt = eff.ObjectId;
                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var substitute = Resolve(obj);
                            substitute.PlayerOwner = this;
                            substitute.isPet = true;
                            w.EnterWorld(substitute);
                            substitute.Move(X, Y);
                            targetlink = target;
                        }
                        break;
                    case ActivateEffects.TomeDamage:
                        {
                            var pkts = new List<Packet>();
                            BehaviorBase.AOE(Owner, this, eff.Range, false,
                                enemy =>
                                {
                                    (enemy as Enemy).Damage(this, time,
                                        (int)statsMgr.GetAttackDamage(eff.TotalDamage, eff.TotalDamage), false);
                                });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.AreaBlast,
                                TargetId = Id,
                                Color = new ARGB(0xFF00FF00),
                                PosA = new Position { X = eff.Range }
                            });
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Mushroom:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            Size = eff.Amount;
                            UpdateCount++;
                            w.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                            {
                                try
                                {
                                    Size = 100;
                                    UpdateCount++;
                                }
                                catch
                                {
                                }
                            }));
                        }
                        break;

                    case ActivateEffects.PearlAbility:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            var pt = eff.ObjectId;
                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var substitute = Resolve(obj);
                            substitute.PlayerOwner = this;
                            substitute.isPet = true;
                            w.EnterWorld(substitute);
                            substitute.Move(X, Y);
                            targetlink = target;
                            var pkts = new List<Packet>();
                            ActivateHealHp(this, eff.Amount, pkts);
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;

                    case ActivateEffects.PermaPet:
                        {
                            Client.Character.Pet = XmlData.IdToObjectType[eff.ObjectId];
                            GivePet(XmlData.IdToObjectType[eff.ObjectId]);
                            UpdateCount++;
                        }
                        break;
                    case ActivateEffects.MiniPot:
                        {
                            Client.Player.Stats[1] = 1;
                            Client.Player.Stats[0] = 1;
                            Client.Player.Stats[6] = 1;
                            Client.Player.Stats[7] = 1;
                            Client.Player.Stats[2] = 1;
                            Client.Player.Stats[3] = 1;
                            Client.Player.Stats[5] = 1;
                            Client.Player.Stats[4] = 1;
                        }
                        break;
                    case ActivateEffects.Backpack:
                        {
                            var bps = 1;
                            foreach (var i in Client.Character.Backpacks)
                            {
                                if (bps < i.Key)
                                    bps = i.Key;
                            }
                            Client.Character.Backpacks.Add(bps + 1, new short[] { -1, -1, -1, -1, -1, -1, -1, -1 });
                            new Database().SaveBackpacks(Client.Character, Client.Account);
                            SendInfo("Added backpack #" + (bps + 1));
                        }
                        break;
                    case ActivateEffects.Drake:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            var pt = eff.ObjectId;
                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var drake = Resolve(obj);
                            drake.PlayerOwner = this;
                            w.EnterWorld(drake);
                            drake.Move(X, Y);
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                TargetId = Id,
                                Color = new ARGB(0x9195A9),
                                EffectType = EffectType.AreaBlast,
                                PosA = new Position
                                {
                                    X = 1
                                }
                            }, null);
                            Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) => { w.LeaveWorld(drake); }));
                        }
                        break;
                    case ActivateEffects.BuildTower:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            var pt = eff.ObjectId;

                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var tower = Resolve(obj);
                            tower.PlayerOwner = this;
                            tower.isPet = true;
                            w.EnterWorld(tower);
                            tower.Move(X, Y);
                            Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) => { w.LeaveWorld(tower); }));
                        }
                        break;
                    case ActivateEffects.MonsterToss:
                        {
                            var w = RealmManager.GetWorld(Owner.Id);
                            var pt = eff.ObjectId;
                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var monster = Resolve(obj);
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.Throw,
                                Color = new ARGB(0x000000),
                                TargetId = Id,
                                PosA = target
                            }, null);
                            Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                            {
                                w.EnterWorld(monster);
                                monster.Move(target.X, target.Y);
                            }));
                        }
                        break;
                    case ActivateEffects.Halo:
                        {
                            var halo = new Halo(this, eff.Range, eff.Amount, eff.DurationMS);
                            halo.Move(X, Y);
                            Owner.EnterWorld(halo);
                        }
                        break;
                    case ActivateEffects.Fame:
                        {
                            CurrentFame = Client.Account.Stats.Fame = new Database().UpdateFame(Client.Account, eff.Amount);
                        }
                        break;
                    case ActivateEffects.SamuraiAbility:
                        {
                            var ydist = target.Y - Y;
                            var xdist = target.X - X;
                            var xwalkable = target.X + xdist / 2;
                            var ywalkable = target.Y + ydist / 2;
                            var tile = Owner.Map[(int)xwalkable, (int)ywalkable];
                            ObjectDesc desc;
                            if (XmlData.Tiles[tile.TileId].NoWalk)
                                return;
                            if (XmlData.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                            {
                                if (!desc.Static)
                                    return;
                            }
                            Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.Diffuse,
                                Color = new ARGB(0xFFFF0000),
                                TargetId = Id,
                                PosA = target,
                                PosB = new Position { X = target.X + eff.Radius, Y = target.Y }
                            }, null);
                            BehaviorBase.AOE(Owner, target, eff.Radius, false, enemy =>
                            {
                                (enemy as Enemy).Damage(this, time, eff.TotalDamage, false, new ConditionEffect
                                {
                                    Effect = ConditionEffectIndex.Bleeding,
                                    DurationMS = eff.DurationMS
                                });
                            });
                            Move(target.X + xdist / 2, target.Y + ydist / 2);
                            UpdateCount++;

                            Owner.BroadcastPackets(new Packet[]
                            {
                            new GotoPacket
                            {
                                ObjectId = Id,
                                Position = new Position
                                {
                                    X = X,
                                    Y = Y
                                }
                            },
                            new ShowEffectPacket
                            {
                                EffectType = EffectType.Teleport,
                                TargetId = Id,
                                PosA = new Position
                                {
                                    X = X,
                                    Y = Y
                                },
                                Color = new ARGB(0xFFFFFFFF)
                            }
                            }, null);
                            ApplyConditionEffect(new ConditionEffect
                            {
                                Effect = ConditionEffectIndex.Paralyzed,
                                DurationMS = eff.DurationMS2
                            });
                        }
                        break;
                    case ActivateEffects.Summon:
                        {
                            var summons = 0;
                            foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, 20))
                            {
                                if (i.PlayerOwner == this && i.isSummon)
                                {
                                    summons++;
                                }
                            }
                            if (summons > 2)
                            {
                                return;
                            }
                            var w = RealmManager.GetWorld(Owner.Id);
                            var pt = eff.ObjectId + " Summon";
                            short obj;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var summon = Resolve(obj);
                            summon.PlayerOwner = this;
                            summon.isPet = true;
                            summon.isSummon = true;
                            w.EnterWorld(summon);
                            summon.Move(X, Y);
                            Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) => { w.LeaveWorld(summon); }));
                        }
                        break;
                    case ActivateEffects.ChristmasPopper:
                        {
                            var pkts = new List<Packet>();
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Diffuse,
                                Color = new ARGB(0xFFFF0000),
                                TargetId = Id,
                                PosA = new Position { X = X, Y = Y },
                                PosB = new Position { X = X + 3, Y = Y + 3 }
                            });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Diffuse,
                                Color = new ARGB(0x0000FF),
                                TargetId = Id,
                                PosA = new Position { X = X, Y = Y },
                                PosB = new Position { X = X + 4, Y = Y + 4 }
                            });
                            pkts.Add(new ShowEffectPacket
                            {
                                EffectType = EffectType.Diffuse,
                                Color = new ARGB(0x008000),
                                TargetId = Id,
                                PosA = new Position { X = X, Y = Y },
                                PosB = new Position { X = X + 5, Y = Y + 5 }
                            });
                            Owner.BroadcastPackets(pkts, null);
                        }
                        break;
                    case ActivateEffects.Belt:
                        {
                            Player start = null;
                            var angle = Math.Atan2(target.Y - Y, target.X - X);
                            var diff = Math.PI / 3;
                            BehaviorBase.AOE(Owner, target, 6, true, player =>
                            {
                                if (!(player is Player) || player.Id == Id) return;
                                var x = Math.Atan2(player.Y - Y, player.X - X);
                                if (Math.Abs(angle - x) < diff)
                                {
                                    start = player as Player;
                                    diff = Math.Abs(angle - x);
                                }
                            });
                            if (start == null)
                                break;

                            var current = start;
                            var targets = new Player[eff.MaxTargets];
                            for (var i = 0; i < targets.Length; i++)
                            {
                                targets[i] = current;
                                float dist = 8;
                                var next = BehaviorBase.GetNearestEntity(current, ref dist, false,
                                    player =>
                                        player is Player &&
                                        Array.IndexOf(targets, player) == -1 &&
                                        BehaviorBase.Dist(this, player) <= 6) as Player;

                                if (next == null) break;
                                current = next;
                            }

                            var pkts = new List<Packet>();
                            for (var i = 0; i < targets.Length; i++)
                            {
                                if (targets[i] == null) break;
                                var prev = i == 0 ? (Entity)this : targets[i - 1];
                                targets[i].ApplyConditionEffect(new ConditionEffect
                                {
                                    Effect = ConditionEffectIndex.Blessed,
                                    DurationMS = (int)(eff.EffectDuration * 1000)
                                });
                                var shotColor = new ARGB(0xffd700);
                                if (eff.Color != null)
                                    shotColor = new ARGB((uint)eff.Color);
                                pkts.Add(new ShowEffectPacket
                                {
                                    EffectType = EffectType.Lightning,
                                    TargetId = prev.Id,
                                    Color = shotColor,
                                    PosA = new Position
                                    {
                                        X = targets[i].X,
                                        Y = targets[i].Y
                                    },
                                    PosB = new Position { X = 350 }
                                });
                            }
                            ApplyConditionEffect(new ConditionEffect
                            {
                                Effect = ConditionEffectIndex.Blessed,
                                DurationMS = (int)(eff.EffectDuration * 1000)
                            });
                        }
                        break;
                    case ActivateEffects.Totem:
                        {
                            short obj;
                            var pt = eff.ObjectId2;
                            XmlData.IdToObjectType.TryGetValue(pt, out obj);
                            var totem = new Totem(this, eff.Range, eff.Amount, eff.ObjectId, obj);
                            totem.isSummon = true;
                            totem.Move(X, Y);
                            Owner.EnterWorld(totem);
                        }
                        break;
                    case ActivateEffects.UnlockPortal:
                        {
                            var LockedId = XmlData.IdToObjectType[eff.LockedName];
                            var DungeonId = XmlData.IdToObjectType[eff.DungeonName];
                            var w = RealmManager.GetWorld(Owner.Id);
                            Entity entity = null;
                            var opened = false;
                            foreach (var i in w.StaticObjects)
                            {
                                if (i.Value.ObjectType != XmlData.IdToObjectType[eff.LockedName]) continue;
                                entity = Resolve(XmlData.IdToObjectType[eff.DungeonName]);
                                opened = true;
                                entity.Move(i.Value.X, i.Value.Y);
                                w.EnterWorld(entity);
                                w.LeaveWorld(i.Value);
                                UpdateCount++;
                                break;
                            }
                            if (opened)
                            {
                                w.BroadcastPacket(new NotificationPacket
                                {
                                    Color = new ARGB(0xFF00FF00),
                                    Text = "Unlocked by " + Client.Account.Name,
                                    ObjectId = Client.Player.Id
                                }, null);
                                w.BroadcastPacket(new TextPacket
                                {
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Name = "",
                                    Text = eff.DungeonName + " unlocked by " + Client.Account.Name
                                }, null);
                                w.Timers.Add(new WorldTimer(XmlData.Portals[DungeonId].TimeoutTime * 1000,
                                    (world, t) => //default portal close time * 1000
                                    {
                                        try
                                        {
                                            w.LeaveWorld(entity);
                                        }
                                        catch
                                        {
                                            Logger.Error("Portal couldnt despawn");
                                        }
                                    }));
                            }
                        }
                        break;
                }
            }
            UpdateCount++;
        }
Exemple #24
0
 private static void ActivateBoostStat(Player player, int idxnew, List<Packet> pkts)
 {
     var OriginalStat = 0;
     OriginalStat = player.Stats[idxnew] + OriginalStat;
     oldstat = OriginalStat;
 }
 public StatsManager(Player player, uint seed)
 {
     this.player = player;
     this.Random = new DamageRandom(seed);
 }
 public void Execute(Player player, string[] args)
 {
     if (player.GuildRank >= 20)
     {
         foreach (var e in from i in RealmManager.Worlds
             where i.Key != 0
             from e in i.Value.Players
             where string.Equals(e.Value.Client.Account.Name, args[0], StringComparison.CurrentCultureIgnoreCase)
             select e)
         {
             if (e.Value.Client.Account.Guild.Name == "")
             {
                 player.SendInfo(e.Value.Client.Account.Name + " has been invited to your guild!");
                 e.Value.Client.SendPacket(new InvitedToGuildPacket
                 {
                     Name = player.Client.Account.Name,
                     Guild = player.Client.Account.Guild.Name
                 });
             }
             else
                 player.SendError(e.Value.Client.Account.Name + " is already in a guild!");
         }
     }
     else
         player.SendInfo("Members and initiates cannot invite!");
 }
Exemple #27
0
 public static void ActivateHealHp(Player player, int amount, List<Packet> pkts)
 {
     var maxHp = player.Stats[0] + player.Boost[0];
     var newHp = Math.Min(maxHp, player.HP + amount);
     if (newHp != player.HP)
     {
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.Potion,
             TargetId = player.Id,
             Color = new ARGB(0xffffffff)
         });
         pkts.Add(new NotificationPacket
         {
             Color = new ARGB(0xff00ff00),
             ObjectId = player.Id,
             Text = "+" + (newHp - player.HP)
         });
         player.HP = newHp;
         player.UpdateCount++;
     }
 }
        public void RequestTrade(RealmTime time, RequestTradePacket pkt)
        {
            if (!NameChosen)
            {
                SendInfo("Unique name is required to trade with others!");
                return;
            }
            if (tradeTarget != null)
            {
                SendError("You're already trading!");
                tradeTarget = null;
                return;
            }
            var target = Owner.GetUniqueNamedPlayer(pkt.Name);
            if (target == null)
            {
                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();

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

                psr.SendPacket(new TradeStartPacket
                {
                    MyItems = my,
                    YourName = target.Name,
                    YourItems = your
                });
                target.psr.SendPacket(new TradeStartPacket
                {
                    MyItems = your,
                    YourName = Name,
                    YourItems = my
                });
            }
            else
            {
                target.potentialTrader[this] = 1000*20;
                target.psr.SendPacket(new TradeRequestedPacket
                {
                    Name = Name
                });
                SendInfo("Sent trade request to " + target.Name);
            }
        }
Exemple #29
0
 private static void ActivateHealMp(Player player, int amount, List<Packet> pkts)
 {
     var maxMp = player.Stats[1] + player.Boost[1];
     var newMp = Math.Min(maxMp, player.MP + amount);
     if (newMp != player.MP)
     {
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.Potion,
             TargetId = player.Id,
             Color = new ARGB(0xffffffff)
         });
         pkts.Add(new NotificationPacket
         {
             Color = new ARGB(0x6084e0), // changed from ff9000ff to 0xDE825F (prod color)
             ObjectId = player.Id,
             Text = "+" + (newMp - player.MP)
         });
         player.MP = newMp;
         player.UpdateCount++;
     }
 }
        private void DoTrade()
        {
            if (tradeTarget != null && Owner != null && tradeTarget.Owner != null &&
                Owner == tradeTarget.Owner)
            {
                var thisItems = new List<Item>();
                for (var i = 0; i < trade.Length; i++)
                    if (trade[i])
                    {
                        thisItems.Add(Inventory[i]);
                        Inventory[i] = null;
                        UpdateCount++;
                        if (itemnumber1 == 0)
                        {
                            items1 = items1 + " " + thisItems[itemnumber1].ObjectId;
                        }
                        else if (itemnumber1 > 0)
                        {
                            items1 = items1 + ", " + thisItems[itemnumber1].ObjectId;
                        }
                        itemnumber1++;
                    }

                if (thisItems.Count == 0)
                    thisItems.Add(null);

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

                        if (itemnumber2 == 0)
                        {
                            items2 = items2 + " " + targetItems[itemnumber2].ObjectId;
                        }
                        else if (itemnumber2 > 0)
                        {
                            items2 = items2 + ", " + targetItems[itemnumber2].ObjectId;
                        }
                        itemnumber2++;
                    }

                if (targetItems.Count == 0)
                    targetItems.Add(null);

                for (var i = 0; i < Inventory.Length; i++) //put items by slotType
                    if (Inventory[i] == null)
                    {
                        if (SlotTypes[i] == 0)
                        {
                            Inventory[i] = targetItems[0];
                            targetItems.RemoveAt(0);
                        }
                        else
                        {
                            var itmIdx = -1;
                            for (var j = 0; j < targetItems.Count; j++)
                            {
                                try
                                {
                                    if (targetItems[j].SlotType == SlotTypes[i])
                                    {
                                        itmIdx = j;
                                        break;
                                    }
                                }
                                catch
                                {
                                    itmIdx = -1;
                                }
                            }
                            if (itmIdx != -1)
                            {
                                Inventory[i] = targetItems[itmIdx];
                                targetItems.RemoveAt(itmIdx);
                            }
                        }
                        if (targetItems.Count == 0) break;
                    }
                if (targetItems.Count > 0)
                    for (var i = 0; i < Inventory.Length; i++) //force put item
                        if (Inventory[i] == null)
                        {
                            Inventory[i] = targetItems[0];
                            targetItems.RemoveAt(0);
                            if (targetItems.Count == 0) break;
                        }

                for (var i = 0; i < tradeTarget.Inventory.Length; i++) //put items by slotType
                    if (tradeTarget.Inventory[i] == null)
                    {
                        if (tradeTarget.SlotTypes[i] == 0)
                        {
                            tradeTarget.Inventory[i] = thisItems[0];
                            thisItems.RemoveAt(0);
                        }
                        else
                        {
                            var itmIdx = -1;
                            for (var j = 0; j < thisItems.Count; j++)
                            {
                                try
                                {
                                    if (thisItems[j].SlotType == tradeTarget.SlotTypes[i])
                                    {
                                        itmIdx = j;
                                        break;
                                    }
                                }
                                catch
                                {
                                    itmIdx = -1;
                                }
                            }
                            if (itmIdx != -1)
                            {
                                tradeTarget.Inventory[i] = thisItems[itmIdx];
                                thisItems.RemoveAt(itmIdx);
                            }
                        }
                        if (thisItems.Count == 0) break;
                    }
                if (thisItems.Count > 0)
                    for (var i = 0; i < tradeTarget.Inventory.Length; i++) //force put item
                        if (tradeTarget.Inventory[i] == null)
                        {
                            tradeTarget.Inventory[i] = thisItems[0];
                            thisItems.RemoveAt(0);
                            if (thisItems.Count == 0) break;
                        }

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

                const string dir = @"logs";
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                using (var writer = new StreamWriter(@"logs\TradeLog.log", true))
                {
                    writer.WriteLine(Name + " traded " + "{" + items1 + "}" + " with " + tradeTarget.Name + " for " +
                                     "{" + items2 + "}");
                }
                Console.Out.WriteLine(Name + " traded " + "{" + items1 + "}" + " with " + tradeTarget.Name + " for " +
                                      "{" + items2 + "}");
                items1 = "";
                items2 = "";
                itemnumber1 = 0;
                itemnumber2 = 0;
                UpdateCount++;
                tradeTarget.UpdateCount++;

                tradeTarget.tradeTarget = null;
                tradeTarget.trade = null;
                tradeTarget.tradeAccepted = false;
                tradeTarget = null;
                trade = null;
                tradeAccepted = false;
            }
        }