Browse Source

refactor: 🎨 make BulletNum IntNumUpdateByCD

dev
shangfengh 2 years ago
parent
commit
53436fa47e
4 changed files with 10 additions and 56 deletions
  1. +7
    -50
      logic/GameClass/GameObj/Character/Character.cs
  2. +1
    -1
      logic/Gaming/AttackManager.cs
  3. +2
    -3
      logic/Preparation/Interface/ICharacter.cs
  4. +0
    -2
      logic/Preparation/Utility/SafeValue.cs

+ 7
- 50
logic/GameClass/GameObj/Character/Character.cs View File

@@ -10,20 +10,7 @@ namespace GameClass.GameObj
{
#region 装弹、攻击相关的基本属性及方法
private readonly object attackLock = new();
/// <summary>
/// 装弹冷却
/// </summary>
protected int cd;
public int CD
{
get
{
lock (attackLock)
{
return cd;
}
}
}
public IntNumUpdateByCD BulletNum { get; }
private int orgCD;
public int OrgCD
{
@@ -50,38 +37,11 @@ namespace GameClass.GameObj
lock (attackLock)
{
bulletOfPlayer = value;
cd = orgCD = (BulletFactory.BulletCD(value));
Debugger.Output(this, string.Format("'s CD has been set to: {0}.", cd));
maxBulletNum = bulletNum = (BulletFactory.BulletNum(value));
}
}
}

protected int maxBulletNum;
public int MaxBulletNum
{
get
{
lock (attackLock)
{
return maxBulletNum;
}
}
}
private int bulletNum;
private int updateTimeOfBulletNum = 0;

public int UpdateBulletNum(int time)//通过该函数获取真正的bulletNum
{
lock (attackLock)
{
if (bulletNum < maxBulletNum && time - updateTimeOfBulletNum >= cd)
{
int add = Math.Min(maxBulletNum - bulletNum, (time - updateTimeOfBulletNum) / cd);
updateTimeOfBulletNum += add * cd;
return (bulletNum += add);
orgCD = (BulletFactory.BulletCD(value));
BulletNum.SetCD(orgCD);
Debugger.Output(this, string.Format("'s CD has been set to: {0}.", orgCD));
BulletNum.SetPositiveMaxNumAndNum(BulletFactory.BulletNum(value));
}
return bulletNum;
}
}

@@ -89,17 +49,14 @@ namespace GameClass.GameObj
/// 进行一次攻击
/// </summary>
/// <returns>攻击操作发出的子弹</returns>
public Bullet? Attack(double angle, int time)
public Bullet? Attack(double angle)
{
lock (attackLock)
{
if (bulletOfPlayer == BulletType.Null)
return null;
if (UpdateBulletNum(time) > 0)
if (BulletNum.TrySub(1) == 1)
{
if (bulletNum == maxBulletNum) updateTimeOfBulletNum = time;
--bulletNum;

XY res = Position + new XY // 子弹紧贴人物生成。
(
(int)(Math.Abs((Radius + BulletFactory.BulletRadius(bulletOfPlayer)) * Math.Cos(angle))) * Math.Sign(Math.Cos(angle)),


+ 1
- 1
logic/Gaming/AttackManager.cs View File

@@ -203,7 +203,7 @@ namespace Gaming
{ // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange
if (!player.Commandable()) return false;

Bullet? bullet = player.Attack(angle, gameMap.Timer.nowTime());
Bullet? bullet = player.Attack(angle);

if (bullet != null)
{


+ 2
- 3
logic/Preparation/Interface/ICharacter.cs View File

@@ -1,5 +1,4 @@
using System;
using Preparation.Utility;
using Preparation.Utility;

namespace Preparation.Interface
{
@@ -15,7 +14,7 @@ namespace Preparation.Interface
public BulletType BulletOfPlayer { get; set; }
public CharacterType CharacterType { get; }
public ActiveSkill FindActiveSkill(ActiveSkillType activeSkillType);
public int UpdateBulletNum(int time);
public IntNumUpdateByCD BulletNum { get; }
public long SetPlayerState(RunningStateType running, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null);
public bool ResetPlayerState(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null);



+ 0
- 2
logic/Preparation/Utility/SafeValue.cs View File

@@ -1,7 +1,5 @@
using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Timers;

namespace Preparation.Utility
{


Loading…
Cancel
Save