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.

79 lines
2.7 KiB

using System.Data;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//武器伤害面板的计算方式 damage = (strAddition + level) * Character.str + (dexAddtion + level) * Character.dex
// + basicDamage * level
public class Weapon : MonoBehaviour
{
//补正
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 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);
}
//武器有不同的攻击范围,选中角色时,可显示武器的攻击范围,并可以标记敌人。
//显示攻击范围
private void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "Cell")
{
other.gameObject.GetComponent<Cell>().SetMask(true);
}
}
//关闭显示攻击范围
private void OnTriggerExit2D(Collider2D other)
{
if(other.gameObject.tag == "Cell")
{
other.gameObject.GetComponent<Cell>().SetMask(false);
}
}
private void OnTriggerStay2D(Collider2D other)
{
//攻击功能
if(Input.GetKeyDown("x"))
{
if(other.gameObject.layer == 8)
{
Cell cell = other.GetComponent<Cell>();
Character enemy = cell.GetCurrentCharacter();
if(enemy == null) return;
Character self = transform.parent.parent.GetComponent<Character>();
if(enemy.groupNumber == self.groupNumber) return;
//判定行动点是否足够
if(self.GetCurrentMovement() >= movementCost)
{
self.ChangeMovement(-movementCost);
if(cell.damage > 0)
{
self.ChangeHealth(-cell.damage);
}
enemy.ChangeHealth(-2);
enemy.ChangePoise(-poiseDamgage);
if(enemy.GetCurrentHealth() == 0)
Destroy(enemy.gameObject);
}
else
self.OutOfMovement();
}
}
}
}