Esempio n. 1
0
    MapHero CreatePartyOnMap(HeroParty heroParty, PartyData partyData)
    {
        Debug.Log("Creating party on map representation");
        // Create new party on map UI
        MapHero newPartyOnMap = Instantiate(heroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>();

        // place party to original position on map
        //newPartyOnMap.GetComponent<RectTransform>().offsetMin = new Vector2(partyData.partyMapPosition.offsetMinX, partyData.partyMapPosition.offsetMinY);
        //newPartyOnMap.GetComponent<RectTransform>().offsetMax = new Vector2(partyData.partyMapPosition.offsetMaxX, partyData.partyMapPosition.offsetMaxY);
        // place it to original position on map based on the tile coordinates
        newPartyOnMap.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(partyData.partyMapCoordinates);
        // Create hero label on map
        MapObjectLabel newPartyOnMapLabel = Instantiate(heroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>();

        // Link hero to the lable and label to the hero
        newPartyOnMap.GetComponent <MapObject>().Label = newPartyOnMapLabel;
        newPartyOnMapLabel.MapObject = newPartyOnMap.GetComponent <MapObject>();
        // create links between party on map and hero party
        newPartyOnMap.LHeroParty = heroParty;
        heroParty.LMapHero       = newPartyOnMap;
        // rename it
        newPartyOnMap.gameObject.name = heroParty.GetPartyLeader().GivenName + " " + heroParty.GetPartyLeader().UnitName + " Party";
        // set color according to the player color preference
        newPartyOnMap.SetColor(GetPlayerByFaction(heroParty.Faction).PlayerColor);
        // activate hero on map
        newPartyOnMap.gameObject.SetActive(true);
        // activate hero label on map
        newPartyOnMapLabel.gameObject.SetActive(true);
        // return result
        return(newPartyOnMap);
    }
Esempio n. 2
0
    void FleeXFromY(HeroParty fleeingHeroParty, HeroParty otherHeroParty)
    {
        Debug.Log("Flee");
        // Grant fleeing hero party leader 1 bonus move point
        fleeingHeroParty.GetPartyLeader().MovePointsCurrent += 1;
        // get fleeing party transform on map
        // it is not possible to flee if your party is not on map, that is why there is no additional checks here
        Transform fleeingPartyTransform = fleeingHeroParty.LMapHero.transform;
        // get other party or city transform on map
        Transform oppositeTransform;

        // verify if prebattle parent was city
        if (otherHeroParty.PreBattleParentTr.GetComponent <City>())
        {
            // player was in city or it was city garnizon
            // get city on map transform
            oppositeTransform = otherHeroParty.PreBattleParentTr.GetComponent <City>().LMapCity.transform;
        }
        else
        {
            // player was on map
            // get linked party on map transform
            oppositeTransform = otherHeroParty.LMapHero.transform;
        }
        // give control to map manager to flee
        MapManager.Instance.EscapeBattle(fleeingPartyTransform, oppositeTransform);
    }
Esempio n. 3
0
    int GetLeadershipConsumedByPartyUnitsExcludingLeader(PartyUnit partyUnit)
    {
        // get unit party
        HeroParty heroParty = partyUnit.GetUnitParty();

        // verify if unit is member of party
        if (heroParty != null)
        {
            Debug.LogWarning("!!Convert UnitSize to class!!");
            return(heroParty.GetLeadershipConsumedByPartyUnits() - (int)heroParty.GetPartyLeader().UnitSize - 1);
        }
        else
        {
            Debug.Log("Unit without party");
            return(0);
        }
        //// structure 5PartyPanel-4Row-3Cell-2UnitSlot-1UnitCanvas-Unit
        //PartyPanel partyPanel = null;
        //if (partyUnit.transform.parent)
        //    if (partyUnit.transform.parent.parent)
        //        if (partyUnit.transform.parent.parent.parent)
        //            if (partyUnit.transform.parent.parent.parent.parent)
        //                if (partyUnit.transform.parent.parent.parent.parent.parent)
        //                    partyPanel = partyUnit.transform.parent.parent.parent.parent.parent.GetComponent<PartyPanel>();
        //if (partyPanel != null)
        //{
        //    return partyPanel.GetNumberOfPresentUnits() - 1;
        //}
        //else
        //{
        //    return 0;
        //}
    }
Esempio n. 4
0
    void SetHeroPartyRepresentationOnTheMap(HeroParty newLeaderParty, City city = null)
    {
        // Create Hero's object on the map
        // create and update Hero Party panel in UI, (no - parent it to city UI)
        //Transform parentCityOnMap = map.Find(transform.name);
        // Create new hero party on map ui
        MapHero newPartyOnMapUI = Instantiate(ObjectsManager.Instance.HeroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>();

        // Verify if argument is null
        if (city == null)
        {
            // Assign currently linked city
            city = LCity;
        }
        // adjust position, because city and hero transform have differnet anchor points
        // Get ui world corners
        // 12
        // 03
        Vector3[] worldCorners = new Vector3[4];
        newPartyOnMapUI.GetComponent <RectTransform>().GetWorldCorners(worldCorners);
        // get map hero ui width and heigh
        float newPartyOnMapUIHeight = Mathf.Abs(worldCorners[3].x - worldCorners[0].x);
        float newPartyOnMapUIWidth  = Mathf.Abs(worldCorners[1].y - worldCorners[0].y);
        // Debug.Log(newPartyOnMapUIWidth + ":" + newPartyOnMapUIHeight);
        Vector3 positionAdjustment = new Vector3(newPartyOnMapUIHeight / 2f, newPartyOnMapUIWidth / 2f, 0);

        // set it to the same position as the parent city
        newPartyOnMapUI.transform.position = city.LMapCity.transform.position + positionAdjustment;
        // Create hero label on map
        MapObjectLabel newPartyOnMapLabel = Instantiate(ObjectsManager.Instance.HeroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>();

        // Link hero to the lable and label to the hero
        newPartyOnMapUI.GetComponent <MapObject>().Label = newPartyOnMapLabel;
        newPartyOnMapLabel.MapObject = newPartyOnMapUI.GetComponent <MapObject>();
        // activate new party on map UI
        newPartyOnMapUI.gameObject.SetActive(true);
        // activate hero label on map
        newPartyOnMapLabel.gameObject.SetActive(true);
        // Link HeroParty to the hero party on the map
        newPartyOnMapUI.LHeroParty = newLeaderParty;
        // Link hero on the map to HeroParty
        newLeaderParty.LMapHero = (newPartyOnMapUI);
        // Link hero on the map to city on the map
        city.LMapCity.GetComponent <MapCity>().LMapHero = newPartyOnMapUI.GetComponent <MapHero>();
        // Link city on the map to hero on the map
        newPartyOnMapUI.GetComponent <MapHero>().lMapCity = city.LMapCity;
        // move hero party to the back, so its UI label is not covering city's UI label
        // but it is in front of map slices
        // newPartyOnMapUI.transform.SetSiblingIndex(1);
        // rename it
        newPartyOnMapUI.gameObject.name = newLeaderParty.GetPartyLeader().GivenName + " " + newLeaderParty.GetPartyLeader().UnitName + " Party";
        // set color according to the player color preference
        newPartyOnMapUI.SetColor(ObjectsManager.Instance.GetPlayerByFaction(newLeaderParty.Faction).PlayerColor);
    }
Esempio n. 5
0
    void UpdateLabelText()
    {
        // set label
        //label = GetComponentInChildren<MapObjectLabel>();
        // set label text
        PartyUnit leaderUnit = lHeroParty.GetPartyLeader();
        string    givenName  = leaderUnit.GivenName;
        string    unitName   = leaderUnit.UnitName;

        GetComponent <MapObject>().Label.LabelTxt.text = "[" + givenName + "]\r\n <size=12>" + unitName + "</size> ";
    }