Commit c1f88acd authored by 16도재형's avatar 16도재형

PseudoFSM.cs added (#7)

parent d30a41c7
......@@ -28,25 +28,20 @@ public class GameManager : MonoBehaviour {
[SerializeField]
GameObject cellPrefab;
private GameObject[,] _cells;
public GameObject[,] Cells { get { return _cells; } }
// Current game
private CivModel.Game _game;
public CivModel.Game Game { get { return _game; } }
// Selected actor
private CivModel.Unit _selectedActor = null;
public CivModel.Unit SelectedActor { get { return _selectedActor; } }
// Variables from Presenter.cs
public bool isThereTodos;
private CivModel.Unit[] _standbyUnits;
private int _standbyUnitIndex = -1;
// For pseudo-FSM
public bool onMoveState = false;
public bool onAttackState = false;
public bool onSkillState = false;
private int _currentSkill = -1;
private CivModel.Terrain.Point?[] _parameterPoints;
// Use this for initialization
void Start() {
// Singleton
......@@ -91,7 +86,7 @@ public class GameManager : MonoBehaviour {
{
HexTile tile = hit.collider.gameObject.GetComponent<HexTile>();
if (onMoveState)
if (PseudoFSM.I.MoveState)
{
if (tile.isFlickering)
{
......@@ -235,7 +230,7 @@ public class GameManager : MonoBehaviour {
}
}
NormalStateEnter();
PseudoFSM.I.NormalStateEnter();
}
// Camera focus
......@@ -273,159 +268,10 @@ public class GameManager : MonoBehaviour {
mainCamera.transform.Translate(vec3 * cameraZoomSpeed * Time.deltaTime, Space.Self);
}
// For state change of pseudo-FSM
// There are enter, exit methods for move and attack states. Enter methods are public, exit methods are default.
// NormalStateEnter() simply resets all state condition.
public void NormalStateEnter()
{
if (onMoveState) MoveStateExit();
if (onAttackState) AttackStateExit();
if (onSkillState) SkillStateExit();
}
// When move state, coloring movable adjacent tiles
// Current MoveStateEnter() shows only adjacent tiles. If moving mechanism of model changes, this should be changed.
public void MoveStateEnter()
{
// State change
if (onMoveState) return;
if (onAttackState) AttackStateExit();
if (onSkillState) SkillStateExit();
onMoveState = true;
// Select movable adjacent tiles
_parameterPoints = _selectedActor.PlacedPoint.Value.Adjacents();
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_selectedActor.MoveAct.IsActable(_parameterPoints[i]))
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerBlue();
}
}
}
void MoveStateExit()
{
onMoveState = false;
if (_parameterPoints == null)
return;
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_parameterPoints[i] != null)
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
_parameterPoints = null;
}
public void AttackStateEnter()
{
// State change
if (onAttackState) return;
if (onMoveState) MoveStateExit();
if (onSkillState) SkillStateExit();
onAttackState = true;
// If _selectedActor cannot attack
if (_selectedActor.MovingAttackAct == null)
return;
// Select attackable adjacent tiles
_parameterPoints = _selectedActor.PlacedPoint.Value.Adjacents();
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_selectedActor.MovingAttackAct.IsActable(_parameterPoints[i]))
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerRed();
}
}
}
void AttackStateExit()
{
onAttackState = false;
if (_parameterPoints == null)
return;
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_parameterPoints[i] != null)
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
_parameterPoints = null;
}
public void SkillStateEnter(int index)
{
// State change
if (onSkillState && _currentSkill == index) return;
if (onMoveState) MoveStateExit();
if (onAttackState) AttackStateExit();
onSkillState = true;
_currentSkill = index;
// If SpecialActs[_currentSkill] is not parametered skill, this skill is immediately activated.
if (!_selectedActor.SpecialActs[_currentSkill].IsParametered)
{
_selectedActor.SpecialActs[_currentSkill].Act(null);
SkillStateExit();
return;
}
else
{
for (int i = 0; i < GameInfo.mapWidth; i++)
{
for (int j = 0; j < GameInfo.mapHeight; j++)
{
CivModel.Terrain.Point? point = _game.Terrain.GetPoint(i, j);
if (_selectedActor.SpecialActs[_currentSkill].IsActable(point))
{
CivModel.Position pos = point.Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerBlue();
}
}
}
}
}
void SkillStateExit()
{
int index = _currentSkill;
onSkillState = false;
_currentSkill = -1;
if (!_selectedActor.SpecialActs[index].IsParametered)
{
return;
}
else
{
for (int i = 0; i < GameInfo.mapWidth; i++)
{
for (int j = 0; j < GameInfo.mapHeight; j++)
{
CivModel.Terrain.Point? point = _game.Terrain.GetPoint(i, j);
if (_selectedActor.SpecialActs[index].IsActable(point))
{
CivModel.Position pos = point.Value.Position;
_cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
}
}
}
// Move _selectedActor
void Move(CivModel.Terrain.Point point)
{
_selectedActor.MoveAct.Act(point);
NormalStateEnter();
PseudoFSM.I.NormalStateEnter();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CivModel;
using CivModel.Common;
public class PseudoFSM : MonoBehaviour {
private static PseudoFSM _fsm = null;
public static PseudoFSM I { get { return _fsm; } }
// For pseudo-FSM
private bool _inMoveState = false;
public bool MoveState { get { return _inMoveState; } }
private bool _inAttackState = false;
public bool AttackState { get { return _inAttackState; } }
private bool _inSkillState = false;
public bool SkillState { get { return _inSkillState; } }
private int _currentSkill = -1;
private CivModel.Terrain.Point?[] _parameterPoints;
// Use this for initialization
void Start () {
// Singleton
if (_fsm != null)
{
Destroy(gameObject);
return;
}
else
{
_fsm = this;
}
}
// Update is called once per frame
void Update () {
}
// For state change of pseudo-FSM
// There are enter, exit methods for move and attack states. Enter methods are public, exit methods are default.
// NormalStateEnter() simply resets all state condition.
public void NormalStateEnter()
{
if (_inMoveState) MoveStateExit();
if (_inAttackState) AttackStateExit();
if (_inSkillState) SkillStateExit();
}
// When move state, coloring movable adjacent tiles
// Current MoveStateEnter() shows only adjacent tiles. If moving mechanism of model changes, this should be changed.
public void MoveStateEnter()
{
// State change
if (_inMoveState) return;
if (_inAttackState) AttackStateExit();
if (_inSkillState) SkillStateExit();
_inMoveState = true;
// Select movable adjacent tiles
_parameterPoints = GameManager.I.SelectedActor.PlacedPoint.Value.Adjacents();
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (GameManager.I.SelectedActor.MoveAct.IsActable(_parameterPoints[i]))
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerBlue();
}
}
}
void MoveStateExit()
{
_inMoveState = false;
if (_parameterPoints == null)
return;
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_parameterPoints[i] != null)
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
_parameterPoints = null;
}
public void AttackStateEnter()
{
// State change
if (_inAttackState) return;
if (_inMoveState) MoveStateExit();
if (_inSkillState) SkillStateExit();
_inAttackState = true;
// If GameManager.I.SelectedActor cannot attack
if (GameManager.I.SelectedActor.MovingAttackAct == null)
return;
// Select attackable adjacent tiles
_parameterPoints = GameManager.I.SelectedActor.PlacedPoint.Value.Adjacents();
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (GameManager.I.SelectedActor.MovingAttackAct.IsActable(_parameterPoints[i]))
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerRed();
}
}
}
void AttackStateExit()
{
_inAttackState = false;
if (_parameterPoints == null)
return;
for (int i = 0; i < _parameterPoints.Length; i++)
{
if (_parameterPoints[i] != null)
{
CivModel.Position pos = _parameterPoints[i].Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
_parameterPoints = null;
}
public void SkillStateEnter(int index)
{
// State change
if (_inSkillState && _currentSkill == index) return;
if (_inMoveState) MoveStateExit();
if (_inAttackState) AttackStateExit();
_inSkillState = true;
_currentSkill = index;
// If SpecialActs[_currentSkill] is not parametered skill, this skill is immediately activated.
if (!GameManager.I.SelectedActor.SpecialActs[_currentSkill].IsParametered)
{
GameManager.I.SelectedActor.SpecialActs[_currentSkill].Act(null);
SkillStateExit();
return;
}
else
{
for (int i = 0; i < GameInfo.mapWidth; i++)
{
for (int j = 0; j < GameInfo.mapHeight; j++)
{
CivModel.Terrain.Point? point = GameManager.I.Game.Terrain.GetPoint(i, j);
if (GameManager.I.SelectedActor.SpecialActs[_currentSkill].IsActable(point))
{
CivModel.Position pos = point.Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().FlickerBlue();
}
}
}
}
}
void SkillStateExit()
{
int index = _currentSkill;
_inSkillState = false;
_currentSkill = -1;
if (!GameManager.I.SelectedActor.SpecialActs[index].IsParametered)
{
return;
}
else
{
for (int i = 0; i < GameInfo.mapWidth; i++)
{
for (int j = 0; j < GameInfo.mapHeight; j++)
{
CivModel.Terrain.Point? point = GameManager.I.Game.Terrain.GetPoint(i, j);
if (GameManager.I.SelectedActor.SpecialActs[index].IsActable(point))
{
CivModel.Position pos = point.Value.Position;
GameManager.I.Cells[pos.X, pos.Y].GetComponent<HexTile>().StopFlickering();
}
}
}
}
}
}
fileFormatVersion: 2
guid: bb8cd2fcbe30d5d429c55f48f213c91d
timeCreated: 1519291515
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -75,13 +75,13 @@ public class UIManager : MonoBehaviour {
public void MoveActive()
{
SkillSet.SetActive(false);
GameManager.I.MoveStateEnter();
PseudoFSM.I.MoveStateEnter();
}
public void AttackActive()
{
SkillSet.SetActive(false);
GameManager.I.AttackStateEnter();
PseudoFSM.I.AttackStateEnter();
}
public void SkillSetActive()
......@@ -91,7 +91,7 @@ public class UIManager : MonoBehaviour {
public void Skill1Active()
{
GameManager.I.SkillStateEnter(0);
PseudoFSM.I.SkillStateEnter(0);
}
/*
public void SkillSpec1MouseOver() // 특수 명령
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment