Esempio n. 1
0
    private void OnTriggerEnter(Collider otherCollider)
    {
        GameObject other = otherCollider.gameObject;

        string[] otherTagSections = GameTags.dissect(other.tag);
        if (GameTags.isOnTeam(other.tag) && otherTagSections[0] == tagSections[0] &&
            otherTagSections[1] == GameTags.Type.WAYPOINT &&
            otherTagSections[2] == tagSections[2])
        {
            arrived = true;
        }
        else
        {
            if (arrived || aggresssive)
            {
                if (GameTags.isOnTeam(other.tag) && otherTagSections[0] != tagSections[0] &&
                    (otherTagSections[1] == GameTags.Type.BUILDING ||
                     otherTagSections[1] == GameTags.Type.UNIT ||
                     otherTagSections[1] == GameTags.Type.PLAYER))
                {
                    targetObjet = other.gameObject;
                }
            }
        }
    }
Esempio n. 2
0
    private void CmdspawnBuilding(GameObject building)
    {
        GameObject clickedObject;

        if (didClickObject(out clickedObject))
        {
            string[] tagSections = GameTags.dissect(clickedObject.tag);
            Debug.LogFormat("team: {0} tags: {1}", team, tagSections);
            if (GameTags.isOnTeam(clickedObject.tag) && tagSections[0] == team && tagSections[1] == GameTags.Type.PLACEHOLDER)
            {
                clickedObject.GetComponent <BuildingPlot>().CmdspawnBuilding(building);
                Debug.Log("spawning building");
            }
        }
    }
Esempio n. 3
0
 // Update is called once per frame
 void Update()
 {
     if (!isOnTeam)
     {
         isOnTeam = GameTags.isOnTeam(gameObject.tag);
         if (isOnTeam)
         {
             tagSections    = GameTags.dissect(gameObject.tag);
             targetWaypoint = GameObject.FindGameObjectWithTag(GameTags.create(tagSections[0], GameTags.Type.WAYPOINT, tagSections[2]));
             Debug.LogFormat("Unit {0} has waypoint {1}", gameObject.tag, targetWaypoint.tag);
             if (targetWaypoint != null)
             {
                 controller.SetTarget(targetWaypoint.transform);
             }
         }
     }
     else
     {
         if (tagSections == null)
         {
             tagSections = GameTags.dissect(gameObject.tag);
         }
         if (arrived && targetObjet == null)
         {
             controller.SetTarget(gameObject.transform);
         }
         else if (targetObjet != null)
         {
             controller.SetTarget(targetObjet.transform);
         }
         else
         {
             controller.SetTarget(targetWaypoint.transform);
         }
     }
 }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (!isOnTeam)
        {
            isOnTeam = GameTags.isOnTeam(gameObject.tag);
            if (isOnTeam)
            {
                team = GameTags.dissect(gameObject.tag)[0];
            }
        }
        else
        {
            if (playerStats.inTerritoryMode)
            {
                if (Input.GetKeyDown(KeyCode.Alpha0))
                {
                    mouseState = MouseState.EMPTY;
                    Debug.Log("set mouse to empty");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    mouseState = MouseState.ATTACK_WAYPOINT;
                    Debug.Log("set mouse to attack waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    mouseState = MouseState.DEFENSE_WAYPOINT;
                    Debug.Log("set mouse to defense waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    mouseState = MouseState.SUPPORT_WAYPOINT;
                    Debug.Log("set mouse to support waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    mouseState = MouseState.SCOUT__WAYPOINT;
                    Debug.Log("set mouse to scout waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    mouseState = MouseState.SPAWN_ATTACK;
                    Debug.Log("set mouse to attack building");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha6))
                {
                    mouseState = MouseState.SPAWN_DEFENSE;
                    Debug.Log("set mouse to defense building");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha7))
                {
                    mouseState = MouseState.SPAWN_SUPPORT;
                    Debug.Log("set mouse to support building");
                }

                //if (Input.GetMouseButtonDown(0)) {
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    Debug.Log("clicked mouse button");
                    bool aggressive = Input.GetKey(KeyCode.LeftShift);
                    if (aggressive)
                    {
                        Debug.Log("set aggressive");
                    }
                    switch (mouseState)
                    {
                    case MouseState.EMPTY: {
                        // spawn units when clicking on a building
                        // if 0 == team
                        // if 1 == building
                        // if 2 == spawn or HQ
                        // call spawn
                        GameObject clickedObject;
                        if (didClickObject(out clickedObject))
                        {
                            Debug.LogFormat("clicked on obj {0} with tag {1}", clickedObject.name,
                                            clickedObject.tag);
                            string[] tagSections = GameTags.dissect(clickedObject.tag);
                            if (GameTags.isOnTeam(clickedObject.tag) && tagSections[0] == team && tagSections[1] == GameTags.Type.BUILDING &&
                                (tagSections[2] == GameTags.BuildingClass.SPAWN || tagSections[2] == GameTags.BuildingClass.HQ))
                            {
                                // TODO: check for resources here
                                Debug.Log("Spawning units");
                                clickedObject.GetComponent <UnitSpawner>().CmdspawnUnit();
                            }
                        }
                        break;
                    }

                    case MouseState.ATTACK_WAYPOINT: {
                        // set waypoint for attack units
                        CmdmoveWaypoint(GameTags.UnitClass.ATTACK, aggressive);
                        Debug.Log("Set attack waypoint");
                        break;
                    }

                    case MouseState.DEFENSE_WAYPOINT: {
                        // set waypoint for defense units
                        CmdmoveWaypoint(GameTags.UnitClass.DEFENSE, aggressive);
                        Debug.Log("Set defense waypoint");
                        break;
                    }

                    case MouseState.SUPPORT_WAYPOINT: {
                        // set waypoint for support units
                        CmdmoveWaypoint(GameTags.UnitClass.SUPPORT, aggressive);
                        Debug.Log("Set support waypoint");
                        break;
                    }

                    case MouseState.SCOUT__WAYPOINT: {
                        // set waypoint for scout units
                        CmdmoveWaypoint(GameTags.UnitClass.SCOUT, aggressive);
                        Debug.Log("Set scout waypoint");
                        break;
                    }

                    case MouseState.SPAWN_ATTACK: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redAttackBuildingPrefab);
                            Debug.Log("Spawn red attack building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueAttackBuildingPrefab);
                            Debug.Log("Spawn blue attack building");
                        }
                        break;
                    }

                    case MouseState.SPAWN_DEFENSE: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redDefenseBuildingPrefab);
                            Debug.Log("Spawn red defense building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueDefenseBuildingPrefab);
                            Debug.Log("Spawn blue defense building");
                        }
                        break;
                    }

                    case MouseState.SPAWN_SUPPORT: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redSupportBuildingPrefab);
                            Debug.Log("Spawn red support building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueSupportBuildingPrefab);
                            Debug.Log("Spawn blue support building");
                        }
                        break;
                    }
                    }
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    switch (mouseState)
                    {
                    case MouseState.ATTACK_WAYPOINT: {
                        // set waypoint for attack units
                        CmdmoveWaypoint(GameTags.UnitClass.ATTACK, true);
                        break;
                    }

                    case MouseState.DEFENSE_WAYPOINT: {
                        // set waypoint for defense units
                        CmdmoveWaypoint(GameTags.UnitClass.DEFENSE, true);
                        break;
                    }

                    case MouseState.SUPPORT_WAYPOINT: {
                        // set waypoint for support units
                        CmdmoveWaypoint(GameTags.UnitClass.SUPPORT, true);
                        break;
                    }

                    case MouseState.SCOUT__WAYPOINT: {
                        // set waypoint for scout units
                        CmdmoveWaypoint(GameTags.UnitClass.SCOUT, true);
                        break;
                    }
                    }
                }
            }
        }
    }