JinChanChan/Assets/Scripts/Game/Character/ICharacter.cs

138 lines
4.1 KiB
C#
Raw Normal View History

2025-02-13 16:54:33 +08:00
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Game
{
2025-02-13 16:54:33 +08:00
/// <summary>
/// 角色不具备战斗逻辑,所有战斗逻辑由战斗系统完成
/// 自走棋的角色不具备自动回血功能只能通过技能buff进行回血
/// </summary>
public interface ICharacter
{
HeroConfig Config { get; }
2025-02-13 16:54:33 +08:00
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;
2025-02-13 16:54:33 +08:00
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;
2025-02-13 16:54:33 +08:00
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)
2025-02-13 16:54:33 +08:00
{
_characterConfig = characterConfig;
_go = go;
_name = _characterConfig.BasicStats.Name;
_description = _characterConfig.BasicStats.Description;
// _hp = _characterConfig.MaxHp;
// _mp = _characterConfig.MaxMp;
2025-02-13 16:54:33 +08:00
_equipments = new List<IEquipment>();
}
public bool AddEquipment(IEquipment equipment)
{
// if (_equipments.Count >= _characterConfig.MaxEquipmentCount)
// return false;
2025-02-13 16:54:33 +08:00
_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;
2025-02-13 16:54:33 +08:00
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)
{
2025-02-13 16:54:33 +08:00
foreach (var equipment in _equipments)
{
2025-02-13 16:54:33 +08:00
}
}
}
}