void _SwapMine(Mine.MineTypes type, Player attacker) { _collectedMines.Remove(type); EventManager.Fire(new Event_PlayerMineCollect() { playerIndex = attacker.Index, mineType = type, attackerIndex = -1 }); }
public static System.Type GetTypeOfMineByIntCode(Mine.MineTypes type) { switch (type) { case MineTypes.Simple: return(typeof(MineSimple)); case MineTypes.Speed: return(typeof(MineSpeed)); case MineTypes.Dash: return(typeof(MineDash)); default: return(typeof(MineSimple)); } }
void LaunchMine(Vector2 direction, Mine.MineTypes mineType) { if (!_collectedMines.Exists(mineType)) { return; } if (Time.time - _lastMineLaunchTime < MINE_LAUNCH_COOLDOWN) { return; } RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, (Vector2)direction, MINE_LAUNCH_MIN_DISTANCE); for (int i = 0; i < hits.Length; i += 1) { if (hits [i].collider.GetType() == typeof(EdgeCollider2D)) { return; } } if (direction.magnitude == 0) { return; } _lastMineLaunchTime = Time.time; GameObject mineObj = Instantiate(MinePrefab, transform.position + (Vector3)direction * 0.75f, Quaternion.identity); System.Type typeOfMine = Mine.GetTypeOfMineByIntCode(mineType); mineObj.AddComponent(typeOfMine); Mine mine = mineObj.GetComponent(typeOfMine) as Mine; mine.Spawn(direction, _rb.velocity, _playerIndex); _collectedMines.Remove(mineType); UpdateInternals(); GetComponent <AudioSource>().Play(); }
public bool Exists(Mine.MineTypes mineType) { return(Mines.Exists(x => x == mineType)); }
public void Remove(Mine.MineTypes mineType) { Mines.RemoveAt(Mines.FindIndex(x => x == mineType)); }
public void Add(Mine.MineTypes mineType) { Mines.Add(mineType); }
void OnMineCollect(Event_PlayerMineCollect e) { if (e.playerIndex == _playerIndex) { if (e.mineType == Mine.MineTypes.Simple) { // calculate mine to swap; TODO: it must be in another place (GameState or another mediator) if (e.attackerIndex > -1) { Player attacker = GameState.Instance.Players[e.attackerIndex];//(Player)FindObjectsOfType(typeof(Player))[e.attackerIndex]; Mine.MineTypes commonMineTypeToSteal = attacker._collectedMines.GetTypeOfMostCommonMines(); //Incorrectness here, always speed swap used if (commonMineTypeToSteal == Mine.MineTypes.Simple) { if (_collectedMines.Exists(Mine.MineTypes.Speed)) { // Debug.Log("Swap speed!"); // _collectedMines.Remove(Mine.MineTypes.Speed); // EventManager.Fire(new Event_PlayerMineCollect() { // playerIndex = attacker.Index, mineType = Mine.MineTypes.Speed, attackerIndex = -1 // }); _SwapMine(Mine.MineTypes.Speed, attacker); } else if (_collectedMines.Exists(Mine.MineTypes.Dash)) { _SwapMine(Mine.MineTypes.Dash, attacker); // Debug.Log("Swap dash!"); } } else if (commonMineTypeToSteal == Mine.MineTypes.Speed) { if (_collectedMines.Exists(Mine.MineTypes.Speed)) { _SwapMine(Mine.MineTypes.Speed, attacker); // Debug.Log("Swap speed!"); } else if (_collectedMines.Exists(Mine.MineTypes.Dash)) { _SwapMine(Mine.MineTypes.Dash, attacker); // Debug.Log("Swap dash!"); } } else { if (_collectedMines.Exists(Mine.MineTypes.Dash)) { _SwapMine(Mine.MineTypes.Dash, attacker); // Debug.Log("Swap dash!"); } else if (_collectedMines.Exists(Mine.MineTypes.Speed)) { _SwapMine(Mine.MineTypes.Speed, attacker); // Debug.Log("Swap speed!"); } } } // Send mine to attacker // Add simple mine } _collectedMines.Add(e.mineType); } PickupSource.Play(); UpdateInternals(); }