public static Entity GetNearestEntityPlayer(Player player, Position pos, double dist) { try { if (player.Owner == null) { return(null); } Entity ret = null; foreach (Entity i in player.Owner.EnemiesCollision.HitTest(pos.X, pos.Y, dist)) { if (!(i is Enemy)) { continue; } double d = i.Dist(player); if (ret == null || d < ret.Dist(player)) { ret = i; } } return(ret); } catch (Exception e) { Console.Out.WriteLine(e); return(null); } }
public static Entity GetNearestEntity(this Entity entity, double dist, ushort?objType) //Null for player { try { if (entity.Owner == null) { return(null); } Entity ret = null; if (objType == null) { foreach (Entity i in entity.Owner.PlayersCollision.HitTest(entity.X, entity.Y, dist)) { if (!(i as IPlayer).IsVisibleToEnemy()) { continue; } double d = i.Dist(entity); if (ret == null || d < ret.Dist(entity)) { ret = i; } } } else { foreach (Entity i in entity.Owner.EnemiesCollision.HitTest(entity.X, entity.Y, dist)) { if (i.ObjectType != objType.Value) { continue; } double d = i.Dist(entity); if (ret == null || d < ret.Dist(entity)) { ret = i; } } } return(ret); } catch (Exception e) { Console.Out.WriteLine(e); return(null); } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (host.AttackTarget == null || host.AttackTarget.Owner == null) { return; } var cool = (int)state; if (cool <= 0) { // death strike if (_killAll) { foreach (var plr in host.Owner.Players.Values .Where(p => !p.HasConditionEffect(ConditionEffects.Hidden))) { Kill(host, plr, time); } } else { Kill(host, host.AttackTarget, time); } // send kill message if (_killMessage != null) { var packet = new Text() { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, NumStars = -1, BubbleTime = 3, Recipient = "", Txt = _killMessage, CleanText = "" }; foreach (var i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15).Where(e => e is Player)) { if (i is Player && host.Dist(i) < 15) { (i as Player).Client.SendPacket(packet); } } } cool = _coolDown.Next(Random); } else { cool -= time.ElaspedMsDelta; } state = cool; }
/// <summary> /// Gets the closest entity to a target entity based on object type. /// </summary> /// <param name="entity">Target entity for search.</param> /// <param name="dist">Maximum distance for query.</param> /// <param name="objType">Type of entity to be queried. Null for player.</param> /// <returns>An Entity.</returns> public static Entity GetNearestEntity(this Entity entity, double dist, ushort?objType) { if (!entity.IsValid()) { return(null); } Entity ret = null; if (objType == null) { foreach (Entity i in entity.Owner.PlayersCollision.HitTest(entity.X, entity.Y, dist)) { if (!i.IsValid() || !(i as IPlayer).IsVisibleToEnemy()) { continue; } if (ret == null || i.Dist(entity) < ret.Dist(entity)) { ret = i; } } } else { foreach (Entity i in entity.Owner.EnemiesCollision.HitTest(entity.X, entity.Y, dist)) { if (!i.IsValid() || i.ObjectType != objType.Value) { continue; } if (ret == null || i.Dist(entity) < ret.Dist(entity)) { ret = i; } } } return(ret); }
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) { TextPacket packet = new TextPacket { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, Stars = -1, BubbleTime = 5, Recipient = "", Text = text, CleanText = "" }; if (text.Contains("{PLAYER}")) { Entity player = host.GetNearestEntity(10, null); if (player == null) { return; } text.Replace("{PLAYER}", player.Name); } text.Replace("{HP}", (host as Enemy).HP.ToString()); foreach (Player i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 999).OfType <Player>()) { if (host.Dist(i) < 999) { i.Client.SendPacket(packet); } } } else { cool -= time.thisTickTimes; Status = CycleStatus.InProgress; } state = cool; }
private static double Predict(Entity host, Entity target, ProjectileDesc desc) { var history = target.TryGetHistory(100); if (history == null) { return(0); } var originalAngle = Math.Atan2(history.Value.Y - host.Y, history.Value.X - host.X); var newAngle = Math.Atan2(target.Y - host.Y, target.X - host.X); var bulletSpeed = desc.Speed / 100f; var dist = target.Dist(host); var angularVelo = (newAngle - originalAngle) / (100 / 1000f); return(angularVelo * bulletSpeed); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { ScaleHPState scstate = (ScaleHPState)state; if (scstate.cooldown <= 0) { scstate.cooldown = 1000; if (!(host is Enemy)) { return; } if (scstate.maxHP == 0) { scstate.maxHP = (host as Enemy).MaximumHP + maxAdditional; } int plrCount = 0; foreach (var i in host.Owner.Players) { if (scstate.pNamesCounted.Contains(i.Value.Name)) { continue; } if (dist > 0) { if (host.Dist(i.Value) < dist) { scstate.pNamesCounted.Add(i.Value.Name); } } else { scstate.pNamesCounted.Add(i.Value.Name); } } plrCount = scstate.pNamesCounted.Count; if (plrCount > scstate.initialScaleAmount) { int amountInc = (plrCount - scstate.initialScaleAmount) * amountPerPlayer; scstate.initialScaleAmount += (plrCount - scstate.initialScaleAmount); if (maxAdditional != 0) { amountInc = Math.Min(maxAdditional, amountInc); } // ex: Enemy with 4000HP / 8000HP, being increased by 1200 int curHp = (host as Enemy).HP; // ex: current hp was 4000HP int hpMaximum = (host as Enemy).MaximumHP; // ex: max hp was 8000HP double curHpPercent = ((double)curHp / hpMaximum); // ex: 0.5 int newHpMaximum = (host as Enemy).MaximumHP + amountInc; // ex: max hp is now 9200HP int newHp = Convert.ToInt32(newHpMaximum * curHpPercent); // ex: current has is now 4600HP if (!scstate.hitMaxHP || healAfterMax) { (host as Enemy).HP = newHp; (host as Enemy).MaximumHP = newHpMaximum; } if ((host as Enemy).MaximumHP >= scstate.maxHP && maxAdditional != 0) { (host as Enemy).MaximumHP = scstate.maxHP; scstate.hitMaxHP = true; } if ((host as Enemy).HP > (host as Enemy).MaximumHP) { (host as Enemy).HP = (host as Enemy).MaximumHP; } // DEBUG Console.WriteLine("Increasing HP by: " + amountInc + ", New HP: " + (host as Enemy).HP + ", Player Count: " + host.Owner.Players.Count); } } else { scstate.cooldown -= time.ElaspedMsDelta; } state = scstate; }
public static Entity GetNearestEntity(this Entity entity, double dist, ushort?objType) //Null for player { try { if (entity.Owner == null) { return(null); } Entity ret = null; if (entity is Enemy && entity.HasConditionEffect(ConditionEffects.Blind)) { return(null); } if (objType == null) { foreach (Entity i in entity.Owner.PlayersCollision.HitTest(entity.X, entity.Y, dist)) { if (!(i as IPlayer).IsVisibleToEnemy()) { continue; } double d = i.Dist(entity); if (ret == null || d < ret.Dist(entity)) { ret = i; } } if (entity is Enemy) { foreach (var i in entity.Owner.EnemiesCollision.HitTest(entity.X, entity.Y, dist)) { if (i is ItemEntity && (i as ItemEntity).targeted == true) { double d = i.Dist(entity); if (ret == null || d < ret.Dist(entity)) { ret = i; } } } foreach (var i in (entity as Enemy).raged) { if (i.Key == null) { continue; } if (!(i.Key as IPlayer).IsVisibleToEnemy()) { continue; } ret = i.Key; } } } else { foreach (Entity i in entity.Owner.EnemiesCollision.HitTest(entity.X, entity.Y, dist)) { if (i.ObjectType != objType.Value) { continue; } double d = i.Dist(entity); if (ret == null || d < ret.Dist(entity)) { ret = i; } } } return(ret); } catch (Exception e) { Console.Out.WriteLine(e); return(null); } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (checkForStates && !states.ToList().Contains(host.CurrentState.Name)) { return; } if (state != null && cooldown.CoolDown == 0) { return; //cooldown = 0 -> once per state entry } int c; if (state == null) { c = cooldown.Next(Random); } else { c = (int)state; } c -= time.ElapsedMsDelta; state = c; if (c > 0) { return; } c = cooldown.Next(Random); state = c; if (Random.NextDouble() >= probability) { return; } string taunt = text.Length == 1 ? text[0] : text[Random.Next(text.Length)]; if (taunt.Contains("{PLAYER}")) { Entity player = host.GetNearestEntity(10, null); if (player == null) { return; } taunt = taunt.Replace("{PLAYER}", player.Name); } taunt = taunt.Replace("{HP}", (host as Enemy).HP.ToString()); TEXT packet = new TEXT { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, Stars = -1, Admin = 0, BubbleTime = 5, Recipient = "", Text = taunt, CleanText = "", NameColor = 0x123456, TextColor = 0x123456 }; if (broadcast) { host.Owner.BroadcastPacket(packet, null); } else { foreach (Player i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15).OfType <Player>()) { if (host.Dist(i) < 15) { i.Client.SendMessage(packet); } } } }
protected override void HandlePacket(Client client, InvSwapPacket packet) { if (client.Player.Owner == null) { return; } if (client.Player.Owner is PetYard) { client.SendPacket(new InvResultPacket { Result = 0 }); } client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.SlotObject1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.SlotObject2.ObjectId); IContainer con1 = en1 as IContainer; IContainer con2 = en2 as IContainer; if (packet.SlotObject1.SlotId == 254 || packet.SlotObject1.SlotId == 255 || packet.SlotObject2.SlotId == 254 || packet.SlotObject2.SlotId == 255) { if (packet.SlotObject2.SlotId == 254) { if (client.Player.HealthPotions < 6) { client.Player.HealthPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject2.SlotId == 255) { if (client.Player.MagicPotions < 6) { client.Player.MagicPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject1.SlotId == 254) { if (client.Player.HealthPotions > 0) { client.Player.HealthPotions--; con2.Inventory[packet.SlotObject2.SlotId] = null; } } if (packet.SlotObject1.SlotId == 255) { if (client.Player.MagicPotions > 0) { client.Player.MagicPotions--; con2.Inventory[packet.SlotObject1.SlotId] = null; } } if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } return; } //TODO: locker Item item1 = con1.Inventory[packet.SlotObject1.SlotId]; Item item2 = con2.Inventory[packet.SlotObject2.SlotId]; List <ushort> publicbags = new List <ushort> { 0x0500, 0x0506, 0x0501 }; if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } if (!IsValid(item1, item2, con1, con2, packet, client)) { client.Disconnect(); return; } if (con2 is OneWayContainer) { con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = null; client.Player.DropBag(item1); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[packet.SlotObject2.SlotId] != null) { (en2 as Player)?.Client.SendPacket(new InvResultPacket { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } using (Database db = new Database()) { try { Account acc = db.GetAccount(client.Account.AccountId, Manager.GameData); acc.Gifts.Remove(con1.Inventory[packet.SlotObject1.SlotId].ObjectType); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = @"UPDATE accounts SET gifts=@gifts WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString(acc.Gifts.ToArray())); cmd.ExecuteNonQuery(); } catch (Exception ex) { log.Error(ex); } } con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = item1; (en2 as Player).CalcBoost(); client.Player.SaveToCharacter(); client.Save(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); return; } if (en1 is Player && en2 is Player & en1.Id != en2.Id) { client.Manager.Chat.Announce($"{en1.Name} just tried to steal items from {en2.Name}'s inventory, GTFO YOU GOD DAMN FEGIT!!!!11111oneoneoneeleven"); return; } ; con1.Inventory[packet.SlotObject1.SlotId] = item2; con2.Inventory[packet.SlotObject2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains(en1.ObjectType) && item2.Soulbound && item2.Divine) { client.Player.DropBag(item2); con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains(en2.ObjectType) && item1.Soulbound && item1.Divine) { client.Player.DropBag(item1); con2.Inventory[packet.SlotObject2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Save(); } (en1 as Player).CalcBoost(); (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Save(); } (en2 as Player).CalcBoost(); (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (client.Player.Owner is Vault) { if ((client.Player.Owner as Vault).PlayerOwnerName == client.Account.Name) { return; } } client.Player.SaveToCharacter(); client.Save(); }, PendingPriority.Networking); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { Player player = host.GetPlayerOwner(); Entity pet = player.Pet; bool hatchling = player.HatchlingPet; if (hatchling) { return; } if (player.Owner == null || pet == null || host == null) { pet.Owner.LeaveWorld(host); return; } if (host.Owner.SafePlace) { return; } int cool = (int?)state ?? -1; Status = CycleStatus.NotStarted; if (cool <= 0) { if (player.HasConditionEffect(ConditionEffectIndex.Sick) || player.HasConditionEffect(ConditionEffectIndex.PetDisable)) { return; } int stars = player.Stars; Entity target = pet.GetNearestEntity(12, false, enemy => enemy is Enemy && pet.Dist(enemy) <= 12) as Enemy; if (target != null && target.ObjectDesc.Enemy) { ProjectileDesc desc = pet.ObjectDesc.Projectiles[projectileIndex]; double a = fixedAngle ?? (target == null ? defaultAngle.Value : Math.Atan2(target.Y - pet.Y, target.X - pet.X)); a += angleOffset; int variance; if (stars == 70) { variance = 7000; } else { variance = player.Stars * 100; } cool = special ? cool = coolDown.Next(Random) : (7750 - variance); // max 750ms cooldown if not special Random rnd = new Random(); int min = 0; int max = 100; int success = stars + 30; int rng = rnd.Next(min, max); if (rng > success) { List <Message> _outgoing = new List <Message>(); SHOWEFFECT _effect = new SHOWEFFECT(); Position _position = new Position(); NOTIFICATION _notification = new NOTIFICATION(); _position.X = .25f; _position.Y = 2 / _position.X; _effect.Color = new ARGB(0xFF0000); _effect.EffectType = EffectType.Flash; _effect.PosA = _position; _effect.TargetId = pet.Id; _outgoing.Add(_effect); _notification.Color = new ARGB(0xFFFFFF); _notification.ObjectId = pet.Id; _notification.Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"Miss!\"}}"; _outgoing.Add(_notification); pet.Owner.BroadcastMessage(_outgoing, null); state = cool; return; } int dmg = rnd.Next(desc.MinDamage, desc.MaxDamage); double startAngle = a - shootAngle * (count - 1) / 2; Position prjPos = new Position() { X = pet.X, Y = pet.Y }; Projectile prj = player.CreateProjectile(desc, pet.ObjectType, dmg, time.TotalElapsedMs, prjPos, (float)startAngle); player.Owner.AddProjectileFromId(player.Id, prj.ProjectileId, prj); player.Owner.EnterWorld(prj); List <Message> _outgoingMessages = new List <Message>(); ENEMYSHOOT _shoot = new ENEMYSHOOT { BulletId = 0, OwnerId = pet.Id, Position = prjPos, Angle = prj.Angle, Damage = 0, BulletType = 0, AngleInc = (float)shootAngle, NumShots = 0 }; SERVERPLAYERSHOOT _shoot2 = new SERVERPLAYERSHOOT { BulletId = prj.ProjectileId, OwnerId = player.Id, ContainerType = pet.ObjectType, StartingPos = prj.BeginPos, Angle = prj.Angle, Damage = (short)prj.Damage }; _outgoingMessages.Add(_shoot); // visual, display no animation only activate pet set alt index _outgoingMessages.Add(_shoot2); player.Owner.BroadcastMessage(_outgoingMessages, null); player.FameCounter.Shoot(prj); Status = CycleStatus.Completed; } else { return; } } else { cool -= time.ElapsedMsDelta; Status = CycleStatus.InProgress; } state = cool; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (state != null && cooldown.CoolDown == 0) return; //cooldown = 0 -> once per state entry int c; if (state == null) c = cooldown.Next(Random); else c = (int)state; c -= time.thisTickTimes; state = c; if (c > 0) return; c = cooldown.Next(Random); state = c; if (Random.NextDouble() >= probability) return; var taunt = text.Length == 1 ? text[0] : text[Random.Next(text.Length)]; if (taunt.Contains("{PLAYER}")) { Entity player = host.GetNearestEntity(10, null); if (player == null) return; taunt = taunt.Replace("{PLAYER}", player.Name); } taunt = taunt.Replace("{HP}", (host as Enemy).HP.ToString()); var packet = new TextPacket() { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, Stars = -1, BubbleTime = 5, Recipient = "", Text = taunt, CleanText = "" }; if (broadcast) host.Owner.BroadcastPacket(packet, null); else foreach (var i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15)) { if (host.Dist(i) < 15) (i as Player).Client.SendPacket(packet); } }
protected override void HandlePacket(Client client, InvSwapPacket packet) { if (client.Player.Owner == null) return; if (client.Player.HasConditionEffect(ConditionEffects.Paused)) return; client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.Obj1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.Obj2.ObjectId); var con1 = en1 as IContainer; var con2 = en2 as IContainer; Item item1 = con1.Inventory[packet.Obj1.SlotId]; Item item2 = con2.Inventory[packet.Obj2.SlotId]; ItemData data1 = con1.Inventory.Data[packet.Obj1.SlotId]; ItemData data2 = con2.Inventory.Data[packet.Obj2.SlotId]; bool Savespots = (en1.Owner.Name == "Market" || en1.Owner.Name == "Gold Market" || en1.Owner.Name == "Cloth Market"); //removed vault since it should save your inv while nexusing (duping) bool Savespots2 = (en2.Owner.Name == "Market" || en2.Owner.Name == "Gold Market" || en2.Owner.Name == "Cloth Market"); if (item1 != null) if (item1.AdminOnly) if (!client.Account.Admin) return; if (item2 != null) if (item2.AdminOnly) if (!client.Account.Admin) return; /* int MaxStack = item2.MaxStack; if (item1.ObjectType == item2.ObjectType && item2.Doses < item2.MaxStack && item2.Stackable) { data2 = new ItemData { Doses = item1.Doses + 1 }; if (item2.Doses > MaxStack) { data2 = new ItemData { Doses = MaxStack }; data1.Doses = (item2.Doses - MaxStack - 1); } else { item1 = null; con1.Inventory.Data[packet.Obj1.SlotId] = null; } } */ if (en1.Dist(en2) > 1) { if (en1 is Player) (en1 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); else if (en2 is Player) (en2 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); en1.UpdateCount++; en2.UpdateCount++; return; } if (!IsValid(item1, item2, con1, con2, packet, client)) { client.Disconnect(); return; } if (con2 is OneWayContainer) { con1.Inventory[packet.Obj1.SlotId] = null; con2.Inventory[packet.Obj2.SlotId] = null; client.Player.DropBag(item1, true); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[packet.Obj2.SlotId] != null) { (en2 as Player)?.Client.SendPacket(new InvResultPacket { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } using (Database db = new Database(Program.Settings.GetValue("conn"))) { try { Account acc = db.GetAccount(client.Account.AccountId); acc.Gifts.Remove(con1.Inventory[packet.Obj1.SlotId].ObjectType); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = @"UPDATE accounts SET gifts=@gifts WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString(acc.Gifts.ToArray())); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex); } } con1.Inventory[packet.Obj1.SlotId] = null; con2.Inventory[packet.Obj2.SlotId] = item1; (en2 as Player).CalculateBoost(); client.Player.SaveToCharacter(); client.Save(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); return; } var publicbags = new List<short> { 0x0500, 0x0506, 0x0501 }; con1.Inventory.Data[packet.Obj1.SlotId] = data2; con2.Inventory.Data[packet.Obj2.SlotId] = data1; con1.Inventory[packet.Obj1.SlotId] = item2; con2.Inventory[packet.Obj2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains((short)en1.ObjectType) && (item2.Soulbound || (data2 != null && data2.Soulbound))) { con1.Inventory.Data[packet.Obj1.SlotId] = null; con1.Inventory[packet.Obj1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains((short)en2.ObjectType) && (item1.Soulbound || (data1 != null && data1.Soulbound))) { con2.Inventory.Data[packet.Obj2.SlotId] = null; con2.Inventory[packet.Obj2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (Savespots) (en1 as Player).Client.Save(); (en1 as Player).CalculateBoost(); (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (en2 is Player) { if (Savespots2) (en2 as Player).Client.Save(); (en2 as Player).CalculateBoost(); (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (!(en2 is Player)) { var con = en2 as Container; } }); client.Save(); client.AddDatabaseOpperation(db => db.SaveCharacter(client.Account, client.Character)); }
protected override void HandlePacket(Client client, InvSwapPacket packet) { if (client.Player.Owner == null) { return; } if (client.Player.Owner is PetYard) { client.SendPacket(new InvResultPacket { Result = 0 }); } client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.SlotObject1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.SlotObject2.ObjectId); IContainer con1 = en1 as IContainer; IContainer con2 = en2 as IContainer; if (packet.SlotObject1.SlotId == 254 || packet.SlotObject1.SlotId == 255 || packet.SlotObject2.SlotId == 254 || packet.SlotObject2.SlotId == 255) { if (packet.SlotObject2.SlotId == 254) { if (client.Player.HealthPotions < 6) { client.Player.HealthPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject2.SlotId == 255) { if (client.Player.MagicPotions < 6) { client.Player.MagicPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject1.SlotId == 254) { if (client.Player.HealthPotions > 0) { client.Player.HealthPotions--; con2.Inventory[packet.SlotObject2.SlotId] = null; } } if (packet.SlotObject1.SlotId == 255) { if (client.Player.MagicPotions > 0) { client.Player.MagicPotions--; con2.Inventory[packet.SlotObject1.SlotId] = null; } } if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } return; } //TODO: locker Item item1 = con1.Inventory[packet.SlotObject1.SlotId]; Item item2 = con2.Inventory[packet.SlotObject2.SlotId]; List <ushort> publicbags = new List <ushort> { 0x0500, 0x0506, 0x0501 }; if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } if (en1 is Player && en2 is Player & en1.Id != en2.Id) { client.Player.kickforCheats(Player.possibleExploit.ITEM_STEAL); return; } ; if (!IsValid(item1, item2, con1, con2, packet, client)) { client.Disconnect(Client.DisconnectReason.INVALID_INVSWAP); return; } if (con2 is OneWayContainer || (en2.ObjectType == 0x0504 && Client.Player.Owner.Name != "Vault" && item1.Soulbound)) { con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = null; client.Player.DropBag(item1); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[packet.SlotObject2.SlotId] != null) { (en2 as Player)?.Client.SendPacket(new InvResultPacket { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } using (Database db = new Database()) { try { Account acc = db.GetAccount(client.Account.AccountId, Manager.GameData); acc.Gifts.Remove(con1.Inventory[packet.SlotObject1.SlotId].serialId); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = @"UPDATE accounts SET gifts=@gifts WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString(acc.Gifts.ToArray())); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex); } } con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = item1; (en2 as Player).CalcBoost(); client.Save(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); return; } con1.Inventory[packet.SlotObject1.SlotId] = item2; if (item1 != null && item1.serialId == -1 && item1.firstUser == -1) //When players pick up items from mob drops { Item newItem = Manager.CreateSerial((en2 as Player).SerialConvert(item1), DroppedIn: item1.droppedIn); newItem.firstUser = Convert.ToInt32((en2 as Player).AccountId); con2.Inventory[packet.SlotObject2.SlotId] = newItem; } else { con2.Inventory[packet.SlotObject2.SlotId] = item1; } if (item2 != null) { if (publicbags.Contains(en1.ObjectType) && item2.Soulbound) { client.Player.DropBag(item2); con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains(en2.ObjectType) && item1.Soulbound) { client.Player.DropBag(item1); con2.Inventory[packet.SlotObject2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Save(); } (en1 as Player).CalcBoost(); (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Save(); } (en2 as Player).CalcBoost(); (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (client.Player.Owner is Vault) { if ((client.Player.Owner as Vault).PlayerOwnerName == client.Account.Name) { return; } } client.Save(); }, PendingPriority.Networking); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (state != null && cooldown.CoolDown == 0) { return; //cooldown = 0 -> once per state entry } int c; if (state == null) { c = cooldown.Next(Random); } else { c = (int)state; } c -= time.thisTickTimes; state = c; if (c > 0) { return; } c = cooldown.Next(Random); state = c; if (Random.NextDouble() >= probability) { return; } var taunt = text.Length == 1 ? text[0] : text[Random.Next(text.Length)]; if (taunt.Contains("{PLAYER}")) { Entity player = host.GetNearestEntity(10, null); if (player == null) { return; } taunt = taunt.Replace("{PLAYER}", player.Name); } taunt = taunt.Replace("{HP}", (host as Enemy).HP.ToString()); var packet = new TextPacket() { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, Stars = -1, BubbleTime = 5, Recipient = "", Text = taunt, CleanText = "" }; if (broadcast) { host.Owner.BroadcastPacket(packet, null); } else { foreach (var i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15)) { if (host.Dist(i) < 15) { (i as Player).Client.SendPacket(packet); } } } }
// duty loop protected override void TickCore( Entity npc, RealmTime time, ref object state ) { if (_NPC == null) { return; } var entities = npc.GetNearestEntities(_range * 2, null).ToList(); Parallel.ForEach(entities, entity => { Player player; if (entity is Player) { player = entity as Player; } else { return; } if (_NPC.ReturnPlayersCache().Contains(player.Name) && !entities.Contains(player)) { _NPC.RemovePlayer(player); // Removing player into NPC's players cache. ChatManager.ChatDataCache.Remove(player.Name); // Removing player from chat data cache. return; } try { if (npc.Dist(player) > _range && _NPC.ReturnPlayersCache().Contains(player.Name)) { _NPC.RemovePlayer(player); // Removing player into NPC's players cache. _NPC.Leave(player, false); // Player sent a valid leave message (polite: false), processing NPC reply. ChatManager.ChatDataCache.Remove(player.Name); // Removing player from chat data cache. return; } if (ChatManager.ChatDataCache.ContainsKey(player.Name)) { //Chat data cache contains player var messageInfo = ChatManager.ChatDataCache[player.Name]; if (_NPC.ReturnPlayersCache().Contains(player.Name)) { // NPC's players cache contains player. if (npc.Dist(player) <= _range) { if (_playerWelcomeMessages.Contains(messageInfo.Item2.ToLower())) { _NPC.NoRepeat(player); // Duplicated NPC Welcome message! Sending non-repeat message to player ChatManager.ChatDataCache.Remove(player.Name); // Removing player from chat data cache. return; } if (_playerLeaveMessages.Contains(messageInfo.Item2.ToLower()) && messageInfo.Item1 >= _now.AddMilliseconds(-_delay) && messageInfo.Item1 <= _now.AddMilliseconds(_delay)) { _NPC.RemovePlayer(player); // Removing player into NPC's players cache. _NPC.Leave(player, true); // Player sent a valid leave message (polite: true), processing NPC reply. ChatManager.ChatDataCache.Remove(player.Name); // Removing player from chat data cache. return; } } } else { if (_playerWelcomeMessages.Contains(messageInfo.Item2.ToLower()) && npc.Dist(player) <= _range && messageInfo.Item1 >= _now.AddMilliseconds(-_delay) && messageInfo.Item1 <= _now.AddMilliseconds(_delay)) { _NPC.AddPlayer(player); // Adding player into NPC's players cache. _NPC.Welcome(player); // Processing Welcome message to player target. ChatManager.ChatDataCache.Remove(player.Name); // Removing player from chat data cache. } } } } catch (InvalidOperationException) { } // collection can be updated, so new handler exception for it }); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { SwirlState s = (SwirlState)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) { return; } int period = (int)(1000 * radius / host.GetSpeed(speed) * (2 * Math.PI)); if (!s.Acquired && s.RemainingTime <= 0 && targeted) { Entity entity = host.GetNearestEntity(acquireRange, null); if (entity != null && entity.X != host.X && entity.Y != host.Y) { //find circle which pass through host and player pos double l = entity.Dist(host); float hx = (host.X + entity.X) / 2; float hy = (host.Y + entity.Y) / 2; double c = Math.Sqrt(Math.Abs(radius * radius - l * l) / 4); s.Center = new Vector2( (float)(hx + c * (host.Y - entity.Y) / l), (float)(hy + c * (entity.X - host.X) / l)); s.RemainingTime = period; s.Acquired = true; } else { s.Acquired = false; } } else if (s.RemainingTime <= 0 || (s.RemainingTime - period > 200 && host.GetNearestEntity(2, null) != null)) { if (targeted) { s.Acquired = false; Entity entity = host.GetNearestEntity(acquireRange, null); if (entity != null) { s.RemainingTime = 0; } else { s.RemainingTime = 5000; } } else { s.RemainingTime = 5000; } } else { s.RemainingTime -= time.thisTickTimes; } double angle; if (host.Y == s.Center.Y && host.X == s.Center.X) //small offset { angle = Math.Atan2(host.Y - s.Center.Y + (Random.NextDouble() * 2 - 1), host.X - s.Center.X + (Random.NextDouble() * 2 - 1)); } else { angle = Math.Atan2(host.Y - s.Center.Y, host.X - s.Center.X); } double spd = host.GetSpeed(speed) * (s.Acquired ? 1 : 0.2); double angularSpd = spd / radius; angle += angularSpd * (time.thisTickTimes / 1000f); double x = s.Center.X + Math.Cos(angle) * radius; double y = s.Center.Y + Math.Sin(angle) * radius; Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(host.X, host.Y); vect.Normalize(); vect *= (float)spd * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y); host.UpdateCount++; Status = CycleStatus.InProgress; state = s; }
protected override void HandleMessage(Client client, INVSWAP message) { if (client.Player.Owner == null) { return; } Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(message.SlotObject1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(message.SlotObject2.ObjectId); IContainer con1 = en1 as IContainer; IContainer con2 = en2 as IContainer; if (message.SlotObject1.SlotId == 254 || message.SlotObject1.SlotId == 255 || message.SlotObject2.SlotId == 254 || message.SlotObject2.SlotId == 255) { if (message.SlotObject2.SlotId == 254) { if (client.Player.HealthPotions < 6) { client.Player.HealthPotions++; con1.Inventory[message.SlotObject1.SlotId] = null; } } if (message.SlotObject2.SlotId == 255) { if (client.Player.MagicPotions < 6) { client.Player.MagicPotions++; con1.Inventory[message.SlotObject1.SlotId] = null; } } if (message.SlotObject1.SlotId == 254) { if (client.Player.HealthPotions > 0) { client.Player.HealthPotions--; con2.Inventory[message.SlotObject2.SlotId] = null; } } if (message.SlotObject1.SlotId == 255) { if (client.Player.MagicPotions > 0) { client.Player.MagicPotions--; con2.Inventory[message.SlotObject1.SlotId] = null; } } if (en1 is Player) { (en1 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } else if (en2 is Player) { (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } return; } //TODO: locker Item item1 = con1.Inventory[message.SlotObject1.SlotId]; Item item2 = con2.Inventory[message.SlotObject2.SlotId]; List <ushort> publicbags = new List <ushort> { 0x0500, 0x0506, 0x0501 }; if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendMessage(new INVRESULT { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendMessage(new INVRESULT { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } //todo //if (!IsValid(item1, item2, con1, con2, packet, client)) //{ // client.Disconnect(); // return; //} if (item1 != null && item2 != null && item1.Quantity > 0 && item2.Quantity > 0 && en1 is Player && en2 is Player && en1 == en2 && message.SlotObject1.SlotId != message.SlotObject2.SlotId) { int quantity = item1.Quantity; for (int i = 1; i <= quantity; i++) { string name2 = Regex.Replace(item2.ObjectId, "\\d+", "") + (item2.Quantity + 1); if (Manager.GameData.IdToObjectType.TryGetValue(name2, out ushort objType)) { string name1 = Regex.Replace(item1.ObjectId, "\\d+", "") + (item1.Quantity - 1); item2 = client.Manager.GameData.Items[Manager.GameData.IdToObjectType[name2]]; item1 = Manager.GameData.IdToObjectType.TryGetValue(name1, out objType) == true ? client.Manager.GameData.Items[Manager.GameData.IdToObjectType[name1]] : null; con1.Inventory[message.SlotObject1.SlotId] = item1; con2.Inventory[message.SlotObject2.SlotId] = item2; (en1 as Player).CalculateBoost(); client.Player.SaveToCharacter(); client.Save(); en1.UpdateCount++; } else { break; } } return; } if (con2 is OneWayContainer) { con1.Inventory[message.SlotObject1.SlotId] = null; con2.Inventory[message.SlotObject2.SlotId] = null; client.Player.DropBag(item1); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[message.SlotObject2.SlotId] != null) { (en2 as Player)?.Client.SendMessage(new INVRESULT { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } List <int> giftsList = client.Account.Gifts.ToList(); giftsList.Remove(con1.Inventory[message.SlotObject1.SlotId].ObjectType); int[] result = giftsList.ToArray(); client.Account.Gifts = result; client.Account.Flush(); con1.Inventory[message.SlotObject1.SlotId] = null; con2.Inventory[message.SlotObject2.SlotId] = item1; (en2 as Player).CalculateBoost(); client.Player.SaveToCharacter(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); return; } if (en1 is Player && en2 is Player & en1.Id != en2.Id) { Manager.Chat.Announce($"{en1.Name} just tried to steal items from {en2.Name}'s inventory!"); return; } ; con1.Inventory[message.SlotObject1.SlotId] = item2; con2.Inventory[message.SlotObject2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains(en1.ObjectType) && item2.Soulbound) { client.Player.DropBag(item2); con1.Inventory[message.SlotObject1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains(en2.ObjectType) && item1.Soulbound) { client.Player.DropBag(item1); con2.Inventory[message.SlotObject2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Player.SaveToCharacter(); } (en1 as Player).CalculateBoost(); (en1 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Player.SaveToCharacter(); } (en2 as Player).CalculateBoost(); (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } if (client.Player.Owner is Vault) { if ((client.Player.Owner as Vault).PlayerOwnerName == client.Account.Name) { return; } } client.Player.SaveToCharacter(); }, PendingPriority.Networking); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (state != null && cooldown.CoolDown == 0) { return; //cooldown = 0 -> once per state entry } int c; if (state == null) { c = cooldown.Next(Random); } else { c = (int)state; } c -= time.ElaspedMsDelta; state = c; if (c > 0) { return; } c = cooldown.Next(Random); state = c; if (Random.NextDouble() >= probability) { return; } string taunt; if (ordered != null) { taunt = text[ordered.Value]; ordered = (ordered.Value + 1) % text.Length; } else { taunt = text[Random.Next(text.Length)]; } if (taunt.Contains("{PLAYER}")) { Entity player = host.GetNearestEntity(10, null); if (player == null) { return; } taunt = taunt.Replace("{PLAYER}", player.Name); } taunt = taunt.Replace("{HP}", (host as Enemy).HP.ToString()); var packet = new Text() { Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId), ObjectId = host.Id, NumStars = -1, BubbleTime = 3, Recipient = "", Txt = taunt }; if (broadcast) { host.Owner.BroadcastPacket(packet, null); } else { foreach (var i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15).Where(e => e is Player)) { if (i is Player && host.Dist(i) < 15) { (i as Player).Client.SendPacket(packet); } } } }
static double Predict(Entity host, Entity target, ProjectileDesc desc) { Position? history = target.TryGetHistory(100); if (history == null) return 0; var originalAngle = Math.Atan2(history.Value.Y - host.Y, history.Value.X - host.X); var newAngle = Math.Atan2(target.Y - host.Y, target.X - host.X); var bulletSpeed = desc.Speed / 100f; var dist = target.Dist(host); var angularVelo = (newAngle - originalAngle) / (100 / 1000f); return angularVelo * bulletSpeed; }
protected override void HandlePacket(Client client, InvSwapPacket packet) { if (client.Player.Owner == null) { return; } client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.SlotObject1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.SlotObject2.ObjectId); IContainer con1 = en1 as IContainer; IContainer con2 = en2 as IContainer; //TODO: locker Item item1 = con1.Inventory[packet.SlotObject1.SlotId]; Item item2 = con2.Inventory[packet.SlotObject2.SlotId]; Console.WriteLine(en1 + "1"); Console.WriteLine(en2 + "2"); Console.WriteLine(con1 + "3"); Console.WriteLine(con2 + "4"); Console.WriteLine(item1 + "5"); Console.WriteLine(item2 + "6"); List <ushort> publicbags = new List <ushort> { 0x0500, 0x0506, 0x0501 }; if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } if (!IsValid(item1, item2, con1, con2, packet, client)) { client.Disconnect(); return; } if (con2 is OneWayContainer) { con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = null; client.Player.DropBag(item1); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[packet.SlotObject2.SlotId] != null) { (en2 as Player)?.Client.SendPacket(new InvResultPacket { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = item1; (en2 as Player).CalcBoost(); client.Player.SaveToCharacter(); client.Save(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); return; } if (en1 is Player && en2 is Player & en1.Id != en2.Id) { client.Manager.Chat.Announce($"{en1.Name} just tried to steal items from {en2.Name}'s inventory, GTFO YOU GOD DAMN FEGIT!!!!11111oneoneoneeleven"); return; } ; con1.Inventory[packet.SlotObject1.SlotId] = item2; con2.Inventory[packet.SlotObject2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains(en1.ObjectType) && item2.Soulbound) { client.Player.DropBag(item2); con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains(en2.ObjectType) && item1.Soulbound) { client.Player.DropBag(item1); con2.Inventory[packet.SlotObject2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Save(); } (en1 as Player).CalcBoost(); (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Save(); } (en2 as Player).CalcBoost(); (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } // if (client.Player.Owner is Vault) // if ((client.Player.Owner as Vault).PlayerOwnerName == client.Account.Name) // return; client.Player.SaveToCharacter(); client.Save(); }, PendingPriority.Networking); }
protected override void HandlePacket(Client client, InvSwapPacket packet) { if (client.Player.Owner == null) { return; } client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.Obj1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.Obj2.ObjectId); var con1 = en1 as IContainer; var con2 = en2 as IContainer; Item item1 = con1.Inventory[packet.Obj1.SlotId]; Item item2 = con2.Inventory[packet.Obj2.SlotId]; ItemData data1 = con1.Inventory.Data[packet.Obj1.SlotId]; ItemData data2 = con2.Inventory.Data[packet.Obj2.SlotId]; if (item1 != null) { if (item1.AdminOnly) { if (!client.Account.Admin) { return; } } } if (item2 != null) { if (item2.AdminOnly) { if (!client.Account.Admin) { return; } } } if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendPacket(new InvResultPacket { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } if (!IsValid(item1, item2, con1, con2, packet, client)) { client.Disconnect(); return; } var publicbags = new List <short> { 0x0500, 0x0506, 0x0501 }; con1.Inventory.Data[packet.Obj1.SlotId] = data2; con2.Inventory.Data[packet.Obj2.SlotId] = data1; con1.Inventory[packet.Obj1.SlotId] = item2; con2.Inventory[packet.Obj2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains((short)en1.ObjectType) && (item2.Soulbound || (data2 != null && data2.Soulbound))) { dropBag(client, item2, data2); con1.Inventory.Data[packet.Obj1.SlotId] = null; con1.Inventory[packet.Obj1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains((short)en2.ObjectType) && (item1.Soulbound || (data1 != null && data1.Soulbound))) { dropBag(client, item1, data1); con2.Inventory.Data[packet.Obj2.SlotId] = null; con2.Inventory[packet.Obj2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Save(); } (en1 as Player).CalculateBoost(); (en1 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Save(); } (en2 as Player).CalculateBoost(); (en2 as Player).Client.SendPacket(new InvResultPacket { Result = 0 }); } if (!(en2 is Player)) { var con = en2 as Container; } }); }
static void Main(string[] args) { int busPerPlayer = int.Parse(Console.ReadLine()); // the amount of bus you control int ghostCount = int.Parse(Console.ReadLine()); // the amount of ghosts on the map int myTeamId = int.Parse(Console.ReadLine()); // if this is 0, your base is on the top left of the map, if it is one, on the bottom right int baseX = (myTeamId == 0)?0:16000; int baseY = (myTeamId == 0)?0:9000; Entity Base = new Entity(baseX, baseY); Entity[] bus = new Entity[busPerPlayer]; // game loop while (true) { int entities = int.Parse(Console.ReadLine()); // the number of bus and ghosts visible to you Entity[] e = new Entity[entities]; int k = 0; List <Entity> Ghosts = new List <Entity>(); List <Entity> Enemy = new List <Entity>(); for (int i = 0; i < entities; i++) { e[i] = new Entity(); string input = Console.ReadLine(); Console.Error.WriteLine(input); string[] inputs = input.Split(' '); e[i].Id = int.Parse(inputs[0]); // buster id or ghost id e[i].x = int.Parse(inputs[1]); e[i].y = int.Parse(inputs[2]); // position of this buster / ghost e[i].entityType = int.Parse(inputs[3]); // the team id if it is a buster, -1 if it is a ghost. e[i].state = int.Parse(inputs[4]); // For bus: 0=idle, 1=carrying a ghost. e[i].value = int.Parse(inputs[5]); // For bus: Ghost id being carried. For ghosts: number of bus attempting to trap this ghost. if (myTeamId == e[i].entityType) { if (bus[i] == null) { bus[k++] = e[i]; } else { bus[i].x = e[i].x; bus[i].y = e[i].y; bus[i].state = e[i].state; bus[i].value = e[i].value; } } else if (e[i].entityType == -1) { Ghosts.Add(e[i]); } else { if (e[i].state == 1) { Enemy.Add(e[i]); } Console.Error.WriteLine("e[i].Id:{0} e[i].state:{1}", e[i].Id, e[i].state); } } for (int bn = 0; bn < busPerPlayer; bn++) { // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); int minD = 100000, D; if (bus[bn].state == 0 && Ghosts.Count > 0) { Entity minG = Ghosts[0]; Console.Error.WriteLine("Ghosts.Count:{0}", Ghosts.Count); foreach (Entity g in Ghosts) { if ((D = g.Dist(bus[bn])) < minD) { minD = D; minG = g; Console.Error.WriteLine("minD:{0} minG.Id:{1}", minD, minG.Id); } } if (minG.Dist(bus[bn]) < 1760) { Console.WriteLine("BUST {0}", minG.Id); } else { Console.WriteLine("MOVE {0} {1}", minG.x, minG.y); // MOVE x y | BUST id | RELEASE } } else if (bus[bn].state == 1) { if (Base.Dist(bus[bn]) < 1600) { Console.WriteLine("RELEASE"); } else { Console.WriteLine("MOVE {0} {1}", baseX, baseY); } } else { if (Math.Abs(bus[bn].x1 - bus[bn].x) < 5 & Math.Abs(bus[bn].y1 - bus[bn].y) < 4) { Random rnd = new Random(); double degree = rnd.Next(1200 * bn, 16000 - 1200 * (busPerPlayer - bn)) % 360; double angle = Math.PI * degree / 180.0; Console.Error.WriteLine("degree:{0} angle:{1:3} x:{2}:{3} y:{4}:{5}", degree, angle, bus[bn].x, bus[bn].x1, bus[bn].y, bus[bn].y1); bus[bn].x1 = (int)((Math.Sin(angle) > 0)?15000:1000); bus[bn].y1 = (int)((Math.Cos(angle) > 0)?8000:1000); Console.Error.WriteLine("bn:{0} x1:{1} y1:{2}", bn, bus[bn].x1, bus[bn].y1); } if (Enemy.Count > 0) { minD = 100000; Entity minE = Enemy[0]; foreach (Entity en in Enemy) { if ((D = en.Dist(bus[bn])) < minD) { minD = D; minE = en; Console.Error.WriteLine("minD:{0} minE.Id:{1}", minD, minE.Id); } } if (minE.Dist(bus[bn]) < 1760) { Console.WriteLine("STUN {0}", minE.Id); } else { Console.WriteLine("MOVE {0} {1}", bus[bn].x1, bus[bn].y1); } } else { Console.WriteLine("MOVE {0} {1}", bus[bn].x1, bus[bn].y1); } } } } }
protected override void HandlePacket(Client client, INVSWAP packet) { if (client.Player.Owner == null) { return; } client.Manager.Logic.AddPendingAction(t => { Entity en1 = client.Player.Owner.GetEntity(packet.SlotObject1.ObjectId); Entity en2 = client.Player.Owner.GetEntity(packet.SlotObject2.ObjectId); IContainer con1 = en1 as IContainer; IContainer con2 = en2 as IContainer; if (packet.SlotObject1.SlotId == 254 || packet.SlotObject1.SlotId == 255 || packet.SlotObject2.SlotId == 254 || packet.SlotObject2.SlotId == 255) { if (packet.SlotObject2.SlotId == 254) { if (client.Player.HealthPotions < 6) { client.Player.HealthPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject2.SlotId == 255) { if (client.Player.MagicPotions < 6) { client.Player.MagicPotions++; con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (packet.SlotObject1.SlotId == 254) { if (client.Player.HealthPotions > 0) { client.Player.HealthPotions--; con2.Inventory[packet.SlotObject2.SlotId] = null; } } if (packet.SlotObject1.SlotId == 255) { if (client.Player.MagicPotions > 0) { client.Player.MagicPotions--; con2.Inventory[packet.SlotObject1.SlotId] = null; } } if (en1 is Player) { (en1 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } else if (en2 is Player) { (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } return; } //TODO: locker Item item1 = con1.Inventory[packet.SlotObject1.SlotId]; Item item2 = con2.Inventory[packet.SlotObject2.SlotId]; List <ushort> publicbags = new List <ushort> { 0x0500, 0x0506, 0x0501 }; if (en1.Dist(en2) > 1) { if (en1 is Player) { (en1 as Player).Client.SendMessage(new INVRESULT { Result = -1 }); } else if (en2 is Player) { (en2 as Player).Client.SendMessage(new INVRESULT { Result = -1 }); } en1.UpdateCount++; en2.UpdateCount++; return; } //todo //if (!IsValid(item1, item2, con1, con2, packet, client)) //{ // client.Disconnect(); // return; //} if (con2 is OneWayContainer) { con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = null; client.Player.DropBag(item1); en1.UpdateCount++; en2.UpdateCount++; return; } if (con1 is OneWayContainer) { if (con2.Inventory[packet.SlotObject2.SlotId] != null) { (en2 as Player)?.Client.SendMessage(new INVRESULT { Result = -1 }); (con1 as OneWayContainer).UpdateCount++; en2.UpdateCount++; return; } List <int> giftsList = client.Account.Gifts.ToList(); giftsList.Remove(con1.Inventory[packet.SlotObject1.SlotId].ObjectType); int[] result = giftsList.ToArray(); client.Account.Gifts = result; client.Account.Flush(); con1.Inventory[packet.SlotObject1.SlotId] = null; con2.Inventory[packet.SlotObject2.SlotId] = item1; (en2 as Player).CalcBoost(); client.Player.SaveToCharacter(); en1.UpdateCount++; en2.UpdateCount++; (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); return; } if (en1 is Player && en2 is Player & en1.Id != en2.Id) { client.Manager.Chat.Announce($"{en1.Name} just tried to steal items from {en2.Name}'s inventory, GTFO YOU GOD DAMN FEGIT!!!!11111oneoneoneeleven"); return; } ; con1.Inventory[packet.SlotObject1.SlotId] = item2; con2.Inventory[packet.SlotObject2.SlotId] = item1; if (item2 != null) { if (publicbags.Contains(en1.ObjectType) && item2.Soulbound) { client.Player.DropBag(item2); con1.Inventory[packet.SlotObject1.SlotId] = null; } } if (item1 != null) { if (publicbags.Contains(en2.ObjectType) && item1.Soulbound) { client.Player.DropBag(item1); con2.Inventory[packet.SlotObject2.SlotId] = null; } } en1.UpdateCount++; en2.UpdateCount++; if (en1 is Player) { if (en1.Owner.Name == "Vault") { (en1 as Player).Client.Player.SaveToCharacter(); } (en1 as Player).CalcBoost(); (en1 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } if (en2 is Player) { if (en2.Owner.Name == "Vault") { (en2 as Player).Client.Player.SaveToCharacter(); } (en2 as Player).CalcBoost(); (en2 as Player).Client.SendMessage(new INVRESULT { Result = 0 }); } if (client.Player.Owner is Vault) { if ((client.Player.Owner as Vault).PlayerOwnerName == client.Account.Name) { return; } } client.Player.SaveToCharacter(); }, PendingPriority.Networking); }