Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-280] Display Energy bar in Battle #420

Merged
merged 15 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 221 additions & 3 deletions client/Assets/Prefabs/Battle/BattleUnit.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,82 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &1711706312681030860
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1230777893496735476}
- component: {fileID: 4397552751306858085}
- component: {fileID: 2540388736762725858}
m_Layer: 5
m_Name: Border
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1230777893496735476
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1711706312681030860}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6353291099953772284}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4397552751306858085
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1711706312681030860}
m_CullTransparentMesh: 1
--- !u!114 &2540388736762725858
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1711706312681030860}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: c5214e3b9b037422ab191b57c26ffb64, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &1744308311795233923
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -147,7 +223,83 @@ MonoBehaviour:
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 0
m_FillAmount: 0.783
m_FillAmount: 0.685
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &3108773769024406539
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 206470469946566632}
- component: {fileID: 7405282455269013799}
- component: {fileID: 1274785858004499842}
m_Layer: 5
m_Name: Fills
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &206470469946566632
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3108773769024406539}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6353291099953772284}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -4, y: -4}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7405282455269013799
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3108773769024406539}
m_CullTransparentMesh: 1
--- !u!114 &1274785858004499842
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3108773769024406539}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0.40392157, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 9473d13d17cfd594cb938b0234fec104, type: 3}
m_Type: 3
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 0
m_FillAmount: 0.27
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
Expand Down Expand Up @@ -182,7 +334,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8610322166662081407}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &3092753279982904866
AudioSource:
Expand Down Expand Up @@ -338,6 +490,69 @@ MonoBehaviour:
m_FillSizing: 0
m_MinWidth: 0
m_MaxWidth: 100
m_FillAmount: 0.685
m_Steps: 0
onChange:
m_PersistentCalls:
m_Calls: []
--- !u!1 &6547873414234776225
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6353291099953772284}
- component: {fileID: 3482965783341462380}
m_Layer: 5
m_Name: EnergyBar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6353291099953772284
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6547873414234776225}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 206470469946566632}
- {fileID: 1230777893496735476}
m_Father: {fileID: 8610322166662081407}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 140.1}
m_SizeDelta: {x: 0, y: 10}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &3482965783341462380
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6547873414234776225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 373415518a0b7b947977a3d9880aca41, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Type: 0
m_TargetImage: {fileID: 1274785858004499842}
m_Sprites: []
m_TargetTransform: {fileID: 0}
m_FillSizing: 0
m_MinWidth: 0
m_MaxWidth: 100
m_FillAmount: 0
m_Steps: 0
onChange:
Expand Down Expand Up @@ -525,7 +740,7 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8610322166662081407}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
Expand Down Expand Up @@ -918,6 +1133,7 @@ RectTransform:
- {fileID: 4910767040816234159}
- {fileID: 8610322166391184613}
- {fileID: 6149935612273939157}
- {fileID: 6353291099953772284}
- {fileID: 2169300769376718971}
- {fileID: 8758104530661023705}
m_Father: {fileID: 0}
Expand Down Expand Up @@ -1006,9 +1222,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
unitImage: {fileID: 8328940659209088198}
healthBar: {fileID: 994135883094543766}
energyBar: {fileID: 3482965783341462380}
indicatorPrefab: {fileID: 8573289930963585773, guid: 5928aa16c7d1040f082d680abccbf5b3, type: 3}
canvasGroup: {fileID: 5847183632047591615}
AttackSFX: {fileID: 3092753279982904866}
isPlayerTeam: 0
--- !u!225 &5847183632047591615
CanvasGroup:
m_ObjectHideFlags: 0
Expand Down
28 changes: 28 additions & 0 deletions client/Assets/Scripts/Battle/BattleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class BattleManager : MonoBehaviour

private bool continuePlayback = true;

private const int MAX_ENERGY = 500;

void Start()
{
victorySplash.SetActive(false);
Expand Down Expand Up @@ -65,6 +67,7 @@ private IEnumerator Battle()
yield return new WaitUntil(() => battleResult != null);

SetUpInitialState(battleResult);

yield return StartCoroutine(PlayOutSteps(battleResult.Steps));

projectilesPooler.ClearProjectiles();
Expand All @@ -85,6 +88,8 @@ private void SetUpInitialState(Protobuf.Messages.BattleResult battleResult)
battleUnit.gameObject.SetActive(true);
battleUnit.MaxHealth = unit.Health;
battleUnit.CurrentHealth = unit.Health;
battleUnit.MaxEnergy = MAX_ENERGY;
battleUnit.CurrentEnergy = unit.Energy;
}
}

Expand Down Expand Up @@ -114,6 +119,13 @@ private IEnumerator PlayOutSteps(RepeatedField<Protobuf.Messages.Step> steps)
case Protobuf.Messages.Action.ActionTypeOneofCase.Death:
battleUnitsUI.Where(battleUnit => battleUnit.SelectedUnit != null).Single(unit => unit.SelectedUnit.id == action.Death.UnitId).DeathFeedback();
break;
case Protobuf.Messages.Action.ActionTypeOneofCase.EnergyRegen:
BattleUnit unit = battleUnitsUI.Single(unit => unit.SelectedUnit != null && unit.SelectedUnit.id == action.EnergyRegen.TargetId);
unit.CurrentEnergy = Math.Min(unit.CurrentEnergy + (int)action.EnergyRegen.Amount, MAX_ENERGY);
break;
case Protobuf.Messages.Action.ActionTypeOneofCase.StatOverride:
StatOverride(action);
break;
default:
break;
}
Expand Down Expand Up @@ -276,4 +288,20 @@ private List<UIReward> CreateRewardsList()
}
return rewards;
}

private void StatOverride(Protobuf.Messages.Action action)
{
BattleUnit target = battleUnitsUI.Single(unit => unit.SelectedUnit != null && unit.SelectedUnit.id == action.StatOverride.TargetId);
switch (action.StatOverride.StatAffected.Stat)
{
case Protobuf.Messages.Stat.Health:
target.CurrentHealth = (int)action.StatOverride.StatAffected.Amount;
break;
case Protobuf.Messages.Stat.Energy:
target.CurrentEnergy = (int)action.StatOverride.StatAffected.Amount;
break;
default:
break;
}
}
}
38 changes: 33 additions & 5 deletions client/Assets/Scripts/Battle/BattleUnit.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using TMPro;
using DG.Tweening;
using DuloGames.UI;
using UnityEngine;
using UnityEngine.UI;
using DuloGames.UI;
using DG.Tweening;
using System.Collections;

public class BattleUnit : MonoBehaviour
{
Expand All @@ -14,6 +11,9 @@ public class BattleUnit : MonoBehaviour
[SerializeField]
UIProgressBar healthBar;

[SerializeField]
UIProgressBar energyBar;

[SerializeField]
GameObject indicatorPrefab;

Expand Down Expand Up @@ -70,6 +70,34 @@ public int CurrentHealth
}
}

private int maxEnergy;
public int MaxEnergy
{
get { return maxEnergy; }
set
{
if (value != maxEnergy)
{
maxEnergy = value;
energyBar.fillAmount = currentEnergy / (float)maxEnergy;
}
}
}

private int currentEnergy;
public int CurrentEnergy
{
get { return currentEnergy; }
set
{
if (value != currentEnergy)
{
currentEnergy = value;
energyBar.fillAmount = currentEnergy / (float)maxEnergy;
}
}
}

public void SetUnit(Unit unit, bool isPlayer)
{
selectedUnit = unit;
Expand Down
Loading