parent
bf19a9e50e
commit
08b2f22052
42
Assets/Scripts/Attribute.cs
Normal file
42
Assets/Scripts/Attribute.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public struct Attribute
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private long _base;
|
||||||
|
|
||||||
|
public Attribute(long stat)
|
||||||
|
{
|
||||||
|
_base = stat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Permanently increase the stat value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="by">Increase amount.</param>
|
||||||
|
public void LevelUp(long by)
|
||||||
|
{
|
||||||
|
_base += by;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the stat value with accumulated buff and debuff modifiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseBonus">Additive bonus applied before multiplicative scaling.</param>
|
||||||
|
/// <param name="permyriadBonus">Multiplicative scaling in hundredths of a percent. E.g., 625 permyriad corresponds to 6.25%.</param>
|
||||||
|
/// <param name="flatBonus">Additive bonus applied after multiplicative scaling.</param>
|
||||||
|
/// <returns>(base + baseBonus) * (100% + permyriadBonus) + flatBonus, bounded below by 0.</returns>
|
||||||
|
public long Calc(long baseBonus, long permyriadBonus, long flatBonus)
|
||||||
|
{
|
||||||
|
var r = _base + baseBonus;
|
||||||
|
var m = permyriadBonus + 10000;
|
||||||
|
r = r * (m / 10000) + (r / 10000) * (m % 10000) + flatBonus;
|
||||||
|
if (r <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Attribute.cs.meta
generated
Normal file
11
Assets/Scripts/Attribute.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b7d084c6ff925d3448dad326e9980f08
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
3
Assets/Scripts/IdleSurvivors.asmdef
Normal file
3
Assets/Scripts/IdleSurvivors.asmdef
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"name": "IdleSurvivors"
|
||||||
|
}
|
7
Assets/Scripts/IdleSurvivors.asmdef.meta
generated
Normal file
7
Assets/Scripts/IdleSurvivors.asmdef.meta
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e5250715ffed2b644bacb4c76ae6a775
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Tests.meta
generated
Normal file
8
Assets/Tests.meta
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9048b33fed80c814dbfdb2713db19d6d
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
25
Assets/Tests/AttributeTest.cs
Normal file
25
Assets/Tests/AttributeTest.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
public class AttributeTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[TestCase(1000000, 0, 0, 0, 0, ExpectedResult = 1000000)]
|
||||||
|
[TestCase(1000000, 1, 0, 0, 0, ExpectedResult = 1000001)]
|
||||||
|
[TestCase(1000000, 0, 2, 0, 0, ExpectedResult = 1000002)]
|
||||||
|
[TestCase(1000000, 0, 0, 10000, 0, ExpectedResult = 2000000)]
|
||||||
|
[TestCase(1000000, 0, 0, 0, 3, ExpectedResult = 1000003)]
|
||||||
|
[TestCase(0, 1000000, 1000000, 5000, 1000, ExpectedResult = 3001000)]
|
||||||
|
[TestCase(1000000, 0, 0, -10000, 0, ExpectedResult = 0)]
|
||||||
|
[TestCase(1000000, 0, 0, -20000, 0, ExpectedResult = 0)]
|
||||||
|
[TestCase(1000000, 0, 0, -20000, 50, ExpectedResult = 0)]
|
||||||
|
public long Calc(long startStat, long levelUp, long baseBonus, long permyriadBonus, long flatBonus)
|
||||||
|
{
|
||||||
|
var attr = new Attribute(startStat);
|
||||||
|
attr.LevelUp(levelUp);
|
||||||
|
return attr.Calc(baseBonus, permyriadBonus, flatBonus);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Tests/AttributeTest.cs.meta
generated
Normal file
11
Assets/Tests/AttributeTest.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d4d405f62d1e7dc4aaf451051bf27d73
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
24
Assets/Tests/Tests.asmdef
Normal file
24
Assets/Tests/Tests.asmdef
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "Tests",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"UnityEngine.TestRunner",
|
||||||
|
"UnityEditor.TestRunner",
|
||||||
|
"IdleSurvivors"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": true,
|
||||||
|
"precompiledReferences": [
|
||||||
|
"nunit.framework.dll"
|
||||||
|
],
|
||||||
|
"autoReferenced": false,
|
||||||
|
"defineConstraints": [
|
||||||
|
"UNITY_INCLUDE_TESTS"
|
||||||
|
],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
7
Assets/Tests/Tests.asmdef.meta
generated
Normal file
7
Assets/Tests/Tests.asmdef.meta
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0e24b24d5798c7c4b979b314b1a7afce
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user