179 lines
4.5 KiB
C#
179 lines
4.5 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 MousterTeam
|
|
{
|
|
public List<MousterEntity> moustList = new List<MousterEntity>();
|
|
public List<Mouster> objlist = new List<Mouster>();
|
|
public MousterTeamType Type;
|
|
public MousterTeamEventType EventType;
|
|
public float dynamic = 0;
|
|
private LevelWaveData _data;
|
|
public void SaveMousterData(int waves)
|
|
{
|
|
Type = MousterTeamType.ready;
|
|
_data = JsonTab.Instance.tables.LevelWave.Get(waves);
|
|
if (_data.Appear==1)
|
|
{
|
|
EventType = MousterTeamEventType.time;
|
|
}
|
|
else
|
|
{
|
|
EventType = MousterTeamEventType.num;
|
|
}
|
|
var allWeight = _data.MonsterWeight.Sum();
|
|
List<int> mousterNum = new List<int>();
|
|
for (int i = 0; i < _data.Monsters.Count; i++)
|
|
{
|
|
var num =(int) (((float)_data.MonsterWeight[i] / (float)allWeight) * _data.Monsterall);
|
|
mousterNum.Add(num);
|
|
}
|
|
|
|
for (int i = 0; i < mousterNum.Count; i++)
|
|
{
|
|
for (int j = 0; j < mousterNum[i]; j++)
|
|
{
|
|
var entity = new MousterEntity();
|
|
entity.SetData(_data.Monsters[i]);
|
|
moustList.Add(entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Drop()
|
|
{
|
|
if (Type==MousterTeamType.end)
|
|
{
|
|
return _data.Drop;
|
|
}
|
|
return 0;
|
|
}
|
|
public void SetEventDynamicData()
|
|
{
|
|
switch (EventType)
|
|
{
|
|
case MousterTeamEventType.time:
|
|
dynamic = BattleManager.ins.NowTime + _data.Conditional;
|
|
break;
|
|
case MousterTeamEventType.num:
|
|
dynamic = _data.Conditional;
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
public bool Update()
|
|
{
|
|
return EventType switch
|
|
{
|
|
MousterTeamEventType.time => BattleManager.ins.NowTime > dynamic,
|
|
MousterTeamEventType.num => BattleManager.ins.MousterCount < dynamic,
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
}
|
|
|
|
public bool AllDeath()
|
|
{
|
|
return moustList.All(t => !t.Death);
|
|
}
|
|
|
|
public int LiveNum()
|
|
{
|
|
return moustList.Count(entity => !entity.Death);
|
|
}
|
|
|
|
public void AddObj(Mouster obj)
|
|
{
|
|
objlist.Add(obj);
|
|
}
|
|
|
|
public void Remove(Mouster obj, ref bool bo)
|
|
{
|
|
if (Type == MousterTeamType.end)
|
|
{
|
|
return;
|
|
}
|
|
foreach (var m in objlist)
|
|
{
|
|
if (m==obj)
|
|
{
|
|
objlist.Remove(obj);
|
|
bo = true;
|
|
if (objlist.Count==0)
|
|
{
|
|
Type = MousterTeamType.end;
|
|
var dropData = JsonTab.Instance.tables.LevelFalling.Get(_data.Drop);
|
|
Falling a = new Falling(dropData.Drop1, Random.Range(dropData.Drop1num[0], dropData.Drop1num[1]));
|
|
BattleManager.ins.AddFallings(a);
|
|
if (dropData.Drop2!=0)
|
|
{
|
|
Falling b = new Falling(dropData.Drop2, Random.Range(dropData.Drop2num[0], dropData.Drop2num[1]));
|
|
BattleManager.ins.AddFallings(b);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
[Serializable]
|
|
public class MousterEntity
|
|
{
|
|
private int id;
|
|
[SerializeField]
|
|
private int hp;
|
|
[SerializeField]
|
|
private int injured;
|
|
public MousterData _data;
|
|
public SkillData skillData;
|
|
public float cd;
|
|
public float nextAttack;
|
|
public bool Death => death;
|
|
private bool death = false;
|
|
public Action DeathAction;
|
|
public void SetData(int _id)
|
|
{
|
|
id = _id;
|
|
injured = 0;
|
|
_data = JsonTab.Instance.tables.Mouster.Get(id);
|
|
hp = _data.HP;
|
|
var skillData = JsonTab.Instance.tables.Skill.Get(_data.Attackskill);
|
|
cd = skillData.SkillCD / 1000;
|
|
death = false;
|
|
|
|
}
|
|
|
|
public void NextAttack()
|
|
{
|
|
nextAttack = BattleManager.ins.NowTime + cd;
|
|
}
|
|
|
|
public void SetInjured(int num)
|
|
{
|
|
injured += num;
|
|
if (injured <= hp) return;
|
|
death = true;
|
|
DeathAction?.Invoke();
|
|
}
|
|
}
|
|
|
|
public enum MousterTeamType
|
|
{
|
|
ready,
|
|
player,
|
|
wait,
|
|
end
|
|
}
|
|
|
|
public enum MousterTeamEventType
|
|
{
|
|
time,
|
|
num
|
|
}
|