Example #1
0
        public override void Tick(RealmTime time)
        {
            if (t/500 == p)
            {
                Owner.BroadcastPacket(new ShowEffectPacket
                {
                    EffectType = EffectType.Trap,
                    Color = new ARGB(0xff9000ff),
                    TargetId = Id,
                    PosA = new Position {X = radius/2}
                }, null);
                p++;
                if (p == LIFETIME*2)
                {
                    Explode(time);
                    return;
                }
            }
            t += time.thisTickTimes;

            bool monsterNearby = false;
            if (player.PvP)
                this.AOE(radius/2, true, enemy =>
                {
                    var plr = (enemy as Player);
                    if (!plr.PvP || (plr.PvP && plr.Team != 0 && plr.Team == player.Team) || plr == player)
                        return;
                    monsterNearby = true;
                });
            this.AOE(radius/2, false, enemy => monsterNearby = true);
            if (monsterNearby)
                Explode(time);

            base.Tick(time);
        }
 protected override bool Process(Player player, RealmTime time, string args)
 {
     if (player.Guild != "")
         try
         {
             var saytext = string.Join(" ", args);
             if ((from w in player.Manager.Worlds let world = w.Value where w.Key != 0 from i in world.Players.Where(i => i.Value.Guild == player.Guild) select world).Any())
             {
                 if (saytext.Equals(" ") || saytext == "")
                 {
                     player.SendHelp("Usage: /guild <text>");
                     return false;
                 }
                 player.Manager.Chat.SayGuild(player, saytext.ToSafeText());
                 return true;
             }
         }
         catch(Exception e)
         {
             player.SendError(e.ToString());
             player.SendInfo("Cannot guild chat!");
             return false;
         }
     else
         player.SendInfo("You need to be in a guild to use guild chat!");
     return false;
 }
 protected override bool Process(Player player, RealmTime time, string[] args)
 {
     if (args.Length == 0)
     {
         player.SendHelp("Usage: /addeff <Effectname or Effectnumber>");
         return false;
     }
     try
     {
         player.ApplyConditionEffect(new ConditionEffect
         {
             Effect = (ConditionEffectIndex)Enum.Parse(typeof(ConditionEffectIndex), args[0].Trim(), true),
             DurationMS = -1
         });
         {
             player.SendInfo("Success!");
         }
     }
     catch
     {
         player.SendError("Invalid effect!");
         return false;
     }
     return true;
 }
Example #4
0
 public void Death(RealmTime time)
 {
     counter.Death(time);
     if (CurrentState != null)
         CurrentState.OnDeath(new BehaviorEventArgs(this, time));
     Owner.LeaveWorld(this);
 }
 protected override bool Process(Player player, RealmTime time, string[] args)
 {
     if (player.HasConditionEffect(ConditionEffectIndex.Paused))
     {
         player.ApplyConditionEffect(new ConditionEffect
         {
             Effect = ConditionEffectIndex.Paused,
             DurationMS = 0
         });
         player.SendInfo("Game resumed.");
     }
     else
     {
         foreach (Enemy i in player.Owner.EnemiesCollision.HitTest(player.X, player.Y, 8).OfType<Enemy>())
         {
             if (i.ObjectDesc.Enemy)
             {
                 player.SendInfo("Not safe to pause.");
                 return false;
             }
         }
         player.ApplyConditionEffect(new ConditionEffect
         {
             Effect = ConditionEffectIndex.Paused,
             DurationMS = -1
         });
         player.SendInfo("Game paused.");
     }
     return true;
 }
Example #6
0
 protected override bool Process(Player player, RealmTime time, string args)
 {
     if (player.HasConditionEffect(ConditionEffects.Paused))
     {
         player.ApplyConditionEffect(new ConditionEffect()
         {
             Effect = ConditionEffectIndex.Paused,
             DurationMS = 0
         });
         player.SendInfo("Game resumed.");
         return true;
     }
     else
     {
         if (player.Owner.EnemiesCollision.HitTest(player.X, player.Y, 8).OfType<Enemy>().Any())
         {
             player.SendError("Not safe to pause.");
             return false;
         }
         else
         {
             player.ApplyConditionEffect(new ConditionEffect()
             {
                 Effect = ConditionEffectIndex.Paused,
                 DurationMS = -1
             });
             player.SendInfo("Game paused.");
             return true;
         }
     }
 }
        private void ActivateAbilityShoot(RealmTime time, Ability ability, Position target)
        {
            double arcGap = ability.ArcGap * Math.PI / 180;
            double startAngle = Math.Atan2(target.Y - Y, target.X - X) - (ability.NumProjectiles - 1) / 2 * arcGap;
            ProjectileDesc prjDesc = ability.Projectiles[0]; //Assume only one

            var batch = new Packet[ability.NumProjectiles];
            for (int i = 0; i < ability.NumProjectiles; i++)
            {
                Projectile proj = CreateProjectile(prjDesc, ObjectDesc.ObjectType,
                    (int)statsMgr.GetAttackDamage(prjDesc.MinDamage, prjDesc.MaxDamage),
                    time.tickTimes, new Position { X = X, Y = Y }, (float)(startAngle + arcGap * i), 1);
                Owner.EnterWorld(proj);
                fames.Shoot(proj);
                batch[i] = new ShootPacket
                {
                    BulletId = proj.ProjectileId,
                    OwnerId = Id,
                    ContainerType = ability.AbilityType,
                    Position = new Position { X = X, Y = Y },
                    Angle = proj.Angle,
                    Damage = (short)proj.Damage,
                    FromAbility = true
                };
            }
            BroadcastSync(batch, p => this.Dist(p) < 25);
        }
        public override void Tick(RealmTime time)
        {
            base.Tick(time); //normal world tick

            CheckDupers();
            UpdatePortals();
        }
        public override void Tick(RealmTime time)
        {
            base.Tick(time);
            CheckOutOfBounds();

            if (CheckPopulation())
            {
                if (ready)
                {
                    if (waiting) return;
                    ready = false;
                    wave++;
                    foreach (KeyValuePair<int, Player> i in Players)
                    {
                        i.Value.Client.SendPacket(new ArenaNextWavePacket
                        {
                            Type = wave
                        });
                    }
                    waiting = true;
                    Timers.Add(new WorldTimer(5000, (world, t) =>
                    {
                        ready = false;
                        Spawn();
                        waiting = false;
                    }));
                }
                ready = true;
            }
        }
Example #10
0
        void HandleGround(RealmTime time)
        {
            if (time.tickTimes - l > 500)
            {
                if (HasConditionEffect(ConditionEffects.Paused) ||
                    HasConditionEffect(ConditionEffects.Invincible))
                    return;

                WmapTile tile = Owner.Map[(int)X, (int)Y];
                ObjectDesc objDesc = tile.ObjType == 0 ? null : XmlDatas.ObjectDescs[tile.ObjType];
                TileDesc tileDesc = XmlDatas.TileDescs[tile.TileId];
                if (tileDesc.Damaging && (objDesc == null || !objDesc.ProtectFromGroundDamage))
                {
                    int dmg = Random.Next(tileDesc.MinDamage, tileDesc.MaxDamage);
                    dmg = (int)statsMgr.GetDefenseDamage(dmg, true);

                    HP -= dmg;
                    UpdateCount++;
                    if (HP <= 0)
                        Death("lava");

                    l = time.tickTimes;
                }
            }
        }
Example #11
0
        public void InventorySwap(RealmTime time, InvSwapPacket pkt)
        {
            Entity en1 = Owner.GetEntity(pkt.Obj1.ObjectId);
            Entity en2 = Owner.GetEntity(pkt.Obj2.ObjectId);
            IContainer con1 = en1 as IContainer;
            IContainer con2 = en2 as IContainer;

            //TODO: locker
            Item item1 = con1.Inventory[pkt.Obj1.SlotId];
            Item item2 = con2.Inventory[pkt.Obj2.SlotId];
            if (!AuditItem(con2, item1, pkt.Obj2.SlotId) ||
                !AuditItem(con1, item2, pkt.Obj1.SlotId))
                (en1 as Player).Client.SendPacket(new InvResultPacket() { Result = 1 });
            else
            {
                con1.Inventory[pkt.Obj1.SlotId] = item2;
                con2.Inventory[pkt.Obj2.SlotId] = item1;
                en1.UpdateCount++;
                en2.UpdateCount++;

                if (en1 is Player)
                {
                    (en1 as Player).CalcBoost();
                    (en1 as Player).Client.SendPacket(new InvResultPacket() { Result = 0 });
                }
                if (en2 is Player)
                {
                    (en2 as Player).CalcBoost();
                    (en2 as Player).Client.SendPacket(new InvResultPacket() { Result = 0 });
                }
            }
        }
Example #12
0
 public override void Tick(RealmTime time)
 {
     base.Tick(time);
     if (MainPlayer == null)
         return;
     if (Cleared)
         return;
     bool foundBoss = false;
     foreach (var i in Enemies.Values)
         if (i.ObjectDesc != null && i.ObjectDesc.ObjectId == FloorBosses[Floor])
             foundBoss = true;
     if(foundBoss)
         return;
     if(MainPlayer.Floors < Floor)
     {
         if (Floor == Tower.FLOORS)
             foreach (var i in Manager.Clients.Values)
                 if (i.Player != null)
                     i.Player.SendInfo(MainPlayer.Name + " has cleared the tower!");
         MainPlayer.Floors = Floor;
         MainPlayer.SaveToCharacter();
         MainPlayer.Client.Save();
     }
     Cleared = true;
 }
        protected override bool Process(Player player, RealmTime time, string args)
        {
            Command[] cmds = player.Manager.Commands.Commands.Values
                .Where(x => x.HasPermission(player))
                .ToArray();

            int curPage = (args != "") ? Convert.ToInt32(args) : 1;
            double maxPage = Math.Floor((double) cmds.Length/10);

            if (curPage > maxPage + 1)
                curPage = (int) maxPage + 1;
            if (curPage < 1)
                curPage = 1;

            var sb = new StringBuilder(string.Format("Commands <Page {0}/{1}>: \n", curPage, maxPage + 1));

            int y = (curPage - 1) * 10;
            int z = y + 10;

            int commands = cmds.Length;
            if (z > commands)
            {
                z = commands;
            }

            for (int i = y; i < z; i++)
            {
                sb.Append(string.Format("[/{0}{1}]{2}", cmds[i].CommandName, (cmds[i].CommandUsage != "" ? " " + cmds[i].CommandUsage : null), (cmds[i].CommandDesc != "" ? ": " + cmds[i].CommandDesc : null)) + "\n");
            }
            player.SendHelp(sb.ToString());
            return true;
        }
Example #14
0
        protected override bool Process(Player player, RealmTime time, string args)
        {
            int index = args.IndexOf(' ');
            int num;
            string name = args;

            if (args.IndexOf(' ') > 0 && int.TryParse(args.Substring(0, args.IndexOf(' ')), out num)) //multi
                name = args.Substring(index + 1);
            else
                num = 1;

            ushort objType;
            if (!player.Manager.GameData.IdToObjectType.TryGetValue(name, out objType) ||
                !player.Manager.GameData.ObjectDescs.ContainsKey(objType))
            {
                player.SendError("Unknown entity!");
                return false;
            }

            for (int i = 0; i < num; i++)
            {
                var entity = Entity.Resolve(player.Manager, objType);
                entity.Move(player.X, player.Y);
                player.Owner.EnterWorld(entity);
            }
            return true;
        }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            if (!player.Guild.IsDefault)
            {
                try
                {
                    var saytext = string.Join(" ", args);

                    if (String.IsNullOrWhiteSpace(saytext))
                    {
                        player.SendHelp("Usage: /guild <text>");
                        return false;
                    }
                    else
                    {
                        player.Guild.Chat(player, saytext.ToSafeText());
                        return true;
                    }
                }
                catch
                {
                    player.SendInfo("Cannot guild chat!");
                    return false;
                }
            }
            else
                player.SendInfo("You need to be in a guild to use guild chat!");
            return false;
        }
Example #16
0
 protected override bool Process(Player player, RealmTime time, string args)
 {
     ConditionEffectIndex effect;
     if (!Enum.TryParse(args, true, out effect))
     {
         player.SendError("Invalid effect!");
         return false;
     }
     if ((player.ConditionEffects & (ConditionEffects)(1 << (int)effect)) != 0)
     {
         //remove
         player.ApplyConditionEffect(new ConditionEffect()
         {
             Effect = effect,
             DurationMS = 0
         });
     }
     else
     {
         //add
         player.ApplyConditionEffect(new ConditionEffect()
         {
             Effect = effect,
             DurationMS = -1
         });
     }
     return true;
 }
Example #17
0
        public override void Tick(RealmTime time)
        {
            if (t / 500 == p)
            {
                Owner.BroadcastPacket(new ShowEffectPacket()
                {
                    EffectType = EffectType.Trap,
                    Color = new ARGB(0xff9000ff),
                    TargetId = Id,
                    PosA = new Position() { X = radius / 2 }
                }, null);
                p++;
                if (p == LIFETIME * 2)
                {
                    Explode(time);
                    return;
                }
            }
            t += time.thisTickTimes;

            bool monsterNearby = false;
            Behavior.AOE(Owner, this, radius / 2, false, enemy => monsterNearby = true);
            if (monsterNearby)
                Explode(time);

            base.Tick(time);
        }
Example #18
0
 public override void Tick(RealmTime time)
 {
     if (t/500 == p2)
     {
         Owner.BroadcastPacket(new ShowEffectPacket
         {
             EffectType = EffectType.Trap,
             Color = new ARGB(0xffd700),
             TargetId = Id,
             PosA = new Position {X = radius}
         }, null);
         p2++;
         //Stuff
     }
     if (t/2000 == p)
     {
         var pkts = new List<Packet>();
         BehaviorBase.AOE(Owner, this, radius, true,
             player => { Player.ActivateHealHp(player as Player, amount, pkts); });
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.AreaBlast,
             TargetId = Id,
             Color = new ARGB(0xffd700),
             PosA = new Position {X = radius}
         });
         Owner.BroadcastPackets(pkts, null);
         p++;
     }
     t += time.thisTickTimes;
     base.Tick(time);
 }
        public bool Execute(Player player, RealmTime time, string args)
        {
            if (!HasPermission(player))
            {
                player.SendInfo("You are not an Admin");
                return false;
            }

            try
            {
                string[] a = args.Split(' ');
                bool success = Process(player, time, a);
                if (success)
                player.Manager.Database.DoActionAsync(db =>
                {
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "insert into commandlog (command, args, player) values (@command, @args, @player);";
                    cmd.Parameters.AddWithValue("@command", CommandName);
                    cmd.Parameters.AddWithValue("@args", args);
                    cmd.Parameters.AddWithValue("@player", $"{player.AccountId}:{player.Name}");
                    cmd.ExecuteNonQuery();
                });
                return success;
            }
            catch (Exception ex)
            {
                logger.Error("Error when executing the command.", ex);
                player.SendError("Error when executing the command.");
                return false;
            }
        }
Example #20
0
        public void PlayerText(RealmTime time, PlayerTextPacket pkt)
        {
            if (pkt.Text[0] == '/')
            {
                string[] x = pkt.Text.Trim().Split(' ');
                ProcessCmd(x[0].Trim('/'), x.Skip(1).ToArray());
                //CommandManager.Execute(this, time, pkt.Text); // Beta Processor
            }
            else
            {
                string txt = Encoding.ASCII.GetString(
                    Encoding.Convert(
                        Encoding.UTF8,
                        Encoding.GetEncoding(
                            Encoding.ASCII.EncodingName,
                            new EncoderReplacementFallback(string.Empty),
                            new DecoderExceptionFallback()
                            ),
                        Encoding.UTF8.GetBytes(pkt.Text)
                    )
                );
                if (txt != "")
                {
                    //Removing unwanted crashing characters from strings
                    string chatColor = "";
                    if (Client.Account.Rank > 3)
                        chatColor = "@";
                    else if (Client.Account.Rank == 3)
                        chatColor = "#";

                    foreach (var i in RealmManager.Worlds)
                    {
                        if (i.Key != 0)
                        {
                            i.Value.BroadcastPacket(new TextPacket()
                            {
                                Name = chatColor + Name,
                                ObjectId = Id,
                                Stars = Stars,
                                BubbleTime = 5,
                                Recipient = "",
                                Text = txt,
                                CleanText = txt
                            }, null);
                        }
                    }
                    foreach (var e in Owner.Enemies)
                    {
                        foreach (var b in e.Value.CondBehaviors)
                        {
                            if (b.Condition == BehaviorCondition.OnChat)
                            {
                                b.Behave(BehaviorCondition.OnChat, e.Value, time, null, pkt.Text);
                                b.Behave(BehaviorCondition.OnChat, e.Value, time, null, pkt.Text, this);
                            }
                        }
                    }
                }
            }
        }
        private void HandleGround(RealmTime time)
        {
            WmapTile tile = Owner.Map[(int)X, (int)Y];
              TileDesc tileDesc = Manager.GameData.Tiles[tile.TileId];
              if (time.tickTimes - b > 100)
              {
            if (Owner.Name != "The Void")
            {
              if (tileDesc.NoWalk)
              {
            if (time.tickCount % 30 == 0)
            {
              client.Disconnect();
            }
              }
            }

            if (Owner.Name == "Ocean Trench")
            {
              bool fObject = false;
              foreach (
              KeyValuePair<int, StaticObject> i in
                  Owner.StaticObjects.Where(i => i.Value.ObjectType == 0x0731)
                      .Where(i => (X - i.Value.X) * (X - i.Value.X) + (Y - i.Value.Y) * (Y - i.Value.Y) < 1))
            fObject = true;

              OxygenRegen = fObject;

              if (!OxygenRegen)
              {
            if (OxygenBar == 0)
              HP -= 2;
            else
              OxygenBar -= 1;

            UpdateCount++;

            if (HP <= 0)
              Death("server.damage_suffocation");
              }
              else
              {
            if (OxygenBar < 100)
              OxygenBar += 8;
            if (OxygenBar > 100)
              OxygenBar = 100;

            UpdateCount++;
              }
            }

            Owner.TileEvent(this, tile);

            b = time.tickTimes;
              }
        }
Example #22
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time); //normal world tick

            CheckDupers();
            UpdatePortals();

            if (time.tickCount % 5 == 0 && Connecting)
                Connecting = false;
        }
 public void UseAbility(RealmTime time, int abilitySlot, Position target)
 {
     if (Ability[abilitySlot] == null)
         return;
     var ability = Ability[abilitySlot];
     if (MP < ability.MpCost || AbilityCooldown[abilitySlot] != 0)
         return;
     MP -= ability.MpCost;
     AbilityCooldown[abilitySlot] = ability.Cooldown;
     foreach (ActivateEffect eff in ability.ActivateEffects)
     {
         switch (eff.Effect)
         {
             case ActivateEffects.BulletNova:
                 {
                     ProjectileDesc prjDesc = ability.Projectiles[0]; //Assume only one
                     var 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, ability.AbilityType,
                             (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 = ability.AbilityType,
                             Position = target,
                             Angle = proj.Angle,
                             Damage = (short)proj.Damage,
                             FromAbility = true
                         };
                     }
                     Random.CurrentSeed = s;
                     batch[20] = new ShowEffectPacket
                     {
                         EffectType = EffectType.Trail,
                         PosA = target,
                         TargetId = Id,
                         Color = new ARGB(0xFFFF00AA)
                     };
                     BroadcastSync(batch, p => this.Dist(p) < 25);
                 } break;
             case ActivateEffects.Shoot:
                 {
                     ActivateAbilityShoot(time, ability, target);
                 } break;
         }
     }
     UpdateCount++;
 }
        public int Damage(Player from, RealmTime time, int dmg, bool noDef, params ConditionEffect[] effs)
        {
            if (stat) return 0;
            if (HasConditionEffect(ConditionEffectIndex.Invincible))
                return 0;
            if (!HasConditionEffect(ConditionEffectIndex.Paused) &&
                !HasConditionEffect(ConditionEffectIndex.Stasis))
            {
                int def = ObjectDesc.Defense;
                if (noDef)
                    def = 0;
                dmg = (int)StatsManager.GetDefenseDamage(this, dmg, def);
                int effDmg = dmg;
                if (effDmg > HP)
                    effDmg = HP;
                if (!HasConditionEffect(ConditionEffectIndex.Invulnerable))
                    HP -= dmg;
                ApplyConditionEffect(effs);
                if (from != null)
                {
                    Owner.BroadcastPacket(new DamagePacket
                    {
                        TargetId = Id,
                        Effects = 0,
                        Damage = (ushort)dmg,
                        Killed = HP < 0,
                        BulletId = 0,
                        ObjectId = from.Id
                    }, null);

                    counter.HitBy(from, time, null, dmg);
                }
                else
                {
                    Owner.BroadcastPacket(new DamagePacket
                    {
                        TargetId = Id,
                        Effects = 0,
                        Damage = (ushort)dmg,
                        Killed = HP < 0,
                        BulletId = 0,
                        ObjectId = -1
                    }, null);
                }

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

                UpdateCount++;
                return effDmg;
            }
            return 0;
        }
Example #25
0
        public void RequestTake(RealmTime time, RequestTradePacket pkt)
        {
            if (tradeTarget != null)
            {
                SendError("You're already trading!");
                tradeTarget = null;
                return;
            }
            var target = Owner.GetUniqueNamedPlayer(pkt.Name);
            if (target == null)
            {
                SendError("Player not found!");
                return;
            }
            if (target.tradeTarget != null && target.tradeTarget != this)
            {
                SendError(target.Name + " is already trading!");
                return;
            }
                tradeTarget = target;
                trade = new bool[12];
                tradeAccepted = false;
                target.tradeTarget = this;
                target.trade = new bool[12];
                taking = true;
                tradeTarget.intake = true;
                var my = new TradeItem[Inventory.Length];
                for (var i = 0; i < Inventory.Length; i++)
                    my[i] = new TradeItem
                    {
                        Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType,
                        SlotType = target.SlotTypes[i],
                        Included = false,
                        Tradeable = (target.Inventory[i] != null)

                    };
                var your = new TradeItem[target.Inventory.Length];
                for (var i = 0; i < target.Inventory.Length; i++)
                    your[i] = new TradeItem
                    {
                        Item = -1,
                        SlotType = target.SlotTypes[i],
                        Included = false,
                        Tradeable = false

                    };

                psr.SendPacket(new TradeStartPacket
                {
                    MyItems = my,
                    YourName = target.Name,
                    YourItems = your
                });
        }
        public void ChangeTrade(RealmTime time, ChangeTradePacket pkt)
        {
            this.tradeAccepted = false;
            tradeTarget.tradeAccepted = false;
            this.trade = pkt.Offers;

            tradeTarget.psr.SendPacket(new TradeChangedPacket()
            {
                Offers = this.trade
            });
        }
 protected override bool Process(Player player, RealmTime time, string args)
 {
     if (args.Length == 0)
     {
         player.SendHelp("Usage: /announce <saytext>");
         return false;
     }
     foreach (var client in player.Manager.Clients.Values)
         client.Player.SendText("@Announcement", args);
     return true;
 }
Example #28
0
        public void PlayerText(RealmTime time, PlayerTextPacket pkt)
        {
            if (pkt.Text[0] == '/')
            {
                string[] x = pkt.Text.Trim().Split(' ');
                ProcessCmd(x[0].Trim('/'), x.Skip(1).ToArray());
                //CommandManager.Execute(this, time, pkt.Text); // Beta Processor
            }
            else
            {
                string txt = Encoding.ASCII.GetString(
                    Encoding.Convert(
                        Encoding.UTF8,
                        Encoding.GetEncoding(
                            Encoding.ASCII.EncodingName,
                            new EncoderReplacementFallback(string.Empty),
                            new DecoderExceptionFallback()
                            ),
                        Encoding.UTF8.GetBytes(pkt.Text)
                    )
                );
                if (txt != "")
                {
                    //Removing unwanted crashing characters from strings
                    string chatColor = "";
                    if (Client.Account.Rank > 1)
                        chatColor = ""; //was @; turns all of your text yellow including your name; looks fugly
                    else if (Client.Account.Rank == 1)
                        chatColor = ""; //was #; turns your name a dark orange but your text stays white; looks like you're a npc

                    Owner.BroadcastPacket(new TextPacket()
                    {
                        Name = chatColor + Name,
                        ObjectId = Id,
                        Stars = Stars,
                        BubbleTime = 5,
                        Recipient = "",
                        Text = txt,
                        CleanText = txt
                    }, null);
                    foreach (var e in Owner.Enemies)
                    {
                        foreach (var b in e.Value.CondBehaviors)
                        {
                            if (b.Condition == BehaviorCondition.OnChat)
                            {
                                b.Behave(BehaviorCondition.OnChat, e.Value, time, null, pkt.Text);
                                b.Behave(BehaviorCondition.OnChat, e.Value, time, null, pkt.Text, this);
                            }
                        }
                    }
                }
            }
        }
 protected override bool Process(Player player, RealmTime time, string[] args)
 {
     try
     {
         if (!String.IsNullOrWhiteSpace(args[0]))
             player.Manager.FindPlayer(args[0])?.Client.GiftCodeReceived("LevelUp");
         else
             player.Client.GiftCodeReceived("LevelUp");
     }
     catch (Exception) { }
     return true;
 }
Example #30
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            foreach (var i in Players)
            {
                if (i.Value.Client.Account.Rank < 3)
                {
                    i.Value.Client.Disconnect();
                }
            }
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int)state;

            if (cool <= 0)
            {
                if (!(host is Pet))
                {
                    return;
                }
                Pet pet = host as Pet;
                if (pet.PlayerOwner == null)
                {
                    return;
                }
                Player player = host.GetEntity(pet.PlayerOwner.Id) as Player;
                if (player == null)
                {
                    return;
                }

                if (player != null)
                {
                    int maxMp = player.Stats[1] + player.Boost[1];
                    int h     = GetMP(pet, ref cool);
                    if (h == -1)
                    {
                        return;
                    }
                    int newMp = Math.Min(player.MaxMp, player.Mp + h);
                    if (newMp != player.Mp)
                    {
                        int n = newMp - player.Mp;
                        if (player.HasConditionEffect(ConditionEffectIndex.Quiet))
                        {
                            player.Owner.BroadcastPacket(new ShowEffectPacket
                            {
                                EffectType = EffectType.Trail,
                                TargetId   = host.Id,
                                PosA       = new Position {
                                    X = player.X, Y = player.Y
                                },
                                Color = new ARGB(0xffffffff)
                            }, null);
                            player.Owner.BroadcastPacket(new NotificationPacket
                            {
                                ObjectId = player.Id,
                                Text     = "{\"key\":\"blank\",\"tokens\":{\"data\":\"No Effect\"}}",
                                Color    = new ARGB(0xFF0000)
                            }, null);
                            cool  = 1000;
                            state = cool;
                            return;
                        }
                        player.Mp = newMp;
                        player.UpdateCount++;
                        player.Owner.BroadcastPacket(new ShowEffectPacket
                        {
                            EffectType = EffectType.Trail,
                            TargetId   = host.Id,
                            PosA       = new Position {
                                X = player.X, Y = player.Y
                            },
                            Color = new ARGB(0xffffffff)
                        }, null);
                        player.Owner.BroadcastPacket(new ShowEffectPacket
                        {
                            EffectType = EffectType.Potion,
                            TargetId   = player.Id,
                            Color      = new ARGB(0x6084e0)
                        }, null);
                        player.Owner.BroadcastPacket(new NotificationPacket
                        {
                            ObjectId = player.Id,
                            Text     = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + n + "\"}}",
                            Color    = new ARGB(0x6084e0)
                        }, null);
                    }
                }
            }
            else
            {
                cool -= time.thisTickTimes;
            }

            state = cool;
        }
Example #32
0
        public override void Tick(RealmTime time)
        {
            try
            {
                if (Size == 0 && MType != -1)
                {
                    Size = MERCHANT_SIZE;
                    UpdateCount++;
                }

                if (!closing)
                {
                    tickcount++;
                    if (tickcount % (Manager?.TPS * 60) == 0) //once per minute after spawning
                    {
                        MTime--;
                        UpdateCount++;
                    }
                }

                if (MRemaining == 0 && MType != -1)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == -1 && Owner != null)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == 1 && !closing)
                {
                    closing = true;
                    Owner?.Timers.Add(new WorldTimer(30 * 1000, (w1, t1) =>
                    {
                        MTime--;
                        UpdateCount++;
                        w1.Timers.Add(new WorldTimer(30 * 1000, (w2, t2) =>
                        {
                            MTime--;
                            UpdateCount++;
                        }));
                    }));
                }

                if (MType == -1)
                {
                    Owner?.LeaveWorld(this);
                }

                base.Tick(time);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Example #33
0
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     behavior.OnStateEntry(host, time);
     state = period;
 }
Example #34
0
        public int Damage(Player from, RealmTime time, int dmg, bool noDef, params ConditionEffect[] effs)
        {
            if (stat)
            {
                return(0);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(0);
            }
            if (!HasConditionEffect(ConditionEffects.Paused) &&
                !HasConditionEffect(ConditionEffects.Stasis))
            {
                var def = ObjectDesc.Defense;
                if (noDef)
                {
                    def = 0;
                }
                dmg = (int)StatsManager.GetDefenseDamage(this, dmg, def);
                var effDmg = dmg;
                if (effDmg > HP)
                {
                    effDmg = HP;
                }
                if (!HasConditionEffect(ConditionEffects.Invulnerable))
                {
                    HP -= dmg;
                }
                ApplyConditionEffect(effs);
                Owner.BroadcastPacket(new DamagePacket
                {
                    TargetId = Id,
                    Effects  = 0,
                    Damage   = (ushort)dmg,
                    Killed   = HP < 0,
                    BulletId = 0,
                    ObjectId = from.Id
                }, null);

                foreach (var i in CondBehaviors)
                {
                    if ((i.Condition & BehaviorCondition.OnHit) != 0)
                    {
                        i.Behave(BehaviorCondition.OnHit, this, time, null);
                    }
                }
                counter.HitBy(from, null, dmg);

                if (HP < 0)
                {
                    foreach (var i in CondBehaviors)
                    {
                        if ((i.Condition & BehaviorCondition.OnDeath) != 0)
                        {
                            i.Behave(BehaviorCondition.OnDeath, this, time, counter);
                        }
                    }
                    counter.Death();
                    if (Owner != null)
                    {
                        Owner.LeaveWorld(this);
                    }
                }

                UpdateCount++;
                return(effDmg);
            }
            return(0);
        }
Example #35
0
        private bool TickCore(long elapsedTicks, RealmTime time)
        {
            Position pos = GetPosition(elapsedTicks);

            Move(pos.X, pos.Y);

            if (pos.X < 0 || pos.X > Owner.Map.Width)
            {
                Destroy(true);
                return(false);
            }
            if (pos.Y < 0 || pos.Y > Owner.Map.Height)
            {
                Destroy(true);
                return(false);
            }
            if (Owner.Map[(int)pos.X, (int)pos.Y].TileId == 0xff)
            {
                Destroy(true);
                return(false);
            }
            bool penetrateObsta = Descriptor.PassesCover;
            bool penetrateEnemy = Descriptor.MultiHit;

            ushort objId = Owner.Map[(int)pos.X, (int)pos.Y].ObjType;

            if (objId != 0 &&
                Manager.GameData.ObjectDescs[objId].OccupySquare &&
                !penetrateObsta)
            {
                Destroy(true);
                return(false);
            }

            double nearestRadius = double.MaxValue;
            Entity entity        = null;

            foreach (Entity i in collisionMap.HitTest(pos.X, pos.Y, 2))
            {
                if (i == ProjectileOwner.Self)
                {
                    continue;
                }
                if (i is Container)
                {
                    continue;
                }
                if (hitted.Contains(i))
                {
                    continue;
                }
                double xSide = (i.X - pos.X) * (i.X - pos.X);
                double ySide = (i.Y - pos.Y) * (i.Y - pos.Y);
                if (xSide <= 0.5 * 0.5 && ySide <= 0.5 * 0.5 && xSide + ySide <= nearestRadius)
                {
                    nearestRadius = xSide + ySide;
                    entity        = i;
                }
            }
            if (entity != null && ProjectileOwner.Self is Enemy && entity.HitByProjectile(this, time))
            {
                if ((entity is Enemy && penetrateEnemy) ||
                    (entity is StaticObject && (entity as StaticObject).Static && !(entity is Wall) && penetrateObsta))
                {
                    hitted.Add(entity);
                }
                else
                {
                    Destroy(true);
                    return(false);
                }
                ProjectileOwner.Self.ProjectileHit(this, entity);
            }
            return(true);
        }
Example #36
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            if (Players.Count > 0)
            {
                if (Enemies.Count < 1 + Pets.Count)
                {
                    if (!Waiting)
                    {
                        Wave++;

                        Waiting = true;
                        ConditionEffect Invincible = new ConditionEffect();
                        Invincible.Effect     = ConditionEffectIndex.Invulnerable;
                        Invincible.DurationMS = 5000;
                        ConditionEffect Healing = new ConditionEffect();
                        Healing.Effect     = ConditionEffectIndex.Healing;
                        Healing.DurationMS = 5000;
                        foreach (var i in Players)
                        {
                            i.Value.ApplyConditionEffect(new ConditionEffect[] {
                                Invincible,
                                Healing
                            });
                        }
                        FullCountdown(5);
                        foreach (var i in Players)
                        {
                            try
                            {
                                if (!Participants.Contains(i.Value.Client.Account.Name))
                                {
                                    Participants.Add(i.Value.Client.Account.Name);
                                }
                            }
                            catch { }
                        }
                    }
                }
                else
                {
                    foreach (var i in Enemies)
                    {
                        if (OutOfBounds(i.Value.X, i.Value.Y))
                        {
                            LeaveWorld(i.Value);
                        }
                    }
                }
            }
            else
            {
                if (Participants.Count > 0)
                {
                    new Database().AddToArenaLB(Wave, Participants);
                    Participants.Clear();
                }
                foreach (var i in Enemies)
                {
                    LeaveWorld(i.Value);
                    Wave = 0;
                }
            }
        }
Example #37
0
 protected abstract bool Process(Player player, RealmTime time, string[] args);
Example #38
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if ((host as Pet)?.PlayerOwner == null)
            {
                return;
            }
            var         pet = (Pet)host;
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            var player = host.GetEntity(pet.PlayerOwner.Id) as Player;

            if (player == null)
            {
                var tile = host.Owner.Map[(int)host.X, (int)host.Y].Clone();
                if (tile.Region != TileRegion.PetRegion)
                {
                    if (!(host.Owner is PetYard))
                    {
                        host.Owner.LeaveWorld(host);
                        return;
                    }
                    if (tile.Region != TileRegion.Spawn)
                    {
                        host.Owner.LeaveWorld(host);
                        return;
                    }
                }
            }

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }

                var vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > 20)
                {
                    host.Move(player.X, player.Y);
                    host.UpdateCount++;
                }
                else if (vect.Length > 1)
                {
                    var dist = host.GetSpeed(0.5f) * (time.thisTickTimes / 1000f);
                    if (vect.Length > 2)
                    {
                        dist = host.GetSpeed(0.5f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 3.5)
                    {
                        dist = host.GetSpeed(0.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 5)
                    {
                        dist = host.GetSpeed(1.0f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 6)
                    {
                        dist = host.GetSpeed(1.35f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 7)
                    {
                        dist = host.GetSpeed(1.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 10)
                    {
                        dist = host.GetSpeed(2f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }

                    Status = CycleStatus.InProgress;
                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }

                break;
            }

            state = s;
        }
Example #39
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            double      effectiveSpeed;
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed))
            {
                return;
            }

            if (host.HasConditionEffect(ConditionEffects.Slowed))
            {
                effectiveSpeed = speed * 0.5;
            }
            else
            {
                effectiveSpeed = speed;
            }

            var     player = host.GetNearestEntity(acquireRange, null);
            Vector2 vect;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (player != null && s.RemainingTime <= 0)
                {
                    s.State = F.Acquired;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    goto case F.Acquired;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElaspedMsDelta;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime <= 0 && duration > 0)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = coolDown.Next(Random);
                    Status          = CycleStatus.Completed;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElaspedMsDelta;
                }

                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > range)
                {
                    Status  = CycleStatus.InProgress;
                    vect.X -= Random.Next(-2, 2) / 2f;
                    vect.Y -= Random.Next(-2, 2) / 2f;
                    vect.Normalize();
                    float dist = host.GetSpeed((float)effectiveSpeed) * (time.ElaspedMsDelta / 1000f);
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }
                else
                {
                    Status          = CycleStatus.Completed;
                    s.State         = F.Resting;
                    s.RemainingTime = 0;
                }
                break;

            case F.Resting:
                if (player == null)
                {
                    s.State = F.DontKnowWhere;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    break;
                }
                Status = CycleStatus.Completed;
                vect   = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > range + 1)
                {
                    s.State         = F.Acquired;
                    s.RemainingTime = duration;
                    goto case F.Acquired;
                }
                break;
            }

            state = s;
        }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     state = 1000;
 }
Example #41
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            if (Players.Count > 0)
            {
                if (Enemies.Count < 1)
                {
                    if (!Waiting)
                    {
                        Wave++;
                        Waiting = true;
                        Timers.Add(new WorldTimer(1500, (w, t) =>
                        {
                            foreach (var i in Players)
                            {
                                i.Value.Client.SendPacket(new NotificationPacket()
                                {
                                    Color    = new ARGB(0xffff00ff),
                                    ObjectId = i.Value.Id,
                                    Text     = "Wave " + Wave.ToString() + " Starting in 5.."
                                });
                            }
                            Timers.Add(new WorldTimer(1000, (w1, t1) =>
                            {
                                foreach (var i in Players)
                                {
                                    i.Value.Client.SendPacket(new NotificationPacket()
                                    {
                                        Color    = new ARGB(0xffff00ff),
                                        ObjectId = i.Value.Id,
                                        Text     = "Wave " + Wave.ToString() + " Starting in 4.."
                                    });
                                }
                                Timers.Add(new WorldTimer(1000, (w2, t2) =>
                                {
                                    foreach (var i in Players)
                                    {
                                        i.Value.Client.SendPacket(new NotificationPacket()
                                        {
                                            Color    = new ARGB(0xffff00ff),
                                            ObjectId = i.Value.Id,
                                            Text     = "Wave " + Wave.ToString() + " Starting in 3.."
                                        });
                                    }
                                    Timers.Add(new WorldTimer(1000, (w3, t3) =>
                                    {
                                        foreach (var i in Players)
                                        {
                                            i.Value.Client.SendPacket(new NotificationPacket()
                                            {
                                                Color    = new ARGB(0xffff00ff),
                                                ObjectId = i.Value.Id,
                                                Text     = "Wave " + Wave.ToString() + " Starting in 2.."
                                            });
                                        }
                                        Timers.Add(new WorldTimer(1000, (w4, t4) =>
                                        {
                                            foreach (var i in Players)
                                            {
                                                i.Value.Client.SendPacket(new NotificationPacket()
                                                {
                                                    Color    = new ARGB(0xffff00ff),
                                                    ObjectId = i.Value.Id,
                                                    Text     = "Wave " + Wave.ToString() + " Starting.."
                                                });
                                            }
                                            Timers.Add(new WorldTimer(500, (w5, t5) =>
                                            {
                                                SpawnEnemies();
                                                Waiting = false;
                                            }));
                                        }));
                                    }));
                                }));
                            }));
                        }));
                    }
                }
                else
                {
                    foreach (var i in Enemies)
                    {
                        if (OutOfBounds(i.Value.X, i.Value.Y))
                        {
                            LeaveWorld(i.Value);
                        }
                    }
                }
            }
            else
            {
                foreach (var i in Enemies)
                {
                    LeaveWorld(i.Value);
                    Wave = 0;
                }
            }
        }
Example #42
0
 public override bool HitByProjectile(Projectile projectile, RealmTime time) => true;
Example #43
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (state == null)
            {
                return;
            }
            int cool = (int)state;

            Status = CycleStatus.NotStarted;

            if (cool <= 0)
            {
                if (host.HasConditionEffect(ConditionEffectIndex.Stunned))
                {
                    return;
                }

                Entity player = host.GetNearestEntity(radius, null);
                if (player != null || defaultAngle != null || fixedAngle != null)
                {
                    ProjectileDesc desc = host.ObjectDesc.Projectiles[projectileIndex];

                    double a = fixedAngle ??
                               (player == null ? defaultAngle.Value : Math.Atan2(player.Y - host.Y, player.X - host.X));
                    a += angleOffset;
                    if (predictive != 0 && player != null)
                    {
                        a += Predict(host, player, desc) * predictive;
                    }

                    int dmg;
                    if (host is Character)
                    {
                        dmg = (host as Character).Random.Next(desc.MinDamage, desc.MaxDamage);
                    }
                    else
                    {
                        dmg = Random.Next(desc.MinDamage, desc.MaxDamage);
                    }

                    double   startAngle = a - shootAngle * (count - 1) / 2;
                    byte     prjId      = 0;
                    Position prjPos     = new Position {
                        X = host.X, Y = host.Y
                    };
                    for (int i = 0; i < count; i++)
                    {
                        Projectile prj = host.CreateProjectile(
                            desc, host.ObjectType, dmg, time.tickTimes,
                            prjPos, (float)(startAngle + shootAngle * i));
                        host.Owner.EnterWorld(prj);
                        if (i == 0)
                        {
                            prjId = prj.ProjectileId;
                        }
                    }

                    host.Owner.BroadcastPacket(new ShootPacket
                    {
                        BulletId   = prjId,
                        OwnerId    = host.Id,
                        Position   = prjPos,
                        Angle      = (float)startAngle,
                        Damage     = (short)dmg,
                        BulletType = (byte)desc.BulletType,
                        AngleInc   = (float)shootAngle,
                        NumShots   = (byte)count
                    }, null);
                }
                cool   = coolDown.Next(Random);
                Status = CycleStatus.Completed;
            }
            else
            {
                cool  -= time.thisTickTimes;
                Status = CycleStatus.InProgress;
            }

            state = cool;
        }
Example #44
0
        public void Teleport(RealmTime time, TeleportPacket packet)
        {
            var obj = Client.Player.Owner.GetEntity(packet.ObjectId);

            try
            {
                if (obj == null)
                {
                    return;
                }
                if (!TPCooledDown())
                {
                    SendError("Player.teleportCoolDown");
                    return;
                }
                if (obj.HasConditionEffect(ConditionEffectIndex.Paused))
                {
                    SendError("server.no_teleport_to_paused");
                    return;
                }
                var player = obj as Player;
                if (player != null && !player.NameChosen)
                {
                    SendError("server.teleport_needs_name");
                    return;
                }
                if (obj.Id == Id)
                {
                    SendError("server.teleport_to_self");
                    return;
                }
                if (!Owner.AllowTeleport)
                {
                    SendError(GetLanguageString("server.no_teleport_in_realm", new KeyValuePair <string, object>("realm", Owner.Name)));
                    return;
                }

                if (CheckTeleportLowHp() && HP <= MaxHp / 2)
                {
                    ApplyConditionEffect(new ConditionEffect
                    {
                        Effect     = ConditionEffectIndex.Damaging,
                        DurationMS = 5000
                    });
                }
                else
                {
                    ApplyConditionEffect(new ConditionEffect
                    {
                        Effect     = ConditionEffectIndex.Damaging,
                        DurationMS = 0
                    });
                }


                SetTPDisabledPeriod();
                Move(obj.X, obj.Y);
                Pet?.Move(obj.X, obj.X);
                FameCounter.Teleport();
                SetNewbiePeriod();
                UpdateCount++;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                SendError("player.cannotTeleportTo");
                return;
            }
            Owner.BroadcastPacket(new GotoPacket
            {
                ObjectId = Id,
                Position = new Position
                {
                    X = X,
                    Y = Y
                }
            }, null);
            if (!isNotVisible)
            {
                Owner.BroadcastPacket(new ShowEffectPacket
                {
                    EffectType = EffectType.Teleport,
                    TargetId   = Id,
                    PosA       = new Position
                    {
                        X = X,
                        Y = Y
                    },
                    Color = new ARGB(0xFFFFFFFF)
                }, null);
            }
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int)state;

            if (cool <= 0)
            {
                var entity = host.GetPlayerOwner();

                if (!entity.HasConditionEffect(ConditionEffectIndex.Sick))
                {
                    try
                    {
                        var distance = Vector2.Distance(new Vector2(host.X, host.Y),
                                                        new Vector2(entity.X, entity.Y));

                        if (distance < 10)
                        {
                            var hp    = entity.HP;
                            var maxHp = entity.Stats[0] + entity.Boost[0];
                            hp = Math.Min(hp + 25, maxHp);

                            if (hp != entity.HP)
                            {
                                var n = hp - entity.HP;
                                entity.HP = hp;
                                entity.UpdateCount++;
                                entity.Owner.BroadcastMessage(new SHOWEFFECT
                                {
                                    EffectType = EffectType.Heal,
                                    TargetId   = entity.Id,
                                    Color      = new ARGB(0xFFFFFF)
                                }, null);
                                entity.Owner.BroadcastMessage(new SHOWEFFECT
                                {
                                    EffectType = EffectType.Line,
                                    TargetId   = host.Id,
                                    PosA       = new Position {
                                        X = entity.X, Y = entity.Y
                                    },
                                    Color = new ARGB(0xFFFFFF)
                                }, null);
                                entity.Owner.BroadcastMessage(new NOTIFICATION
                                {
                                    ObjectId = entity.Id,
                                    Text     = "+" + n,
                                    Color    = new ARGB(0xff00ff00)
                                }, null);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                cool = 500;
            }
            else
            {
                cool -= time.ElapsedMsDelta;
            }

            state = cool;
        }
Example #46
0
 protected override void TickCore(Entity host, RealmTime time, ref object state)
 {
 }
Example #47
0
        public void SendUpdate(RealmTime time)
        {
            mapWidth  = Owner.Map.Width;
            mapHeight = Owner.Map.Height;
            var map   = Owner.Map;
            var xBase = (int)X;
            var yBase = (int)Y;

            var sendEntities = new HashSet <Entity>(GetNewEntities());

            var list = new List <UpdatePacket.TileData>(APPOX_AREA_OF_SIGHT);
            var sent = 0;

            foreach (var i in Sight.GetSightCircle(SIGHTRADIUS))
            {
                var x = i.X + xBase;
                var y = i.Y + yBase;

                WmapTile tile;
                if (x < 0 || x >= mapWidth ||
                    y < 0 || y >= mapHeight ||
                    tiles[x, y] >= (tile = map[x, y]).UpdateCount)
                {
                    continue;
                }

                var world = Manager.GetWorld(Owner.Id);
                if (world.Dungeon)
                {
                    //Todo add blocksight
                }

                list.Add(new UpdatePacket.TileData()
                {
                    X    = (short)x,
                    Y    = (short)y,
                    Tile = tile.TileId
                });
                tiles[x, y] = tile.UpdateCount;
                sent++;
            }
            FameCounter.TileSent(sent);

            var dropEntities = GetRemovedEntities().Distinct().ToArray();

            clientEntities.RemoveWhere(_ => Array.IndexOf(dropEntities, _.Id) != -1);

            var toRemove = lastUpdate.Keys.Where(i => !clientEntities.Contains(i)).ToList();

            toRemove.ForEach(i => lastUpdate.Remove(i));

            foreach (var i in sendEntities)
            {
                lastUpdate[i] = i.UpdateCount;
            }

            var newStatics    = GetNewStatics(xBase, yBase).ToArray();
            var removeStatics = GetRemovedStatics(xBase, yBase).ToArray();
            var removedIds    = new List <int>();

            foreach (var i in removeStatics)
            {
                removedIds.Add(Owner.Map[i.X, i.Y].ObjId);
                clientStatic.Remove(i);
            }

            if (sendEntities.Count <= 0 && list.Count <= 0 && dropEntities.Length <= 0 && newStatics.Length <= 0 &&
                removedIds.Count <= 0)
            {
                return;
            }
            var packet = new UpdatePacket()
            {
                Tiles            = list.ToArray(),
                NewObjects       = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(),
                RemovedObjectIds = dropEntities.Concat(removedIds).ToArray()
            };

            Client.SendPacket(packet);
            UpdatesSend++;
        }
Example #48
0
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     state = coolDownOffset;
 }
Example #49
0
 public override void Tick(RealmTime time)
 {
     base.Tick(time);
 }
Example #50
0
 protected abstract void TickCore(Pet host, RealmTime time, ref object state);
Example #51
0
 protected override bool TickCore(Entity host, RealmTime time, ref object state)
 {
     return(host.GetNearestEntity(_dist, _target) != null);
 }
Example #52
0
 protected sealed override void OnStateExit(Entity host, RealmTime time, ref object state)
 {
     base.OnStateExit(host, time, ref state);
 }
Example #53
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            try
            {
                int cool = (int?)state ?? -1;
                Status = CycleStatus.NotStarted;

                if (cool <= 0)
                {
                    if (host.HasConditionEffect(ConditionEffectIndex.Stunned))
                    {
                        return;
                    }
                    int count = shoots;
                    if (host.HasConditionEffect(ConditionEffectIndex.Dazed))
                    {
                        count = Math.Max(1, count / 2);
                    }

                    Entity player = host.GetNearestEntity(range, null);
                    if (player != null || defaultAngle != null || direction != null)
                    {
                        ProjectileDesc desc = host.ObjectDesc.Projectiles[index];

                        double a = direction ??
                                   (player == null ? defaultAngle.Value : Math.Atan2(player.Y - host.Y, player.X - host.X));
                        a += angleOffset;

                        /*if (aim != 0 && player != null)
                         *  a += Predict(host, player, desc) * aim;*/

                        int dmg;
                        if (host is Character)
                        {
                            dmg = (host as Character).Random.Next(desc.MinDamage, desc.MaxDamage);
                        }
                        else
                        {
                            dmg = Random.Next(desc.MinDamage, desc.MaxDamage);
                        }

                        double   startAngle = a - shootAngle * (count - 1) / 2;
                        byte     prjId      = 0;
                        Position prjPos     = EnemyShootHistory(host);
                        for (int i = 0; i < count; i++)
                        {
                            Projectile prj = host.CreateProjectile(
                                desc, host.ObjectType, dmg, time.TotalElapsedMs,
                                prjPos, (float)(startAngle + shootAngle * i));
                            host.Owner.EnterWorld(prj);
                            if (i == 0)
                            {
                                prjId = prj.ProjectileId;
                            }
                        }
                        if (rotateEffect)
                        {
                            Position target;
                            if (rotateAngle != null)
                            {
                                target = new Position
                                {
                                    X = host.X + (float)(Math.Cos(rotateAngle.Value)),
                                    Y = host.Y + (float)(Math.Sin(rotateAngle.Value)),
                                }
                            }
                            ;
                            else
                            {
                                target = new Position
                                {
                                    X = player.X,
                                    Y = player.Y,
                                }
                            };

                            host.Owner.BroadcastMessage(new SHOWEFFECT
                            {
                                EffectType = EffectType.Coneblast,
                                Color      = new ARGB(rotateColor),
                                TargetId   = host.Id,
                                PosA       = target,
                                PosB       = new Position {
                                    X = rotateRadius
                                },                                        //radius
                            }, null);
                        }

                        host.Owner.BroadcastMessage(new ENEMYSHOOT
                        {
                            BulletId   = prjId,
                            OwnerId    = host.Id,
                            Position   = prjPos,
                            Angle      = (float)startAngle,
                            Damage     = (short)dmg,
                            BulletType = (byte)desc.BulletType,
                            AngleInc   = (float)shootAngle,
                            NumShots   = (byte)count,
                        }, null);
                    }
                    cool   = coolDown.Next(Random);
                    Status = CycleStatus.Completed;
                }
                else
                {
                    cool  -= time.ElapsedMsDelta;
                    Status = CycleStatus.InProgress;
                }

                state = cool;
            }
            catch (IndexOutOfRangeException)
            {
                Log.Warn($"Projectile index '{index}' doesn't exist in Shoot behavior of entity {host.Name} (state: {host.CurrentState.Name}).");
                return;
            }
        }
 public override void Tick(RealmTime time)
 {
     base.Tick(time);
     if (!started && duelist1 != null)
     {
         waitingNotif--;
         if (waitingNotif <= 0)
         {
             duelist1.Client.SendPacket(new NotificationPacket
             {
                 Color    = new ARGB(0xFF2222FF),
                 ObjectId = duelist1.Id,
                 Text     = "Waiting for duelist..."
             });
             waitingNotif = 2 * 10;
         }
     }
     if (started && QueuedPlayers.ContainsKey(duelist1))
     {
         QueuedPlayers.Remove(duelist1);
     }
     if (started && timeLeft > 0)
     {
         if (timeLeft % Manager.Logic.TPS == 0)
         {
             if (timeLeft / Manager.Logic.TPS == 5)
             {
                 duelist1.SendInfo("Duel begun with " + duelist2.Name + ".");
                 duelist2.SendInfo("Duel begun with " + duelist1.Name + ".");
             }
             foreach (Player i in Players.Values)
             {
                 i.Client.SendPacket(new NotificationPacket
                 {
                     Color    = timeLeft / Manager.Logic.TPS == 5 ? new ARGB(0xFFFF00FF) : new ARGB(0xFFFF0000),
                     ObjectId = i.Id,
                     Text     = timeLeft / Manager.Logic.TPS == 5
                         ? duelist1.Name + " vs. " + duelist2.Name
                         : timeLeft / Manager.Logic.TPS == 4
                             ? "Duel beginning in..."
                             : (timeLeft / Manager.Logic.TPS).ToString()
                 });
             }
         }
         timeLeft--;
     }
     else if (started && timeLeft == 0)
     {
         AllowAbilityTeleport = true;
         PvP = true;
         foreach (Player i in Players.Values)
         {
             i.Client.SendPacket(new NotificationPacket
             {
                 Color    = new ARGB(0xFF770000),
                 ObjectId = i.Id,
                 Text     = "Fight!"
             });
             i.PvP = true;
             i.UpdateCount++;
         }
         foreach (IntPoint point in Map.Regions[TileRegion.Hallway])
         {
             WmapTile tile = Map[point.X, point.Y].Clone();
             tile.ObjType          = 0;
             Map[point.X, point.Y] = tile;
         }
         timeLeft = -1;
     }
 }
Example #55
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int?)state ?? -1; // <-- crashes server due to state being null... patched now but should be looked at.

            Status = CycleStatus.NotStarted;

            if (cool <= 0)
            {
                if (host.HasConditionEffect(ConditionEffects.Stunned))
                {
                    return;
                }

                var count = _count;
                if (host.HasConditionEffect(ConditionEffects.Dazed))
                {
                    count = (int)Math.Ceiling(_count / 2.0);
                }

                Entity player;
                if (host.AttackTarget != null)
                {
                    player = host.AttackTarget;
                }
                else
                {
                    player = _shootLowHp ?
                             host.GetLowestHpEntity(_radius, null) :
                             host.GetNearestEntity(_radius, null);
                }

                if (player != null || _defaultAngle != null || _fixedAngle != null)
                {
                    var desc = host.ObjectDesc.Projectiles[_projectileIndex];

                    float a;

                    if (_fixedAngle != null)
                    {
                        a = (float)_fixedAngle;
                    }
                    else if (player != null)
                    {
                        if (_predictive != 0 && _predictive > Random.NextDouble())
                        {
                            a = Predict(host, player, desc);
                        }
                        else
                        {
                            a = (float)Math.Atan2(player.Y - host.Y, player.X - host.X);
                        }
                    }
                    else if (_defaultAngle != null)
                    {
                        a = (float)_defaultAngle;
                    }
                    else
                    {
                        a = 0;
                    }

                    a += _angleOffset + ((_rotateAngle != null) ? (float)_rotateAngle * _rotateCount : 0);
                    _rotateCount++;

                    int      dmg        = Random.Next(desc.MinDamage, desc.MaxDamage);
                    var      startAngle = a - _shootAngle * (count - 1) / 2;
                    byte     prjId      = 0;
                    Position prjPos     = new Position()
                    {
                        X = host.X, Y = host.Y
                    };
                    var prjs = new Projectile[count];
                    for (int i = 0; i < count; i++)
                    {
                        var prj = host.CreateProjectile(
                            desc, host.ObjectType, dmg, time.TotalElapsedMs,
                            prjPos, (float)(startAngle + _shootAngle * i));
                        host.Owner.EnterWorld(prj);

                        if (i == 0)
                        {
                            prjId = prj.ProjectileId;
                        }

                        prjs[i] = prj;
                    }

                    var pkt = new EnemyShoot()
                    {
                        BulletId    = prjId,
                        OwnerId     = host.Id,
                        StartingPos = prjPos,
                        Angle       = startAngle,
                        Damage      = (short)dmg,
                        BulletType  = (byte)(desc.BulletType),
                        AngleInc    = _shootAngle,
                        NumShots    = (byte)count,
                    };
                    foreach (var plr in host.Owner.Players.Values
                             .Where(p => p.DistSqr(host) < Player.RadiusSqr))
                    {
                        plr.Client.SendPacket(pkt);
                    }
                }
                cool   = _coolDown.Next(Random);
                Status = CycleStatus.Completed;
            }
            else
            {
                cool  -= time.ElaspedMsDelta;
                Status = CycleStatus.InProgress;
            }

            state = cool;
        }
Example #56
0
 protected override bool TickCore(RealmTime time)
 {
     Taunt(taunt, false);
     return(true);
 }
Example #57
0
        public override bool HitByProjectile(Projectile projectile, RealmTime time)
        {
            if (stat)
            {
                return(false);
            }
            if (HasConditionEffect(ConditionEffects.Invincible))
            {
                return(false);
            }

            var player = projectile.ProjectileOwner is Player;
            var pet    = projectile.ProjectileOwner.Self.isPet;

            if ((player || pet) &&
                !HasConditionEffect(ConditionEffects.Paused) &&
                !HasConditionEffect(ConditionEffects.Stasis))
            {
                var plr = pet ? projectile.ProjectileOwner.Self.PlayerOwner : projectile.ProjectileOwner as Player;

                var def = ObjectDesc.Defense;
                if (projectile.Descriptor.ArmorPiercing)
                {
                    def = 0;
                }
                var dmg = (int)StatsManager.GetDefenseDamage(this, projectile.Damage, def);
                if (!HasConditionEffect(ConditionEffects.Invulnerable))
                {
                    HP -= dmg;
                }
                ApplyConditionEffect(projectile.Descriptor.Effects);
                Owner.BroadcastPacket(new DamagePacket
                {
                    TargetId = Id,
                    Effects  = projectile.ConditionEffects,
                    Damage   = (ushort)dmg,
                    Killed   = HP < 0,
                    BulletId = projectile.ProjectileId,
                    ObjectId = projectile.ProjectileOwner.Self.Id
                }, pet ? null : plr);

                foreach (var i in CondBehaviors)
                {
                    if ((i.Condition & BehaviorCondition.OnHit) != 0)
                    {
                        i.Behave(BehaviorCondition.OnHit, this, time, projectile);
                    }
                }
                counter.HitBy(plr, projectile, dmg);

                if (HP < 0)
                {
                    foreach (var i in CondBehaviors)
                    {
                        if ((i.Condition & BehaviorCondition.OnDeath) != 0)
                        {
                            i.Behave(BehaviorCondition.OnDeath, this, time, counter);
                        }
                    }
                    counter.Death();
                    if (Owner != null)
                    {
                        Owner.LeaveWorld(this);
                    }
                }
                UpdateCount++;
                return(true);
            }
            return(false);
        }
Example #58
0
 protected abstract override bool TickCore(RealmTime time);
Example #59
0
        public override void Tick(RealmTime time)
        {
            try
            {
                if (Manager.Clients.Count(_ => _.Value.Id == Client.Id) == 0)
                {
                    if (Owner != null)
                    {
                        Owner.LeaveWorld(this);
                    }
                    else
                    {
                        WorldInstance.LeaveWorld(this);
                    }
                    Manager.Database.DoActionAsync(db => db.UnlockAccount(Client.Account));
                    return;
                }
                if (Client.Stage == ProtocalStage.Disconnected || (!Client.Account.VerifiedEmail && Program.Verify))
                {
                    if (Owner != null)
                    {
                        Owner.LeaveWorld(this);
                    }
                    else
                    {
                        WorldInstance.LeaveWorld(this);
                    }
                    Manager.Database.DoActionAsync(db => db.UnlockAccount(Client.Account));
                    return;
                }
            }
            catch (Exception e)
            {
                log.Error(e);
            }

            if (Stats != null && Boost != null)
            {
                MaxHp = Stats[0] + Boost[0];
                MaxMp = Stats[1] + Boost[1];
            }



            if (CheckHalfMPAImmune() && Mp >= MaxMp / 2)
            {
                ApplyConditionEffect(new ConditionEffect
                {
                    Effect     = ConditionEffectIndex.ArmorBreakImmune,
                    DurationMS = -1
                });
            }
            else
            {
                ApplyConditionEffect(new ConditionEffect
                {
                    Effect     = ConditionEffectIndex.ArmorBreakImmune,
                    DurationMS = 0
                });
            }

            if (!KeepAlive(time))
            {
                return;
            }

            if (Boost == null)
            {
                CalcBoost();
            }

            TradeHandler?.Tick(time);
            HandleRegen(time);
            HandleQuest(time);
            HandleEffects(time);
            HandleGround(time);
            HandleBoosts();

            FameCounter.Tick(time);

            //if(pingSerial > 5)
            //    if (!Enumerable.Range(UpdatesSend, 5000).Contains(UpdatesReceived))
            //        Client.Disconnect();

            if (Mp < 0)
            {
                Mp = 0;
            }

            /* try
             * {
             *     psr.Database.SaveCharacter(psr.Account, psr.Character);
             *     UpdateCount++;
             * }
             * catch (ex)
             * {
             * }
             */

            try
            {
                if (Owner != null)
                {
                    SendUpdate(time);
                    if (!Owner.IsPassable((int)X, (int)Y) && Client.Account.Rank < 2)
                    {
                        log.Fatal($"Player {Name} No-Cliped at position: {X}, {Y}");
                    }
                }
            }
            catch (Exception e)
            {
                log.Error(e);
            }
            try
            {
                SendNewTick(time);
            }
            catch (Exception e)
            {
                log.Error(e);
            }

            if (HP < 0 && !dying)
            {
                Death("Unknown");
                return;
            }

            base.Tick(time);
        }
Example #60
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int)state;

            if (cool <= 0)
            {
                if (host.HasConditionEffect(ConditionEffectIndex.Stunned))
                {
                    return;
                }

                Entity player = host.GetNearestEntity(range, null);
                if (player != null || fixedAngle != null)
                {
                    Position target;
                    if (fixedAngle != null)
                    {
                        target = new Position
                        {
                            X = (float)(range * Math.Cos(fixedAngle.Value)),
                            Y = (float)(range * Math.Sin(fixedAngle.Value)),
                        }
                    }
                    ;
                    else
                    {
                        target = new Position
                        {
                            X = player.X,
                            Y = player.Y,
                        }
                    };
                    host.Owner.BroadcastPacket(new ShowEffectPacket
                    {
                        EffectType = EffectType.Throw,
                        Color      = new ARGB(0xffff0000),
                        TargetId   = host.Id,
                        PosA       = target
                    }, null);
                    host.Owner.Timers.Add(new WorldTimer(1500, (world, t) =>
                    {
                        world.BroadcastPacket(new AOEPacket
                        {
                            Position       = target,
                            Radius         = radius,
                            Damage         = (ushort)damage,
                            EffectDuration = 0,
                            Effects        = 0,
                            OriginType     = host.ObjectType
                        }, null);
                        world.Aoe(target, radius, true, p => { (p as IPlayer).Damage(damage, host as Character); });
                    }));
                }
                cool = coolDown.Next(Random);
            }
            else
            {
                cool -= time.thisTickTimes;
            }

            state = cool;
        }
    }