|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- using GameClass.GameObj;
- using System.Threading;
- using Preparation.Interface;
- using Preparation.Utility;
- using System;
- using Timothy.FrameRateTask;
-
- namespace Gaming
- {
- public partial class Game
- {
- private partial class SkillManager
- {
- public static bool CanBeginToCharge(Character player)
- {
-
- if ((!player.Commandable())) return false;
- IActiveSkill skill = player.FindIActiveSkill(ActiveSkillType.CanBeginToCharge);
- Debugger.Output(player, "can begin to charge!");
-
-
- return ActiveSkillEffect(skill, player, () =>
- {
- player.AddMoveSpeed(skill.DurationTime, 3.0);
- //See SkillWhenColliding in ActionManager
- },
- () =>
- { });
- }
-
- public bool ShowTime(Character player)
- {
- if ((!player.Commandable())) return false;
- IActiveSkill skill = player.FindIActiveSkill(ActiveSkillType.ShowTime);
-
- return ActiveSkillEffect(skill, player, () =>
- {
- player.AddMoveSpeed(skill.DurationTime, 0.8);
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.Commandable() && gameMap.Timer.IsGaming,
- loopToDo: () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character person in gameMap.GameObjDict[GameObjType.Character])
- {
- if (!person.IsGhost() && player.CharacterType != CharacterType.Robot && !person.NoHp())
- {
- double dis = XY.DistanceFloor3(person.Position, player.Position);
- if (dis >= player.AlertnessRadius)
- {
- person.AddMoveSpeed(GameData.checkIntervalWhenShowTime, dis / player.AlertnessRadius);
- actionManager.MovePlayerWhenStunned(person, GameData.checkIntervalWhenShowTime, (player.Position - person.Position).Angle());
- }
- else if (dis >= player.ViewRange)
- {
- Student student = (Student)person;
- student.GamingAddiction += GameData.checkIntervalWhenShowTime;
- if (student.GamingAddiction == student.MaxGamingAddiction)
- {
- player.AddScore(GameData.TrickerScoreStudentDie);
- characterManager.Die(student);
- }
- }
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- },
- timeInterval: GameData.checkIntervalWhenShowTime,
- finallyReturn: () => 0
- )
-
- .Start();
- }
- )
- { IsBackground = true }.Start();
- },
- () =>
- {
- }
- );
- }
-
- public static bool BecomeInvisible(Character player)
- {
- if ((!player.Commandable())) return false;
- IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.BecomeInvisible);
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- player.AddScore(GameData.ScoreBecomeInvisible);
- player.AddInvisible(activeSkill.DurationTime);
- Debugger.Output(player, "become invisible!");
- },
- () =>
- { });
- }
-
- public bool UseRobot(Character player)
- {
- IGolem? golem = (IGolem?)(((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned);
- if ((!player.Commandable()) || ((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned == null) return false;
- Debugger.Output(player, "use robot!");
- IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.UseRobot);
- activeSkill.IsBeingUsed = (activeSkill.IsBeingUsed) ? false : true;
- if (activeSkill.IsBeingUsed) characterManager.SetPlayerState(player, PlayerStateType.UsingSkill);
- else characterManager.SetPlayerState(player);
- return true;
- }
-
- public static bool JumpyBomb(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.JumpyBomb), player, () =>
- {
- player.BulletOfPlayer = BulletType.BombBomb;
- Debugger.Output(player, "uses jumpybomb!");
- },
- () =>
- { player.BulletOfPlayer = player.OriBulletOfPlayer; });
- }
-
- public bool WriteAnswers(Character player)
- {
- if ((!player.Commandable())) return false;
- IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.WriteAnswers);
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- Generator? generator = (Generator?)gameMap.OneForInteract(player.Position, GameObjType.Generator);
- if (generator != null)
- {
- if (generator.Repair(((WriteAnswers)activeSkill).DegreeOfMeditation, player))
- gameMap.NumOfRepairedGenerators++;
- Debugger.Output(player, "uses WriteAnswers in" + generator.ToString() + "with " + (((WriteAnswers)activeSkill).DegreeOfMeditation).ToString());
- ((WriteAnswers)activeSkill).DegreeOfMeditation = 0;
- }
- },
- () =>
- { });
- }
-
- public bool SummonGolem(Character player)
- {
- if ((!player.Commandable())) return false;
- IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.SummonGolem);
- if (((SummonGolem)activeSkill).GolemSummoned != null) return false;
- XY res = player.Position + new XY(player.FacingDirection, player.Radius * 2);
- if (actionManager.moveEngine.CheckCollision(player, res) != null)
- return false;
- Golem? golem = (Golem?)characterManager.AddPlayer(res, player.TeamID, player.PlayerID + GameData.numOfPeople, CharacterType.Robot, player);
- if (golem == null) return false;
- ((SummonGolem)activeSkill).GolemSummoned = golem;
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- },
- () =>
- { });
- }
-
- public static bool UseKnife(Character player)
- {
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.UseKnife), player, () =>
- {
- player.BulletOfPlayer = BulletType.FlyingKnife;
- Debugger.Output(player, "uses flyingknife!");
- },
- () =>
- { player.BulletOfPlayer = player.OriBulletOfPlayer; });
- }
-
- public bool Howl(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Howl), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if (!character.IsGhost() && !character.NoHp() && XY.DistanceFloor3(character.Position, player.Position) <= player.ViewRange)
- {
- if (characterManager.BeStunned(character, GameData.timeOfStudentStunnedWhenHowl))
- player.AddScore(GameData.TrickerScoreStudentBeStunned(GameData.timeOfStudentStunnedWhenHowl));
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- characterManager.BackSwing(player, GameData.timeOfGhostSwingingAfterHowl);
- Debugger.Output(player, "howled!");
- },
- () =>
- { });
- }
-
- public bool Punish(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Punish), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if (character.IsGhost() &&
- (character.PlayerState == PlayerStateType.TryingToAttack || character.PlayerState == PlayerStateType.Swinging
- || character.PlayerState == PlayerStateType.UsingSkill || character.PlayerState == PlayerStateType.LockingOrOpeningTheDoor || character.PlayerState == PlayerStateType.ClimbingThroughWindows)
- && gameMap.CanSee(player, character))
- {
- if (characterManager.BeStunned(character, GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)))
- player.AddScore(GameData.StudentScoreTrickerBeStunned(GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)));
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "uses punishing!");
- },
- () =>
- { });
- }
-
- public bool Rouse(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Rouse), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
- {
- characterManager.SetPlayerState(character);
- character.HP = GameData.RemainHpWhenAddLife;
- ((Student)character).TimeOfRescue = 0;
- player.AddScore(GameData.StudentScoreRescue);
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "rouse someone!");
- },
- () =>
- { });
- }
-
- public bool Encourage(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Encourage), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if ((character.HP < character.MaxHp) && gameMap.CanSee(player, character))
- {
- player.AddScore(GameData.StudentScoreTreat(GameData.addHpWhenEncourage));
- character.HP += GameData.addHpWhenEncourage;
- ((Student)character).SetDegreeOfTreatment0();
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "encourage someone!");
- },
- () =>
- { });
- }
-
- public bool Inspire(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Inspire), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if (gameMap.CanSee(player, character))
- {
- player.AddScore(GameData.ScoreInspire);
- character.AddMoveSpeed(GameData.timeOfAddingSpeedWhenInspire, GameData.addedTimeOfSpeedWhenInspire);
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "inspires!");
- },
- () =>
- { });
- }
-
- public static bool ActiveSkillEffect(IActiveSkill activeSkill, Character player, Action startSkill, Action endSkill)
- {
- lock (activeSkill.ActiveSkillLock)
- {
- ActiveSkillType activeSkillType = SkillFactory.FindActiveSkillType(activeSkill);
- if (player.TimeUntilActiveSkillAvailable[activeSkillType] == 0)
- {
- player.SetTimeUntilActiveSkillAvailable(activeSkillType, activeSkill.SkillCD);
- new Thread
- (() =>
- {
- startSkill();
- activeSkill.IsBeingUsed = true;
- new FrameRateTaskExecutor<int>(
- () => !player.IsRemoved,
- () =>
- {
- player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
- },
- timeInterval: GameData.frameDuration,
- () => 0,
- maxTotalDuration: (long)(activeSkill.DurationTime)
- )
- {
- AllowTimeExceed = true,
- MaxTolerantTimeExceedCount = ulong.MaxValue,
- }
- .Start();
-
- endSkill();
- activeSkill.IsBeingUsed = false;
- Debugger.Output(player, "return to normal.");
-
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.TimeUntilActiveSkillAvailable[activeSkillType] > 0 && !player.IsRemoved,
- loopToDo: () =>
- {
- player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
- {
- AllowTimeExceed = true,
- MaxTolerantTimeExceedCount = ulong.MaxValue,
- }
- .Start();
-
- player.SetTimeUntilActiveSkillAvailable(activeSkillType, 0);
- Debugger.Output(player, "ActiveSkill is ready.");
- }
- )
- { IsBackground = true }.Start();
-
- return true;
- }
- else
- {
- Debugger.Output(player, "CommonSkill is cooling down!");
- return false;
- }
- }
- }
- }
- }
- }
|