Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Spieleentwicklung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adrian Paschkowski
Spieleentwicklung
Commits
67da2743
Verified
Commit
67da2743
authored
3 years ago
by
Adrian Paschkowski
Browse files
Options
Downloads
Patches
Plain Diff
StatsManager: Public upgrade info, add CanModifyMana
parent
45c8e2aa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Scripts/StatsManager.cs
+39
-23
39 additions, 23 deletions
Assets/Scripts/StatsManager.cs
with
39 additions
and
23 deletions
Assets/Scripts/StatsManager.cs
+
39
−
23
View file @
67da2743
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
...
...
@@ -10,20 +11,41 @@ public enum UpgradeTypes
MANA_COST
,
}
class
UpgradeData
public
struct
EnemyStats
{
public
float
healthMultiplier
;
public
float
damageMultiplier
;
public
float
armorMultiplier
;
}
public
struct
PlayerStats
{
public
float
healthMultiplier
;
public
float
damageMultiplier
;
public
float
armorMultiplier
;
}
public
class
UpgradeData
{
public
Upgrade
upgrade
;
public
int
count
;
public
int
GetUnadjustedNextUpgradeCost
()
// How much it costs to purchase another one of this upgrade
public
int
GetNextUpgradeCost
()
{
return
(
int
)(
upgrade
.
baseCost
*
(
1
+
count
*
u
pgrade
.
c
ost
Multiplier
));
return
StatsManager
.
instance
.
AdjustManaCost
(
GetUnadjustedNextU
pgrade
C
ost
(
));
}
public
float
GetTotalEffectMultiplier
()
{
return
1
+
count
*
upgrade
.
effectMultiplier
;
}
// You probably shouldn't call this outside this file.
public
int
GetUnadjustedNextUpgradeCost
()
{
return
(
int
)(
upgrade
.
baseCost
*
(
1
+
count
*
upgrade
.
costMultiplier
));
}
}
public
class
StatsManager
:
MonoBehaviour
...
...
@@ -36,7 +58,9 @@ public class StatsManager : MonoBehaviour
[
SerializeField
]
int
currentMana
;
[
SerializeField
]
List
<
Upgrade
>
availableUpgrades
;
Dictionary
<
UpgradeTypes
,
UpgradeData
>
upgrades
=
new
Dictionary
<
UpgradeTypes
,
UpgradeData
>();
// Information about currently available and purchased upgrades. Should only be read, not modified.
public
Dictionary
<
UpgradeTypes
,
UpgradeData
>
upgrades
=
new
Dictionary
<
UpgradeTypes
,
UpgradeData
>();
public
EnemyStats
GetEnemyStats
()
{
...
...
@@ -55,20 +79,20 @@ public class StatsManager : MonoBehaviour
}
// Adjusts the given Mana cost based on the amount of Mana cost upgrades currently bought.
public
int
Get
Adjust
ed
ManaCost
(
int
cost
)
public
int
AdjustManaCost
(
int
cost
)
{
return
(
int
)(
cost
*
upgrades
[
UpgradeTypes
.
MANA_COST
].
GetTotalEffectMultiplier
());
}
public
int
GetNextUpgradeCost
(
UpgradeTypes
type
)
{
return
GetAdjustedManaCost
(
upgrades
[
type
].
Get
Unadjusted
NextUpgradeCost
()
)
;
return
upgrades
[
type
].
GetNextUpgradeCost
();
}
// Buys an upgrade, spending the required amount of Mana in the process. Returns false if not enough Mana is available.
public
bool
BuyUpgrade
(
UpgradeTypes
type
)
{
if
(!
ModifyMana
(
GetNextUpgradeCost
(
type
)))
if
(!
ModifyMana
(
-
GetNextUpgradeCost
(
type
)))
{
return
false
;
}
...
...
@@ -77,10 +101,10 @@ public class StatsManager : MonoBehaviour
return
true
;
}
// Add (positive value) or spend (negative value) Mana.
// Add (positive value) or spend (negative value) Mana.
Returns false if not enough Mana is available to spend.
public
bool
ModifyMana
(
int
delta
)
{
if
(
current
Mana
+
delta
<
0
)
if
(
!
CanModify
Mana
(
delta
)
)
{
return
false
;
}
...
...
@@ -88,6 +112,12 @@ public class StatsManager : MonoBehaviour
return
true
;
}
// If `delta` is negative, returns this amount of Mana can be spent. If `delta` is positive, this will always return `true`.
public
bool
CanModifyMana
(
int
delta
)
{
return
currentMana
+
delta
>=
0
;
}
void
RecalculateStatMultipliers
()
{
currentEnemyStats
.
healthMultiplier
=
upgrades
[
UpgradeTypes
.
ENEMY_HEALTH
].
GetTotalEffectMultiplier
();
...
...
@@ -121,17 +151,3 @@ public class StatsManager : MonoBehaviour
currentPlayerStats
.
armorMultiplier
=
1f
;
}
}
public
struct
EnemyStats
{
public
float
healthMultiplier
;
public
float
damageMultiplier
;
public
float
armorMultiplier
;
}
public
struct
PlayerStats
{
public
float
healthMultiplier
;
public
float
damageMultiplier
;
public
float
armorMultiplier
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment