/// <summary> /// Reads a packet from the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="message">The message to read from.</param> /// <returns>The packet read from the message.</returns> public override IInboundPacket ReadFromMessage(INetworkMessage message) { message.ThrowIfNull(nameof(message)); // 1 - offensive, 2 - balanced, 3 - defensive FightMode fightMode = message.GetByte() switch { 0x01 => FightMode.FullAttack, 0x02 => FightMode.Balanced, 0x03 => FightMode.FullDefense, _ => FightMode.Balanced, }; // 0 - stand while fightning, 1 - chase opponent ChaseMode chaseMode = message.GetByte() switch { 0x00 => ChaseMode.Stand, 0x01 => ChaseMode.Chase, 0x02 => ChaseMode.KeepDistance, _ => ChaseMode.Chase, }; // 0 - safe mode, 1 - free mode var isSafetyEnabled = message.GetByte() > 0; return(new ModesPacket(fightMode, chaseMode, isSafetyEnabled)); }
/// <summary> /// Initializes a new instance of the <see cref="ChangeModesOperation"/> class. /// </summary> /// <param name="requestorId">The id of the creature setting the modes.</param> /// <param name="fightMode">The fight mode to set.</param> /// <param name="chaseMode">The chase mode to set.</param> /// <param name="safeModeOn">A value indicating whether the safety mode is on.</param> public ChangeModesOperation(uint requestorId, FightMode fightMode, ChaseMode chaseMode, bool safeModeOn) : base(requestorId) { this.FightMode = fightMode; this.ChaseMode = chaseMode; this.IsSafeModeOn = safeModeOn; }
/// <summary> /// Reads a packet from the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="message">The message to read from.</param> /// <returns>The packet read from the message.</returns> public override IIncomingPacket ReadFromMessage(INetworkMessage message) { message.ThrowIfNull(nameof(message)); // 1 - offensive, 2 - balanced, 3 - defensive var rawFightMode = message.GetByte(); // 0 - stand while fightning, 1 - chase opponent var rawChaseMode = message.GetByte(); // 0 - safe mode, 1 - free mode var rawSafeMode = message.GetByte(); FightMode fightMode = FightMode.Balanced; ChaseMode chaseMode = ChaseMode.Stand; if (Enum.IsDefined(typeof(FightMode), rawFightMode)) { fightMode = (FightMode)rawFightMode; } if (Enum.IsDefined(typeof(ChaseMode), rawChaseMode)) { chaseMode = (ChaseMode)rawChaseMode; } return(new ModesPacket(fightMode, chaseMode, isSafetyEnabled: rawSafeMode > 0)); }
public void ComputeNextMove(ChaseMode mode) { Vector2 target; if (Spawned) { Move(); switch (mode) { case ChaseMode.Chase: target = ComputeTarget(type); break; case ChaseMode.Scatter: target = ScatterTarget(type); break; case ChaseMode.Frighten: target = ScatterTarget(type); break; default: target = position; break; } currentDir = (MoveDir)GetTurnClosestToTarget(position, target, GetOpenTiles(position)); //Debug Debug.DrawLine(transform.localPosition, Misc.ConvertToMatrixCoordinates(target), GetComponent <Renderer>().material.color, FindObjectOfType <GameManager>().timeTillUpdate, false); } }
IEnumerator UpdateChaseLogic() { for (int i = 0; i < ChaseModes.Count; i++) { CurrentMode = ChaseModes[i]; while (power.IsPacmanSuper()) { yield return(null); } yield return(new WaitForSecondsRealtime(ChaseTime[i])); } while (true) { CurrentMode = ChaseMode.Chase; //Whatever the last mode in the array was, defaults to chase till player either dies or level ends while (!power.IsPacmanSuper()) { yield return(null); //Fix : Eating supers sometimes prevented ghosts to switch back to chase mode, this avoids that scenario } while (power.IsPacmanSuper()) { yield return(null); } yield return(new WaitForEndOfFrame()); } }
public CombatControlsCommand(Player player, FightMode fightMode, ChaseMode chaseMode, SafeMode safeMode) { Player = player; FightMode = fightMode; ChaseMode = chaseMode; SafeMode = safeMode; }
public void ModesPacket_Initialization() { const FightMode ExpectedFightMode = FightMode.Balanced; const ChaseMode ExpectedChaseMode = ChaseMode.KeepDistance; const bool ExpectedSafetyModeValue = true; IModesInfo modesInfo = new ModesPacket(ExpectedFightMode, ExpectedChaseMode, ExpectedSafetyModeValue); Assert.AreEqual(ExpectedFightMode, modesInfo.FightMode, $"Expected {nameof(modesInfo.FightMode)} to match {ExpectedFightMode}."); Assert.AreEqual(ExpectedChaseMode, modesInfo.ChaseMode, $"Expected {nameof(modesInfo.ChaseMode)} to match {ExpectedChaseMode}."); Assert.AreEqual(ExpectedSafetyModeValue, modesInfo.SafeModeOn, $"Expected {nameof(modesInfo.SafeModeOn)} to match {ExpectedSafetyModeValue}."); }
private float DistanceValue(float distance, ChaseMode mode) { switch (mode) { case ChaseMode.Linear: return(speed * Time.deltaTime); case ChaseMode.Square: return(Mathf.Pow(distance, 2) * Time.deltaTime); case ChaseMode.Cubic: return(Mathf.Pow(distance, 3) * Time.deltaTime); case ChaseMode.Exponential: return(Mathf.Pow(2, distance) * Time.deltaTime); default: return(0); } }
/// <summary> /// Initializes a new instance of the <see cref="ModesPacket"/> class. /// </summary> /// <param name="fightMode">The fight mode selected.</param> /// <param name="chaseMode">The chase mode selected.</param> /// <param name="isSafetyEnabled">A value indicating whether the safety mode is on.</param> public ModesPacket(FightMode fightMode, ChaseMode chaseMode, bool isSafetyEnabled) { this.FightMode = fightMode; this.ChaseMode = chaseMode; this.SafeModeOn = isSafetyEnabled; }
/// <summary> /// Requests the gameworld to update a player's modes. /// </summary> /// <param name="playerId">The id of the player.</param> /// <param name="fightMode">The chosen fight mode.</param> /// <param name="chaseMode">The chosen chase mode.</param> /// <param name="safeModeOn">A value indicating whether the safety mode is on.</param> public void RequestToUpdateModesAsync(uint playerId, FightMode fightMode, ChaseMode chaseMode, bool safeModeOn) { this.gameworldClientAdapter.RequestToUpdateModesAsync(playerId, fightMode, chaseMode, safeModeOn); }
public void SetChaseMode(ChaseMode chaseMode) { ChaseMode = chaseMode; }
IEnumerator UpdateGameLogic() { while (isGame) { //Gameloop and update logic // Debug.Log("TICK : " + Time.time); if (power.IsPacmanSuper()) { AudioManager.PlaySound("fuite"); CurrentMode = ChaseMode.Frighten; } //Check if pacman collide an ennemy foreach (GhostBehavior ghost in ghostPrefabs) { ghost.ComputeNextMove(CurrentMode); if (ghost.position == pacman.position) { pacman.colliding = true; } } if (pacman.colliding && pacmanLife > 0 && !power.IsPacmanSuper()) { AudioManager.PlaySound("death"); pacman.colliding = false; pacman.lastDir = MoveDir.Up; pacmanLife -= 1; UIManager.Touch(); pacman.Spawn(); GhostRespawn(); } else if (pacman.colliding && power.IsPacmanSuper()) { pacman.colliding = false; GhostBehavior closest = ghostPrefabs[0]; float distance = 100f; foreach (GhostBehavior ghost in ghostPrefabs) { if (Vector2.Distance(ghost.position, pacman.position) < distance) { closest = ghost; distance = Vector2.Distance(ghost.position, pacman.position); Debug.Log("Closest is : " + closest.name); } } closest.Spawn(); AudioManager.PlaySound("chomp"); } else if (pacman.colliding && pacmanLife == 0) { pacman.colliding = false; AudioManager.PlaySound("death"); score.SaveScore(); UIManager.GameOver(); isGame = false; } //Update Pacman pacman.Move(currDirection); pacman.colliding = false; //Wait timeTillUpdate seconds till next update cycle while (triggerUpdate == false) { yield return(null); } triggerUpdate = false; } }