using System; using System.Threading; using GameClass.GameObj; using Preparation.Interface; using Preparation.Utility; using Timothy.FrameRateTask; namespace GameClass.Skill // 被动技能开局时就释放,持续到游戏结束 { public class RecoverAfterBattle : IPassiveSkill // 脱战回血,普通子弹 { public void SkillEffect(Map map, Character player) { const int recoverDegree = 5; // 每帧回复血量 int nowHP = player.HP; int lastHP = nowHP; long waitTime = 0; const long interval = 10000; // 每隔interval时间不受伤害,角色即开始回血 new Thread ( () => { new FrameRateTaskExecutor ( () => true, () => { lastHP = nowHP; // lastHP等于上一帧的HP nowHP = player.HP; // nowHP更新为这一帧的HP if (lastHP > nowHP) // 这一帧扣血了 { waitTime = 0; } else if (waitTime < interval) { waitTime += GameData.frameDuration; } if (waitTime >= interval) // 回复时,每帧(50ms)回复5,即1s回复100。 player.TryAddHp(recoverDegree); }, timeInterval: GameData.frameDuration, () => 0, maxTotalDuration: GameData.gameDuration ) { AllowTimeExceed = true, MaxTolerantTimeExceedCount = ulong.MaxValue, TimeExceedAction = b => { if (b) Console.WriteLine("Fetal Error: The computer runs so slow that passive skill time exceeds!!!!!!"); #if DEBUG else { Console.WriteLine("Debug info: passive skill time exceeds for once."); } #endif } }.Start(); } ) { IsBackground = true }.Start(); } } public class SpeedUpWhenLeavingGrass : IPassiveSkill // 3倍速 { public void SkillEffect(Map map, Character player) { PlaceType nowPlace = map.GetPlaceType(player.Position); PlaceType lastPlace = nowPlace; bool speedup = false; const int SpeedUpTime = 2000; // 加速时间:2s new Thread ( () => { new FrameRateTaskExecutor ( () => true, () => { lastPlace = nowPlace; nowPlace = map.GetPlaceType(player.Position); if ((lastPlace == PlaceType.Grass) && nowPlace == PlaceType.Null) { if (!speedup) { new Thread(() => { speedup = true; player.AddMoveSpeed(SpeedUpTime, 3.0); speedup = false; }) { IsBackground = true }.Start(); } } }, timeInterval: GameData.frameDuration, () => 0, maxTotalDuration: GameData.gameDuration ) { AllowTimeExceed = true, MaxTolerantTimeExceedCount = ulong.MaxValue, TimeExceedAction = b => { if (b) Console.WriteLine("Fetal Error: The computer runs so slow that passive skill time exceeds!!!!!!"); #if DEBUG else { Console.WriteLine("Debug info: passive skill time exceeds for once."); } #endif } }.Start(); } ) { IsBackground = true }.Start(); } } public class Vampire : IPassiveSkill // 被动就是吸血,普通子弹 { public void SkillEffect(Map map, Character player) { player.OriVampire = 0.5; player.Vampire = player.OriVampire; } } public class NoPassiveSkill : IPassiveSkill // 没技能,这种情况不应该发生,先定义着以防意外 { public void SkillEffect(Map map, Character player) { } } public static class PassiveSkillFactory { public static IPassiveSkill? FindIPassiveSkill(PassiveSkillType passiveSkillType) { switch (passiveSkillType) { default: return null; } } public static PassiveSkillType FindpassiveSkillType(IPassiveSkill passiveSkill) { switch (passiveSkill) { default: return PassiveSkillType.Null; } } } }