/// <summary> /// 执行HOT效果 /// </summary> /// <param name="index"></param> public void ExeCountStartState(int index) { foreach (State s in state) { if (s.type != StateType.DamageOverTime && s.type != StateType.HealOverTime) { continue; } string text = string.Format("因为{0}的效果!", s.name); if (s.type == StateType.HealOverTime) { if (s.times == 0 && s.counts == 0) { continue; } if (s.times > 0) { s.times--; } MyDraw.DrawBattleMessage(text); if (!IsForbidHeal()) { GetRecover(s.hprecover, index); } } } }
private void DrawParty() { for (int i = 0; i < heros.Count; i++) { MyDraw.DrawChoiceText(i, heros[i].name, textPos[i]); } }
/// <summary> /// 角色受到伤害 /// </summary> /// <param name="damage"></param> /// <param name="index"></param> /// <returns></returns> public bool GetDamage(int damage, int index) { MyDraw.DrawDamageAnimation(this, index); int tempDamage = 0; if (Hp >= damage) { tempDamage = damage; Hp -= damage; } else { tempDamage = Hp; Hp = 0; } string text = string.Format("{0}受到了{1}点伤害", name, tempDamage); MyDraw.DrawCharacterInfo(this, index); MyDraw.DrawBattleMessageDelay(text); if (!IsAlive()) { if (!IsRevive()) { MyDraw.DrawBattleMessageDelay(name + "死亡了"); ResetState(); } MyDraw.DrawCharacterInfo(this, index); } return(IsAlive()); }
/// <summary> /// 执行DOT效果 /// </summary> /// <param name="index"></param> public void ExeCountEndState(int index) { foreach (State s in state) { if (s.type != StateType.DamageOverTime && s.type != StateType.HealOverTime) { continue; } string text = string.Format("因为{0}的效果!", s.name); if (s.type == StateType.DamageOverTime) { if (s.times == 0 && s.counts == 0) { continue; } if (s.times > 0) { s.times--; } MyDraw.DrawBattleMessage(text); if (!IsInvincible()) { GetDamage(s.damage, index); } } } }
private void DrawSkill() { for (int i = 0; i < heros[actionIndex].skill.Count; i++) { MyDraw.DrawChoiceText(i, heros[actionIndex].skill[i].name, textPos[i]); } }
private void DrawEnemy() { for (int i = 0; i < enemy.Count; i++) { MyDraw.DrawChoiceText(i, enemy[i].name, textPos[i]); } }
/// <summary> /// 玩家的行动部分 /// </summary> private void HerosAction() { //玩家的行动 for (int i = 0; i < heros.Count; i++) { if (heros[i].Hp == 0 || heros[i].IsDizzy()) { continue; } actionIndex = i; textPos.Clear(); SetSkillPos(); DrawSkill(); MyDraw.DrawIntroText("轮到" + heros[actionIndex].name + "行动了,请选择指令:"); tempSkill = heros[actionIndex].skill[GetSkillChoice(heros[actionIndex])]; MyDraw.DrawBattleMessage(heros[actionIndex].name + "选择了技能:" + tempSkill.name); if (tempSkill.targetType == TargetType.EnemySingle) { MyDraw.DrawIntroText("请选择目标:"); SetEnemyPos(); DrawEnemy(); targetEnemy = GetEnemyChoice(); if (targetEnemy == -1) { i--; continue; } tempSkill.UseSkillSingle(heros[actionIndex], actionIndex, enemy[targetEnemy], targetEnemy); } if (tempSkill.targetType == TargetType.EnemyMulti) { tempSkill.UseSkillMulti(heros[actionIndex], actionIndex, enemy); } if (tempSkill.targetType == TargetType.PartySingle) { MyDraw.DrawIntroText("请选择目标:"); SetPartyPos(); DrawParty(); targetEnemy = GetPartyChoice(); if (targetEnemy == -1) { i--; continue; } tempSkill.UseSkillSingle(heros[actionIndex], actionIndex, heros[targetEnemy], targetEnemy); } if (tempSkill.targetType == TargetType.PartyMulti) { tempSkill.UseSkillMulti(heros[actionIndex], actionIndex, heros); } if (tempSkill.targetType == TargetType.Self) { tempSkill.UseSkillSingle(heros[actionIndex], actionIndex, heros[actionIndex], actionIndex); } } }
private void EnemyAction() { for (int i = 0; i < enemy.Count; i++) { if (enemy[i].Hp == 0 || enemy[i].IsDizzy()) { continue; } Skill temp = enemy[i].GetRandomSkill(enemy[i], enemy, counts); if (temp.targetType == TargetType.Self) { temp.UseSkillSingle(enemy[i], i, enemy[i], i); } if (temp.targetType == TargetType.EnemySingle) { int target = GetRandomAttackerTarget(enemy[i], temp, heros); //处理嘲讽状态 for (int j = 0; j < heros.Count; j++) { double tauntRatio = heros[j].IsTaunt(); if (heros[j].Hp > 0 && tauntRatio != -1.0) { if (tauntRatio > Program.random.NextDouble()) { target = j; MyDraw.DrawBattleMessageDelay(string.Format("{0}处于嘲讽状态下,敌人的攻击转了过去。", heros[j].name)); } break; } } temp.UseSkillSingle(enemy[i], i, heros[target], target); } if (temp.targetType == TargetType.EnemyMulti) { temp.UseSkillMulti(enemy[i], i, heros); } if (temp.targetType == TargetType.PartySingle) { int target = 0; if (temp.type == SkillType.Heal) { target = GetHealTarget(temp, enemy); } else { target = GetRandomAttackerTarget(enemy[i], temp, enemy); } temp.UseSkillSingle(enemy[i], i, enemy[target], target); } if (temp.targetType == TargetType.PartyMulti) { temp.UseSkillMulti(enemy[i], i, enemy); } } }
public void DrawBattleField() { for (int i = 0; i < heros.Count; i++) { MyDraw.DrawCharacterInfo(heros[i], i); } for (int j = 0; j < enemy.Count; j++) { MyDraw.DrawCharacterInfo(enemy[j], j); } }
private void SetSkillPos() { textPos.Clear(); int len = 0; for (int i = 0; i < heros[actionIndex].skill.Count; i++) { textPos.Add(len); len += MyDraw.GetLength((1 + i) + "." + heros[actionIndex].skill[i].name + " "); } }
private void SetEnemyPos() { textPos.Clear(); int len = 0; for (int i = 0; i < enemy.Count; i++) { textPos.Add(len); len += MyDraw.GetLength((1 + i) + "." + enemy[i].name + " "); } }
private void SetPartyPos() { textPos.Clear(); int len = 0; for (int i = 0; i < heros.Count; i++) { textPos.Add(len); len += MyDraw.GetLength((1 + i) + "." + heros[i].name + " "); } }
public int GetPartyChoice() { int temp = 0; MyDraw.DrawChoiced(temp, heros[temp].name, textPos[temp]); bool enter = false; while (!enter) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.LeftArrow) { if (temp > 0) { MyDraw.ClearLine(21); MyDraw.DrawChoiceText(temp, heros[temp].name, textPos[temp]); temp = temp - 1; MyDraw.DrawChoiced(temp, heros[temp].name, textPos[temp]); } } else if (key.Key == ConsoleKey.RightArrow) { if (temp < textPos.Count - 1) { MyDraw.ClearLine(21); MyDraw.DrawChoiceText(temp, heros[temp].name, textPos[temp]); temp = temp + 1; MyDraw.DrawChoiced(temp, heros[temp].name, textPos[temp]); } } else if (key.Key == ConsoleKey.Enter) { if (heros[temp].CanBeTarget(tempSkill)) { MyDraw.ClearChoiceText(); break; } else { MyDraw.DrawBattleMessage("无法选择已经死亡的目标,请重新选择"); } } else if (key.Key == ConsoleKey.Escape) { MyDraw.ClearLine(1); return(-1); } } return(temp); }
private bool IsOver() { if (IsAllDead(enemy)) { MyDraw.DrawBattleMessage("敌人全灭,玩家胜利!"); return(true); } if (IsAllDead(heros)) { MyDraw.DrawBattleMessage("玩家全灭,战斗失败!"); return(true); } return(false); }
/// <summary> /// 移除一个状态 /// </summary> /// <param name="s"></param> public void RemoveState(State s) { int i = 0; for (; i < state.Count; i++) { if (state[i].name == s.name && state[i].skillName == s.skillName) { state[i]?.RemoveState(this); state.RemoveAt(i); MyDraw.DrawBattleMessageDelay(name + "失去了" + s.name + "状态"); break; } } }
/// <summary> /// 判断角色是否能够释放技能 /// </summary> /// <param name="attacker"></param> /// <returns></returns> public bool CanUseSkill(BaseCharacter attacker) { //判断角色是否有足够的资源释放技能 if (attacker.Hp <= hpCost || attacker.Mp < mpCost) { MyDraw.DrawBattleMessage("消耗不足,无法使用技能!"); return(false); } //判断角色是否被禁用了技能 if (attacker.IsSilence() && type != SkillType.NormalAttack) { MyDraw.DrawBattleMessage(attacker.name + "被沉默了,无法使用技能!"); return(false); } return(true); }
/// <summary> /// 群体技能的释放逻辑,因为有单次技能伤害加成状态的原因,需要在技能结束后多做一次判断 /// </summary> /// <param name="attacker"></param> /// <param name="att_index"></param> /// <param name="targets"></param> public void UseSkillMulti(BaseCharacter attacker, int att_index, List <BaseCharacter> targets) { //消耗位置放在这里放置全体技能多次扣除技能消耗 attacker.Hp -= hpCost; attacker.Mp -= mpCost; for (int i = 0; i < targets.Count; i++) { if (attacker.Hp == 0) { return; } if (targets[i].Hp == 0 && canDeath == false) { continue; } UseSkill(attacker, att_index, targets[i], i); } if (type == SkillType.Damage) { if (skillDamage != null) { if (damageType == DamageType.Magic) { attacker.IncreaseStateDec(StateType.MagicDamageIncrease); foreach (var t in targets) { t.IncreaseStateDec(StateType.MagicBeDamageIncrease); } } else if (damageType == DamageType.Physical) { attacker.IncreaseStateDec(StateType.PhysicalDamageIncrease); foreach (var t in targets) { t.IncreaseStateDec(StateType.PhysicalBeDamageIncrease); } } } } MyDraw.DrawState(attacker, att_index); for (int i = 0; i < targets.Count; i++) { MyDraw.DrawState(targets[i], i); } }
/// <summary> /// 添加一个状态 /// </summary> /// <param name="s"></param> public void AddState(State s) { int i = 0; for (; i < state.Count; i++) { if (state[i].name == s.name && state[i].skillName == s.skillName) { state[i].times = s.times; state[i].counts = s.counts; MyDraw.DrawBattleMessageDelay(name + "的" + s.name + "状态持续时间延长!"); return; } } s.AddState?.Invoke(this); state.Add(s); MyDraw.DrawBattleMessageDelay(name + "获得了" + s.name + "状态"); }
/// <summary> /// 清理角色的状态栏,将次数和回合数为一的状态删除 /// </summary> public void CleanUpState() { List <int> list = new List <int>(); for (int i = state.Count - 1; i >= 0; i--) { if (state[i].counts == 0 && state[i].times == 0) { list.Add(i); } } for (int i = 0; i < list.Count; i++) { string text = string.Format("{0}失去了{1}状态", name, state[list[i]].name); MyDraw.DrawBattleMessageDelay(text); state.RemoveAt(list[i]); } }
public int GetSkillChoice(BaseCharacter b) { int temp = 0; MyDraw.DrawChoiced(temp, b.skill[temp].name, textPos[temp]); MyDraw.DrawChoiceInfo(b.skill[temp]); bool enter = false; while (!enter) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.LeftArrow) { if (temp > 0) { MyDraw.ClearLine(21); MyDraw.DrawChoiceText(temp, b.skill[temp].name, textPos[temp]); temp = temp - 1; MyDraw.DrawChoiced(temp, b.skill[temp].name, textPos[temp]); MyDraw.DrawChoiceInfo(b.skill[temp]); } } else if (key.Key == ConsoleKey.RightArrow) { if (temp < textPos.Count - 1) { MyDraw.ClearLine(21); MyDraw.DrawChoiceText(temp, b.skill[temp].name, textPos[temp]); temp = temp + 1; MyDraw.DrawChoiced(temp, b.skill[temp].name, textPos[temp]); MyDraw.DrawChoiceInfo(b.skill[temp]); } } else if (key.Key == ConsoleKey.Enter) { if (b.skill[temp].CanUseSkill(b)) { MyDraw.ClearChoiceText(); break; } } } return(temp); }
/// <summary> /// 角色受到的恢复量 /// </summary> /// <param name="recover"></param> /// <param name="index"></param> public void GetRecover(int recover, int index) { MyDraw.DrawEffectAnimation(this, index); int tempRecover = 0; if (maxHp <= recover + Hp) { tempRecover = maxHp - Hp; Hp = maxHp; } else { tempRecover = recover; Hp += tempRecover; } string text = string.Format("{0}恢复了{1}点生命值", name, tempRecover); MyDraw.DrawCharacterInfo(this, index); MyDraw.DrawBattleMessageDelay(text); }
public void BattleStart() { while (true) { actionIndex = 0; targetEnemy = 0; MyDraw.DrawCounts(counts); ExeCountStartState(); HerosAction(); EnemyAction(); ExeCountEndState(); StateCountDec(); if (IsOver()) { break; } counts++; ClearUpState(); MyDraw.DrawIntroText("按任意键进入下一回合"); Console.ReadKey(true); } }
/// <summary> /// 判断角色是否禁止生命恢复 /// </summary> /// <returns></returns> public bool IsForbidHeal() { bool temp = false; foreach (State s in state) { if (s.type == StateType.ForbidHeal) { MyDraw.DrawBattleMessageDelay(name + "处于" + s.name + "状态中,无法恢复生命值!"); if (s.times > 0) { s.times -= 1; } temp = true; } } if (temp) { CleanUpState(); } return(temp); }
/// <summary> /// 判断角色是否具有无敌状态 /// </summary> /// <returns></returns> public bool IsInvincible() { bool temp = false; foreach (State s in state) { if (s.type == StateType.Invincible) { MyDraw.DrawBattleMessageDelay(name + "处于无敌状态中,伤害无效!"); if (s.times > 0) { s.times -= 1; } temp = true; } } if (temp) { CleanUpState(); } return(temp); }
/// <summary> /// 判断角色是否被沉默 /// </summary> /// <returns></returns> public bool IsSilence() { bool temp = false; foreach (State s in state) { if (s.type == StateType.Silence) { MyDraw.DrawBattleMessageDelay(name + "处于沉默状态中,无法释放技能!"); if (s.times > 0) { s.times -= 1; } temp = true; } } if (temp) { CleanUpState(); } return(temp); }
/// <summary> /// 判断角色是否具有魔法反射 /// </summary> /// <returns></returns> public bool IsMagicReflect() { bool temp = false; foreach (State s in state) { if (s.type == StateType.MagicReflect) { MyDraw.DrawBattleMessageDelay(name + "处于魔法反射状态中,魔法被弹了回来"); if (s.times > 0) { s.times -= 1; } temp = true; } } if (temp) { CleanUpState(); } return(temp); }
/// <summary> /// 判断角色是否具有复活状态 /// </summary> /// <returns></returns> public bool IsRevive() { bool temp = false; foreach (State s in state) { if (s.type == StateType.Revive) { MyDraw.DrawBattleMessageDelay(name + "处于复活状态中,重新站了起来!"); Hp = s.hprecover; if (s.times > 0) { s.times -= 1; } temp = true; } } if (temp) { CleanUpState(); } return(temp); }
/// <summary> /// 单体技能的释放逻辑,因为有单次技能伤害加成状态的原因,需要在技能结束后多做一次判断 /// </summary> /// <param name="attacker"></param> /// <param name="att_index"></param> /// <param name="target"></param> /// <param name="tar_index"></param> public void UseSkillSingle(BaseCharacter attacker, int att_index, BaseCharacter target, int tar_index) { attacker.Hp -= hpCost; attacker.Mp -= mpCost; UseSkill(attacker, att_index, target, tar_index); if (type == SkillType.Damage) { if (skillDamage != null) { if (damageType == DamageType.Magic) { attacker.IncreaseStateDec(StateType.MagicDamageIncrease); target.IncreaseStateDec(StateType.MagicBeDamageIncrease); } else if (damageType == DamageType.Physical) { attacker.IncreaseStateDec(StateType.PhysicalDamageIncrease); target.IncreaseStateDec(StateType.PhysicalBeDamageIncrease); } } } MyDraw.DrawState(attacker, att_index); MyDraw.DrawState(target, tar_index); }
/// <summary> /// 创建角色艾露露,治疗 /// </summary> /// <returns></returns> public static BaseCharacter CreateCharEruruu() { BaseCharacter eruruu = new BaseCharacter(); eruruu.name = "艾露露"; eruruu.maxHp = 288; eruruu.maxMp = 321; eruruu.Hp = 288; eruruu.Mp = 321; eruruu.atk = 0; eruruu.def = 17; eruruu.mat = 23; eruruu.men = 27; eruruu.hit = 95; eruruu.crt = 10; eruruu.level = 5; eruruu.type = CharacterType.Hero; Skill herb = CreateHealSkill("草药", 0, 15, 1, 10, TargetType.PartySingle); herb.description = "艾露露自制的草药,恢复己方单体生命值。(MP:15)"; herb.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { return(attacker.men * 2); }; eruruu.skill.Add(herb); Skill rest = CreateStateSkill("摩洛洛粥", 0, 0, TargetType.Self); rest.description = "艾露露为自己准备的家乡的小食,恢复自身的MP值。"; rest.skillEffect = (BaseCharacter attacker, BaseCharacter target) => { int temp = Convert.ToInt32(attacker.men * 1.34); if (attacker.Mp + temp > attacker.maxMp) { temp = attacker.maxMp - attacker.Mp; } attacker.Mp += temp; MyDraw.DrawCharacterInfo(eruruu, 1); MyDraw.DrawBattleMessageDelay(string.Format("艾露露恢复了{0}点魔法值", temp)); }; eruruu.skill.Add(rest); Skill lilac = CreateHealSkill("花语", 0, 40, 1, 0, TargetType.PartyMulti); lilac.description = "艾露露利用山野中的鲜花特质的线香,为己方全体施加生命恢复效果。(MP:40)"; lilac.skillEffect = (BaseCharacter attacker, BaseCharacter target) => { int tempRecover = Convert.ToInt32(attacker.men * 3.0 / 2); State lilacState = CreateHOTState("花语", 0, 3, tempRecover); lilacState.skillName = lilac.name; target.AddState(lilacState); }; eruruu.skill.Add(lilac); Skill mandara = CreateDamageSkill("毒雾", 0, 30, 1, 0, TargetType.EnemyMulti, DamageType.Magic); mandara.description = "艾露露利用山中的毒草制成的迷雾攻击敌方全体,一定概率使得敌方中毒。(MP:30)"; mandara.skillEffect = (BaseCharacter attacker, BaseCharacter target) => { int tempRecover = Convert.ToInt32(target.maxHp * 0.07); if (Program.random.Next(0, 100) > 70) { State mandaraState = CreateDOTState("中毒", 0, 3, tempRecover); mandaraState.skillName = mandara.name; target.AddState(mandaraState); } }; eruruu.skill.Add(mandara); Skill callBack = CreateHealSkill("复活", 0, 50, 1, 10, TargetType.PartySingle); callBack.description = "艾露露利用流传下来的秘药,复活一名已经阵亡的队友。(MP:50)"; callBack.canDeath = true; callBack.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { return(Convert.ToInt32(target.maxHp * 0.3)); }; eruruu.skill.Add(callBack); Skill lifeLoop = CreateHealSkill("子守歌", 0, 60, 1, 20, TargetType.PartyMulti); lifeLoop.description = "艾露露唱起小时候听过的子守歌,恢复己方全体的生命值。(MP:60)"; lifeLoop.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { return(Convert.ToInt32(attacker.mat * 2.3 + 16)); }; eruruu.skill.Add(lifeLoop); return(eruruu); }
/// <summary> /// 创建角色玲,魔法师 /// </summary> /// <returns></returns> public static BaseCharacter CreateCharRenne() { BaseCharacter renne = new BaseCharacter(); renne.name = "玲"; renne.maxHp = 267; renne.maxMp = 352; renne.Hp = 267; renne.Mp = 352; renne.atk = 10; renne.def = 14; renne.mat = 32; renne.men = 23; renne.hit = 90; renne.crt = 5; renne.level = 5; renne.type = CharacterType.Hero; Skill normalAttack = CreateAttackSkill(1, 10, DamageType.Magic, TargetType.EnemySingle); normalAttack.description = "普通攻击,魔法伤害。"; normalAttack.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { int temp = attacker.mat * 2 - target.men; return(temp > 0 ? temp : 1); }; renne.skill.Add(normalAttack); Skill stone = CreateStateSkill("石化光线", 0, 20, TargetType.EnemySingle); stone.description = "召唤帕蒂尔·玛蒂尔释放石化光线,有70%的概率使敌人进入石化状态3回合。(MP:20)"; stone.skillEffect = (BaseCharacter attacker, BaseCharacter target) => { if (Program.random.Next(0, 100) > 70) { return; } MyDraw.DrawBattleMessageDelay("触发了石化效果!"); State dizzy = CreateSpecialState("石化", 0, 3); dizzy.type = StateType.Dizzy; dizzy.skillName = stone.name; target.AddState(dizzy); State damageDec = CreateIncOrDecState("物理抗性提升", 0, 3, -0.5); damageDec.type = StateType.PhysicalBeDamageIncrease; damageDec.skillName = stone.name; target.AddState(damageDec); }; renne.skill.Add(stone); Skill renneKill = CreateDamageSkill("玲·歼灭", 20, 40, 1, 15, TargetType.EnemyMulti, DamageType.Magic); renneKill.description = "玲挥动收割敌人的生命,对敌方全体造成伤害并且低概率即死。(HP:20,MP:40)"; renneKill.isDeathNow = true; renneKill.deathRatio = 15; renneKill.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { int temp = Convert.ToInt32(attacker.mat * 1.67); return(temp); }; renne.skill.Add(renneKill); Skill silence = CreateDamageSkill("天国之门", 0, 32, 1, 13, TargetType.EnemySingle, DamageType.Magic); silence.description = "开启天国之门,对单个敌人造成魔法伤害并且必定沉默。(MP:32)"; silence.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { int temp = Convert.ToInt32(attacker.mat * 2.44 - target.men * 0.83); return(temp); }; silence.skillEffect = (BaseCharacter attacker, BaseCharacter target) => { State silenceState = CreateSpecialState("沉默", 0, 3); silenceState.skillName = silence.name; silenceState.type = StateType.Silence; target.AddState(silenceState); }; renne.skill.Add(silence); Skill PatelMattel = CreateDamageSkill("帕蒂尔·玛蒂尔", 0, 83, 3, 10, TargetType.EnemyMulti, DamageType.Magic); PatelMattel.description = "帕蒂尔·玛蒂尔用加农炮轰击前方的全体敌人,血量越低伤害越高。(MP:83)"; PatelMattel.skillDamage = (BaseCharacter attacker, BaseCharacter target) => { int temp = Convert.ToInt32((attacker.mat * 2.5 - target.men * 0.6) * (2 - target.Hp * 1.0 / target.maxHp)); return(temp); }; renne.skill.Add(PatelMattel); return(renne); }