2021-04-08 20:09:59 +08:00
|
|
|
|
using MongoDB.Bson.Serialization.Attributes;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public enum UnitType
|
|
|
|
|
{
|
|
|
|
|
Robot,
|
|
|
|
|
//玩家
|
|
|
|
|
Player,
|
|
|
|
|
//怪物
|
2021-05-01 11:27:41 +08:00
|
|
|
|
Monster,
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
public enum UnitStateType
|
|
|
|
|
{
|
|
|
|
|
Alive,
|
|
|
|
|
Dead,
|
|
|
|
|
WillLive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class UnitAwakeSystem : AwakeSystem<Unit, UnitType>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(Unit self, UnitType a)
|
|
|
|
|
{
|
|
|
|
|
self.Awake(a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class UnitDestroySystem : DestroySystem<Unit>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(Unit self)
|
|
|
|
|
{
|
|
|
|
|
self.TeamLeaderId = 0;
|
|
|
|
|
self.BattleId = 0;
|
|
|
|
|
self.isAgainOnLine = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class Unit : Entity
|
|
|
|
|
{
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public long TeamLeaderId { get; set; }
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public TeamState teamState { get; set; }
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public long BattleId { get; set; }
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public bool isAI{ get; set; }
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public bool IsTeamLeader => Id == TeamLeaderId;
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public bool IsAlive => UnitStateType == UnitStateType.Alive;
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public int? pos => GetComponent<Position>()?.pos;
|
|
|
|
|
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public bool isAgainOnLine { get; set; }
|
|
|
|
|
public UnitType UnitType { get; private set; }
|
|
|
|
|
|
|
|
|
|
public UnitStateType UnitStateType{ get; private set; }
|
|
|
|
|
[BsonIgnore] public long LastSaveTime;
|
|
|
|
|
[BsonIgnore] public bool IsTransfer{ get; set; }
|
|
|
|
|
[BsonIgnore] public bool IsOffline { get; set; }
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public Vector2 Position
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
UnitScene unitScene = this.GetComponent<UnitScene>();
|
|
|
|
|
if (!unitScene) return default;
|
|
|
|
|
return unitScene.Position;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
UnitScene unitScene = this.GetComponent<UnitScene>();
|
|
|
|
|
if (!unitScene) return;
|
|
|
|
|
unitScene.Position = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[BsonIgnore]
|
|
|
|
|
public int YAngle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
UnitScene unitScene = this.GetComponent<UnitScene>();
|
|
|
|
|
if (!unitScene) return default;
|
|
|
|
|
return unitScene.YAngle;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
UnitScene unitScene = this.GetComponent<UnitScene>();
|
|
|
|
|
if (!unitScene) return;
|
|
|
|
|
unitScene.YAngle = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Awake(UnitType unitType)
|
|
|
|
|
{
|
|
|
|
|
this.UnitType = unitType;
|
|
|
|
|
UnitStateType = UnitStateType.Alive;
|
|
|
|
|
IsOffline = false;
|
|
|
|
|
IsTransfer = false;
|
|
|
|
|
}
|
|
|
|
|
public void Live(NumericComponent num=null)
|
|
|
|
|
{
|
|
|
|
|
if (UnitStateType != UnitStateType.Dead)
|
|
|
|
|
return;
|
|
|
|
|
num ??= GetComponent<NumericComponent>();
|
|
|
|
|
num.Set(NumericType.Hp, 1, true);
|
|
|
|
|
UnitStateType = UnitStateType.Alive;
|
|
|
|
|
}
|
|
|
|
|
public void Dead(NumericComponent num=null)
|
|
|
|
|
{
|
|
|
|
|
num ??= GetComponent<NumericComponent>();
|
|
|
|
|
num.Set(NumericType.Hp, 0, true);
|
|
|
|
|
UnitStateType = UnitStateType.Dead;
|
|
|
|
|
}
|
|
|
|
|
public void DeadWillLive()
|
|
|
|
|
{
|
|
|
|
|
UnitStateType = UnitStateType.WillLive;
|
|
|
|
|
}
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return ToCustomString();
|
|
|
|
|
}
|
|
|
|
|
public string ToCustomString()
|
|
|
|
|
{
|
|
|
|
|
return $"【{UserComponent.Instance.Get(Id)?.NickName}({this.Id})】";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|