示例#1
0
        protected override bool TickCore(RealmTime time)
        {
            var chr = Host as Character;
            var w   = RealmManager.GetWorld(Host.Self.Owner.Id);

            while (doTimes > timesDone)
            {
                w.Timers.Add(new WorldTimer(cooldown, (world, t) =>
                {
                    try
                    {
                        timesDone++;
                    }
                    catch
                    {
                        timesDone++;
                    }
                }));


                return(behavior.Tick(Host, time));
            }

            return(false);
        }
示例#2
0
 void ProcessEscapePacket(EscapePacket pkt)
 {
     try
     {
         World world = RealmManager.GetWorld(Player.Owner.Id);
         if (world.Id == World.NEXUS_ID)
         {
             SendPacket(new TextPacket()
             {
                 Stars      = -1,
                 BubbleTime = 0,
                 Name       = "",
                 Text       = "You are already in the nexus!"
             });
             return;
         }
         Reconnect(new ReconnectPacket()
         {
             Host   = "",
             Port   = 2050,
             GameId = World.NEXUS_ID,
             Name   = "Nexus",
             Key    = Empty <byte> .Array,
         });
     }
     catch
     {
     }
 }
示例#3
0
 void ProcessEscapePacket(EscapePacket pkt)
 {
     try
     {
         World world = RealmManager.GetWorld(Player.Owner.Id);
         if (world.Id == World.NEXUS_ID)
         {
             SendPacket(new TextPacket()
             {
                 Stars      = 52,
                 BubbleTime = 0,
                 Name       = "You stupid?",
                 Text       = "Please do not bother Nexusing in Nexus..."
             });
             return;
         }
         Reconnect(new ReconnectPacket()
         {
             Host   = "",
             Port   = 2050,
             GameId = World.NEXUS_ID,
             Name   = "Nexus",
             Key    = Empty <byte> .Array,
         });
     }
     catch
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.Out.WriteLine("[Error while sending EscapePacket, Check ClientProcessor.cs]");
         Player.SaveToCharacter();
         psr.Disconnect();
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
示例#4
0
 //public bool CheckAccountInUse(string uuid)
 //{
 //    int count = 0;
 //    int accId = 0;
 //    using(db.Database dbx = new Database())
 //    {
 //        var cmd = dbx.CreateQuery();
 //        cmd.CommandText = "SELECT id FROM accounts WHERE uuid = @uuid";
 //        cmd.Parameters.AddWithValue("@uuid", uuid);
 //        if (cmd.ExecuteNonQuery() != 0)
 //        {
 //            object id;
 //            id = cmd.ExecuteScalar();
 //            accId = int.Parse(id.ToString());
 //        }
 //    }
 //    foreach (var i in RealmManager.Clients.Values)
 //    {
 //        if (i.Account.AccountId == accId)
 //        {
 //            return true;
 //        }
 //        else
 //        {
 //            count = count + 1;
 //        }
 //    }
 //    if (count == RealmManager.Clients.ToArray().Length)
 //    {
 //        return false;
 //    }
 //    return false;
 //}
 //public bool CheckAccountInUse(int accId)
 //{
 //    int count = 0;
 //    foreach (var i in RealmManager.Clients.Values)
 //    {
 //        if (i.Account.AccountId == accId)
 //        {
 //            return true;
 //        }
 //        else
 //        {
 //            count = count + 1;
 //        }
 //    }
 //    if (count == RealmManager.Clients.ToArray().Length)
 //    {
 //        return false;
 //    }
 //    return false;
 //}
 public bool CheckAccountInUse(int accId)
 {
     try
     {
         int count = 0;
         for (int i = 0; i < RealmManager.Worlds.Values.Count; i++)
         {
             World w = RealmManager.GetWorld(i);
             foreach (var plr in w.Players.Values)
             {
                 if (plr.AccountId == accId)
                 {
                     return(true);
                 }
                 else
                 {
                     count = count + 1;
                 }
             }
             if (count == w.Players.Values.ToArray().Length)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         Console.WriteLine("Error checking if account " + accId + " is in use, check ClientProcessor.cs");
         return(false);
     }
 }
示例#5
0
        protected override void BehaveCore(BehaviorCondition cond, RealmTime?time, object state)
        {
            if (Host.Self.Owner.Name != "Battle Arena" && Host.Self.Owner.Name != "Free Battle Arena" && Host.Self.Owner.Name != "Arena" && Host.Self.Owner.Name != "Nexus")
            {
                if (new Random().Next(1, 100) <= percent)
                {
                    var entity = Entity.Resolve(objType) as Portal;
                    var parent = Host as Entity;
                    entity.Move(parent.X, parent.Y);
                    parent.Owner.EnterWorld(entity);
                    var w = RealmManager.GetWorld(Host.Self.Owner.Id);
                    w.Timers.Add(new WorldTimer(timeExist * 1000, (world, t) =>
                    {
                        if (timeExist > 0)
                        {
                            try
                            {
                                w.LeaveWorld(entity);
                            }

                            catch
                            {
                            }
                        }
                    }));
                }
            }
        }
示例#6
0
 private void ProcessEscapePacket(EscapePacket pkt)
 {
     try
     {
         World world = RealmManager.GetWorld(Player.Owner.Id);
         if (world.Id == World.NEXUS_ID)
         {
             SendPacket(new TextPacket()
             {
                 Stars      = -1,
                 BubbleTime = 0,
                 Name       = "",
                 Text       = "You are already at the Nexus!"
             });
             return;
         }
         Reconnect(new ReconnectPacket()
         {
             Host   = "",
             Port   = 2050,
             GameId = World.NEXUS_ID,
             Name   = "Nexus",
             Key    = Empty <byte> .Array,
         });
     }
     catch
     {
         logger.Error("Error while sending EscapePacket, Check Client.cs");
     }
 }
示例#7
0
        private void ProcessEscapePacket(EscapePacket pkt)
        {
            try
            {
                World world = RealmManager.GetWorld(Player.Owner.Id);
                if (world.Id == World.NEXUS_ID)
                {
                    SendPacket(new TextPacket
                    {
                        Stars      = -1,
                        BubbleTime = 0,
                        Name       = "",
                        Text       = "You are already at the Nexus!"
                    });
                    return;
                }

                /*Reconnect(new ReconnectPacket
                 * {
                 *  Host = "",
                 *  Port = 2050,
                 *  GameId = World.NEXUS_ID,
                 *  Name = "Nexus",
                 *  Key = Empty<byte>.Array,
                 * });*/
                Disconnect();
            }
            catch
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("Error while sending EscapePacket, Check ClientProcessor.cs");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
示例#8
0
 void ProcessEscapePacket(EscapePacket pkt)
 {
     try
     {
         World world = RealmManager.GetWorld(Player.Owner.Id);
         //if (world.Id == World.NEXUS_ID)
         //{
         //    SendPacket(new TextPacket()
         //    {
         //        Stars = -1,
         //        BubbleTime = 0,
         //        Name = "",
         //        Text = "You are already at the Nexus!"
         //    });
         //    return;
         //}
         Reconnect(new ReconnectPacket()
         {
             Host   = "",
             Port   = 2050,
             GameId = World.NEXUS_ID,
             Name   = "Nexus",
             Key    = Empty <byte> .Array,
         });
     }
     catch
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.Out.WriteLine("Error while sending EscapePacket, Check ClientProcessor.cs");
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
示例#9
0
 //public bool CheckAccountInUse(string uuid)
 //{
 //    int count = 0;
 //    int accId = 0;
 //    using(db.Database dbx = new Database())
 //    {
 //        var cmd = dbx.CreateQuery();
 //        cmd.CommandText = "SELECT id FROM accounts WHERE uuid = @uuid";
 //        cmd.Parameters.AddWithValue("@uuid", uuid);
 //        if (cmd.ExecuteNonQuery() != 0)
 //        {
 //            object id;
 //            id = cmd.ExecuteScalar();
 //            accId = int.Parse(id.ToString());
 //        }
 //    }
 //    foreach (var i in RealmManager.Clients.Values)
 //    {
 //        if (i.Account.AccountId == accId)
 //        {
 //            return true;
 //        }
 //        else
 //        {
 //            count = count + 1;
 //        }
 //    }
 //    if (count == RealmManager.Clients.ToArray().Length)
 //    {
 //        return false;
 //    }
 //    return false;
 //}
 //public bool CheckAccountInUse(int accId)
 //{
 //    int count = 0;
 //    foreach (var i in RealmManager.Clients.Values)
 //    {
 //        if (i.Account.AccountId == accId)
 //        {
 //            return true;
 //        }
 //        else
 //        {
 //            count = count + 1;
 //        }
 //    }
 //    if (count == RealmManager.Clients.ToArray().Length)
 //    {
 //        return false;
 //    }
 //    return false;
 //}
 public bool CheckAccountInUse(int accId)
 {
     try
     {
         World w     = RealmManager.GetWorld(World.NEXUS_ID);
         World v     = RealmManager.GetWorld(World.VAULT_ID);
         int   count = 0;
         foreach (var i in w.Players.Values)
         {
             if (i.AccountId == accId)
             {
                 return(true);
             }
             else
             {
                 count = count + 1;
             }
         }
         if (count == w.Players.Values.ToArray().Length)
         {
             return(false);
         }
         return(true);
     }
     catch
     {
         Console.WriteLine("Error checking if account " + accId + " is in use, check ClientProcessor.cs");
         return(false);
     }
 }
示例#10
0
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            // connect to database
            db      = new Database();
            account = db.Verify(pkt.GUID, pkt.Password);
            ip      = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0]);

            Console.Write(@"Connecting " + ((account == null)? "null":account.Name) +
                          "@" + ip.Address + "... ");

            // check if ok to connect
            string msg;

            if ((msg = OkToConnect(pkt)) != null)
            {
                Console.WriteLine(msg);
                account = null;
                Disconnect();
                return;
            }

            // ok to connect, add client to client list
            RealmManager.Clients.TryAdd(account.AccountId, this);

            // setup client world
            World world = RealmManager.GetWorld(pkt.GameId);

            if (world.Id == -6) //Test World
            {
                (world as Test).LoadJson(pkt.MapInfo);
            }
            else if (world.IsLimbo)
            {
                world = world.GetInstance(this);
            }
            uint seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;

            Random      = new wRandom(seed);
            targetWorld = world.Id;

            // connection successful, send MapInfo packet
            SendPacket(new MapInfoPacket
            {
                Width         = world.Map.Width,
                Height        = world.Map.Height,
                Name          = world.Name,
                Seed          = seed,
                Background    = world.Background,
                AllowTeleport = world.AllowTeleport,
                ShowDisplays  = world.ShowDisplays,
                Music         = world.GetMusic(Random),
                ClientXML     = world.ClientXML,
                ExtraXML      = world.ExtraXML,
                SendMusic     = true
            });
            stage = ProtocalStage.Handshaked;

            Console.WriteLine("Joined " + world.Name + " (" + world.Id + ").");
        }
示例#11
0
        /* Makes various checks to see if client is allowed to connect.
         * Returns null on success, otherwise return value contains
         * discription of error.
         */
        private string OkToConnect(HelloPacket pkt)
        {
            string retMsg = null;

            ConnectedBuild = pkt.BuildVersion;

            // check client version
            if (!ConnectedBuild.StartsWith(clientVer))
            {
                ConnectionFailed(retMsg = "Wrong build version.");
            }

            // has valid account?
            else if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                ConnectionFailed(retMsg = "Invalid account.");
            }

            // ip banned?
            else if (ip.Banned)
            {
                ConnectionFailed(retMsg = "IP banned.");
            }

            // account banned?
            else if (account.Banned)
            {
                ConnectionFailed(retMsg = "Account banned.");
            }

            // server full?
            else if (RealmManager.Clients.Count >= RealmManager.MAX_CLIENT)
            {
                ConnectionFailed(retMsg = "Server full.");
            }

            // valid gameId?
            else if (RealmManager.GetWorld(pkt.GameId) == null)
            {
                // invalid world... send to nexus instead
                pkt.GameId = World.NEXUS_ID;
            }

            // account already connected? disconnect if so
            else if (AccountConnected(account.AccountId))
            {
                ConnectionFailed(retMsg = "Account in use... ");
                ClientProcessor target = RealmManager.Clients[account.AccountId];
                target.Disconnect();
            }

            return(retMsg);
        }
示例#12
0
        public void UsePortal(RealmTime time, UsePortalPacket pkt)
        {
            Portal entity = Owner.GetEntity(pkt.ObjectId) as Portal;

            if (entity == null || !entity.Usable)
            {
                return;
            }
            World world = entity.WorldInstance;

            if (world == null)
            {
                switch (entity.ObjectType)
                {
                case 0x0712:
                case 0x071d:
                    world = RealmManager.GetWorld(World.NEXUS_ID); break;

                case 0x071c:
                    world = RealmManager.Monitor.GetRandomRealm(); break;

                case 0x0720:
                    world = RealmManager.GetWorld(World.VAULT_ID); break;

                case 0x071e:
                    world = RealmManager.AddWorld(new Kitchen()); break;

                case 0x233D:
                    world = RealmManager.AddWorld(new Banana()); break;

                case 0x2553:
                    world = RealmManager.AddWorld(new Gee()); break;     //map creating tutorial world
                }
                entity.WorldInstance = world;
            }
            psr.Reconnect(new ReconnectPacket()
            {
                Host   = "",
                Port   = 2050,
                GameId = world.Id,
                Name   = world.Name,
                Key    = Empty <byte> .Array,
            });
        }
示例#13
0
        public void Execute(Player player, string[] args)
        {
            var prtal = Portal.Resolve(0x1900);

            prtal.Move(player.X, player.Y);
            player.Owner.EnterWorld(prtal);
            World w = RealmManager.GetWorld(player.Owner.Id);

            w.Timers.Add(new WorldTimer(30 * 1000, (world, t) => //default portal close time * 1000

            {
                try
                {
                    w.LeaveWorld(prtal);
                }
                catch //couldn't remove portal, Owner became null. Should be fixed with RealmManager implementation
                {
                    Console.Out.WriteLine("Couldn't despawn portal.");
                }
            }));
            foreach (var i in RealmManager.Clients.Values)
            {
                i.SendPacket(new TextPacket()
                {
                    BubbleTime = 0,
                    Stars      = -1,
                    Name       = "",
                    Text       = "Arena Opened by:" + " " + player.nName
                });
            }
            foreach (var i in RealmManager.Clients.Values)
            {
                i.SendPacket(new NotificationPacket()
                {
                    Color    = new ARGB(0xff00ff00),
                    ObjectId = player.Id,
                    Text     = "Arena Opened by " + player.nName
                });
            }
        }
示例#14
0
 protected override void BehaveCore(BehaviorCondition cond, realm.RealmTime?time, object state)
 {
     if (new Random().Next(1, 100) <= percent)
     {
         Portal entity = Entity.Resolve(objType) as Portal;
         Entity parent = Host as Entity;
         entity.Move(parent.X, parent.Y);
         parent.Owner.EnterWorld(entity);
         World w = RealmManager.GetWorld(Host.Self.Owner.Id);
         w.Timers.Add(new WorldTimer(30 * 1000, (world, t) => //default portal close time * 1000
         {
             try
             {
                 w.LeaveWorld(entity);
             }
             catch //couldn't remove portal, Owner became null. Should be fixed with RealmManager implementation
             {
                 Program.logger.Error("Couldn't despawn portal.");
             }
         }));
     }
 }
示例#15
0
        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
                    Packet[] batch   = new Packet[21];
                    uint     s       = Random.CurrentSeed;
                    Random.CurrentSeed = (uint)(s * time.tickTimes);
                    for (int i = 0; i < 20; i++)
                    {
                        Projectile proj = CreateProjectile(prjDesc, item.ObjectType,
                                                           (int)statsMgr.GetAttackDamage(prjDesc.MinDamage, prjDesc.MaxDamage),
                                                           time.tickTimes, target, (float)(i * (Math.PI * 2) / 20));
                        Owner.EnterWorld(proj);
                        fames.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(0x000099)    //was 0xFFFF00AA
                    };
                    Owner.BroadcastPackets(batch, null);
                } break;

                case ActivateEffects.InvertNova:            //inverted spell bomb behavior. Spellbombs start on the outside and move into a center point. Good for older computers that cant do perfect spellbombs
                {
                    var      prjDesc = item.Projectiles[0]; //Assume only one
                    Packet[] batch   = new Packet[21];      //calls the shoot packet
                    uint     s       = Random.CurrentSeed;  //seeds the effects and position of effects
                    Random.CurrentSeed = (uint)(s * time.tickTimes);
                    for (int i = 0; i < 20; i++)            //this is how many bullets are shot, atm i can't get anymore or any less shots...
                    {
                        Projectile proj = CreateProjectile(prjDesc, item.ObjectType,
                                                           (int)statsMgr.GetAttackDamage(prjDesc.MinDamage, prjDesc.MaxDamage), //We can't have negative Pi?
                                                           time.tickTimes, target, (float)(i + (i * Math.PI) / 4));             //This is what divides the shots from the nova, here we can make it inverted
                        Owner.EnterWorld(proj);                                                                                 //the line above was (i * (Math.PI + 2) / 20)); //Took out Math.PI and put in the actual few numbers in pi to make it easier to use. However if you increase the range on spellbomb shots eventually the shots will become uneven because not using Math.PI; Math.PI uses EVERY infinite number, making each spellbomb 99.99999999999% accurate.
                        fames.Shoot(proj);
                        batch[i] = new ShootPacket()
                        {
                            BulletId      = proj.ProjectileId,
                            OwnerId       = Id,
                            ContainerType = item.ObjectType,
                            Position      = target,     //This plays a part of the positioning of the bullets
                            Angle         = proj.Angle, //And THIS helps angle all of the bullets correctly, but you can prolly leave it as proj.Angle
                            Damage        = (short)proj.Damage
                        };
                    }
                    Random.CurrentSeed = s;
                    batch[20]          = new ShowEffectPacket()
                    {
                        EffectType = EffectType.Trail,
                        PosA       = target,
                        TargetId   = Id,
                        Color      = new ARGB(0x00500)    //was 0xFFFF00AA
                    };
                    Owner.BroadcastPackets(batch, null);
                } break;

                case ActivateEffects.Shoot:
                {
                    ActivateShoot(time, item, target);
                } break;

                case ActivateEffects.StatBoostSelf:
                {
                    int 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;
                    }
                    int s = eff.Amount;
                    Boost[idx] += s;
                    UpdateCount++;
                    Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                        {
                            Boost[idx] -= s;
                            UpdateCount++;
                        }));
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Potion,
                            TargetId   = Id,
                            Color      = new ARGB(0xffffffff)
                        }, null);
                } break;

                case ActivateEffects.StatBoostAura:
                {
                    int 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;
                    }
                    int s = eff.Amount;
                    Behavior.AOE(Owner, this, eff.Range / 2, 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), //was 0xffffffff
                            PosA       = new Position()
                            {
                                X = eff.Range / 2
                            }
                        }, 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), //was 0xffffffff
                            PosA       = new Position()
                            {
                                X = 1
                            }
                        }, null);
                } break;

                case ActivateEffects.ConditionEffectAura:
                {
                    Behavior.AOE(Owner, this, eff.Range / 2, true, player =>
                        {
                            player.ApplyConditionEffect(new ConditionEffect()
                            {
                                Effect     = eff.ConditionEffect.Value,
                                DurationMS = eff.DurationMS
                            });
                        });
                    uint 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 / 2
                            }
                        }, null);
                } break;

                case ActivateEffects.Heal:
                {
                    List <Packet> pkts = new List <Packet>();
                    ActivateHealHp(this, eff.Amount, pkts);
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.HealNova:
                {
                    List <Packet> pkts = new List <Packet>();
                    Behavior.AOE(Owner, this, eff.Range / 2, 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 / 2
                            }
                        });
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.Magic:
                {
                    List <Packet> pkts = new List <Packet>();
                    ActivateHealMp(this, eff.Amount, pkts);
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.MagicNova:
                {
                    List <Packet> pkts = new List <Packet>();
                    Behavior.AOE(Owner, this, eff.Range / 2, 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 / 2
                            }
                        });
                    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(0x000000)     //was 0xFFFFFFFF
                            }
                        }, null);
                } break;

                case ActivateEffects.VampireBlast:
                {
                    List <Packet> pkts = new List <Packet>();
                    pkts.Add(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Trail,
                            TargetId   = Id,
                            PosA       = target,
                            Color      = new ARGB(0xFFFFFF) //was 0xFFFF0000
                        });
                    pkts.Add(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Diffuse,
                            Color      = new ARGB(0xFFFFFF), //was 0xFFFF0000
                            TargetId   = Id,
                            PosA       = target,
                            PosB       = new Position()
                            {
                                X = target.X + eff.Radius, Y = target.Y
                            }
                        });

                    int totalDmg = 0;
                    var enemies  = new List <Enemy>();
                    Behavior.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>();
                    Behavior.AOE(Owner, this, eff.Radius, true, player =>
                        {
                            players.Add(player as Player);
                            ActivateHealHp(player as Player, totalDmg, pkts);
                        });

                    Random rand = new System.Random();
                    for (int i = 0; i < 5; i++)
                    {
                        Enemy  a = enemies[rand.Next(0, enemies.Count)];
                        Player 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)     //was 0xffffffff
                            });
                    }

                    if (enemies.Count > 0)
                    {
                        Enemy  a = enemies[rand.Next(0, enemies.Count)];
                        Player 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:
                {
                    ARGB effColor = new ARGB(0x6600CC);         //was 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) =>
                        {
                            Trap 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:
                {
                    List <Packet> pkts     = new List <Packet>();
                    ARGB          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
                        });
                    Behavior.AOE(Owner, target, 3, false, enemy =>
                        {
                            if (enemy.HasConditionEffect(ConditionEffects.StasisImmune))
                            {
                                pkts.Add(new NotificationPacket()
                                {
                                    ObjectId = enemy.Id,
                                    Color    = new ARGB(0xff00ff00),  //was 0xff00ff00
                                    Text     = "Immune"
                                });
                            }
                            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),  //was 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;
                    double angle = Math.Atan2(target.Y - Y, target.X - X);
                    double diff  = Math.PI / 3;
                    Behavior.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;
                    }

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

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

                    List <Packet> pkts = new List <Packet>();
                    for (int i = 0; i < targets.Length; i++)
                    {
                        if (targets[i] == null)
                        {
                            break;
                        }
                        Entity 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)
                                });
                        }
                        ARGB shotColor = new ARGB(0x000000);         //was 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(0x006600), //was 0xffddff00
                                TargetId   = Id,
                                PosA       = target
                            }, null);
                        Placeholder 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 { Console.ForegroundColor = ConsoleColor.DarkRed;
                                        Console.Out.WriteLine("Crash halted - Nobody likes death...");
                                        Console.ForegroundColor = ConsoleColor.White; }
                                List <Enemy> enemies = new List <Enemy>();
                                Behavior.AOE(world, target, eff.Radius, false,
                                             enemy => PoisonEnemy(enemy as Enemy, eff));
                            }));
                    }
                    catch
                    {
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        Console.Out.WriteLine("Crash halted - Poison grenade??");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                } break;

                case ActivateEffects.RemoveNegativeConditions:
                {
                    Behavior.AOE(Owner, this, eff.Range / 2, true, player =>
                        {
                            ApplyConditionEffect(NegativeEffs);
                        });
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.AreaBlast,
                            TargetId   = Id,
                            Color      = new ARGB(0xffffffff),
                            PosA       = new Position()
                            {
                                X = eff.Range / 2
                            }
                        }, 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:
                {
                    int 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;
                    int limit = int.Parse(XmlDatas.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 (!XmlDatas.IdToType.TryGetValue(eff.Id, out objType) ||
                        !XmlDatas.PortalDescs.ContainsKey(objType))
                    {
                        break;        // object not found, ignore
                    }
                    var entity = Entity.Resolve(objType);
                    entity.Move(X, Y);
                    int    TimeoutTime = XmlDatas.PortalDescs[objType].TimeoutTime;
                    string DungName    = XmlDatas.PortalDescs[objType].DungeonName;

                    Owner.EnterWorld(entity);
                    ARGB c;
                    c.A = 0;
                    c.B = 91;
                    c.R = 233;
                    c.G = 176;
                    psr.SendPacket(new NotificationPacket()
                        {
                            Color    = c,
                            Text     = DungName + " opened by " + psr.Account.Name,
                            ObjectId = psr.Player.Id
                        });
                    World w = RealmManager.GetWorld(Owner.Id);     //can't use Owner here, as it goes out of scope
                    w.BroadcastPacket(new TextPacket()
                        {
                            BubbleTime = 0,
                            Stars      = -1,
                            Name       = "",
                            Text       = DungName + " opened by " + psr.Account.Name
                        }, null);
                    w.Timers.Add(new WorldTimer(TimeoutTime * 1000, (world, t) =>     //default portal close time * 1000
                        {
                            try
                            {
                                w.LeaveWorld(entity);
                            }
                            catch //couldn't remove portal, Owner became null. Should be fixed with RealmManager implementation
                            {
                                Console.WriteLine("Couldn't despawn portal.");
                            }
                        }));
                } break;

                case ActivateEffects.Dye:
                {
                    if (item.Texture1 != 0)
                    {
                        this.Texture1 = item.Texture1;
                    }
                    if (item.Texture2 != 0)
                    {
                        this.Texture2 = item.Texture2;
                    }
                    this.SaveToCharacter();
                } break;

                case ActivateEffects.ShurikenAbility:
                {
                    World w = RealmManager.GetWorld(Owner.Id);
                    ApplyConditionEffect(new ConditionEffect()
                        {
                            Effect     = ConditionEffectIndex.Speedy,
                            DurationMS = eff.DurationMS
                        });
                    w.Timers.Add(new WorldTimer(eff.DurationMS * 1000, (world, t) =>
                        {
                            try
                            {
                                ActivateShoot(time, item, target);
                            }
                            catch
                            {
                            }
                        }));
                } break;

                case ActivateEffects.TomeDamage:
                {
                    List <Packet> pkts = new List <Packet>();
                    Behavior.AOE(Owner, this, eff.Range / 2, false, enemy =>
                        {
                            (enemy as Enemy).Damage(this, time, (int)this.statsMgr.GetAttackDamage(eff.TotalDamage, eff.TotalDamage), false, new ConditionEffect[0]);
                        });
                    pkts.Add(new ShowEffectPacket()
                        {
                            EffectType = EffectType.AreaBlast,
                            TargetId   = Id,
                            Color      = new ARGB(0xFF00FF00),
                            PosA       = new Position()
                            {
                                X = eff.Range / 2
                            }
                        });
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.Mushroom:
                {
                    World 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.PermaPet: //petcode
                 *  {
                 *      psr.Character.Pet = XmlDatas.IdToType[eff.ObjectId];
                 *      GivePet(XmlDatas.IdToType[eff.ObjectId]);
                 *      UpdateCount++;
                 *  } break;
                 * case ActivateEffects.Pet: //Drakes*/
                case ActivateEffects.UnlockPortal:
                    break;
                }
            }
            UpdateCount++;
        }
示例#16
0
        public void UsePortal(RealmTime time, UsePortalPacket pkt)
        {
            var entity = Owner.GetEntity(pkt.ObjectId);

            if (entity == null || !entity.Usable)
            {
                return;
            }
            World  world  = null;
            var    player = this;
            Portal p      = null;

            if (entity is Portal)
            {
                p     = entity as Portal;
                world = p.WorldInstance;
            }
            if (world == null)
            {
                if (p != null)
                {
                    var setWorldInstance = true;
                    var d = "";
                    if (XmlDatas.IdToDungeon.TryGetValue(entity.ObjectType, out d))
                    {
                        world = RealmManager.AddWorld(new XmlWorld(XmlDatas.DungeonDescs[d]));
                    }
                    else
                    {
                        switch (entity.ObjectType) //handling default case for not found. Add more as implemented
                        {
                        case 0x0703:               //portal of cowardice
                        {
                            if (RealmManager.PlayerWorldMapping.ContainsKey(AccountId))
                            {
                                //may not be valid, realm recycled?
                                world = RealmManager.PlayerWorldMapping[AccountId];
                            }
                            //also reconnecting to vault is a little unexpected
                            else if (world.Id == -5 || world.Id == -11)
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                            else
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                        }
                        break;

                        case 0x0d40:
                        {
                            if (RealmManager.PlayerWorldMapping.ContainsKey(AccountId))
                            {
                                //may not be valid, realm recycled?
                                world = RealmManager.PlayerWorldMapping[AccountId];
                            }
                            //also reconnecting to vault is a little unexpected
                            else if (world.Id == -5 || world.Id == -11)
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                            else
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                        }
                        break;

                        case 0x0712:
                            world = RealmManager.GetWorld(World.NEXUS_ID);
                            break;

                        case 0x071d:
                            world = RealmManager.GetWorld(World.NEXUS_ID);
                            break;

                        case 0x071c:
                            world = RealmManager.Monitor.GetRandomRealm();
                            break;

                        case 0x0720:
                            world            = RealmManager.PlayerVault(psr);
                            setWorldInstance = false;
                            break;

                        case 0x071e:
                            world = RealmManager.AddWorld(new Kitchen());
                            break;

                        case 0x0ffa:     //these need to match IDs
                            //world = RealmManager.GetWorld(World.GauntletMap); break; //this creates a singleton dungeon
                            world = RealmManager.AddWorld(new Island());
                            break;     //this allows each dungeon to be unique

                        case 0x0ffc:
                            world = RealmManager.AddWorld(new WineCellarMap());
                            break;

                        case 0x1900:
                            world = RealmManager.AddWorld(new ArenaMap());
                            break;

                        case 0x0730:
                            world = RealmManager.AddWorld(new OceanTrench());
                            break;

                        case 0x070c:
                            world = RealmManager.AddWorld(new SpriteWorld());
                            break;

                        case 0x071b:
                            world = RealmManager.AddWorld(new Abyss());
                            break;

                        case 0x071a:
                            world = RealmManager.AddWorld(new UndeadLair());
                            break;

                        case 0x1901:
                            world = RealmManager.AddWorld(new VoidWorld());
                            break;

                        case 0x072c:
                            world = RealmManager.AddWorld(new TombMap());
                            break;

                        case 0x1905:
                        {
                            psr.SendPacket(new TextBoxPacket
                                {
                                    Button1 = "Enter",
                                    Button2 = "Cancel",
                                    Message = "Join the arena at the price of 150 fame?",
                                    Title   = "Arena Confirmation",
                                    Type    = "EnterArena1"
                                });
                        }
                        break;

                        case 0x1908:

                            psr.SendPacket(new TextBoxPacket
                            {
                                Button1 = "Enter",
                                Button2 = "Cancel",
                                Message = "Join the free arena?",
                                Title   = "Arena Confirmation",
                                Type    = "EnterArena2"
                            });
                            break;

                        case 0x0742:
                            world = RealmManager.AddWorld(new BeachZone());
                            break;

                        case 0x0718:
                            world = RealmManager.AddWorld(new SnakePit());
                            break;

                        case 0x0890:
                            world = RealmManager.AddWorld(new MadLabMap());
                            break;

                        case 0x1919:
                            world = RealmManager.AddWorld(new Secret());
                            break;

                        case 0x1923:
                            world = RealmManager.AddWorld(new ZombieMap());
                            break;

                        default:
                            SendError("Portal Not Implemented!");
                            break;

                        case 0x195d:
                            world = RealmManager.AddWorld(new MarketMap());
                            break;

                        case 0x070d:
                            world = RealmManager.Monitor.GetRandomRealm();
                            break;

                        case 0x070e:
                            world = RealmManager.Monitor.GetRandomRealm();
                            break;

                        case 0x0704:
                            world = RealmManager.Monitor.GetRandomRealm();
                            break;

                        case 0x753E:
                            world = RealmManager.AddWorld(new LairofDraconis());
                            break;

                        case 0x7002:
                            world = RealmManager.AddWorld(new PartyCellarMap());
                            break;

                        case 0x701c:
                        {
                            psr.SendPacket(new TextBoxPacket
                                {
                                    Button1 = "Enter",
                                    Button2 = "Cancel",
                                    Message = "Join sheep herding at the price of 500 fame?",
                                    Title   = "Sheep Herding",
                                    Type    = "SheepHerding"
                                });
                        }
                        break;

                        case 0x7024:
                        {
                            psr.SendPacket(new TextBoxPacket
                                {
                                    Button1 = "Yes",
                                    Button2 = "Cancel",
                                    Message = "Join zombies at the price of 100 fame?",
                                    Title   = "Zombies",
                                    Type    = "Zombies"
                                });
                        }
                        break;

                        case 0x4a2b:
                        {
                            psr.SendPacket(new TextBoxPacket
                                {
                                    Button1 = "Yes",
                                    Button2 = "Cancel",
                                    Message = "Sorry, this isn't quite done yet. Look forward to it, though.",
                                    Title   = "Nexus Defense",
                                    Type    = "Nexus Defense"
                                });
                        }
                        break;

                        case 0x7025:
                            world = RealmManager.AddWorld(new ForestMap());
                            break;

                        case 0x4a29:
                            world = RealmManager.AddWorld(new ChristmasCellarMap());
                            break;

                        case 0x4a2a:
                            world = RealmManager.AddWorld(new TurkeyMap());
                            break;

                        case 0x5050:
                            world = RealmManager.AddWorld(new Shatters());
                            break;

                        case 0x2fbb:
                            world = RealmManager.AddWorld(new EC());
                            break;

                        case 0x0d7b:
                            world = RealmManager.AddWorld(new OryxChamberMap());
                            break;
                        }
                    }
                    if (setWorldInstance)
                    {
                        p.WorldInstance = world;
                    }
                }
                else
                {
                    switch (entity.ObjectType) // Special Portals that cannot be the portal class
                    {
                    case 0x072f:
                        world = RealmManager.GuildHallWorld(Guild);
                        break;

                    default:
                        psr.SendPacket(new TextPacket
                        {
                            BubbleTime = 0,
                            Stars      = -1,
                            Name       = "",
                            Text       = "Semi-Portal Not Implemented!"
                        });
                        break;
                    }
                }
            }

            //used to match up player to last realm they were in, to return them to it. Sometimes is odd, like from Vault back to Vault...

            if (RealmManager.PlayerWorldMapping.ContainsKey(AccountId))
            {
                World tempWorld;
                RealmManager.PlayerWorldMapping.TryRemove(AccountId, out tempWorld);
            }
            RealmManager.PlayerWorldMapping.TryAdd(AccountId, Owner);
            psr.Reconnect(new ReconnectPacket
            {
                Host   = "",
                Port   = 2050,
                GameId = world.Id,
                Name   = world.Name,
                Key    = Empty <byte> .Array,
            });
        }
示例#17
0
        public void TextBoxButton(TextBoxButtonPacket pkt)
        {
            var type = pkt.Type;

            if (type == "test")
            {
                psr.SendPacket(new TextBoxPacket
                {
                    Button1 = "Yes",
                    Button2 = "No",
                    Message = "Do you want to enter the testing arena?",
                    Title   = "Testing Arena Confirmation",
                    Type    = "EnterTestArena"
                });
            }
            if (type == "NewClient")
            {
                psr.Disconnect();
            }
            if (type == "DecideArena")
            {
                if (pkt.Button == 1)
                {
                    psr.SendPacket(new TextBoxPacket
                    {
                        Button1 = "Enter",
                        Button2 = "Cancel",
                        Message = "Host an arena at the price of x fame?",
                        Title   = "Arena Host Confirmation",
                        Type    = "EnterArena2"
                    });
                }
                else
                {
                    psr.SendPacket(new TextBoxPacket
                    {
                        Button1 = "Enter",
                        Button2 = "Cancel",
                        Message = "Enter the arena solo at the price of 150 fame?",
                        Title   = "Solo Arena Confirmation",
                        Type    = "EnterArena1"
                    });
                }
            }
            if (type == "EnterTestArena")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 150)
                    {
                        /*RealmManager.PlayerWorldMapping.TryAdd(this.AccountId, Owner);
                         * psr.Reconnect(new ReconnectPacket()
                         * {
                         *  Host = "",
                         *  Port = 2050,
                         *  GameId = world.Id,
                         *  Name = world.Name,
                         *  Key = Empty<byte>.Array,
                         * });
                         */
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "EnterArena1")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 150)
                    {
                        using (var db = new Database())
                        {
                            db.UpdateFame(psr.Account, -150);
                            db.Dispose();
                        }

                        var world  = RealmManager.GetWorld(World.NEXUS_ID);
                        var fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is BattleArenaMap)
                            {
                                if ((i.Value as BattleArenaMap).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new BattleArenaMap());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "EnterArena2")
            {
                if (pkt.Button == 1)
                {
                    var world  = RealmManager.GetWorld(World.NEXUS_ID);
                    var fworld = false;
                    foreach (var i in RealmManager.Worlds)
                    {
                        if (i.Value is BattleArenaMap2)
                        {
                            if ((i.Value as BattleArenaMap2).Joinable)
                            {
                                world  = i.Value;
                                fworld = true;
                                break;
                            }
                        }
                    }
                    if (!fworld)
                    {
                        world = RealmManager.AddWorld(new BattleArenaMap2());
                    }

                    psr.Reconnect(new ReconnectPacket
                    {
                        Host   = "",
                        Port   = 2050,
                        GameId = world.Id,
                        Name   = world.Name,
                        Key    = Empty <byte> .Array,
                    });
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "SheepHerding")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 500)
                    {
                        using (var db = new Database())
                        {
                            db.UpdateFame(psr.Account, -500);
                            db.Dispose();
                        }

                        var world  = RealmManager.GetWorld(World.NEXUS_ID);
                        var fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is Herding)
                            {
                                if ((i.Value as Herding).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new Herding());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering sheep herding.");
                }
            }
            if (type == "Zombies")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 100)
                    {
                        using (var db = new Database())
                        {
                            db.UpdateFame(psr.Account, -100);
                            db.Dispose();
                        }

                        var world  = RealmManager.GetWorld(World.NEXUS_ID);
                        var fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is ZombieMG)
                            {
                                if ((i.Value as ZombieMG).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new ZombieMG());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering zombies.");
                }
            }
            if (type == "SlotMachine1")
            {
                if (pkt.Button == 1)
                {
                    var weaponsT5   = TierLoot.WeaponItems[5].ToList();
                    var weaponsT6   = TierLoot.WeaponItems[6].ToList();
                    var weaponsT7   = TierLoot.WeaponItems[7].ToList();
                    var abilitiesT3 = TierLoot.AbilityItems[2].ToList();
                    var ringsT3     = TierLoot.RingItems[3].ToList();
                    var armorT6     = TierLoot.ArmorItems[6].ToList();
                    var armorT7     = TierLoot.ArmorItems[7].ToList();
                    var armorT8     = TierLoot.ArmorItems[8].ToList();

                    var calculator = Random.Next(1, 1000);
                    if (calculator <= 600)
                    {
                        SendHelp("Better luck next time!");
                    }
                    else if (calculator <= 700 && calculator > 600)
                    {
                        SendHelp("Congratulations! You won a T5 Weapon!");

                        weaponsT5.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT5[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 750 && calculator > 700)
                    {
                        SendHelp("Congratulations! You won a T6 Weapon!");

                        weaponsT6.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT6[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 787.5 && calculator > 775)
                    {
                        SendHelp("Congratulations! You won a T7 Weapon!");

                        weaponsT7.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT7[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 800 && calculator > 787.5)
                    {
                        SendHelp("Congratulations! You won a T3 Ability!");

                        abilitiesT3.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = abilitiesT3[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 850 && calculator > 800)
                    {
                        SendHelp("Congratulations! You won a T6 Armor!");

                        armorT6.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT6[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 875 && calculator > 850)
                    {
                        SendHelp("Congratulations! You won a T7 Armor!");

                        armorT7.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT7[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 887.5 && calculator > 875)
                    {
                        SendHelp("Congratulations! You won a T8 Armor!");

                        armorT8.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT8[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 900 && calculator > 887.5)
                    {
                        SendHelp("Congratulations! You won a T3 Ring!");

                        ringsT3.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = ringsT3[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 905 && calculator > 900)
                    {
                        SendHelp("Too bad! You only got 1 fame!");
                        Client.Database.UpdateFame(Client.Account, 1);
                        Fame += 1;
                        UpdateCount++;
                    }
                    else if (calculator <= 910 && calculator > 905)
                    {
                        SendHelp("Too bad! You only got 5 fame!");
                        Client.Database.UpdateFame(Client.Account, 5);
                        Fame += 5;
                        UpdateCount++;
                    }
                    else if (calculator <= 940 && calculator > 910)
                    {
                        SendHelp("You won back the fame you paid!");
                        Client.Database.UpdateFame(Client.Account, 10);
                        Fame += 10;
                        UpdateCount++;
                    }
                    else if (calculator <= 970 && calculator > 940)
                    {
                        SendHelp("Nice! You won 25 fame!");
                        Client.Database.UpdateFame(Client.Account, 25);
                        Fame += 25;
                        UpdateCount++;
                    }
                    else if (calculator <= 985 && calculator > 970)
                    {
                        SendHelp("Nice! You won 50 fame!");
                        Client.Database.UpdateFame(Client.Account, 50);
                        Fame += 50;
                        UpdateCount++;
                    }
                    else if (calculator <= 990 && calculator > 985)
                    {
                        SendHelp("Very Nice! You won 100 fame!");
                        Client.Database.UpdateFame(Client.Account, 100);
                        Fame += 100;
                        UpdateCount++;
                    }
                    else if (calculator <= 994 && calculator > 990)
                    {
                        SendHelp("Awesome! You won 500 fame!");
                        Client.Database.UpdateFame(Client.Account, 500);
                        Fame += 500;
                        UpdateCount++;
                    }
                    else if (calculator <= 997 && calculator > 994)
                    {
                        SendHelp("Amazing! You won 1000 fame!");
                        Client.Database.UpdateFame(Client.Account, 1000);
                        Fame += 1000;
                        UpdateCount++;
                    }
                    else if (calculator <= 999 && calculator > 997)
                    {
                        SendHelp("Amazing! You won 5000 fame!");
                        Client.Database.UpdateFame(Client.Account, 5000);
                        Fame += 5000;
                        UpdateCount++;
                    }
                    else if (calculator <= 1000 && calculator > 999)
                    {
                        SendHelp("Incredible! You won the 10000 fame jackpot!");
                        foreach (var i in RealmManager.Clients.Values)
                        {
                            i.SendPacket(new TextPacket
                            {
                                BubbleTime = 0,
                                Stars      = -1,
                                Name       = "#Announcement",
                                Text       = Name + " has won the 10000 Fame jackpot on the bronze slot machines!"
                            });
                        }
                        Client.Database.UpdateFame(Client.Account, 10000);
                        Fame += 10000;
                        UpdateCount++;
                    }
                    psr.SendPacket(new BuyResultPacket
                    {
                        Result = 0
                    });
                }
                else
                {
                    SendInfo("Canceled");
                    psr.SendPacket(new BuyResultPacket
                    {
                        Result = 0
                    });
                }
            }
        }
示例#18
0
        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
                    Packet[] batch   = new Packet[21];
                    uint     s       = Random.CurrentSeed;
                    Random.CurrentSeed = (uint)(s * time.tickTimes);
                    for (int i = 0; i < 20; i++)
                    {
                        Projectile proj = CreateProjectile(prjDesc, item.ObjectType,
                                                           (int)statsMgr.GetAttackDamage(prjDesc.MinDamage, prjDesc.MaxDamage),
                                                           time.tickTimes, target, (float)(i * (Math.PI * 2) / 20));
                        Owner.EnterWorld(proj);
                        fames.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.StatBoostSelf:
                {
                    int 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;
                    }
                    int s = eff.Amount;
                    Boost[idx] += s;
                    UpdateCount++;
                    Owner.Timers.Add(new WorldTimer(eff.DurationMS, (world, t) =>
                        {
                            Boost[idx] -= s;
                            UpdateCount++;
                        }));
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Potion,
                            TargetId   = Id,
                            Color      = new ARGB(0xffffffff)
                        }, null);
                } break;

                case ActivateEffects.StatBoostAura:
                {
                    int 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;
                    }
                    int s = eff.Amount;
                    Behavior.AOE(Owner, this, eff.Range / 2, 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 / 2
                            }
                        }, 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:
                {
                    Behavior.AOE(Owner, this, eff.Range / 2, true, player =>
                        {
                            player.ApplyConditionEffect(new ConditionEffect()
                            {
                                Effect     = eff.ConditionEffect.Value,
                                DurationMS = eff.DurationMS
                            });
                        });
                    uint 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 / 2
                            }
                        }, null);
                } break;

                case ActivateEffects.Heal:
                {
                    List <Packet> pkts = new List <Packet>();
                    ActivateHealHp(this, eff.Amount, pkts);
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.HealNova:
                {
                    List <Packet> pkts = new List <Packet>();
                    Behavior.AOE(Owner, this, eff.Range / 2, 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 / 2
                            }
                        });
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.Magic:
                {
                    List <Packet> pkts = new List <Packet>();
                    ActivateHealMp(this, eff.Amount, pkts);
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.MagicNova:
                {
                    List <Packet> pkts = new List <Packet>();
                    Behavior.AOE(Owner, this, eff.Range / 2, 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 / 2
                            }
                        });
                    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:
                {
                    List <Packet> pkts = new List <Packet>();
                    pkts.Add(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Trail,
                            TargetId   = Id,
                            PosA       = target,
                            Color      = new ARGB(0xFFFF0000)
                        });
                    pkts.Add(new AOEPacket()
                        {
                            Position       = target,
                            Radius         = eff.Radius,
                            Damage         = (ushort)eff.TotalDamage,
                            EffectDuration = 0,
                            Effects        = 0,
                            OriginType     = item.ObjectType
                        });

                    int totalDmg = 0;
                    var enemies  = new List <Enemy>();
                    Behavior.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>();
                    Behavior.AOE(Owner, this, eff.Radius, true, player =>
                        {
                            players.Add(player as Player);
                            ActivateHealHp(player as Player, totalDmg, pkts);
                        });

                    Random rand = new System.Random();
                    for (int i = 0; i < 5; i++)
                    {
                        Enemy  a = enemies[rand.Next(0, enemies.Count)];
                        Player 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:
                {
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Throw,
                            Color      = new ARGB(0xff9000ff),
                            TargetId   = Id,
                            PosA       = target
                        }, null);
                    Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                        {
                            Trap 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:
                {
                    List <Packet> pkts = new List <Packet>();

                    pkts.Add(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Concentrate,
                            TargetId   = Id,
                            PosA       = target,
                            PosB       = new Position()
                            {
                                X = target.X + 3, Y = target.Y
                            },
                            Color = new ARGB(0xffffffff)
                        });
                    Behavior.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.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.Lightning:
                {
                    Enemy  start = null;
                    double angle = Math.Atan2(target.Y - Y, target.X - X);
                    double diff  = Math.PI / 3;
                    Behavior.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;
                    }

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

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

                    List <Packet> pkts = new List <Packet>();
                    for (int i = 0; i < targets.Length; i++)
                    {
                        if (targets[i] == null)
                        {
                            break;
                        }
                        Entity prev = i == 0 ? (Entity)this : targets[i - 1];
                        targets[i].Damage(this, time, eff.TotalDamage, false);
                        if (eff.ConditionEffect != null)         //Start of the code made by ossimc82
                        {
                            targets[i].ApplyConditionEffect(new ConditionEffect()
                                {
                                    Effect     = eff.ConditionEffect.Value,
                                    DurationMS = (int)(eff.EffectDuration * 1000)
                                });    //End of the code made by ossimc82
                        }
                        pkts.Add(new ShowEffectPacket()
                            {
                                EffectType = EffectType.Lightning,
                                TargetId   = prev.Id,
                                Color      = new ARGB(0xffff0088),
                                PosA       = new Position()
                                {
                                    X = targets[i].X,
                                    Y = targets[i].Y
                                },
                                PosB = new Position()
                                {
                                    X = 350
                                }
                            });
                    }
                    Owner.BroadcastPackets(pkts, null);
                } break;

                case ActivateEffects.PoisonGrenade:
                {
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.Throw,
                            Color      = new ARGB(0xffddff00),
                            TargetId   = Id,
                            PosA       = target
                        }, null);
                    Placeholder x = new Placeholder(1500);
                    x.Move(target.X, target.Y);
                    Owner.EnterWorld(x);
                    Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                        {
                            Owner.BroadcastPacket(new ShowEffectPacket()
                            {
                                EffectType = EffectType.AreaBlast,
                                Color      = new ARGB(0xffddff00),
                                TargetId   = x.Id,
                                PosA       = new Position()
                                {
                                    X = eff.Radius
                                }
                            }, null);
                            List <Enemy> enemies = new List <Enemy>();
                            Behavior.AOE(world, target, eff.Radius, false,
                                         enemy => PoisonEnemy(enemy as Enemy, eff));
                        }));
                } break;

                case ActivateEffects.RemoveNegativeConditions:
                {
                    Behavior.AOE(Owner, this, eff.Range / 2, true, player =>
                        {
                            ApplyConditionEffect(NegativeEffs);
                        });
                    Owner.BroadcastPacket(new ShowEffectPacket()
                        {
                            EffectType = EffectType.AreaBlast,
                            TargetId   = Id,
                            Color      = new ARGB(0xffffffff),
                            PosA       = new Position()
                            {
                                X = eff.Range / 2
                            }
                        }, 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:
                {
                    int 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;
                    int limit = int.Parse(XmlDatas.TypeToElement[ObjectType].Element(StatsManager.StatsIndexToName(idx)).Attribute("max").Value);
                    if (Stats[idx] > limit)
                    {
                        Stats[idx] = limit;
                    }
                    UpdateCount++;
                } break;

                case ActivateEffects.Pet:
                case ActivateEffects.Create:     //portals
                {
                    short objType;
                    if (!XmlDatas.IdToType.TryGetValue(eff.Id, out objType))
                    {
                        /*!XmlDatas.PortalDescs.ContainsKey(objType))*/
                        break;        // object not found, ignore
                    }
                    var entity = Entity.Resolve(objType);
                    entity.Move(X, Y);
                    int TimeoutTime = 20;    //XmlDatas.PortalDescs[objType].TimeoutTime;
                    var dungeonname = 0;
                    Owner.EnterWorld(entity);
                    ARGB c;
                    c.A = 0;
                    c.B = 0;
                    c.G = 255;
                    c.R = 0;
                    //psr.SendPacket(new BuyResultPacket()
                    //{
                    //    Color = c,
                    //    Text = "Opened by " + psr.Account.Name
                    //});
                    psr.SendPacket(new NotificationPacket()
                        {
                            Color    = c,
                            Text     = "Opened by " + psr.Account.Name,
                            ObjectId = psr.Player.Id
                        });
                    World w = RealmManager.GetWorld(Owner.Id);     //can't use Owner here, as it goes out of scope
                    w.BroadcastPacket(new TextPacket()
                        {
                            BubbleTime = 0,
                            Stars      = -1,
                            Name       = "",
                            Text       = "Opened by " + psr.Account.Name
                        }, null);
                    w.Timers.Add(new WorldTimer(TimeoutTime * 1000, (world, t) =>     //default portal close time * 1000
                        {
                            try
                            {
                                w.LeaveWorld(entity);
                            }
                            catch //couldn't remove portal, Owner became null. Should be fixed with RealmManager implementation
                            {
                                Console.WriteLine("Couldn't despawn portal.");
                            }
                        }));
                } break;

                case ActivateEffects.UnlockPortal:
                {
                    break;
                }

                case ActivateEffects.Dye:
                {
                    if (item.Texture1 != "0")
                    {
                        psr.Player.Texture1 = db.dyes_hextointmod.hextoint(item.Texture1.ToString(), item.Cloth);
                    }
                    if (item.Texture2 != "0")
                    {
                        psr.Player.Texture2 = db.dyes_hextointmod.hextoint(item.Texture2.ToString(), item.Cloth);
                    }
                    this.SaveToCharacter();
                    UpdateCount++;
                }
                break;
                }
            }
            UpdateCount++;
        }
示例#19
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            Console.WriteLine("Accepting new client...");
            db0 = new Database();
            if ((account = db0.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                //Database.SaveCharacter(account, Database.CreateCharacter(782, 1));
                //Database.Register(pkt.GUID, pkt.Password, true);

                if (account == null)
                {
                    Console.WriteLine("Account is null");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });

                    return;
                }
            }
            if (db0.isWhitelisted(db0.Verify(pkt.GUID, pkt.Password)) == false)
            {
                Console.WriteLine("Not whitelisted account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "You are not whitelisted!"
                });
                //eventual account ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            if (db0.isBanned(db0.Verify(pkt.GUID, pkt.Password)) == true)
            {
                Console.WriteLine("Banned account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Your account is banned!"
                });
                //eventual IP ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            Console.WriteLine("Client trying to connect");
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Console.WriteLine("Failed to connect.");
            }
            else
            {
                Console.WriteLine("Client loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Console.WriteLine("Invalid world");
                }
                else
                {
                    Console.WriteLine("Client joined world " + world.Id.ToString());
                    if (world.Id == -6) //Test World
                    {
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    }
                    else if (world.IsLimbo)
                    {
                        world = world.GetInstance(this);
                    }

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random      = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width         = world.Map.Width,
                        Height        = world.Map.Height,
                        Name          = world.Name,
                        Seed          = seed,
                        Background    = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays  = world.ShowDisplays,
                        ClientXML     = world.ClientXML,
                        ExtraXML      = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                    Console.WriteLine("End of client world packet");
                }
            }
        }
        public void TextBoxButton(TextBoxButtonPacket pkt)
        {
            string type = pkt.Type;

            if (type == "test")
            {
                psr.SendPacket(new TextBoxPacket
                {
                    Button1 = "Yes",
                    Button2 = "No",
                    Message = "Do you want to enter the testing arena?",
                    Title   = "Testing Arena Confirmation",
                    Type    = "EnterTestArena"
                });
            }
            if (type == "NewClient")
            {
                psr.Disconnect();
            }
            if (type == "DecideArena")
            {
                if (pkt.Button == 1)
                {
                    psr.SendPacket(new TextBoxPacket
                    {
                        Button1 = "Enter",
                        Button2 = "Cancel",
                        Message = "Host an arena at the price of x fame?",
                        Title   = "Arena Host Confirmation",
                        Type    = "EnterArena2"
                    });
                }
                else
                {
                    psr.SendPacket(new TextBoxPacket
                    {
                        Button1 = "Enter",
                        Button2 = "Cancel",
                        Message = "Enter the arena solo at the price of 150 fame?",
                        Title   = "Solo Arena Confirmation",
                        Type    = "EnterArena1"
                    });
                }
            }
            if (type.Split(':')[0] == "ConfirmBan")
            {
                string pName = type.Split(':')[1];
                if (pkt.Button == 2)
                {
                    return;
                }
                if (psr.Account.Rank < 2)
                {
                    SendError("You do not have permission to ban!");
                    return;
                }
                Player target;
                if ((target = RealmManager.FindPlayer(pName)) != null)
                {
                    if (target.Client.Account.Rank > psr.Account.Rank)
                    {
                        SendError("You cannot ban someone higher than you!");
                        return;
                    }
                    MySqlCommand cmd;
                    using (var db = new Database())
                        cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET banned=1, rank=0 WHERE name=@name";
                    cmd.Parameters.AddWithValue("@name", target.Client.Account.Name);
                    if (cmd.ExecuteNonQuery() == 0)
                    {
                        SendError("Ban failed for some reason");
                        return;
                    }
                    target.Client.Disconnect();
                    SendInfo(pName + " successfully banned!");
                }
            }
            if (type.Split(':')[0] == "ConfirmIPBan")
            {
                string pName = type.Split(':')[1];
                if (pkt.Button == 2)
                {
                    return;
                }
                if (psr.Account.Rank < 2)
                {
                    SendError("You do not have permission to ban!");
                    return;
                }
                Player target;
                if ((target = RealmManager.FindPlayer(pName)) != null)
                {
                    if (target.Client.Account.Rank > psr.Account.Rank)
                    {
                        SendError("You cannot ban someone higher than you!");
                        return;
                    }

                    string       address = target.Client.IP.Address;
                    MySqlCommand cmd;
                    using (var db = new Database())
                        cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE ips SET banned=1 WHERE ip=@Adress";
                    cmd.Parameters.AddWithValue("Adress", target.Client.IP.Address);
                    if (cmd.ExecuteNonQuery() == 0)
                    {
                        SendInfo("Could not ban");
                        return;
                    }

                    target.Client.Disconnect();
                    SendInfo("IP successfully Banned");
                }
            }


            if (type == "EnterTestArena")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 150)
                    {
                        /*RealmManager.PlayerWorldMapping.TryAdd(this.AccountId, Owner);
                         * psr.Reconnect(new ReconnectPacket()
                         * {
                         *  Host = "",
                         *  Port = 2050,
                         *  GameId = world.Id,
                         *  Name = world.Name,
                         *  Key = Empty<byte>.Array,
                         * });
                         */
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "EnterArena1")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 150)
                    {
                        using (var db = new Database())
                            db.UpdateFame(psr.Account, -150);

                        World world  = RealmManager.GetWorld(World.NEXUS_ID);
                        bool  fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is BattleArenaMap)
                            {
                                if ((i.Value as BattleArenaMap).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new BattleArenaMap());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "EnterArena2")
            {
                if (pkt.Button == 1)
                {
                    World world  = RealmManager.GetWorld(World.NEXUS_ID);
                    bool  fworld = false;
                    foreach (var i in RealmManager.Worlds)
                    {
                        if (i.Value is BattleArenaMap2)
                        {
                            if ((i.Value as BattleArenaMap2).Joinable)
                            {
                                world  = i.Value;
                                fworld = true;
                                break;
                            }
                        }
                    }
                    if (!fworld)
                    {
                        world = RealmManager.AddWorld(new BattleArenaMap2());
                    }

                    psr.Reconnect(new ReconnectPacket
                    {
                        Host   = "",
                        Port   = 2050,
                        GameId = world.Id,
                        Name   = world.Name,
                        Key    = Empty <byte> .Array,
                    });
                }
                else
                {
                    SendInfo("Cancelled entering arena.");
                }
            }
            if (type == "SheepHerding")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 500)
                    {
                        using (var db = new Database())
                            db.UpdateFame(psr.Account, -500);

                        World world  = RealmManager.GetWorld(World.NEXUS_ID);
                        bool  fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is Herding)
                            {
                                if ((i.Value as Herding).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new Herding());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering sheep herding.");
                }
            }
            if (type == "Zombies")
            {
                if (pkt.Button == 1)
                {
                    if (Client.Account.Stats.Fame >= 100)
                    {
                        using (var db = new Database())
                            db.UpdateFame(psr.Account, -100);

                        World world  = RealmManager.GetWorld(World.NEXUS_ID);
                        bool  fworld = false;
                        foreach (var i in RealmManager.Worlds)
                        {
                            if (i.Value is ZombieMG)
                            {
                                if ((i.Value as ZombieMG).Joinable)
                                {
                                    world  = i.Value;
                                    fworld = true;
                                    break;
                                }
                            }
                        }
                        if (!fworld)
                        {
                            world = RealmManager.AddWorld(new ZombieMG());
                        }

                        psr.Reconnect(new ReconnectPacket
                        {
                            Host   = "",
                            Port   = 2050,
                            GameId = world.Id,
                            Name   = world.Name,
                            Key    = Empty <byte> .Array,
                        });
                    }
                    else
                    {
                        SendHelp("Not Enough Fame");
                    }
                }
                else
                {
                    SendInfo("Cancelled entering zombies.");
                }
            }
            if (type == "Nexus Defense")
            {
                if (pkt.Button == 1)
                {
                    SendInfo("Cancelled entering Nexus Defense.");
                }
                else
                {
                    SendInfo("Cancelled entering Nexus Defense.");
                }
            }
            if (type == "SlotMachine1")
            {
                if (pkt.Button == 1)
                {
                    List <Item> weaponsT5   = TierLoot.WeaponItems[5].ToList();
                    List <Item> weaponsT6   = TierLoot.WeaponItems[6].ToList();
                    List <Item> weaponsT7   = TierLoot.WeaponItems[7].ToList();
                    List <Item> abilitiesT3 = TierLoot.AbilityItems[2].ToList();
                    List <Item> ringsT3     = TierLoot.RingItems[3].ToList();
                    List <Item> armorT6     = TierLoot.ArmorItems[6].ToList();
                    List <Item> armorT7     = TierLoot.ArmorItems[7].ToList();
                    List <Item> armorT8     = TierLoot.ArmorItems[8].ToList();

                    int calculator = Random.Next(1, 1000);
                    if (calculator <= 600)
                    {
                        SendHelp("Better luck next time!");
                    }
                    else if (calculator <= 700 && calculator > 600)
                    {
                        SendHelp("Congratulations! You won a T5 Weapon!");

                        weaponsT5.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT5[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 750 && calculator > 700)
                    {
                        SendHelp("Congratulations! You won a T6 Weapon!");

                        weaponsT6.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT6[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 787.5 && calculator > 775)
                    {
                        SendHelp("Congratulations! You won a T7 Weapon!");

                        weaponsT7.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = weaponsT7[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 800 && calculator > 787.5)
                    {
                        SendHelp("Congratulations! You won a T3 Ability!");

                        abilitiesT3.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = abilitiesT3[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 850 && calculator > 800)
                    {
                        SendHelp("Congratulations! You won a T6 Armor!");

                        armorT6.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT6[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 875 && calculator > 850)
                    {
                        SendHelp("Congratulations! You won a T7 Armor!");

                        armorT7.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT7[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 887.5 && calculator > 875)
                    {
                        SendHelp("Congratulations! You won a T8 Armor!");

                        armorT8.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = armorT8[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 900 && calculator > 887.5)
                    {
                        SendHelp("Congratulations! You won a T3 Ring!");

                        ringsT3.Shuffle();

                        var container = new Container(0x0507, 1000 * 60, true)
                        {
                            BagOwner = psr.Account.AccountId
                        };
                        container.Inventory[0] = ringsT3[0];
                        container.Move(X + (float)((invRand.NextDouble() * 2 - 1) * 0.5),
                                       Y + (float)((invRand.NextDouble() * 2 - 1) * 0.5));
                        container.Size = 75;
                        Owner.EnterWorld(container);
                    }
                    else if (calculator <= 905 && calculator > 900)
                    {
                        SendHelp("Too bad! You only got 1 fame!");
                        Client.Database.UpdateFame(Client.Account, 1);
                        Fame += 1;
                        UpdateCount++;
                    }
                    else if (calculator <= 910 && calculator > 905)
                    {
                        SendHelp("Too bad! You only got 5 fame!");
                        Client.Database.UpdateFame(Client.Account, 5);
                        Fame += 5;
                        UpdateCount++;
                    }
                    else if (calculator <= 940 && calculator > 910)
                    {
                        SendHelp("You won back the fame you paid!");
                        Client.Database.UpdateFame(Client.Account, 10);
                        Fame += 10;
                        UpdateCount++;
                    }
                    else if (calculator <= 970 && calculator > 940)
                    {
                        SendHelp("Nice! You won 25 fame!");
                        Client.Database.UpdateFame(Client.Account, 25);
                        Fame += 25;
                        UpdateCount++;
                    }
                    else if (calculator <= 985 && calculator > 970)
                    {
                        SendHelp("Nice! You won 50 fame!");
                        Client.Database.UpdateFame(Client.Account, 50);
                        Fame += 50;
                        UpdateCount++;
                    }
                    else if (calculator <= 990 && calculator > 985)
                    {
                        SendHelp("Very Nice! You won 100 fame!");
                        Client.Database.UpdateFame(Client.Account, 100);
                        Fame += 100;
                        UpdateCount++;
                    }
                    else if (calculator <= 994 && calculator > 990)
                    {
                        SendHelp("Awesome! You won 500 fame!");
                        Client.Database.UpdateFame(Client.Account, 500);
                        Fame += 500;
                        UpdateCount++;
                    }
                    else if (calculator <= 997 && calculator > 994)
                    {
                        SendHelp("Amazing! You won 1000 fame!");
                        Client.Database.UpdateFame(Client.Account, 1000);
                        Fame += 1000;
                        UpdateCount++;
                    }
                    else if (calculator <= 999 && calculator > 997)
                    {
                        SendHelp("Amazing! You won 5000 fame!");
                        Client.Database.UpdateFame(Client.Account, 5000);
                        Fame += 5000;
                        UpdateCount++;
                    }
                    else if (calculator <= 1000 && calculator > 999)
                    {
                        SendHelp("Incredible! You won the 10000 fame jackpot!");
                        foreach (ClientProcessor i in RealmManager.Clients.Values)
                        {
                            i.SendPacket(new TextPacket
                            {
                                BubbleTime = 0,
                                Stars      = -1,
                                Name       = "#Announcement",
                                Text       = Name + " has won the 10000 Fame jackpot on the bronze slot machines!"
                            });
                        }
                        Client.Database.UpdateFame(Client.Account, 10000);
                        Fame += 10000;
                        UpdateCount++;
                    }
                    psr.SendPacket(new BuyResultPacket
                    {
                        Result = 0
                    });
                }
                else
                {
                    SendInfo("Canceled");
                    psr.SendPacket(new BuyResultPacket
                    {
                        Result = 0
                    });
                }
            }
        }
示例#21
0
        int targetWorld = -1;         //-2 = nexus

        void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
            {
                Disconnect();
            }
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            Console.WriteLine("Client is connecting!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(skt.RemoteEndPoint + " to connect.");
                return;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(skt.RemoteEndPoint + " loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine("Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(skt.RemoteEndPoint + " joined world " + world.Id.ToString());
                if (world.Id == -5)                 //Test World
                {
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                }
                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    //Music = world.GetMusic(Random),
                    ClientXML = world.ClientXML,
                    ExtraXML  = world.ExtraXML
                });
                //TODO: Fix this
                if (hasRead)
                {
                    return;
                }
                else
                {
                    SendPacket(new TextBoxPacket
                    {
                        Button1 = "I understand!",
                        Message = "This server is not meant to be played! It is a playground for exploits. Any exploits such as duping, godmode, and anything in between is allowed. Be warned that players may be able to steal your items. :) \n Add zeroehdev on skype to discuss any exploits. \n Your actions, ip, and id are being logged and time stamped.",
                        Title   = "Watch Out!",
                        Type    = "Test"
                    });
                    Console.WriteLine("[" + DateTime.Now + "]" + Account.AccountId + " has connected!");
                    var dir = @"logs";
                    if (!System.IO.Directory.Exists(dir))
                    {
                        System.IO.Directory.CreateDirectory(dir);
                    }
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\IDConnectedLog.txt", true))
                    {
                        writer.WriteLine("[" + DateTime.Now + "]" + Account.AccountId + " has connected!");
                    }
                    hasRead = !hasRead;
                }
                //DDoS client and server 101:
                //while (hasRead == false)
                //{
                //	//hasRead ^= hasRead;
                //	SendPacket(new TextBoxPacket
                //	{
                //		Button1 = "I understand!",
                //		Message =
                //			"This server is not meant to be played, but rather to be exploited. Any exploits such as duping, godmode, and anything else is allowed. Be warned that players may be able to steal your items. :) \n Add zeroehdev on skype to discuss any exploits. \n Your actions, ip, username, and id are being logged and time stamped.",
                //		Title = "Watch Out!",
                //		Type = "Test"
                //	});
                //	//hasRead ^= hasRead;
                //}
                //hasRead = true;
                stage = ProtocalStage.Handshaked;
            }
        }
示例#22
0
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            db = new Database();
            //Console.Out.WriteLine(pkt.GUID + ": " + pkt.Password);
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine(@"Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine(@"Account is null!");
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
            }
            if ((ip = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0])) == null)
            {
                Console.WriteLine(@"Error checking IP");
                SendPacket(new FailurePacket
                {
                    Message = "Error with IP."
                });
                Disconnect();
                db.Dispose();
                return;
            }
            Console.WriteLine(@"Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine(@"Account in use: " + account.AccountId + @" " + account.Name);
                    account = null;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
                account = null;
                SendPacket(new FailurePacket
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(@"Failed to connect.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                var world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine(@"Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                try
                {
                    Console.WriteLine(@"Client joined world " + world.Id);
                }
                catch
                {
                    Console.WriteLine(@"Error! World is null");
                }
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                {
                    (world as Test).LoadJson(pkt.MapInfo);
                }

                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                if (!ConnectedBuildStartsWith(clientVer))
                {
                    SendPacket(new TextPacket
                    {
                        BubbleTime = 1,
                        Stars      = -1,
                        Name       = "",
                        Text       = "Your client is outdated. Visit http://forum.zerorealms.com to get the latest one!"
                    });
                    Disconnect();

                    /*SendPacket(new TextBoxPacket
                     * {
                     *  Button1 = "Okay",
                     *  Message = "Your client is outdated, Click <font color=\"white\"><b><a href='http://forum.zerorealms.com'>Here</a></b></font> to get the latest one!",
                     *  Title = "Outdated Client!",
                     *  Type = "NewClient"
                     * });*/
                }
                SendPacket(new MapInfoPacket
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    Music         = world.GetMusic(Random),
                    ClientXML     = world.ClientXML,
                    ExtraXML      = world.ExtraXML,

                    SendMusic = ConnectedBuildStartsWith(clientVer)
                });
                stage = ProtocalStage.Handshaked;
            }
        }
示例#23
0
        public void UsePortal(RealmTime time, UsePortalPacket pkt)
        {
            Entity entity = Owner.GetEntity(pkt.ObjectId);

            if (entity == null || !entity.Usable)
            {
                return;
            }
            World  world = null;
            Portal p     = null;

            if (entity is Portal)
            {
                p     = entity as Portal;
                world = p.WorldInstance;
            }
            if (world == null)
            {
                if (p != null)
                {
                    bool   setWorldInstance = true;
                    string d = "";
                    if (XmlDatas.IdToDungeon.TryGetValue(entity.ObjectType, out d))
                    {
                        world = RealmManager.AddWorld(new XMLWorld(XmlDatas.DungeonDescs[d]));
                    }
                    else
                    {
                        switch (entity.ObjectType) //handling default case for not found. Add more as implemented
                        {
                        case 0x070e:
                        case 0x0703:                                                         //portal of cowardice
                        {
                            if (RealmManager.PlayerWorldMapping.ContainsKey(this.AccountId)) //may not be valid, realm recycled?
                            {
                                world = RealmManager.PlayerWorldMapping[this.AccountId];     //also reconnecting to vault is a little unexpected
                            }
                            else if (world.Id == -5 || world.Id == -11)
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                            else
                            {
                                world = RealmManager.GetWorld(World.NEXUS_ID);
                            }
                        } break;

                        case 0x0712:
                            world = RealmManager.GetWorld(World.NEXUS_ID); break;

                        case 0x071d:
                            world = RealmManager.GetWorld(World.NEXUS_ID); break;

                        case 0x071c:
                            world = RealmManager.Monitor.GetRandomRealm(); break;

                        case 0x0720:
                            world            = RealmManager.PlayerVault(psr);
                            setWorldInstance = false; break;

                        case 0x071e:
                            world = RealmManager.AddWorld(new Kitchen()); break;

                        case 0x0ffa:                                            //these need to match IDs
                            //world = RealmManager.GetWorld(World.GauntletMap); break; //this creates a singleton dungeon
                            world = RealmManager.AddWorld(new Island()); break; //this allows each dungeon to be unique

                        case 0x0ffc:
                            world = RealmManager.AddWorld(new WineCellarMap()); break;

                        case 0x1900:
                            world = RealmManager.AddWorld(new ArenaMap()); break;

                        case 0x0730:
                            world = RealmManager.AddWorld(new OceanTrench()); break;

                        case 0x070c:
                            world = RealmManager.AddWorld(new SpriteWorld()); break;

                        case 0x071b:
                            world = RealmManager.AddWorld(new Abyss()); break;

                        case 0x071a:
                            world = RealmManager.AddWorld(new UndeadLair()); break;

                        case 0x1901:
                            world = RealmManager.AddWorld(new VoidWorld()); break;

                        case 0x072c:
                            world = RealmManager.AddWorld(new TombMap()); break;

                        case 0x0742:
                            world = RealmManager.AddWorld(new BeachZone()); break;

                        case 0x0718:
                            world = RealmManager.AddWorld(new SnakePit()); break;

                        case 0x0890:
                            world = RealmManager.AddWorld(new MadLabMap()); break;

                        case 0x1905:
                            world            = RealmManager.AddWorld(new BattleArenaMap());
                            setWorldInstance = false; break;

                        case 0x1919:
                            world = RealmManager.AddWorld(new Secret()); break;

                        case 0x1923:
                            world = RealmManager.AddWorld(new ZombieMap()); break;

                        case 0x195d:
                            world = RealmManager.AddWorld(new MarketMap()); break;

                        case 0x195f:
                            world = RealmManager.AddWorld(new Mine()); break;

                        default: SendError("Portal Not Implemented!"); break;
                        }
                    }
                    if (setWorldInstance)
                    {
                        p.WorldInstance = world;
                    }
                }
                else
                {
                    switch (entity.ObjectType) // Special Portals that cannot be the portal class
                    {
                    case 0x072f:
                        world = RealmManager.GuildHallWorld(Guild);
                        break;

                    default: psr.SendPacket(new TextPacket
                        {
                            BubbleTime = 0,
                            Stars      = -1,
                            Name       = "",
                            Text       = "Semi-Portal Not Implemented!"
                        }); break;
                    }
                }
            }

            //used to match up player to last realm they were in, to return them to it. Sometimes is odd, like from Vault back to Vault...
            if (RealmManager.PlayerWorldMapping.ContainsKey(this.AccountId))
            {
                World tempWorld;
                RealmManager.PlayerWorldMapping.TryRemove(this.AccountId, out tempWorld);
            }
            RealmManager.PlayerWorldMapping.TryAdd(this.AccountId, Owner);
            psr.Reconnect(new ReconnectPacket()
            {
                Host   = "",
                Port   = 2050,
                GameId = world.Id,
                Name   = world.Name,
                Key    = Empty <byte> .Array,
            });
        }
示例#24
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
            {
                Disconnect();
            }
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            Console.WriteLine("Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine("Failed to connect.");
                return;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine("Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Client joined world " + world.Id.ToString());
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                {
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                }

                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    ClientXML     = world.ClientXML,
                    ExtraXML      = world.ExtraXML
                });
                stage = ProtocalStage.Handshaked;
                if (!Connected)
                {
                    Connected = true;
                }
            }
        }