/// <summary> /// スキル効果範囲(Extent)がSINGLEの時の対象を決定します /// </summary> /// <returns>対象のリスト</returns> /// <param name="useSkill">使用するスキル</param> private IBattleable decideBufSingleTarget(BufSkill useSkill) { //keyに選択可能性、要素にIBattleable本体を持つリスト Dictionary <int, IBattleable> targetsAndProbality = new Dictionary <int, IBattleable>(); int sumFriendlyLevel = 0; var targets = BattleManager.getInstance().getCharacterInRange(user, useSkill.getRange()); foreach (IBattleable target in targets) { if (!target.isHostility(user.getFaction())) { Debug.Log("into hos"); //レベルが高いほど選択可能性が高い targetsAndProbality.Add(target.getLevel(), target); sumFriendlyLevel += target.getLevel(); Debug.Log("sum " + sumFriendlyLevel + "lv " + target.getLevel()); } } //乱数判定 int random = UnityEngine.Random.Range(0, sumFriendlyLevel); Debug.Log("rand " + random); var probalities = targetsAndProbality.Keys; foreach (int probality in probalities) { if (probality >= random) { return(targetsAndProbality[probality]); } else { random -= probality; } } throw new InvalidOperationException("cannot decide singleBufTarget"); }
/// <summary> /// BufSkillの効果範囲(Extent)がAREAの時の対象を決定します /// </summary> /// <returns>対象のリスト</returns> /// <param name="useSkill">使用するスキル</param> private FieldPosition decideAreaBufTarget(BufSkill useSkill) { //エリアの友軍 Dictionary <FieldPosition, List <IBattleable> > areaFriendlyCharacter = new Dictionary <FieldPosition, List <IBattleable> >(); //エリアの選択可能性 Dictionary <FieldPosition, int> areaProbality = new Dictionary <FieldPosition, int>(); //レベルの合計 int levelSum = 0; //現在のpos FieldPosition nowPos = BattleManager.getInstance().searchCharacter(user); //ループ変数の設定 int fieldPosMax = Enum.GetNames(typeof(FieldPosition)).Length; int index = BattleManager.getInstance().restructionPositionValue(nowPos, -1 * useSkill.getRange()); int maxIndex = BattleManager.getInstance().restructionPositionValue(nowPos, useSkill.getRange()); //エリアの友軍の合計レベルが高いほど可能性が高くなる for (; index <= maxIndex; index++) { int areaFriendlyLevelSum = 0; areaFriendlyCharacter.Add((FieldPosition)index, new List <IBattleable>()); foreach (IBattleable target in BattleManager.getInstance().getAreaCharacter((FieldPosition)index)) { if (!target.isHostility(user.getFaction())) { areaFriendlyCharacter[(FieldPosition)index].Add(target); areaFriendlyLevelSum += target.getLevel(); } } areaProbality.Add((FieldPosition)index, areaFriendlyLevelSum); levelSum += areaFriendlyLevelSum; } //乱数判定 int rand = UnityEngine.Random.Range(0, levelSum); var probalistyKeys = areaProbality.Keys; foreach (FieldPosition pos in probalistyKeys) { if (areaProbality[pos] > rand) { return(pos); } else { rand -= areaProbality[pos]; } } throw new InvalidOperationException("cannot decide areaTarget"); }