Exemple #1
0
 void OnUnitDestroyed(UnitTB unit)
 {
     for (int i = 0; i < activeUnitAbilityEffectList.Count; i++)
     {
         activeUnitAbilityEffectList[i].countTillNextTurn -= 1;
     }
 }
Exemple #2
0
    void MoveUnitToTileInstant(UnitTB unit, Tile tile)
    {
        List <Tile> path = AStar.SearchToOccupiedTile(unit.occupiedTile, tile);

        //make sure the target tile is not occupied
        if (path.Count > 0)
        {
            if (path[path.Count - 1].unit != null)
            {
                path.RemoveAt(path.Count - 1);
            }
        }

        //make sure the unit doesnt move beyond the allowed range
        while (path.Count > Mathf.Max(1, unit.GetMoveRange() + 1))
        {
            path.RemoveAt(path.Count - 1);
        }

        if (path.Count > 0)
        {
            Tile destinationTile = path[path.Count - 1];

            unit.occupiedTile.unit = null;
            unit.occupiedTile      = destinationTile;
            destinationTile.unit   = unit;
            unit.thisT.position    = destinationTile.pos;
        }

        unitInAction = false;
    }
 void OnUnitDestroyed(UnitTB unit)
 {
     if (unit == selectedUnit)
     {
         OnUnitDeselected();
     }
 }
Exemple #4
0
    public static void MoveUnit(UnitTB unit)
    {
        //Debug.Log("move "+unit);
        instance.StartCoroutine(instance._AIRoutineSingleUnit(unit));

        //for testing
        //Debug.Log("single AI routine");
        //instance.StartCoroutine(instance.SkippedAIRoutine(null));
    }
Exemple #5
0
    public void SetUnit(UnitTB newUnit)
    {
        unit = newUnit;

        if (collectible != null)
        {
            collectible.Trigger(newUnit);
        }
    }
Exemple #6
0
    void SwapCreep(int ID)
    {
        UnitTB unit = unitList[currentSwapID];

        unitList[currentSwapID] = unitList[ID];
        unitList[ID]            = unit;

        currentSwapID = -1;
    }
Exemple #7
0
    public static void MoveUnit(UnitTB unit)
    {
        //Debug.Log("move "+unit);
        instance.StartCoroutine(instance._AIRoutineSingleUnit(unit));

        //for testing
        //Debug.Log("single AI routine");
        //instance.StartCoroutine(instance.SkippedAIRoutine(null));
    }
Exemple #8
0
 public void ClearUnit()
 {
     unit = null;
     SetState(_TileState.Default);
     if (attackableToSelected)
     {
         GridManager.ClearIndicatorH(this);
         attackableToSelected = false;
     }
 }
Exemple #9
0
 void OnUnitDestroyed(UnitTB unit)
 {
     if (playerFactionExisted && !hotseat)
     {
         if (!playerFactionID.Contains(unit.factionID))
         {
             GainPoint(unit.pointReward);
         }
     }
 }
Exemple #10
0
    //shoot at tile
    public void Shoot(Tile tgt, AttackInstance aInstance)
    {
        float val=GridManager.GetTileSize()/4;
        offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val));

        if(tgt.unit!=null) targetUnit=tgt.unit;
        targetTile=tgt;
        targetPos=targetTile.pos+offsetPos;

        Shoot(aInstance);
    }
Exemple #11
0
    public UnitStatModifier(UnitTB unitTB)
    {
        unit = unitTB;

        int enumLength = Enum.GetValues(typeof(_PerkTypeTB)).Length;

        for (int i = 0; i < enumLength; i++)
        {
            stats.Add(new EffectValue());
        }
    }
 UnitTB[] MatchUnitPrefabListLength(UnitTB[] oldList, int count)
 {
     UnitTB[] newList = new UnitTB[count];
     for (int i = 0; i < count; i++)
     {
         if (i < oldList.Length)
         {
             newList[i] = oldList[i];
         }
     }
     return(newList);
 }
Exemple #13
0
    //for ability shootToCenter
    public void Shoot(Vector3 pos, List <Tile> allTgt, AttackInstance aInstance)
    {
        float val = GridManager.GetTileSize() / 4;

        offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val));

        targetUnit     = null;        targetTile = null;
        targetPos      = pos + offsetPos;
        targetTileList = allTgt;

        Shoot(aInstance);
    }
Exemple #14
0
    public void Shoot(UnitTB tgt, AttackInstance aInstance, bool missed)
    {
        attMissed=missed;

        float val=GridManager.GetTileSize()/(missed ? 2f : 8);
        offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val));

        targetUnit=tgt;
        if(tgt!=null) targetPos=targetUnit.GetTargetT().position+offsetPos;
        if(tgt!=null) targetTile=targetUnit.occupiedTile;

        Shoot(aInstance);
    }
Exemple #15
0
    //shoot at tile
    public void Shoot(Tile tgt, AttackInstance aInstance)
    {
        float val = GridManager.GetTileSize() / 4;

        offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val));

        if (tgt.unit != null)
        {
            targetUnit = tgt.unit;
        }
        targetTile = tgt;
        targetPos  = targetTile.pos + offsetPos;

        Shoot(aInstance);
    }
    IEnumerator _OnUnitSelected(UnitTB sUnit)
    {
        yield return(null);

        if (sUnit.IsControllable())
        {
            selectedUnit = sUnit;
            selectedID   = -1;

            UnitTB.onUnitDeselectedE += OnUnitDeselected;
            UnitTB.onUnitDestroyedE  += OnUnitDestroyed;
        }
        else
        {
            selectedUnit = null;
        }
    }
Exemple #17
0
    public void Shoot(UnitTB tgt, AttackInstance aInstance, bool missed)
    {
        attMissed = missed;

        float val = GridManager.GetTileSize() / (missed ? 2f : 8);

        offsetPos = new Vector3(Random.Range(-val, val), Random.Range(0, val / 2), Random.Range(-val, val));

        targetUnit = tgt;
        if (tgt != null)
        {
            targetPos = targetUnit.GetTargetT().position + offsetPos;
        }
        if (tgt != null)
        {
            targetTile = targetUnit.occupiedTile;
        }

        Shoot(aInstance);
    }
Exemple #18
0
    //AI routine to move a single unit
    IEnumerator _AIRoutineSingleUnit(UnitTB unit)
    {
        while (GameControlTB.IsActionInProgress())
        {
            yield return(null);
        }
        yield return(new WaitForSeconds(1f));

        unitInAction = true;
        instance.StartCoroutine(instance._MoveUnit(unit));

        //wait a frame for the unit to start moving, set the inAction flag, etc..
        yield return(null);

        while (unit.InAction() || GameControlTB.IsActionInProgress() || unitInAction)
        {
            yield return(null);
        }

        GameControlTB.OnEndTurn();
    }
Exemple #19
0
    public void Trigger(UnitTB unit)
    {
        foreach (EffectAttr effectAttr in effect.effectAttrs)
        {
            if (effectAttr.type == _EffectAttrType.PointGain)
            {
                GameControlTB.GainPoint((int)effectAttr.value);
            }
        }

        if (enableAOE && aoeRange > 1)
        {
            List <Tile> list = GridManager.GetTilesWithinRange(occupiedTile, aoeRange);
            foreach (Tile tile in list)
            {
                if (tile.unit != null)
                {
                    tile.unit.ApplyCollectibleEffect(effect);
                }
            }
        }
        else
        {
            unit.ApplyCollectibleEffect(effect);
        }


        if (triggerEffect != null)
        {
            Instantiate(triggerEffect, occupiedTile.pos, Quaternion.identity);
        }

        if (triggerAudio != null)
        {
            AudioManager.PlaySound(triggerAudio, thisT.position);
        }

        Destroy(thisObj);
    }
Exemple #20
0
 //function call to set actionInProgress flag to false
 //re-enable user input
 public static void OnActionCompleted(UnitTB unit)
 {
     actionInProgress = false;
 }
Exemple #21
0
    //for ability shootToCenter
    public void Shoot(Vector3 pos, List<Tile> allTgt, AttackInstance aInstance)
    {
        float val=GridManager.GetTileSize()/4;
        offsetPos=new Vector3(Random.Range(-val, val), Random.Range(0, val/2), Random.Range(-val, val));

        targetUnit=null;	targetTile=null;
        targetPos=pos+offsetPos;
        targetTileList=allTgt;

        Shoot(aInstance);
    }
Exemple #22
0
	public static void ChangeUnitFaction(UnitTB scUnit, int targetFactionID){
		Faction srcFaction=null;
		Faction tgtFaction=null;
		
		for(int i=0; i<instance.allFactionList.Count; i++){
			Faction faction=instance.allFactionList[i];
			if(faction.factionID==scUnit.factionID){
				srcFaction=faction;
			}
		}
		
		for(int i=0; i<instance.allFactionList.Count; i++){
			Faction faction=instance.allFactionList[i];
			if(faction.factionID==targetFactionID){
				tgtFaction=faction;
			}
		}
		
		if(srcFaction!=null && tgtFaction!=null){
			for(int i=0; i<srcFaction.allUnitList.Count; i++){
				UnitTB unit=srcFaction.allUnitList[i];
				if(unit==scUnit){
					srcFaction.allUnitList.RemoveAt(i);
				}
			}
			tgtFaction.allUnitList.Add(scUnit);
			
			scUnit.factionID=targetFactionID;
			
			if(onUnitFactionChangedE!=null) onUnitFactionChangedE(scUnit);
		}
		else{
			Debug.Log("faction doesn't exist");
		}
	}
Exemple #23
0
    public void DrawUnitMenu()
    {
        GUIStyle style = new GUIStyle();

        style.fontSize = 20;      style.fontStyle = FontStyle.Bold; style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;

        int winWidth  = 385;
        int winHeight = 550;

        int startX = Screen.width / 2 - 30;
        int startY = Screen.height / 2 - winHeight / 2;

        int rowLimit = 5;

        int row = 0;              int column = 0;

        for (int i = 0; i < 3; i++)
        {
            GUI.Box(new Rect(startX, startY, winWidth, winHeight), "");
        }



        GUI.Label(new Rect(startX, startY + 10, winWidth, winHeight), "Unit Selection", style);

        style.fontSize = 16;      style.alignment = TextAnchor.UpperLeft;
        GUI.Label(new Rect(startX + 10, startY + 45, winWidth, winHeight), "Available Units:", style);

        startX += 10;     startY += 65;

        int scrollLength = (int)(Mathf.Ceil(availableUnits.Count / rowLimit + 1) * 70);

        if (availableUnits.Count % rowLimit == 0)
        {
            scrollLength -= 70;
        }
        Rect viewRect   = new Rect(startX, startY, winWidth - 20, 280);
        Rect scrollRect = new Rect(startX, startY, winWidth - 50, scrollLength);

        GUI.Box(viewRect, "");
        scrollPosition1 = GUI.BeginScrollView(viewRect, scrollPosition1, scrollRect);

        startX += 5;      startY += 5;

        for (int i = 0; i < availableUnits.Count; i++)
        {
            if (tab == _Tab.Available && selectedID == i)
            {
                if (GUI.Button(new Rect(startX + column * 70 - 3, startY + row * 70 - 3, 66, 66), availableUnits[i].icon))
                {
                }
            }
            else
            {
                if (GUI.Button(new Rect(startX + column * 70, startY + row * 70, 60, 60), availableUnits[i].icon))
                {
                    tab        = _Tab.Available;
                    selectedID = i;
                }
            }

            column += 1;
            if (column == 5)
            {
                row += 1; column = 0;
            }
        }

        GUI.EndScrollView();

        startY += 280;

        if (tab == _Tab.Available)
        {
            if (GUI.Button(new Rect(startX + 280, startY, 80, 30), "Select", UI.buttonStyle))
            {
                UnitTB unit = availableUnits[selectedID];
                if (UISetup.playerPoint >= unit.pointCost)
                {
                    UISetup.UpdatePoints(-unit.pointCost);
                    selectedUnits.Add(unit);
                }
            }
        }
        else if (tab == _Tab.Selected)
        {
            if (GUI.Button(new Rect(startX + 280, startY, 80, 30), "Remove", UI.buttonStyle))
            {
                UISetup.UpdatePoints(selectedUnits[selectedID].pointCost);
                selectedUnits.RemoveAt(selectedID);
                if (selectedUnits.Count > 0)
                {
                    selectedID = Mathf.Max(selectedID - 1, 0);
                }
                else
                {
                    selectedID = 0;
                    tab        = _Tab.Available;
                }
            }
        }

        style.fontSize = 16;
        GUI.Label(new Rect(startX, startY + 15, winWidth, winHeight), "Selected Units:", style);

        startX -= 5;      startY += 35;

        scrollLength = (int)(Mathf.Ceil(selectedUnits.Count / rowLimit + 1) * 70);
        if (selectedUnits.Count % rowLimit == 0)
        {
            scrollLength -= 70;
        }
        viewRect   = new Rect(startX, startY, winWidth - 20, 140);
        scrollRect = new Rect(startX, startY, winWidth - 50, scrollLength);
        GUI.Box(viewRect, "");
        scrollPosition2 = GUI.BeginScrollView(viewRect, scrollPosition2, scrollRect);

        row = 0;          column = 0;

        startX += 5;              startY += 5;

        for (int i = 0; i < selectedUnits.Count; i++)
        {
            if (tab == _Tab.Selected && selectedID == i)
            {
                if (GUI.Button(new Rect(startX + column * 70 - 3, startY + row * 70 - 3, 66, 66), selectedUnits[i].icon))
                {
                }
            }
            else
            {
                if (GUI.Button(new Rect(startX + column * 70, startY + row * 70, 60, 60), selectedUnits[i].icon))
                {
                    tab        = _Tab.Selected;
                    selectedID = i;
                }
            }

            column += 1;
            if (column == 5)
            {
                row += 1; column = 0;
            }
        }

        GUI.EndScrollView();

        UnitTB selectedUnit = null;

        if (tab == _Tab.Available)
        {
            selectedUnit = availableUnits[selectedID];
        }
        else if (tab == _Tab.Selected)
        {
            selectedUnit = selectedUnits[selectedID];
        }
        DrawSelectedUnit(selectedUnit);
    }
Exemple #24
0
    public UnitStatModifier(UnitTB unitTB)
    {
        unit=unitTB;

        int enumLength = Enum.GetValues(typeof(_PerkTypeTB)).Length;
        for(int i=0; i<enumLength; i++){
            stats.Add(new EffectValue());
        }
    }
Exemple #25
0
    void OnGUI()
    {
        if (window == null)
        {
            Init();
        }

        Undo.SetSnapshotTarget(this, "UnitManagerWindow");

        int currentUnitCount = unitList.Count;

        if (GUI.Button(new Rect(window.position.width - 110, 5, 100, 25), "UnitEditor"))
        {
            this.Close();
            UnitTBEditorWindow.Init();
        }

        EditorGUI.LabelField(new Rect(5, 10, 150, 17), "Add new unit:");
        newUnit = (UnitTB)EditorGUI.ObjectField(new Rect(100, 10, 150, 17), newUnit, typeof(UnitTB), false);
        if (newUnit != null)
        {
            if (!unitList.Contains(newUnit))
            {
                int rand = 0;
                while (unitIDList.Contains(rand))
                {
                    rand += 1;
                }
                unitIDList.Add(rand);
                newUnit.prefabID = rand;

                newUnit.unitName = newUnit.gameObject.name;
                unitList.Add(newUnit);

                GUI.changed = true;
            }
            newUnit = null;
        }


        if (unitList.Count > 0)
        {
            GUI.Box(new Rect(5, 40, 50, 20), "ID");
            GUI.Box(new Rect(5 + 50 - 1, 40, 60 + 1, 20), "Icon");
            GUI.Box(new Rect(5 + 110 - 1, 40, 160 + 2, 20), "Name");
            GUI.Box(new Rect(5 + 270, 40, window.position.width - 300, 20), "");
        }

        scrollPos = GUI.BeginScrollView(new Rect(5, 60, window.position.width - 12, window.position.height - 50), scrollPos, new Rect(5, 55, window.position.width - 30, 15 + ((unitList.Count)) * 50));

        int row = 0;

        for (int i = 0; i < unitList.Count; i++)
        {
            if (i % 2 == 0)
            {
                GUI.color = new Color(.8f, .8f, .8f, 1);
            }
            else
            {
                GUI.color = Color.white;
            }
            GUI.Box(new Rect(5, 60 + i * 49, window.position.width - 30, 50), "");
            GUI.color = Color.white;

            if (currentSwapID == i)
            {
                GUI.color = new Color(.9f, .9f, .0f, 1);
            }
            if (GUI.Button(new Rect(19, 12 + 60 + i * 49, 30, 30), unitList[i].prefabID.ToString()))
            {
                if (currentSwapID == i)
                {
                    currentSwapID = -1;
                }
                else if (currentSwapID == -1)
                {
                    currentSwapID = i;
                }
                else
                {
                    SwapCreep(i);
                    GUI.changed = true;
                }
            }
            if (currentSwapID == i)
            {
                GUI.color = Color.white;
            }

            if (unitList[i] != null)
            {
                unitList[i].icon     = (Texture)EditorGUI.ObjectField(new Rect(12 + 50, 3 + 60 + i * 49, 44, 44), unitList[i].icon, typeof(Texture), false);
                unitList[i].unitName = EditorGUI.TextField(new Rect(5 + 120, 6 + 60 + i * 49, 150, 17), unitList[i].unitName);

                if (unitList[i].icon != null && unitList[i].icon.name != unitList[i].iconName)
                {
                    unitList[i].iconName = unitList[i].icon.name;
                    GUI.changed          = true;
                }

                EditorGUI.LabelField(new Rect(5 + 120, 6 + 60 + i * 49 + 20, 150, 17), "Prefab:");
                EditorGUI.ObjectField(new Rect(5 + 165, 6 + 60 + i * 49 + 20, 105, 17), unitList[i].gameObject, typeof(GameObject), false);
            }

            if (delete != i)
            {
                if (GUI.Button(new Rect(window.position.width - 55, 12 + 60 + i * 49, 25, 25), "X"))
                {
                    delete = i;
                }
            }
            else
            {
                GUI.color = Color.red;
                if (GUI.Button(new Rect(window.position.width - 90, 12 + 60 + i * 49, 60, 25), "Remove"))
                {
                    if (currentSwapID == i)
                    {
                        currentSwapID = -1;
                    }
                    unitIDList.Remove(unitList[i].prefabID);
                    unitList.RemoveAt(i);
                    delete = -1;
                    //~ if(onCreepUpdateE!=null) onCreepUpdateE();
                    GUI.changed = true;
                }
                GUI.color = Color.white;
            }

            row += 1;
        }


        GUI.EndScrollView();

        if (GUI.changed || currentUnitCount != unitList.Count)
        {
            EditorUtility.SetDirty(prefab);
            for (int i = 0; i < unitList.Count; i++)
            {
                EditorUtility.SetDirty(unitList[i]);
            }
        }

        if (GUI.changed || currentUnitCount != unitList.Count)
        {
            Undo.CreateSnapshot();
            Undo.RegisterSnapshot();
        }
        Undo.ClearSnapshotTarget();
    }
Exemple #26
0
    void OnGUI()
    {
        //if(!battleStarted) return;
                #if customGui
        GUI.skin = Resources.Load("Skins/Fantasy-Colorable") as GUISkin;
                #endif

        DrawOverlay();

        List <UnitTB> unitList = UnitControl.GetAllUnit();

        int length = 40;
        int height = 3;

        for (int i = 0; i < unitList.Count; i++)
        {
            UnitTB unit = unitList[i];

            if (GameControlTB.EnableFogOfWar())
            {
                if (!unit.IsVisibleToPlayer())
                {
                    continue;
                }
            }



#if hoverInfo
            Camera  cam       = CameraControl.GetActiveCamera();
            Vector3 screenPos = cam.WorldToScreenPoint(unitList[i].thisT.position);
            screenPos.y = Screen.height - screenPos.y;

            int startPosX = (int)(screenPos.x - length / 2 + 7);
            int startPosY = (int)screenPos.y + 5;

            float hpRatio = (float)unit.HP / (float)unit.GetFullHP() * length;
            float apRatio = (float)unit.AP / (float)unit.GetFullAP() * length;


            GUIStyle style = new GUIStyle();
            style.fontStyle = FontStyle.Bold;

            style.fontSize = 20;



            style.fontSize = 20;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(startPosX - x_offset, startPosY + y_offset, 90, 90), "\n HP:" + unit.HP + "/" + unit.GetFullHP() + "\n AP:" + unit.AP + "/" + unit.GetFullAP(), style);


            GUI.color = Color.white;
            //draw the hp and AP
            //GUI.Box(new Rect(startPosX, startPosY-20, 200, 200), UI.texBar);
#else
            Camera  cam       = CameraControl.GetActiveCamera();
            Vector3 screenPos = cam.WorldToScreenPoint(unitList[i].thisT.position);
            screenPos.y = Screen.height - screenPos.y;

            int startPosX = (int)(screenPos.x - length / 2 + 7);
            int startPosY = (int)screenPos.y + 5;

            float hpRatio = (float)unit.HP / (float)unit.GetFullHP() * length;
            float apRatio = (float)unit.AP / (float)unit.GetFullAP() * length;

            GUI.color = new Color(.5f, .5f, .5f, 1);
            GUI.DrawTexture(new Rect(startPosX - 1, startPosY - 1, length + 2, 2 * height + 2), UI.texBar);
            GUI.color = Color.green;
            //TODO: Add the numbers for AP and HP here, we have startpos X and Y, and other values
            //are calculated elsewhere
            GUI.DrawTexture(new Rect(startPosX, startPosY, hpRatio, height), UI.texBar);
            //GUI.Label(new Rect(screenPos.x, screenPos.y, 500, 500), "5555");
            GUI.color = new Color(0f, 1f, 1f, 1);
            GUI.DrawTexture(new Rect(startPosX, startPosY + height, apRatio, height), UI.texBar);
            Texture fIcon = UnitControl.GetFactionIcon(unitList[i].factionID);
            if (fIcon != null)
            {
                fIcon = UI.texBar;
            }

            GUI.color = Color.white;
            GUI.DrawTexture(new Rect(startPosX - 15, startPosY - 5, 15, 15), UI.texBar);


            GUI.color = UnitControl.GetFactionColor(unit.factionID);
            GUI.DrawTexture(new Rect(startPosX - 14, startPosY - 4, 13, 13), UI.texBar);

            GUI.color = Color.white;
#endif
        }

        if (tileHovered != null)
        {
            DrawHoverInfo();
        }
        ///Draw text box with selected unit health and AP
                #if ibox
        /*
         *
         * void ShowTooltip(UnitAbility ability){
         * GUIStyle style=new GUIStyle();
         * style.fontStyle=FontStyle.Bold;
         *
         * int width=500;
         * int height=160;
         *
         *
         * for(int i=0; i<3; i++) GUI.Box(new Rect(Screen.width/2-width/2, Screen.height-230, width, height), "");
         *
         * style.fontSize=20;	style.normal.textColor=UI.colorH;	style.alignment=TextAnchor.UpperCenter;
         * GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-220, width, height), ability.name, style);
         *
         * style.fontSize=16;	style.normal.textColor=UI.colorH;	style.alignment=TextAnchor.UpperRight;
         * GUI.Label(new Rect(Screen.width/2-width/2-5, Screen.height-220, width, height), ability.cost+"AP", style);
         *
         * style.fontSize=16;	style.normal.textColor=UI.colorN;	style.alignment=TextAnchor.UpperCenter;	style.wordWrap=true;
         * GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-190, width, height), ability.desp, style);
         *
         * GUI.color=Color.white;
         * }
         * */

        if (UnitControl.selectedUnit != null)         //only perform this calculation once every second
        //get the selected unit
        {
            UnitTB selectedUnit = UnitControl.selectedUnit;
            string name         = selectedUnit.unitName;


            Camera  cam       = CameraControl.GetActiveCamera();
            Vector3 screenPos = cam.WorldToScreenPoint(UnitControl.selectedUnit.thisT.position);
            screenPos.y = Screen.height - screenPos.y;

            int startPosX = (int)(screenPos.x - length / 2 + 7);
            int startPosY = (int)screenPos.y + 5;



            styleA.fontSize = 20;



            styleA.fontSize = 20;     styleA.normal.textColor = UI.colorH;      styleA.alignment = TextAnchor.UpperCenter;


            GUI.Box(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), "");

            GUI.Label(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), "\n HP:" + UnitControl.selectedUnit.HP + "/" + UnitControl.selectedUnit.GetFullHP() + "\n AP:" + UnitControl.selectedUnit.AP + "/" + UnitControl.selectedUnit.GetFullAP() + "\n Moves:" + UnitControl.selectedUnit.moveRemain + "\n Attacks:" + UnitControl.selectedUnit.attackRemain, styleA);


            GUI.color = Color.white;


            GUIStyle style = new GUIStyle();
            style.fontStyle = FontStyle.Bold;

            int w = w_width;
            int h = w_height;

            style.fontSize = 20;

            style.fontSize = 20;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;
#if window
            //Color c = GUI.color;
            //GUI.color = Color.red;
            //windowRect0 = GUI.Window(0,windowRect0,DoMyWindow, "Green Window");
            //GUI.color = c;

                        #if devIbox
            GUI.Box(new Rect(Screen.width / 2 - 750 / 2, -80, 750, h), "");
            GUI.Label(new Rect(Screen.width / 2 - w / 2, 0, w, h), name + " HP:" + selectedUnit.HP + " AP:" + selectedUnit.AP + " Remaining Moves:" + selectedUnit.moveRemain + " Remaining Attacks: " + selectedUnit.attackRemain, style);
#endif
#if mo
            if (timeSinceCheck > .25)
            {
                //TODO: This method is not efficient, change it later
                //get the unit position
                //get the gameObject first
                GameObject g = selectedUnit.thisObj;
                //get the camera
                Camera  c         = GameObject.Find("MainCamera").GetComponent <Camera>();
                Vector3 screenPos = camera.WorldToScreenPoint(g.transform.position);

                Debug.Log(screenPos.x + " : " + screenPos.y);
                //put a simplified version of the ibox at the unit position
                GUI.Box(new Rect(screenPos.x, screenPos.y, 100, 30), "");
                GUI.Label(new Rect(screenPos.x, screenPos.y, 100, 30), " HP:" + selectedUnit.HP + " AP:" + selectedUnit.AP, style);
            }
#endif

            //print unit information
            //GUI.Label(new Rect(Screen.width/2-250, 0, 500, 20), name+" HP:"+selectedUnit.HP+" AP:"+selectedUnit.AP+" Remaining Moves:"+selectedUnit.moveRemain +" Remaining Attacks: " +selectedUnit.attackRemain);
            if (lastCheck >= waitTime)
            {
                lastCheck = 0;
                idleUnits = totalUnits;
                //get idle units
                //get an array of their units
                p_units = UnitControl.GetAllUnitsOfFaction(p_factionId);
                //loop through the array
                foreach (UnitTB unit in p_units)
                {
                    if (unit.AreAllActionsCompleted())
                    {
                        /*GameObject g = unit.thisObj;
                         * Renderer r = g.renderer;
                         * r.material.color = Color.grey;*/
                        idleUnits--;
                    }
                    else if (false)                     //TODO: if the unit has no more moves, cannot use an ability, and cannot attack anyone

                    {
                    }
                    //if a unit has moves left, or attacks left, increment idle units
                }
            }
            else
            {
                lastCheck += Time.deltaTime;
            }
            //print idle information
            if (idleUnits == 0)
            {
                //TODO: change coords to put it right above next turn button
                //GUI.Label(new Rect(Screen.width/2-w/2, 25, w, h), "All units have exhausted their moves, hit the next turn.", style);
                //only toggle glow once per turn
                if (!messageSent)
                {
                    BroadcastMessage("toggleGlow");
                    messageSent = true;
                }
                //GUI.Label (new Rect(Screen.width/2-250, 15, 500, 20), "All units have exhausted their moves, hit the next turn.");
            }
            else
            {
                BroadcastMessage("turnoffGlow");
                GUI.Label(new Rect(Screen.width - 100, Screen.height - 65 - 20, 60, 60), idleUnits + "/" + totalUnits + " idle units", style);

                //GUI.Label (new Rect(Screen.width/2-250, 15, 500, 20),idleUnits + "/"+ totalUnits + " units still have available actions.");
            }
#else
            GUI.Box(new Rect(Screen.width / 2 - 750 / 2, -80, 750, h), "");
            GUI.Label(new Rect(Screen.width / 2 - w / 2, 0, w, h), name + " HP:" + selectedUnit.HP + " AP:" + selectedUnit.AP + " Remaining Moves:" + selectedUnit.moveRemain + " Remaining Attacks: " + selectedUnit.attackRemain, style);

            //print unit information
            //GUI.Label(new Rect(Screen.width/2-250, 0, 500, 20), name+" HP:"+selectedUnit.HP+" AP:"+selectedUnit.AP+" Remaining Moves:"+selectedUnit.moveRemain +" Remaining Attacks: " +selectedUnit.attackRemain);
            if (lastCheck >= waitTime)
            {
                lastCheck = 0;
                idleUnits = totalUnits;
                //get idle units
                //get an array of their units
                p_units = UnitControl.GetAllUnitsOfFaction(p_factionId);
                //loop through the array
                foreach (UnitTB unit in p_units)
                {
                    if (unit.AreAllActionsCompleted())
                    {
                        idleUnits--;
                    }
                    else if (false)                     //TODO: if the unit has no more moves, cannot use an ability, and cannot attack anyone

                    {
                    }
                    //if a unit has moves left, or attacks left, increment idle units
                }
            }
            else
            {
                lastCheck += Time.deltaTime;
            }
            //print idle information
            if (idleUnits == 0)
            {
                GUI.Label(new Rect(Screen.width / 2 - w / 2, 25, w, h), "All units have exhausted their moves, hit the next turn.", style);
                //GUI.Label (new Rect(Screen.width/2-250, 15, 500, 20), "All units have exhausted their moves, hit the next turn.");
            }
            else
            {
                GUI.Label(new Rect(Screen.width / 2 - w / 2, 25, w, h), idleUnits + "/" + totalUnits + " units still have available actions.", style);

                //GUI.Label (new Rect(Screen.width/2-250, 15, 500, 20),idleUnits + "/"+ totalUnits + " units still have available actions.");
            }
#endif
        }
                #endif
    }
Exemple #27
0
	//short delay before starting the counter attack action sequence
	IEnumerator CounterAttackRoutine(UnitTB srcUnit){
		//Debug.Log("counter");
		counterAttackRemain-=1;
		yield return new WaitForSeconds(0.5f);
		CounterAttack(srcUnit);
	}
Exemple #28
0
	bool ContainedInAttackerList(UnitTB unit){
		for(int i=0; i<attackerList.Count; i++){
			if(attackerList[i].unit==unit) return true;
			else if(attackerList[i]==null){
				attackerList.RemoveAt(i);
				i-=1;
			}
		}
		return false;
	}
Exemple #29
0
	IEnumerator _HitTarget(UnitTB target, AttackInstance attInstance){
		//HitResult hitResult=null;
		
		//apply the attackInfo to the target, get the hit result info in return
		if(target!=null){
			attInstance=target.ApplyHitEffect(attInstance);
		}
		
		yield return new WaitForSeconds(0.1f);
		actionQueued-=1;
		if(actionQueued<=0){
			actionQueued=0;
			
			if(attInstance!=null){
				//~ if(!hitResult.counterAttack){
					if(attInstance.type!=_AttackType.Melee_Counter && attInstance.type!=_AttackType.Range_Counter){
						//if the attack is not counter attack, complete the action using delay based on if the target is destroyed
						if(attInstance.destroyed) StartCoroutine(ActionComplete(attInstance.destroyEffectDuration));
						else if(!attInstance.counterAttacking){
							//complete action if target is not counterAttacking
							//otherwise waiting for counter attack to complete, CounterAttackComplete will be called
							StartCoroutine(ActionComplete(0.25f));
						}
					}
					//if the attack is counter attack, tell the attacker that the counter attack has been completed
					else target.CounterAttackComplete(attInstance);
				//~ }
			}
			else{
				StartCoroutine(ActionComplete(0.25f));
			}
		}
	}
Exemple #30
0
	//called by shootObject when hit the target
	public void HitTarget(UnitTB target, AttackInstance attInstance){
		StartCoroutine(_HitTarget(target, attInstance));
	}
Exemple #31
0
	//function call to set actionInProgress flag to false
	//re-enable user input
	public static void OnActionCompleted(UnitTB unit){
		actionInProgress=false;
	}
Exemple #32
0
	void OnUnitDestroyed(UnitTB unit){
		if(playerFactionExisted && !hotseat){
			if(!playerFactionID.Contains(unit.factionID)){
				GainPoint(unit.pointReward);
			}
		}
	}
Exemple #33
0
 //shoot at unit
 public void Shoot(UnitTB tgt, AttackInstance aInstance)
 {
     Shoot(tgt, aInstance, false);
 }
 void OnUnitSelected(UnitTB sUnit)
 {
     StartCoroutine(_OnUnitSelected(sUnit));
 }
Exemple #35
0
	//called when the current selected player unit has used up all available move
	public static void SwitchToNextUnitInTurn(){
		GridManager.Deselect();
		
		_TurnMode turnMode=GameControlTB.GetTurnMode();
		
		//select next unit for this round,  if all unit has been moved, start new round
		if(turnMode==_TurnMode.SingleUnitPerTurn){
			currentUnitTurnID+=1;
			if(currentUnitTurnID>=instance.allUnits.Count){
				currentUnitTurnID=-1;
				//if all unit has been moved, issue a new round,
				GameControlTB.OnNewRound();
			}
			else{
				//Unit with the highest turnPriority move first
				//all unit has been arrange in order using function ArrangeAllUnitToTurnPriority() at every new round, check OnNewRound
				//so we simply select next unit based on currentUnitTurnID
				selectedUnit=instance.allUnits[currentUnitTurnID];
				selectedUnit.occupiedTile.Select();
				
				GameControlTB.turnID=selectedUnit.factionID;
				
				if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)) AIManager.MoveUnit(selectedUnit);
				//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
			}
		}
		else if(turnMode==_TurnMode.SingleUnitRealTime || turnMode==_TurnMode.SingleUnitRealTimeNoRound){
			
			if(turnMode==_TurnMode.SingleUnitRealTime){
				if(instance.allUnitsMoved.Count==instance.allUnits.Count){
					GameControlTB.OnNewRound();
					instance.allUnitsMoved=new List<UnitTB>();
					return;
				}
			}
			
			float lowest=100000;
			instance.holdWaitedTime=false;
			UnitTB currentSelected=null;
			
			for(int i=0; i<instance.allUnits.Count; i++){
				UnitTB unit=instance.allUnits[i];
				if(unit.waitedTime<=0){
					if(unit.waitedTime==lowest) {
						instance.holdWaitedTime=true;
					}
					if(unit.waitedTime<lowest){
						lowest=unit.waitedTime;
						currentSelected=unit;
					}
				}
			}
			
			if(currentSelected==null){
				instance.OnNextTurn();
				return;
			}
			
			selectedUnit=currentSelected;
			selectedUnit.waitedTime=selectedUnit.waitingTime;
			selectedUnit.OnNewRound(0);
			selectedUnit.occupiedTile.Select();
			if(!instance.allUnitsMoved.Contains(selectedUnit)) instance.allUnitsMoved.Add(selectedUnit);
			
			GameControlTB.turnID=selectedUnit.factionID;
			
			if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)) AIManager.MoveUnit(selectedUnit);
			//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
		}
		else{
			if(turnMode==_TurnMode.FactionAllUnitPerTurn){
				//when in FactionAllUnitPerTurn
				//this section is only called when the faction in turn belongs to player
				//otherwise AIROutine is called to move all AI's units
				if(!GameControlTB.IsPlayerTurn()) return;
			}
			
			//get the faction in turn and make sure a unit has been selected successfully
			Faction faction=instance.allFactionList[GameControlTB.turnID];
			if(!instance.SelectNexUnit(faction)) return;
			
			if(turnMode!=_TurnMode.FactionAllUnitPerTurn){
				//if the selecte unit doesnt belong to player, call AI to move the unit
				if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)){
					AIManager.MoveUnit(selectedUnit);
				}
				else{
					//Debug.Log("UC unit switched, player's turn");
				}
				//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
			}
		}
	}
Exemple #36
0
	public Attacker(UnitTB attacker){
		unit=attacker;
		roundSinceLastAttack=0;
	}
Exemple #37
0
    //code execution for when a left mouse click happen on a tile and when a touch is double tap on a tile
    public void OnTouchMouseDown()
    {
                #if !UNITY_IPHONE && !UNITY_ANDROID
        if (GameControlTB.IsCursorOnUI(Input.mousePosition))
        {
            return;
        }
        //if(GameControlTB.IsObjectOnUI(pos)) return;
                #endif

        if (GameControlTB.IsUnitPlacementState())
        {
            PlaceUnit();
            return;
        }

        if (GameControlTB.GetTurnMode() != _TurnMode.SingleUnitPerTurn)
        {
            if (!GameControlTB.IsPlayerTurn())
            {
                //if(GameControlTB.turnID!=GameControlTB.GetPlayerFactionTurnID()){
                return;
            }
        }

        if (GameControlTB.IsActionInProgress())
        {
            return;
        }

        if (!walkable && !GridManager.IsInTargetTileSelectMode())
        {
            return;
        }

        UnitTB sUnit = UnitControl.selectedUnit;

        //if a friendly unit has been selected
        //if(sUnit!=null && sUnit.IsControllable(GameControlTB.GetPlayerFactionID())){
        if (sUnit != null && sUnit.IsControllable())
        {
            //if HexFridManager is actively looking for a target for current selectedUnit
            if (GridManager.IsInTargetTileSelectMode())
            {
                ManualSelect();
            }
            else
            {
                if (!walkableToSelected && !attackableToSelected)
                {
                    ManualSelect();
                }
                else
                {
                    if (attackableToSelected && unit != null)
                    {
                        sUnit.Attack(unit);
                    }
                    else if (walkableToSelected)
                    {
                        sUnit.Move(this);
                    }
                    else
                    {
                        Debug.Log("error");
                    }
                }
            }

            return;
        }
        else
        {
            ManualSelect();
        }
    }
Exemple #38
0
	//rotate to face a unit;
	//called when unit is being attack to face the attacker, or when unit is attack to face the target
	public void RotateToUnit(UnitTB unit){
		//~ if(rotateToAttacker) StartCoroutine(_RotateToAttacker(attacker));
		StartCoroutine(_RotateToUnit(unit));
	}
Exemple #39
0
 void OnUnitDestroyed(UnitTB unit)
 {
     countTillNextTurn -= 1;
 }
Exemple #40
0
	IEnumerator _RotateToUnit(UnitTB unit){
		Quaternion wantedRot=Quaternion.LookRotation(unit.occupiedTile.pos-occupiedTile.pos);
		while(true){
			thisT.rotation=Quaternion.Slerp(thisT.rotation, wantedRot, Time.deltaTime*rotateSpeed);
			if(Quaternion.Angle(thisT.rotation, wantedRot)<1){
				thisT.rotation=wantedRot;
				break;
			}
			yield return null;
		}
	}
Exemple #41
0
    void DrawSelectedUnit(UnitTB unit)
    {
        GUIStyle style = new GUIStyle();

        style.fontSize = 20;      style.fontStyle = FontStyle.Bold; style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;

        int winWidth  = 300;
        int winHeight = 550;

        int startX = Screen.width / 2 - 350;
        int startY = Screen.height / 2 - winHeight / 2;

        for (int i = 0; i < 3; i++)
        {
            GUI.Box(new Rect(startX, startY, winWidth, winHeight), "");
        }
        startX += 15;     winWidth -= 30;

        GUI.Label(new Rect(startX, startY + 10, winWidth, winHeight), unit.unitName, style);
        GUI.Label(new Rect(startX, startY + 12, winWidth, winHeight), "_________________________________________________", style);

        startY += 40;

        GUI.DrawTexture(new Rect(startX + 10, startY, 60, 60), texBar);
        GUI.DrawTexture(new Rect(startX + 13, startY + 3, 54, 54), unit.icon);
        style.alignment = TextAnchor.UpperLeft;   style.fontSize = 16;
        GUI.Label(new Rect(startX + 80, startY + 10, winWidth - 80, winHeight), "Hit Point:\nAction Point:", style);
        style.alignment = TextAnchor.UpperRight;
        GUI.Label(new Rect(startX + 80, startY + 10, winWidth - 80, winHeight), unit.fullHP + "\n" + unit.fullAP, style);

        startY += 70;

        if (infoTab == _InfoTab.General)
        {
            style.alignment = TextAnchor.UpperCenter; style.wordWrap = true;    style.normal.textColor = UI.colorN;
            GUI.Label(new Rect(startX, startY, winWidth, 100), unit.desp, style);
        }
        else
        {
            string offText  = "";
            string offVText = "";
            if (unit.attackMode == _AttackMode.Hybrid)
            {
                offText = "Damage (melee/range):\nHit (melee/range):\nCritical (melee/range):\nAttack Range";

                offVText += unit.GetMeleeDamageMin() + "-" + unit.GetMeleeDamageMax() + "/" + unit.GetRangeDamageMin() + "-" + unit.GetRangeDamageMax() + "\n";
                offVText += (unit.GetMeleeAttack() * 100).ToString("f0") + "/" + (unit.GetRangeAttack() * 100).ToString("f0") + "%" + "\n";
                offVText += (unit.GetMeleeCritical() * 100).ToString("f0") + "/" + (unit.GetRangeCritical() * 100).ToString("f0") + "%" + "\n";
                offVText += unit.GetAttackRangeMax().ToString("f0") + "\n";
            }
            else
            {
                offText = "Attack Damage:\nHit Chance:\nCritical Hit Chance:\nAttack Range:";
            }

            if (unit.attackMode == _AttackMode.Melee)
            {
                offVText += unit.GetMeleeDamageMin() + "-" + unit.GetMeleeDamageMax() + "\n";
                offVText += (unit.GetMeleeAttack() * 100).ToString("f0") + "%" + "\n";
                offVText += (unit.GetMeleeCritical() * 100).ToString("f0") + "%" + "\n";

                offVText += unit.GetAttackRangeMax().ToString("f0") + "\n";
            }
            else if (unit.attackMode == _AttackMode.Range)
            {
                offVText += unit.GetRangeDamageMin() + "-" + unit.GetRangeDamageMax() + "\n";
                offVText += (unit.GetRangeAttack() * 100).ToString("f0") + "%" + "\n";
                offVText += (unit.GetRangeCritical() * 100).ToString("f0") + "%" + "\n";

                int dist = unit.GetAttackRangeMin();
                if (dist <= 0)
                {
                    offVText += unit.GetAttackRangeMax().ToString("f0") + "\n";
                }
                else
                {
                    offVText += unit.GetRangeDamageMin() + "-" + unit.GetRangeDamageMax() + "\n";
                }
            }

            string defText  = "Armour:\nDodge Chance:\nCritical Immunity:";
            string miscText = "Mobility:\nSpeed:\nAbilities:";

            string defVText = "";
            defVText += unit.GetDmgReduc().ToString("f0") + "\n";
            defVText += (unit.GetDefend() * 100).ToString("f0") + "%" + "\n";
            defVText += (unit.GetCritDef() * 100).ToString("f0") + "%" + "\n";

            string miscVText = "";
            miscVText += unit.GetMoveRange().ToString("f0") + "\n";
            miscVText += unit.GetTurnPriority().ToString("f0") + "\n";

            style.alignment = TextAnchor.UpperLeft;   style.fontSize = 16;      style.normal.textColor = UI.colorH;
            GUI.Label(new Rect(startX, startY, winWidth, winHeight), "Offense:", style);
            style.fontSize = 12;      style.normal.textColor = UI.colorN;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), offText, style);
            style.alignment = TextAnchor.UpperRight;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), offVText, style);

            startY += 90;

            style.alignment = TextAnchor.UpperLeft;   style.fontSize = 16;      style.normal.textColor = UI.colorH;
            GUI.Label(new Rect(startX, startY, winWidth, winHeight), "Defense:", style);
            style.fontSize = 12;      style.normal.textColor = UI.colorN;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), defText, style);
            style.alignment = TextAnchor.UpperRight;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), defVText, style);

            startY += 75;

            style.alignment = TextAnchor.UpperLeft;   style.fontSize = 16;      style.normal.textColor = UI.colorH;
            GUI.Label(new Rect(startX, startY, winWidth, winHeight), "Misc:", style);
            style.fontSize = 12;      style.normal.textColor = UI.colorN;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), miscText, style);
            style.alignment = TextAnchor.UpperRight;
            GUI.Label(new Rect(startX, startY + 18, winWidth, winHeight), miscVText, style);

            startY += 65;

            List <int> abilityIDList = unit.abilityIDList;
            for (int i = 0; i < abilityIDList.Count; i++)
            {
                foreach (UnitAbility uAB in unitAbilityList)
                {
                    if (uAB.ID == abilityIDList[i])
                    {
                        GUI.DrawTexture(new Rect(15 + startX + i * 35, startY, 31, 31), texBar);
                        GUI.DrawTexture(new Rect(15 + startX + i * 35 + 2, startY + 2, 27, 27), uAB.icon);
                        GUIContent cont = new GUIContent("", uAB.ID.ToString());
                        GUI.Label(new Rect(15 + startX + i * 35, startY + 3, 25, 25), cont);
                    }
                }
            }

            startY += 40;

            if (GUI.tooltip != "")
            {
                int ID = int.Parse(GUI.tooltip);
                foreach (UnitAbility uAB in unitAbilityList)
                {
                    if (uAB.ID == ID)
                    {
                        style.alignment = TextAnchor.UpperCenter; style.wordWrap = true;
                        GUI.Label(new Rect(startX + 3, startY + 3, winWidth, 50), uAB.desp.ToString());
                    }
                }
            }
        }

        string buttonText = "Less Details";

        if (infoTab == _InfoTab.General)
        {
            buttonText = "More Details";
        }
        bool switchFlag = GUI.Button(new Rect(startX + winWidth / 2 - 60, Screen.height / 2 + winHeight / 2 - 40, 120, 30), buttonText, UI.buttonStyle);

        if (switchFlag)
        {
            if (infoTab == _InfoTab.General)
            {
                infoTab = _InfoTab.Stats;
            }
            else
            {
                infoTab = _InfoTab.General;
            }
        }
    }
    public void GenerateUnit()
    {
        Tile[]      allTilesInScene = (Tile[])FindObjectsOfType(typeof(Tile));
        List <Tile> tileList        = new List <Tile>();

        foreach (Tile tile in allTilesInScene)
        {
            tileList.Add(tile);
        }

        //clear all the unit on the grid
        for (int i = 0; i < tileList.Count; i++)
        {
            if (tileList[i].unit != null)
            {
                DestroyImmediate(tileList[i].unit.gameObject);
                tileList[i].unit = null;
            }
        }

        //first get the TBTK/Units
        Transform unitParent = null;

        foreach (Transform child in gm.transform.parent)
        {
            if (child.gameObject.name == "Units")
            {
                unitParent = child;
                break;
            }
        }

        int count = 0;

        foreach (Faction fac in gm.factionList)
        {
            foreach (FactionSpawnInfo sInfo in fac.spawnInfo)
            {
                //make sure there's no empty element in the prefab list
                bool unitPrefabFilled = true;
                if (sInfo.unitPrefabs.Length > 0)
                {
                    for (int i = 0; i < sInfo.unitPrefabs.Length; i++)
                    {
                        if (sInfo.unitPrefabs[i] == null)
                        {
                            unitPrefabFilled = false;
                        }
                    }
                }
                else
                {
                    unitPrefabFilled = false;
                }

                if (unitPrefabFilled)
                {
                    if (sInfo.unitCount > 0)
                    {
                        List <Tile> tempList = gm.GetTileWithinRect(sInfo.area);

                        for (int i = 0; i < tempList.Count; i++)
                        {
                            Tile tile = tempList[i];
                            if (tile.unit != null || !tile.walkable || tile.collectible != null)
                            {
                                tempList.RemoveAt(i);
                                i -= 1;
                            }
                        }

                        if (sInfo.spawnQuota == _SpawnQuota.UnitBased)
                        {
                            int facUnitCount = Mathf.Min(sInfo.unitCount, tempList.Count);

                            count = 0;
                            while (count < facUnitCount)
                            {
                                int  rand  = UnityEngine.Random.Range(0, tempList.Count);
                                Tile hTile = tempList[rand];

                                int        randUnit = UnityEngine.Random.Range(0, sInfo.unitPrefabs.Length);
                                GameObject unitObj  = (GameObject)PrefabUtility.InstantiatePrefab(sInfo.unitPrefabs[randUnit].gameObject);

                                unitObj.transform.position = hTile.transform.position;
                                if (unitParent != null)
                                {
                                    unitObj.transform.parent = unitParent;
                                }

                                int rotationOption = sInfo.unitRotation - 1;
                                if (rotationOption == -1)
                                {
                                    unitObj.transform.rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 6) * 60, 0);
                                }
                                else
                                {
                                    unitObj.transform.rotation = Quaternion.Euler(0, rotationOption * 60, 0);
                                }

                                UnitTB unit = unitObj.GetComponent <UnitTB>();
                                unit.factionID    = fac.factionID;
                                unit.occupiedTile = hTile;
                                hTile.unit        = unit;
                                unitObj.name      = "Gen" + unit.factionID + "_" + unit.unitName + "_" + count.ToString();

                                EditorUtility.SetDirty(hTile);
                                EditorUtility.SetDirty(unit);

                                tempList.RemoveAt(rand);
                                if (tempList.Count == 0)
                                {
                                    break;
                                }

                                count += 1;
                            }
                        }
                        else
                        {
                            int budget          = sInfo.budget;
                            int lowestUnitPoint = 99999999;
                            for (int i = 0; i < sInfo.unitPrefabs.Length; i++)
                            {
                                if (sInfo.unitPrefabs[i].pointCost < lowestUnitPoint)
                                {
                                    lowestUnitPoint = sInfo.unitPrefabs[i].pointCost;
                                }
                            }
                            while (budget >= lowestUnitPoint)
                            {
                                int  rand  = UnityEngine.Random.Range(0, tempList.Count);
                                Tile hTile = tempList[rand];

                                int        randUnit = UnityEngine.Random.Range(0, sInfo.unitPrefabs.Length);
                                GameObject unitObj  = (GameObject)PrefabUtility.InstantiatePrefab(sInfo.unitPrefabs[randUnit].gameObject);

                                unitObj.transform.position = hTile.transform.position;
                                if (unitParent != null)
                                {
                                    unitObj.transform.parent = unitParent;
                                }

                                int rotationOption = sInfo.unitRotation - 1;
                                if (rotationOption == -1)
                                {
                                    unitObj.transform.rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 6) * 60, 0);
                                }
                                else
                                {
                                    unitObj.transform.rotation = Quaternion.Euler(0, rotationOption * 60, 0);
                                }

                                UnitTB unit = unitObj.GetComponent <UnitTB>();
                                unit.factionID    = fac.factionID;
                                unit.occupiedTile = hTile;
                                hTile.unit        = unit;
                                unitObj.name      = "Gen" + unit.factionID + "_" + unit.unitName + "_" + count.ToString();

                                EditorUtility.SetDirty(hTile);
                                EditorUtility.SetDirty(unit);

                                tempList.RemoveAt(rand);
                                if (tempList.Count == 0)
                                {
                                    break;
                                }

                                budget -= Mathf.Max(1, unit.pointCost);
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log("unit assignment error for faction: " + fac.factionID);
                }
            }
        }
    }
Exemple #43
0
 //shoot at unit
 public void Shoot(UnitTB tgt, AttackInstance aInstance)
 {
     Shoot(tgt, aInstance, false);
 }
Exemple #44
0
 void OnActionCompleted(UnitTB unit)
 {
     UnitTB.onActionCompletedE -= OnActionCompleted;
     StartCoroutine(_OnActionCompleted());
 }
Exemple #45
0
	/*
	//place unit at a tile
	public static void PlaceUnitAt(Tile tile){
		if(instance.startingUnit.Count==0) return;
		
		if(instance.startingUnit[instance.unitPlacementID]==null){
			instance.startingUnit.RemoveAt(instance.unitPlacementID);
			if(instance.unitPlacementID>=instance.startingUnit.Count){
				instance.unitPlacementID-=1;
			}
			return;
		}
		
		UnitTB unit=instance.startingUnit[instance.unitPlacementID];
		unit.transform.position=tile.thisT.position;
		unit.occupiedTile=tile;
		tile.unit=unit;
		instance.startingUnit.RemoveAt(instance.unitPlacementID);
		instance.allUnits.Add(unit);
		
		GridManager.PlaceUnitAt(tile);
		
		if(instance.unitPlacementID>=instance.startingUnit.Count){
			instance.unitPlacementID-=1;
		}
		
		//Debug.Log(instance.unitPlacementID);

		if(onPlacementUpdateE!=null) onPlacementUpdateE();
	}
	//remove a unit from the grid
	public static void RemoveUnit(UnitTB unit){
		GridManager.RemoveUnitAt(unit.occupiedTile);
		
		instance.startingUnit.Insert(0, unit);
		unit.occupiedTile.unit=null;
		unit.occupiedTile=null;
		unit.transform.position=new Vector3(0, 9999, 0);
		instance.allUnits.Remove(unit);
		
		if(instance.unitPlacementID<0) instance.unitPlacementID=0;
		
		if(onPlacementUpdateE!=null) onPlacementUpdateE();
	}
	
	public static void AutoPlaceUnit(){
		instance._AutoPlaceUnit();
	}
	public void _AutoPlaceUnit(){
		List<Tile> tileList=GridManager.GetAllPlaceableTiles();
		
		//to make sure there's sufficient tile
		//if(tileList.Count<startingUnit.Count){
		//	Debug.Log("not enough space");
		//	return;
		//}
		
		while(startingUnit.Count>0){
			int ID=Random.Range(0, tileList.Count);
			PlaceUnitAt(tileList[ID]);	//tileList will be remove at GridManager when unit is placed
			if(tileList.Count<=0) break;
		}
	}
	
	private int unitPlacementID=0;
	public static int GetUnitPlacementID(){
		return instance.unitPlacementID;
	}
	public static void NextUnitPlacementID(){
		instance.unitPlacementID+=1;
		if(instance.unitPlacementID>=instance.startingUnit.Count) instance.unitPlacementID=0;
	}
	//~ public static void ResetUnitPlacementID(){
		//~ instance.unitPlacementID=0;
	//~ }
	
	public static bool IsAllUnitPlaced(){
		if(instance.startingUnit.Count==0) return true;
		return false;
	}
	*/
	
	//to place a unit in runtime, untested, will probably cause issue with certain turnMode
	public static void InsertUnit(UnitTB unit, Tile tile, int factionID, int duration){
		if(unit==null){
			Debug.Log("no unit is specified");
			return;
		}
		
		if(tile.unit!=null){
			Debug.Log("tile is occupied");
			return;
		}
		
		GameObject unitObj=(GameObject)Instantiate(unit.gameObject);
		unit=unitObj.GetComponent<UnitTB>();
		unit.SetSpawnInGameFlag(true);
		if(duration>0) unit.SetSpawnDuration(duration);
		
		//if(unit.occupiedTile!=null){
		//	unit.occupiedTile.unit=null;
		//}
		
		unit.factionID=factionID;
		
		unit.transform.position=tile.thisT.position;
		unit.occupiedTile=tile;
		tile.unit=unit;
		
		for(int i=0; i<instance.allFactionList.Count; i++){
			Faction faction=instance.allFactionList[i];
			if(faction.factionID==factionID){
				faction.allUnitList.Add(unit);
				break;
			}
		}
		
		instance.allUnits.Add(unit);
		
		if(onNewUnitInRuntimeE!=null) onNewUnitInRuntimeE(unit);
		
		selectedUnit.occupiedTile.Select();
	}
Exemple #46
0
	public float GetTotalHitChanceRange(UnitTB target){
		float coverBonus=0;
		if(GameControlTB.EnableCover()) coverBonus=target.occupiedTile.GetCoverDefendBonus(occupiedTile.pos);
		return Mathf.Clamp(GetRangeAttack()-(target.GetDefend()+coverBonus), 0, 1);
	}
Exemple #47
0
	//remove a unit from the grid
	public static void RemoveUnit(UnitTB unit){
		GridManager.RemoveUnitAt(unit.occupiedTile);
		
		instance.playerUnits[instance.facPlacementID].starting.Insert(0, unit);
		unit.occupiedTile.unit=null;
		unit.occupiedTile=null;
		unit.transform.position=new Vector3(0, 9999, 0);
		instance.allUnits.Remove(unit);
		
		if(instance.unitPlacementID<0) instance.unitPlacementID=0;
		
		if(onPlacementUpdateE!=null) onPlacementUpdateE();
	}
Exemple #48
0
	//called to register that a unit has been moved
	//registered which unit has been moved for each faction so they wont been selected again in the same round
	public static void MoveUnit(UnitTB unit){
		if(GameControlTB.GetMoveOrder()!=_MoveOrder.Free) return;
		
		bool match=false;
		
		//get the matching faction
		for(int n=0; n<instance.allFactionList.Count; n++){
			if(unit.factionID==instance.allFactionList[n].factionID){
				//get the matching unit
				for(int i=0; i<instance.allFactionList[n].allUnitList.Count; i++){
					if(instance.allFactionList[n].allUnitList[i]==unit){
						//~ if(unit.IsAllActionCompleted()){
							//remove the unit ID form yetToMove list
							instance.allFactionList[n].unitYetToMove.Remove(i);
							//instance.allFactionList[n].numOfUnitMoved+=1;
							if(instance.allFactionList[n].unitYetToMove.Count==0)
								instance.allFactionList[n].allUnitMoved=true;
						//~ }
						
						match=true;
						break;
					}
				}
			}
		}
		
		if(!match) Debug.Log("Error: no unit found trying to registered a unit moved ");
	}
Exemple #49
0
	public float GetTotalCritChanceRange(UnitTB target){
		float critBonus=0;
		if(GameControlTB.EnableCover()){
			if(target.occupiedTile.GetCoverDefendBonus(occupiedTile.pos)<=0) critBonus=GameControlTB.GetExposedCritBonus();
		}
		return Mathf.Clamp((GetRangeCritical()+critBonus)-target.GetCritDef(), 0, 1);
	}
Exemple #50
0
	public void Process(UnitTB unit){
		processed=true;
		
		targetUnit=unit;
		
		Tile targetTile=targetUnit.occupiedTile;
		
		//get cover bonus of the unit if cover is enabled for the game
		float coverDefBonus=0;
		float exposedCritBonus=0;
		if(GameControlTB.EnableCover()){
			coverDefBonus=targetTile.GetCoverDefendBonus(srcUnit.occupiedTile.pos);
			if(coverDefBonus<=0){
				exposedCritBonus=GameControlTB.GetExposedCritBonus();
			}
		}
		
		float attack=0;
		int damageType=0;
		if(type==_AttackType.Range_Normal || type==_AttackType.Range_Counter){
			attack=srcUnit.GetRangeAttack();
			damageType=srcUnit.damageTypeRange;
		}
		else if(type==_AttackType.Melee_Normal || type==_AttackType.Melee_Counter){
			attack=srcUnit.GetMeleeAttack();
			damageType=srcUnit.damageTypeMelee;
		}
		
		if(type==_AttackType.Range_Counter || type==_AttackType.Melee_Counter){
			isCounterAttack=true;
		}
		
		//calculate if the attack hits
		float missChance=(1-attack)+targetUnit.GetDefend()+coverDefBonus;
		if(Random.Range(0f, 1f)<Mathf.Max(0.0f, missChance)){
			if(!isCounterAttack) Debug.Log(srcUnit.unitName+" attacked "+targetUnit.unitName+" and missed");
			else Debug.Log(srcUnit.unitName+" counter-attack "+targetUnit.unitName+" and missed");
			missed=true;
			return;
		}
		
		//get the damage modifier from the damagetable based on the unit armorType and the attacking damageType
		float modifier=DamageTable.GetModifier(targetUnit.armorType, damageType);
		int dmg=0;
		
		float dmgMin=0;
		float dmgMax=0;
		float critChance=0;
		
		if(type==_AttackType.Range_Normal){
			dmgMin=srcUnit.GetRangeDamageMin();
			dmgMax=srcUnit.GetRangeDamageMax();
			critChance=srcUnit.GetRangeCritical();
		}
		else if(type==_AttackType.Melee_Normal){
			dmgMin=srcUnit.GetMeleeDamageMin();
			dmgMax=srcUnit.GetMeleeDamageMax();
			critChance=srcUnit.GetMeleeCritical();
		}
		else if(type==_AttackType.Range_Counter){
			dmgMin=(int)((float)srcUnit.GetRangeDamageMin()*srcUnit.GetCounterDmgModifier());
			dmgMax=(int)((float)srcUnit.GetRangeDamageMax()*srcUnit.GetCounterDmgModifier());
			critChance=srcUnit.GetRangeCritical();
		}
		else if(type==_AttackType.Melee_Counter){
			dmgMin=(int)((float)srcUnit.GetMeleeDamageMin()*srcUnit.GetCounterDmgModifier());
			dmgMax=(int)((float)srcUnit.GetMeleeDamageMax()*srcUnit.GetCounterDmgModifier());
			critChance=srcUnit.GetMeleeCritical();
		}
		
		//calculate if the attack crits
		if(Random.Range(0f, 1f)<=critChance+exposedCritBonus){
			dmg=(int)((float)dmgMax*Random.Range(1.5f, 2f));
			dmg=(int)((float)dmg*modifier);
			critical=true;
			if(!isCounterAttack) Debug.Log(srcUnit.unitName+" attacked "+targetUnit.unitName+" for "+dmg+" (critical)");
			else Debug.Log(srcUnit.unitName+" counter-attack "+targetUnit.unitName+" for "+dmg+" (critical)");
		}
		else{
			dmg=(int)((float)Random.Range(dmgMin, dmgMax+1)*modifier);
			if(!isCounterAttack) Debug.Log(srcUnit.unitName+" attacked "+targetUnit.unitName+" for "+dmg+" ");
			else Debug.Log(srcUnit.unitName+" counter-attack "+targetUnit.unitName+" for "+dmg+" ");
		}
		
		damageDone=dmg;
		destroyed=dmg>=targetUnit.HP ? true : false;
		destroyEffectDuration=targetUnit.destroyEffectDuration;
	}
Exemple #51
0
	//switch to next unit in turn, return true if there's a next unit exist for the faction, false if otherwise
	bool SelectNexUnit(Faction faction){
		//make sure there is unit to be selected
		if(faction.allUnitList.Count==0){
			Debug.Log("Error, UnitControl tried to select unit from empty faction");
			faction.allUnitMoved=true;
			GameControlTB.OnEndTurn();
			return false;
		}
		
		//make sure there is unit to be selected
		if(faction.allUnitMoved){
			Debug.Log("Error, UnitControl tried to select unit from faction with all unit moved");
			GameControlTB.OnEndTurn();
			return false;
		}
		
		//if move order is free, randomly select a unit
		if(GameControlTB.GetMoveOrder()==_MoveOrder.Free){
			int rand=UnityEngine.Random.Range(0, faction.unitYetToMove.Count);
			faction.currentTurnID=faction.unitYetToMove[rand];
		}
		
		//select the unit
		selectedUnit=faction.allUnitList[faction.currentTurnID];
		selectedUnit.occupiedTile.Select();
		
		if(GameControlTB.GetMoveOrder()!=_MoveOrder.Free){
			//move the currentTurnID so in the next turn, the next unit in line will be selected
			faction.currentTurnID+=1;
			if(faction.currentTurnID>=faction.allUnitList.Count){
				faction.currentTurnID=0;
				//faction.numOfUnitMoved+=1;
				faction.allUnitMoved=true;
			}
		}
		
		return true;
	}
Exemple #52
0
	//function call to attack a target(groups), could be a direct attack or a shoot action for certain UnitAbility
	//this put the unit into action and locks any further player input until the action is complete
	//can do single or multiple target, with or without 
	public bool Attack(UnitTB target){ return Attack(target.occupiedTile); }
 void OnUnitDeselected()
 {
     selectedUnit              = null;
     UnitTB.onUnitDeselectedE -= OnUnitDeselected;
     UnitTB.onUnitDestroyedE  -= OnUnitDestroyed;
 }
Exemple #54
0
	//similar to attack(), but called when unit is performing an counter attack
	public void CounterAttack(UnitTB target){
		List<Tile> targetTileList=new List<Tile>();
		targetTileList.Add(target.occupiedTile);
		
		AttackInstance attInstance=new AttackInstance();
		attInstance.srcUnit=this;
		
		if(attackMode==_AttackMode.Melee){
			attInstance.type=_AttackType.Melee_Counter;
			StartCoroutine(AttackRoutineMelee(targetTileList, attInstance));
		}
		else if(attackMode==_AttackMode.Range){
			attInstance.type=_AttackType.Range_Counter;
			StartCoroutine(AttackRoutineRange(targetTileList, attInstance));
		}
		else if(attackMode==_AttackMode.Hybrid){
			int dist=AStar.Distance(occupiedTile, targetTileList[0]);
			if(dist<=attackRangeMelee){
				attInstance.type=_AttackType.Melee_Counter;
				StartCoroutine(AttackRoutineMelee(targetTileList, attInstance));
			}
			else{
				attInstance.type=_AttackType.Range_Counter;
				StartCoroutine(AttackRoutineRange(targetTileList, attInstance));
			}
		}
	}
Exemple #55
0
    void DrawHoverInfo()
    {
        UnitTB selectedUnit = UnitControl.selectedUnit;

#if hoverHP
        if (tileHovered.unit != null)
        {
            //draw hp and AP for unit
            UnitTB hUnit = tileHovered.unit;

            Camera  camA       = CameraControl.GetActiveCamera();
            Vector3 screenPosA = camA.WorldToScreenPoint(hUnit.thisT.position);
            screenPosA.y = Screen.height - screenPosA.y;

            int startPosX = (int)(screenPosA.x - 40 / 2 + 7);
            int startPosY = (int)screenPosA.y + 5;

            styleA.fontSize = 20;     styleA.normal.textColor = UI.colorH;      styleA.alignment = TextAnchor.UpperCenter;
            GUI.Box(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), "");

            GUI.Label(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), "\n HP:" + hUnit.HP + "/" + hUnit.GetFullHP() + "\n AP:" + hUnit.AP + "/" + hUnit.GetFullAP() + "\n Moves:" + hUnit.moveRemain + "\n Attacks:" + hUnit.attackRemain, styleA);
        }
#endif
        if (tileHovered.attackableToSelected)
        {
            UnitTB unit = tileHovered.unit;

            int    dmgMin = 0, dmgMax = 0;
            string hit = "", crit = "";

            int dist = GridManager.Distance(tileHovered, selectedUnit.occupiedTile);

            int   armorType   = unit.armorType;
            int   damageType  = selectedUnit.damageType;
            float dmgModifier = DamageTable.GetModifier(armorType, damageType);

            if (dist == 1 && selectedUnit.attackMode != _AttackMode.Range)
            {
                dmgMin = (int)((float)selectedUnit.GetMeleeDamageMin() * dmgModifier);
                dmgMax = (int)((float)selectedUnit.GetMeleeDamageMax() * dmgModifier);

                hit  = (selectedUnit.GetTotalHitChanceMelee(unit) * 100).ToString("f0") + "%";
                crit = (selectedUnit.GetTotalCritChanceMelee(unit) * 100).ToString("f0") + "%";
            }
            else
            {
                dmgMin = (int)((float)selectedUnit.GetRangeDamageMin() * dmgModifier);
                dmgMax = (int)((float)selectedUnit.GetRangeDamageMax() * dmgModifier);

                hit  = (selectedUnit.GetTotalHitChanceRange(unit) * 100).ToString("f0") + "%";
                crit = (selectedUnit.GetTotalCritChanceRange(unit) * 100).ToString("f0") + "%";
            }

            string text = "";
            text += hit + "chance to hit\n";
            text += "Damage: " + dmgMin + "-" + dmgMax + "\n\n";
            if (crit != "0%")
            {
                text += "Critical Chance: " + crit;
            }


            bool counter = false;
            if (GameControlTB.IsCounterAttackEnabled())
            {
                if (dist >= unit.GetAttackRangeMin() && dist <= unit.GetAttackRangeMax() && unit.counterAttackRemain > 0)
                {
                    counter = true;
                }
            }

            int cost = 0;
            if (GameControlTB.AttackAPCostRule() == _AttackAPCostRule.PerAttack)
            {
                cost = selectedUnit.APCostAttack;
            }

            GUIStyle style = new GUIStyle();
            style.fontStyle = FontStyle.Bold;

#if mousePos
            int width    = 500;
            int w_offset = 50;
            int height   = 160;
            int h_offset = 20;


            //get pos X and Y once every second to prevent flicker
            getMousePos();

            /*for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width+w_offset)/2, posY-230, width+w_offset, height), "");
             *
             * style.fontSize=20;	style.normal.textColor=UI.colorH;	style.alignment=TextAnchor.UpperCenter;
             * GUI.Label(new Rect(posX-width/2, posY-240, width, height), ability.name, style);
             *
             * style.fontSize=16;	style.normal.textColor=UI.colorH;	style.alignment=TextAnchor.UpperRight;
             * GUI.Label(new Rect(posX-width/2-5, posY-240, width, height), ability.cost+"AP", style);
             *
             * style.fontSize=16;	style.normal.textColor=UI.colorN;	style.alignment=TextAnchor.UpperCenter;	style.wordWrap=true;
             * GUI.Label(new Rect(posX-width/2, posY-190, width, height), ability.desp, style);
             *
             * GUI.color=Color.white;*/

            //for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width +w_offset)/2, posY, width+w_offset, height), "");


            GUI.Box(new Rect(posX - (width / 2) / 2, Screen.height - posY + 40, width / 2, height - 20), "");       // to remove flicker comment out this line

            style.fontSize = 20;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(posX - (width) / 2, Screen.height - posY + 40 + h_offset, width, height), "Attack", style);


            if (cost > 0)
            {
                style.fontSize = 16;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperRight;
                GUI.Label(new Rect(posX - width / 2 - 5, Screen.height - posY + 50 + h_offset, width, height), cost + "AP", style);
            }

            //reposition to be at location of mouse
            style.fontSize = 16;      style.normal.textColor = UI.colorN;       style.alignment = TextAnchor.UpperCenter; style.wordWrap = true;
            GUI.Label(new Rect(posX - width / 2, Screen.height - posY + 60 + h_offset, width, height), text, style);
            if (counter)
            {
                style.fontSize = 14;      style.normal.textColor = UI.colorH;       style.wordWrap = false;
                GUI.Label(new Rect(posX - width / 2, Screen.height - posY + 40 + h_offset, width, height), "Target will counter attack", style);
            }
#else
            int width  = 500;
            int height = 160;
            for (int i = 0; i < 3; i++)
            {
                GUI.Box(new Rect(Screen.width / 2 - width / 2, Screen.height - 230, width, height), "");
            }

            style.fontSize = 20;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 240, width, height), "Attack", style);

            if (cost > 0)
            {
                style.fontSize = 16;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperRight;
                GUI.Label(new Rect(Screen.width / 2 - width / 2 - 5, Screen.height - 220, width, height), cost + "AP", style);
            }

            //reposition to be at location of mouse
            style.fontSize = 16;      style.normal.textColor = UI.colorN;       style.alignment = TextAnchor.UpperCenter; style.wordWrap = true;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 190, width, height), text, style);
            if (counter)
            {
                style.fontSize = 14;      style.normal.textColor = UI.colorH;       style.wordWrap = false;
                GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 120, width, height), "Target will counter attack", style);
            }
#endif

            GUI.color = Color.white;
        }
        else
        {
            if (tileHovered.walkableToSelected && selectedUnit != null)
            {
                //Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos);
                //hoverObject.transform.localPosition=screenPos+new Vector3(-40, 40, 0);

                List <Vector3> list = AStar.SearchWalkablePos(tileHovered, selectedUnit.occupiedTile);
                int            dist = list.Count;
                string         text = "Move: " + (dist * selectedUnit.APCostMove) + "AP";
                //string text="Move: "+Random.Range(0, 9999)+"AP";
                GUIContent cont = new GUIContent(text);

                GUI.color = Color.white;
                GUIStyle style = new GUIStyle();
                style.fontStyle        = FontStyle.Bold;
                style.fontSize         = 16;
                style.normal.textColor = UI.colorN;
                style.alignment        = TextAnchor.LowerRight;

                Camera  cam       = CameraControl.GetActiveCamera();
                Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos);
                screenPos.y = Screen.height - screenPos.y;

                float widthMin = 0; float widthMax = 0;
                style.CalcMinMaxWidth(cont, out widthMin, out widthMax);
#if ibox
#else
                GUI.Box(new Rect(screenPos.x - widthMax - 50, screenPos.y - 50, widthMax + 25, 22), "");
                GUI.Label(new Rect(screenPos.x - widthMax - 50, screenPos.y - 50, widthMax + 25 - 4, 20), text, style);
#endif
            }
        }
    }
Exemple #56
0
 void OnUnitDestroyed(UnitTB unit)
 {
     countTillNextTurn-=1;
 }
Exemple #57
0
	public float GetTotalCritChanceMelee(UnitTB target){
		return Mathf.Clamp(GetMeleeCritical()-target.GetCritDef(), 0, 1);
	}
Exemple #58
0
    void OnGUI()
    {
        List <UnitTB> list = UnitControl.GetUnplacedUnit();

        GUIStyle style = new GUIStyle();

        style.fontStyle = FontStyle.Bold;

        int width  = 500;
        int height = 180;

        if (list.Count > 0)
        {
            UnitTB sUnit = list[UnitControl.GetUnitPlacementID()];

            for (int i = 0; i < 3; i++)
            {
                GUI.Box(new Rect(Screen.width / 2 - width / 2, Screen.height - 185, width, height), "");
            }

            GUI.DrawTexture(new Rect(Screen.width / 2 - width / 2 + 25, Screen.height - 180 - 40, 60, 60), UI.texBar);
            GUI.DrawTexture(new Rect(Screen.width / 2 - width / 2 + 25 + 2, Screen.height - 180 - 40 + 2, 56, 56), sUnit.icon);

            style.fontSize = 20;      style.normal.textColor = UI.colorH;       style.alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 180, width, height), sUnit.unitName, style);

            style.fontSize = 16;      style.normal.textColor = UI.colorN;       style.alignment = TextAnchor.UpperCenter; style.wordWrap = true;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 150, width, height), sUnit.desp, style);

            style.fontSize = 16; style.normal.textColor = UI.colorH; style.wordWrap = false;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 30, width, height), "Units to be deployed: " + list.Count, style);


            GUI.color = Color.white;

            if (GUI.Button(new Rect(Screen.width / 2 - width / 2 + 10, Screen.height - 50, 50, 40), "<<-", UI.buttonStyle))
            {
                UnitControl.PrevUnitPlacementID();
            }
            if (GUI.Button(new Rect(Screen.width / 2 + width / 2 - 100, Screen.height - 50, 50, 40), "->>", UI.buttonStyle))
            {
                UnitControl.NextUnitPlacementID();
            }


            if (GUI.Button(new Rect(Screen.width - 100, Screen.height - 65, 60, 60), "Auto\nPlace", UI.buttonStyle))
            {
                UnitControl.AutoPlaceUnit();
            }
        }
        else
        {
            style.fontSize = 16; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 30, width, height), "All units had been deployed", style);

            if (GUI.Button(new Rect(Screen.width - 100, Screen.height - 65, 60, 60), "Start\nBattle", UI.buttonStyle))
            {
                if (UnitControl.GetPlayerUnitsRemainng() == 1 && UnitControl.IsFactionAllUnitPlaced())
                {
                    GameControlTB.UnitPlacementCompleted();
                    this.enabled = false;
                }
                //if all unit for this faction is done, move to next faction
                else if (UnitControl.IsFactionAllUnitPlaced())
                {
                    UnitControl.NextFactionPlacementID();
                }
                //if not all unit has been placed, prompt player to place the remaining unit
                else
                {
                    //UINGUI.DisplayMessage("You must place all your unit first!");
                }
            }
        }
    }
Exemple #59
0
//*************************************************************************************************************************//
//code related fog of war system, wip
	
	//public List<Tile> currentTileInLOS=new List<Tile>();
	
	//call to check LOS against the unit that moved
	void OnCheckFogOfWar(UnitTB unit){
		if(factionID==unit.factionID) return;
		
		if(GameControlTB.EnableFogOfWar()){
			if(unit.factionID==GameControlTB.GetPlayerFactionID()){
				AIUnitCheckFogOfWar();
			}
		}
	}
Exemple #60
0
	public int GetAbilityDisabled(){ return Mathf.Max(0, abilityDisabled); }//+occupiedTile.abilityDisabled); }
	
	//called by attacker to check potential value of each corresponding function call
	public float GetTotalHitChanceMelee(UnitTB target){
		return Mathf.Clamp(GetMeleeAttack()-target.GetDefend(), 0, 1);
	}