Exemple #1
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;
            }
        }
    }
Exemple #2
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 #3
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);
	}
Exemple #4
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 #5
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;
        }
    }