浏览代码

got hit action working with basic physics detection. Added stub for characters dying--right now they just instantly destroy themselves

/main
David Woodruff 4 年前
当前提交
f6b9a66a
共有 10 个文件被更改,包括 116 次插入37 次删除
  1. 8
      Assets/BossRoom/Prefabs/Enemy.prefab
  2. 8
      Assets/BossRoom/Prefabs/Player.prefab
  3. 7
      Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs
  4. 23
      Assets/BossRoom/Scripts/Server/Game/Action/Action.cs
  5. 11
      Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs
  6. 12
      Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs
  7. 48
      Assets/BossRoom/Scripts/Server/Game/Action/MeleeAction.cs
  8. 21
      Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs
  9. 11
      Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs
  10. 4
      ProjectSettings/TagManager.asset

8
Assets/BossRoom/Prefabs/Enemy.prefab


- component: {fileID: -7347463593668903068}
- component: {fileID: -2661490869309078486}
- component: {fileID: -3025025970778375211}
m_Layer: 0
m_Name: Enemy2
m_Layer: 6
m_Name: Enemy
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Name:
m_EditorClassIdentifier:
HitPoints:
InternalValue: 0
InternalValue: 50
InternalValue: 0
InternalValue: 20
--- !u!195 &4129073990757611390
NavMeshAgent:
m_ObjectHideFlags: 0

8
Assets/BossRoom/Prefabs/Player.prefab


- component: {fileID: 6970334877957368017}
- component: {fileID: 4602672899881656135}
- component: {fileID: 7690172137830037487}
m_Layer: 0
m_Layer: 3
m_Name: Player
m_TagString: Player
m_Icon: {fileID: 0}

m_Name:
m_EditorClassIdentifier:
HitPoints:
InternalValue: 0
InternalValue: 1000000
InternalValue: 0
InternalValue: 10
--- !u!114 &4600110157238723776
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 920a440eb254ba348915767fd046027a, type: 3}
m_Name:
m_EditorClassIdentifier:
IsNPC: 0
DetectRange: 10
--- !u!114 &7690172137830037487
MonoBehaviour:
m_ObjectHideFlags: 0

7
Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs


private void SmoothMove()
{
if (m_Parent == null) { return; } //parent was destroyed, and we won't be far behind.
if (m_Parent == null)
{
//since we aren't in the transform hierarchy, we have to explicitly die when our parent dies.
GameObject.Destroy(this.gameObject);
return;
}
var pos_diff = m_Parent.transform.position - transform.position;

23
Assets/BossRoom/Scripts/Server/Game/Action/Action.cs


/// </remarks>
public abstract class Action
{
protected ServerCharacter m_parent;
protected ServerCharacter m_Parent;
protected int m_level;
protected int m_Level;
protected ActionRequestData m_data;
protected ActionRequestData m_Data;
/// <summary>
/// Time when this Action was started (from Time.time) in seconds. Set by the ActionPlayer.
/// </summary>
public float TimeStarted { get; set; }
public ref ActionRequestData Data { get { return ref m_data; } }
public ref ActionRequestData Data { get { return ref m_Data; } }
/// <summary>
/// Data Description for this action.

get
{
var list = ActionData.ActionDescriptions[Data.ActionTypeEnum];
int level = Mathf.Min(m_level, list.Count - 1); //if we don't go up to the requested level, just cap at the max level.
int level = Mathf.Min(m_Level, list.Count - 1); //if we don't go up to the requested level, just cap at the max level.
return list[level];
}
}

/// </summary>
public Action(ServerCharacter parent, ref ActionRequestData data, int level)
{
m_parent = parent;
m_level = level;
m_data = data; //do a shallow copy.
m_data.Level = level;
m_Parent = parent;
m_Level = level;
m_Data = data; //do a shallow copy.
m_Data.Level = level;
}
/// <summary>

11
Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs


private ServerCharacter m_parent;
private List<Action> m_queue;
private float m_actionStarted_s = 0f;
public ActionPlayer(ServerCharacter parent )
{

if( m_queue.Count > 0 )
{
m_actionStarted_s = Time.time;
m_queue[0].TimeStarted = Time.time;
bool play = m_queue[0].Start();
if( !play )
{

{
if( this.m_queue.Count > 0 )
{
bool keepgoing = this.m_queue[0].Update();
bool expirable = (this.m_queue[0].Description.Duration_s > 0f); //non-positive value is a sentinel indicating the duration is indefinite.
bool time_expired = expirable && (Time.time - this.m_actionStarted_s) >= this.m_queue[0].Description.Duration_s;
bool keepgoing = m_queue[0].Update();
bool expirable = m_queue[0].Description.Duration_s > 0f; //non-positive value is a sentinel indicating the duration is indefinite.
bool time_expired = expirable && (Time.time - m_queue[0].TimeStarted) >= m_queue[0].Description.Duration_s;
this.AdvanceQueue(true);
AdvanceQueue(true);
}
}
}

12
Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs


/// <returns>false if the action decided it doesn't want to run after all, true otherwise. </returns>
public override bool Start()
{
if(m_data.TargetIds == null || m_data.TargetIds.Length == 0 || !MLAPI.Spawning.SpawnManager.SpawnedObjects.ContainsKey(m_data.TargetIds[0]) )
if(m_Data.TargetIds == null || m_Data.TargetIds.Length == 0 || !MLAPI.Spawning.SpawnManager.SpawnedObjects.ContainsKey(m_Data.TargetIds[0]) )
m_Target = MLAPI.Spawning.SpawnManager.SpawnedObjects[m_data.TargetIds[0]];
m_Target = MLAPI.Spawning.SpawnManager.SpawnedObjects[m_Data.TargetIds[0]];
m_Movement = m_parent.GetComponent<ServerCharacterMovement>();
m_Movement = m_Parent.GetComponent<ServerCharacterMovement>();
m_Movement.SetMovementTarget(m_Target.transform.position);
m_CurrentTargetPos = m_Target.transform.position;

/// <returns>true to keep running, false to stop. The Action will stop by default when its duration expires, if it has a duration set. </returns>
public override bool Update()
{
float dist_to_target = (m_parent.transform.position - m_Target.transform.position).magnitude;
if( m_data.Amount > dist_to_target )
float dist_to_target = (m_Parent.transform.position - m_Target.transform.position).magnitude;
if( m_Data.Amount > dist_to_target )
{
//we made it! we're done.
Cancel();

float target_moved = (m_Target.transform.position - m_CurrentTargetPos).magnitude;
if( m_data.Amount < target_moved )
if( m_Data.Amount < target_moved )
{
//target has moved past our range tolerance. Must repath.
this.m_Movement.SetMovementTarget(m_Target.transform.position);

48
Assets/BossRoom/Scripts/Server/Game/Action/MeleeAction.cs


{
public class MeleeAction : Action
{
private bool m_ExecFired;
public MeleeAction(ServerCharacter parent, ref ActionRequestData data, int level) : base(parent, ref data, level)
{
}

//stub. For now, just relay the action to all clients.
m_parent.NetState.S2C_BroadcastAction(ref Data);
m_Parent.NetState.S2C_BroadcastAction(ref Data);
public override bool Update() { return true; }
public override bool Update()
{
if( !m_ExecFired && (Time.time-TimeStarted) >= Description.ExecTime_s )
{
m_ExecFired = true;
var foe = DetectFoe();
if(foe != null )
{
foe.RecieveHP(this.m_Parent, -Description.Amount);
}
}
return true;
}
/// <summary>
/// Returns the ServerCharacter of the foe we hit, or null if none found.
/// </summary>
/// <returns></returns>
private ServerCharacter DetectFoe()
{
//this simple detect just does a boxcast out from our position in the direction we're facing, out to the range of the attack.
var my_bounds = this.m_Parent.GetComponent<Collider>().bounds;
RaycastHit hit;
//NPCs (monsters) can hit PCs, and vice versa. No friendly fire allowed on either side.
int mask = LayerMask.GetMask(m_Parent.IsNPC ? "PCs" : "NPCs");
if( Physics.BoxCast(m_Parent.transform.position, my_bounds.extents, m_Parent.transform.forward, out hit, Quaternion.identity,
Description.Range, mask ))
{
var foe_character = hit.collider.GetComponent<ServerCharacter>();
return foe_character;
}
return null;
}
}
}

21
Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs


this.PlayAction(ref data);
}
/// <summary>
/// Receive an HP change from somewhere. Could be healing or damage.
/// </summary>
/// <param name="Inflicter">Person dishing out this damage/healing. Can be null. </param>
/// <param name="HP">The HP to receive. Positive value is healing. Negative is damage. </param>
public void RecieveHP( ServerCharacter inflicter, int HP)
{
//in a more complicated implementation, we might look up all sorts of effects from the inflicter, and compare them
//to our own effects, and modify the damage or healing as appropriate. But in this game, we just take it straight.
NetState.HitPoints.Value += HP;
if( NetState.HitPoints.Value <= 0 )
{
//TODO: handle death state.
GameObject.Destroy(this.gameObject);
}
}
// Update is called once per frame
void Update()
{

11
Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs


public float Duration_s;
/// <summary>
/// Time when the Action should do its "main thing" (e.g. when a melee attack should apply damage).
/// </summary>
public float ExecTime_s;
/// <summary>
/// How long the effect this Action leaves behind will last, in seconds.
/// </summary>
public float EffectDuration_s;

{
{ ActionType.TANK_BASEATTACK , new List<ActionDescription>
{
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=10, ManaCost=2, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 1
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=15, ManaCost=2, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 2
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=20, ManaCost=2, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 3
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=10, ManaCost=2, ExecTime_s=0.3f, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 1
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=15, ManaCost=2, ExecTime_s=0.3f, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 2
{new ActionDescription{Logic=ActionLogic.MELEE, Amount=20, ManaCost=2, ExecTime_s=0.3f, Duration_s=0.5f, Range=4f, Anim="Todo" } }, //level 3
}
},

4
ProjectSettings/TagManager.asset


- Default
- TransparentFX
- Ignore Raycast
-
- PCs
-
- NPCs
-
-
-

正在加载...
取消
保存