Example #1
0
    private bool resetProcessingAction()
    {
        if (processingAction == null)
        {
            return(false);
        }

        processingAction = null;

        originalAction = null;

        selectedMonster = null;

        previousTargetsCount = 0;

        currentTargetIndex = 0;

        actionTargetIndex = 0;

        foreach (List <System.Object> list in targets)
        {
            list.Clear();
        }

        targets.Clear();

        return(true);
    }
Example #2
0
    /// <summary>
    /// Get the potential target and filters out what is and isnt a valid target
    /// based on the action given. Returns the target as a System.Object if it
    /// is a valid target. Returns null otherwise.
    /// </summary>
    /// <param name="potentialTarget"></param>
    /// <param name="action"></param>
    /// <param name="currentTargetInfoIndex">The current index of </param>
    /// <returns></returns>
    public System.Object getTargetableObject(Transform potentialTarget,
                                             BattleAction action, int currentTargetInfoIndex)
    {
        // Distance check
        if (action.range != -1)
        {
            float dist = Vector3.Distance(selectedPuppet.transform.position,
                                          potentialTarget.position);

            if (dist > action.range)
            {
                return(null);
            }

            // Check for self casting
        }
        else if (action.range == 0)
        {
            if (action.targetInfos[0].targetTypes[0] == ActionTarget.SELF)
            {
                return((System.Object)selectedPuppet);
            }
            else
            {
                Debug.LogError
                    ("ERROR! Range == 0 but not self cast for action: "
                    + action);

                return(null);
            }
        }



        foreach (ActionTarget possibleTargetType in action.targetInfos
                 [currentTargetInfoIndex].targetTypes)
        {
            switch (possibleTargetType)
            {
            case ActionTarget.MONSTER:

            case ActionTarget.MONSTER_PART:

                BattleMonsterScript monster = potentialTarget.
                                              GetComponentInChildren <BattleMonsterScript>();

                if (monster != null)
                {
                    return((System.Object)monster);
                }
                else
                {
                    return(null);
                }

            default:
                Debug.LogError("ERROR! UNKNWON TARGET INFO: " +
                               possibleTargetType);

                return(null);
            }
        }

        return(null);
    }
Example #3
0
    /// <summary>
    /// Ran every frame; used to process the mouse's input on the battlefield.
    /// </summary>
    public void processMoueInput()
    {
        if ((selectedPuppet != null && selectedPuppet.isMoving) ||
            MouseInputUIBlocker.BlockedByUI)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (processingAction != null)
            {
                /* The ray where the the mouse is positioned */
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                /* Holds the data for what got hit by the ray IF something got
                 *  hit */
                RaycastHit hit;

                // If something was hit
                if (Physics.Raycast(ray, out hit, Mathf.Infinity,
                                    targetableLayers))
                {
                    System.Object objectTarget = getTargetableObject(hit.
                                                                     transform.parent, processingAction, currentTargetIndex);

                    if (objectTarget != null)
                    {
                        Debug.LogError("Valid Hit!");

                        if (objectTarget is BattleMonsterScript &&
                            processingAction.targetInfos[currentTargetIndex].
                            containsMonsterBodyPart)
                        {
                            selectedMonster = (BattleMonsterScript)objectTarget;
                        }
                        else
                        {
                            targets[actionTargetIndex].Add(objectTarget);
                        }
                    }
                    else
                    {
                        Debug.LogError("Invalid Hit!");
                    }
                }
            }
            else if (!MouseInputUIBlocker.BlockedByUI)
            {
                /* The ray where the the mouse is positioned */
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                /* Holds the data for what got hit by the ray IF something got
                 * hit */
                RaycastHit hit;

                // If something was hit
                if (Physics.Raycast(ray, out hit, Mathf.Infinity,
                                    puppetRaycastLayers))
                {
                    setSelectedPuppet(hit.transform.parent);
                }
                else
                {
                    setSelectedPuppet(null);
                }
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            if (processingAction != null)
            {
                resetProcessingAction();
            }
        }
    }
Example #4
0
    /// <summary>
    /// Updates each frame to determine what the player/camera must calculate
    /// and execute in that exact frame. Currently calculate shunter selection
    /// </summary>
    void Update()
    {
        // If the processing action is not null...
        if (processingAction != null)
        {
            // If all the targets have been set for the current action list...
            if (processingAction.totalTargetCount == targets[actionTargetIndex].Count)
            {
                if (!(processingAction is FollowupAction))
                {
                    battleCombatScript.processAction(originalAction, targets,
                                                     (ParentPuppetScript)selectedPuppet);

                    resetProcessingAction();
                }
                else
                {
                    targets.Add(new List <System.Object>());

                    actionTargetIndex++;

                    previousTargetsCount = 0;

                    currentTargetIndex = 0;

                    processingAction = ((FollowupAction)processingAction).getFollowup();
                }

                // If the current targetInfo being processed has reached
                //   the needed amount of targets, then increment the
                //   currentTargetInfoIndex to move to the next
                //   targetInfo being processed and update the previous
                //   target count to add the now previous targetInfo
                //   target count.
            }
            else if (processingAction.targetInfos[currentTargetIndex].
                     targetCount == targets[actionTargetIndex].Count -
                     previousTargetsCount)
            {
                currentTargetIndex++;

                previousTargetsCount = targets[actionTargetIndex].Count;

                selectedMonster = null;

                monsterBodyPartPanel.gameObject.SetActive(false);
            }
        }
        else if (selectedPuppet != null)
        {
            updateUI(selectedPuppet.battleActions,
                     selectedPuppet.getPuppetName(),
                     selectedPuppet.currentActionPointCount,
                     selectedPuppet.getModifiedActionPointCount(),
                     selectedPuppet.getCurrentSanity(),
                     selectedPuppet.getModifiedMaxSanity()
                     );

            selectedPuppet.processMovement();
        }

        if (selectedMonster != null &&
            monsterBodyPartPanel.gameObject.activeSelf == false)
        {
            List <GameObject> children = new List <GameObject>();

            foreach (Transform child in
                     mbpScrollView.Find(MBP_PANEL_SCROLL_CONTENT))
            {
                children.Add(child.gameObject);
            }

            children.ForEach(child => Destroy(child));

            addBodyPartsToScrollView(selectedMonster.connectedMonster);

            monsterBodyPartPanel.gameObject.SetActive(true);
        }
        else if (selectedMonster == null)
        {
            monsterBodyPartPanel.gameObject.SetActive(false);
        }

        processMoueInput();
    }