cda0c4a34f
# Conflicts: # Blacksmith/Assets/Pack/Icon/changbinglei.png.meta # Blacksmith/Assets/Pack/Icon/feibiaolei.png.meta # Blacksmith/Assets/Pack/Icon/gonglei.png.meta # Blacksmith/Assets/Pack/Icon/jianlei.png.meta # Blacksmith/Assets/Pack/Icon/nujianlei.png.meta # Blacksmith/Assets/Pack/Icon/qingjialei.png.meta # Blacksmith/Assets/Pack/Icon/zhanglei.png.meta # Blacksmith/Assets/Pack/Icon/zhongjialei.png.meta # Blacksmith/Assets/Resources/Prefab/player/player.prefab # Blacksmith/Assets/Scenes/SampleScene.unity # Blacksmith/Assets/Script/Battle/BattleManager.cs # Blacksmith/Assets/Script/Battle/Player/PlayerItem.cs # Blacksmith/Assets/Script/DataManager.cs # Blacksmith/Assets/WX-WASM-SDK-V2/Editor/MiniGameConfig.asset # Blacksmith/UserSettings/Layouts/default-2022.dwlt # box1/UserSettings/Layouts/default-2022.dwlt # box1/project.config.json
964 lines
26 KiB
C#
964 lines
26 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using cfg.BlacksmithData;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class BattleManager : MonoBehaviour
|
|
{
|
|
public static BattleManager ins;
|
|
[SerializeField] private Transform mousterPoint;//怪所在节点
|
|
[SerializeField] private Transform[] mousters;//怪生成区域
|
|
|
|
[SerializeField] private Transform[] playerParent;//玩家所在节点
|
|
public List<Mouster> Mousters => _mousters;
|
|
[SerializeField] private List<Mouster> _mousters=new List<Mouster>();//怪列表
|
|
public int MousterCount => _mousters.Count;
|
|
|
|
[SerializeField] private PlayerRunState[] playerItems;//玩家列表
|
|
[SerializeField] private List<MousterTeam> _mousterTeams = new List<MousterTeam>();//波次列表
|
|
[SerializeField] private List<Bullet> _bullets = new List<Bullet>();//玩家子弹列表
|
|
public List<SkillState> SkillStates => _skillStates;
|
|
[SerializeField] private List<SkillState> _skillStates;
|
|
[SerializeField] private List<int> id=new List<int>();
|
|
public List<Falling> Fallings => _fallings;
|
|
[SerializeField] private List<Falling> _fallings = new List<Falling>();
|
|
|
|
public float NowTime => nowTime;
|
|
private float nowTime=0;//关卡内时间
|
|
public int HP => hp;
|
|
[SerializeField]
|
|
private int hp;//总血量
|
|
|
|
public int Injured => injured;
|
|
private int injured;//受到的伤害
|
|
private bool player = false;//运行状态
|
|
private int mousterIndex=0;//当前波次
|
|
public int Exp => exp;
|
|
private int exp;
|
|
public int ExpLevel => expLevel;
|
|
private int expLevel;
|
|
public int MaxExp => maxExp;
|
|
private int maxExp;
|
|
public int EquipmentIndex => equipmentIndex;
|
|
private int equipmentIndex = 0;
|
|
public BattleEquipment[] BattleEquipments => _battleEquipments;
|
|
private BattleEquipment[] _battleEquipments = new BattleEquipment[3];
|
|
/// <summary>
|
|
/// 是否开启装备栏
|
|
/// </summary>
|
|
public bool OpenVideoWeaponry => openVideoWeaponry;
|
|
private bool openVideoWeaponry;
|
|
/// <summary>
|
|
/// 是否开启佣兵
|
|
/// </summary>
|
|
public bool OpenVideoSoldier => openVideoSoldier;
|
|
private bool openVideoSoldier;
|
|
private Dictionary<int, BuffAddData> buff = new Dictionary<int, BuffAddData>();
|
|
|
|
private void Awake()
|
|
{
|
|
ins = this;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
#region 准备战斗阶段
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 初始准备阶段装备数据
|
|
/// </summary>
|
|
public void ResetBattleData()
|
|
{
|
|
_battleEquipments=new BattleEquipment[3];
|
|
for (int i = 0; i < _battleEquipments.Length; i++)
|
|
{
|
|
_battleEquipments[i] = new BattleEquipment();
|
|
}
|
|
|
|
_battleEquipments[0].SetLock(true);
|
|
|
|
openVideoWeaponry = false;
|
|
openVideoSoldier = false;
|
|
equipmentIndex = 0;
|
|
}
|
|
/// <summary>
|
|
/// 解锁装备
|
|
/// </summary>
|
|
public void OpenVideoWeaponryEvent()
|
|
{
|
|
openVideoWeaponry = true;
|
|
}
|
|
/// <summary>
|
|
/// 解锁佣兵
|
|
/// </summary>
|
|
public void OpenVideoSoldierEvent()
|
|
{
|
|
openVideoSoldier = true;
|
|
foreach (var battle in _battleEquipments)
|
|
{
|
|
battle.SetLock(true);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置道具到指定单位
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <param name="data"></param>
|
|
public void SaveBattleData(int index,BattleEquipment data)
|
|
{
|
|
if (!openVideoSoldier)
|
|
{
|
|
if (index!=0)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
_battleEquipments[index] = data;
|
|
}
|
|
/// <summary>
|
|
/// 添加道具到单位组
|
|
/// </summary>
|
|
/// <param name="itemId"></param>
|
|
/// <param name="bo"></param>
|
|
public void AddItem(int itemId,out bool bo)
|
|
{
|
|
bo = false;
|
|
OpenAdd(itemId,_battleEquipments[equipmentIndex],ref bo);
|
|
// OpenAdd(itemId,_battleEquipments[0],ref bo);
|
|
// if (!bo&&openVideoSoldier)
|
|
// {
|
|
// OpenAdd(itemId,_battleEquipments[1],ref bo);
|
|
// }
|
|
// if (!bo&&openVideoSoldier)
|
|
// {
|
|
// OpenAdd(itemId,_battleEquipments[2],ref bo);
|
|
// }
|
|
}
|
|
|
|
public void SetIndex(int idnex)
|
|
{
|
|
equipmentIndex = idnex;
|
|
UIMgr.ins.ResetBattlePlayer();
|
|
}
|
|
/// <summary>
|
|
/// 添加一个道具到单位
|
|
/// </summary>
|
|
/// <param name="itemID"></param>
|
|
/// <param name="data"></param>
|
|
/// <param name="bo"></param>
|
|
private void OpenAdd(int itemID, BattleEquipment data, ref bool bo)
|
|
{
|
|
var itemData = JsonTab.Instance.tables.Item.Get(itemID);
|
|
if (data.weaponID==0)
|
|
{
|
|
data.weaponID = itemData.ID;
|
|
bo = true;
|
|
return;
|
|
}
|
|
if (data.weapon2ID==0)
|
|
{
|
|
data.weapon2ID = itemData.ID;
|
|
bo = true;
|
|
return;
|
|
}
|
|
if (data.armorID==0)
|
|
{
|
|
data.armorID = itemData.ID;
|
|
bo = true;
|
|
return;
|
|
}
|
|
if (data.audioUniversalID==0&&openVideoWeaponry)
|
|
{
|
|
data.audioUniversalID = itemData.ID;
|
|
bo = true;
|
|
return;
|
|
}
|
|
if (data.audioWeaponID==0&&openVideoWeaponry)
|
|
{
|
|
data.audioWeaponID = itemData.ID;
|
|
bo = true;
|
|
return;
|
|
}
|
|
if (data.audioWeapon2ID==0&&openVideoWeaponry)
|
|
{
|
|
data.audioWeapon2ID = itemData.ID;
|
|
bo = true;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取所有单位道具数量
|
|
/// </summary>
|
|
/// <param name="itemID"></param>
|
|
/// <param name="num"></param>
|
|
public void GetItemNum(int itemID,out int num)
|
|
{
|
|
num = 0;
|
|
EquipmentNum(itemID,_battleEquipments[0],ref num);
|
|
EquipmentNum(itemID,_battleEquipments[1],ref num);
|
|
EquipmentNum(itemID,_battleEquipments[2],ref num);
|
|
}
|
|
/// <summary>
|
|
/// 获取单位该道具的数量
|
|
/// </summary>
|
|
/// <param name="itemid"></param>
|
|
/// <param name="data"></param>
|
|
/// <param name="num"></param>
|
|
private void EquipmentNum(int itemid,BattleEquipment data,ref int num)
|
|
{
|
|
if (data.weaponID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
if (data.weapon2ID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
if (data.armorID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
if (data.audioUniversalID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
if (data.audioWeaponID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
if (data.audioWeapon2ID==itemid)
|
|
{
|
|
num++;
|
|
}
|
|
}
|
|
#endregion
|
|
public void StartBattle()
|
|
{
|
|
|
|
var allHP = 0;
|
|
foreach (var equipment in _battleEquipments)
|
|
{
|
|
AddNum(equipment.weaponID, ref allHP);
|
|
AddNum(equipment.weapon2ID, ref allHP);
|
|
AddNum(equipment.armorID, ref allHP);
|
|
AddNum(equipment.audioUniversalID, ref allHP);
|
|
AddNum(equipment.audioWeaponID, ref allHP);
|
|
AddNum(equipment.audioWeapon2ID, ref allHP);
|
|
DataManager.RemoveItem(equipment.weaponID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
DataManager.RemoveItem(equipment.weapon2ID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
DataManager.RemoveItem(equipment.armorID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
DataManager.RemoveItem(equipment.audioUniversalID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
DataManager.RemoveItem(equipment.audioWeaponID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
DataManager.RemoveItem(equipment.audioWeapon2ID, (bool b) =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
_skillStates = new List<SkillState>();
|
|
hp = allHP;
|
|
injured = 0;
|
|
BDebug.Log(hp);
|
|
nowTime = 0;
|
|
exp = 0;
|
|
expLevel = 1;
|
|
maxExp = JsonTab.Instance.tables.ExpRogue.Get(expLevel).Developexp;
|
|
if (playerItems!=null)
|
|
{
|
|
foreach (var p in playerItems)
|
|
{
|
|
if (p.player!=null)
|
|
{
|
|
PrefabPool.ins.RecycleObj(p.player.gameObject);
|
|
p.player = null;
|
|
}
|
|
}
|
|
}
|
|
playerItems = new PlayerRunState[playerParent.Length];
|
|
for (int i = 0; i < playerParent.Length; i++)
|
|
{
|
|
var index = i;
|
|
if (BattleEquipments[i].EquipmentLock)
|
|
{
|
|
PrefabPool.ins.LoadObj("Prefab/player/player",index, (GameObject obj,int idex) =>
|
|
{
|
|
obj.transform.parent = playerParent[idex];
|
|
obj.transform.localPosition=Vector3.zero;
|
|
playerItems[idex] = new PlayerRunState();
|
|
playerItems[idex].player = obj.GetComponent<PlayerItem>();
|
|
playerItems[idex].equipent = BattleEquipments[idex];
|
|
playerItems[idex].RestState();
|
|
playerItems[idex].player.SetModel(idex+1);
|
|
});
|
|
}
|
|
}
|
|
|
|
ResetLevelMouster();
|
|
player = true;
|
|
UIMgr.ins.ResetHp();
|
|
UIMgr.ins.ResetExp();
|
|
UIMgr.ins.OpenCombatPanel();
|
|
}
|
|
|
|
public void GetAttribute(ref int allHP,ref int aAttack)
|
|
{
|
|
foreach (var equipment in _battleEquipments)
|
|
{
|
|
AddNum(equipment.weaponID, ref allHP);
|
|
AddNum(equipment.weapon2ID, ref allHP);
|
|
AddNum(equipment.armorID, ref allHP);
|
|
AddNum(equipment.audioUniversalID, ref allHP);
|
|
AddNum(equipment.audioWeaponID, ref allHP);
|
|
AddNum(equipment.audioWeapon2ID, ref allHP);
|
|
AddAttackNum(equipment.weaponID, ref aAttack);
|
|
AddAttackNum(equipment.weapon2ID, ref aAttack);
|
|
AddAttackNum(equipment.armorID, ref aAttack);
|
|
AddAttackNum(equipment.audioUniversalID, ref aAttack);
|
|
AddAttackNum(equipment.audioWeaponID, ref aAttack);
|
|
AddAttackNum(equipment.audioWeapon2ID, ref aAttack);
|
|
}
|
|
}
|
|
|
|
public bool BattleStart()
|
|
{
|
|
bool bo = false;
|
|
foreach (var equipment in _battleEquipments)
|
|
{
|
|
if (equipment.weaponID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
if (equipment.weapon2ID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
if (equipment.armorID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
if (equipment.audioUniversalID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
if (equipment.audioWeaponID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
if (equipment.audioWeapon2ID!=0)
|
|
{
|
|
bo = true;
|
|
return bo;
|
|
}
|
|
}
|
|
return bo;
|
|
}
|
|
|
|
public void AddFallings(Falling data)
|
|
{
|
|
_fallings.Add(data);
|
|
}
|
|
public void AddSkillStates(SkillState state)
|
|
{
|
|
_skillStates.Add(state);
|
|
UIMgr.ins.ResetHp();
|
|
}
|
|
public void SetInjured(int num)
|
|
{
|
|
injured += num;
|
|
BDebug.Log(injured);
|
|
UIMgr.ins.ResetHp();
|
|
if (injured>hp)
|
|
{
|
|
BattleEnd(false);
|
|
}
|
|
}
|
|
|
|
void ResetLevelMouster()
|
|
{
|
|
mousterIndex = 0;
|
|
BDebug.Log("mouster");
|
|
var levelData = JsonTab.Instance.tables.Level.Get(DataManager.GetNowLevel());
|
|
_mousterTeams = new List<MousterTeam>();
|
|
for (int i = 0; i < levelData.Levelwaves.Count; i++)
|
|
{
|
|
var team = new MousterTeam();
|
|
team.SaveMousterData(levelData.Levelwaves[i]);
|
|
_mousterTeams.Add(team);
|
|
}
|
|
}
|
|
|
|
void AddNum(int id,ref int num)
|
|
{
|
|
if (id!=0)
|
|
{
|
|
var data = JsonTab.Instance.tables.Item.Get(id);
|
|
num+= JsonTab.Instance.attributeData(data.Includearms, DataManager.GetDrawLevel(data.Includearms))
|
|
.HP;
|
|
}
|
|
}
|
|
void AddAttackNum(int id,ref int num)
|
|
{
|
|
if (id!=0)
|
|
{
|
|
var data = JsonTab.Instance.tables.Item.Get(id);
|
|
var weapon =
|
|
JsonTab.Instance.attributeData(data.Includearms, DataManager.GetDrawLevel(data.Includearms));
|
|
num += weapon.Attack;
|
|
}
|
|
}
|
|
|
|
public void BattleEnd(bool win)
|
|
{
|
|
if (win)
|
|
{
|
|
var id = DataManager.GetNowLevel();
|
|
for (int i = 0; i < JsonTab.Instance.tables.Level.DataList.Count; i++)
|
|
{
|
|
if (JsonTab.Instance.tables.Level.DataList[i].ID==id)
|
|
{
|
|
if (i+1<JsonTab.Instance.tables.Level.DataList.Count)
|
|
{
|
|
DataManager.SetLevelLock(JsonTab.Instance.tables.Level.DataList[i+1].ID,DataManager.GetLevelLock(JsonTab.Instance.tables.Level.DataList[i+1].Levelopen));
|
|
DataManager.SetNowLevel(JsonTab.Instance.tables.Level.DataList[i+1].ID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
player = false;
|
|
StartCoroutine(DistoryAllMouster());
|
|
UIMgr.ins.OpenEndPanel(win);
|
|
}
|
|
|
|
IEnumerator DistoryAllMouster()
|
|
{
|
|
yield return null;
|
|
for (int i = _mousters.Count-1; i >=0; i--)
|
|
{
|
|
var m= _mousters[i];
|
|
_mousters.Remove(m);
|
|
PrefabPool.ins.RecycleObj(m.gameObject);
|
|
}
|
|
|
|
for (int i = _bullets.Count - 1; i >= 0; i--)
|
|
{
|
|
var m= _bullets[i];
|
|
_bullets.Remove(m);
|
|
PrefabPool.ins.RecycleObj(m.gameObject);
|
|
}
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (!player)
|
|
{
|
|
if (playerItems!=null)
|
|
{
|
|
foreach (var player in playerItems)
|
|
{
|
|
if (player!=null)
|
|
{
|
|
player.player.Type = playerAniType.wait;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
nowTime += Time.deltaTime;
|
|
if (_mousters!=null)
|
|
{
|
|
for (var i = _mousters.Count - 1; i >= 0; i--)
|
|
{
|
|
_mousters[i].Move(playerParent[0]);
|
|
}
|
|
}
|
|
|
|
TeamUpdate();
|
|
BulletUpdata();
|
|
if (playerItems!=null)
|
|
{
|
|
foreach (var player in playerItems)
|
|
{
|
|
if (player!=null)
|
|
{
|
|
if (MousterCount>0)
|
|
{
|
|
player.RunTimeMove();
|
|
player.player.Type = playerAniType.play;
|
|
}
|
|
else
|
|
{
|
|
player.player.Type = playerAniType.wait;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 波次组刷新
|
|
/// </summary>
|
|
public void TeamUpdate()
|
|
{
|
|
if (mousterIndex<_mousterTeams.Count)
|
|
{
|
|
if (_mousterTeams[mousterIndex].Type== MousterTeamType.ready)
|
|
{
|
|
_mousterTeams[mousterIndex].Type = MousterTeamType.wait;
|
|
_mousterTeams[mousterIndex].SetEventDynamicData();
|
|
}
|
|
|
|
if (_mousterTeams[mousterIndex].Type==MousterTeamType.wait&&_mousterTeams[mousterIndex].Update())
|
|
{
|
|
_mousterTeams[mousterIndex].Type = MousterTeamType.player;
|
|
AddMouster();
|
|
mousterIndex++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var bo = true;
|
|
foreach (var unused in _mousterTeams.Where(mouster => mouster.Type!=MousterTeamType.end))
|
|
{
|
|
bo = false;
|
|
}
|
|
|
|
if (bo)
|
|
{
|
|
BattleEnd(true);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 玩家子弹组刷新
|
|
/// </summary>
|
|
public void BulletUpdata()
|
|
{
|
|
for (int i = _bullets.Count-1; i >= 0; i--)
|
|
{
|
|
_bullets[i].BulletUpdate();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加玩家子弹
|
|
/// </summary>
|
|
/// <param name="bullet"></param>
|
|
public void AddBullets(Bullet bullet )
|
|
{
|
|
_bullets.Add(bullet);
|
|
}
|
|
/// <summary>
|
|
/// 移除玩家子弹
|
|
/// </summary>
|
|
/// <param name="bullet"></param>
|
|
public void RemoveBullets(Bullet bullet)
|
|
{
|
|
_bullets.Remove(bullet);
|
|
PrefabPool.ins.RecycleObj(bullet.gameObject);
|
|
}
|
|
/// <summary>
|
|
/// 添加怪
|
|
/// </summary>
|
|
public void AddMouster()
|
|
{
|
|
var index = mousterIndex;
|
|
foreach (var entity in _mousterTeams[mousterIndex].moustList)
|
|
{
|
|
PrefabPool.ins.LoadObj(entity._data.Prefab, (GameObject obj) =>
|
|
{
|
|
obj.transform.parent = mousterPoint;
|
|
var pos = new Vector3(Random.Range(mousters[0].position.x, mousters[1].position.x),
|
|
Random.Range(mousters[0].position.y, mousters[1].position.y), 0);
|
|
obj.transform.position=pos;
|
|
AxisLookAt(obj.transform, obj.transform.position - new Vector3(0, -2, 0));
|
|
var m = obj.GetComponent<Mouster>();
|
|
m.InitMousterData(entity);
|
|
_mousters.Add(m);
|
|
_mousterTeams[index].AddObj(m);
|
|
});
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 移除怪
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void RemoveMouster(Mouster obj)
|
|
{
|
|
var index = mousterIndex;
|
|
if (mousterIndex>=MousterCount)
|
|
{
|
|
index = mousterIndex - 1;
|
|
}
|
|
|
|
bool bo = false;
|
|
foreach (var mouster in _mousterTeams)
|
|
{
|
|
mouster.Remove(obj,ref bo);
|
|
if (bo)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
_mousters.Remove(obj);
|
|
PrefabPool.ins.RecycleObj(obj.gameObject);
|
|
exp++;
|
|
BDebug.LogWarning(exp);
|
|
UIMgr.ins.ResetExp();
|
|
if (exp>=maxExp)
|
|
{
|
|
player = false;
|
|
exp = 0;
|
|
expLevel++;
|
|
if (expLevel>15)
|
|
{
|
|
return;
|
|
}
|
|
maxExp = JsonTab.Instance.tables.ExpRogue.Get(expLevel).Developexp;
|
|
UIMgr.ins.OpenRogenPanel();
|
|
}
|
|
}
|
|
|
|
public void SetRogen(SkillRogueData data)
|
|
{
|
|
if (data.Frontend!=0)
|
|
{
|
|
foreach (var state in _skillStates)
|
|
{
|
|
state.UpRogen(data);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (data.Addskill!=0)
|
|
{
|
|
var skill = JsonTab.Instance.tables.Skill.Get(data.Addskill);
|
|
var buffdata = JsonTab.Instance.tables.Buff.Get(skill.Skilladdbuff);
|
|
AddBuff(buffdata.Bufftarget, buffdata);
|
|
}
|
|
else
|
|
{
|
|
var skill = JsonTab.Instance.tables.Skill.Get(data.Replace);
|
|
}
|
|
}
|
|
|
|
player = true;
|
|
}
|
|
|
|
public BuffAddData Buff(int id)
|
|
{
|
|
if (buff.TryGetValue(id, out var buff1)) return buff1;
|
|
var buffData = new BuffAddData();
|
|
buff.Add(id,buffData);
|
|
|
|
return buff[id];
|
|
}
|
|
|
|
public void AddBuff(int id, BuffData scale)
|
|
{
|
|
if (buff.ContainsKey(id))
|
|
{
|
|
BuffAddData objData = new BuffAddData();
|
|
switch (scale.Buffeffect1)
|
|
{
|
|
case 1:
|
|
objData.attack = scale.Buffparameter1;
|
|
break;
|
|
case 2:
|
|
objData.hp = scale.Buffparameter1;
|
|
break;
|
|
case 3:
|
|
objData.cd = scale.Buffparameter1;
|
|
break;
|
|
case 4:
|
|
objData.criticalStrike = scale.Buffparameter1;
|
|
break;
|
|
case 5:
|
|
break;
|
|
case 6:
|
|
break;
|
|
case 7:
|
|
break;
|
|
case 8:
|
|
break;
|
|
case 9:
|
|
objData.piercing = scale.Buffparameter1;
|
|
break;
|
|
case 10:
|
|
break;
|
|
}
|
|
buff[id].SetBuff(objData);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 朝向通用接口
|
|
/// </summary>
|
|
/// <param name="tr_self"></param>
|
|
/// <param name="lookPos"></param>
|
|
public void AxisLookAt(Transform tr_self, Vector3 lookPos)
|
|
{
|
|
Vector3 dir = lookPos - tr_self.position;
|
|
dir.z = 0;
|
|
float angle = Vector3.SignedAngle(Vector3.up, dir, Vector3.forward);
|
|
Quaternion rotation = Quaternion.Euler(0, 0, angle); //将欧拉角转换为四元数
|
|
tr_self.rotation = rotation;
|
|
}
|
|
|
|
|
|
}
|
|
public class BattleEquipment
|
|
{
|
|
public int playerID=0;
|
|
public int weaponID=0;
|
|
public int weapon2ID=0;
|
|
public int armorID=0;
|
|
public int audioUniversalID=0;
|
|
public int audioWeaponID=0;
|
|
public int audioWeapon2ID=0;
|
|
public bool EquipmentLock => equipmentLock;
|
|
private bool equipmentLock = false;
|
|
public SkillState Weapon => weapon;
|
|
private SkillState weapon;
|
|
public SkillState Weapon2 => weapon2;
|
|
private SkillState weapon2;
|
|
public SkillState Armor => armor;
|
|
private SkillState armor;
|
|
public SkillState AudioUniversal => audioUniversal;
|
|
private SkillState audioUniversal;
|
|
public SkillState AudioWeapon => audioWeapon;
|
|
private SkillState audioWeapon;
|
|
public SkillState AudioWeapon2 => audioWeapon2;
|
|
private SkillState audioWeapon2;
|
|
|
|
public void SetLock(bool bo)
|
|
{
|
|
equipmentLock = bo;
|
|
}
|
|
|
|
public void RestSkill()
|
|
{
|
|
if (weaponID!=0)
|
|
{
|
|
weapon = new SkillState(weaponID,"weaponID");
|
|
BattleManager.ins.AddSkillStates(weapon);
|
|
}
|
|
if (weapon2ID!=0)
|
|
{
|
|
weapon2 = new SkillState(weapon2ID,"weapon2ID");
|
|
BattleManager.ins.AddSkillStates(weapon2);
|
|
}
|
|
if (armorID!=0)
|
|
{
|
|
armor = new SkillState(armorID,"armorID");
|
|
BattleManager.ins.AddSkillStates(armor);
|
|
}
|
|
if (audioUniversalID!=0)
|
|
{
|
|
audioUniversal = new SkillState(audioUniversalID,"audioUniversalID");
|
|
BattleManager.ins.AddSkillStates(audioUniversal);
|
|
}
|
|
if (audioWeaponID!=0)
|
|
{
|
|
audioWeapon = new SkillState(audioWeaponID,"audioWeaponID");
|
|
BattleManager.ins.AddSkillStates(audioWeapon);
|
|
}
|
|
if (audioWeapon2ID!=0)
|
|
{
|
|
audioWeapon2 = new SkillState(audioWeapon2ID,"audioWeapon2ID");
|
|
BattleManager.ins.AddSkillStates(audioWeapon2);
|
|
}
|
|
|
|
}
|
|
|
|
public void RunTime()
|
|
{
|
|
weapon?.SkillStateEvent();
|
|
weapon2?.SkillStateEvent();
|
|
armor?.SkillStateEvent();
|
|
audioUniversal?.SkillStateEvent();
|
|
audioWeapon?.SkillStateEvent();
|
|
audioWeapon2?.SkillStateEvent();
|
|
|
|
}
|
|
}
|
|
|
|
public class SkillState
|
|
{
|
|
public int id;
|
|
public ItemData itemData;
|
|
public SkillData data;
|
|
public float cd;
|
|
public float cdTime;
|
|
public int Attack => attack;
|
|
private int attack = 0;
|
|
public float Ratio => ratio;
|
|
private float ratio = 1;
|
|
public List<Action<SkillState>> Actions = new List<Action<SkillState>>();
|
|
public List<Action> WaitActions = new List<Action>();
|
|
public bool SkillLock => skillLock;
|
|
private bool skillLock = false;
|
|
public string Name => name;
|
|
private string name;
|
|
|
|
public SkillState(int _id,string na)
|
|
{
|
|
if (_id==0)
|
|
{
|
|
id = 0;
|
|
return;
|
|
}
|
|
|
|
name = na;
|
|
id = _id;
|
|
itemData = JsonTab.Instance.tables.Item.Get(id);
|
|
var attributeData = JsonTab.Instance.tables.WeaponSkill.Get(id);
|
|
var weapon =
|
|
JsonTab.Instance.attributeData(itemData.Includearms, DataManager.GetDrawLevel(itemData.Includearms));
|
|
attack = weapon.Attack;
|
|
data = JsonTab.Instance.tables.Skill.Get(attributeData.Initialskill);
|
|
ratio = data.SkillDamage;
|
|
cd = data.SkillCD / 1000;
|
|
cdTime = BattleManager.ins.NowTime;
|
|
Actions = new List<Action<SkillState>>();
|
|
skillLock = false;
|
|
}
|
|
|
|
public void ResetSkill()
|
|
{
|
|
|
|
}
|
|
|
|
public void SkillCD()
|
|
{
|
|
// skillLock = false;
|
|
cdTime = BattleManager.ins.NowTime;
|
|
BDebug.LogWarning(name);
|
|
foreach (var a in Actions)
|
|
{
|
|
a?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
public void AddAction(Action<SkillState> action)
|
|
{
|
|
Actions.Add(action);
|
|
}
|
|
|
|
public void RemoveAction(Action<SkillState> action)
|
|
{
|
|
Actions.Remove(action);
|
|
}
|
|
|
|
public void AddWaitActions(Action action)
|
|
{
|
|
WaitActions.Add(action);
|
|
}
|
|
public void RemoveWaitActions(Action action)
|
|
{
|
|
WaitActions.Remove(action);
|
|
}
|
|
|
|
public void SkillStateEvent()
|
|
{
|
|
// if (skillLock)
|
|
// {
|
|
// foreach (var a in WaitActions)
|
|
// {
|
|
// a?.Invoke();
|
|
// }
|
|
// return;
|
|
// }
|
|
|
|
if (BattleManager.ins.NowTime-cdTime>cd*(1/(1+(float)BattleManager.ins.Buff(itemData.Includearms).cd/10000)))
|
|
{
|
|
// skillLock = true;
|
|
SkillCD();
|
|
}
|
|
}
|
|
|
|
public void UpRogen(SkillRogueData rogueData)
|
|
{
|
|
if (rogueData.Frontend==data.ID)
|
|
{
|
|
data = JsonTab.Instance.tables.Skill.Get(rogueData.Replace);
|
|
ratio = data.SkillDamage;
|
|
cd = data.SkillCD / 1000;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public class PlayerRunState
|
|
{
|
|
public PlayerItem player;
|
|
public BattleEquipment equipent;
|
|
|
|
public void RestState()
|
|
{
|
|
|
|
equipent.RestSkill();
|
|
player.SetData(equipent);
|
|
}
|
|
public void RunTimeMove()
|
|
{
|
|
equipent.RunTime();
|
|
}
|
|
}
|
|
|
|
public class BuffAddData
|
|
{
|
|
public int id = 0;
|
|
public int hp = 0;
|
|
public int attack = 0;
|
|
public int cd = 0;
|
|
public int criticalStrike = 0;
|
|
public int piercing = 0;
|
|
|
|
public void SetBuff(BuffAddData data)
|
|
{
|
|
hp= hp + data.hp;
|
|
attack = attack + data.attack;
|
|
cd = cd + data.cd;
|
|
criticalStrike = criticalStrike +data.criticalStrike;
|
|
piercing = piercing + data.piercing;
|
|
}
|
|
}
|
|
|
|
public class Falling
|
|
{
|
|
public int id;
|
|
public int num;
|
|
|
|
public Falling(int _id, int _num)
|
|
{
|
|
id = _id;
|
|
num = _num;
|
|
}
|
|
} |