/// <summary> /// 効果範囲が範囲のスキルの対象を決定します /// </summary> /// <returns>対象のキャラクターのリスト</returns> /// <param name="useSkill">使用するスキル</param> private FieldPosition decideHostileAreaTarget(IActiveSkill useSkill) { int range = ActiveSkillSupporter.searchRange(useSkill, user); Dictionary <FieldPosition, int> areaDangerLevelTable = BattleManager.getInstance().getRawAreaDangerLevelTableInRange(user, range); var keys = areaDangerLevelTable.Keys; int sumDangerLevel = 0; foreach (FieldPosition pos in keys) { sumDangerLevel += areaDangerLevelTable[pos]; } //最終判定:レベルが高いところへ int rand = UnityEngine.Random.Range(0, sumDangerLevel); foreach (FieldPosition pos in keys) { if (areaDangerLevelTable[pos] <= rand) { return(pos); } else { rand -= areaDangerLevelTable[pos]; } } throw new InvalidOperationException("cannot decide areaTarget"); }
/// <summary> /// 効果範囲が単体のスキルの対象を決定します /// </summary> /// <returns>対象となったキャラクター</returns> /// <param name="useSkill">使用するスキル</param> private IBattleable decideHostileSingleTarget(IActiveSkill useSkill) { //レベルを合計する int sumLevel = 0; List <IBattleable> hostalityTargets = new List <IBattleable>(); var targets = BattleManager.getInstance().getCharacterInRange(user, ActiveSkillSupporter.searchRange(useSkill, user)); foreach (IBattleable target in targets) { if (target.isHostility(user.getFaction())) { hostalityTargets.Add(target); sumLevel += target.getLevel(); } } //最終判定:計算可能な形式の変数にする Dictionary <int, int> levelTable = new Dictionary <int, int>(); for (int i = 0; i < hostalityTargets.Count; i++) { levelTable.Add(i, hostalityTargets[i].getLevel()); } return(hostalityTargets[MathHelper.getRandomKeyLowerOrderProbality(levelTable)]); throw new InvalidOperationException("Cannot decideHostileSingleTarget."); }
/// <summary> /// skillNodeが選択された時の処理 /// </summary> /// <param name="chosenSkill">選択されたIActiveSkill</param> public void skillChose(IActiveSkill chosenSkill) { this.chosenActiveSkill = chosenSkill; if (ActiveSkillSupporter.isAffectSkill(chosenSkill)) { Extent extent = ActiveSkillSupporter.searchExtent(chosenSkill); int range = ActiveSkillSupporter.searchRange(chosenSkill, player); inputTargetList(extent, range); } else if (chosenSkill.getActiveSkillType() == ActiveSkillType.MOVE) { int move = ActiveSkillSupporter.searchMove(chosenSkill, player); inputMoveAreaList(move); } else { throw new NotSupportedException("Unkonwn skillType"); } }
public IActiveSkill decideSkill() { //ボーナス値のテーブルです。最終的に足されます。 Dictionary <ActiveSkillCategory, int> probalityBonus = new Dictionary <ActiveSkillCategory, int>() { { ActiveSkillCategory.NORMAL, 0 }, { ActiveSkillCategory.CAUTION, 0 }, { ActiveSkillCategory.DANGER, 0 }, { ActiveSkillCategory.POWER, 0 }, { ActiveSkillCategory.FULL_POWER, 0 }, { ActiveSkillCategory.SUPPORT, 0 }, { ActiveSkillCategory.HEAL, 0 }, { ActiveSkillCategory.MOVE, 0 } }; //div0を防ぐための処理 int maxMp = (user.getMaxMp() > 0) ? user.getMaxMp() : 1; //HPが50%以下の場合、caution可能性値を+20します if (this.user.getHp() / maxMp <= 0.5f) { probalityBonus[ActiveSkillCategory.CAUTION] += 20; } //HPが20%以下の場合、danger可能性値を+30します if (this.user.getHp() / maxMp <= 0.2f) { probalityBonus[ActiveSkillCategory.DANGER] += 30; } //HPが70%以下の場合、攻撃する可能性値を-5、移動する可能性を+10します if (this.user.getHp() / maxMp <= 0.7f) { probalityBonus[ActiveSkillCategory.NORMAL] -= 5; probalityBonus[ActiveSkillCategory.POWER] -= 5; probalityBonus[ActiveSkillCategory.FULL_POWER] -= 5; probalityBonus[ActiveSkillCategory.MOVE] += 10; } List <ActiveSkillCategory> categories = new List <ActiveSkillCategory>(probalityBonus.Keys); //スキルの射程内に何もいない、またはコスト外の時、ボーナス値を使って可能性値を0にします。 foreach (ActiveSkillCategory category in categories) { IActiveSkill categorySkill = activeSkills.getSkillFromSkillCategory(category); if (!ActiveSkillSupporter.isAffectSkill(categorySkill)) { continue; } int range = ActiveSkillSupporter.searchRange(categorySkill, user); bool isInRange = BattleManager.getInstance().sumFromAreaTo(user, range) > 0; bool canUse = categorySkill.getCost() <= user.getMp(); if (!isInRange || !canUse) { probalityBonus[category] = -1 * probalityTable[category]; } } //基礎値 + ボーナス値が負の値の場合、可能性値が0になるように設定し直します foreach (ActiveSkillCategory category in categories) { if (probalityTable[category] + probalityBonus[category] < 0) { probalityBonus[category] = -1 * probalityTable[category];; } } //可能性値を合計します int sum = 0; foreach (ActiveSkillCategory category in categories) { sum += probalityTable[category] + probalityBonus[category]; } //合計が0の場合、攻撃不可と判断して移動します if (sum <= 0) { return(activeSkills.getSkillFromSkillCategory(ActiveSkillCategory.MOVE)); } //乱数でスキルを選択します int choose = UnityEngine.Random.Range(0, sum); foreach (ActiveSkillCategory category in categories) { int probality = probalityTable[category] + probalityBonus[category]; if (choose < probality) { return(activeSkills.getSkillFromSkillCategory(category)); } choose -= probalityTable[category] + probalityBonus[category]; } throw new InvalidOperationException("exception state"); }