Ejemplo n.º 1
0
    // searches for the player of the other team by chosing the other team and the target row
    public PlayerProperties GetTargetPlayer(PhaseHandler.RowPosition row)
    {
        PhaseHandler.Team       team            = player.team == PhaseHandler.Team.Left ? PhaseHandler.Team.Right : PhaseHandler.Team.Left;
        List <PlayerProperties> matchingPlayers = players.FindAll(somePlayer => somePlayer.team == team &&
                                                                  somePlayer.rowPosition == row);

        if (matchingPlayers.Count == 1)
        {
            print($"Matching target player is: {matchingPlayers[0].playerName}, was called from { new StackFrame(1, true).GetMethod().Name}");
            return(matchingPlayers[0]);
        }

        else
        {
            // more or less than one player found
            print($"found {matchingPlayers.Count} matching players, but there should be only exactly 1");
            if (matchingPlayers.Count > 1)
            {
                print("found following players:");
                foreach (PlayerProperties player in matchingPlayers)
                {
                    print(player.playerName);
                }
            }
            throw new InvalidOperationException();
        }
    }
Ejemplo n.º 2
0
    PhaseHandler.RowPosition GetRandomTargetRow(ActionPhase actionPhase = null)
    {
        print("selecting a random target row");
        if (actionPhase == null)
        {
            actionPhase = this;
        }

        Array values = Enum.GetValues(typeof(PhaseHandler.RowPosition));

        System.Random            random          = new System.Random();
        PhaseHandler.RowPosition randomTargetRow = (PhaseHandler.RowPosition)values.GetValue(random.Next(values.Length));

        var targetPlayer = actionPhase.GetTargetPlayer(randomTargetRow);

        print("validating whether the randomly chosen target is valid");
        if (actionPhase.CanPlayerAttack(targetPlayer))
        {
            print($"got valid random target row: {randomTargetRow} (player {targetPlayer.playerName})");
            return(randomTargetRow);
        }
        else
        {
            // this is ugly since it will only work for 2 rows but its okay for our usecase now
            print($"got invalid target row: {randomTargetRow}, therefore choosing the other one");
            return(randomTargetRow == PhaseHandler.RowPosition.Front ? PhaseHandler.RowPosition.Back : PhaseHandler.RowPosition.Front);
        }
    }
Ejemplo n.º 3
0
    public void ChangeLeftHandWeapon(PhaseHandler.RowPosition rowPosition, WeaponDefinitions.WeaponType weaponType)
    {
        // print("equipping new left hand weapon");
        Transform leftHandTransform = player.transform.parent.Find("Minifig Character/jointScaleOffset_grp/Joint_grp/detachSpine/spine01/spine02/spine03/spine04/spine05/spine06/shoulder_L/armUp_L/arm_L/wristTwist_L/wrist_L/hand_L/finger01_L").transform;
        // weapon color should stay the same as previous
        Color color = leftHandWeapon != null?leftHandWeapon.GetComponent <Renderer>().material.color : Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);

        RemoveLeftHandWeapon();
        // spawns a new weapon and sets it as leftHandWeapon
        leftHandWeapon = SpawnNewWeapon(rowPosition, weaponType, color);
        leftHandWeapon.transform.parent = leftHandTransform;
    }
Ejemplo n.º 4
0
 public void ChangeTargetRow(PhaseHandler.RowPosition targetRow)
 {
     print("ChangeTargetRow triggered");
     if (phase == PhaseHandler.Phase.Decision)
     {
         print($"Changing TargetRow to {targetRow}");
         selectedTargetRow = targetRow;
     }
     else
     {
         print("Changing TargetRow is currently not allowed");
     }
 }
Ejemplo n.º 5
0
    GameObject SpawnNewWeapon(PhaseHandler.RowPosition rowPosition, WeaponDefinitions.WeaponType weaponType, Color color)
    {
        // load a gameobject with the correct prefab
        Weapon[] matchingWeapons = WeaponDefinitions.GetWeapon(weaponType, rowPosition);

        if (matchingWeapons.Length > 0)
        {
            string     assetPath = matchingWeapons[0].asset;
            GameObject newWeapon = LoadNewWeapon(assetPath, new Vector3(0.3f, 0.3f, 0.3f), color);
            return(newWeapon);
        }
        else
        {
            // no matching weapon type was found
            throw new InvalidOperationException();
        }
    }
Ejemplo n.º 6
0
 // searches through all availabe weapons and returns the ones that match the weapon type and row position
 public static Weapon[] GetWeapon(WeaponType weaponType, PhaseHandler.RowPosition rowPosition)
 {
     return(Array.FindAll <Weapon>(weapons.weapons, weapon => weapon.type == weaponType.ToString() &&
                                   weapon.row == rowPosition.ToString()));
 }