You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.1 KiB
121 lines
4.1 KiB
using System;
|
|
using System.Data;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
//武器伤害面板的计算方式 damage = (strAddition + level) * Character.str + (dexAddtion + level) * Character.dex
|
|
// + basicDamage * level
|
|
public abstract class Weapon : MonoBehaviour
|
|
{
|
|
Character self;
|
|
List<Character> enemiesInRange = new List<Character>();
|
|
List<Character> destroyedEnemies = new List<Character>();
|
|
//补正
|
|
public float strAddition = 1.0f;
|
|
public float dexAddtion = 3.0f;
|
|
//基础伤害
|
|
public int basicDamage = 9;
|
|
//对强韧度造成的伤害
|
|
public int poiseDamgage = 1;
|
|
//攻击消耗的行动点数
|
|
public int movementCost = 3;
|
|
//武器等级
|
|
public int level = 0;
|
|
public bool valid = true;
|
|
public int manaCovery = 0;
|
|
//武器描述
|
|
public string description;
|
|
public string weaponName;
|
|
public void SetRotation(Vector2 direction)
|
|
{
|
|
if(direction == Vector2.up)
|
|
transform.localEulerAngles = new Vector3(0,0,180);
|
|
if(direction == Vector2.right)
|
|
transform.localEulerAngles = new Vector3(0,0,90);
|
|
if(direction == Vector2.down)
|
|
transform.localEulerAngles = new Vector3(0,0,0);
|
|
if(direction == Vector2.left)
|
|
transform.localEulerAngles = new Vector3(0,0,-90);
|
|
}
|
|
protected void Awake()
|
|
{
|
|
self = transform.parent.parent.GetComponent<Character>();
|
|
Revise();
|
|
}
|
|
public void Attack()
|
|
{
|
|
if (enemiesInRange != null && enemiesInRange.Count > 0) // **** 若攻击范围内无敌人则不能进行攻击
|
|
{
|
|
if(self.GetCurrentMovement() >= movementCost)
|
|
{
|
|
self.ChangeMana(manaCovery);
|
|
self.ChangeMovement(-movementCost);
|
|
RaycastHit2D hit = Physics2D.Raycast(self.transform.position,Vector2.up,1.0f,LayerMask.GetMask("Cells"));
|
|
Cell currentCell = hit.collider.GetComponent<Cell>();
|
|
if(currentCell.damage > 0)
|
|
self.ChangeHealth(-currentCell.damage);
|
|
ApplyAttack();
|
|
}
|
|
else
|
|
self.OutOfMovement();
|
|
}
|
|
}
|
|
//关闭显示攻击范围
|
|
protected void OnTriggerExit2D(Collider2D other)
|
|
{
|
|
if(other.gameObject.layer == 8)
|
|
{
|
|
Cell cell = other.gameObject.GetComponent<Cell>();
|
|
cell.SetMask(false);
|
|
if(cell.currentCharacter != null && self.groupNumber != cell.currentCharacter.groupNumber)
|
|
enemiesInRange.Remove(cell.currentCharacter);
|
|
}
|
|
}
|
|
protected void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if(other.gameObject.layer == 8)
|
|
{
|
|
Cell cell = other.gameObject.GetComponent<Cell>();
|
|
if(cell.currentCharacter != null && self.groupNumber != cell.currentCharacter.groupNumber)
|
|
enemiesInRange.Add(cell.currentCharacter);
|
|
}
|
|
}
|
|
protected void OnTriggerStay2D(Collider2D other)
|
|
{
|
|
//武器有不同的攻击范围,选中角色时,可显示武器的攻击范围。
|
|
//显示攻击范围
|
|
if(other.gameObject.layer == 8)
|
|
{
|
|
other.gameObject.GetComponent<Cell>().SetMask(true);
|
|
}
|
|
}
|
|
//攻击功能
|
|
protected void ApplyAttack()
|
|
{
|
|
foreach (var enemy in enemiesInRange)
|
|
{
|
|
enemy.ChangeHealth(GameSettlement.DamageSettlement(this,self,enemy));
|
|
enemy.ChangePoise(-poiseDamgage);
|
|
if(enemy.GetCurrentHealth() == 0)
|
|
{
|
|
destroyedEnemies.Add(enemy);
|
|
if(self.GetExecute())
|
|
{
|
|
self.ChangeHealth(10);
|
|
self.ChangeMana(5);
|
|
}
|
|
}
|
|
self.buffManager.ApplyActiveSpecial(enemy);
|
|
enemy.buffManager.ApplyPassiveSpecial(self);
|
|
}
|
|
foreach (var enemy in destroyedEnemies)
|
|
{
|
|
enemiesInRange.Remove(enemy);
|
|
}
|
|
destroyedEnemies.Clear();
|
|
}
|
|
public abstract void LevelUp(Character character);
|
|
protected abstract void Revise();
|
|
public abstract int CheckLevelUpCost();
|
|
}
|