예제 #1
0
    public void Shoot(Unit shooter, Node targetNode)
    {
        //get the node we're shooting at
        Node originNode = map.WorldToNode(shooter.gameObject.transform.position);
        //get the unit sitting in the node
        Unit targetUnit = GetSoldierInNode(targetNode).GetComponent <Unit>();

        //if there is no target, just pretend this never happened
        if (targetUnit == null)
        {
            return;
        }
        //get the number we require to be rolled
        int required = Shooting.GetRequiredHitRoll(shooter);
        //get ready to record the shot modifiers
        int modifier = 0;
        //get the path of the shot
        List <Node> shotPath = map.GetLine(originNode, targetNode);

        //apply cover modifier
        modifier += Shooting.GetCoverModifier(shotPath);
        //apply modifiers from the unit shooting and their weapon
        modifier += Shooting.GetShooterModifier(shooter, weapons[shooter.weapon1], (int)Mathf.Round(map.Distance(originNode, targetNode)));
        //apply modifiers from the unit being shot at
        modifier += Shooting.GetTargetModifier(targetUnit, weapons[shooter.weapon1]);
        //roll a die
        int roll = Dice.Roll();

        //always miss on a 1 or if the modified roll is lower than the required roll
        if (roll == 1 || roll + modifier < required)
        {
            Debug.Log("miss");
        }
        else
        {
            Debug.Log("hit");
        }
    }