Entity FindQuest(Position?destination = null) { Entity ret = null; double?bestScore = null; var pX = !destination.HasValue ? X : destination.Value.X; var pY = !destination.HasValue ? Y : destination.Value.Y; foreach (var i in Owner.Quests.Values .OrderBy(quest => MathsUtils.DistSqr(quest.X, quest.Y, pX, pY))) { if (i.ObjectDesc == null || !i.ObjectDesc.Quest) { continue; } Tuple <int, int, int> x; if (!QuestDat.TryGetValue(i.ObjectDesc.ObjectId, out x)) { continue; } if ((Level >= x.Item2 && Level <= x.Item3)) { var score = (20 - Math.Abs((i.ObjectDesc.Level ?? 0) - Level)) * x.Item1 - //priority * level diff this.Dist(i) / 100; //minus 1 for every 100 tile distance if (bestScore == null || score > bestScore) { bestScore = score; ret = i; } } } return(ret); }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { // read the particle's angle in degrees float angle = particles.shape.angle; // 0.5 = scale of the cylinder float radius = particles.shape.radius * 0.5f; // read the particles distance travelled, ie the length of the cone times scale of cylinder float range = particles.main.startLifetime.constant * particles.main.startSpeed.constant * 0.5f; // for each target in the scene, check if they're inside our cone // if they are, make their particle system go off foreach (Target target in Target.targets) { if (isCylinder == false) { if (MathsUtils.IsInCone(target.transform.position, transform.position, transform.up, angle, range)) { target.Hit(); } } else { if (MathsUtils.IsInCylinder(target.transform.position, transform.position, transform.up, radius, range)) { target.Hit(); } } } } }
public static void Aoe(this World world, Position pos, float radius, bool players, Action <Entity> callback) //Null for player { if (players) { foreach (Entity i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius)) { if (i is Pet) { continue; } double d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y); if (d < radius) { callback(i); } } } else { foreach (Entity i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius)) { if (!(i is Enemy)) { continue; } double d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y); if (d < radius) { callback(i); } } } }
private Entity FindQuest() { Entity ret = null; double bestScore = 0; foreach (Enemy i in Owner.Quests.Values .OrderBy(quest => MathsUtils.DistSqr(quest.X, quest.Y, X, Y))) { if (i.ObjectDesc == null || !i.ObjectDesc.Quest) { continue; } Tuple <int, int, int> x; if (!QuestDat.TryGetValue(i.ObjectDesc.ObjectId, out x)) { continue; } if ((Level >= x.Item2 && Level <= x.Item3)) { double score = (120 - Math.Abs((i.ObjectDesc.Level ?? 0) - Level)) * x.Item1 - //priority * level diff this.Dist(i) / 100; //minus 1 for every 100 tile distance if (score > bestScore) { bestScore = score; ret = i; } } } return(ret); }
static Sight() { InitUnblockedView(); InitSightRays(); Primes = MathsUtils.GeneratePrimes(MaxNumRegions); }
private bool MoveIfNeeded() { var chunk = chunks[index]; var offset = target.position.x - chunk.position.x; if (offset > offsetTrigger) { // Target is ahead move back chunk forward. var backChunk = chunks[MathsUtils.Mod(index - indexFromCenterToBack, chunks.Length)]; backChunk.Translate(backToFrontDistance, 0, 0); if (OnChunkMoved != null) { OnChunkMoved(backChunk); } index = (index + 1) % chunks.Length; return(true); } else if (offset < -offsetTrigger) { // Target is behind move front chunk backward. var frontChunk = chunks[(index + indexFromCenterToFront) % chunks.Length]; frontChunk.Translate(-backToFrontDistance, 0, 0); if (OnChunkMoved != null) { OnChunkMoved(frontChunk); } index = MathsUtils.Mod(index - 1, chunks.Length); return(true); } return(false); }
/** * Update the position of the reticle */ private void UpdateReticle(Rigidbody target, GameObject reticle) { Vector3 targetVelocity = target.velocity; Vector3 relativePosition = target.transform.position - transform.position; float boltVelocity = (BoltForce / boltMass); float t = MathsUtils.CalculateInterceptTime(boltVelocity, relativePosition, targetVelocity); if (t <= 0) { reticle.transform.position = transform.position; reticle.transform.LookAt(actor.transform, actor.transform.up); //reticle.SetActive(false); } else { float reticleX = target.transform.position.x + (targetVelocity.x * t); float reticleY = target.transform.position.y + (targetVelocity.y * t); float reticleZ = target.transform.position.z + (targetVelocity.z * t); reticle.transform.position = new Vector3(reticleX, reticleY, reticleZ); reticle.transform.LookAt(actor.transform, actor.transform.up); //reticle.SetActive(true); } }
private IEnumerable <int> GetRemovedEntities() { foreach (Entity i in clientEntities.Where(i => i is Player)) { if ((i as Player).isNotVisible && i != this && !PvP) { yield return(i.Id); } } foreach (Entity i in clientEntities) { if (i is Player && i.Owner != null) { continue; } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > RADIUS * RADIUS && !(i is StaticObject && (i as StaticObject).Static) && i != questEntity) { yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (i is Player) { if ((i as Player).isNotVisible && i != this && !PvP) { yield return(i.Id); } } } }
/// <summary> /// Extend a line the specified distance in either/both directions /// <para>This method is immutable</para> /// </summary> /// <param name="bottomLeftExtension">The amount to extend the logical bottom left length of the line</param> /// <param name="topRightExtension">The amount to extend the logical top right length of the line</param> /// <returns>A new line with the extensions added as required</returns> public Line2D <T> Extend(T bottomLeftExtension, T topRightExtension) { Point2D <T> p1 = Ends[0]; Point2D <T> p2 = Ends[1]; T adj = (dynamic)p2.X - p1.X; T opp = (dynamic)p2.Y - p1.Y; double divisor = (double)(dynamic)opp / (double)(dynamic)adj; double atan = Math.Atan(divisor); double angle = MathsUtils.ToDegrees(atan); if ((dynamic)opp == 0) { if ((dynamic)p1.X > p2.X) { angle = 180; } } if ((dynamic)adj == 0) { if ((dynamic)p1.Y > p2.Y) { angle = 270; } } if ((dynamic)topRightExtension != 0) { p2 = p2.LocatePointAtDistance(angle, topRightExtension); } if ((dynamic)bottomLeftExtension != 0) { p1 = p1.LocatePointAtDistance(angle + 180, bottomLeftExtension); } return(new Line2D <T>(p1, p2)); }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { int index = 0; // display the order of each object, from 1 to N, clockwise foreach (Target target in Target.targets) { index++; target.SetText(index.ToString()); } } else { // display the actual angles above each target foreach (Target target in Target.targets) { target.SetText(MathsUtils.AngleTo(transform, target.transform.position).ToString("0.0")); } } // sort the targets in order ofn their angle to the player Target.targets.Sort(delegate(Target a, Target b) { return(MathsUtils.AngleTo(transform, a.transform.position).CompareTo(MathsUtils.AngleTo(transform, b.transform.position))); }); }
protected override void TickCore(Entity host, RealmTime time, ref object state) { if (MathsUtils.GenerateProb(50)) { host.Owner.LeaveWorld(host); } }
/// <summary> /// The snake make sharp turns left and right and shoots whenever it can. /// </summary> public override Action NextAction() { // Make sure to move in a stright line. var rotation = spaceship.Rotation; // Rotation is in specific degrees so we won't allways be exactly 90 // degrees. var modAngle = MathsUtils.Mod(rotation, 90f); if (modAngle > 45f) { modAngle = 90f - modAngle; } if (modAngle >= Spaceship.ROTATION_PER_ACTION * 0.7f) { return(turnDirection); } // Checks if we should rotate. if (Random.value < rotationChance) { // Initialize Rotation. ChooseDirection(); return(turnDirection); } return(spaceship.CanShoot ? Shoot.action : DoNothing.action); }
private IEnumerable <int> GetRemovedEntities() { foreach (var i in _clientEntities.Where(i => i is Player)) { if ((i as Player).vanished && i != this) { yield return(i.Id); } } foreach (var i in _clientEntities.Where(i => !(i is Player) || i.Owner == null)) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > SightRadius * SightRadius && !(i is StaticObject && (i as StaticObject).Static) && i != questEntity) { yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (i is Player) { if ((i as Player).vanished && i != this) { yield return(i.Id); } } } }
public virtual void LeaveWorld(Entity entity) { if (entity is Player) { Player dummy; Players.TryRemove(entity.Id, out dummy); PlayersCollision.Remove(entity); // if in trade, cancel it... if (dummy.tradeTarget != null) { dummy.CancelTrade(); } } else if (entity is Enemy) { Enemy dummy; Enemies.TryRemove(entity.Id, out dummy); EnemiesCollision.Remove(entity); if (entity.ObjectDesc.Quest) { Quests.TryRemove(entity.Id, out dummy); } } else if (entity is Projectile) { var p = entity as Projectile; Projectiles.TryRemove(new Tuple <int, byte>(p.ProjectileOwner.Self.Id, p.ProjectileId), out p); } else if (entity is StaticObject) { StaticObject dummy; StaticObjects.TryRemove(entity.Id, out dummy); if (entity.ObjectDesc?.BlocksSight == true) { if (Blocking == 3) { Sight.UpdateRegion(Map, (int)entity.X, (int)entity.Y); } foreach (var plr in Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, entity.X, entity.Y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } if (entity is Decoy) { PlayersCollision.Remove(entity); } else { EnemiesCollision.Remove(entity); } } entity.Dispose(); }
public void randomise() { randomiseSeeds(); randomiseNoise(surfaceNoise); randomiseNoise(landNoise); landColour0 = MathsUtils.randomColour(); landColour1 = MathsUtils.randomColour(); landColour2 = MathsUtils.randomColour(); landColour3 = MathsUtils.randomColour(); randomiseNoise(landColourNoise01); randomiseNoise(landColourNoise23); waterColour0 = MathsUtils.randomColour(); waterColour1 = MathsUtils.randomColour(); waterLevel = Random.Range(0f, 1f); waterSpecular = Random.Range(0f, 1f); waterFalloff = Random.Range(0.1f, 20); iceColour = MathsUtils.randomColour(); iceReach = Random.Range(0f, 1f); iceHeight = Random.Range(0f, 1f); shadowRange = Random.Range(0f, 100f); shadowStrength = Random.Range(0f, 1f); cityReach = Random.Range(0f, 1f); cityHeight = Random.Range(0f, 1f); cityColour = MathsUtils.randomColour(); cityCount = Random.Range(0, 32); cityMultiplier = Random.Range(1, 6); cityDropoff = Random.Range(1, 10); cityDepth = Random.Range(1, 5); citySpread = Random.Range(0.25f, 4f); cityIntensity = Random.Range(8f, 128f); maxCityIntensity = Random.Range(4f, 64f); cityFalloff = Random.Range(0.25f, 2f); randomiseNoise(cloudNoise); cloudWorleyNoiseOctaves = Random.Range(0, 10); cloudWorleyNoiseFrequency = Random.Range(1f, 100f); cloudWorleyNoiseAmplitude = Random.Range(1f, 10f); cloudShadowRange = Random.Range(0f, 100f); cloudShadowStrength = Random.Range(0f, 1f); cloudColour0 = MathsUtils.randomColour(); cloudColour1 = MathsUtils.randomColour(); cloudSpin = Random.Range(1f, 10f); }
private IEnumerable <int> GetRemovedEntities() { foreach (var i in clientEntities.Where(i => !(i is Player) || i.Owner == null)) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > SIGHTRADIUS * SIGHTRADIUS && !(i is StaticObject && (i as StaticObject).Static) && i != Quest) { if (i is Pet) { continue; } yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (!(i is Player)) { continue; } if (i != this) { yield return(i.Id); } } }
public void BroadcastPacketNearby( Packet pkt, Position pos) { BroadcastPacketConditional( pkt, p => MathsUtils.DistSqr(p.X, p.Y, pos.X, pos.Y) < Player.RadiusSqr); }
public uint Encode(object data, CEContext ctx, uint id) { var key = (Tuple <uint, uint>)data; uint ret = (id ^ key.Item2) * key.Item1; Debug.Assert(((ret * MathsUtils.modInv(key.Item1)) ^ key.Item2) == id); return(ret); }
void EncodeField(object sender, ModuleWriterListenerEventArgs e) { var writer = (ModuleWriterBase)sender; if (e.WriterEvent == ModuleWriterEvent.MDMemberDefRidsAllocated && keyAttrs != null) { var keyFuncs = keyAttrs .Where(entry => entry != null) .ToDictionary(entry => entry.Item1, entry => entry.Item2); foreach (var desc in fieldDescs) { var token = writer.MetaData.GetToken(desc.Method).Raw; var key = encodeCtx.Random.NextUInt32() | 1; // CA var ca = desc.Field.CustomAttributes[0]; var encodedKey = keyFuncs[(TypeDef)ca.AttributeType]((int)MathsUtils.modInv(key)); ca.ConstructorArguments.Add(new CAArgument(encodeCtx.Module.CorLibTypes.Int32, encodedKey)); token *= key; // Encoding token = (uint)desc.InitDesc.Encoding.Encode(desc.InitDesc.Method, encodeCtx, (int)token); // Field name var name = new char[5]; name[desc.InitDesc.OpCodeIndex] = (char)((byte)desc.OpCode ^ desc.OpKey); var nameKey = encodeCtx.Random.NextBytes(4); uint encodedNameKey = 0; for (var i = 0; i < 4; i++) { // No zero bytes while (nameKey[i] == 0) { nameKey[i] = encodeCtx.Random.NextByte(); } name[desc.InitDesc.TokenNameOrder[i]] = (char)nameKey[i]; encodedNameKey |= (uint)nameKey[i] << desc.InitDesc.TokenByteOrder[i]; } desc.Field.Name = new string(name); // Field sig var sig = desc.Field.FieldSig; var encodedToken = (token - writer.MetaData.GetToken(((CModOptSig)sig.Type).Modifier).Raw) ^ encodedNameKey; var extra = new byte[8]; extra[0] = 0xc0; extra[3] = (byte)(encodedToken >> desc.InitDesc.TokenByteOrder[3]); extra[4] = 0xc0; extra[5] = (byte)(encodedToken >> desc.InitDesc.TokenByteOrder[2]); extra[6] = (byte)(encodedToken >> desc.InitDesc.TokenByteOrder[1]); extra[7] = (byte)(encodedToken >> desc.InitDesc.TokenByteOrder[0]); sig.ExtraData = extra; } } }
private IEnumerable <Entity> GetNewEntities() { int xBase = (int)X; int yBase = (int)Y; var blockPos = getBlocks(xBase, yBase); foreach (var i in Owner.Players.Where(i => clientEntities.Add(i.Value))) { yield return(i.Value); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Decoy>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Pet>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, SIGHTRADIUS)) { if (i is Container) { var owner = (i as Container).BagOwners?.Length == 1 ? (i as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { continue; } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (i.ObjectType != 0x500 || i.ObjectType != 0x506)) { (i as Container).BoostedBag = true; //boosted bag } } } if ((!(MathsUtils.DistSqr(i.X, i.Y, X, Y) <= SIGHTRADIUS * SIGHTRADIUS))) { continue; } if (Owner.Dungeon && invalidTile(xBase, yBase, (int)i.X, (int)i.Y, blockPos)) { continue; } if (clientEntities.Add(i)) { yield return(i); } } if (Quest != null && clientEntities.Add(Quest)) { yield return(Quest); } }
Tuple <int, int> GetKey(RandomGenerator random, MethodDef init) { if (!keys.TryGetValue(init, out var ret)) { var key = random.NextInt32() | 1; keys[init] = ret = Tuple.Create(key, (int)MathsUtils.modInv((uint)key)); } return(ret); }
private IEnumerable <Entity> GetNewEntities() { var newEntities = new List <Entity>(); try { Owner.Players.Where(i => clientEntities.Add(i.Value)).Select(_ => { newEntities.Add(_.Value); return(_); }).ToList(); } catch { } try { Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Decoy>().Where(i => clientEntities.Add(i)).Select(_ => { newEntities.Add(_); return(_); }).ToList(); } catch { } try { Owner.EnemiesCollision.HitTest(X, Y, SIGHTRADIUS).Where(_ => MathsUtils.DistSqr(_.X, _.Y, X, Y) <= SIGHTRADIUS * SIGHTRADIUS).Select(_ => { if (_ is Container) { var owner = (_ as Container).BagOwners?.Length == 1 ? (_ as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { return(_); } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (_.ObjectType != 0x500 || _.ObjectType != 0x506)) { (_ as Container).BoostedBag = true; } } } if (visibleTiles.ContainsKey(new IntPoint((int)_.X, (int)_.Y))) { if (clientEntities.Add(_)) { newEntities.Add(_); } } return(_); }).ToList(); } catch { } try { if (Quest != null && clientEntities.Add(Quest) && (Quest as Enemy).HP >= 0) { newEntities.Add(Quest); } } catch { } return(newEntities); }
void EmitCore(CipherGenContext context) { Expression a = context.GetDataExpression(DataIndexes[0]); Expression b = context.GetDataExpression(DataIndexes[1]); VariableExpression tmp; if (Mask == 0xffffffff) { /* t = a * k; * a = b; * b = t * k^-1; */ using (context.AcquireTempVar(out tmp)) { context.Emit(new AssignmentStatement { Value = a * (LiteralExpression)Key, Target = tmp }).Emit(new AssignmentStatement { Value = b, Target = a }).Emit(new AssignmentStatement { Value = tmp * (LiteralExpression)MathsUtils.modInv(Key), Target = b }); } } else { var mask = (LiteralExpression)Mask; var notMask = (LiteralExpression) ~Mask; /* t = (a & mask) * k; * a = a & (~mask) | (b & mask); * b = b & (~mask) | (t * k^-1); */ using (context.AcquireTempVar(out tmp)) { context.Emit(new AssignmentStatement { Value = (a & mask) * (LiteralExpression)Key, Target = tmp }).Emit(new AssignmentStatement { Value = (a & notMask) | (b & mask), Target = a }).Emit(new AssignmentStatement { Value = (b & notMask) | (tmp * (LiteralExpression)MathsUtils.modInv(Key)), Target = b }); } } }
public void BroadcastPacketNearby( Packet pkt, Position pos, PacketPriority priority = PacketPriority.Normal) { BroadcastPacketConditional( pkt, p => MathsUtils.DistSqr(p.X, p.Y, pos.X, pos.Y) < Player.RadiusSqr, priority); }
void Flash(bool isLeft) { foreach (Target target in Target.targets) { if (MathsUtils.IsOnLeft(transform, target.transform.position) == isLeft) { target.Hit(); } } }
private Dictionary <String, float> GetSpellCooldownsAsPercent() { Dictionary <String, float> dic = new Dictionary <string, float>(); foreach (KeyValuePair <string, Spell> spell in m_getSpellTree().GetSpells()) { dic.Add(spell.Value._id, MathsUtils.PercentValueFromAnotherValue((float)spell.Value.m_turnCooling, (float)spell.Value.cooldown) / 100f); } return(dic); }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { //var objType = GetObjType(_objName); XmlData dat = host.Manager.Resources.GameData; var tileId = dat.IdToTileType[_objName]; var replacedTileId = dat.IdToTileType[_replacedObjName]; var map = host.Owner.Map; var w = map.Width; var h = map.Height; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var tile = map[x, y]; if (tile.TileId != tileId || tile.TileId == replacedTileId) { continue; } var dx = Math.Abs(x - (int)host.X); var dy = Math.Abs(y - (int)host.Y); if (dx > _range || dy > _range) { continue; } if (tile.ObjDesc?.BlocksSight == true) { if (host.Owner.Blocking == 3) { Sight.UpdateRegion(map, x, y); } foreach (var plr in host.Owner.Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, x, y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } tile.TileId = replacedTileId; if (tile.ObjId == 0) { tile.ObjId = host.Owner.GetNextEntityId(); } tile.UpdateCount++; map[x, y] = tile; } } }
public void ResetChunks() { if (OnChunkMoved != null) { for (int i = 0; i < chunks.Length; i++) { var chunk = chunks[MathsUtils.Mod(index - indexFromCenterToBack + i, chunks.Length)]; OnChunkMoved(chunk); } } }
private Tuple <int, int> GetKey(RandomGenerator random, MethodDef init) { Tuple <int, int> tuple; if (!this.keys.TryGetValue(init, out tuple)) { int num = random.NextInt32() | 1; this.keys[init] = tuple = Tuple.Create <int, int>(num, (int)MathsUtils.modInv((uint)num)); } return(tuple); }
IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players) { if (clientEntities.Add(i.Value)) { yield return(i.Value); } } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, RADIUS)) { if (i is Decoy || i is Pet) { if (clientEntities.Add(i)) { yield return(i); } } } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, RADIUS)) { if (i is Container) { var owner = (i as Container).BagOwners?.Length == 1 ? (i as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { continue; } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (i.ObjectType != 0x500 || i.ObjectType != 0x506)) { (i as Container).BoostedBag = true; //boosted bag } } } if (SightTiles.Contains(new IntPoint((int)i.X, (int)i.Y))) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= RADIUS * RADIUS) { if (clientEntities.Add(i)) { yield return(i); } } } } if (Quest != null && clientEntities.Add(Quest)) { yield return(Quest); } }