private UnwillingVolunteerChallenge(ChallengeChecker pattern, Fight fight) : base(pattern, fight) { var random = new AsyncRandom(); this.m_target = base.m_fight.BlueTeam.Fighters[random.Next(fight.BlueTeam.Fighters.Count)]; }
// CONSTRUCTORS private ArenaManager() { this.m_queue = new ConcurrentList <Character>(); this.m_partyQueue = new ConcurrentList <ArenaParty>(); this.m_asyncRandom = new AsyncRandom(); }
public Challenge[] PopChallenges(FightTeam team, int count) { List <Challenge> results = new List <Challenge>(); AsyncRandom random = new AsyncRandom(); for (int i = 0; i < count; i++) { var pair = m_challenges.ToList().FindAll(x => CanAddChallenge(results, x.Key)).Random(); if (pair.Value != null) { Challenge challenge = (Challenge)Activator.CreateInstance(pair.Value, new object[] { pair.Key, team }); challenge.Initialize(); if (challenge.Valid()) { results.Add(challenge); } else { i--; } } } return(results.ToArray()); }
public void GenerateArenaLoot() { if ((Fighter as CharacterFighter).HasLeft) { return; } WorldClient client = (Fighter as CharacterFighter).Client; AsyncRandom random = new AsyncRandom(); FightLoot.kamas += (uint)(random.Next(50 * client.Character.Record.Level, 250 * client.Character.Record.Level)); client.Character.AddKamas((int)FightLoot.kamas); uint itemQt = (uint)random.Next(1, client.Character.Record.Level); FightLoot.objects.Add(FightArena.ARENA_ITEM_ID); FightLoot.objects.Add((ushort)itemQt); client.Character.Inventory.Add(FightArena.ARENA_ITEM_ID, itemQt); if (client.Character.Record.Level != 200) { var experienceForNextLevel = ExperienceRecord.GetExperienceForLevel((uint)client.Character.Record.Level + 1); var experienceForLevel = ExperienceRecord.GetExperienceForLevel(client.Character.Record.Level); int earnedXp = (int)((double)(experienceForNextLevel - (double)experienceForLevel) / (double)15); var expdatas = new FightResultExperienceData(true, true, true, true, false, false, false, client.Character.Record.Exp, experienceForLevel, experienceForNextLevel, earnedXp, 0, 0, 0); AdditionalDatas.Add(expdatas); client.Character.AddXp((ulong)earnedXp); } }
public static void HandleBS_CS_SELECT_MAP(SimpleClient client, BS_CS_SELECT_MAP message) { if (client.Character.RoomConnected != null) { if (message.mapId == 0) { message.mapId = (short)(Enum.GetValues(typeof(MapIdEnum)) as MapIdEnum[]).Shuffle().First(); } client.Character.RoomConnected.MapId = message.mapId; client.Character.RoomConnected.Clients.Send(new BM_SC_SELECT_MAP()); client.Character.RoomConnected.Clients.Send(new BM_SC_MAP_INFO(message.mapId)); string encryptionKey = new AsyncRandom().RandomString(16); client.Character.RoomConnected.Clients.Send(new BM_SC_START_GAME(encryptionKey, client.Character.RoomConnected.PlayersConnected.Select(x => x.GetPlayerGameInfoType()))); client.Character.RoomConnected.State = RoomStateEnum.Closed; //Thread.Sleep(6000); client.Send(new BM_SC_PSB_LEADER_NAME(client.Character.RoomConnected.PlayersConnected .FirstOrDefault(x => x.IsLeader).Name)); } else { } }
public int RollMonsterLengthLimit(int imposedLimit = 8) { var difficulty = Difficulty; if (!MonsterGroupLengthProb.ContainsKey(difficulty)) { difficulty = Difficulty.Normal; } var thresholds = MonsterGroupLengthProb[difficulty].Take(imposedLimit).ToArray(); var sum = thresholds.Sum(); var rand = new AsyncRandom(); var roll = rand.NextDouble(0, sum); double l = 0; for (var i = 0; i < thresholds.Length; i++) { l += thresholds[i]; if (roll <= l) { return(i + 1); } } return(1); }
public Cell GetCellToFlee() { var rand = new AsyncRandom(); var movementsCells = GetMovementCells(); var fighters = Fight.GetAllFighters(entry => entry.IsEnnemyWith(Fighter)); var currentCellIndice = fighters.Sum(entry => entry.Position.Point.ManhattanDistanceTo(Fighter.Position.Point)); Cell betterCell = null; long betterCellIndice = 0; foreach (var c in movementsCells) { if (!CellInformationProvider.IsCellWalkable(c.Id)) { continue; } var indice = fighters.Sum(entry => entry.Position.Point.ManhattanDistanceTo(new MapPoint(c))); if (betterCellIndice < indice) { betterCellIndice = indice; betterCell = c; } else if (betterCellIndice == indice && rand.Next(2) == 0) // random factory { betterCellIndice = indice; betterCell = c; } } return(currentCellIndice == betterCellIndice ? Fighter.Cell : betterCell); }
static void MoveGroup(MapRecord map, MonsterGroup group) { var random = new AsyncRandom(); var info = MonsterGroup.GetActorInformations(map, group); List <short> cells = Pathfinding.GetCircleCells(info.disposition.cellId, MoveCellsCount); cells.Remove(info.disposition.cellId); cells.RemoveAll(x => !map.WalkableCells.Contains(x)); cells.RemoveAll(x => PathHelper.GetDistanceBetween(info.disposition.cellId, x) <= MoveCellsCount); if (cells.Count == 0) { return; } var newCell = cells[random.Next(0, cells.Count())]; var path = new Pathfinder(map, info.disposition.cellId, newCell).FindPath(); if (path != null) { path.Insert(0, info.disposition.cellId); map.Instance.Send(new GameMapMovementMessage(path, info.contextualId)); group.CellId = (ushort)newCell; } else { Logger.Error("Unable to move group" + group.MonsterGroupId + " on map " + map.Id + ", wrong path"); } }
public static void MonsterFight(Character character, NpcReplyRecord reply) { List <MonsterRecord> templates = new List <MonsterRecord>(); foreach (var monsterId in reply.Value1.FromCSV <ushort>()) { templates.Add(MonsterRecord.GetMonster(monsterId)); } List <MonsterRecord> allyTemplates = new List <MonsterRecord>(); foreach (var monsterId in reply.Value2.FromCSV <ushort>()) { allyTemplates.Add(MonsterRecord.GetMonster(monsterId)); } FightInstancePvM fight = FightProvider.Instance.CreateFightInstancePvM(templates.ToArray(), character.Map); fight.RedTeam.AddFighter(character.CreateFighter(fight.RedTeam)); var random = new AsyncRandom(); foreach (var ally in allyTemplates) { fight.RedTeam.AddFighter(new MonsterFighter(fight.RedTeam, ally, ally.RandomGrade(random), character.CellId)); } foreach (var fighter in fight.Group.CreateFighters(fight.BlueTeam)) { fight.BlueTeam.AddFighter(fighter); } fight.StartPlacement(); }
public Cell GetCellToFlee() { AsyncRandom asyncRandom = new AsyncRandom(); Cell[] movementsCells = this.GetMovementCells(); IEnumerable <FightActor> allFighters = this.Fight.GetAllFighters((Predicate <FightActor>)(entry => entry.IsEnnemyWith((FightActor)this.Fighter))); long num1 = Enumerable.Sum <FightActor>(allFighters, (Func <FightActor, long>)(entry => (long)entry.Position.Point.DistanceToCell(this.Fighter.Position.Point))); Cell cell = (Cell)null; long num2 = 0L; for (int i = 0; i < movementsCells.Length; ++i) { if (this.CellInformationProvider.IsCellWalkable(movementsCells[i].Id)) { long num3 = Enumerable.Sum <FightActor>(allFighters, (Func <FightActor, long>)(entry => (long)entry.Position.Point.DistanceToCell(new MapPoint(movementsCells[i])))); if (num2 < num3) { num2 = num3; cell = movementsCells[i]; } else if ((num2 != num3 ? 1 : (asyncRandom.Next(2) != 0 ? 1 : 0)) == 0) { num2 = num3; cell = movementsCells[i]; } } } return(num1 != num2 ? cell : this.Fighter.Cell); }
public override EffectBase GenerateEffect(EffectGenerationContext context, EffectGenerationType type = EffectGenerationType.Normal) { var rand = new AsyncRandom(); var max = m_dicenum >= m_diceface ? m_dicenum : m_diceface; var min = m_dicenum <= m_diceface ? m_dicenum : m_diceface; if (min == 0) { min = max; } if (type == EffectGenerationType.MaxEffects && Template.Operator == "+") { return(new EffectInteger(Id, Template.Operator != "-" ? max : min, this)); } if (type == EffectGenerationType.MinEffects) { return(new EffectInteger(Id, Template.Operator != "-" ? min : max, this)); } if (min != 0) { return(new EffectInteger(Id, (short)rand.Next(min, max + 1), this)); } return(max == 0 ? new EffectInteger(Id, m_value, this) : new EffectInteger(Id, max, this)); }
// [StartupInvoke(StartupInvokePriority.Modules)] public static void FixTemplates() { AsyncRandom random = new AsyncRandom(); foreach (var monster in MonsterRecord.Monsters) { int minDroppedKamas = 0; int maxDroppedKamas = 0; int level = monster.GetGrade(1).Level; minDroppedKamas = random.Next(level * DroppedKamasRatio, level * (DroppedKamasRatio * 2)); maxDroppedKamas = minDroppedKamas + level * 2; if (monster.IsBoss) { minDroppedKamas *= BossDroppedKamasMultiplicator; maxDroppedKamas *= BossDroppedKamasMultiplicator; } monster.MinDroppedKamas = minDroppedKamas / 2; monster.MaxDroppedKamas = maxDroppedKamas / 2; monster.UpdateInstantElement(); logger.Gray("Fixed : " + monster.Name); } }
public static string TransfertToGame(Account account) { string text = new AsyncRandom().RandomString(32); _tickets.Add(text, account); return(text); }
public int RollMonsterGrade(int minGrade, int maxGrade) { Difficulty key = this.Difficulty; if (!SubArea.MonsterGroupLengthProb.ContainsKey(key)) { key = Difficulty.Normal; } double[] array = SubArea.MonsterGroupLengthProb[key].Skip(minGrade - 1).Take(maxGrade - minGrade + 1).ToArray <double>(); double max = array.Sum(); AsyncRandom asyncRandom = new AsyncRandom(); double num = asyncRandom.NextDouble(0.0, max); double num2 = 0.0; int result; for (int i = 0; i < array.Length; i++) { num2 += array[i]; if (num <= num2) { if (i >= array.Length - 1 && maxGrade > array.Length) { int num3 = asyncRandom.Next(0, maxGrade - array.Length + 1); result = i + num3 + 1; } else { result = i + 1; } return(result); } } result = 1; return(result); }
public int RollMonsterLengthLimit(int imposedLimit = 8) { Difficulty key = this.Difficulty; if (!SubArea.MonsterGroupLengthProb.ContainsKey(key)) { key = Difficulty.Normal; } double[] array = SubArea.MonsterGroupLengthProb[key].Take(imposedLimit).ToArray <double>(); double max = array.Sum(); AsyncRandom asyncRandom = new AsyncRandom(); double num = asyncRandom.NextDouble(0.0, max); double num2 = 0.0; int result; for (int i = 0; i < array.Length; i++) { num2 += array[i]; if (num <= num2) { result = i + 1; return(result); } } result = 1; return(result); }
/// <summary> /// Spawn un groupe de monstre qui sera généré en fonction des constantes de générations. /// </summary> /// <param name="spawns"></param> /// <param name="quiet"></param> public void AddGeneratedMonsterGroup(AbstractMapInstance instance, MonsterSpawnRecord[] spawns, bool quiet) { AsyncRandom random = new AsyncRandom(); MonsterGroup group = new MonsterGroup(instance.Record); for (int w = 0; w < random.Next(1, instance.Record.BlueCells.Count + 1); w++) { int max = spawns.Sum((MonsterSpawnRecord entry) => entry.Probability); int num = random.Next(0, max); int num2 = 0; foreach (var monsterRecord in spawns) { num2 += monsterRecord.Probability; if (num <= num2) { MonsterRecord template = MonsterRecord.GetMonster(monsterRecord.MonsterId); Monster monster = new Monster(template, group, template.RandomGrade(random)); group.AddMonster(monster); break; } } } if (quiet) { instance.AddQuietEntity(group); } else { instance.AddEntity(group); } }
public static MapRecord RandomOutdoorMap() { var maps = Maps.FindAll(x => x.Position != null && x.Position.Outdoor); AsyncRandom random = new AsyncRandom(); int index = random.Next(0, maps.Count); return(maps[index]); }
public void Initialize() { AsyncRandom random = new AsyncRandom(); for (int i = 0; i < Weigths.Length; i++) { Weigths[i] = RandomUtils.NormalRandom(0.3f) * 0.10f; } }
public Barn(BrainFighter fighter) : base(fighter) { this.GradeRandomizer = new AsyncRandom(); fighter.Fight.FightStartEvt += Fight_FightStart; fighter.OnDamageTaken += fighter_OnDamageTaken; this.SummonedTemplate = MonsterRecord.GetMonster(SummonedMonsterId); }
protected override int GetNextSpawnInterval() { var rand = new AsyncRandom(); if (rand.Next(0, 2) == 0) { return((int)((Interval - (rand.NextDouble() * Interval / 4)) * 1000)); } return((int)((Interval + (rand.NextDouble() * Interval / 4)) * 1000)); }
public FightSpellCastCriticalEnum RollCriticalDice(SpellLevelRecord spell) { AsyncRandom asyncRandom = new AsyncRandom(); FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL; if (spell.CriticalHitProbability != 0u && asyncRandom.Next((int)this.CalculateCriticRate(spell.CriticalHitProbability)) == 0) { result = FightSpellCastCriticalEnum.CRITICAL_HIT; } return(result); }
public FightSpellCastCriticalEnum RollCriticalDice(WeaponRecord weapon) { AsyncRandom asyncRandom = new AsyncRandom(); FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL; int num = (int)this.CalculateCriticRate(weapon.CriticalHitProbability) / 6; if (weapon.CriticalHitProbability != 0 && asyncRandom.Next(num) == 0) { result = FightSpellCastCriticalEnum.CRITICAL_HIT; } return(result); }
/// <summary> /// Spawn les groupes de monstres d'une carte. /// </summary> /// <param name="map"></param> public void SpawnMonsters(MapRecord map) { AsyncRandom random = new AsyncRandom(); if (map.MonsterSpawnsSubArea.Length > 0) { for (sbyte groupId = 0; groupId < random.Next(1, MaxMonsterGroupPerMap + 1); groupId++) { AddGeneratedMonsterGroup(map.Instance, map.MonsterSpawnsSubArea, true); } } }
public static string GetRandomString(int length) { var random = new AsyncRandom(); string characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; StringBuilder result = new StringBuilder(length); for (int i = 0; i < length; i++) { result.Append(characters[random.Next(characters.Length)]); } return(result.ToString()); }
public FightSpellCastCriticalEnum RollCriticalDice(WeaponTemplate weapon) { AsyncRandom asyncRandom = new AsyncRandom(); FightSpellCastCriticalEnum result = FightSpellCastCriticalEnum.NORMAL; if (weapon.CriticalHitProbability != 0u && asyncRandom.Next(100) < this.CalculateCriticRate((uint)weapon.CriticalHitProbability)) { result = FightSpellCastCriticalEnum.CRITICAL_HIT; } return(result); }
public override void Apply() { var random = new AsyncRandom(); foreach (var monster in Result.Fighter.OposedTeam().GetFighters <MonsterFighter>(false)) { if (NonLootable.Contains(monster.Template.Id)) { return; } } this.Add(17745, GetGoldenTicketsCount(Result.ExperienceData.ExperienceFightDelta)); }
public override EffectBase GenerateEffect(EffectGenerationContext context, EffectGenerationType type = EffectGenerationType.Normal) { var rand = new AsyncRandom(); if (type == EffectGenerationType.MaxEffects && Template.Operator == "+") { return(new EffectInteger(Id, Template.Operator != "-" ? ValueMax : ValueMin, this)); } if (type == EffectGenerationType.MinEffects) { return(new EffectInteger(Id, Template.Operator != "-" ? ValueMin : ValueMax, this)); } return(new EffectInteger(Id, (short)rand.Next(ValueMin, ValueMax + 1), this)); }
protected override int GetNextSpawnInterval() { AsyncRandom asyncRandom = new AsyncRandom(); int result; if (asyncRandom.Next(0, 2) == 0) { result = (int)(((double)base.Interval - asyncRandom.NextDouble() * (double)base.Interval / 4.0) * 1000.0); } else { result = (int)(((double)base.Interval + asyncRandom.NextDouble() * (double)base.Interval / 4.0) * 1000.0); } return(result); }
public override IEnumerable <DroppedItem> RollLoot(int teamPp, int dropBonusPercent) { if (this.Alive) { return(new DroppedItem[0]); } AsyncRandom asyncRandom = new AsyncRandom(); List <DroppedItem> list = new List <DroppedItem>(); int prospectingSum = this.OposedTeam().GetFighters <CharacterFighter>().Sum(entry => entry.Stats.Prospecting.TotalInContext()); IEnumerable <MonsterDrop> monsterDroppableItems = from droppableItem in this.Template.Drops where prospectingSum >= droppableItem.ProspectingLock && !droppableItem.HasCriteria select droppableItem; foreach (MonsterDrop droppableItem in monsterDroppableItems) { int attempts = 0; while (attempts < droppableItem.Count && (droppableItem.DropLimit <= 0 || !this.m_dropsCount.ContainsKey(droppableItem) || this.m_dropsCount[droppableItem] < droppableItem.DropLimit)) { double randomDropThreshold = asyncRandom.Next(0, 100) + asyncRandom.NextDouble(); double randomDropChance = FormulasProvider.Instance.AdjustDropChance(teamPp, droppableItem, this.GradeId, this.Fight.AgeBonus, dropBonusPercent); // Probability to drop if (randomDropChance >= randomDropThreshold) { // Item dropped, add it to list list.Add(new DroppedItem(droppableItem.ItemId, 1u)); // Update the map for while conditions if (!this.m_dropsCount.ContainsKey(droppableItem)) { this.m_dropsCount.Add(droppableItem, 1); } else { Dictionary <MonsterDrop, int> dropsCount; MonsterDrop key; (dropsCount = this.m_dropsCount)[key = droppableItem] = dropsCount[key] + 1; } } attempts++; } } return(list); }
public void SyncMonsters() { lock (this) { if (MonstersGroups.Count > 0 || Record.HaveZaap || !MapNoSpawnRecord.CanSpawn(Record.Id)) { return; } AsyncRandom random = new AsyncRandom(); if (this.Record.DugeonMap) { if (this.MonstersGroups.Count == 0) { List <MonsterSpawnMapRecord> monsters = DungeonRecord.GetDungeonMapMonsters(this.Record.Id).ConvertAll <MonsterSpawnMapRecord>(x => new MonsterSpawnMapRecord(-1, x, this.Record.Id, 100)); monsters.ForEach(x => x.ActualGrade = (sbyte)random.Next(1, 6)); MonstersGroups.Add(new MonsterGroup(MonsterGroup.START_ID, monsters, (ushort)Record.RandomWalkableCell())); } return; } var spawns = MonsterSpawnSubRecord.GetSpawns(Record.Id); if (spawns.Count() == 0) { return; } for (sbyte groupId = 0; groupId < random.Next(1, MAX_MONSTER_PER_GROUP + 1); groupId++) { List <MonsterSpawnMapRecord> monsters = new List <MonsterSpawnMapRecord>(); for (int w = 0; w < random.Next(1, MAX_MONSTER_PER_GROUP + 1); w++) { int max = spawns.Sum((MonsterSpawnMapRecord entry) => entry.Probability); int num = random.Next(0, max); int num2 = 0; foreach (var monster in spawns) { num2 += monster.Probability; if (num <= num2) { monster.ActualGrade = (sbyte)random.Next(1, 6); monsters.Add(monster); break; } } } MonstersGroups.Add(new MonsterGroup(groupId + MonsterGroup.START_ID, monsters, (ushort)Record.RandomWalkableCell())); } } }