public List <UnitSpawner> GetSpawners(List <int> unique_ids, int for_id) { int id = for_id == 0 ? M_Math.GetRandomObject(unique_ids) : for_id; unique_ids.Remove(id); return(GetSpawners(id)); }
Tile GetPatrolTile(Tile start) { List <Tile> tiles_in_range = TileManager.Instance.GetRandomTilesAroundCenter(start, Constants.AI_PATROL_DISTANCE); // MDebug.Log("PATROL query tiles in range = " + tiles_in_range.Count); tiles_in_range.RemoveAll(t => !t.isAccessible || !t.isEnabled || t.isCamp || t.isCrumbling); return(M_Math.GetRandomObject(tiles_in_range)); }
public LootConfig GetLootConfig(LootCategory cat) { List <LootConfig> configs = LootConfigs.Where(lc => lc.Category == cat).ToList(); /* List<WeightedRegion> configs = Regions.Where( r => ..... ) ).ToList(); * * WeightedRegion wr = WeightableFactory.GetWeighted(configs);*/ LootConfig conf = M_Math.GetRandomObject(configs); return(conf); }
IEnumerator AttackOrMove() { MDebug.Log("What to do..`?"); UnitAction_ApplyEffectFromWeapon attack = getAttack(); UnitAction_Move move = getMove(); //dictionary of all units and the paths by which they are attackable Dictionary <Unit, List <List <Tile> > > attack_map = GetPathMapForTargets(); MDebug.Log("^aiAttack Map Count:" + attack_map.Count); List <Unit> units_attackable = Unit.GetAllUnitsOfOwner(0, false).Where(unit => attack.CanTarget(unit)).ToList(); MDebug.Log("^aiAttackable " + units_attackable.Count); List <Unit> units_move_attackable = attack_map.Where(kvp => CanFinishPathInMoves(1, kvp.Value)).Select(kvp => kvp.Key).ToList(); List <Unit> units_movable = attack_map.Where(kvp => !units_move_attackable.Contains(kvp.Key)).Select(kvp => kvp.Key).ToList(); if (attack_map.Count > 0 && (preferred_target == null || !preferred_target.IsActive)) { preferred_target = M_Math.GetRandomObject(attack_map.Select(kvp => kvp.Key).ToList()); } if (preferred_target == null) { yield return(StartCoroutine(MoveRandom())); yield break; } if (!units_attackable.Contains(preferred_target) && (!units_attackable.IsNullOrEmpty() && (!attack_map.ContainsKey(preferred_target) || M_Math.Roll(Constants.AI_TARGET_SWITCH_WHEN_OUT_OF_ATTACK_RANGE)))) { MDebug.Log("^ainew Prefferred from" + units_attackable.Count); preferred_target = M_Math.GetRandomObject(units_attackable); } if (attack.CanTarget(preferred_target) && units_attackable.Contains(preferred_target)) { Tile better_pos = GetReachableAttackPosition(preferred_target); if (m_Actions.HasAP(2) && better_pos != null) { yield return(StartCoroutine(Move(better_pos))); yield break; } else { yield return(StartCoroutine(Attack(preferred_target))); yield break; } } else { List <Unit> other_move_targets = units_move_attackable.Where(unit => unit != preferred_target && !units_attackable.Contains(unit)).ToList(); if (!other_move_targets.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_ATTACK_MOVE_WHEN_OUT_OF_MOVE_ATTACK_RANGE)) { preferred_target = M_Math.GetRandomObject(other_move_targets); } else { if (!attack_map.ContainsKey(preferred_target) && !units_movable.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_CHASE_WHEN_OUT_OF_ATTACK_RANGE)) { preferred_target = M_Math.GetRandomObject(units_movable); } } if (attack_map.ContainsKey(preferred_target)) { if (units_move_attackable.Contains(preferred_target)) { Tile attack_pos = GetReachableAttackPosition(preferred_target); if (attack_pos != null) { yield return(StartCoroutine(Move(attack_pos))); } else { yield return(StartCoroutine(MoveRandom())); } yield break; } else { Tile Final_Target_Tile = GetBestAttackPosition(preferred_target, attack_map[preferred_target].Select(path => path[path.Count - 1]).ToList()); List <Tile> final_path = TileManager.Instance.FindPath(m_unit.currentTile, Final_Target_Tile, m_unit); Tile target = move.GetFurthestMovibleTileOnPath(final_path); yield return(StartCoroutine(Move(target))); yield break; } } else { yield return(StartCoroutine(MoveRandom( ))); yield break; } } }