Create basic Story classes and parameterize monsters in Battle scene
This commit is contained in:
parent
6181a7d50c
commit
0d7f4f4954
17 changed files with 268 additions and 48 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
|
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
|
||||||
{
|
{
|
||||||
|
|
@ -39,6 +40,39 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
private event BattleStateChangedAction OnBattleStateChanged;
|
private event BattleStateChangedAction OnBattleStateChanged;
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
|
BattleParameters parameters = BattleSetup.RetrieveParameters();
|
||||||
|
if (parameters == null) {
|
||||||
|
Debug.Log("Using default battle");
|
||||||
|
|
||||||
|
MonsterId[] monsterIds = new MonsterId[3] {
|
||||||
|
MonsterId.Golem,
|
||||||
|
MonsterId.Bat,
|
||||||
|
MonsterId.Bat,
|
||||||
|
};
|
||||||
|
|
||||||
|
MCardId[] mCardIds = new MCardId[10] {
|
||||||
|
MCardId.GraniteDefense,
|
||||||
|
MCardId.GraniteDefense,
|
||||||
|
MCardId.GolemCharge,
|
||||||
|
MCardId.GolemFist,
|
||||||
|
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.Whirlwind,
|
||||||
|
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.Whirlwind,
|
||||||
|
};
|
||||||
|
int[] mCardOwnerIndexes = new int[10] {
|
||||||
|
0, 0, 0, 0,
|
||||||
|
1, 1, 1,
|
||||||
|
2, 2, 2,
|
||||||
|
};
|
||||||
|
parameters = new BattleParameters();
|
||||||
|
parameters.SetMonsters(monsterIds, mCardIds, mCardOwnerIndexes);
|
||||||
|
}
|
||||||
|
|
||||||
HeroId[] heroIds = new HeroId[3] {
|
HeroId[] heroIds = new HeroId[3] {
|
||||||
HeroId.Alchemist,
|
HeroId.Alchemist,
|
||||||
HeroId.NPCGuard,
|
HeroId.NPCGuard,
|
||||||
|
|
@ -78,43 +112,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
// HCardId.IronskinDraught,
|
// HCardId.IronskinDraught,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
MonsterId[] monsterIds = new MonsterId[3] {
|
|
||||||
MonsterId.Golem,
|
|
||||||
MonsterId.Bat,
|
|
||||||
MonsterId.Bat,
|
|
||||||
};
|
|
||||||
|
|
||||||
MCardId[] mCardIds = new MCardId[10] {
|
|
||||||
MCardId.GraniteDefense,
|
|
||||||
MCardId.GraniteDefense,
|
|
||||||
MCardId.GolemCharge,
|
|
||||||
MCardId.GolemFist,
|
|
||||||
|
|
||||||
MCardId.VampireFangs,
|
|
||||||
MCardId.VampireFangs,
|
|
||||||
MCardId.Whirlwind,
|
|
||||||
|
|
||||||
MCardId.VampireFangs,
|
|
||||||
MCardId.VampireFangs,
|
|
||||||
MCardId.Whirlwind,
|
|
||||||
};
|
|
||||||
int[] mCardOwnerIndexes = new int[10] {
|
|
||||||
0, 0, 0, 0,
|
|
||||||
1, 1, 1,
|
|
||||||
2, 2, 2,
|
|
||||||
};
|
|
||||||
// MCardId[] mCardIds = new MCardId[5] {
|
|
||||||
// MCardId.Whirlwind,
|
|
||||||
// MCardId.Whirlwind,
|
|
||||||
// MCardId.Whirlwind,
|
|
||||||
// MCardId.Whirlwind,
|
|
||||||
// MCardId.Whirlwind,
|
|
||||||
// };
|
|
||||||
// int[] mCardOwnerIndexes = new int[5] {
|
|
||||||
// 1, 1,
|
|
||||||
// 2, 2, 2,
|
|
||||||
// };
|
|
||||||
|
|
||||||
this.heroCardDatabase = new HeroCardDatabase();
|
this.heroCardDatabase = new HeroCardDatabase();
|
||||||
this.monsterCardDatabase = new MonsterCardDatabase();
|
this.monsterCardDatabase = new MonsterCardDatabase();
|
||||||
|
|
||||||
|
|
@ -154,11 +151,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
this.heroUIs[hero] = heroUI;
|
this.heroUIs[hero] = heroUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.monsters = new BattleMonster[monsterIds.Length];
|
this.monsters = new BattleMonster[parameters.MonsterIds.Length];
|
||||||
this.monsterSprites = new Dictionary<BattleMonster, GameObject>();
|
this.monsterSprites = new Dictionary<BattleMonster, GameObject>();
|
||||||
this.monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
|
this.monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
MonsterId id = monsterIds[i];
|
MonsterId id = parameters.MonsterIds[i];
|
||||||
|
|
||||||
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
||||||
monster.Init();
|
monster.Init();
|
||||||
|
|
@ -186,16 +183,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
this.heroDeck = new BattleDeck<HeroCard>(
|
this.heroDeck = new BattleDeck<HeroCard>(
|
||||||
this.heroCardDatabase, cardIds.Cast<int>().ToArray(), cardOwners);
|
this.heroCardDatabase, cardIds.Cast<int>().ToArray(), cardOwners);
|
||||||
|
|
||||||
BattleParticipant[] mCardOwners = new BattleParticipant[mCardIds.Length];
|
BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length];
|
||||||
if (mCardIds.Length != mCardOwnerIndexes.Length) {
|
for (int i = 0; i < parameters.MCardIds.Length; i++) {
|
||||||
throw new System.ArgumentException(
|
mCardOwners[i] = this.monsters[parameters.MCardOwnerIndexes[i]];
|
||||||
"mCardIds and mCardOwnerIndexes need to have the same length");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < mCardIds.Length; i++) {
|
|
||||||
mCardOwners[i] = this.monsters[mCardOwnerIndexes[i]];
|
|
||||||
}
|
}
|
||||||
this.monsterDeck = new BattleDeck<MonsterCard>(
|
this.monsterDeck = new BattleDeck<MonsterCard>(
|
||||||
this.monsterCardDatabase, mCardIds.Cast<int>().ToArray(), mCardOwners);
|
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
|
||||||
|
|
||||||
this.playArea = new PlayArea();
|
this.playArea = new PlayArea();
|
||||||
|
|
||||||
|
|
|
||||||
24
Assets/Battle/BattleParameters.cs
Normal file
24
Assets/Battle/BattleParameters.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
public class BattleParameters {
|
||||||
|
private MonsterId[] monsterIds;
|
||||||
|
private MCardId[] mCardIds;
|
||||||
|
private int[] mCardOwnerIndexes;
|
||||||
|
|
||||||
|
public BattleParameters() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetMonsters(MonsterId[] monsterIds, MCardId[] mCardIds, int[] mCardOwnerIndexes) {
|
||||||
|
if (mCardIds.Length != mCardOwnerIndexes.Length) {
|
||||||
|
throw new System.ArgumentException(
|
||||||
|
"mCardIds and mCardOwnerIndexes need to have the same length");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.monsterIds = monsterIds;
|
||||||
|
this.mCardIds = mCardIds;
|
||||||
|
this.mCardOwnerIndexes = mCardOwnerIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonsterId[] MonsterIds {get => this.monsterIds;}
|
||||||
|
public MCardId[] MCardIds {get => this.mCardIds;}
|
||||||
|
public int[] MCardOwnerIndexes {get => this.mCardOwnerIndexes;}
|
||||||
|
}
|
||||||
11
Assets/Battle/BattleParameters.cs.meta
Normal file
11
Assets/Battle/BattleParameters.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 27e7d9637e99afb46ab6521f276bcdbd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
16
Assets/Battle/BattleSetup.cs
Normal file
16
Assets/Battle/BattleSetup.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
public class BattleSetup {
|
||||||
|
private static BattleParameters sParameters;
|
||||||
|
|
||||||
|
public static void StartBattle(BattleParameters parameters) {
|
||||||
|
sParameters = parameters;
|
||||||
|
SceneManager.LoadScene("BattleScene");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BattleParameters RetrieveParameters() {
|
||||||
|
BattleParameters result = sParameters;
|
||||||
|
sParameters = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Battle/BattleSetup.cs.meta
Normal file
11
Assets/Battle/BattleSetup.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d20269def60ce9b418f46f701f6eba0e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Story/SceneId.cs
Normal file
8
Assets/Story/SceneId.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public enum SceneId
|
||||||
|
{
|
||||||
|
Chapter1_Cave,
|
||||||
|
}
|
||||||
11
Assets/Story/SceneId.cs.meta
Normal file
11
Assets/Story/SceneId.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8adf44d7c7685443a7454f0ca29023b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Story/Scenes.meta
Normal file
8
Assets/Story/Scenes.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a17f0c1277fdfea4285176b4888ca019
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
45
Assets/Story/Scenes/Scene_Chapter1_Cave.cs
Normal file
45
Assets/Story/Scenes/Scene_Chapter1_Cave.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Scene_Chapter1_Cave: StoryScene
|
||||||
|
{
|
||||||
|
public override IEnumerator Play() {
|
||||||
|
Debug.Log("OMG monsters!");
|
||||||
|
yield return new WaitForSeconds(2f);
|
||||||
|
|
||||||
|
BattleParameters battleParameters = BuildBattleGolemBats();
|
||||||
|
BattleSetup.StartBattle(battleParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BattleParameters BuildBattleGolemBats() {
|
||||||
|
BattleParameters battleParameters = new BattleParameters();
|
||||||
|
MonsterId[] monsterIds = new MonsterId[3] {
|
||||||
|
MonsterId.Golem,
|
||||||
|
MonsterId.Bat,
|
||||||
|
MonsterId.Bat,
|
||||||
|
};
|
||||||
|
|
||||||
|
MCardId[] mCardIds = new MCardId[10] {
|
||||||
|
MCardId.GraniteDefense,
|
||||||
|
MCardId.GraniteDefense,
|
||||||
|
MCardId.GolemCharge,
|
||||||
|
MCardId.GolemFist,
|
||||||
|
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.Whirlwind,
|
||||||
|
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.VampireFangs,
|
||||||
|
MCardId.Whirlwind,
|
||||||
|
};
|
||||||
|
int[] mCardOwnerIndexes = new int[10] {
|
||||||
|
0, 0, 0, 0,
|
||||||
|
1, 1, 1,
|
||||||
|
2, 2, 2,
|
||||||
|
};
|
||||||
|
battleParameters.SetMonsters(monsterIds, mCardIds, mCardOwnerIndexes);
|
||||||
|
return battleParameters;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Story/Scenes/Scene_Chapter1_Cave.cs.meta
Normal file
11
Assets/Story/Scenes/Scene_Chapter1_Cave.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f44cf58dd36528d44892aa54d8d17637
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
21
Assets/Story/StoryController.cs
Normal file
21
Assets/Story/StoryController.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class StoryController : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// TODO: Read which scene should be loaded.
|
||||||
|
StoryScene scene = StorySceneDatabase.Load(SceneId.Chapter1_Cave);
|
||||||
|
|
||||||
|
StartCoroutine(scene.Play());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Story/StoryController.cs.meta
Normal file
11
Assets/Story/StoryController.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e976139d539dae45bf8db63e6f697fe
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Story/StoryScene.cs
Normal file
8
Assets/Story/StoryScene.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public abstract class StoryScene
|
||||||
|
{
|
||||||
|
public abstract IEnumerator Play();
|
||||||
|
}
|
||||||
11
Assets/Story/StoryScene.cs.meta
Normal file
11
Assets/Story/StoryScene.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 354fc5f67bf09ba42b407a7858cdf711
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
14
Assets/Story/StorySceneDatabase.cs
Normal file
14
Assets/Story/StorySceneDatabase.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class StorySceneDatabase {
|
||||||
|
public static StoryScene Load(SceneId id) {
|
||||||
|
switch (id) {
|
||||||
|
case SceneId.Chapter1_Cave:
|
||||||
|
return new Scene_Chapter1_Cave();
|
||||||
|
default:
|
||||||
|
throw new System.NotImplementedException("StoryScene with id " + id + " missing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Story/StorySceneDatabase.cs.meta
Normal file
11
Assets/Story/StorySceneDatabase.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4bcc3155ffc3d3d4cb862f25f7ae431a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -4,5 +4,11 @@
|
||||||
EditorBuildSettings:
|
EditorBuildSettings:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Scenes: []
|
m_Scenes:
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Story/StoryScene.unity
|
||||||
|
guid: 34bfaaf524118f34b8e2d9d80122ab5c
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Battle/BattleScene.unity
|
||||||
|
guid: 2cda990e2423bbf4892e6590ba056729
|
||||||
m_configObjects: {}
|
m_configObjects: {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue