|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using TMPro;
|
|
|
//控制选中取消角色与角色的移动
|
|
|
public class GameManager : MonoBehaviour
|
|
|
{
|
|
|
public GameObject menuUI; //调出菜单
|
|
|
public float speed = 3.0f; //镜头移动速度
|
|
|
public Character selected; //记录选中的棋子
|
|
|
bool menuActive = false; //是否显示菜单
|
|
|
bool exploreMode = false; //true时为探索模式,false时为战斗模式
|
|
|
public TMP_Text cellCost; //显示鼠标所在单元格消耗行动力
|
|
|
public TMP_Text cellDamage; //显示鼠标所在单元格造成的伤害
|
|
|
public TMP_Text characterHealth; //显示鼠标所在角色当前生命值
|
|
|
public TMP_Text characterPoise; //显示鼠标所在角色当前韧性值
|
|
|
public GameObject[] pieces; //记录所有的棋子
|
|
|
public int[] groupCount; //记录敌我双方棋子数量,groupCount[0]为友方,groupCount[1]为敌方
|
|
|
public int currentGroup = 0; //当前的回合是哪一方的,0是友军,1是敌方
|
|
|
float horizontal; //移动镜头
|
|
|
float vertical; //移动镜头
|
|
|
public GameObject turnObject; // ** 回合UI
|
|
|
public GameObject turnText;
|
|
|
public TMP_Text DEX;
|
|
|
public TMP_Text SAN;
|
|
|
public TMP_Text VIG;
|
|
|
public TMP_Text DEF;
|
|
|
public TMP_Text STR;
|
|
|
public TMP_Text INT;
|
|
|
public TMP_Text CurrentHealth;
|
|
|
public TMP_Text MaxHealth;
|
|
|
public TMP_Text CurrentPoise;
|
|
|
public TMP_Text MaxPoise;
|
|
|
public TMP_Text CurrentMana;
|
|
|
public TMP_Text MaxMana;
|
|
|
public GameObject detailInformation;
|
|
|
// ** 敌我回合的文本框
|
|
|
int enemyNumber; // **** 关卡中敌人总数
|
|
|
public Character maincharacter; // **** 记录主角
|
|
|
public GameObject myBag; // **** 背包
|
|
|
bool isOpen; // **** 背包是否打开
|
|
|
public GameObject gameSettlement; // **** 结算界面
|
|
|
bool settlementFlag; // **** 是否需要结算界面
|
|
|
|
|
|
// !!!! 加点界面
|
|
|
public GameObject strAdd;
|
|
|
public GameObject dexAdd;
|
|
|
public GameObject sanAdd;
|
|
|
public GameObject inteAdd;
|
|
|
public GameObject defAdd;
|
|
|
public GameObject vigAdd;
|
|
|
|
|
|
public AIManager aiManager;
|
|
|
|
|
|
void Start()
|
|
|
{
|
|
|
SearchPieces();
|
|
|
SetCount();
|
|
|
SetExploreMode();
|
|
|
|
|
|
if (GetExploreMode()) // **
|
|
|
{
|
|
|
turnObject.SetActive(false); // ****
|
|
|
settlementFlag = false; // **** 初始状态中无敌人时不需要结算界面
|
|
|
enemyNumber = 0; // **** 初始状态敌人数量为0
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
turnObject.SetActive(true); // ****
|
|
|
settlementFlag = true; // **** 初始状态中有敌人时需要结算界面
|
|
|
enemyNumber = groupCount[1]; // **** 记录初始状态关卡中敌人总数
|
|
|
} // **
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
|
{
|
|
|
if(!menuActive)
|
|
|
{
|
|
|
ShowSettlement();
|
|
|
ShowTurn(); // ** 不显示菜单时先判断是否显示敌我回合
|
|
|
ShowBag(); // **** 不显示菜单时可以打开背包
|
|
|
//选中角色时,镜头移动到角色上,方向键控制角色走动
|
|
|
if (currentGroup ==0) //只有在玩家回合才接受操控
|
|
|
{
|
|
|
if (selected != null)
|
|
|
{
|
|
|
//取消选择
|
|
|
if(Input.GetMouseButtonDown(1))
|
|
|
{
|
|
|
selected.Cancel();
|
|
|
return;
|
|
|
}
|
|
|
MoveCharacter();
|
|
|
//选中角色在lookDirection方向上与NPC对话
|
|
|
if (exploreMode && Input.GetKeyDown(KeyCode.X))
|
|
|
selected.Dialogue();
|
|
|
// **** 选中角色在lookDirection方向上进入下一场景
|
|
|
if (exploreMode)
|
|
|
selected.EnterNextScene();
|
|
|
// **** 选中角色时按f捡起物品
|
|
|
if (Input.GetKeyDown("f"))
|
|
|
selected.Pickup();
|
|
|
//选中角色时可切换武器
|
|
|
if(Input.GetKeyDown("c"))
|
|
|
selected.GetNextWeapon();
|
|
|
if(Input.GetKeyDown("e"))
|
|
|
selected.weaponManager.SetWeaponsGUI();
|
|
|
if(Input.GetKeyDown("z"))
|
|
|
{
|
|
|
selected.skillManager.SetSkillsGUI();
|
|
|
bool value = !selected.skillManager.GetGameObjectValue();
|
|
|
//selected.weaponManager.gameObject.SetActive(value);
|
|
|
}
|
|
|
if(Input.GetKeyDown("x") && !selected.GetIsUsingSkill())
|
|
|
{
|
|
|
selected.Attack();
|
|
|
}
|
|
|
}
|
|
|
//未选中角色时,方向键控制镜头移动
|
|
|
else
|
|
|
MoveCamera();
|
|
|
}
|
|
|
}
|
|
|
CallMenu();
|
|
|
}
|
|
|
|
|
|
//调用AI
|
|
|
void AITurn()
|
|
|
{
|
|
|
aiManager.AIStart();
|
|
|
}
|
|
|
|
|
|
//移动镜头
|
|
|
void MoveCamera()
|
|
|
{
|
|
|
horizontal = Input.GetAxis("Horizontal");
|
|
|
vertical = Input.GetAxis("Vertical");
|
|
|
Vector2 position = transform.position;
|
|
|
position.x += speed*horizontal*Time.deltaTime;
|
|
|
position.y += speed*vertical*Time.deltaTime;
|
|
|
transform.position = position;
|
|
|
}
|
|
|
//移动角色
|
|
|
void MoveCharacter()
|
|
|
{
|
|
|
transform.position = selected.transform.position;
|
|
|
//角色走动
|
|
|
if(Input.GetKeyDown("up"))
|
|
|
{
|
|
|
selected.Move(Vector2.up);
|
|
|
}
|
|
|
if(Input.GetKeyDown("down"))
|
|
|
{
|
|
|
selected.Move(Vector2.down);
|
|
|
}
|
|
|
if(Input.GetKeyDown("left"))
|
|
|
{
|
|
|
selected.Move(Vector2.left);
|
|
|
}
|
|
|
if(Input.GetKeyDown("right"))
|
|
|
{
|
|
|
selected.Move(Vector2.right);
|
|
|
}
|
|
|
//角色转向
|
|
|
if(Input.GetKeyDown("w"))
|
|
|
{
|
|
|
selected.Turn(Vector2.up);
|
|
|
}
|
|
|
if(Input.GetKeyDown("s"))
|
|
|
{
|
|
|
selected.Turn(Vector2.down);
|
|
|
}
|
|
|
if(Input.GetKeyDown("a"))
|
|
|
{
|
|
|
selected.Turn(Vector2.left);
|
|
|
}
|
|
|
if(Input.GetKeyDown("d"))
|
|
|
{
|
|
|
selected.Turn(Vector2.right);
|
|
|
}
|
|
|
}
|
|
|
//呼出菜单
|
|
|
void CallMenu()
|
|
|
{
|
|
|
if(Input.GetKeyDown("escape"))
|
|
|
{
|
|
|
menuActive = !menuActive;
|
|
|
menuUI.SetActive(menuActive);
|
|
|
}
|
|
|
}
|
|
|
//改变选中的棋子
|
|
|
public void SetSelected(Character character)
|
|
|
{
|
|
|
selected = character;
|
|
|
}
|
|
|
//返回选中的棋子
|
|
|
public Character GetSelected()
|
|
|
{
|
|
|
return selected;
|
|
|
}
|
|
|
//回合结束
|
|
|
public void TurnEnd()
|
|
|
{
|
|
|
if(exploreMode) return;
|
|
|
if(selected != null)
|
|
|
selected.Cancel();
|
|
|
foreach (var piece in pieces)
|
|
|
{
|
|
|
if(piece.GetComponent<Character>().groupNumber == currentGroup)
|
|
|
piece.GetComponent<Character>().ReSet();
|
|
|
piece.GetComponent<Character>().buffManager.TurnEnd();
|
|
|
}
|
|
|
if(currentGroup == 0)
|
|
|
{
|
|
|
foreach (var piece in pieces)
|
|
|
{
|
|
|
if(piece.GetComponent<Character>().groupNumber == currentGroup)
|
|
|
piece.GetComponent<Character>().ReSet();
|
|
|
piece.GetComponent<Character>().buffManager.TurnEnd();
|
|
|
}
|
|
|
currentGroup = 1;
|
|
|
|
|
|
AITurn();
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (var piece in pieces)
|
|
|
{
|
|
|
if(piece.GetComponent<Character>().groupNumber == currentGroup)
|
|
|
piece.GetComponent<Character>().ReSet();
|
|
|
piece.GetComponent<Character>().buffManager.TurnEnd();
|
|
|
}
|
|
|
currentGroup = 0; //交换回合
|
|
|
}
|
|
|
}
|
|
|
//搜寻棋子
|
|
|
public void SearchPieces()
|
|
|
{
|
|
|
pieces = GameObject.FindGameObjectsWithTag("Pieces");
|
|
|
}
|
|
|
//数敌我双方棋子数
|
|
|
void SetCount()
|
|
|
{
|
|
|
groupCount = new int[3];
|
|
|
foreach (var piece in pieces)
|
|
|
{
|
|
|
Character character = piece.GetComponent<Character>();
|
|
|
groupCount[character.groupNumber] ++ ;
|
|
|
//Debug.Log("gruopCount[" + character.groupNumber + "] = " + groupCount[character.groupNumber]);
|
|
|
}
|
|
|
}
|
|
|
public bool GetExploreMode()
|
|
|
{
|
|
|
return exploreMode;
|
|
|
}
|
|
|
//当敌人数量为0时,状态切换为探索模式
|
|
|
public void SetExploreMode()
|
|
|
{
|
|
|
if(groupCount[1] == 0)
|
|
|
{
|
|
|
if(selected != null)
|
|
|
selected.Cancel();
|
|
|
exploreMode = true;
|
|
|
Debug.Log("exploreMode");
|
|
|
currentGroup = 0;
|
|
|
foreach (var piece in pieces)
|
|
|
{
|
|
|
Character character = piece.GetComponent<Character>();
|
|
|
Debug.Log(character.id);
|
|
|
character.ReSet();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// **** 战斗结算
|
|
|
void MakeSettlement()
|
|
|
{
|
|
|
for (int i = 0; i < enemyNumber; i++)
|
|
|
{
|
|
|
maincharacter.money += 10;
|
|
|
maincharacter.exp += 10;
|
|
|
while (maincharacter.exp >= maincharacter.levelUp[maincharacter.level - 1])
|
|
|
{
|
|
|
maincharacter.exp -= maincharacter.levelUp[maincharacter.level - 1];
|
|
|
maincharacter.level++;
|
|
|
maincharacter.points += 5;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// **** 显示结算界面
|
|
|
void ShowSettlement()
|
|
|
{
|
|
|
if (settlementFlag) // **** 初始状态有敌人才需要结算
|
|
|
{
|
|
|
if (exploreMode) // **** 战斗模式结束时显示结算界面
|
|
|
{
|
|
|
MakeSettlement(); // **** 击杀所有敌人后获得经验和金钱
|
|
|
gameSettlement.SetActive(true);
|
|
|
|
|
|
// !!!! 是否显示加点系统
|
|
|
if(maincharacter.points > 0)
|
|
|
{
|
|
|
strAdd.SetActive(true);
|
|
|
dexAdd.SetActive(true);
|
|
|
sanAdd.SetActive(true);
|
|
|
inteAdd.SetActive(true);
|
|
|
defAdd.SetActive(true);
|
|
|
vigAdd.SetActive(true);
|
|
|
}
|
|
|
|
|
|
settlementFlag = false; // **** 此场景中不再需要结算界面
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ShowTurn() // **
|
|
|
{ // **
|
|
|
if (exploreMode) // ** 探索模式下不显示敌我回合
|
|
|
turnObject.SetActive(false); // **
|
|
|
else // **
|
|
|
{ // **
|
|
|
if (currentGroup != 0) // **
|
|
|
turnText.GetComponent<TMP_Text>().text = "敌方回合"; // **
|
|
|
else // **
|
|
|
turnText.GetComponent<TMP_Text>().text = "我方回合"; // **
|
|
|
turnObject.SetActive(true); // ** 战斗模式下始终显示敌我回合
|
|
|
} // **
|
|
|
}
|
|
|
|
|
|
// **** 是否显示背包
|
|
|
void ShowBag()
|
|
|
{
|
|
|
isOpen = myBag.activeSelf; // **** 防止鼠标点击退出背包后按两次I才能再次打开
|
|
|
if(Input.GetKeyDown("i")) // **** 按I键打开背包
|
|
|
{
|
|
|
isOpen = !isOpen; // ****
|
|
|
myBag.SetActive(isOpen); // ****
|
|
|
InventoryManager.RefreshItem(); // ****
|
|
|
}
|
|
|
} // **
|
|
|
public void ChangeCellInformation(int x, int y)
|
|
|
{
|
|
|
cellCost.text = x.ToString();
|
|
|
cellDamage.text = y.ToString();
|
|
|
}
|
|
|
public void ChangeCharaterInformation(int x, int y)
|
|
|
{
|
|
|
characterHealth.text = x.ToString();
|
|
|
characterPoise.text = y.ToString();
|
|
|
}
|
|
|
public void CheckDetailInformation(int str,int inte, int dex, int san,int vig, int def, int currentHealth,
|
|
|
int maxHealth, int currentPoise, int maxPoise, int currentMana, int maxMana)
|
|
|
{
|
|
|
STR.text = str.ToString();
|
|
|
INT.text = inte.ToString();
|
|
|
DEX.text = dex.ToString();
|
|
|
SAN.text = san.ToString();
|
|
|
VIG.text = vig.ToString();
|
|
|
DEF.text = def.ToString();
|
|
|
CurrentHealth.text = currentHealth.ToString();
|
|
|
MaxHealth.text = maxHealth.ToString();
|
|
|
CurrentPoise.text = currentPoise.ToString();
|
|
|
MaxPoise.text = maxPoise.ToString();
|
|
|
CurrentMana.text = currentMana.ToString();
|
|
|
MaxMana.text = maxMana.ToString();
|
|
|
|
|
|
detailInformation.SetActive(true);
|
|
|
//Debug.Log("!!");
|
|
|
}
|
|
|
}
|