string GenerateSeed(int seed, byte[] rom_data, string linkSpriteFilename, string inputFilename, string outputPath) { #if !DEBUG try // make sure we don't crash in release build { #endif RomData romData = new RomData(rom_data); Randomization randomize = new Randomization(); RomData randomizedRom = randomize.MakeRandomization("", seed, config.OptionFlags, romData, linkSpriteFilename); string fileNameNoExtension = Path.Combine(outputPath, $"Enemizer {EnemizerLibrary.Version.CurrentVersion} - {Path.GetFileNameWithoutExtension(inputFilename)} (EN{randomizedRom.EnemizerSeed})"); if (config.OptionFlags.GenerateSpoilers) { File.WriteAllText($"{fileNameNoExtension}.txt", randomizedRom.Spoiler.ToString()); } #if DEBUG // build a patch for testing var romPatch = randomizedRom.GeneratePatch(); string patch = JsonConvert.SerializeObject(romPatch); File.WriteAllText($"{fileNameNoExtension}.patch", patch); #endif Randomization.SetSwordGfx(randomizedRom, config.OptionFlags.SwordGraphics); Randomization.SetShieldGfx(randomizedRom, config.OptionFlags.ShieldGraphics); if (config.OptionFlags.RandomizeSpriteOnHit) { Randomization.BuildRandomLinkSpriteTable(randomizedRom, seed, config.OptionFlags); } string fileName = $"{fileNameNoExtension}.sfc"; var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); randomizedRom.WriteRom(fs); fs.Close(); return(fileName); #if !DEBUG } catch (Exception ex) { logger.Error(ex); MessageBox.Show($"{ex.Message}\r\n{ex.StackTrace}", "Enemizer"); } return("Failed"); #endif }
private void SpawnMapNpc(int i) { byte x = 0; byte y = 0; byte dir = 0; var npcBase = NpcBase.Get(Spawns[i].NpcId); if (npcBase != null) { MapNpcSpawn npcSpawnInstance; if (NpcSpawnInstances.ContainsKey(Spawns[i])) { npcSpawnInstance = NpcSpawnInstances[Spawns[i]]; } else { npcSpawnInstance = new MapNpcSpawn(); NpcSpawnInstances.Add(Spawns[i], npcSpawnInstance); } if (Spawns[i].Direction != NpcSpawnDirection.Random) { dir = (byte)(Spawns[i].Direction - 1); } else { dir = (byte)Randomization.Next(0, 4); } if (Spawns[i].X >= 0 && Spawns[i].Y >= 0) { npcSpawnInstance.Entity = SpawnNpc((byte)Spawns[i].X, (byte)Spawns[i].Y, dir, Spawns[i].NpcId); } else { for (var n = 0; n < 100; n++) { x = (byte)Randomization.Next(0, Options.MapWidth); y = (byte)Randomization.Next(0, Options.MapHeight); if (Attributes[x, y] == null || Attributes[x, y].Type == (int)MapAttributes.Walkable) { break; } x = 0; y = 0; } npcSpawnInstance.Entity = SpawnNpc(x, y, dir, Spawns[i].NpcId); } } }
public void Spawn() { nextNum = Randomization.RandomPercentage(); // Debug.Log ("num: " + nextNum); // Debug.Log ("score: " + score); if (score == 0) { sc.AddShape(SelectPrefab.RandomShape(), 1); } if (score == 10) { if (nextNum < 20) { sc.AddShape(SelectPrefab.RandomShape(), 1); } } if (score > 100) { if (nextNum < 30) { sc.AddShape(SelectPrefab.RandomShape(), 1); } } if (score > 250) { if (nextNum < 40) { sc.AddShape(SelectPrefab.RandomShape(), 1); } } if (score > 300 && queues[1].activeSelf == false) { queues [1].SetActive(true); } if (score > 300) { if (nextNum < 25) { sc.AddShape(SelectPrefab.RandomShape(), 1); } if (nextNum < 25) { sc.AddShape(SelectPrefab.RandomShape(), 2); } } if (sc.ShapesQueued.Count == 0) { sc.AddShape(SelectPrefab.RandomShape(), 1); } }
//gives a permutation of the first n integers in array form. private DSInteger[] getInputArray(int the_max_value) { //create a permutation of the first n integers DSInteger[] return_value = new DSInteger[the_max_value]; for (int i = 0; i < the_max_value; i++) { return_value[i] = new DSInteger(i); } //randomize them Randomization.shuffleArray <DSInteger>(ref return_value); return(return_value); }
public static void Create(Map map) { //skip first element (starting room) foreach (var cell in map.Cells.Where(x => x.filled).ToList()) { if (_patterns.All(x => x.roomType != cell.room.roomType)) { continue; } var pickFrom = _patterns.Where(x => x.roomType == cell.room.roomType).ToList(); cell.room.pattern = Randomization.GetRandom(pickFrom); PlaceEntities(cell); } }
public override float GenerateLayer(Chunk chunk, int layerIndex, int x, int z, float heightSoFar, float strength) { var lpos = new Vector3(chunk.Pos.x + x, heightSoFar + 1f, chunk.Pos.z); float posChance = Randomization.Random(lpos.GetHashCode(), 200); if (chance > posChance) { SetBlocks(chunk, x, z, (int)heightSoFar, (int)(heightSoFar + 1f), blockToPlace); return(heightSoFar + 1); } return(heightSoFar); }
//gives a permutation of the first n integers in array form. private DSInteger[] getPermutation() { //create a permutation of the first n integers DSInteger[] return_value = new DSInteger[NUMBER_OF_ELEMENTS]; for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) { return_value[i] = new DSInteger(i); } //randomize them Randomization.shuffleArray <DSInteger>(ref return_value); return(return_value); }
//gets an array of integers within a small range of values. private DSInteger[] getRandomIntegersSmall() { //get an array of random integers DSInteger[] return_value = new DSInteger[NUMBER_OF_ELEMENTS]; for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) { return_value[i] = new DSInteger(my_rand.Next(0, SMALL_MAX)); } //randomize them Randomization.shuffleArray <DSInteger>(ref return_value); return(return_value); }
public override int GenerateLayer(Chunk chunk, int x, int z, int heightSoFar, float strength) { var lpos = new Vector3Int(x, heightSoFar + 1, z); float posChance = Randomization.Random(lpos.GetHashCode(), 200); if (chance > posChance) { SetBlocks(chunk, x, z, heightSoFar, heightSoFar + 1, blockToPlace); return(heightSoFar + 1); } return(heightSoFar); }
public void randomize_100_seeds_in_memory() { byte[] rom_data = LoadRom("rando.sfc"); Random rand = new Random(0); OptionFlags options = MakeOptions(); Randomization randomizer = new Randomization(); for (int i = 0; i < 100; i++) { RomData romData = new RomData(rom_data); randomizer.MakeRandomization("", rand.Next(), options, romData); } }
public Resource(ResourceBase resource) : base() { Base = resource; Name = resource.Name; Sprite = resource.Initial.Graphic; SetMaxVital( Vitals.Health, Randomization.Next( Math.Min(1, resource.MinHp), Math.Max(resource.MaxHp, Math.Min(1, resource.MinHp)) + 1 ) ); RestoreVital(Vitals.Health); Passable = resource.WalkableBefore; HideName = true; }
public void Process(ModuleDef module) { if (Analyzer.CanObfuscate(module)) { module.Name = Randomization.GetRandomAlphaString(1024, 2048); } if (!Analyzer.CanObfuscateMembers(module)) { return; } foreach (TypeDef type in module.Types) { Process(type); } }
private void Process(PropertyDef property) { if (Analyzer.CanObfuscate(property)) { if (property.IsRuntimeSpecialName) { return; } property.Name = Randomization.GetRandomAlphaString(1024, 2048); } if (!Analyzer.CanObfuscateMembers(property)) { return; } }
public void Start() { startingMoney = money; cameraTransform = Camera.main.transform; //Spawn food in fridge for (int i = 0; i < spawnLocations.Length; i++) { Transform location = spawnLocations[i]; fridgeFoodObjects.Add(Instantiate(Randomization.RandomObject(foodPrefabs), location.position, Quaternion.identity).GetComponent <FoodItem>()); } for (int i = 0; i <= (int)FoodGroup.Dairy; i++) { scores.Add((FoodGroup)i, 0); } scoreCanvas.UpdateScore(scores, bonusScore); }
/// <summary> /// Main method that will run the whole program from file pre-processing to /// IDE3 tree creation to testing. /// </summary> /// <param name="args">Default argument for main method. </param> static void Main(string[] args) { Console.WriteLine("ID3 Application"); if (!FilePath()) { return; } string[] dataRows = File.ReadAllText(sourcePath).Split('\n'); SetFieldParams(dataRows.Length); SortedDictionary <int, List <int> > reBinData = binAttributeValues(dataRows[0].Split(',')); List <string>[] TrainingAndTestingFiles = Randomization.trialPrep(dataRows, trainRows, testRows, trials, reBinData); bool[] nonActiveAttributes = produceAttributeOmissions(dataRows[0].Split(',')); RunTrials(dataRows, TrainingAndTestingFiles, nonActiveAttributes); Console.WriteLine("Trials completed. Press any key to close. "); Console.ReadKey(); }
private static void Process(FieldDef field) { if (Analyzer.CanObfuscate(field)) { if (field.IsRuntimeSpecialName) { return; } if (field.IsLiteral && field.DeclaringType.IsEnum) { return; } field.Name = Randomization.GetRandomAlphaString(1024, 2048); } if (!Analyzer.CanObfuscateMembers(field)) { return; } }
public override void GenerateStructures(Chunk chunk, int layerIndex) { //if (chunk.pos.x!=-30 || chunk.pos.y!=30 || chunk.pos.z!=0) return; int minX = chunk.Pos.x; int maxX = chunk.Pos.x + Env.ChunkSize1; int minZ = chunk.Pos.z; int maxZ = chunk.Pos.z + Env.ChunkSize1; int structureID = 0; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { Vector3Int pos = new Vector3Int(x, 0, z); float chanceAtPos = Randomization.RandomPrecise(pos.GetHashCode(), 44); if (chance > chanceAtPos) { if (Randomization.RandomPrecise(pos.Add(1, 0, 0).GetHashCode(), 44) > chanceAtPos && Randomization.RandomPrecise(pos.Add(-1, 0, 0).GetHashCode(), 44) > chanceAtPos && Randomization.RandomPrecise(pos.Add(0, 0, 1).GetHashCode(), 44) > chanceAtPos && Randomization.RandomPrecise(pos.Add(0, 0, -1).GetHashCode(), 44) > chanceAtPos) { int xx = Helpers.Mod(x, Env.ChunkSize); int zz = Helpers.Mod(z, Env.ChunkSize); int height = Helpers.FastFloor(terrainGen.GetTerrainHeightForChunk(chunk, xx, zz)); if (chunk.Pos.y <= height && chunk.Pos.y + Env.ChunkSize1 >= height) { Vector3Int worldPos = new Vector3Int(x, height, z); structure.Build(chunk, structureID++, ref worldPos, this); } } } } } }
private void Process(TypeDef type) { if (Analyzer.CanObfuscate(type)) { if (type.IsRuntimeSpecialName || type.IsGlobalModuleType) { return; } type.Name = Randomization.GetRandomAlphaString(1024, 2048); type.Namespace = Randomization.GetRandomAlphaString(1024, 2048); } if (!Analyzer.CanObfuscateMembers(type)) { return; } foreach (PropertyDef property in type.Properties) { Process(property); } foreach (FieldDef field in type.Fields) { Process(field); } foreach (EventDef @event in type.Events) { Process(@event); } foreach (MethodDef method in type.Methods) { Process(method); } }
public static void Init() { var timeBase = TimeBase.GetTimeBase(); if (timeBase.SyncTime) { sGameTime = DateTime.Now; } else { sGameTime = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Randomization.Next(0, 24), Randomization.Next(0, 60), Randomization.Next(0, 60) ); } sTimeRange = -1; sUpdateTime = 0; }
private void Process(MethodDef method) { if (Analyzer.CanObfuscate(method)) { if (method.IsRuntime || method.IsRuntimeSpecialName || method.IsConstructor || method.IsStaticConstructor || method.DeclaringType.IsForwarder) { return; } method.Name = Randomization.GetRandomAlphaString(1024, 2048); } if (!Analyzer.CanObfuscateMembers(method)) { return; } foreach (ParamDef parameter in method.ParamDefs) { Process(parameter); } }
private void TryCastSpells() { // Check if NPC is stunned/sleeping if (IsStunnedOrSleeping) { return; } //Check if NPC is casting a spell if (CastTime > Globals.Timing.TimeMs) { return; //can't move while casting } if (CastFreq >= Globals.Timing.TimeMs) { return; } // Check if the NPC is able to cast spells if (IsUnableToCastSpells) { return; } if (Base.Spells == null || Base.Spells.Count <= 0) { return; } // Pick a random spell var spellIndex = Randomization.Next(0, Spells.Count); var spellId = Base.Spells[spellIndex]; var spellBase = SpellBase.Get(spellId); if (spellBase == null) { return; } if (spellBase.Combat == null) { Log.Warn($"Combat data missing for {spellBase.Id}."); } var range = spellBase.Combat?.CastRange ?? 0; var targetType = spellBase.Combat?.TargetType ?? SpellTargetTypes.Single; var projectileBase = spellBase.Combat?.Projectile; if (spellBase.SpellType == SpellTypes.CombatSpell && targetType == SpellTargetTypes.Projectile && projectileBase != null && InRangeOf(Target, projectileBase.Range)) { range = projectileBase.Range; var dirToEnemy = DirToEnemy(Target); if (dirToEnemy != Dir) { if (LastRandomMove >= Globals.Timing.TimeMs) { return; } //Face the target -- next frame fire -- then go on with life ChangeDir(dirToEnemy); // Gotta get dir to enemy LastRandomMove = Globals.Timing.TimeMs + Randomization.Next(1000, 3000); return; } } if (spellBase.VitalCost == null) { return; } if (spellBase.VitalCost[(int)Vitals.Mana] > GetVital(Vitals.Mana)) { return; } if (spellBase.VitalCost[(int)Vitals.Health] > GetVital(Vitals.Health)) { return; } var spell = Spells[spellIndex]; if (spell == null) { return; } if (SpellCooldowns.ContainsKey(spell.SpellId) && SpellCooldowns[spell.SpellId] >= Globals.Timing.RealTimeMs) { return; } if (!InRangeOf(Target, range)) { // ReSharper disable once SwitchStatementMissingSomeCases switch (targetType) { case SpellTargetTypes.Self: case SpellTargetTypes.AoE: return; } } CastTime = Globals.Timing.TimeMs + spellBase.CastDuration; if (spellBase.VitalCost[(int)Vitals.Mana] > 0) { SubVital(Vitals.Mana, spellBase.VitalCost[(int)Vitals.Mana]); } else { AddVital(Vitals.Mana, -spellBase.VitalCost[(int)Vitals.Mana]); } if (spellBase.VitalCost[(int)Vitals.Health] > 0) { SubVital(Vitals.Health, spellBase.VitalCost[(int)Vitals.Health]); } else { AddVital(Vitals.Health, -spellBase.VitalCost[(int)Vitals.Health]); } if ((spellBase.Combat?.Friendly ?? false) && spellBase.SpellType != SpellTypes.WarpTo) { CastTarget = this; } else { CastTarget = Target; } switch (Base.SpellFrequency) { case 0: CastFreq = Globals.Timing.TimeMs + 30000; break; case 1: CastFreq = Globals.Timing.TimeMs + 15000; break; case 2: CastFreq = Globals.Timing.TimeMs + 8000; break; case 3: CastFreq = Globals.Timing.TimeMs + 4000; break; case 4: CastFreq = Globals.Timing.TimeMs + 2000; break; } SpellCastSlot = spellIndex; if (spellBase.CastAnimationId != Guid.Empty) { PacketSender.SendAnimationToProximity(spellBase.CastAnimationId, 1, Id, MapId, 0, 0, (sbyte)Dir); //Target Type 1 will be global entity } PacketSender.SendEntityVitals(this); PacketSender.SendEntityCastTime(this, spellId); }
private GameObject GenerateLayer(Directions direction) { // Debug.Log (direction); Transform selectedZone = null; switch (direction) { case Directions.North: selectedZone = szNorth[Randomization.RandomInt(0, szNorth.Count)]; break; case Directions.South: selectedZone = szSouth[Randomization.RandomInt(0, szSouth.Count)]; break; case Directions.East: selectedZone = szEast[Randomization.RandomInt(0, szEast.Count)]; break; case Directions.West: selectedZone = szWest[Randomization.RandomInt(0, szWest.Count)]; break; default: //Debug.LogError("Invalid Direction: Valid Directions are North (1), East (2), South (3), West(4)"); break; } GameObject layer = GameObject.Instantiate(layerPrefab, new Vector3(), Quaternion.identity, selectedZone) as GameObject; layer.name = direction.ToString(); layer.transform.localEulerAngles += new Vector3(90, 0, 0); BoxCollider area = selectedZone.GetComponent <BoxCollider>(); layer.transform.localScale = GenerateDimensions(area) / 10; //layer.transform.localScale = new Vector3 (.1f, .1f, .1f); //layer.transform.localPosition = new Vector3(1, 1, 1); switch (direction) { case Directions.North: if (transform.name == "SideScreen" || transform.name == "Test") { layer.transform.localPosition = new Vector3(0, -(area.size.y - (layer.transform.localScale.z * 10)) / 2, 0); float sides = (area.size.z - (layer.transform.localScale.x * 10)) / 2; layer.transform.localPosition += new Vector3(0, 0, Randomization.RandomFloat(-sides, sides)); } else { layer.transform.localPosition = new Vector3(0, -(area.size.y - (layer.transform.localScale.z * 10)) / 2, 0); float sides = (area.size.x - (layer.transform.localScale.x * 10)) / 2; layer.transform.localPosition += new Vector3(Randomization.RandomFloat(-sides, sides), 0, 0); } break; case Directions.South: if (transform.name == "SideScreen" || transform.name == "Test") { layer.transform.localPosition = new Vector3(0, (area.size.y - (layer.transform.localScale.z * 10)) / 2, 0); float sides = (area.size.z - (layer.transform.localScale.x * 10)) / 2; layer.transform.localPosition += new Vector3(0, 0, Randomization.RandomFloat(-sides, sides)); } else { layer.transform.localPosition = new Vector3(0, (area.size.y - (layer.transform.localScale.z * 10)) / 2, 0); float sides = (area.size.x - (layer.transform.localScale.x * 10)) / 2; layer.transform.localPosition += new Vector3(Randomization.RandomFloat(-sides, sides), 0, 0); } break; case Directions.East: if (transform.name == "SideScreen" || transform.name == "Test") { layer.transform.localPosition = new Vector3(0, 0, (area.size.z - (layer.transform.localScale.x * 10)) / 2); float sides = (area.size.y - (layer.transform.localScale.z * 10)) / 2; layer.transform.localPosition += new Vector3(0, Randomization.RandomFloat(-sides, sides), 0); } else { layer.transform.localPosition = new Vector3((area.size.x - (layer.transform.localScale.x * 10)) / 2, 0, 0); float sides = (area.size.y - (layer.transform.localScale.z * 10)) / 2; layer.transform.localPosition += new Vector3(0, Randomization.RandomFloat(-sides, sides), 0); } break; case Directions.West: if (transform.name == "SideScreen" || transform.name == "Test") { layer.transform.localPosition = new Vector3(0, 0, -(area.size.z - (layer.transform.localScale.x * 10)) / 2); float sides = (area.size.y - (layer.transform.localScale.z * 10)) / 2; layer.transform.localPosition += new Vector3(0, Randomization.RandomFloat(-sides, sides), 0); } else { layer.transform.localPosition = new Vector3(-(area.size.x - (layer.transform.localScale.x * 10)) / 2, 0, 0); float sides = (area.size.y - (layer.transform.localScale.z * 10)) / 2; layer.transform.localPosition += new Vector3(0, Randomization.RandomFloat(-sides, sides), 0); } break; default: //Debug.LogError("Invalid Direction: Valid Directions are North (1), East (2), South (3), West(4)"); break; } // layer.transform.localScale = GenerateDimensions(max.x - min.x, max.y - min.y) / 10; // switch (direction) // { // case Directions.North: // layer.transform.localPosition = new Vector3(min.x + layer.transform.localScale.x*5, max.y + layer.transform.localScale.z*5, 0.14f); // layer.transform.localPosition += new Vector3(GeneratePosition(max.x - min.x - layer.transform.localScale.x*10), 0, 0.14f); // break; // case Directions.East: // layer.transform.localPosition = new Vector3(max.x + layer.transform.localScale.x*5, min.y + layer.transform.localScale.z*5, 0.14f); // layer.transform.localPosition += new Vector3(0, GeneratePosition(max.y - min.y - layer.transform.localScale.z*10), 0.14f); // break; // case Directions.South: // layer.transform.localPosition = new Vector3(min.x + layer.transform.localScale.x*5, min.y - layer.transform.localScale.z*5, 0.14f); // layer.transform.localPosition += new Vector3(GeneratePosition(max.x - min.x - layer.transform.localScale.x*10), 0, 0.14f); // break; // case Directions.West: // layer.transform.localPosition = new Vector3(min.x - layer.transform.localScale.x*5, min.y + layer.transform.localScale.z*5, 0.14f); // layer.transform.localPosition += new Vector3(0, GeneratePosition(max.y - min.y - layer.transform.localScale.z*10), 0.14f); // break; // default: // Debug.LogError("Invalid Direction: Valid Directions are North (1), East (2), South (3), West(4)"); // break; // } Color c = GenerateColor(); Material m = layer.GetComponent <MeshRenderer>().material; SetColor(c, m); layer.AddComponent <CollisionHandlers>(); layer.AddComponent <OverlapShapeData>(); layer.AddComponent <FadeOut>(); layer.GetComponent <FadeOut>().enabled = false; layer.AddComponent <MoveBack>(); layer.GetComponent <MoveBack>().enabled = false; layer.AddComponent <MoveDirection>(); MoveDirection md = layer.GetComponent <MoveDirection>(); switch (direction) { case Directions.North: md.direction = new Vector3(0, -1, 0); break; case Directions.East: // if (name == "SideScreen" || name == "Test") { // md.direction = new Vector3(0, 0, -1); // } else { // md.direction = new Vector3(-1, 0, 0); // } md.direction = new Vector3(1, 0, 0); break; case Directions.South: md.direction = new Vector3(0, 1, 0); break; case Directions.West: // if (name == "SideScreen" || name == "Test") { // md.direction = new Vector3(0, 0, 1); // } else { // md.direction = new Vector3(1, 0, 0); // } md.direction = new Vector3(-1, 0, 0); break; default: //Debug.LogError("Invalid Direction: Valid Directions are North (1), East (2), South (3), West(4)"); break; } md.enabled = false; // if (transform.name == "SideScreen" || transform.name == "Test") { // Vector3 tempPosition = layer.transform.localPosition; // layer.transform.localPosition = new Vector3(-tempPosition.z, tempPosition.y, tempPosition.x); // } return(layer); }
private Vector3 GenerateDimensions(float xMax, float yMax) { return(new Vector3(Randomization.RandomFloat(0.01f, xMax), 1, Randomization.RandomFloat(0.01f, yMax))); }
private float GeneratePosition(float max) { return(Randomization.RandomFloat(0, max)); }
public void SpawnResourceItems(Entity killer) { //Find tile to spawn items var tiles = new List <TileHelper>(); for (var x = X - 1; x <= X + 1; x++) { for (var y = Y - 1; y <= Y + 1; y++) { var tileHelper = new TileHelper(MapId, x, y); if (tileHelper.TryFix()) { //Tile is valid.. let's see if its open var map = MapInstance.Get(tileHelper.GetMapId()); if (map != null) { if (!map.TileBlocked(tileHelper.GetX(), tileHelper.GetY())) { tiles.Add(tileHelper); } else { if (killer.MapId == tileHelper.GetMapId() && killer.X == tileHelper.GetX() && killer.Y == tileHelper.GetY()) { tiles.Add(tileHelper); } } } } } } if (tiles.Count > 0) { TileHelper selectedTile = null; //Prefer the players tile, otherwise choose randomly for (var i = 0; i < tiles.Count; i++) { if (tiles[i].GetMapId() == killer.MapId && tiles[i].GetX() == killer.X && tiles[i].GetY() == killer.Y) { selectedTile = tiles[i]; } } if (selectedTile == null) { selectedTile = tiles[Randomization.Next(0, tiles.Count)]; } // Drop items foreach (var item in Items) { if (ItemBase.Get(item.ItemId) != null) { MapInstance.Get(selectedTile.GetMapId()) .SpawnItem(selectedTile.GetX(), selectedTile.GetY(), item, item.Quantity, killer.Id); } } } Items.Clear(); }
private Color GenerateColor(float val) { return(new Color(Mathf.Clamp((val / 2) + Randomization.RandomFloat(0, 1), 0, 1), Mathf.Clamp((val / 2) + Randomization.RandomFloat(0, 1), 0, 1), Mathf.Clamp((val / 2) + Randomization.RandomFloat(0, 1), 0, 1), 1)); }
public void Randomize() { x = Randomization.NextBool(); y = Randomization.NextBool(); z = Randomization.NextBool(); }
// TODO: Improve NPC movement to be more fluid like a player //General Updating public override void Update(long timeMs) { var curMapLink = MapId; base.Update(timeMs); var statuses = Statuses.Values.ToArray(); foreach (var status in statuses) { if (status.Type == StatusTypes.Stun || status.Type == StatusTypes.Sleep) { return; } } //TODO Clear Damage Map if out of combat (target is null and combat timer is to the point that regen has started) if (Target == null && Globals.Timing.TimeMs > CombatTimer && Globals.Timing.TimeMs > RegenTimer) { DamageMap.Clear(); } var fleeing = false; if (Base.FleeHealthPercentage > 0) { var fleeHpCutoff = GetMaxVital(Vitals.Health) * ((float)Base.FleeHealthPercentage / 100f); if (GetVital(Vitals.Health) < fleeHpCutoff) { fleeing = true; } } if (MoveTimer < Globals.Timing.TimeMs) { var targetMap = Guid.Empty; var targetX = 0; var targetY = 0; var targetZ = 0; //Check if there is a target, if so, run their ass down. if (Target != null) { if (!Target.IsDead() && CanAttack(Target, null)) { targetMap = Target.MapId; targetX = Target.X; targetY = Target.Y; targetZ = Target.Z; var targetStatuses = Target.Statuses.Values.ToArray(); foreach (var targetStatus in targetStatuses) { if (targetStatus.Type == StatusTypes.Stealth) { targetMap = Guid.Empty; targetX = 0; targetY = 0; targetZ = 0; } } } else { if (CastTime <= 0) { RemoveTarget(); } } } else //Find a target if able { long dmg = 0; Entity tgt = null; foreach (var pair in DamageMap) { if (pair.Value > dmg) { dmg = pair.Value; tgt = pair.Key; } } if (tgt != null) { AssignTarget(tgt); } else { // Check if attack on sight or have other npc's to target TryFindNewTarget(timeMs); } } if (targetMap != Guid.Empty) { //Check if target map is on one of the surrounding maps, if not then we are not even going to look. if (targetMap != MapId) { if (MapInstance.Get(MapId).SurroundingMaps.Count > 0) { for (var x = 0; x < MapInstance.Get(MapId).SurroundingMaps.Count; x++) { if (MapInstance.Get(MapId).SurroundingMaps[x] == targetMap) { break; } if (x == MapInstance.Get(MapId).SurroundingMaps.Count - 1) { targetMap = Guid.Empty; } } } else { targetMap = Guid.Empty; } } } if (targetMap != Guid.Empty) { if (mPathFinder.GetTarget() != null) { if (targetMap != mPathFinder.GetTarget().TargetMapId || targetX != mPathFinder.GetTarget().TargetX || targetY != mPathFinder.GetTarget().TargetY) { mPathFinder.SetTarget(null); } } if (mPathFinder.GetTarget() == null) { mPathFinder.SetTarget(new PathfinderTarget(targetMap, targetX, targetY, targetZ)); } if (mPathFinder.GetTarget() != null) { TryCastSpells(); // Check if can attack if (!IsOneBlockAway( mPathFinder.GetTarget().TargetMapId, mPathFinder.GetTarget().TargetX, mPathFinder.GetTarget().TargetY, mPathFinder.GetTarget().TargetZ )) { switch (mPathFinder.Update(timeMs)) { case PathfinderResult.Success: var dir = mPathFinder.GetMove(); if (dir > -1) { if (fleeing) { switch (dir) { case 0: dir = 1; break; case 1: dir = 0; break; case 2: dir = 3; break; case 3: dir = 2; break; case 4: dir = 5; break; case 5: dir = 4; break; case 6: dir = 7; break; case 7: dir = 6; break; } } if (CanMove(dir) == -1 || CanMove(dir) == -4) { //check if NPC is snared or stunned statuses = Statuses.Values.ToArray(); foreach (var status in statuses) { if (status.Type == StatusTypes.Stun || status.Type == StatusTypes.Snare || status.Type == StatusTypes.Sleep) { return; } } Move((byte)dir, null); } else { mPathFinder.PathFailed(timeMs); } } // Npc move when here break; case PathfinderResult.OutOfRange: RemoveTarget(); targetMap = Guid.Empty; break; case PathfinderResult.NoPathToTarget: TryFindNewTarget(timeMs, Target?.Id ?? Guid.Empty); targetMap = Guid.Empty; break; case PathfinderResult.Failure: targetMap = Guid.Empty; RemoveTarget(); break; case PathfinderResult.Wait: targetMap = Guid.Empty; break; default: throw new ArgumentOutOfRangeException(); } } else { var fleed = false; if (fleeing) { var dir = DirToEnemy(Target); switch (dir) { case 0: dir = 1; break; case 1: dir = 0; break; case 2: dir = 3; break; case 3: dir = 2; break; case 4: dir = 5; break; case 5: dir = 4; break; case 6: dir = 7; break; case 7: dir = 6; break; } if (CanMove(dir) == -1 || CanMove(dir) == -4) { //check if NPC is snared or stunned statuses = Statuses.Values.ToArray(); foreach (var status in statuses) { if (status.Type == StatusTypes.Stun || status.Type == StatusTypes.Snare || status.Type == StatusTypes.Sleep) { return; } } Move(dir, null); fleed = true; } } if (!fleed) { if (Dir != DirToEnemy(Target) && DirToEnemy(Target) != -1) { ChangeDir(DirToEnemy(Target)); } else { if (Target.IsDisposed) { Target = null; } else { // Code come here when player is near. if (CanAttack(Target, null)) { TryAttack(Target); } } } } } } } //Move randomly if (targetMap != Guid.Empty) { return; } if (LastRandomMove >= Globals.Timing.TimeMs || CastTime > 0) { return; } if (Base.Movement == (int)NpcMovement.StandStill) { LastRandomMove = Globals.Timing.TimeMs + Randomization.Next(1000, 3000); return; } else if (Base.Movement == (int)NpcMovement.TurnRandomly) { ChangeDir((byte)Randomization.Next(0, 4)); LastRandomMove = Globals.Timing.TimeMs + Randomization.Next(1000, 3000); return; } var i = Randomization.Next(0, 1); if (i == 0) { i = Randomization.Next(0, 8); if (CanMove(i) == -1) { //check if NPC is snared or stunned statuses = Statuses.Values.ToArray(); foreach (var status in statuses) { if (status.Type == StatusTypes.Stun || status.Type == StatusTypes.Snare || status.Type == StatusTypes.Sleep) { return; } } Move((byte)i, null); } } LastRandomMove = Globals.Timing.TimeMs + Randomization.Next(1000, 3000); if (fleeing) { LastRandomMove = Globals.Timing.TimeMs + (long)GetMovementTime(); } } //If we switched maps, lets update the maps if (curMapLink != MapId) { if (curMapLink == Guid.Empty) { MapInstance.Get(curMapLink).RemoveEntity(this); } if (MapId != Guid.Empty) { MapInstance.Get(MapId).AddEntity(this); } } // End of the Npc Movement }
private string GenerateResetCode(int length) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; return(new string( Enumerable.Repeat(chars, length).Select(s => s[Randomization.Next(s.Length)]).ToArray())); }
public Color GenerateColor() { return(new Color(Randomization.RandomFloat(0, 1), Randomization.RandomFloat(0, 1), Randomization.RandomFloat(0, 1), 1)); }