138 lines
4.1 KiB
C#
138 lines
4.1 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
|
||
namespace Game
|
||
{
|
||
/// <summary>
|
||
/// 角色不具备战斗逻辑,所有战斗逻辑由战斗系统完成
|
||
/// 自走棋的角色不具备自动回血功能,只能通过技能buff进行回血
|
||
/// </summary>
|
||
public interface ICharacter
|
||
{
|
||
HeroConfig Config { get; }
|
||
GameObject Go { get; }
|
||
|
||
string Name { get; }
|
||
string Description { get; }
|
||
int Level { get; }
|
||
float Hp { get; }
|
||
float Mp { get; }
|
||
float Attack { get; }
|
||
float Defense { get; }
|
||
float MoveSpeed { get; }
|
||
float AttackSpeed { get; }
|
||
bool IsDead { get; }
|
||
|
||
IReadOnlyList<IEquipment> Equipments { get; }
|
||
IReadOnlyList<Buff> Buffs { get; }
|
||
|
||
bool AddEquipment(IEquipment equipment);
|
||
bool RemoveAllEquipment(out List<IEquipment> equipments);
|
||
|
||
void OnAttack(Character character);
|
||
}
|
||
|
||
public class Character : ICharacter
|
||
{
|
||
private HeroConfig _characterConfig;
|
||
private GameObject _go;
|
||
private List<IEquipment> _equipments;
|
||
private string _name;
|
||
private string _description;
|
||
private int _level;
|
||
private float _hp;
|
||
private float _mp;
|
||
private float _attack;
|
||
private float _defense;
|
||
private float _moveSpeed;
|
||
private float _attackSpeed;
|
||
|
||
private float tmphp;
|
||
private float tmpmp;
|
||
private float tmpattack;
|
||
private float tmpdefense;
|
||
private float tmpmoveSpeed;
|
||
private float tmpattackSpeed;
|
||
private IReadOnlyList<Buff> _buffs;
|
||
|
||
public HeroConfig Config => _characterConfig;
|
||
|
||
public GameObject Go => _go;
|
||
|
||
public string Name => _name;
|
||
|
||
public string Description => _description;
|
||
|
||
public int Level => _level;
|
||
|
||
public float Hp => _hp + tmphp;
|
||
|
||
public float Mp => _mp + tmpmp;
|
||
|
||
public float Attack => _attack + tmpattack;
|
||
|
||
public float Defense => _defense + tmpdefense;
|
||
|
||
public float MoveSpeed => _moveSpeed + tmpmoveSpeed;
|
||
|
||
public float AttackSpeed => _attackSpeed + tmpattackSpeed;
|
||
|
||
public bool IsDead => _hp <= 0;
|
||
|
||
public IReadOnlyList<IEquipment> Equipments => _equipments;
|
||
|
||
public IReadOnlyList<Buff> Buffs => _buffs;
|
||
|
||
public Character(HeroConfig characterConfig, GameObject go)
|
||
{
|
||
_characterConfig = characterConfig;
|
||
_go = go;
|
||
_name = _characterConfig.BasicStats.Name;
|
||
_description = _characterConfig.BasicStats.Description;
|
||
// _hp = _characterConfig.MaxHp;
|
||
// _mp = _characterConfig.MaxMp;
|
||
_equipments = new List<IEquipment>();
|
||
}
|
||
|
||
public bool AddEquipment(IEquipment equipment)
|
||
{
|
||
// if (_equipments.Count >= _characterConfig.MaxEquipmentCount)
|
||
// return false;
|
||
|
||
_equipments.Add(equipment);
|
||
// tmphp += equipment.Config.Hp;
|
||
// tmpmp += equipment.Config.Mp;
|
||
// tmpattack += equipment.Config.Attack;
|
||
// tmpdefense += equipment.Config.Defense;
|
||
// tmpmoveSpeed += equipment.Config.MoveSpeed;
|
||
// tmpattackSpeed += equipment.Config.AttackSpeed;
|
||
return true;
|
||
}
|
||
|
||
public bool RemoveAllEquipment(out List<IEquipment> equipments)
|
||
{
|
||
equipments = _equipments.ToList();
|
||
// foreach (var equipment in _equipments)
|
||
// {
|
||
// tmphp -= equipment.Config.Hp;
|
||
// tmpmp -= equipment.Config.Mp;
|
||
// tmpattack -= equipment.Config.Attack;
|
||
// tmpdefense -= equipment.Config.Defense;
|
||
// tmpmoveSpeed -= equipment.Config.MoveSpeed;
|
||
// tmpattackSpeed -= equipment.Config.AttackSpeed;
|
||
// }
|
||
|
||
_equipments.Clear();
|
||
return true;
|
||
}
|
||
|
||
public void OnAttack(Character target)
|
||
{
|
||
foreach (var equipment in _equipments)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
} |