|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- 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;
- ActiveSkill skill = player.FindActiveSkill(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;
- ActiveSkill skill = player.FindActiveSkill(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() && person.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)
- {
- characterManager.Die(student);
- }
- }
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- },
- timeInterval: GameData.checkIntervalWhenShowTime,
- maxTotalDuration: skill.DurationTime,
- finallyReturn: () => 0
- )
-
- .Start();
- }
- )
- { IsBackground = true }.Start();
- },
- () =>
- {
- }
- );
- }
-
- public static bool BecomeInvisible(Character player)
- {
- ActiveSkill activeSkill = player.FindActiveSkill(ActiveSkillType.BecomeInvisible);
- long stateNum = player.SetPlayerState(RunningStateType.RunningForcibly, PlayerStateType.UsingSkill);
- if (stateNum == -1)
- {
- return false;
- }
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- player.AddScore(GameData.ScoreBecomeInvisible);
- player.AddInvisible(activeSkill.DurationTime);
- Debugger.Output(player, "become invisible!");
- },
- () =>
- {
- player.ResetPlayerState(stateNum);
- }
- );
- }
-
- public static bool UseRobot(Character player, int robotID)
- {
- if ((robotID - player.PlayerID) % GameData.numOfPeople != 0) return false;
- if ((robotID - (int)player.PlayerID) / GameData.numOfPeople < 0 || (robotID - (int)player.PlayerID) / GameData.numOfPeople > GameData.maxSummonedGolemNum) return false;
- UseRobot activeSkill = (UseRobot)player.FindActiveSkill(ActiveSkillType.UseRobot);
- lock (activeSkill.ActiveSkillUseLock)
- {
- if (robotID == player.PlayerID)
- {
- lock (player.ActionLock)
- {
- if (player.PlayerState == PlayerStateType.UsingSkill && player.WhatInteractingWith == null)
- player.SetPlayerStateNaturally();
- activeSkill.NowPlayerID = robotID;
- }
- }
- else
- {
- SummonGolem summonGolemSkill = (SummonGolem)player.FindActiveSkill(ActiveSkillType.SummonGolem);
- if (summonGolemSkill.GolemStateArray[(robotID - (int)player.PlayerID) / GameData.numOfPeople - 1] == 2)
- {
- activeSkill.NowPlayerID = robotID;
- }
- else return false;
- long stateNum = player.SetPlayerState(RunningStateType.RunningForcibly, PlayerStateType.UsingSkill);
- if (stateNum == -1)
- {
- activeSkill.NowPlayerID = (int)player.PlayerID;
- return false;
- }
- }
- return ActiveSkillEffect(activeSkill, player, () => { }, () => { });
- }
- }
-
- public static bool JumpyBomb(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.JumpyBomb), player, () =>
- {
- player.BulletOfPlayer = BulletType.BombBomb;
- Debugger.Output(player, "uses jumpybomb!");
- },
- () =>
- { player.BulletOfPlayer = player.OriBulletOfPlayer; });
- }
-
- public bool SparksNSplash(Character player, int AttackID)
- {
- Character? whoAttacked = gameMap.FindPlayer(AttackID);
- if (whoAttacked == null || whoAttacked.NoHp()) return false;
- ActiveSkill activeSkill = player.FindActiveSkill(ActiveSkillType.SparksNSplash);
-
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- new Thread
- (
- () =>
- {
- Bullet? homingMissile = null;
- double dis;
- new FrameRateTaskExecutor<int>(
- loopCondition: () => gameMap.Timer.IsGaming && !whoAttacked.NoHp(),
- loopToDo: () =>
- {
- dis = ((homingMissile == null || homingMissile.IsRemoved) ? double.MaxValue : XY.DistanceFloor3(homingMissile.Position, whoAttacked.Position));
- gameMap.GameObjLockDict[GameObjType.Bullet].EnterReadLock();
- try
- {
- foreach (Bullet bullet in gameMap.GameObjDict[GameObjType.Bullet])
- {
- if (!bullet.CanMove && XY.DistanceFloor3(bullet.Position, whoAttacked.Position) < dis && bullet.TypeOfBullet == BulletType.JumpyDumpty)
- {
- homingMissile = bullet;
- dis = XY.DistanceFloor3(bullet.Position, whoAttacked.Position);
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Bullet].ExitReadLock();
- }
- if (homingMissile != null)
- {
- homingMissile.ReSetCanMove(true);
- attackManager.moveEngine.MoveObj(homingMissile, GameData.checkIntervalWhenSparksNSplash - 1, (whoAttacked.Position - homingMissile.Position).Angle(), ++homingMissile.StateNum);
- }
- },
- timeInterval: GameData.checkIntervalWhenSparksNSplash,
- maxTotalDuration: activeSkill.DurationTime,
- finallyReturn: () => 0
- )
-
- .Start();
- }
- )
- { IsBackground = true }.Start();
- Debugger.Output(player, "uses sparks n splash!");
- },
- () =>
- { });
- }
-
- public bool WriteAnswers(Character player)
- {
- if ((!player.Commandable())) return false;
- ActiveSkill activeSkill = player.FindActiveSkill(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.AddNumOfRepairedGenerators();
- Debugger.Output(player, "uses WriteAnswers in" + generator.ToString() + "with " + (((WriteAnswers)activeSkill).DegreeOfMeditation).ToString());
- ((WriteAnswers)activeSkill).DegreeOfMeditation = 0;
- }
- },
- () =>
- { });
- }
-
- public bool SummonGolem(Character player)
- {
- ActiveSkill activeSkill = player.FindActiveSkill(ActiveSkillType.SummonGolem);
- int num = ((SummonGolem)activeSkill).BuildGolem();
- if (num >= GameData.maxSummonedGolemNum) return false;
-
- XY res = player.Position + new XY(player.FacingDirection, player.Radius * 2);
- lock (activeSkill.ActiveSkillUseLock)
- {
- CraftingBench craftingBench = new(res, player, num);
-
- long stateNum = player.SetPlayerState(RunningStateType.Waiting, PlayerStateType.UsingSkill, craftingBench);
- if (stateNum == -1)
- {
- ((SummonGolem)activeSkill).DeleteGolem(num);
- return false;
- }
-
-
- return ActiveSkillEffect(activeSkill, player, () =>
- {
- player.ThreadNum.WaitOne();
- if (!player.StartThread(stateNum, RunningStateType.RunningSleepily))
- {
- ((SummonGolem)activeSkill).DeleteGolem(num);
- player.ThreadNum.Release();
- }
- else
- {
- if (actionManager.moveEngine.CheckCollision(craftingBench, res) != null)
- {
- ((SummonGolem)activeSkill).DeleteGolem(num);
- if (player.ResetPlayerState(stateNum))
- player.ThreadNum.Release();
- }
- else
- {
- craftingBench.ParentStateNum = stateNum;
- gameMap.Add(craftingBench);
- }
- }
- },
- () =>
- {
- if (player.ResetPlayerState(stateNum))
- {
- gameMap.RemoveJustFromMap(craftingBench);
- Golem? golem = (Golem?)characterManager.AddPlayer(res, player.TeamID, (num + 1) * GameData.numOfPeople + player.PlayerID, CharacterType.Robot, player);
- if (golem == null)
- {
- ((SummonGolem)activeSkill).AddGolem(num);
- }
- player.ThreadNum.Release();
- }
- }
- );
- }
- }
-
- public static bool UseKnife(Character player)
- {
- return ActiveSkillEffect(player.FindActiveSkill(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.FindActiveSkill(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) > 0)
- 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.FindActiveSkill(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.LockingTheDoor || character.PlayerState == PlayerStateType.OpeningTheDoor
- || character.PlayerState == PlayerStateType.ClimbingThroughWindows)
- && XY.DistanceFloor3(character.Position, player.Position) <= player.ViewRange / 3)
- {
- int stunTime = (GameData.timeOfGhostStunnedWhenPunish + (int)((GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP) / GameData.basicApOfGhost))) / characterManager.FactorTeacher;
- if (CharacterManager.BeStunned(character, stunTime) > 0)
- player.AddScore(GameData.StudentScoreTrickerBeStunned(stunTime) / characterManager.FactorTeacher);
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "uses punishing!");
- },
- () =>
- { });
- }
-
- public bool HaveTea(Character player, int angle1000)
- {
- long stateNum = player.SetPlayerState(RunningStateType.Waiting, PlayerStateType.UsingSkill);
- if (stateNum == -1)
- {
- return false;
- }
-
- return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.HaveTea), player, () =>
- {
- player.ThreadNum.WaitOne();
-
- XY res = player.Position + new XY(angle1000 / 1000.0, GameData.distanceOfHaveTea);
- if (!player.StartThread(stateNum, RunningStateType.RunningActively))
- {
- player.ThreadNum.Release();
- }
- else
- {
- if (actionManager.moveEngine.CheckCollision(player, res) != null)
- {
- player.ThreadNum.Release();
- }
- else
- {
- Debugger.Output("NO Collision!");
- player.ReSetPos(res);
- player.ThreadNum.Release();
- player.ResetPlayerState(stateNum);
- Debugger.Output(player, "have tea!");
- }
- }
- },
- () =>
- { });
- }
-
- public bool Rouse(Character player)
- {
- if ((!player.Commandable())) return false;
- return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.Rouse), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- lock (character.ActionLock)
- {
- if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
- {
- character.SetPlayerStateNaturally();
- character.HP = GameData.RemainHpWhenAddLife;
- ((Student)character).SetTimeOfRescue(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.FindActiveSkill(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.FindActiveSkill(ActiveSkillType.Inspire), player, () =>
- {
- gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
- try
- {
- foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
- {
- if (gameMap.CanSee(player, character) && !character.IsGhost())
- {
- player.AddScore(GameData.ScoreInspire);
- character.AddMoveSpeed(GameData.timeOfAddingSpeedWhenInspire, GameData.addedTimeOfSpeedWhenInspire);
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
- }
- Debugger.Output(player, "inspires!");
- },
- () =>
- { });
- }
-
- public static bool ActiveSkillEffect(ActiveSkill activeSkill, Character player, Action startSkill, Action endSkill)
- {
- lock (activeSkill.ActiveSkillUseLock)
- {
- if (activeSkill.TimeUntilActiveSkillAvailable == 0)
- {
- activeSkill.TimeUntilActiveSkillAvailable = activeSkill.SkillCD;
-
- new Thread
- (() =>
- {
- startSkill();
- activeSkill.IsBeingUsed = 1;
- new FrameRateTaskExecutor<int>(
- () => !player.IsRemoved,
- () =>
- {
- activeSkill.TimeUntilActiveSkillAvailable -= (int)GameData.frameDuration;
- },
- timeInterval: GameData.frameDuration,
- () => 0,
- maxTotalDuration: (long)(activeSkill.DurationTime)
- )
- {
- AllowTimeExceed = true,
- MaxTolerantTimeExceedCount = ulong.MaxValue,
- }
- .Start();
-
- endSkill();
- activeSkill.IsBeingUsed = 0;
- Debugger.Output(player, "return to normal.");
-
- new FrameRateTaskExecutor<int>(
- loopCondition: () => activeSkill.TimeUntilActiveSkillAvailable > 0,
- loopToDo: () =>
- {
- activeSkill.TimeUntilActiveSkillAvailable -= (int)GameData.frameDuration;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
- {
- AllowTimeExceed = true,
- MaxTolerantTimeExceedCount = ulong.MaxValue,
- }
- .Start();
-
- activeSkill.TimeUntilActiveSkillAvailable = 0;
- Debugger.Output(player, "ActiveSkill is ready.");
- }
- )
- { IsBackground = true }.Start();
-
- return true;
- }
- else
- {
- Debugger.Output(player, "CommonSkill is cooling down!");
- return false;
- }
- }
- }
- }
- }
- }
|