public void TestEntityContinuousAttackBasedOnAttackSpeed() { var now = GameThread.TIME_MS_NOW; _client.RecievedPackets.Clear(); var player = Server.GetPlayer(_player.UserId); var playerAtkSpeed = player.AtkSpeed; var playerAtkSpeedDelay = Formulas.GetTimeBetweenAttacks(playerAtkSpeed); _client.SendToServer(new EntityTargetPacket() { WhoUuid = _player.UserId, TargetUuid = _monster.UID }); Assert.AreEqual(player.NextAttackAt, now + playerAtkSpeedDelay); GameThread.TIME_MS_NOW = now + playerAtkSpeedDelay; GameScheduler.RunTasks(now + playerAtkSpeedDelay); GameThread.TIME_MS_NOW = now + (playerAtkSpeedDelay * 2); GameScheduler.RunTasks(now + (playerAtkSpeedDelay * 2)); GameThread.TIME_MS_NOW = now + (playerAtkSpeedDelay * 3); GameScheduler.RunTasks(now + (playerAtkSpeedDelay * 3)); var attackPackets = _client.RecievedPackets .Where(p => p.GetType() == typeof(EntityAttackPacket)) .Select(p => (EntityAttackPacket)p) .Where(p => p.AttackerUID == _player.UserId) .ToList(); Assert.AreEqual(attackPackets.Count, 4); }
public void TestMultipleMoves() { var date = DateTime.MinValue; GameScheduler.SetLogicalTime(date); var tile = _party.Tile; var next1 = tile.GetNeighbor(Direction.SOUTH); var next2 = next1.GetNeighbor(Direction.SOUTH); var next3 = next2.GetNeighbor(Direction.SOUTH); _path.Add(new Position(next1.X, next1.Y)); _path.Add(new Position(next2.X, next2.Y)); _path.Add(new Position(next3.X, next3.Y)); SendMoveRequest(); Assert.AreEqual(tile, _party.Tile); date += _party.Course.Delay; GameScheduler.Tick(date); Assert.AreEqual(next1, _party.Tile); date += _party.Course.Delay; GameScheduler.Tick(date); Assert.AreEqual(next2, _party.Tile); date += _party.Course.Delay; GameScheduler.Tick(date); Assert.AreEqual(next3, _party.Tile); var moveEvents = _player.ReceivedEventsOfType <EntityMoveEvent>(); Assert.AreEqual(3, moveEvents.Count); }
void Start() { game = GameScheduler.instance; anim = AnimationManager.instance; pageStack.Push(songSelectPage); synthConfigPage.Init(this); synthConfigPage.Disable(); synthConfigPage.group.interactable = false; midiDetailPage.Init(this); midiDetailPage.Disable(); midiDetailPage.group.interactable = false; songSelectPage.Init(this); songSelectPage.Enable(); midiDetailPage.group.interactable = true; midiDirectPage.Init(this); midiDirectPage.Disable(); midiDirectPage.group.interactable = false; appConfigPageScheduler.Init(this); appConfigPageScheduler.Disable(); appConfigPageScheduler.group.interactable = false; }
public void Init(GameplayLevelScheduler level) { game_ = GameScheduler.instance; anim_ = AnimationManager.instance; scoreText.text = "0"; scoreAdditionText.text = ""; comboText.text = ""; comboGroup.alpha = 0; judgmentText.text = ""; accuracyText.text = ""; //flashControllers = new FlashController[laneCount]; //for (int i = 0; i < laneCount; i++) { // var flashController = Instantiate(flashPrefab, flashPageRect).GetComponent<FlashController>(); // flashController.rect.anchoredPosition = new Vector2(laneXDict[i], judgeHeight); // flashController.rect.sizeDelta = new Vector2(blockWidth, 0); // flashControllers[i] = flashController; //} shouldUploadTrial = 1 <= level.playbackSpeed && level.playbackSpeed <= 2; #if UNITY_EDITOR shouldUploadTrial = true; #endif }
public void Start() { game = GameScheduler.instance; anim = AnimationManager.instance; net = GameScheduler.instance.netManager; web = WebCache.instance; if (game.userObj != null) { DisplayUserInfo(game.userObj); } else if (!string.IsNullOrEmpty(game.username)) { usernameInput.text = game.username; passwordInput.text = ""; net.ClAppUserLogin(game.username, game.password, (error, data) => { if (!string.IsNullOrEmpty(error)) { return; } game.ExecuteOnMain(() => { game.userObj = (JsonObj)data; DisplayUserInfo((JsonObj)data); }); }); } else { usernameInput.text = ""; passwordInput.text = ""; } }
public static void RescheduleAttack(LivingEntity attacker, LivingEntity defender, long attackDelay) { if (attacker.AttackTaskId != null) { GameScheduler.CancelTask(attacker.AttackTaskId); } var attackTask = new SchedulerTask(attackDelay + 1, GameThread.TIME_MS_NOW) { Task = () => { if (attacker.EntityType == EntityType.PLAYER) { if (Server.GetPlayer(attacker.UID) == null) { return; } } TryAttacking(attacker, defender); } }; GameScheduler.Schedule(attackTask); attacker.AttackTaskId = attackTask.UID; }
public void OnEntityTarget(EntityTargetPacket packet) { var player = Server.GetPlayer(packet.WhoUuid); if (packet.TargetUuid == null) { player.Target.BeingTargetedBy.Remove(player); player.Target = null; Log.Info("CANCEL TARGET"); GameScheduler.CancelTask(player.AttackTaskId); return; } var targetEntityType = packet.TargetUuid.GetEntityTypeFromUid(); if (targetEntityType == EntityType.MONSTER) { var monster = Server.Map.Monsters[packet.TargetUuid]; Server.Events.Call(new EntityTargetEvent() { Entity = player, TargetedEntity = monster }); } }
public virtual void Init() { if (gameObject.activeInHierarchy) { bullets = new List <Bullet>(); obj = pool.AddBullet(sprite, type, material, GameScheduler.ComputeScale(transform.position)); } }
public void Setup() { _game = new TestGame(); _player = _game.GetTestPlayer(); _path = new List <Position>(); _party = _player.Parties[0]; GameScheduler.Clear(); }
public void Setup() { _game = new TestGame(); _player = _game.GetTestPlayer(); _path = new List <Position>(); _party = _player.Parties[0]; _dungeon = new Dungeon(new BattleTeam(new Unit(0))); GameScheduler.Clear(); }
public override void Die() { Log.Debug(this.Name + " Died"); Server.Map.UpdateEntityPosition(this, from: this.Position, to: null); Server.Map.Monsters.Remove(this.UID); this.OriginSpawner?.CreateSpawnTask(); GameScheduler.CancelTask(MovementTaskId); GameScheduler.CancelTask(AttackTaskId); }
// Test to ensure server is recieving the packets and keeping the recieve order public void TestBasicScheduling() { List <int> executedTasks = new List <int>(); var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; GameScheduler.Schedule(new SchedulerTask(1000) { Task = () => { executedTasks.Add(1); } }); GameScheduler.Schedule(new SchedulerTask(2000) { Task = () => { executedTasks.Add(2); } }); GameScheduler.Schedule(new SchedulerTask(3000) { Task = () => { executedTasks.Add(3); } }); GameScheduler.Schedule(new SchedulerTask(1500) { Task = () => { executedTasks.Add(4); } }); GameScheduler.RunTasks(now); var tasks = GameScheduler.Tasks; Assert.That(executedTasks.Count == 0); GameScheduler.RunTasks(now + 1500); Assert.That(executedTasks.Contains(4)); Assert.That(executedTasks.Contains(1)); Assert.That(executedTasks.Count == 2); GameScheduler.RunTasks(now + 3000); Assert.That(executedTasks.Contains(2)); Assert.That(executedTasks.Contains(3)); Assert.That(executedTasks.Count == 4); Assert.That(GameScheduler.Tasks.Count == 0); }
public void TestNextTask() { GameScheduler.SetLogicalTime(DateTime.UnixEpoch); var t1 = new TestTask(TimeSpan.FromSeconds(10)); GameScheduler.Tick(DateTime.UnixEpoch + TimeSpan.FromMilliseconds(1)); Assert.AreEqual(t1, GameScheduler.NextTask); Assert.AreEqual(1, GameScheduler.PendingTasks); }
void Awake() { Instance = this; Application.logMessageReceived += (condition, stackTrace, type) => { if (type == LogType.Error || type == LogType.Exception) { uiErrorText.text = stackTrace; } }; }
private void Update() { if (!Looping) { return; } ProcessPackets(); var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; GameScheduler.RunTasks(now); }
public void CreateSpawnTask() { var schedulerTask = new SchedulerTask(SpawnTimerSeconds / 1000, GameThread.TIME_MS_NOW) { Task = () => { SpawnTick(); } }; GameScheduler.Schedule(schedulerTask); }
/// <summary> /// Replaces GameScheduler.Schedule with a method that does nothing. /// </summary> private static SchedulerHandle DoNotSchedule(GameScheduler scheduler, string name, float time, Action <object> callback, object callback_data, SchedulerGroup group) { _ = scheduler; _ = name; _ = time; _ = callback; _ = callback_data; _ = group; return(new SchedulerHandle()); }
public void Start() { game = GameScheduler.instance; anim = AnimationManager.instance; versionPopupGroup.HideAndDeactivate(); userInfoPopupGroup.HideAndDeactivate(); socialPopupGroup.HideAndDeactivate(); loginPopupGroup.HideAndDeactivate(); game.netManager.onNetStatusChangedEvent += OnNetStatusChanged; OnNetStatusChanged(game.netManager.netStatus); }
public void TestMonsterDieCleansMonsterData() { var client = ServerMocker.GetClient(); var player = client.FullLoginSequence(_player); var skeleton = new Skeleton() { Position = new Position(0, 1) }; Server.Events.Call(new EntitySpawnEvent() { Entity = skeleton, Position = skeleton.Position }); skeleton.MovementBehaviour = null; skeleton.MovementTick(); var skeletonMoveTask = GameScheduler.GetTask(skeleton.MovementTaskId); Assert.That(skeletonMoveTask != null, "Monster movement task should be created upon spawning"); player.Atk = 5; player.AtkSpeed = 99999999; skeleton.Def = 0; player.TryAttacking(skeleton, singleHit: true); Assert.That(skeleton.HP == skeleton.MAXHP - 5, "5 atk on 0 def should deal 5 damage"); player.Atk = 5000; player.TryAttacking(skeleton, singleHit: true); var moveTask = GameScheduler.GetTask(skeleton.MovementTaskId); var attackTask = GameScheduler.GetTask(skeleton.AttackTaskId); Assert.That(skeleton.HP < 0, "Skeleton should have < 0 hp as he took 5k damage"); Assert.That(!Server.Map.Monsters.ContainsKey(skeleton.UID), "Server should not contain the skeleton as its dead."); Assert.That(moveTask == null, "Skeleton is dead and his move task should have been cancelled"); Assert.That(attackTask == null, "Skeleton is dead and his move task should have been cancelled"); }
public void MovementTick() { if (MovementBehaviour != null) { MovementBehaviour.PerformMovement(this); LastMovement = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; GameScheduler.Schedule(new SchedulerTask(MovementDelay) { Task = () => { MovementTick(); } }); } }
public void TestOrdering() { GameScheduler.SetLogicalTime(DateTime.UnixEpoch); var t1 = new TestTask(TimeSpan.FromSeconds(1)); var t2 = new TestTask(TimeSpan.FromSeconds(2)); var t3 = new TestTask(TimeSpan.FromSeconds(3)); var minute = (long)GameScheduler.NowTimespan.TotalMinutes; var queue = GameScheduler.Queue; Assert.AreEqual(t1, queue.First()); Assert.AreEqual(t3, queue.Last()); Assert.AreEqual(3, GameScheduler.PendingTasks); }
public void MovementTick() { if (MovementBehaviour != null) { MovementBehaviour.PerformMovement(this); LastMovement = GameThread.TIME_MS_NOW; GameScheduler.Schedule(new SchedulerTask(MovementDelay, LastMovement) { Task = () => { MovementTick(); } }); } }
public override void RunThread() { Log.Info("Starting Game Thread"); LastTick = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; while (Running) { TIME_MS_NOW = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (TIME_MS_NOW - LastTick > 50) { Log.Error("Took more then 50ms to do a Game Loop"); } ProcessPackets(); GameScheduler.RunTasks(TIME_MS_NOW); LastTick = TIME_MS_NOW; } }
public void TestTickNotRunningTasks() { var time = DateTime.UnixEpoch; GameScheduler.SetLogicalTime(time); var t1 = new TestTask(TimeSpan.FromSeconds(1)); var t2 = new TestTask(TimeSpan.FromSeconds(1 + 60)); var t3 = new TestTask(TimeSpan.FromSeconds(1 + 120)); GameScheduler.Tick(time); Assert.IsFalse(t1.Ran); Assert.IsFalse(t2.Ran); Assert.IsFalse(t3.Ran); Assert.AreEqual(t1, GameScheduler.NextTask); }
public override void RunThread() { Log.Info("Starting Game Thread"); LastTick = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; while (Running) { var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (now - LastTick > 50) { Log.Error("Took more then 50ms to do a Game Loop"); } ProcessPlayerInput(); ProcessEntities(); GameScheduler.RunTasks(now); LastTick = now; } }
void Start() { // Set instance to this object if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } // Avoid music stopping on alt tab Application.runInBackground = true; // Initialize quadtree and meshpool quadtree.Init(); meshpool.Init(); // Initialize player player.Init(); dialogue.StartDialogue(); quadtree.player = player; if (Application.isPlaying) { audioManager.Init(); audioManager.PlayMusic(stageMusic, stageMusic_spirit, stageStartLoop); } if (dialogue.isActiveAndEnabled) { StartCoroutine(dialogue.StartDialogue()); StartCoroutine(MoveCameraAfterDialogueEnd()); } // Initialize enemies enemies = FindObjectsOfType(typeof(Enemy)) as Enemy[]; for (int i = 0; i < enemies.Length; ++i) { enemies[i].Init(); } meshpool.UpdateAt(0); }
public void TestRunningTwoTasks() { var time = DateTime.UnixEpoch; GameScheduler.SetLogicalTime(time); var t1 = new TestTask(TimeSpan.FromSeconds(1)); var t2 = new TestTask(TimeSpan.FromSeconds(5)); var t3 = new TestTask(TimeSpan.FromSeconds(7)); GameScheduler.Tick(time + TimeSpan.FromSeconds(5)); Assert.IsTrue(t1.Ran); Assert.IsTrue(t2.Ran); Assert.IsFalse(t3.Ran); Assert.AreEqual(t3, GameScheduler.NextTask); Assert.AreEqual(1, GameScheduler.PendingTasks); }
void OnEnable() { // Set instance to this object if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } InitializeCameraSettings(); // Initialize quadtree and meshpool quadtree.Init(); meshpool.Init(); border.Init(); border.obj.Scale = new Vector3(scale_factor, scale_factor); //origin.position = border.obj.OBB.FL; background.position = ComputePosition(new Vector3(-96, 0, 10)); background.localScale = ComputeScale(new Vector3(384, 448)); dialogue.Init(); // Initialize player player.Init(); // Initialize bomb and life bars lifebar.Init(); bombbar.Init(); lifetext.Init(); bombtext.Init(); // Initialize enemies for (int i = 0; i < enemies.Count; ++i) { enemies[i].Init(); } meshpool.UpdateAt(0); }
public void TestCourseMovingParty() { var date = DateTime.MinValue; GameScheduler.SetLogicalTime(date); var tile = _party.Tile; var next = tile.GetNeighbor(Direction.SOUTH); _path.Add(new Position(next.X, next.Y)); SendMoveRequest(); Assert.AreEqual(tile, _party.Tile); GameScheduler.Tick(date + _party.Course.Delay); Assert.AreEqual(next, _party.Tile); }
// Use this for initialization public void Init() { if (gameObject.activeInHierarchy) { // Setting start position and scale Vector3 scale = GameScheduler.ComputeScale(transform.localScale); frame = new Bullet[max]; for (int i = 0; i < max; i++) { Vector3 position = GameScheduler.ComputePosition(new Vector3(transform.position.x + i * 20, transform.position.y)); // Add lives full frame[i] = pool.AddBullet(empty, EType.EFFECT, EMaterial.GUI, position); frame[i].Scale = scale; } UpdateBar(); } }